Exemple #1
0
def test_augment_artifact_position_from_blueprint():
    test_blueprint = ObsBlueprint(position_axes=(1, 2))
    test_blueprint.set('Chunk.positionAxis1', '1')
    test_blueprint.set('Chunk.positionAxis2', '2')
    test_blueprint.set('Chunk.position.axis.axis1.ctype', 'GLON-CAR')
    test_blueprint.set('Chunk.position.axis.axis1.cunit', 'deg')
    test_blueprint.set('Chunk.position.axis.axis2.ctype', 'GLAT-CAR')
    test_blueprint.set('Chunk.position.axis.axis2.cunit', 'deg')
    test_blueprint.set('Chunk.position.axis.function.cd11', '-0.004999999')
    test_blueprint.set('Chunk.position.axis.function.cd12', '0.0')
    test_blueprint.set('Chunk.position.axis.function.cd21', '0.0')
    test_blueprint.set('Chunk.position.axis.function.cd22', '0.004999999')
    test_blueprint.set('Chunk.position.axis.function.dimension.naxis1', '1')
    test_blueprint.set('Chunk.position.axis.function.dimension.naxis2', '1')
    test_blueprint.set('Chunk.position.axis.range.start.coord1.pix', '513.0')
    test_blueprint.set('Chunk.position.axis.range.start.coord1.val',
                       '128.7499990027')
    test_blueprint.set('Chunk.position.axis.range.start.coord2.pix', '513.0')
    test_blueprint.set('Chunk.position.axis.range.start.coord2.val',
                       '-0.9999999922536')
    test_fitsparser = FitsParser(sample_file_4axes,
                                 test_blueprint,
                                 uri='test_parser')
    test_chunk = Chunk()
    test_fitsparser._try_position_with_blueprint(test_chunk, 0)
    ex = _get_from_str_xml(EXPECTED_POSITION_XML,
                           ObservationReader()._get_spatial_wcs, 'position')
    result = get_differences(ex, test_chunk.position)
    assert result is None
Exemple #2
0
def test_augment_energy():
    bp = ObsBlueprint(energy_axis=1)
    test_fitsparser = FitsParser(sample_file_4axes, bp)
    artifact = Artifact('ad:{}/{}'.format('TEST', sample_file_4axes),
                        ProductType.SCIENCE, ReleaseType.DATA)
    test_fitsparser.augment_artifact(artifact)
    energy = artifact.parts['0'].chunks[0].energy
    ex = _get_from_str_xml(EXPECTED_ENERGY_XML,
                           ObservationReader()._get_spectral_wcs, 'energy')
    result = get_differences(ex, energy)
    assert result is None, repr(energy)
Exemple #3
0
def test_augment_polarization():
    test_fitsparser = FitsParser(sample_file_4axes,
                                 ObsBlueprint(polarization_axis=1))
    artifact = Artifact('ad:{}/{}'.format('TEST', sample_file_4axes),
                        ProductType.SCIENCE, ReleaseType.DATA)
    test_fitsparser.augment_artifact(artifact)
    polarization = artifact.parts['0'].chunks[0].polarization
    ex = _get_from_str_xml(EXPECTED_POLARIZATION_XML,
                           ObservationReader()._get_polarization_wcs,
                           'polarization')
    result = get_differences(ex, polarization)
    assert result is None, result
def test_compatibility():
    # tests a previously generated observation and validates the
    # entities, and the entities with children

    source_file_path = os.path.join(THIS_DIR, TEST_DATA,
                                    'SampleComposite-CAOM-2.3.xml')
    reader = ObservationReader(True)
    with open(source_file_path):
        obs = reader.read(source_file_path)

    # shallow validates first
    for plane in obs.planes.values():
        for artifact in plane.artifacts.values():
            for part in artifact.parts.values():
                for chunk in part.chunks:
                    validate(chunk, False)
                validate(part, False)
            validate(artifact, False)
        validate(plane, False)

    validate(obs, False)

    # deep validate
    validate(obs, True)
Exemple #5
0
def test_augment_artifact_time():
    test_fitsparser = FitsParser(sample_file_time_axes,
                                 ObsBlueprint(time_axis=1))
    artifact = Artifact('ad:{}/{}'.format('TEST', sample_file_time_axes),
                        ProductType.SCIENCE, ReleaseType.DATA)
    test_fitsparser.augment_artifact(artifact)
    assert artifact.parts is not None
    assert len(artifact.parts) == 6
    test_part = artifact.parts['1']
    test_chunk = test_part.chunks.pop()
    assert test_chunk is not None
    assert test_chunk.time is not None
    ex = _get_from_str_xml(EXPECTED_CFHT_WIRCAM_RAW_GUIDE_CUBE_TIME,
                           ObservationReader()._get_temporal_wcs, 'time')
    result = get_differences(ex, test_chunk.time)
    assert result is None
Exemple #6
0
def test_augment_artifact():
    test_blueprint = ObsBlueprint(position_axes=(1, 2))
    test_fitsparser = FitsParser(sample_file_4axes, test_blueprint)
    artifact = Artifact('ad:{}/{}'.format('TEST', sample_file_4axes),
                        ProductType.SCIENCE, ReleaseType.DATA)
    test_fitsparser.augment_artifact(artifact)
    assert artifact.parts is not None
    assert len(artifact.parts) == 1
    test_part = artifact.parts['0']
    test_chunk = test_part.chunks.pop()
    assert test_chunk is not None
    assert test_chunk.position is not None
    ex = _get_from_str_xml(EXPECTED_POSITION_XML,
                           ObservationReader()._get_spatial_wcs, 'position')
    result = get_differences(ex, test_chunk.position)
    assert result is None
Exemple #7
0
def test_augment_artifact_polarization_from_blueprint():
    test_blueprint = ObsBlueprint(polarization_axis=1)
    test_blueprint.set('Chunk.polarizationAxis', '1')
    test_blueprint.set('Chunk.polarization.axis.axis.ctype', 'STOKES')
    test_blueprint.set('Chunk.polarization.axis.function.refCoord.pix', '1.0')
    test_blueprint.set('Chunk.polarization.axis.function.refCoord.val', '1.0')
    test_blueprint.set('Chunk.polarization.axis.function.delta', '1.0')
    test_blueprint.set('Chunk.polarization.axis.function.naxis', '1')
    test_fitsparser = FitsParser(sample_file_4axes,
                                 test_blueprint,
                                 uri='test_parser')
    test_chunk = Chunk()
    test_fitsparser._try_polarization_with_blueprint(test_chunk, 0)
    ex = _get_from_str_xml(EXPECTED_POLARIZATION_XML,
                           ObservationReader()._get_polarization_wcs,
                           'polarization')
    result = get_differences(ex, test_chunk.polarization)
    assert result is None
Exemple #8
0
def test_augment_artifact_energy_from_blueprint():
    test_blueprint = ObsBlueprint(energy_axis=1)
    test_blueprint.set('Chunk.energyAxis', 1)
    test_blueprint.set('Chunk.energy.specsys', 'LSRK')
    test_blueprint.set('Chunk.energy.axis.axis.ctype', 'VRAD')
    test_blueprint.set('Chunk.energy.axis.axis.cunit', 'm / s')
    test_blueprint.set('Chunk.energy.axis.function.refCoord.pix', '145.0')
    test_blueprint.set('Chunk.energy.axis.function.refCoord.val', '-60000.0')
    test_blueprint.set('Chunk.energy.axis.function.delta', '-824.46002')
    test_blueprint.set('Chunk.energy.axis.function.naxis', '1')
    test_fitsparser = FitsParser(sample_file_4axes,
                                 test_blueprint,
                                 uri='ad:TEST/test_blueprint')
    test_chunk = Chunk()
    test_fitsparser._try_energy_with_blueprint(test_chunk, 0)
    ex = _get_from_str_xml(EXPECTED_ENERGY_XML,
                           ObservationReader()._get_spectral_wcs, 'energy')
    result = get_differences(ex, test_chunk.energy)
    assert result is None
Exemple #9
0
def test_augment_artifact_time_from_blueprint():
    test_blueprint = ObsBlueprint(time_axis=1)
    test_blueprint.set('Chunk.timeAxis', '1')
    test_blueprint.set('Chunk.time.exposure', '0.02')
    test_blueprint.set('Chunk.time.resolution', '0.02')
    test_blueprint.set('Chunk.time.timesys', 'UTC')
    test_blueprint.set('Chunk.time.axis.axis.ctype', 'TIME')
    test_blueprint.set('Chunk.time.axis.axis.cunit', 'd')
    test_blueprint.set('Chunk.time.axis.error.syser', '1e-07')
    test_blueprint.set('Chunk.time.axis.error.rnder', '1e-07')
    test_blueprint.set('Chunk.time.axis.function.refCoord.pix', '0.5')
    test_blueprint.set('Chunk.time.axis.function.refCoord.val',
                       '56789.4298069')
    test_blueprint.set('Chunk.time.axis.function.delta', '2.31481e-07')
    test_blueprint.set('Chunk.time.axis.function.naxis', '1')
    test_fitsparser = FitsParser(sample_file_4axes,
                                 test_blueprint,
                                 uri='ad:TEST/test_blueprint')
    test_chunk = Chunk()
    test_fitsparser._try_time_with_blueprint(test_chunk, 0)
    ex = _get_from_str_xml(EXPECTED_CFHT_WIRCAM_RAW_GUIDE_CUBE_TIME,
                           ObservationReader()._get_temporal_wcs, 'time')
    result = get_differences(ex, test_chunk.time)
    assert result is None
Exemple #10
0
def test_augment_artifact_bounds_range_from_blueprint():
    test_blueprint = ObsBlueprint(energy_axis=1,
                                  time_axis=2,
                                  polarization_axis=3,
                                  position_axes=(4, 5))
    test_blueprint.set('Chunk.energy.axis.range.start.pix', '145.0')
    test_blueprint.set('Chunk.energy.axis.range.start.val', '-60000.0')
    test_blueprint.set('Chunk.energy.axis.range.end.pix', '-824.46002')
    test_blueprint.set('Chunk.energy.axis.range.end.val', '1')
    test_blueprint.set('Chunk.time.axis.range.start.pix', '145.0')
    test_blueprint.set('Chunk.time.axis.range.start.val', '-60000.0')
    test_blueprint.set('Chunk.time.axis.range.end.pix', '-824.46002')
    test_blueprint.set('Chunk.time.axis.range.end.val', '1')
    test_blueprint.set('Chunk.polarization.axis.range.start.pix', '145.0')
    test_blueprint.set('Chunk.polarization.axis.range.start.val', '-60000.0')
    test_blueprint.set('Chunk.polarization.axis.range.end.pix', '-824.46002')
    test_blueprint.set('Chunk.polarization.axis.range.end.val', '1')
    test_blueprint.set('Chunk.position.axis.range.start.coord1.pix', '145.0')
    test_blueprint.set('Chunk.position.axis.range.start.coord1.val',
                       '-60000.0')
    test_blueprint.set('Chunk.position.axis.range.end.coord1.pix',
                       '-824.46002')
    test_blueprint.set('Chunk.position.axis.range.end.coord1.val', '1')
    test_blueprint.set('Chunk.position.axis.range.start.coord2.pix', '145.0')
    test_blueprint.set('Chunk.position.axis.range.start.coord2.val',
                       '-60000.0')
    test_blueprint.set('Chunk.position.axis.range.end.coord2.pix',
                       '-824.46002')
    test_blueprint.set('Chunk.position.axis.range.end.coord2.val', '1')
    test_fitsparser = FitsParser(sample_file_4axes,
                                 test_blueprint,
                                 uri='ad:TEST/test_blueprint')
    test_chunk = Chunk()
    test_chunk.energy = SpectralWCS(CoordAxis1D(Axis('WAVE', 'm')), 'TOPOCENT')
    test_chunk.time = TemporalWCS(CoordAxis1D(Axis('TIME', 'd')))
    test_chunk.polarization = PolarizationWCS(CoordAxis1D(Axis('STOKES')))
    test_chunk.position = SpatialWCS(
        CoordAxis2D(Axis('RA', 'deg'), Axis('DEC', 'deg')))
    test_fitsparser._try_range_with_blueprint(test_chunk, 0)

    assert test_chunk.energy.axis.range is not None, \
        'chunk.energy.axis.range should be declared'
    assert test_chunk.time.axis.range is not None, \
        'chunk.time.axis.range should be declared'
    assert test_chunk.polarization.axis.range is not None, \
        'chunk.polarization.axis.range should be declared'
    assert test_chunk.position.axis.range is not None, \
        'chunk.position.axis.range should be declared'
    ex = _get_from_str_xml(EXPECTED_ENERGY_RANGE_BOUNDS_XML,
                           ObservationReader()._get_spectral_wcs, 'energy')
    assert ex is not None, \
        'energy string from expected output should be declared'
    result = get_differences(ex, test_chunk.energy)
    assert result is None

    ex = _get_from_str_xml(EXPECTED_TIME_RANGE_BOUNDS_XML,
                           ObservationReader()._get_temporal_wcs, 'time')
    assert ex is not None, \
        'time string from expected output should be declared'
    result = get_differences(ex, test_chunk.time)
    assert result is None

    ex = _get_from_str_xml(EXPECTED_POL_RANGE_BOUNDS_XML,
                           ObservationReader()._get_polarization_wcs,
                           'polarization')
    assert ex is not None, \
        'polarization string from expected output should be declared'
    result = get_differences(ex, test_chunk.polarization)
    assert result is None

    ex = _get_from_str_xml(EXPECTED_POS_RANGE_BOUNDS_XML,
                           ObservationReader()._get_spatial_wcs, 'position')
    assert ex is not None, \
        'position string from expected output should be declared'
    result = get_differences(ex, test_chunk.position)
    assert result is None
def read_obs_from_file(fqn):
    """Common code to read a CAOM Observation from a file."""
    if not os.path.exists(fqn):
        raise CadcException('Could not find {}'.format(fqn))
    reader = ObservationReader(False)
    return reader.read(fqn)
Exemple #12
0
def _read_obs(fname):
    assert os.path.exists(fname)
    reader = ObservationReader(False)
    result = reader.read(fname)
    return result
Exemple #13
0
def _read_observation(fname):
    reader = ObservationReader(False)
    result = reader.read(fname)
    return result
Exemple #14
0
def _read_observation(fname):
    reader = ObservationReader(False)
    result = reader.read(fname)
    return result