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
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
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
def add_headers_to_obs_by_blueprint(obs, headers, blueprint, uri, product_id): """ Common code that puts together knowledge of the blueprint and the FitsParser to add information to an Observation. :param obs Observation to be added to :param headers astropy FITS headers with in-coming metadata :param blueprint caom2utils.ObsBlueprint instance to map from the metadata to the CAOM structure :param uri Artifact URI to add to Observation instance :param product_id Plane identifier, to know which plane to add """ parser = FitsParser(headers, blueprint, uri) parser.augment_observation(obs, uri, product_id) # re-home the chunk information to be consistent with accepted CAOM # patterns of part/chunk relationship - i.e. part 0 never has chunks # if the file being represented has extensions. This # relationship gets missed when only using the headers[1:], so # shift all the chunks up by one, and set the 0th to no chunks for plane in obs.planes.values(): if plane.product_id != product_id: continue for artifact in plane.artifacts.values(): if artifact.uri == uri and len(artifact.parts) > 1: first_index = None prev_chunks = None for key, value in artifact.parts.items(): if first_index is None: first_index = key prev_chunks = value.chunks continue else: temp = value.chunks value.chunks = prev_chunks prev_chunks = temp artifact.parts['0'].chunks = TypedList(Chunk, )