Source code for sofia_redux.scan.custom.sofia.info.dithering

# Licensed under a 3-clause BSD style license - see LICENSE.rst

from astropy import units
import numpy as np

from sofia_redux.scan.info.base import InfoBase
from sofia_redux.scan.utilities.utils import to_header_float
from sofia_redux.scan.coordinate_systems.coordinate_2d import Coordinate2D
from sofia_redux.scan.utilities.utils import insert_info_in_header

__all__ = ['SofiaDitheringInfo']


[docs] class SofiaDitheringInfo(InfoBase): def __init__(self): """ Initialize the SOFIA dithering information. Contains information on the SOFIA dither parameters. """ super().__init__() self.dithering = None self.coordinate_system = None self.pattern_shape = None self.offset = Coordinate2D(np.full(2, np.nan), unit='arcsec') self.positions = -1 self.index = -1 @property def log_id(self): """ Return the string log ID for the info. The log ID is used to extract certain information from table data. Returns ------- str """ return 'dither'
[docs] def apply_configuration(self): """ Update dithering information with FITS header information. Updates the chopping information by taking the following keywords from the FITS header:: DITHER - Whether dithering is enabled for the scan (bool) DTHCRSYS - The MCCS chopping coordinate system (str) DTHPATT - The approximate pattern for dithering (str) DTHXOFF - The x-offset for dithering (arcseconds) DTHYOFF - The y-offset for dithering (arcseconds) DTHNPOS - The number of dithering positions (int) DTHINDEX - The dither position index (int) Returns ------- None """ options = self.options if options is None: return self.dithering = options.get_bool("DITHER") self.coordinate_system = options.get_string("DTHCRSYS") self.pattern_shape = options.get_string("DTHPATT") self.offset.x = options.get_float('DTHXOFF') self.offset.y = options.get_float('DTHYOFF') self.positions = options.get_int("DTHNPOS") self.index = options.get_int("DTHINDEX")
[docs] def edit_header(self, header): """ Edit an image header with available information. Parameters ---------- header : astropy.fits.Header The FITS header to apply. Returns ------- None """ if self.offset is None: offset = Coordinate2D(np.full(2, np.nan) * units.Unit('arcsec')) else: offset = self.offset info = [ ('COMMENT', "<------ SOFIA Dithering Data ------>"), ('DTHCRSYS', self.coordinate_system, 'Dither coordinate system.'), ('DTHXOFF', to_header_float(offset.x, 'arcsec'), '(arcsec) Dither X offset.'), ('DTHYOFF', to_header_float(offset.y, 'arcsec'), '(arcsec) Dither Y offset.'), ('DTHPATT', self.pattern_shape, 'Approximate shape of dither pattern.'), ('DTHNPOS', self.positions, 'Number of dither positions.'), ('DTHINDEX', self.index, 'Dither position index.') ] insert_info_in_header(header, info, delete_special=True)
[docs] def get_table_entry(self, name): """ Given a name, return the parameter stored in the information object. Note that names do not exactly match to attribute names. Parameters ---------- name : str Returns ------- value """ if name == 'dx': return self.offset.x.to('arcsec') elif name == 'dy': return self.offset.y.to('arcsec') elif name == 'index': return self.index elif name == 'pattern': return self.pattern_shape elif name == 'npos': return self.positions elif name == 'sys': return self.coordinate_system else: return super().get_table_entry(name)