示例#1
0
def test_clean_headers():
    test_input = """ilename: S20141130S0001.fits.bz2

AstroData Tags: {'CAL', 'RAW', 'AT_ZENITH', 'SOUTH', 'AZEL_TARGET', 'UNPREPARED', 'DARK', 'F2', 'NON_SIDEREAL', 'GEMINI'}


--- PHU ---
SIMPLE  =                    T / file does conform to FITS standard
BITPIX  =                   16 / number of bits per data pixel
NAXIS   =                    0 / number of data axes
EXTEND  =                    T / FITS dataset may contain extensions
COMMENT   FITS (Flexible Image Transport System) format is defined in 'Astronomy
COMMENT   and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H

--- HDU 0 ---
XTENSION= 'IMAGE   '           / IMAGE extension
BITPIX  =                   32 / number of bits per data pixel
NAXIS   =                    3 / number of data axes
NAXIS1  =                 2048 / length of data axis 1
NAXIS2  =                 2048 / length of data axis 2
NAXIS3  =                    1 / length of data axis 3
    """
    test_result = data_util.make_headers_from_string(test_input)
    assert test_result is not None, 'expect a result'
    assert len(test_result) == 2, 'expect two headers'
示例#2
0
 def _get_vos_headers(uri, subject=None):
     if uri.startswith('vos'):
         fname = data_files_parameter.split()[1].strip()
         fits_header = open(fname).read()
         return data_util.make_headers_from_string(fits_header)
     else:
         return None
示例#3
0
def _get_headers_mock(uri_ignore):
    x = """SIMPLE  =                    T   / Written by IDL:  Fri Oct  6 01:48:35 2017
BITPIX  =                  -32   / Bits per pixel
NAXIS   =                    2   / Number of dimensions
NAXIS1  =                 2048   /
NAXIS2  =                 2048   /
DATATYPE= 'REDUC   '             /Data type, SCIENCE/CALIB/REJECT/FOCUS/TEST
DATALAB = 'GN-2014A-Q-85-16-013' /
END
"""
    y = data_util.make_headers_from_string(x)
    return y
示例#4
0
def retrieve_headers(source_name, logger, session):
    logger.debug(f'Begin retrieve_headers for {source_name}')
    header_url = f'{HEADER_URL}{source_name}.fits'
    # Open the URL and fetch the JSON document for the observation
    response = None
    try:
        response = session.get(header_url, timeout=20)
        response.raise_for_status()
        headers = data_util.make_headers_from_string(response.text)
    finally:
        if response is not None:
            response.close()
    logger.debug(f'End retrieve_headers')
    return headers
示例#5
0
 def _header(fqn):
     # during operation, want to use astropy on FITS files
     # but during testing want to use headers and built-in Python file
     # operations
     from urllib.parse import urlparse
     from astropy.io import fits
     file_uri = urlparse(fqn)
     try:
         fits_header = open(file_uri.path).read()
         headers = data_util.make_headers_from_string(fits_header)
     except UnicodeDecodeError:
         hdulist = fits.open(fqn, memmap=True, lazy_load_hdus=True)
         hdulist.verify('fix')
         hdulist.close()
         headers = [h.header for h in hdulist]
     return headers
示例#6
0
def test_builder(dmf_mock, vos_mock):

    test_config = mc.Config()
    test_config.proxy_fqn = (f'{test_main_app.TEST_DATA_DIR}/test_proxy.pem')
    test_config.task_types = [mc.TaskType.VISIT]
    test_id = 'ctfbrsnN20140428S0086'
    test_f_name = f'{test_id}.fits'

    dmf_mock._check_caom2.side_effect = [
        em.DefiningMetadata('GNIRS', 'TEST_DATA_LABEL'),
        em.DefiningMetadata('GNIRS', 'TEST_DATA_LABEL'),
    ]
    x = """SIMPLE  =                    T / Written by IDL:  Fri Oct  6 01:48:35 2017
BITPIX  =                  -32 / Bits per pixel
NAXIS   =                    2 / Number of dimensions
NAXIS1  =                 2048 /
NAXIS2  =                 2048 /
DATALAB = 'TEST_DATA_LABEL'
INSTRUME= 'GNIRS'
DATATYPE= 'REDUC   '           /Data type, SCIENCE/CALIB/REJECT/FOCUS/TEST
END
"""
    y = data_util.make_headers_from_string(x)
    vos_mock.return_value = y

    test_subject = builder.GemProcBuilder(test_config)
    for entry in [
            test_f_name,
            f'vos:goliaths/tests/{test_f_name}',
            f'/tmp/{test_f_name}',
    ]:
        test_sn = test_subject.build(entry)
        assert test_sn.file_uri == f'cadc:GEMINICADC/{test_f_name}'
        assert test_sn.lineage == f'{test_id}/cadc:GEMINICADC/{test_f_name}'
        assert test_sn.prev == f'{test_id}.jpg'
        assert test_sn.thumb == f'{test_id}_th.jpg'
        assert test_sn.prev_uri == f'cadc:GEMINICADC/{test_id}.jpg'
        assert test_sn.thumb_uri == f'cadc:GEMINICADC/{test_id}_th.jpg'
        assert (test_sn.destination_uris == [
            'cadc:GEMINICADC/ctfbrsnN20140428S0086.fits'
        ]), f'wrong destination uris for {entry}'
        assert test_sn.obs_id == 'TEST_DATA_LABEL', f'wrong obs_id for {entry}'
        assert test_sn._source_names[0] == entry, 'wrong source name'