def test_repair_provenance():
    if em.gofr is None:
        em.gofr = GemObsFileRelationship(TEST_FILE)
    for ii in test_subjects:
        ignore, test_fid = _repair_provenance_value(ii[1], 'test obs')
        assert test_fid is not None, 'failed lookup {}'.format(ii)
        assert test_fid == ii[0], 'error {}'.format(ii[1])
def test_mixed_case_file_names():
    mixed_case_f_names_order_1 = os.path.join(gem_mocks.TEST_DATA_DIR,
                                              'mixed_case_1.txt')
    mixed_case_f_names_order_2 = os.path.join(gem_mocks.TEST_DATA_DIR,
                                              'mixed_case_2.txt')
    test_obs_id = 'GN-CAL20100415-6-086-BIAS'
    test_file_id = 'N20100415S0452_bias'

    for f_name in [mixed_case_f_names_order_1, mixed_case_f_names_order_2]:
        import shutil
        shutil.copy(f_name, '/app/data/from_paul.txt')
        test_subject = GemObsFileRelationship()

        result_obs_id = test_subject.get_obs_id(test_file_id)
        assert result_obs_id is not None, 'expected result {}'.format(f_name)
        assert result_obs_id == test_obs_id, 'wrong result {}'.format(f_name)

        test_timestamp = test_subject.get_timestamp(test_file_id)
        assert test_timestamp is not None, 'expected result {}'.format(f_name)
        assert test_timestamp == 1498316473.885391, 'wrong timestamp'

        result_file_names = test_subject.get_file_names(test_obs_id)
        assert result_file_names is not None, 'expected result {}'.format(
            f_name)
        assert len(result_file_names) == 1, 'wrong size result {}'.format(
            f_name)
        assert result_file_names[0] == '{}.fits'.format(test_file_id), \
            'wrong result {} {}'.format(f_name, result_file_names)
Пример #3
0
def list_observations(start=None, end=None, maxrec=None):
    """
    List observations
    :param start: start date (UTC)
    :param end: end date (UTC)
    :param maxrec: maximum number of rows to return
    :return: Comma separated list, each row consisting of ObservationID,
    last mod date.

    NOTE: For stream the results use a generator, e.g:
        for i in range(3):
        yield "{}\n".format(datetime.datetime.now().isoformat())
        time.sleep(1)

    The results of this query come from a file supplied by Gemini
    approximately once every six months. That file is located on this
    container. It's read in and re-formatted into the information required
    to support this endpoint query.
    """

    if em.gofr is None:
        em.gofr = GemObsFileRelationship('/app/data/from_paul.txt')

    temp = em.gofr.subset(start, end, maxrec)
    for ii in temp:
        yield '{}\n'.format(ii)
def test_subset_all():
    gofr = GemObsFileRelationship(TEST_FILE)
    temp = gofr.subset()
    assert temp is not None, 'should have content'
    assert temp[0].startswith(
        'GEMINI GN-CAL20170616-11-022 2017-06-19T03:21:29.345'), \
        'wrong content'
    assert len(list(temp)) == 513, 'wrong count'
    result = gofr.get_file_names('GN-2015B-Q-1-12-1003')
    assert result == \
           ['N20150807G0044m.fits', 'N20150807G0044i.fits',
            'N20150807G0044.fits'], \
        'entry missing {}'.format(result)
def test_repair_data_label():
    if em.gofr is None:
        em.gofr = GemObsFileRelationship(TEST_FILE)
    for ii in test_main_app.LOOKUP:
        test_result = em.gofr.repair_data_label(ii)
        if ii == 'S20181230S0026':
            assert test_result == 'S20181230S0026', \
                'repair failed for {} actual {} expected {}'.format(
                    ii, test_result, test_main_app.LOOKUP[ii][0])
        else:
            assert test_result == test_main_app.LOOKUP[ii][0], \
                'repair failed for {} actual {} expected {}'.format(
                    ii, test_result, test_main_app.LOOKUP[ii][0])
    test_result = em.gofr.repair_data_label('N20181217S0266')
    assert test_result is not None, 'no result'
    assert test_result == 'GN-2018B-Q-133-20-001', 'wrong result'
def test_subset_only_end():
    end = datetime.strptime('2018-12-16T18:12:26.16614', ISO_DATE)
    gofr = GemObsFileRelationship(TEST_FILE)
    temp = gofr.subset(end=end)
    assert temp is not None, 'should have content'
    assert temp[0].startswith(
        'GEMINI GN-CAL20170616-11-022 2017-06-19T03:21:29.345'), \
        'wrong content'
    assert len(list(temp)) == 416, 'wrong count'

    temp = gofr.subset(end=end, maxrec=3)
    assert temp is not None, 'should have content'
    assert temp[0].startswith(
        'GEMINI GN-CAL20170616-11-022 2017-06-19T03:21:29.345'), \
        'wrong content'
    assert len(list(temp)) == 3, 'wrong maxrec count'
def test_subset_only_start():
    start = datetime.strptime('2018-12-16T03:47:03.939488', ISO_DATE)
    gofr = GemObsFileRelationship(TEST_FILE)
    temp = gofr.subset(start=start)
    assert temp is not None, 'should have content'
    assert temp[0].startswith(
        'GEMINI GN-2018B-FT-113-24-015 2018-12-17T18:08:29.362'), \
        'wrong content'
    assert len(list(temp)) == 97, 'wrong count'

    temp = gofr.subset(start=start, maxrec=3)
    assert temp is not None, 'should have content'
    assert temp[0].startswith(
        'GEMINI GN-2018B-FT-113-24-015 2018-12-17T18:08:29.362'), \
        'wrong content'
    assert len(list(temp)) == 3, 'wrong maxrec count'
Пример #8
0
def get_observation(obs_id):
    """
    Return the observation corresponding to the obs_id
    :param obs_id: id of the observation
    :return: observation corresponding to the id or None if such
    such observation does not exist
    """

    if em.gofr is None:
        em.gofr = GemObsFileRelationship('/app/data/from_paul.txt')

    obs = _invoke_gem2caom2(obs_id)
    if obs is None:
        logger.error('Could not create observation for {}'.format(obs_id))
        return None
    return obs
def test_subset_start_end():
    start = datetime.strptime('2017-06-20T12:36:35.681662', ISO_DATE)
    end = datetime.strptime('2017-12-17T20:13:56.572387', ISO_DATE)
    test_subject = GemObsFileRelationship(TEST_FILE)
    temp = test_subject.subset(start=start, end=end)
    assert temp is not None, 'should have content'
    assert temp[0].startswith(
        'GEMINI GN-CAL20150925-2-007 2017-06-20T14:50:59.795'), \
        'wrong content'
    assert len(list(temp)) == 314, 'wrong count'

    temp = test_subject.subset(start=start, end=end, maxrec=3)
    assert temp is not None, 'should have content'
    assert temp[0].startswith(
        'GEMINI GN-CAL20150925-2-007 2017-06-20T14:50:59.795'), \
        'wrong content'
    assert len(list(temp)) == 3, 'wrong maxrec count'
def test_make_gem2caom2_args():
    gofr = GemObsFileRelationship('/app/data/from_paul.txt')

    for ii in x:
        test_result = gofr.get_args(ii)
        assert test_result is not None, 'no result'
        assert len(test_result) == len(x[ii]), \
            'wrong length for {}'.format(ii)
        for jj in test_result:
            found = False
            for kk in x[ii]:
                if jj.obs_id == kk.obs_id:
                    found = True
                    assert jj.lineage == kk.lineage, \
                        '{} lineage {} expected {}'.format(
                            jj.obs_id, jj.lineage, kk.lineage)
                    assert jj.urls == kk.urls, \
                        '{} urls {} expected {}'.format(jj.obs_id, jj.urls, kk.urls)
                    break
            assert found, 'new obs id {}'.format(jj.obs_id)
def test_get_timestamp():
    gofr = GemObsFileRelationship('/app/data/from_paul.txt')
    test_result = gofr.get_timestamp('ag2003feb19_6.0001')
    assert test_result is not None, 'no result'
    assert test_result == 1498571069.924588, 'wrong result'