コード例 #1
0
def test_augment_observation(test_file, test_file_uri):
    test_fitsparser = FitsParser(test_file)
    test_obs = Observation('collection', 'observation_id',
                           Algorithm('algorithm'))
    test_fitsparser.augment_observation(test_obs, test_file_uri)
    assert test_obs is not None
    assert test_obs.planes is not None
    assert len(test_obs.planes) == 1
    test_plane = test_obs.planes['HI-line']
    assert test_plane.artifacts is not None
    assert len(test_plane.artifacts) == 1
    test_artifact = test_plane.artifacts[test_file_uri]
    assert test_artifact is not None
    test_part = test_artifact.parts['0']
    # remove the chunk bit, as it's part of other tests -
    # results in <caom2:chunks/> xml output
    test_part.chunks.pop()
    # set the ids to expected values
    test_obs._id = uuid.UUID('00000000000000001234567812345678')
    test_plane._id = uuid.UUID('00000000000000001234567812345678')
    test_artifact._id = uuid.UUID('00000000000000001234567812345678')
    test_part._id = uuid.UUID('00000000000000001234567812345678')
    output = BytesIO()
    ow = ObservationWriter(False, False, "caom2",
                           obs_reader_writer.CAOM20_NAMESPACE)
    ow.write(test_obs, output)
    result = output.getvalue().decode('UTF-8')
    output.close()
    assert result == EXPECTED_OBS_XML  # , result
コード例 #2
0
 def get(self, id):
     obs = _get_resource(get_observation, id=id)
     if not isinstance(obs, Observation):
         logger.info("Type of obs is {}".format(type(obs)))
         return obs
     writer = ObservationWriter(True)
     output = BytesIO()
     writer.write(obs, output)
     return output.getvalue().decode('utf-8')
コード例 #3
0
ファイル: app.py プロジェクト: SharonGoliath/gemHarvest2Caom2
 def get(self, id):
     logger.debug("get observation")
     obs = get_observation(id)
     if not obs:
         return 'Observation {}/{} not found'.format(COLLECTION, id), 404
     writer = ObservationWriter(True)
     output = BytesIO()
     writer.write(obs, output)
     return output.getvalue().decode('utf-8')
コード例 #4
0
def test_augment_observation():
    test_obs_blueprint = ObsBlueprint(position_axes=(1, 2))
    test_obs_blueprint.set('Observation.target.name', 'CGPS Mosaic MA1')
    test_obs_blueprint.set('Observation.target.standard', False)
    test_obs_blueprint.set('Observation.telescope.name', 'DRAO-ST')
    test_obs_blueprint.set('Observation.instrument.name', 'DRAO-ST')
    test_obs_blueprint.set('Observation.telescope.geoLocationX',
                           '-2100330.87517')
    test_obs_blueprint.set('Observation.telescope.geoLocationY',
                           '-3694247.82445')
    test_obs_blueprint.set('Observation.telescope.geoLocationZ',
                           '4741018.33097')

    test_obs_blueprint.set('Plane.dataProductType', 'cube')
    test_obs_blueprint.set('Artifact.productType', 'info')
    test_obs_blueprint.set('Artifact.releaseType', 'data')
    test_obs_blueprint.set('Plane.calibrationLevel', '2')
    test_fitsparser = FitsParser(sample_file_4axes_obs, test_obs_blueprint)
    test_fitsparser.blueprint = test_obs_blueprint
    test_obs = SimpleObservation('collection', 'MA1_DRAO-ST',
                                 Algorithm('exposure'))
    test_fitsparser.augment_observation(test_obs,
                                        sample_file_4axes_uri,
                                        product_id='HI-line')
    assert test_obs is not None
    assert test_obs.planes is not None
    assert len(test_obs.planes) == 1
    test_plane = test_obs.planes['HI-line']
    assert test_plane.artifacts is not None
    assert len(test_plane.artifacts) == 1
    test_artifact = test_plane.artifacts[sample_file_4axes_uri]
    assert test_artifact is not None
    test_part = test_artifact.parts['0']
    # remove the chunk bit, as it's part of other tests -
    # results in <caom2:chunks/> xml output
    test_part.chunks.pop()
    output = BytesIO()
    ow = ObservationWriter(False, False, "caom2",
                           obs_reader_writer.CAOM20_NAMESPACE)
    ow.write(test_obs, output)
    result = output.getvalue().decode('UTF-8')
    output.close()
    expected = _get_obs(EXPECTED_OBS_XML)
    actual = _get_obs(result)
    diff_result = get_differences(expected, actual, 'Observation')
    assert diff_result is None
コード例 #5
0
ファイル: test_fits2caom2.py プロジェクト: hjeeves/caom2tools
def test_augment_polarization(test_file):
    test_fitsparser = FitsParser(test_file, ObsBlueprint(polarization_axis=1))
    artifact = Artifact('ad:{}/{}'.format('TEST', test_file),
                        ProductType.SCIENCE, ReleaseType.DATA)
    test_fitsparser.augment_artifact(artifact)
    polarization = artifact.parts['0'].chunks[0].polarization
    check_xml(ObservationWriter()._add_polarization_wcs_element, polarization,
              EXPECTED_POLARIZATION_XML)
コード例 #6
0
def test_augment_energy(test_file):
    test_fitsparser = FitsParser(test_file)
    artifact = Artifact('ad:{}/{}'.format('TEST', test_file),
                        ProductType.SCIENCE, ReleaseType.DATA)
    test_fitsparser.augment_artifact(artifact)
    energy = artifact.parts['0'].chunks[0].energy
    energy.bandpassName = '21 cm'  # user set attribute
    check_xml(ObservationWriter()._add_spectral_wcs_element, energy,
              EXPECTED_ENERGY_XML)
コード例 #7
0
ファイル: test_fits2caom2.py プロジェクト: hjeeves/caom2tools
def test_augment_observation(test_file, test_file_uri):
    # logging.basicConfig(level=logging.DEBUG, stream=sys.stdout)
    test_obs_blueprint = ObsBlueprint(position_axis=(1, 2))
    test_obs_blueprint.set('Observation.target.name', 'CGPS Mosaic MA1')
    test_obs_blueprint.set('Observation.telescope.name', 'DRAO-ST')
    test_obs_blueprint.set('Observation.instrument.name', 'DRAO-ST')
    test_obs_blueprint.set('Observation.telescope.geoLocationX',
                           '-2100330.87517')
    test_obs_blueprint.set('Observation.telescope.geoLocationY',
                           '-3694247.82445')
    test_obs_blueprint.set('Observation.telescope.geoLocationZ',
                           '4741018.33097')

    test_obs_blueprint.set('Plane.dataProductType', 'cube')
    test_obs_blueprint.set('Plane.calibrationLevel', '2')
    test_fitsparser = FitsParser(test_file, test_obs_blueprint)
    test_fitsparser.blueprint = test_obs_blueprint
    test_obs = Observation('collection', 'MA1_DRAO-ST', Algorithm('exposure'))
    test_fitsparser.augment_observation(test_obs,
                                        test_file_uri,
                                        product_id='HI-line')
    assert test_obs is not None
    assert test_obs.planes is not None
    assert len(test_obs.planes) == 1
    test_plane = test_obs.planes['HI-line']
    assert test_plane.artifacts is not None
    assert len(test_plane.artifacts) == 1
    test_artifact = test_plane.artifacts[test_file_uri]
    assert test_artifact is not None
    test_part = test_artifact.parts['0']
    # remove the chunk bit, as it's part of other tests -
    # results in <caom2:chunks/> xml output
    test_part.chunks.pop()
    output = BytesIO()
    ow = ObservationWriter(False, False, "caom2",
                           obs_reader_writer.CAOM20_NAMESPACE)
    ow.write(test_obs, output)
    result = output.getvalue().decode('UTF-8')
    output.close()
    compare = re.sub(r'caom2:id=".*"', 'caom2:id=""', result)
    assert compare == EXPECTED_OBS_XML  # , result
コード例 #8
0
ファイル: test_fits2caom2.py プロジェクト: hjeeves/caom2tools
def test_augment_artifact_time(test_file, expected):
    test_fitsparser = FitsParser(test_file, ObsBlueprint(time_axis=1))
    artifact = Artifact('ad:{}/{}'.format('TEST', test_file),
                        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
    check_xml(ObservationWriter()._add_temporal_wcs_element, test_chunk.time,
              expected)
コード例 #9
0
ファイル: test_fits2caom2.py プロジェクト: hjeeves/caom2tools
def test_augment_artifact(test_file):
    test_fitsparser = FitsParser(test_file, ObsBlueprint(position_axis=(1, 2)))
    artifact = Artifact('ad:{}/{}'.format('TEST', test_file),
                        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
    check_xml(ObservationWriter()._add_spatial_wcs_element,
              test_chunk.position, EXPECTED_POSITION_XML)
コード例 #10
0
def write_obs_to_file(obs, fqn):
    """Common code to write a CAOM Observation to a file."""
    ow = ObservationWriter()
    ow.write(obs, fqn)
コード例 #11
0
def _write_observation(obs):
    writer = ObservationWriter(True, False, 'caom2',
                               'http://www.opencadc.org/caom2/xml/v2.3')
    writer.write(obs, './x.xml')
コード例 #12
0
ファイル: test_collections.py プロジェクト: opencadc/caom2eng
def _write_observation(obs):
    writer = ObservationWriter(True, False, 'caom2',
                               'http://www.opencadc.org/caom2/xml/v2.3')
    writer.write(obs, './x.xml')