def _build_chunk_position(chunk, headers, obs_id): # DB 18-08-19 # Ignoring rotation for now: Use CRVAL1 = RA from header, CRVAL2 = DEC # from header. NAXIS1/NAXIS2 values gives number of pixels along RA/DEC # axes (again, ignoring rotation) and assume CRPIX1 = NAXIS1/2.0 and # CRPIX2 = NAXIS2/2.0 (i.e. in centre of image). XBINNING/YBINNING # give binning values along RA/DEC axes. CDELT1 (scale in # degrees/pixel; it’s 3 arcsec/unbinned pixel)= 3.0*XBINNING/3600.0 # CDELT2 = 3.0*YBINNING/3600.0. Set CROTA2=0.0 header = headers[0] ra = get_ra(header) dec = get_dec(header) if ra is None or dec is None: logging.warning(f'No position information for {obs_id}') chunk.naxis = None else: header['CTYPE1'] = 'RA---TAN' header['CTYPE2'] = 'DEC--TAN' header['CUNIT1'] = 'deg' header['CUNIT2'] = 'deg' header['CRVAL1'] = ra header['CRVAL2'] = dec header['CRPIX1'] = get_position_axis_function_naxis1(header) header['CRPIX2'] = get_position_axis_function_naxis2(header) wcs_parser = WcsParser(header, obs_id, 0) if chunk is None: chunk = Chunk() wcs_parser.augment_position(chunk) x_binning = header.get('XBINNING') if x_binning is None: x_binning = 1.0 cdelt1 = 3.0 * x_binning / 3600.0 y_binning = header.get('YBINNING') if y_binning is None: y_binning = 1.0 cdelt2 = 3.0 * y_binning / 3600.0 objct_rol = header.get('OBJCTROL') if objct_rol is None: objct_rol = 0.0 crota2 = 90.0 - objct_rol crota2_rad = math.radians(crota2) cd11 = cdelt1 * math.cos(crota2_rad) cd12 = abs(cdelt2) * _sign(cdelt1) * math.sin(crota2_rad) cd21 = -abs(cdelt1) * _sign(cdelt2) * math.sin(crota2_rad) cd22 = cdelt2 * math.cos(crota2_rad) dimension = Dimension2D(header.get('NAXIS1'), header.get('NAXIS2')) x = RefCoord(get_position_axis_function_naxis1(header), get_ra(header)) y = RefCoord(get_position_axis_function_naxis2(header), get_dec(header)) ref_coord = Coord2D(x, y) function = CoordFunction2D(dimension, ref_coord, cd11, cd12, cd21, cd22) chunk.position.axis.function = function chunk.position_axis_1 = 1 chunk.position_axis_2 = 2
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
def copy_chunk(from_chunk, features=None): """Make a copy of a Chunk. This works around the CAOM2 constraint 'org.postgresql.util.PSQLException: ERROR: duplicate key value violates unique constraint "chunk_pkey"', when trying to use the same chunk information in different parts (e.g. when referring to hdf5 files). :param from_chunk Chunk of which to make a copy :param features which version of CAOM to use :return a copy of the from_chunk """ if features is not None and features.supports_latest_caom: copy = Chunk( product_type=from_chunk.product_type, naxis=from_chunk.naxis, position_axis_1=from_chunk.position_axis_1, position_axis_2=from_chunk.position_axis_2, position=from_chunk.position, energy_axis=from_chunk.energy_axis, energy=from_chunk.energy, time_axis=from_chunk.time_axis, time=from_chunk.time, custom_axis=from_chunk.custom_axis, custom=from_chunk.custom, polarization_axis=from_chunk.polarization_axis, polarization=from_chunk.polarization, observable_axis=from_chunk.observable_axis, observable=from_chunk.observable, ) copy.meta_producer = from_chunk.meta_producer else: copy = Chunk( product_type=from_chunk.product_type, naxis=from_chunk.naxis, position_axis_1=from_chunk.position_axis_1, position_axis_2=from_chunk.position_axis_2, position=from_chunk.position, energy_axis=from_chunk.energy_axis, energy=from_chunk.energy, time_axis=from_chunk.time_axis, time=from_chunk.time, polarization_axis=from_chunk.polarization_axis, polarization=from_chunk.polarization, observable_axis=from_chunk.observable_axis, observable=from_chunk.observable, ) return copy
def update(self, observation, omm_name, file_info): """Called to fill multiple CAOM model elements and/or attributes, must have this signature for import_module loading and execution. :param observation A CAOM Observation model instance. :param omm_name OmmName instance :param file_info cadcdata.FileInfo instance """ self._logger.debug('Begin update.') self._update_telescope_location(observation) for plane in observation.planes.values(): for artifact in plane.artifacts.values(): if omm_name.product_id != plane.product_id: continue fits2caom2.update_artifact_meta(artifact, file_info) for part in artifact.parts.values(): if len(part.chunks) == 0 and part.name == '0': # always have a time axis, and usually an energy # axis as well, so create a chunk for the zero-th part part.chunks.append(Chunk()) for chunk in part.chunks: chunk.product_type = self.get_product_type(0) self._update_energy(chunk) self._update_time(chunk, observation.observation_id) self._update_position(plane, observation.intent, chunk) if chunk.position is None: # for WCS validation correctness chunk.naxis = None chunk.energy_axis = None chunk.time_axis = None if omm_name.is_rejected(): self._update_requirements(observation) if OmmName.is_composite(plane.product_id): if OmmChooser.change_type(observation): observation = cc.change_to_composite(observation) self._logger.info( f'Changing from Simple to Composite for ' f'{observation.observation_id}' ) self._update_provenance(observation) if ( observation.instrument is None or observation.instrument.name is None or len(observation.instrument.name) == 0 ): self._update_instrument_name(observation) self._logger.debug('Done update.') return observation
def update(observation, **kwargs): """Called to fill multiple CAOM model elements and/or attributes, must have this signature for import_module loading and execution. :param observation A CAOM Observation model instance. :param **kwargs Everything else.""" logging.debug('Begin update.') mc.check_param(observation, Observation) headers = None if 'headers' in kwargs: headers = kwargs['headers'] fqn = None if 'fqn' in kwargs: fqn = kwargs['fqn'] logging.error(type(headers)) logging.error(type(headers[0])) _update_telescope_location(observation, headers) for plane in observation.planes: for artifact in observation.planes[plane].artifacts: parts = observation.planes[plane].artifacts[artifact].parts for part in parts: p = parts[part] if len(p.chunks) == 0 and part == '0': # always have a time axis, and usually an energy # axis as well, so create a chunk for the zero-th part p.chunks.append(Chunk()) for chunk in p.chunks: chunk.naxis = 4 chunk.product_type = get_product_type(headers[0]) _update_energy(chunk, headers) _update_time(chunk, headers) _update_position(chunk, headers) if observation.observation_id.endswith('_REJECT'): _update_requirements(observation) if (observation.instrument is None or observation.instrument.name is None or len(observation.instrument.name) == 0): _update_instrument_name(observation) if OmmName.is_composite(observation.observation_id): if OmmChooser().needs_delete(observation): observation = _update_observation_type(observation) _update_provenance(observation, headers) # _update_time_bounds(observation, fqn) logging.debug('Done update.') return True
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
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
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
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 test_compute(self): # _choose_product returns Artifact.product (SCIENCE), # user_chunk = False test_chunk = Chunk() test_chunk.product_type = chunk.ProductType.CALIBRATION test_chunk.custom = CustomTestUtil.good_wcs() test_chunks = TypedList(Chunk, test_chunk) part_name = "test_part" part_product_type = chunk.ProductType.CALIBRATION part = Part(part_name, part_product_type, test_chunks) uri = 'mast:HST/product/test_file.jpg' artifact_product_type = chunk.ProductType.SCIENCE release_type = ReleaseType.DATA artifact = Artifact(uri, artifact_product_type, release_type) artifact.parts = TypedOrderedDict((Part), (part_name, part)) artifacts = TypedList(Artifact, artifact) actual_axis = wcs_util.CustomAxisUtil.compute(artifacts) expected_axis = None self.assertEqual(expected_axis, actual_axis) # _choose_product returns Artifact.product (CALIBRATION), # user_chunk = False test_chunk = Chunk() test_chunk.product_type = chunk.ProductType.SCIENCE test_chunk.custom = CustomTestUtil.good_wcs() test_chunks = TypedList(Chunk, test_chunk) part_name = "test_part" part_product_type = chunk.ProductType.SCIENCE part = Part(part_name, part_product_type, test_chunks) uri = 'mast:HST/product/test_file.jpg' artifact_product_type = chunk.ProductType.CALIBRATION release_type = ReleaseType.DATA artifact = Artifact(uri, artifact_product_type, release_type) artifact.parts = TypedOrderedDict((Part), (part_name, part)) artifacts = TypedList(Artifact, artifact) actual_axis = wcs_util.CustomAxisUtil.compute(artifacts) expected_axis = None self.assertEqual(expected_axis, actual_axis) # _choose_product returns Part.product (SCIENCE), # user_chunk = False test_chunk = Chunk() test_chunk.product_type = chunk.ProductType.SCIENCE test_chunk.custom = CustomTestUtil.good_wcs() test_chunks = TypedList(Chunk, test_chunk) part_name = "test_part" part_product_type = chunk.ProductType.SCIENCE part = Part(part_name, part_product_type, test_chunks) uri = 'mast:HST/product/test_file.jpg' artifact_product_type = chunk.ProductType.PREVIEW release_type = ReleaseType.DATA artifact = Artifact(uri, artifact_product_type, release_type) artifact.parts = TypedOrderedDict((Part), (part_name, part)) artifacts = TypedList(Artifact, artifact) actual_axis = wcs_util.CustomAxisUtil.compute(artifacts) expected_axis = None self.assertEqual(expected_axis, actual_axis) # _choose_product returns Part.product (CALIBRATION), # user_chunk = False test_chunk = Chunk() test_chunk.product_type = chunk.ProductType.SCIENCE test_chunk.custom = CustomTestUtil.good_wcs() test_chunks = TypedList(Chunk, test_chunk) part_name = "test_part" part_product_type = chunk.ProductType.CALIBRATION part = Part(part_name, part_product_type, test_chunks) uri = 'mast:HST/product/test_file.jpg' artifact_product_type = chunk.ProductType.PREVIEW release_type = ReleaseType.DATA artifact = Artifact(uri, artifact_product_type, release_type) artifact.parts = TypedOrderedDict((Part), (part_name, part)) artifacts = TypedList(Artifact, artifact) actual_axis = wcs_util.CustomAxisUtil.compute(artifacts) expected_axis = None self.assertEqual(expected_axis, actual_axis) # _choose_product returns Chunk.product (SCIENCE), user_chunk = False test_chunk = Chunk() test_chunk.product_type = chunk.ProductType.SCIENCE test_chunk.custom = CustomTestUtil.good_wcs() test_chunks = TypedList(Chunk, test_chunk) part_name = "test_part" part_product_type = chunk.ProductType.PREVIEW part = Part(part_name, part_product_type, test_chunks) uri = 'mast:HST/product/test_file.jpg' artifact_product_type = chunk.ProductType.PREVIEW release_type = ReleaseType.DATA artifact = Artifact(uri, artifact_product_type, release_type) artifact.parts = TypedOrderedDict((Part), (part_name, part)) artifacts = TypedList(Artifact, artifact) actual_axis = wcs_util.CustomAxisUtil.compute(artifacts) expected_axis = None self.assertEqual(expected_axis, actual_axis) # _choose_product returns Chunk.product (CALIBRATION), # user_chunk = False test_chunk = Chunk() test_chunk.product_type = chunk.ProductType.CALIBRATION test_chunk.custom = CustomTestUtil.good_wcs() test_chunks = TypedList(Chunk, test_chunk) part_name = "test_part" part_product_type = chunk.ProductType.PREVIEW part = Part(part_name, part_product_type, test_chunks) uri = 'mast:HST/product/test_file.jpg' artifact_product_type = chunk.ProductType.PREVIEW release_type = ReleaseType.DATA artifact = Artifact(uri, artifact_product_type, release_type) artifact.parts = TypedOrderedDict((Part), (part_name, part)) artifacts = TypedList(Artifact, artifact) actual_axis = wcs_util.CustomAxisUtil.compute(artifacts) expected_axis = None self.assertEqual(expected_axis, actual_axis) # _choose_product returns None, user_chunk = False test_chunk = Chunk() test_chunk.product_type = chunk.ProductType.PREVIEW test_chunk.custom = CustomTestUtil.good_wcs() test_chunks = TypedList(Chunk, test_chunk) part_name = "test_part" part_product_type = chunk.ProductType.PREVIEW part = Part(part_name, part_product_type, test_chunks) uri = 'mast:HST/product/test_file.jpg' artifact_product_type = chunk.ProductType.PREVIEW release_type = ReleaseType.DATA artifact = Artifact(uri, artifact_product_type, release_type) artifact.parts = TypedOrderedDict((Part), (part_name, part)) artifacts = TypedList(Artifact, artifact) actual_axis = wcs_util.CustomAxisUtil.compute(artifacts) expected_axis = None self.assertEqual(expected_axis, actual_axis) # _choose_product returns Artifact.product (SCIENCE), # user_chunk = True, Chunk.custom is None test_chunk = Chunk() test_chunk.product_type = chunk.ProductType.SCIENCE test_chunk.custom = None test_chunks = TypedList(Chunk, test_chunk) part_name = "test_part" part_product_type = chunk.ProductType.SCIENCE part = Part(part_name, part_product_type, test_chunks) uri = 'mast:HST/product/test_file.jpg' artifact_product_type = chunk.ProductType.SCIENCE release_type = ReleaseType.DATA artifact = Artifact(uri, artifact_product_type, release_type) artifact.parts = TypedOrderedDict((Part), (part_name, part)) artifacts = TypedList(Artifact, artifact) expected_axis = None actual_axis = wcs_util.CustomAxisUtil.compute(artifacts) self.assertEqual(expected_axis, actual_axis) # _choose_product returns Artifact.product (SCIENCE), # user_chunk = True, Chunk.custom is not None # bad Chunk.custom.axis.axis.ctype test_chunk = Chunk() test_chunk.product_type = chunk.ProductType.SCIENCE test_chunk.custom = CustomTestUtil.bad_ctype_wcs() test_chunks = TypedList(Chunk, test_chunk) part_name = "test_part" part_product_type = chunk.ProductType.SCIENCE part = Part(part_name, part_product_type, test_chunks) uri = 'mast:HST/product/test_file.jpg' artifact_product_type = chunk.ProductType.SCIENCE release_type = ReleaseType.DATA artifact = Artifact(uri, artifact_product_type, release_type) artifact.parts = TypedOrderedDict((Part), (part_name, part)) artifacts = TypedList(Artifact, artifact) with pytest.raises(ValueError) as ex: actual_axis = wcs_util.CustomAxisUtil.compute(artifacts) assert ('Unsupported CTYPE:' in str(ex.value)) # _choose_product returns Artifact.product (SCIENCE), # user_chunk = True, Chunk.custom is not None # first_ctype == Chunk.custom.axis.axis.ctype test_chunk = Chunk() test_chunk.product_type = chunk.ProductType.SCIENCE test_chunk.custom = CustomTestUtil.good_wcs_with_function() test_chunks = TypedList(Chunk, test_chunk) part_name = "test_part" part_product_type = chunk.ProductType.SCIENCE part = Part(part_name, part_product_type, test_chunks) uri = 'mast:HST/product/test_file.jpg' artifact_product_type = chunk.ProductType.SCIENCE release_type = ReleaseType.DATA artifact = Artifact(uri, artifact_product_type, release_type) artifact.parts = TypedOrderedDict((Part), (part_name, part)) artifacts = TypedList(Artifact, artifact) expected_ctype = "RM" expected_sample = Interval(-49.5, 19950.5) expected_samples = [expected_sample] expected_bounds = Interval(-49.5, 19950.5, expected_samples) expected_dimension = 200 expected_axis = plane.CustomAxis(expected_ctype, expected_bounds, expected_dimension) actual_axis = wcs_util.CustomAxisUtil.compute(artifacts) self.assertEqual(expected_axis.ctype, actual_axis.ctype) self.assertEqual(expected_axis.bounds.lower, actual_axis.bounds.lower) self.assertEqual(expected_axis.bounds.upper, actual_axis.bounds.upper) self.assertEqual(expected_axis.bounds.samples[0].lower, actual_axis.bounds.samples[0].lower) self.assertEqual(expected_axis.bounds.samples[0].upper, actual_axis.bounds.samples[0].upper) self.assertEqual(expected_axis.dimension, actual_axis.dimension) # _choose_product returns Artifact.product (SCIENCE), # user_chunk = True, Chunk.custom is not None # first_ctype == Chunk.custom.axis.axis.ctype test_chunk_1 = Chunk() test_chunk_1.product_type = chunk.ProductType.SCIENCE test_chunk_1.custom = CustomTestUtil.good_wcs_with_function() test_chunk_2 = Chunk() test_chunk_2.product_type = chunk.ProductType.SCIENCE test_chunk_2.custom = CustomTestUtil.good_wcs_with_function() test_chunk_2.custom.axis.axis.ctype = "FARADAY" test_chunks = TypedList(Chunk, test_chunk_1, test_chunk_2) part_name = "test_part" part_product_type = chunk.ProductType.SCIENCE part = Part(part_name, part_product_type, test_chunks) uri = 'mast:HST/product/test_file.jpg' artifact_product_type = chunk.ProductType.SCIENCE release_type = ReleaseType.DATA artifact = Artifact(uri, artifact_product_type, release_type) artifact.parts = TypedOrderedDict((Part), (part_name, part)) artifacts = TypedList(Artifact, artifact) expected_ctype = "RM" expected_sample = Interval(-49.5, 19950.5) expected_samples = [expected_sample] expected_bounds = Interval(-49.5, 19950.5, expected_samples) expected_dimension = 200 expected_axis = plane.CustomAxis(expected_ctype, expected_bounds, expected_dimension) with pytest.raises(ValueError) as ex: actual_axis = wcs_util.CustomAxisUtil.compute(artifacts) assert ('CTYPE must be the same across all Artifacts' in str(ex.value))
def test_compute_bounds(self): # user_chunk = False test_chunk = Chunk() test_chunk.product_type = chunk.ProductType.SCIENCE test_chunk.custom = CustomTestUtil.good_wcs() test_chunks = TypedList(Chunk, test_chunk) part_name = "test_part" part_product_type = chunk.ProductType.SCIENCE part = Part(part_name, part_product_type, test_chunks) uri = 'mast:HST/product/test_file.jpg' artifact_product_type = chunk.ProductType.SCIENCE release_type = ReleaseType.DATA artifact = Artifact(uri, artifact_product_type, release_type) artifact.parts = TypedOrderedDict((Part), (part_name, part)) artifacts = TypedList(Artifact, artifact) product_type = None expected_ctype = "RM" actual_bounds = wcs_util.CustomAxisUtil.compute_bounds( artifacts, product_type, expected_ctype) expected_bounds = None self.assertEqual(expected_bounds, actual_bounds) # user_chunk = True, current_type != expected_ctype test_chunk = Chunk() test_chunk.product_type = chunk.ProductType.CALIBRATION test_chunk.custom = CustomTestUtil.good_wcs_with_function() test_chunks = TypedList(Chunk, test_chunk) part_name = "test_part" part_product_type = chunk.ProductType.CALIBRATION part = Part(part_name, part_product_type, test_chunks) uri = 'mast:HST/product/test_file.jpg' artifact_product_type = chunk.ProductType.CALIBRATION release_type = ReleaseType.DATA artifact = Artifact(uri, artifact_product_type, release_type) artifact.parts = TypedOrderedDict((Part), (part_name, part)) artifacts = TypedList(Artifact, artifact) product_type = chunk.ProductType.CALIBRATION expected_ctype = "FARADAY" with pytest.raises(ValueError) as ex: wcs_util.CustomAxisUtil.compute_bounds(artifacts, product_type, expected_ctype) assert ('CTYPE must be the same across all Artifacts' in str(ex.value)) # user_chunk = True, range is not None test_chunk = Chunk() test_chunk.product_type = chunk.ProductType.CALIBRATION test_chunk.custom = CustomTestUtil.good_wcs_with_range() test_chunks = TypedList(Chunk, test_chunk) part_name = "test_part" part_product_type = chunk.ProductType.CALIBRATION part = Part(part_name, part_product_type, test_chunks) uri = 'mast:HST/product/test_file.jpg' artifact_product_type = chunk.ProductType.CALIBRATION release_type = ReleaseType.DATA artifact = Artifact(uri, artifact_product_type, release_type) artifact.parts = TypedOrderedDict((Part), (part_name, part)) artifacts = TypedList(Artifact, artifact) product_type = chunk.ProductType.CALIBRATION expected_ctype = "RM" actual_interval = wcs_util.CustomAxisUtil.compute_bounds( artifacts, product_type, expected_ctype) expected_interval = Interval(1.1, 11.1) self.assertEqual(expected_interval.lower, actual_interval.lower) self.assertEqual(expected_interval.upper, actual_interval.upper) # user_chunk = True, get_num_pixels: bounds with 3 samples that # traverses _merge_into_list completely test_chunk = Chunk() test_chunk.product_type = chunk.ProductType.CALIBRATION test_chunk.custom = CustomTestUtil.good_wcs_with_bounds_3_samples() test_chunks = TypedList(Chunk, test_chunk) part_name = "test_part" part_product_type = chunk.ProductType.CALIBRATION part = Part(part_name, part_product_type, test_chunks) uri = 'mast:HST/product/test_file.jpg' artifact_product_type = chunk.ProductType.CALIBRATION release_type = ReleaseType.DATA artifact = Artifact(uri, artifact_product_type, release_type) artifact.parts = TypedOrderedDict((Part), (part_name, part)) artifacts = TypedList(Artifact, artifact) product_type = chunk.ProductType.CALIBRATION expected_ctype = "RM" actual_interval = wcs_util.CustomAxisUtil.compute_bounds( artifacts, product_type, expected_ctype) expected_interval = Interval(-1.2, 11.2) self.assertEqual(expected_interval.lower, actual_interval.lower) self.assertEqual(expected_interval.upper, actual_interval.upper) # user_chunk = True, function is not None test_chunk = Chunk() test_chunk.product_type = chunk.ProductType.CALIBRATION test_chunk.custom = CustomTestUtil.good_wcs_with_function() test_chunks = TypedList(Chunk, test_chunk) part_name = "test_part" part_product_type = chunk.ProductType.CALIBRATION part = Part(part_name, part_product_type, test_chunks) uri = 'mast:HST/product/test_file.jpg' artifact_product_type = chunk.ProductType.CALIBRATION release_type = ReleaseType.DATA artifact = Artifact(uri, artifact_product_type, release_type) artifact.parts = TypedOrderedDict((Part), (part_name, part)) artifacts = TypedList(Artifact, artifact) product_type = chunk.ProductType.CALIBRATION expected_ctype = "RM" actual_interval = wcs_util.CustomAxisUtil.compute_bounds( artifacts, product_type, expected_ctype) expected_interval = Interval(-49.5, 19950.5) self.assertEqual(expected_interval.lower, actual_interval.lower) self.assertEqual(expected_interval.upper, actual_interval.upper)
def test_compute_dimension_from_wcs(self): # bounds is None bounds = None artifacts = None product_type = None expected_ctype = None actual_dimension = wcs_util.CustomAxisUtil.compute_dimension_from_wcs( bounds, artifacts, product_type, expected_ctype) expected_dimension = None self.assertEqual(expected_dimension, actual_dimension) # bounds is not None, user_chunk = True, current_type != expected_ctype bounds = Interval(1.1, 11.1) test_chunk = Chunk() test_chunk.product_type = chunk.ProductType.CALIBRATION test_chunk.custom = CustomTestUtil.good_wcs_with_function() test_chunks = TypedList(Chunk, test_chunk) part_name = "test_part" part_product_type = chunk.ProductType.CALIBRATION part = Part(part_name, part_product_type, test_chunks) uri = 'mast:HST/product/test_file.jpg' artifact_product_type = chunk.ProductType.CALIBRATION release_type = ReleaseType.DATA artifact = Artifact(uri, artifact_product_type, release_type) artifact.parts = TypedOrderedDict((Part), (part_name, part)) artifacts = TypedList(Artifact, artifact) product_type = chunk.ProductType.CALIBRATION expected_ctype = "FARADAY" with pytest.raises(ValueError) as ex: wcs_util.CustomAxisUtil.compute_dimension_from_wcs( bounds, artifacts, product_type, expected_ctype) assert ('CTYPE must be the same across all Artifacts' in str(ex.value)) # bounds is not None, user_chunk = True, current_type is not None and # current_type == expected_ctype, ss >= scale, num = 1 bounds = Interval(1.1, 11.1) test_chunk = Chunk() test_chunk.product_type = chunk.ProductType.CALIBRATION test_chunk.custom = CustomTestUtil.good_wcs_with_negative_delta() test_chunks = TypedList(Chunk, test_chunk) part_name = "test_part" part_product_type = chunk.ProductType.CALIBRATION part = Part(part_name, part_product_type, test_chunks) uri = 'mast:HST/product/test_file.jpg' artifact_product_type = chunk.ProductType.CALIBRATION release_type = ReleaseType.DATA artifact = Artifact(uri, artifact_product_type, release_type) artifact.parts = TypedOrderedDict((Part), (part_name, part)) artifacts = TypedList(Artifact, artifact) product_type = chunk.ProductType.CALIBRATION expected_ctype = "RM" actual_dimension = wcs_util.CustomAxisUtil.compute_dimension_from_wcs( bounds, artifacts, product_type, expected_ctype) expected_dimension = 200 self.assertEqual(expected_dimension, actual_dimension) # bounds is not None, user_chunk = False, sw = None test_chunk = Chunk() test_chunk.product_type = chunk.ProductType.SCIENCE test_chunk.custom = CustomTestUtil.good_wcs() test_chunks = TypedList(Chunk, test_chunk) part_name = "test_part" part_product_type = chunk.ProductType.SCIENCE part = Part(part_name, part_product_type, test_chunks) uri = 'mast:HST/product/test_file.jpg' artifact_product_type = chunk.ProductType.SCIENCE release_type = ReleaseType.DATA artifact = Artifact(uri, artifact_product_type, release_type) artifact.parts = TypedOrderedDict((Part), (part_name, part)) artifacts = TypedList(Artifact, artifact) product_type = None expected_ctype = "RM" actual_dimension = wcs_util.CustomAxisUtil.compute_dimension_from_wcs( bounds, artifacts, product_type, expected_ctype) expected_dimension = None self.assertEqual(expected_dimension, actual_dimension) # bounds is not None, user_chunk = True, current_type is not None and # current_type == expected_ctype, ss >= scale, num = 2 bounds = Interval(1.1, 11.1) test_chunk1 = Chunk() test_chunk1.product_type = chunk.ProductType.CALIBRATION test_chunk1.custom = CustomTestUtil.good_wcs_with_negative_delta() test_chunk2 = Chunk() test_chunk2.product_type = chunk.ProductType.CALIBRATION test_chunk2.custom = CustomTestUtil.good_wcs() test_chunks = TypedList(Chunk, test_chunk1, test_chunk2) part_name = "test_part" part_product_type = chunk.ProductType.CALIBRATION part = Part(part_name, part_product_type, test_chunks) uri = 'mast:HST/product/test_file.jpg' artifact_product_type = chunk.ProductType.CALIBRATION release_type = ReleaseType.DATA artifact = Artifact(uri, artifact_product_type, release_type) artifact.parts = TypedOrderedDict((Part), (part_name, part)) artifacts = TypedList(Artifact, artifact) product_type = chunk.ProductType.CALIBRATION expected_ctype = "RM" actual_dimension = wcs_util.CustomAxisUtil.compute_dimension_from_wcs( bounds, artifacts, product_type, expected_ctype) expected_dimension = 500 self.assertEqual(expected_dimension, actual_dimension)
def test_compute_dimension_from_range_bounds(self): # user_chunk = False, matches is None test_chunk = Chunk() test_chunk.product_type = chunk.ProductType.SCIENCE test_chunk.custom = CustomTestUtil.good_wcs() test_chunks = TypedList(Chunk, test_chunk) part_name = "test_part" part_product_type = chunk.ProductType.SCIENCE part = Part(part_name, part_product_type, test_chunks) uri = 'mast:HST/product/test_file.jpg' artifact_product_type = chunk.ProductType.SCIENCE release_type = ReleaseType.DATA artifact = Artifact(uri, artifact_product_type, release_type) artifact.parts = TypedOrderedDict((Part), (part_name, part)) artifacts = TypedList(Artifact, artifact) product_type = None expected_ctype = "RM" actual_num_pixels = \ wcs_util.CustomAxisUtil.compute_dimension_from_range_bounds( artifacts, product_type, expected_ctype) expected_num_pixels = None self.assertEqual(expected_num_pixels, actual_num_pixels) # user_chunk = False, ctype not match test_chunk = Chunk() test_chunk.product_type = chunk.ProductType.SCIENCE test_chunk.custom = CustomTestUtil.good_wcs() test_chunks = TypedList(Chunk, test_chunk) part_name = "test_part" part_product_type = chunk.ProductType.SCIENCE part = Part(part_name, part_product_type, test_chunks) uri = 'mast:HST/product/test_file.jpg' artifact_product_type = chunk.ProductType.SCIENCE release_type = ReleaseType.DATA artifact = Artifact(uri, artifact_product_type, release_type) artifact.parts = TypedOrderedDict((Part), (part_name, part)) artifacts = TypedList(Artifact, artifact) product_type = chunk.ProductType.CALIBRATION expected_ctype = "RM" actual_num_pixels = \ wcs_util.CustomAxisUtil.compute_dimension_from_range_bounds( artifacts, product_type, expected_ctype) expected_num_pixels = None self.assertEqual(expected_num_pixels, actual_num_pixels) # user_chunk = False, ptype not match test_chunk = Chunk() test_chunk.product_type = chunk.ProductType.CALIBRATION test_chunk.custom = CustomTestUtil.good_wcs() test_chunks = TypedList(Chunk, test_chunk) part_name = "test_part" part_product_type = chunk.ProductType.SCIENCE part = Part(part_name, part_product_type, test_chunks) uri = 'mast:HST/product/test_file.jpg' artifact_product_type = chunk.ProductType.SCIENCE release_type = ReleaseType.DATA artifact = Artifact(uri, artifact_product_type, release_type) artifact.parts = TypedOrderedDict((Part), (part_name, part)) artifacts = TypedList(Artifact, artifact) product_type = chunk.ProductType.CALIBRATION expected_ctype = "RM" actual_num_pixels = \ wcs_util.CustomAxisUtil.compute_dimension_from_range_bounds( artifacts, product_type, expected_ctype) expected_num_pixels = None self.assertEqual(expected_num_pixels, actual_num_pixels) # user_chunk = False, atype not match test_chunk = Chunk() test_chunk.product_type = chunk.ProductType.CALIBRATION test_chunk.custom = CustomTestUtil.good_wcs() test_chunks = TypedList(Chunk, test_chunk) part_name = "test_part" part_product_type = chunk.ProductType.CALIBRATION part = Part(part_name, part_product_type, test_chunks) uri = 'mast:HST/product/test_file.jpg' artifact_product_type = chunk.ProductType.SCIENCE release_type = ReleaseType.DATA artifact = Artifact(uri, artifact_product_type, release_type) artifact.parts = TypedOrderedDict((Part), (part_name, part)) artifacts = TypedList(Artifact, artifact) product_type = chunk.ProductType.CALIBRATION expected_ctype = "RM" actual_num_pixels = \ wcs_util.CustomAxisUtil.compute_dimension_from_range_bounds( artifacts, product_type, expected_ctype) expected_num_pixels = None self.assertEqual(expected_num_pixels, actual_num_pixels) # user_chunk = True, current_type != expected_ctype test_chunk = Chunk() test_chunk.product_type = chunk.ProductType.CALIBRATION test_chunk.custom = CustomTestUtil.good_wcs_with_function() test_chunks = TypedList(Chunk, test_chunk) part_name = "test_part" part_product_type = chunk.ProductType.CALIBRATION part = Part(part_name, part_product_type, test_chunks) uri = 'mast:HST/product/test_file.jpg' artifact_product_type = chunk.ProductType.CALIBRATION release_type = ReleaseType.DATA artifact = Artifact(uri, artifact_product_type, release_type) artifact.parts = TypedOrderedDict((Part), (part_name, part)) artifacts = TypedList(Artifact, artifact) product_type = chunk.ProductType.CALIBRATION expected_ctype = "FARADAY" with pytest.raises(ValueError) as ex: wcs_util.CustomAxisUtil.compute_dimension_from_range_bounds( artifacts, product_type, expected_ctype) assert ('CTYPE must be the same across all Artifacts' in str(ex.value)) # user_chunk = True, get_num_pixels: range is not None test_chunk = Chunk() test_chunk.product_type = chunk.ProductType.CALIBRATION test_chunk.custom = CustomTestUtil.good_wcs_with_range() test_chunks = TypedList(Chunk, test_chunk) part_name = "test_part" part_product_type = chunk.ProductType.CALIBRATION part = Part(part_name, part_product_type, test_chunks) uri = 'mast:HST/product/test_file.jpg' artifact_product_type = chunk.ProductType.CALIBRATION release_type = ReleaseType.DATA artifact = Artifact(uri, artifact_product_type, release_type) artifact.parts = TypedOrderedDict((Part), (part_name, part)) artifacts = TypedList(Artifact, artifact) product_type = chunk.ProductType.CALIBRATION expected_ctype = "RM" actual_num_pixels = \ wcs_util.CustomAxisUtil.compute_dimension_from_range_bounds( artifacts, product_type, expected_ctype) expected_num_pixels = 10 self.assertEqual(expected_num_pixels, actual_num_pixels) # user_chunk = True, get_num_pixels: bounds with 3 samples that # traverses _merge_into_list completely test_chunk = Chunk() test_chunk.product_type = chunk.ProductType.CALIBRATION test_chunk.custom = CustomTestUtil.good_wcs_with_bounds_3_samples() test_chunks = TypedList(Chunk, test_chunk) part_name = "test_part" part_product_type = chunk.ProductType.CALIBRATION part = Part(part_name, part_product_type, test_chunks) uri = 'mast:HST/product/test_file.jpg' artifact_product_type = chunk.ProductType.CALIBRATION release_type = ReleaseType.DATA artifact = Artifact(uri, artifact_product_type, release_type) artifact.parts = TypedOrderedDict((Part), (part_name, part)) artifacts = TypedList(Artifact, artifact) product_type = chunk.ProductType.CALIBRATION expected_ctype = "RM" actual_num_pixels = \ wcs_util.CustomAxisUtil.compute_dimension_from_range_bounds( artifacts, product_type, expected_ctype) expected_num_pixels = 11 self.assertEqual(expected_num_pixels, actual_num_pixels) # user_chunk = True, range = None, bounds = None, use_func and # function = None test_chunk = Chunk() test_chunk.product_type = chunk.ProductType.CALIBRATION test_chunk.custom = CustomTestUtil.good_wcs() test_chunks = TypedList(Chunk, test_chunk) part_name = "test_part" part_product_type = chunk.ProductType.CALIBRATION part = Part(part_name, part_product_type, test_chunks) uri = 'mast:HST/product/test_file.jpg' artifact_product_type = chunk.ProductType.CALIBRATION release_type = ReleaseType.DATA artifact = Artifact(uri, artifact_product_type, release_type) artifact.parts = TypedOrderedDict((Part), (part_name, part)) artifacts = TypedList(Artifact, artifact) product_type = chunk.ProductType.CALIBRATION expected_ctype = "RM" actual_num_pixels = \ wcs_util.CustomAxisUtil.compute_dimension_from_range_bounds( artifacts, product_type, expected_ctype) expected_num_pixels = None self.assertEqual(expected_num_pixels, actual_num_pixels)
def stuff(args): obs = None index = 0 for f_name in args.local: product_id = args.lineage[index].split('/')[0] t_header = Table.read(f_name, format='hdf5', path='header') # logging.error(t_header.colnames) # ['VERSION_MAJOR', 'VERSION_MINOR', 'TIME_IN_SEC', # 'TIME_IN_MICROSEC', 'RUN_ID', 'ORIGIN', 'OBSMODE', 'FIELD', 'RA', # 'DEC', 'EXPTIME', 'NUM_IMAGER'] # logging.error(t_header) # t_header['RUN_ID'].data[0].decode() - return this string # 20190805T024026 # logging.error(t_header['RUN_ID'].data[0].decode()) release_date = datetime.strptime( t_header['RUN_ID'].data[0].decode(), '%Y%m%dT%H%M%S') t_image = Table.read(f_name, format='hdf5', path='image') # logging.error(t_image.colnames) # ['col0', 'col1', 'col2'] # logging.error(t_image) # logging.error(t_image['col0'].data[0]) # logging.error(t_image['col0'].data[143999]) t_catalog = Table.read(f_name, format='hdf5', path='catalog') # logging.error(t_catalog.colnames) # ['CAT_ID', 'GAIA_ID', '2MASS_ID', 'RA', 'DEC', 'TAOS_MAG', # 'GAIA_MAG', '2MASS_JMAG'] # logging.error(t_catalog) t_imager = Table.read(f_name, format='hdf5', path='imager') # logging.error(t_imager.colnames) # ['TEL_ID', 'CAM_ID', 'IMGR_ID', 'XLOC', 'YLOC'] # logging.error(t_imager) t_moment = Table.read(f_name, format='hdf5', path='moment') # logging.error(t_moment.colnames) # ['col0', 'col1', 'col2'] # logging.error(t_moment) t_window = Table.read(f_name, format='hdf5', path='window') # logging.error(t_window.colnames) # ['X0', 'X1', 'Y0', 'Y1', 'XC', 'YC'] # logging.error(t_window) t_wcs= Table.read(f_name, format='hdf5', path='/wcs/cdmatrix') # ['CRVAL1','CRVAL2','CRPIX1','CRPIX2','CD1_1','CD1_2','CD2_1','CD2_2'] # logging.error(t_wcs) taos = Telescope(name='TAOS', geo_location_x=-2354953.99637757, geo_location_y=-4940160.3636381, geo_location_z=3270123.70695983) target = Target(name=str(t_header['FIELD'].data[0]), target_type=TargetType.FIELD, standard=None, redshift=None, keywords=None, moving=None) proposal = Proposal(id=COLLECTION, pi_name=None, project=COLLECTION, title=None) obs = SimpleObservation(collection=COLLECTION, observation_id=args.observation[1], sequence_number=None, intent=ObservationIntentType.SCIENCE, type='FIELD', proposal=proposal, telescope=taos, instrument=None, target=target, meta_release=release_date) provenance = Provenance(name=COLLECTION, version='{}.{}'.format( t_header['VERSION_MAJOR'].data[0], t_header['VERSION_MINOR'].data[0]), project=COLLECTION, producer=COLLECTION, run_id=t_header['RUN_ID'].data[0].decode(), reference='https://taos2.asiaa.sinica.edu.tw/', last_executed=release_date) plane = Plane(product_id=product_id, data_release=release_date, meta_release=release_date, provenance=provenance, data_product_type=DataProductType.IMAGE, calibration_level=CalibrationLevel.RAW_STANDARD) artifact = mc.get_artifact_metadata( f_name, ProductType.SCIENCE, ReleaseType.DATA, mc.build_uri(COLLECTION, os.path.basename(f_name))) # parts are always named '0' part = Part('0') # do each of the three telescopes for telescope in [0, 1, 2]: position = build_position(t_wcs, t_window, telescope) time = build_time(t_header['TIME_IN_SEC'].data[0], t_header['TIME_IN_MICROSEC'].data[0]) energy = build_energy() chunk = Chunk(naxis=4, position_axis_1=1, position_axis_2=2, energy_axis=3, time_axis=4, position=position, energy=energy, time=time) part.chunks.append(chunk) artifact.parts.add(part) plane.artifacts.add(artifact) obs.planes.add(plane) index += 1 return obs