Skip to content
Snippets Groups Projects
Commit 6b0200af authored by Mattia Mancini's avatar Mattia Mancini
Browse files

SSB-47: Add accessors to readonly fields

parent dddee213
No related branches found
No related tags found
1 merge request!44Merge back holography to master
......@@ -8,6 +8,7 @@ from .holography_dataset_definitions import *
from .holography_observation import HolographyObservation
from .holography_specification import HolographySpecification
from numpy import isnan
logger = logging.getLogger(__file__)
......@@ -37,6 +38,7 @@ def compare_nested_collections(dict1, dict2):
return False
return result
def bytestring_list_to_string(list):
return [item.decode('utf-8') for item in list]
......@@ -63,54 +65,54 @@ class HolographyDataset():
initialised with an assignment to their respective constructors.
'''
# float, HDS version
self.version = HOLOGRAPHY_DATA_SET_VERSION
self._version = HOLOGRAPHY_DATA_SET_VERSION
# list of ints
self.rcu_list = list()
self._rcu_list = list()
# integer
self.mode = None
self._mode = None
# list of strings
self.sas_ids = list()
self._sas_ids = list()
# string
self.target_station_name = None
self._target_station_name = None
# list of 3 floats
self.target_station_position = None
self._target_station_position = None
# name of the source (str)
self.source_name = None
self._source_name = None
# position of the source array[ (RA, numpy.float64), (DEC, numpy.float64), (EPOCH, 'S10')]
self.source_position = None
self._source_position = None
# date time when the observation started in MJD in seconds (float)
self.start_time = None
self._start_time = None
# date time when the observation started in MJD in seconds (float)
self.end_time = None
self._end_time = None
# array(3,3), translation matrix for
# (RA, DEC) <-> (l, m) conversion
self.rotation_matrix = None
self._rotation_matrix = None
# list of beamlet numbers
self.beamlets = list()
self._beamlets = list()
# The central beam or beamlet for each frequency
self.central_beamlets = dict()
self.calibration_tables = dict()
self._central_beamlets = dict()
self._calibration_tables = dict()
self.derived_calibration_tables = dict()
# coordinates of the antenna position in the target
self.antenna_field_position = list()
self._antenna_field_position = list()
# list of reference station names
self.reference_stations = list()
self._reference_stations = list()
# list of _frequencies
self.frequencies = list()
self._frequencies = list()
# dict(frequency:
# array that contains the ra_dec of which a beam
# points at given a frequency and a beamlet number
# numpy.dtype([('RA', numpy.float64),
# ('DEC',numpy.float64),
# ('EPOCH', 'S10')])
self.ra_dec = dict()
self._ra_dec = dict()
# dict(reference_station_name:
# dict(frequency:
# dict(beamlet_number:
......@@ -131,6 +133,70 @@ class HolographyDataset():
# numpy.array()
self.derived_data = None
@property
def version(self):
return self._version
@property
def rcu_list(self):
return self._rcu_list
@property
def mode(self):
return self._mode
@property
def sas_ids(self):
return self._sas_ids
@property
def target_station_name(self):
return self._target_station_name
@property
def target_station_position(self):
return self._target_station_position
@property
def source_name(self):
return self._source_name
@property
def source_position(self):
return self.source_position
@property
def start_time(self):
return self._start_time
@property
def end_time(self):
return self._end_time
def rotation_matrix(self):
return self._rotation_matrix
def beamlets(self):
return self._beamlets
def central_beamlets(self):
return self._central_beamlets
def calibration_tables(self):
return self._calibration_tables
def antenna_field_position(self):
return self._antenna_field_position
def reference_stations(self):
return self._reference_stations
def frequencies(self):
return self._frequencies
def ra_dec(self):
return self._ra_dec
def __eq__(self, hds=None):
'''
This comparison operator compares the values of the relevant members of
......@@ -173,7 +239,6 @@ class HolographyDataset():
return False
return equality
def find_central_beamlets(self, source, ra_dec, frequencies, beamlets):
'''
This function finds the central beamlet of a target station for every
......@@ -233,8 +298,8 @@ class HolographyDataset():
logger.debug('reading data')
self.__read_data(station_name, list_of_hbs_ms_tuples)
logger.debug('read data')
self.central_beamlets = self.find_central_beamlets(self.source_position, self.ra_dec,
self.frequencies, self.beamlets)
self._central_beamlets = self.find_central_beamlets(self._source_position, self._ra_dec,
self._frequencies, self._beamlets)
logger.info("Creation of a holography data set for station \"%s\" done.", station_name)
except Exception as e:
logger.exception("Error creating dataset for station \"%s\": %s", station_name, e)
......@@ -298,9 +363,9 @@ class HolographyDataset():
if station_name in hbs.target_station_names:
frequency = ho.frequency
frequency_string = str(frequency)
for beamlet in self.beamlets:
for beamlet in self._beamlets:
beamlet_string = str(beamlet)
if beamlet_string not in self.ra_dec[frequency_string]:
if beamlet_string not in self._ra_dec[frequency_string]:
logger.error('missing pointing %s at frequency %s for station %s skipping',
beamlet_string,
frequency_string,
......@@ -310,9 +375,9 @@ class HolographyDataset():
ho.ms_for_a_given_beamlet_number[
beamlet].read_cross_correlation_time_flags_lm_per_station_name(
station_name,
self.reference_stations,
self.ra_dec[frequency_string][beamlet_string],
self.rotation_matrix)
self._reference_stations,
self._ra_dec[frequency_string][beamlet_string],
self._rotation_matrix)
for reference_station_index, reference_station in \
enumerate(reference_station_names):
......@@ -378,7 +443,7 @@ class HolographyDataset():
sas_ids.add(ho.sas_id)
self.target_station_name = station_name
self._target_station_name = station_name
reference_stations.update(hbs.reference_station_names)
try:
single_beamlet = int(beam_specification.beamlets)
......@@ -394,20 +459,20 @@ class HolographyDataset():
beam_specification.virtual_pointing['coordinate_system'])
else:
continue
self.frequencies = sorted(frequencies)
self.beamlets = sorted(beamlets)
self.start_time = start_mjd
self.end_time = end_mjd
self.sas_ids = list(sas_ids)
self.reference_stations = list(reference_stations)
self.rcu_list = list(rcu_list)
self.ra_dec = dict()
for frequency in self.frequencies:
self._frequencies = sorted(frequencies)
self._beamlets = sorted(beamlets)
self._start_time = start_mjd
self._end_time = end_mjd
self._sas_ids = list(sas_ids)
self._reference_stations = list(reference_stations)
self._rcu_list = list(rcu_list)
self._ra_dec = dict()
for frequency in self._frequencies:
frequency_string = str(frequency)
if frequency not in self.ra_dec:
self.ra_dec[frequency_string] = dict()
for beamlet in self.beamlets:
if frequency not in self._ra_dec:
self._ra_dec[frequency_string] = dict()
for beamlet in self._beamlets:
beamlet_string = str(beamlet)
ra, dec, _ = virtual_pointing[(frequency, beamlet)]
if isnan(ra) or isnan(dec):
......@@ -416,7 +481,7 @@ class HolographyDataset():
# skip if the pointing is ill specified
continue
self.ra_dec[frequency_string][beamlet_string] = numpy.array(
self._ra_dec[frequency_string][beamlet_string] = numpy.array(
virtual_pointing[(frequency, beamlet)],
dtype=HDS_coordinate_type)
......@@ -429,11 +494,11 @@ class HolographyDataset():
station_name)
logger.debug('selecting used antenna ids %s', used_antennas)
self.antenna_field_position = [list(station_position - antenna_offset)
for antenna_id, antenna_offset in enumerate(tile_offset)
if antenna_id in used_antennas]
self.target_station_position = list(station_position)
self.rotation_matrix = axes_coordinates
self._antenna_field_position = [list(station_position - antenna_offset)
for antenna_id, antenna_offset in enumerate(tile_offset)
if antenna_id in used_antennas]
self._target_station_position = list(station_position)
self._rotation_matrix = axes_coordinates
if station_name not in target_stations:
logger.error('Station %s was not involved in the observation.'
......@@ -443,18 +508,18 @@ class HolographyDataset():
% station_name, )
if len(mode) == 1:
self.mode = mode.pop()
self._mode = mode.pop()
else:
raise ValueError('Multiple RCUs mode are not supported')
if len(source_position) == 1:
self.source_position = numpy.array(source_position.pop(), dtype=HDS_coordinate_type)
self._source_position = numpy.array(source_position.pop(), dtype=HDS_coordinate_type)
else:
logger.error('Multiple source positions are not supported: %s', source_position)
raise ValueError('Multiple source positions are not supported')
if len(source_name) == 1:
self.source_name = source_name.pop()
self._source_name = source_name.pop()
else:
raise ValueError('Multiple source name are not supported')
......@@ -469,23 +534,23 @@ class HolographyDataset():
if text is not None and isinstance(text, str):
logger.info("%s", text)
if hds is not None and isinstance(hds, HolographyDataset) is True:
logger.info("Version = %s", hds.version)
logger.info("Mode = %s", hds.mode)
logger.info("RCU list = ", hds.rcu_list)
logger.info("SAS IDs = %s", hds.sas_ids)
logger.info("Target station name = %s", hds.target_station_name)
logger.info("Target station position = %s", hds.target_station_position)
logger.info("Source name = %s", hds.source_name)
logger.info("Source position = %s", hds.source_position)
logger.info("Central beamlets = %s", hds.central_beamlets)
logger.info("Start time = %s", hds.start_time)
logger.info("End time = %s", hds.end_time)
logger.info("Rotation matrix = %s", hds.rotation_matrix)
logger.info("Antenna field position = %s", hds.antenna_field_position)
logger.info("Reference stations = %s", hds.reference_stations)
logger.info("Frequencies = %s", hds.frequencies)
logger.info("Beamlets = %s", hds.beamlets)
logger.info("RA DEC = %s", hds.ra_dec)
logger.info("Version = %s", hds._version)
logger.info("Mode = %s", hds._mode)
logger.info("RCU list = ", hds._rcu_list)
logger.info("SAS IDs = %s", hds._sas_ids)
logger.info("Target station name = %s", hds._target_station_name)
logger.info("Target station position = %s", hds._target_station_position)
logger.info("Source name = %s", hds._source_name)
logger.info("Source position = %s", hds._source_position)
logger.info("Central beamlets = %s", hds._central_beamlets)
logger.info("Start time = %s", hds._start_time)
logger.info("End time = %s", hds._end_time)
logger.info("Rotation matrix = %s", hds._rotation_matrix)
logger.info("Antenna field position = %s", hds._antenna_field_position)
logger.info("Reference stations = %s", hds._reference_stations)
logger.info("Frequencies = %s", hds._frequencies)
logger.info("Beamlets = %s", hds._beamlets)
logger.info("RA DEC = %s", hds._ra_dec)
logger.info("Data = %s", hds.data)
else:
logger.warning(
......@@ -622,42 +687,42 @@ class HolographyDataset():
f = h5py.File(path, "r")
result = HolographyDataset()
result.version = f.attrs[HDS_VERSION]
result.mode = f.attrs[HDS_MODE]
result.rcu_list = list(f.attrs[HDS_RCU_LIST])
result.sas_ids = list(f.attrs[HDS_SAS_ID])
result.target_station_name = f.attrs[HDS_TARGET_STATION_NAME]
result.target_station_position = list(f.attrs[HDS_TARGET_STATION_POSITION])
result.source_name = f.attrs[HDS_SOURCE_NAME]
result.source_position = numpy.array(f.attrs[HDS_SOURCE_POSITION])
(result.start_time, result.end_time) = f.attrs[HDS_OBSERVATION_TIME]
result.rotation_matrix = f.attrs[HDS_ROTATION_MATRIX]
result.beamlets = list(f.attrs[HDS_BEAMLETS])
result.antenna_field_position = f.attrs[HDS_ANTENNA_FIELD_POSITION].tolist()
result.reference_stations = bytestring_list_to_string(list(f[HDS_REFERENCE_STATION]))
result.frequencies = list(f[HDS_FREQUENCY])
result._version = f.attrs[HDS_VERSION]
result._mode = f.attrs[HDS_MODE]
result._rcu_list = list(f.attrs[HDS_RCU_LIST])
result._sas_ids = list(f.attrs[HDS_SAS_ID])
result._target_station_name = f.attrs[HDS_TARGET_STATION_NAME]
result._target_station_position = list(f.attrs[HDS_TARGET_STATION_POSITION])
result._source_name = f.attrs[HDS_SOURCE_NAME]
result._source_position = numpy.array(f.attrs[HDS_SOURCE_POSITION])
(result._start_time, result._end_time) = f.attrs[HDS_OBSERVATION_TIME]
result._rotation_matrix = f.attrs[HDS_ROTATION_MATRIX]
result._beamlets = list(f.attrs[HDS_BEAMLETS])
result._antenna_field_position = f.attrs[HDS_ANTENNA_FIELD_POSITION].tolist()
result._reference_stations = bytestring_list_to_string(list(f[HDS_REFERENCE_STATION]))
result._frequencies = list(f[HDS_FREQUENCY])
if HDS_CALIBRATION_TABLES in f:
for mode in f[HDS_CALIBRATION_TABLES]:
uri = '/%s/%s' % (HDS_CALIBRATION_TABLES, mode)
result.calibration_tables[mode] = \
result._calibration_tables[mode] = \
CalibrationTable.load_from_hdf(file_descriptor=f, uri=uri)
if HDS_DERIVED_CAL_TABLES in f:
for mode in f[HDS_DERIVED_CAL_TABLES]:
uri = '/%s/%s' % (HDS_DERIVED_CAL_TABLES, mode)
result.calibration_tables[mode] = \
result._calibration_tables[mode] = \
CalibrationTable.load_from_hdf(file_descriptor=f, uri=uri)
result.ra_dec = dict()
result._ra_dec = dict()
for frequency in f["RA_DEC"].keys():
for beamlet in f["RA_DEC"][frequency].keys():
if frequency not in result.ra_dec:
result.ra_dec[frequency] = dict()
if frequency not in result._ra_dec:
result._ra_dec[frequency] = dict()
result.ra_dec[frequency][beamlet] = numpy.array(f["RA_DEC"][frequency][beamlet])
result._ra_dec[frequency][beamlet] = numpy.array(f["RA_DEC"][frequency][beamlet])
beamlets = set()
for reference_station in f["CROSSCORRELATION"].keys():
......@@ -667,7 +732,7 @@ class HolographyDataset():
result.data = f['CROSSCORRELATION']
result.central_beamlets = HolographyDataset._read_grouped_data(f, HDS_CENTRAL_BEAMLETS)
result._central_beamlets = HolographyDataset._read_grouped_data(f, HDS_CENTRAL_BEAMLETS)
if '/DERIVED_DATA' in f:
result.derived_data = f['/DERIVED_DATA']
......@@ -683,7 +748,7 @@ class HolographyDataset():
def insert_calibration_table(self, caltable: CalibrationTable):
mode = caltable.observation_mode
self.calibration_tables[mode] = caltable
self._calibration_tables[mode] = caltable
def store_to_file(self, path):
"""
......@@ -700,33 +765,33 @@ class HolographyDataset():
f.attrs[HDS_VERSION] = HOLOGRAPHY_DATA_SET_VERSION
# RCU list
f.attrs[HDS_RCU_LIST] = numpy.array(self.rcu_list, dtype=int)
f.attrs[HDS_RCU_LIST] = numpy.array(self._rcu_list, dtype=int)
# RCU mode
f.attrs[HDS_MODE] = self.mode
f.attrs[HDS_MODE] = self._mode
# Moan... Again this needs to be stored like that.
f.attrs[HDS_SAS_ID] = numpy.array(self.sas_ids,
f.attrs[HDS_SAS_ID] = numpy.array(self._sas_ids,
dtype=h5py.special_dtype(vlen=str))
f.attrs[HDS_TARGET_STATION_NAME] = self.target_station_name
f.attrs[HDS_TARGET_STATION_POSITION] = self.target_station_position
f.attrs[HDS_SOURCE_NAME] = self.source_name
f.attrs[HDS_SOURCE_POSITION] = self.source_position
f.attrs[HDS_OBSERVATION_TIME] = numpy.array([self.start_time, self.end_time])
f.attrs[HDS_ROTATION_MATRIX] = self.rotation_matrix
f.attrs[HDS_ANTENNA_FIELD_POSITION] = self.antenna_field_position
f.attrs[HDS_BEAMLETS] = self.beamlets
f.attrs[HDS_TARGET_STATION_NAME] = self._target_station_name
f.attrs[HDS_TARGET_STATION_POSITION] = self._target_station_position
f.attrs[HDS_SOURCE_NAME] = self._source_name
f.attrs[HDS_SOURCE_POSITION] = self._source_position
f.attrs[HDS_OBSERVATION_TIME] = numpy.array([self._start_time, self._end_time])
f.attrs[HDS_ROTATION_MATRIX] = self._rotation_matrix
f.attrs[HDS_ANTENNA_FIELD_POSITION] = self._antenna_field_position
f.attrs[HDS_BEAMLETS] = self._beamlets
# Store the list of reference stations and _frequencies. We just
# want to keep 'em around for quick reference.
f[HDS_REFERENCE_STATION] = to_numpy_array_string(self.reference_stations)
f[HDS_FREQUENCY] = self.frequencies
f[HDS_REFERENCE_STATION] = to_numpy_array_string(self._reference_stations)
f[HDS_FREQUENCY] = self._frequencies
f.create_group(HDS_CALIBRATION_TABLES)
for mode in self.calibration_tables:
self.calibration_tables[mode].store_to_hdf(f,
'/{}/{}'.format(
HDS_CALIBRATION_TABLES, mode))
for mode in self._calibration_tables:
self._calibration_tables[mode].store_to_hdf(f,
'/{}/{}'.format(
HDS_CALIBRATION_TABLES, mode))
for mode in self.derived_calibration_tables:
self.derived_calibration_tables[mode].store_to_hdf(f,
'/{}/{}'.format(
......@@ -734,7 +799,7 @@ class HolographyDataset():
mode))
HolographyDataset._store_grouped_data(h5file=f, uri='/RA_DEC',
data_to_store=self.ra_dec)
data_to_store=self._ra_dec)
# We create groups for the reference stations and the _frequencies.
# Then we store the data samples [XX, YY, XY, YX, t, l, m, flag]
......@@ -746,7 +811,7 @@ class HolographyDataset():
HolographyDataset._store_grouped_data(h5file=f,
uri=HDS_CENTRAL_BEAMLETS,
data_to_store=self.central_beamlets)
data_to_store=self._central_beamlets)
if self.derived_data:
self._store_grouped_data(h5file=f,
uri='/DERIVED_DATA',
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment