Exemplo n.º 1
0
def _day_intervals(starttime, endtime):
    interval = stime.TimeRange(starttime, endtime)
    daylist = interval.get_dates()
    intervallist = [
        stime.TimeRange(t, t + dt.timedelta(days=1)) for t in daylist
    ]
    return intervallist
Exemplo n.º 2
0
def _year_intervals(starttime, endtime):
    intervallist = []
    for year in range(starttime.year, endtime.year + 1):
        intervallist.append(
            stime.TimeRange(dt.datetime(year, 1, 1),
                            dt.datetime(year + 1, 1, 1)))
    return intervallist
Exemplo n.º 3
0
    def intervals(self, starttime, endtime):
        base_url = ('http://soar.esac.esa.int/soar-sl-tap/tap/'
                    'sync?REQUEST=doQuery&')
        begin_time = time.parse_time(starttime).isot.replace('T', '+')
        end_time = time.parse_time(endtime).isot.replace('T', '+')
        # Need to manually set the intervals based on a query
        request_dict = {}
        request_dict['LANG'] = 'ADQL'
        request_dict['FORMAT'] = 'json'

        query = {}
        query['SELECT'] = '*'
        if self.product_type == 'LOW_LATENCY':
            query['FROM'] = 'v_ll_data_item'
        else:
            query['FROM'] = 'v_sc_data_item'
        query['WHERE'] = (f"descriptor='{self.descriptor}'+AND+"
                          f"level='{self.level}'+AND+"
                          f"begin_time<='{end_time}'+AND+"
                          f"end_time>='{begin_time}'")
        request_dict['QUERY'] = '+'.join(
            [f'{item}+{query[item]}' for item in query])

        request_str = ''
        request_str = [f'{item}={request_dict[item]}' for item in request_dict]
        request_str = '&'.join(request_str)

        url = base_url + request_str
        # Get request info
        r = requests.get(url)
        # TODO: intelligently detect and error on a bad descriptor

        # Do some list/dict wrangling
        names = [m['name'] for m in r.json()['metadata']]
        info = {name: [] for name in names}
        for entry in r.json()['data']:
            for i, name in enumerate(names):
                info[name].append(entry[i])

        # Setup intervals
        intervals = []
        for start, end in zip(info['begin_time'], info['end_time']):
            intervals.append(time.TimeRange(start, end))

        if len(intervals) == 0:
            raise RuntimeError(f'No data files found for '
                               f'descriptor={self.descriptor}, '
                               f'start_time={begin_time}, '
                               f'end_time={end_time}.')

        self.file_ids = {
            interval.start.isot: id
            for interval, id in zip(intervals, info['data_item_id'])
        }
        # TODO: log the number of intervals found here
        return intervals