def parse_station_resp(fid): """ Gather information from a single station IRIS response file *fid*. Return the information as a :class:`RespMap`. """ resp_map = RespMap() # sanity check initialization network = None stn = None location = None # skip initial header comment block skip_block_header_comments(fid) while True: block_header, block, eof = parse_block(fid) # sanity check (same network, station, and location across recorded blocks) network = check(block_header, 'Network', network) stn = check(block_header, 'Station', stn) location = check(block_header, 'Location', location) # store block information interval = DateTimeInterval.closed_open(block_header['Start_date'], block_header['End_date']) resp_map.setdefault(interval, {})[block_header['Channel']] = block if eof: break resp_map.network = network resp_map.stn = stn resp_map.location = location return resp_map
def __init__(self, glo_status_fname=GLO_STATUS_FNAME): """ Parse *glo_status_fname* and store GLONASS status information. """ super(GLONASS_Status, self).__init__() if glo_status_fname == GLO_STATUS_FNAME and not os.path.isfile( glo_status_fname): update_glo_status() def parse_dt(date, time): if date == '0000-00-00' and time == '00:00': return None else: return datetime.strptime(date + ' ' + time, '%Y-%m-%d %H:%M') with open(glo_status_fname) as fid: for line in fid: if line.startswith('#'): continue toks = line.split() launch_dt = parse_dt(toks[0], toks[1]) start_dt = parse_dt(toks[2], toks[3]) end_dt = parse_dt(toks[4], toks[5]) slot, freq, plane, GLONASS, cosmos = map(int, toks[6:]) interval = DateTimeInterval.closed_open(start_dt, end_dt) info = StatusInfo(launch_dt, slot, freq, plane, GLONASS, cosmos) self.setdefault(slot, OrderedDict())[interval] = info
def __new__(cls, local_fname=BARTELS_FNAME): """ Build a new Bartels rotation information object. """ obj = super(Bartels, cls).__new__(cls) parse(local_fname=local_fname, data_map=obj) obj._interval_map = OrderedDict() times_1 = [x.dt for x in obj.values()[:-1]] times_2 = [x.dt for x in obj.values()[1:]] for b_id, (t1, t2) in zip(obj, zip(times_1, times_2)): interval = DateTimeInterval.closed_open(t1, t2) obj._interval_map[interval] = b_id return obj
def parse_edit_commands(df_fname): """ ??? """ time_reject_map = defaultdict(list) phase_adjust_map = defaultdict(list) start_command = None with open(df_fname) as fid: for line in fid: if line.startswith('-DS+'): if start_command is not None: raise RuntimeError( 'adjacent start time ranges detected in ' '{} ({})'.format(df_fname, line)) start_command = line elif line.startswith('-DS-'): if start_command is None: raise RuntimeError( 'found time range end prior to start in ' '{} ({})'.format(df_fname, line)) _, sv_start, dt_start = parse_delete_command(start_command) _, sv_end, dt_end = parse_delete_command(line) if sv_start != sv_end: raise RuntimeError('time range start is for {} but end is ' 'for {}'.format(sv_start, sv_end)) time_reject_map[sv_start].append( DateTimeInterval([dt_start, dt_end])) start_command = None elif line.startswith('-DS'): _, sv, dt = parse_delete_command(line) time_reject_map[sv].append(DateTimeInterval([dt, dt])) elif line.startswith('-BD+'): _, sv, obs_type, dt, offset = parse_bias_command(line) phase_adjust_map[sv].append((dt, obs_type, offset)) else: raise NotImplementedError( 'unhandled edit command {}'.format(line)) return time_reject_map, phase_adjust_map
class TestIntervalProperties(object): @mark.parametrize(('number_range', 'length'), ( ([1, 4], 3), ([-1, 1], 2), ((-inf, inf), inf), ((1, inf), inf), )) def test_length(self, number_range, length): assert IntInterval(number_range).length == length @mark.parametrize(('number_range', 'radius'), ( ([1, 4], 1.5), ([-1, 1], 1.0), ([-4, -1], 1.5), ((-inf, inf), inf), ((1, inf), inf), )) def test_radius(self, number_range, radius): assert IntInterval(number_range).radius == radius @mark.parametrize(('number_range', 'centre'), ( ([1, 4], 2.5), ([-1, 1], 0), ([-4, -1], -2.5), ((1, inf), inf), )) def test_centre(self, number_range, centre): assert IntInterval(number_range).centre == centre @mark.parametrize(('number_range', 'is_open'), (((2, 3), True), ('(2, 5)', True), ('[3, 4)', False), ('(4, 5]', False), ('3 - 4', False), ([4, 5], False), ('[4, 5]', False))) def test_open(self, number_range, is_open): assert IntInterval(number_range).open == is_open @mark.parametrize( ('number_range', 'is_closed'), (((2, 3), False), ('(2, 5)', False), ('[3, 4)', False), ('(4, 5]', False), ('3 - 4', True), ([4, 5], True), ('[4, 5]', True))) def test_closed(self, number_range, is_closed): assert IntInterval(number_range).closed == is_closed @mark.parametrize(('number_range', 'empty'), ( ((2, 3), True), ([2, 3], False), ([2, 2], False), ((2, 2), True), ('[2, 2)', True), ('(2, 2]', True), ('[2, 3)', False), ((2, 10), False), )) def test_empty(self, number_range, empty): assert IntInterval(number_range).empty == empty @mark.parametrize(('number_range', 'degenerate'), ( ((2, 4), False), ('(2, 2)', True), ('[0, 0)', True), )) def test_degenerate(self, number_range, degenerate): assert IntInterval(number_range).degenerate == degenerate @mark.parametrize( ('interval', 'discrete'), ((IntInterval((2, 3)), True), (IntInterval(5), True), (FloatInterval(3.5), False), (DecimalInterval(Decimal('2.4')), False), (DateTimeInterval(datetime(2002, 1, 1)), False), (DateInterval(date(2002, 1, 1)), True))) def test_discrete(self, interval, discrete): assert interval.discrete == discrete