Beispiel #1
0
    def _get_observations(self,
                          collection,
                          start=None,
                          end=None,
                          obs_file=None):
        """
        Returns a list of observations from the collection
        :param collection: name of the collection
        :param start: earliest observation
        :param end: latest observation
        :return: list of observation ids
        """
        assert collection is not None
        observations = []
        params = {'MAXREC': BATCH_SIZE}
        if start is not None:
            params['START'] = util.date2ivoa(start)
        if end is not None:
            params['END'] = util.date2ivoa(end)

        response = self._repo_client.get(
            (CAOM2REPO_OBS_CAPABILITY_ID, collection), params=params)
        last_datetime = None
        for line in response.text.splitlines():
            columns = line.split('\t')
            if len(columns) >= 3:
                obs = columns[1]
                last_datetime = columns[2]
                observations.append(obs)
            else:
                self.logger.warn('Incomplete listing line: {}'.format(line))
        if last_datetime is not None:
            self._start = util.str2ivoa(last_datetime)
        return observations
Beispiel #2
0
def list_observations(start=None, end=None, maxrec=None):
    """
    List observations based on their observation dates. It implements the
    functionality required by the base proxy docker image for listing ALMA
    observations
    :param start: start observation date (UTC)
    :param end: end observation date (UTC)
    :param maxrec: maximum number of rows to return
    :return: Comma separated list, each row consisting of ObservationID,
    observation date.
    """

    where = ''
    if start or end:
        if start:
            where = 'WHERE t_min>={}'.format(AstropyTime(start).mjd)
            if end:
                where += ' AND t_min<={}'.format(AstropyTime(end).mjd)
        else:
            where = 'WHERE t_min<={}'.format(AstropyTime(end).mjd)
    top = ''

    if maxrec:
        if int(maxrec) < 1:
            raise AttributeError('maxrec must be positive integer')
        top = 'TOP {}'.format(maxrec)
    query = "SELECT {} obs_id, min(t_min) AS obsTime " \
            "FROM ivoa.obscore {} GROUP BY obs_id ORDER by obsTime".\
        format(top, where)
    response = requests.get(ALMA_TAP_SYNC_URL,
                            params={
                                'QUERY': query,
                                'LANG': 'ADQL'
                            })
    response.raise_for_status()
    temp = BytesIO(response.content)
    obs_ids = parse_single_table(temp)

    result = []
    for r in obs_ids.array:
        obsID = _to_obs_id(r[0].decode('ascii'))
        timestamp = date2ivoa(AstropyTime(r[1], format='mjd').datetime)
        result.append('{}\t{}\t{}\n'.format(COLLECTION, obsID, timestamp))

    return result