Skip to content
Snippets Groups Projects
Commit 2ea58e2d authored by Thomas Jürges's avatar Thomas Jürges
Browse files

Task SSB-42: It is good practice to check for the default behaviour first and then for the rest

parent b42252be
No related branches found
No related tags found
1 merge request!44Merge back holography to master
...@@ -304,21 +304,21 @@ class HolographyDataset(): ...@@ -304,21 +304,21 @@ class HolographyDataset():
raise Exception('Station %s was not involved in the observation.' raise Exception('Station %s was not involved in the observation.'
% station_name, ) % station_name, )
if len(mode) > 1: if len(mode) == 1:
raise ValueError('Multiple RCUs mode are not supported')
else:
self.mode = mode.pop() self.mode = mode.pop()
else:
raise ValueError('Multiple RCUs mode are not supported')
if len(source_position) > 1: if len(source_position) == 1:
self.source_position = source_position.pop()
else:
logger.error('Multiple source positions are not supported: %s', source_position) logger.error('Multiple source positions are not supported: %s', source_position)
raise ValueError('Multiple source positions are not supported') raise ValueError('Multiple source positions are not supported')
else:
self.source_position = source_position.pop()
if len(source_name) > 1: if len(source_name) == 1:
raise ValueError('Multiple source name are not supported')
else:
self.source_name = source_name.pop() self.source_name = source_name.pop()
else:
raise ValueError('Multiple source name are not supported')
@staticmethod @staticmethod
def print_info(hds=None, text=None): def print_info(hds=None, text=None):
......
...@@ -19,12 +19,12 @@ class HolographyMeasurementSet(object): ...@@ -19,12 +19,12 @@ class HolographyMeasurementSet(object):
def __init__(self, ms_name, ms_path): def __init__(self, ms_name, ms_path):
self.path = os.path.join(ms_path, ms_name) self.path = os.path.join(ms_path, ms_name)
if not HolographyMeasurementSet.is_a_valid_ms_name(ms_name): if HolographyMeasurementSet.is_a_valid_ms_name(ms_name):
raise ValueError('The measurement set located in %s has not a valid name' % self.path, )
self.name = ms_name self.name = ms_name
self.sas_id, self.beamlet = \ self.sas_id, self.beamlet = \
HolographyMeasurementSet.parse_sas_id_and_sub_band_from_ms_name(self.name) HolographyMeasurementSet.parse_sas_id_and_sub_band_from_ms_name(self.name)
else:
raise ValueError('The measurement set located in %s has not a valid name' % self.path, )
def get_frequency(self): def get_frequency(self):
observation_table = self.get_spectral_window_table() observation_table = self.get_spectral_window_table()
...@@ -94,10 +94,10 @@ class HolographyMeasurementSet(object): ...@@ -94,10 +94,10 @@ class HolographyMeasurementSet(object):
try: try:
unique_names = {name for name in pointing_table.getcol('NAME')} unique_names = {name for name in pointing_table.getcol('NAME')}
if len(unique_names) > 1: if len(unique_names) == 1:
raise ValueError('Expected only a source as a target for the observation')
else:
source_name = unique_names.pop() source_name = unique_names.pop()
else:
raise ValueError('Expected only a source as a target for the observation')
finally: finally:
pointing_table.close() pointing_table.close()
...@@ -255,10 +255,7 @@ class HolographyMeasurementSet(object): ...@@ -255,10 +255,7 @@ class HolographyMeasurementSet(object):
def _compute_lm_from_ra_dec_station_position_rotation_matrix_and_time(ra_dec_epoch, def _compute_lm_from_ra_dec_station_position_rotation_matrix_and_time(ra_dec_epoch,
rotation_matrix, rotation_matrix,
mjd_times): mjd_times):
if isinstance(ra_dec_epoch, numpy.ndarray):
if not isinstance(ra_dec_epoch, numpy.ndarray):
raise TypeError('Expected a structured numpy array for ra_dec obtained {}'.
format(ra_dec_epoch))
ra, dec, epoch = ra_dec_epoch.tolist() ra, dec, epoch = ra_dec_epoch.tolist()
astropy_times = [HolographyMeasurementSet.__mjd_to_astropy_time(mjd_time) astropy_times = [HolographyMeasurementSet.__mjd_to_astropy_time(mjd_time)
...@@ -272,6 +269,9 @@ class HolographyMeasurementSet(object): ...@@ -272,6 +269,9 @@ class HolographyMeasurementSet(object):
return_value['l'][:] = l_m_arrays[:, 0] return_value['l'][:] = l_m_arrays[:, 0]
return_value['m'][:] = l_m_arrays[:, 1] return_value['m'][:] = l_m_arrays[:, 1]
else:
raise TypeError('Expected a structured numpy array for ra_dec obtained {}'.
format(ra_dec_epoch))
return return_value return return_value
...@@ -283,9 +283,10 @@ class HolographyMeasurementSet(object): ...@@ -283,9 +283,10 @@ class HolographyMeasurementSet(object):
@staticmethod @staticmethod
def parse_sas_id_and_sub_band_from_ms_name(ms_name): def parse_sas_id_and_sub_band_from_ms_name(ms_name):
if not HolographyMeasurementSet.is_a_valid_ms_name(ms_name): if HolographyMeasurementSet.is_a_valid_ms_name(ms_name):
raise ValueError('The measurement set %s has not a valid name' % ms_name, )
match = re.match(HolographyMeasurementSet.ms_name_pattern, ms_name) match = re.match(HolographyMeasurementSet.ms_name_pattern, ms_name)
else:
raise ValueError('The measurement set %s has not a valid name' % ms_name, )
return str(match.group('sas_id')), int(match.group('sub_band_id')) return str(match.group('sas_id')), int(match.group('sub_band_id'))
@staticmethod @staticmethod
......
...@@ -117,31 +117,29 @@ class HolographyObservation(): ...@@ -117,31 +117,29 @@ class HolographyObservation():
extract_unique_reference_frequencies_from_ms_list( extract_unique_reference_frequencies_from_ms_list(
ms_indexed_per_beamlet_number.values()) ms_indexed_per_beamlet_number.values())
if len(unique_frequencies) > 1: if len(unique_frequencies) == 1:
frequency = unique_frequencies.pop()
else:
raise ValueError( raise ValueError(
'Multiple reference frequencies per observation are not supported') 'Multiple reference frequencies per observation are not supported')
else:
frequency = unique_frequencies.pop()
unique_source_names = HolographyObservation.\ unique_source_names = HolographyObservation.\
extract_unique_source_names_from_ms_list(ms_indexed_per_beamlet_number.values()) extract_unique_source_names_from_ms_list(ms_indexed_per_beamlet_number.values())
if len(unique_source_names) > 1: if len(unique_source_names) == 1:
raise ValueError(
'Multiple source target per observation are not supported'
)
else:
source_name = unique_source_names.pop() source_name = unique_source_names.pop()
else:
raise ValueError(
'Multiple source target per observation are not supported')
unique_subband = HolographyObservation.\ unique_subband = HolographyObservation.\
extract_unique_subband_from_ms_list(ms_indexed_per_beamlet_number.values()) extract_unique_subband_from_ms_list(ms_indexed_per_beamlet_number.values())
if len(unique_subband) > 1: if len(unique_subband) == 1:
raise ValueError(
'Multiple subband per observation are not supported'
)
else:
sub_band = unique_subband.pop() sub_band = unique_subband.pop()
else:
raise ValueError(
'Multiple subband per observation are not supported')
observations_list.append( observations_list.append(
HolographyObservation(path, sas_id, ms_indexed_per_beamlet_number, HolographyObservation(path, sas_id, ms_indexed_per_beamlet_number,
......
...@@ -14,11 +14,11 @@ def is_observation_in_range(start, end, from_datetime, to_datetime): ...@@ -14,11 +14,11 @@ def is_observation_in_range(start, end, from_datetime, to_datetime):
:return: true if the observation is contained in the range false otherwise :return: true if the observation is contained in the range false otherwise
:raises: ValueError if start > end :raises: ValueError if start > end
""" """
if start > end: if start <= end:
raise ValueError('start datetime is greater then end datetime')
start_in_range = from_datetime < start < to_datetime start_in_range = from_datetime < start < to_datetime
end_in_range = from_datetime < end < to_datetime end_in_range = from_datetime < end < to_datetime
else:
raise ValueError('start datetime is greater then end datetime')
return start_in_range and end_in_range return start_in_range and end_in_range
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment