def _update_energy(chunk, header, filter_name, obs_id): logging.debug(f'Begin _update_energy for {obs_id}.') # because the type for the axes are 'LINEAR', which isn't an energy type, # so can't use the WcsParser from caom2utils. disp_axis = header.get('DISPAXIS') naxis = header.get('NAXIS') if disp_axis is not None and naxis is not None and disp_axis <= naxis: axis = Axis(ctype='WAVE', cunit='Angstrom') coord_axis_1d = CoordAxis1D(axis) ref_coord = RefCoord( pix=header.get(f'CRPIX{disp_axis}'), val=header.get(f'CRVAL{disp_axis}'), ) fn = CoordFunction1D( naxis=header.get(f'NAXIS{disp_axis}'), delta=header.get(f'CD{disp_axis}_{disp_axis}'), ref_coord=ref_coord, ) coord_axis_1d.function = fn energy = SpectralWCS(axis=coord_axis_1d, specsys='TOPOCENT') energy.bandpass_name = filter_name # DB 07-08-20 # I think the best we can do is assume that a resolution element is 2 # pixels wide. So resolving power is the absolute value of # approximately CRVAL3/(2 * CD3_3) energy.resolving_power = abs( header.get(f'CRVAL{disp_axis}') / (2 * header.get(f'CD{disp_axis}_{disp_axis}'))) chunk.energy = energy chunk.energy_axis = disp_axis logging.debug('End _update_energy.')
def _build_chunk_energy(chunk, headers): # DB 18-09-19 # NEOSSat folks wanted the min/max wavelengths in the BANDPASS keyword to # be used as the upper/lower wavelengths. BANDPASS = ‘4000,9000’ so # ref_coord1 = RefCoord(0.5, 4000) and ref_coord2 = RefCoord(1.5, 9000). # The WAVELENG value is not used for anything since they opted to do it # this way. They interpret WAVELENG as being the wavelengh of peak # throughput of the system I think. min_wl, max_wl = _get_energy(headers[0]) axis = CoordAxis1D(axis=Axis(ctype='WAVE', cunit='um')) if min_wl is not None and max_wl is not None: ref_coord1 = RefCoord(0.5, min_wl) ref_coord2 = RefCoord(1.5, max_wl) axis.range = CoordRange1D(ref_coord1, ref_coord2) # DB 24-09-19 # If FILTER not in header, set filter_name = ‘CLEAR’ filter_name = headers[0].get('FILTER', 'CLEAR') # DB 24-09-19 # if wavelength IS None, wl = 0.6 microns, and resolving_power is # always determined. resolving_power = None wavelength = headers[0].get('WAVELENG', 6000) wl = wavelength / 1e4 # everything in microns resolving_power = wl / (max_wl - min_wl) energy = SpectralWCS(axis=axis, specsys='TOPOCENT', ssyssrc='TOPOCENT', ssysobs='TOPOCENT', bandpass_name=filter_name, resolving_power=resolving_power) chunk.energy = energy
def _update_energy(self, chunk): """Create SpectralWCS information using FITS headers, if available. If the WLEN and BANDPASS keyword values are set to the defaults, there is no energy information.""" self._logger.debug('Begin _update_energy') mc.check_param(chunk, Chunk) wlen = self._headers[0].get('WLEN') bandpass = self._headers[0].get('BANDPASS') if wlen is None or wlen < 0 or bandpass is None or bandpass < 0: chunk.energy = None chunk.energy_axis = None self._logger.debug( f'Setting chunk energy to None because WLEN {wlen} and ' f'BANDPASS {bandpass}' ) else: naxis = CoordAxis1D(Axis('WAVE', 'um')) start_ref_coord = RefCoord(0.5, self.get_start_ref_coord_val(0)) end_ref_coord = RefCoord(1.5, self.get_end_ref_coord_val(0)) naxis.range = CoordRange1D(start_ref_coord, end_ref_coord) chunk.energy = SpectralWCS( naxis, specsys='TOPOCENT', ssysobs='TOPOCENT', ssyssrc='TOPOCENT', bandpass_name=self._headers[0].get('FILTER'), ) chunk.energy_axis = None self._logger.debug('Setting chunk energy range (CoordRange1D).')
def build_chunk_energy_range(chunk, filter_name, filter_md): """ Set a range axis for chunk energy using central wavelength and FWHM. Units are Angstroms. Axis is set to 4. :param chunk: Chunk to add a CoordRange1D Axis to :param filter_name: string to set to bandpassName :param filter_md: dict with a 'cw' and 'fwhm' value """ # If n_axis=1 (as I guess it will be for all but processes GRACES # spectra now?) that means crpix=0.5 and the corresponding crval would # central_wl - bandpass/2.0 (i.e. the minimum wavelength). It is fine # if you instead change crpix to 1.0. I guess since the ‘range’ of # one pixel is 0.5 to 1.5. cw = ac.FilterMetadataCache.get_central_wavelength(filter_md) fwhm = ac.FilterMetadataCache.get_fwhm(filter_md) if cw is not None and fwhm is not None: resolving_power = ac.FilterMetadataCache.get_resolving_power(filter_md) axis = CoordAxis1D(axis=Axis(ctype='WAVE', cunit='Angstrom')) ref_coord1 = RefCoord(0.5, cw - fwhm / 2.0) ref_coord2 = RefCoord(1.5, cw + fwhm / 2.0) axis.range = CoordRange1D(ref_coord1, ref_coord2) energy = SpectralWCS(axis=axis, specsys='TOPOCENT', ssyssrc=None, ssysobs=None, bandpass_name=filter_name, resolving_power=resolving_power) chunk.energy = energy
def _do_energy(artifact, science_file, working_dir, cfht_name): # PD slack 08-01-20 # espadons is a special case because using bounds allows one to # define "tiles" and then the SODA cutout service can extract the # subset of tiles that overlap the desired region. That's the best # that can be done because it is not possible to create a # CoordFunction1D to say what the wavelength of each pixel is # # If the coverage had significant gaps (eg SCUBA or SCUBA2 from # JCMT) then the extra detail in bounds would enable better # discovery (as the gaps would be captured in the plane metadata). # In the case of espadons I don't think the gaps are significant # (iirc, espadons is an eschelle spectrograph but I don't recall # whether the discontinuity between eschelle was a small gap or an # overlap) # # So: bounds provides more detail and it can in principle improve # data discovery (if gaps) and enable extraction of subsections of # the spectrum via the SODA service. Espadons was one of the use # cases that justified having bounds there # SF slack 08-01-20 # We need the information that is contained in bounds. Gaps need # to be captured. So keep bounds. If you decide to remove range, # then advanced users would have to dig in the info to understand # range is first and last bounds. # read in the complete fits file, including the data fqn = f'{working_dir}/{science_file}' logging.info(f'Reading ESPaDOnS energy data from {fqn}.') hdus = ac.read_fits_data(fqn) wave = hdus[0].data[0, :] axis = Axis('WAVE', 'nm') coord_bounds = ac.build_chunk_energy_bounds(wave, axis) coord_axis = CoordAxis1D(axis=axis, bounds=coord_bounds) params = {'header': hdus[0].header, 'uri': artifact.uri} resolving_power = main_app.get_espadons_energy_resolving_power(params) chunk = artifact.parts['0'].chunks[0] chunk.energy = SpectralWCS(coord_axis, specsys='TOPOCENT', ssyssrc='TOPOCENT', resolving_power=resolving_power) chunk.energy_axis = 1 chunk.naxis = hdus[0].header.get('NAXIS') if (chunk.naxis is not None and chunk.naxis == 2 and chunk.observable is not None): chunk.observable_axis = 2 chunk.position_axis_1 = None chunk.position_axis_2 = None chunk.time_axis = None chunk.custom_axis = None if cfht_name.suffix != 'p': chunk.polarization_axis = None hdus.close() return 1
def build_energy(): # units are nm min = 400 max = 800 central_wl = (min + max) / 2.0 # = 1200.0 / 2.0 == 600.0 nm fwhm = (max - min) ref_coord1 = RefCoord(0.5, central_wl - fwhm / 2.0) # == 100.0 nm ref_coord2 = RefCoord(1.5, central_wl + fwhm / 2.0) # == 500.0 nm axis = CoordAxis1D(axis=Axis(ctype='WAVE', cunit='nm')) axis.range = CoordRange1D(ref_coord1, ref_coord2) energy = SpectralWCS(axis=axis, specsys='TOPOCENT', ssyssrc='TOPOCENT', ssysobs='TOPOCENT', bandpass_name='CLEAR') return energy
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