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

SSB-42: fixing rcu list information

parent 6466848b
No related branches found
No related tags found
1 merge request!44Merge back holography to master
......@@ -11,7 +11,7 @@ logger = logging.getLogger(__name__)
class HolographyDataset():
def __init__(self):
self.version = HOLOGRAPHY_DATA_SET_VERSION # float, HDS version
self.rcu_list = set() # array of ints
self.rcu_list = set() # list of ints
self.mode = None # integer
self.sas_ids = set() # array of strings
self.target_station_name = None # string
......@@ -285,11 +285,8 @@ class HolographyDataset():
# Start with the version information
f.attrs[HDS_VERSION] = HOLOGRAPHY_DATA_SET_VERSION
# Create a numpy array that contains the RCU list as unicode strings.
# The type has to be str because nump/h5py cannot handle unicode string
# arrays.
f.attrs[HDS_RCU_LIST] = numpy.array(self.rcu_list,
dtype=h5py.special_dtype(vlen = str))
# RCU list
f.attrs[HDS_RCU_LIST] = numpy.array(list(self.rcu_list), int)
# RCU mode
f.attrs[HDS_MODE] = self.mode
......
......@@ -97,6 +97,35 @@ class HolographySpecification(object):
dec = float(dec)
return dict(ra=ra, dec=dec, coordinate_system=coordinate_system)
@staticmethod
def _parse_integer_range_or_list(string_to_be_parsed):
"""
Parses a string containing a list of int or an inclusive range and returns a list of int
ex "1,2,3,4,5" -> [1, 2, 3, 4, 5]
"1:4" -> [1, 2, 3, 4]
:param string_to_be_parsed: the string representing a list of int or a range
:return: a list of int
:rtype: list(int)
"""
if ':' in string_to_be_parsed:
try:
start, end = map(int, string_to_be_parsed.split(':'))
except ValueError as e:
raise ValueError('Cannot parse string %s expected [start]:[end] -> %s' %
(string_to_be_parsed, e))
return_value = [x for x in range(start, end)]
elif ',' in string_to_be_parsed:
try:
return_value = list(map(int, string_to_be_parsed.split(',')))
except ValueError as e:
raise ValueError('Cannot parse string %s expected [int],[int],... -> %s' %
(string_to_be_parsed, e))
else:
raise ValueError('Cannot parse string %s expected [int],[int],... or [start]:[end] %s' %
string_to_be_parsed)
return return_value
@staticmethod
def _parse_line(splitted_line):
......@@ -106,7 +135,8 @@ class HolographySpecification(object):
beam_specification.rcus_mode = int(splitted_line['rcus_mode'])
beam_specification.sub_band_ids = [int(sub_band) for sub_band in splitted_line['sub_band'].split(',')]
beam_specification.mode_description = splitted_line['mode_description']
beam_specification.rcus_involved = splitted_line['rcus']
beam_specification.rcus_involved = HolographySpecification._parse_integer_range_or_list(
splitted_line['rcus'])
beam_specification.beamlets = splitted_line['beamlets']
beam_specification.station_pointing = HolographySpecification._parse_pointing(
......
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