def test_class_apply_defaults(override_file):
    ob = ObsBlueprint(position_axis=(1, 2),
                      energy_axis=3,
                      polarization_axis=4,
                      time_axis=5)
    usc = {
        'Plane.dataProductType': 'plane.dataProductType',
        'Plane.provenance.producer': 'provenance.producer',
        'Plane.provenance.project': 'provenance.project',
        'Plane.metaRelease': 'plane.metaRelease',
        'Plane.dataRelease': 'plane.dataRelease',
        'Plane.calibrationLevel': 'plane.calibrationLevel',
        'Observation.metaRelease': 'obs.metaRelease',
        'Observation.intent': 'obs.intent',
        'Observation.type': 'obs.type',
        'Observation.proposal.pi': 'proposal.pi',
        'Observation.proposal.project': 'proposal.project',
        'Observation.proposal.title': 'proposal.title',
        'Observation.sequenceNumber': 'obs.sequenceNumber',
        'Observation.target.standard': 'target.standard',
        'Artifact.productType': 'artifact.productType',
        'Chunk.time.resolution': 'time.resolution',
        'Chunk.time.exposure': 'time.exposure',
        'Chunk.energy.resolvingPower': 'resolvingPower',
        'Chunk.energy.bandpassName': 'filtername',
        'Artifact.contentChecksum': 'artifact.contentChecksum'
    }

    convert = ConvertFromJava(ob, usc)
    test_overrides = load_config(override_file)

    for key, value in test_overrides.items():
        try:
            # artifacts is a substructure to be dealt with separately,
            # WCSAXES should work .... ;)
            if key == 'artifacts' or key == 'WCSAXES':
                continue

            result = convert.get_caom2_elements(key)
            for r in result:
                ob._get(r)
        except ValueError:
            assert False, 'Could not find key {} in ObsBlueprint'.format(key)
def test_class_apply_defaults(override_file):
    ob = ObsBlueprint(position_axes=(1, 2), energy_axis=3,
                      polarization_axis=4, time_axis=5)
    usc = {'Plane.dataProductType': 'plane.dataProductType',
           'Plane.provenance.producer': 'provenance.producer',
           'Plane.provenance.project': 'provenance.project',
           'Plane.metaRelease': 'plane.metaRelease',
           'Plane.dataRelease': 'plane.dataRelease',
           'Plane.calibrationLevel': 'plane.calibrationLevel',
           'Observation.metaRelease': 'obs.metaRelease',
           'Observation.intent': 'obs.intent',
           'Observation.type': 'obs.type',
           'Observation.proposal.pi': 'proposal.pi',
           'Observation.proposal.project': 'proposal.project',
           'Observation.proposal.title': 'proposal.title',
           'Observation.sequenceNumber': 'obs.sequenceNumber',
           'Observation.target.standard': 'target.standard',
           'Artifact.productType': 'artifact.productType',
           'Chunk.time.resolution': 'time.resolution',
           'Chunk.time.exposure': 'time.exposure',
           'Chunk.energy.resolvingPower': 'resolvingPower',
           'Chunk.energy.bandpassName': 'filtername',
           'Artifact.contentChecksum': 'artifact.contentChecksum'
           }

    convert = ConvertFromJava(ob, usc)
    test_overrides = load_config(override_file)

    for key, value in test_overrides.items():
        try:
            # artifacts is a substructure to be dealt with separately,
            # WCSAXES should work .... ;)
            if key == 'artifacts' or key == 'WCSAXES':
                continue

            result = convert.get_caom2_elements(key)
            for r in result:
                ob._get(r)
        except ValueError:
            assert False, 'Could not find key {} in ObsBlueprint'.format(key)
Example #3
0
def test_load_config_overrides():
    # cool override file content
    result = load_config(override_file)
    assert result == TEST_OVERRIDES
Example #4
0
def test_update_fits_headers():
    # The rules for the values:
    # all upper case - a FITS keyword
    # has an '{' or an '}' - a FITS keyword with an index
    #
    # The rules for the keys:
    # has a '.' - a config keyword
    # all upper case - a FITS keyword

    hdr1 = fits.Header()
    hdr2 = fits.Header()
    hdr3 = fits.Header()
    hdr4 = fits.Header()
    hdr5 = fits.Header()
    hdr6 = fits.Header()
    hdr7 = fits.Header()
    test_blueprint = ObsBlueprint()
    test_blueprint.configure_time_axis(3)

    test_parser = FitsParser(src=[hdr1, hdr2, hdr3, hdr4, hdr5, hdr6, hdr7])

    test_uri = 'ad:CFHT/1709071g.fits.gz'
    update_blueprint(test_blueprint,
                     test_uri,
                     config={},
                     defaults={},
                     overrides={})
    assert test_parser.blueprint._get('Observation.type') == \
        (['OBSTYPE'], None), 'unmodified blueprint'

    test_defaults = {
        'CTYPE1': 'RA---TAN',
        'CTYPE2': 'DEC--TAN',
        'CTYPE3': 'TIME',
        'CTYPE4': 'WAVE',
        'CDELT4': '1.2',
        'CRVAL4': '32'
    }
    update_blueprint(test_blueprint,
                     test_uri,
                     config={},
                     defaults=test_defaults,
                     overrides={})
    assert test_blueprint._get('Chunk.position.axis.axis1.ctype') == \
        (['CTYPE1'], 'RA---TAN'), 'default value assigned'
    assert test_blueprint._get('Chunk.position.axis.axis2.ctype') == \
        (['CTYPE2'], 'DEC--TAN'), 'default value assigned'
    assert test_blueprint._get('Chunk.time.axis.axis.ctype') ==  \
        (['CTYPE3'], 'TIME'), 'default value assigned, value all upper case'

    # print(test_parser.blueprint)

    test_defaults = {
        'CTYPE1': 'RA--TAN',
        'CTYPE2': 'DEC--TAN',
        'CTYPE3': 'TIME',
        'plane.dataProductType': 'image',
        'provenance.producer': 'CFHT',
        'provenance.project': 'STANDARD PIPELINE'
    }
    test_config = load_config(java_config_file)
    test_overrides = load_config(override_file)
    update_blueprint(test_blueprint, test_uri, test_config, test_defaults,
                     test_overrides)
    assert test_blueprint._get('Plane.dataProductType') == \
        'image', 'default value assigned to configuration'
    assert test_blueprint._get('Plane.provenance.producer') == \
        (['ORIGIN'], 'CFHT'), \
        'default value assigned to configuration, all upper-case'
    assert test_blueprint._get('Plane.provenance.project') == \
        (['ADC_ARCH'], 'STANDARD PIPELINE'), \
        'default value assigned to configuration, with white-space'
    assert test_blueprint._get('Observation.type') == 'OBJECT', \
        'default value over-ridden, value all upper case'
    assert test_blueprint._get(
        'Chunk.position.axis.function.refCoord.coord1.val',
        0) == '210.551666667', 'override HDU 0'
    assert test_blueprint._get(
        'Chunk.position.axis.function.refCoord.coord1.val', 1) == \
        '210.551666667',         'override HDU 1'
    assert test_blueprint._get(
        'Chunk.position.axis.function.refCoord.coord1.val',
        2) == '210.508333333', 'override HDU 2'
    assert test_blueprint._get(
        'Chunk.position.axis.function.refCoord.coord1.val',
        3) == '210.898333333', 'override HDU 3'
    assert test_blueprint._get(
        'Chunk.position.axis.function.refCoord.coord1.val',
        4) == '210.942083333', 'override HDU 4'
    assert test_blueprint._get(
        'Chunk.position.axis.function.refCoord.coord1.val',
        5) == '0.000000000', 'override HDU 5'

    test_parser.blueprint = test_blueprint
    assert test_parser._headers[0]['CRVAL1'] == 210.551666667, 'override HDU 0'
    assert test_parser._headers[1]['CRVAL1'] == 210.551666667, 'override HDU 1'
    assert test_parser._headers[2]['CRVAL1'] == 210.508333333, 'override HDU 2'
    assert test_parser._headers[3]['CRVAL1'] == 210.898333333, 'override HDU 3'
    assert test_parser._headers[4]['CRVAL1'] == 210.942083333, 'override HDU 4'
    assert test_parser._headers[5]['CRVAL1'] == 0.000000000, 'override HDU 5'
    assert test_parser._headers[0][
        'CRVAL3'] == 56789.429806900000, 'override HDU 0'
    # this will fail because of CompositeObservation.members errors
    assert len(test_parser._errors) == 0, test_parser._errors