Skip to content

Commit

Permalink
use gmu.return_requested_units() for _get_actual_cenwave()
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-simpson committed Jan 14, 2025
1 parent 09e4cd5 commit 2663544
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 65 deletions.
33 changes: 8 additions & 25 deletions geminidr/core/primitives_spect.py
Original file line number Diff line number Diff line change
Expand Up @@ -5652,41 +5652,24 @@ def _get_resolution(self, ext):
slit_width_pix = ext.slit_width()/ext.pixel_scale()
return abs(resolution_1pix_slit // slit_width_pix)

def _get_actual_cenwave(self, ext, asMicrometers=False,
asNanometers=False, asAngstroms=False):
@staticmethod
@gmu.return_requested_units(input_units="m")
def _get_actual_cenwave(ext):
"""
For some instruments (NIRI, F2) wavelenght at the central pixel
For some instruments (NIRI, F2) wavelength at the central pixel
can differ significantly from the descriptor value.
Parameters
----------
asMicrometers : bool
If True, return the wavelength in microns
asNanometers : bool
If True, return the wavelength in nanometers
asAngstroms : bool
If True, return the wavelength in Angstroms
ext; single-slice AstroData object
the extension for which to determine the central wavelength
Returns
-------
float
Actual cenral wavelenght
Actual central wavelength
"""
unit_arg_list = [asMicrometers, asNanometers, asAngstroms]
output_units = "meters" # By default
if unit_arg_list.count(True) == 1:
# Just one of the unit arguments was set to True. Return the
# central wavelength in these units
if asMicrometers:
output_units = "micrometers"
if asNanometers:
output_units = "nanometers"
if asAngstroms:
output_units = "angstroms"
cenwave = ext.central_wavelength()
actual_cenwave = gmu.convert_units('meters', cenwave, output_units)

return actual_cenwave
return ext.central_wavelength()

def _get_cenwave_accuracy(self, ext):
# TODO: remove this
Expand Down
29 changes: 7 additions & 22 deletions geminidr/f2/primitives_f2_spect.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,43 +366,28 @@ def _get_arc_linelist(self, ext, waves=None):
filename = os.path.join(lookup_dir, linelist)
return wavecal.LineList(filename)


def _get_actual_cenwave(self, ext, asMicrometers=False, asNanometers=False, asAngstroms=False):
@staticmethod
@gmu.return_requested_units(input_units="m")
def _get_actual_cenwave(ext):
"""
For some instruments (NIRI, F2) wavelenght at the central pixel
For some instruments (NIRI, F2) wavelength at the central pixel
can differ significantly from the descriptor value.
Parameters
----------
asMicrometers : bool
If True, return the wavelength in microns
asNanometers : bool
If True, return the wavelength in nanometers
asAngstroms : bool
If True, return the wavelength in Angstroms
ext: single-slice AstroDataF2
the extension for which to determine the central wavelength
Returns
-------
float
Actual cenral wavelenght
Actual central wavelength
"""
unit_arg_list = [asMicrometers, asNanometers, asAngstroms]
output_units = "meters" # By default
if unit_arg_list.count(True) == 1:
# Just one of the unit arguments was set to True. Return the
# central wavelength in these units
if asMicrometers:
output_units = "micrometers"
if asNanometers:
output_units = "nanometers"
if asAngstroms:
output_units = "angstroms"
index = (ext.disperser(pretty=True), ext.filter_name(keepID=True))
mask = dispersion_offset_mask.get(index, None)
cenwave_offset = mask.cenwaveoffset if mask else None
actual_cenwave = ext.central_wavelength() + \
abs(ext.dispersion()) * cenwave_offset
actual_cenwave = gmu.convert_units('meters', actual_cenwave, output_units)
return actual_cenwave


Expand Down
36 changes: 18 additions & 18 deletions geminidr/niri/primitives_niri_spect.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,30 +226,30 @@ def _get_resolution(self, ad):
return None
return resolution

def _get_actual_cenwave(self, ext, asMicrometers=False, asNanometers=False, asAngstroms=False):
# For NIRI wavelength at central pixel doesn't match the descriptor value

unit_arg_list = [asMicrometers, asNanometers, asAngstroms]
output_units = "meters" # By default
if unit_arg_list.count(True) == 1:
# Just one of the unit arguments was set to True. Return the
# central wavelength in these units
if asMicrometers:
output_units = "micrometers"
if asNanometers:
output_units = "nanometers"
if asAngstroms:
output_units = "angstroms"
@staticmethod
@gmu.return_requested_units(input_units="m")
def _get_actual_cenwave(ext):
"""
For some instruments (NIRI, F2) wavelength at the central pixel
can differ significantly from the descriptor value.
Parameters
----------
ext: single-slice AstroDataNIRI
the extension for which to determine the central wavelength
Returns
-------
float
Actual central wavelength
"""
camera = ext.camera()
try:
disperser = ext.disperser(stripID=True)[0:6]
except TypeError:
disperser = None
fpmask = ext.focal_plane_mask(stripID=True)
try:
cenwave = lookup.spec_wavelengths[camera, fpmask, disperser][1]
return lookup.spec_wavelengths[camera, fpmask, disperser].cenpixwave
except KeyError:
return None
actual_cenwave = gmu.convert_units('nanometers', cenwave, output_units)

return actual_cenwave

0 comments on commit 2663544

Please sign in to comment.