Exemplo n.º 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
Exemplo n.º 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')
Exemplo n.º 3
0
 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')
Exemplo n.º 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
Exemplo n.º 5
0
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
Exemplo n.º 6
0
def write_obs_to_file(obs, fqn):
    """Common code to write a CAOM Observation to a file."""
    ow = ObservationWriter()
    ow.write(obs, fqn)
Exemplo n.º 7
0
def _write_observation(obs):
    writer = ObservationWriter(True, False, 'caom2',
                               'http://www.opencadc.org/caom2/xml/v2.3')
    writer.write(obs, './x.xml')
Exemplo n.º 8
0
def _write_observation(obs):
    writer = ObservationWriter(True, False, 'caom2',
                               'http://www.opencadc.org/caom2/xml/v2.3')
    writer.write(obs, './x.xml')