diff --git a/gemini_instruments/bhros/adclass.py b/gemini_instruments/bhros/adclass.py index c246188bf8..c866722b4c 100644 --- a/gemini_instruments/bhros/adclass.py +++ b/gemini_instruments/bhros/adclass.py @@ -17,48 +17,22 @@ def _tag_instrument(self): return TagSet({'BHROS', 'SPECT'}, ()) @astro_data_descriptor - def central_wavelength(self, asMicrometers=False, asNanometers=False, - asAngstroms=False): + @gmu.return_requested_units + def central_wavelength(self): """ - Returns the central wavelength in meters or the specified units - - 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 + Returns the central wavelength in microns Returns ------- float - The central wavelength setting + The central wavelength setting in nm """ - unit_arg_list = [asMicrometers, asNanometers, asAngstroms] - 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" - else: - # Either none of the unit arguments were set to True or more than - # one of the unit arguments was set to True. In either case, - # return the central wavelength in the default units of meters. - output_units = "meters" - # The central_wavelength keyword is in Angstroms keyword = self._keyword_for('central_wavelength') wave_in_angstroms = self.phu.get(keyword, -1) if wave_in_angstroms < 0: return None - return gmu.convert_units('angstroms', wave_in_angstroms, - output_units) + return wave_in_angstroms * 0.1 @astro_data_descriptor def dec(self): diff --git a/gemini_instruments/f2/adclass.py b/gemini_instruments/f2/adclass.py index c6aa86020d..5774ba5461 100644 --- a/gemini_instruments/f2/adclass.py +++ b/gemini_instruments/f2/adclass.py @@ -164,63 +164,32 @@ def camera(self, stripID=False, pretty=False): return self._may_remove_component(camera, stripID, pretty) @astro_data_descriptor - def central_wavelength(self, asMicrometers=False, asNanometers=False, - asAngstroms=False): + @gmu.return_requested_units + def central_wavelength(self): """ - Returns the central wavelength in meters or the specified units - For F2, central wavelength is specified for the middle of the - grism + filter transmission window, not for the central row. - - 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 + Returns the central wavelength in microns Returns ------- float The central wavelength setting - """ - unit_arg_list = [asMicrometers, asNanometers, asAngstroms] - 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" - else: - # Either none of the unit arguments were set to True or more than - # one of the unit arguments was set to True. In either case, - # return the central wavelength in the default units of meters. - output_units = "meters" - - central_wavelength = float(self.phu['WAVELENG']) + central_wavelength = float(self.phu['WAVELENG']) * 0.1 filter = self.filter_name(keepID=True) # Header value for this filter in early data is incorrect: if filter == 'K-long_G0812': - central_wavelength = 22000 + central_wavelength = 2200.0 # The new JH_G0816 and HK_G0817 filters were installed in 2022, but their # WAVELENG header keywords weren't simultaneously updated, thus the correction. if filter == "JH_G0816": - central_wavelength = 13385 + central_wavelength = 1338.5 if filter == "HK_G0817": - central_wavelength = 19000 + central_wavelength = 1900.0 if central_wavelength < 0.0: return None - - else: - return gmu.convert_units('angstroms', central_wavelength, - output_units) + return central_wavelength @astro_data_descriptor def data_section(self, pretty=False): @@ -333,21 +302,13 @@ def detector_y_offset(self): return -offset if self.phu.get('INPORT') == 1 else offset @astro_data_descriptor - def dispersion(self, asMicrometers=False, asNanometers=False, asAngstroms=False): + @gmu.return_requested_units + def dispersion(self): """ - Returns the dispersion in meters per pixel as a list (one value per + Returns the dispersion in microns per pixel as a list (one value per extension) or a float if used on a single-extension slice. It is possible to control the units of wavelength using the input arguments. - 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 - Returns ------- list/float @@ -359,22 +320,7 @@ def dispersion(self, asMicrometers=False, asNanometers=False, asAngstroms=False) mask = dispersion_offset_mask.get(config, None) dispersion = float(mask.dispersion if mask else None) - 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" - - if dispersion is not None: - dispersion = gmu.convert_units('nanometers', dispersion, output_units) - - if not self.is_single: + if dispersion is not None and not self.is_single: dispersion = [dispersion] * len(self) return dispersion diff --git a/gemini_instruments/flamingos/adclass.py b/gemini_instruments/flamingos/adclass.py index 8f0a8a5caf..9bc5b67bc9 100644 --- a/gemini_instruments/flamingos/adclass.py +++ b/gemini_instruments/flamingos/adclass.py @@ -41,43 +41,17 @@ def _tag_dark(self): return TagSet(['DARK', 'CAL']) @astro_data_descriptor - def central_wavelength(self, asMicrometers=False, asNanometers=False, - asAngstroms=False): + @gmu.return_requested_units + def central_wavelength(self): """ - Returns the central wavelength in meters or the specified units - - 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 + Returns the central wavelength in microns Returns ------- float - The central wavelength setting - + The central wavelength setting in um """ - unit_arg_list = [asMicrometers, asNanometers, asAngstroms] - 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" - else: - # Either none of the unit arguments were set to True or more than - # one of the unit arguments was set to True. In either case, - # return the central wavelength in the default units of meters. - output_units = "meters" - - return gmu.convert_units('micrometers', 1.5, output_units) + return 1500.0 @astro_data_descriptor def dec(self): diff --git a/gemini_instruments/gemini/adclass.py b/gemini_instruments/gemini/adclass.py index 2ca5bbff43..36c016700f 100644 --- a/gemini_instruments/gemini/adclass.py +++ b/gemini_instruments/gemini/adclass.py @@ -610,50 +610,23 @@ def cass_rotator_pa(self): return crpa if abs(crpa) <= 360 else None @astro_data_descriptor - def central_wavelength(self, asMicrometers=False, asNanometers=False, - asAngstroms=False): + @gmu.return_requested_units + def central_wavelength(self): """ Returns the central wavelength in meters or the specified units - 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 - Returns ------- float - The central wavelength setting - """ - unit_arg_list = [asMicrometers, asNanometers, asAngstroms] - 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" - else: - # Either none of the unit arguments were set to True or more than - # one of the unit arguments was set to True. In either case, - # return the central wavelength in the default units of meters. - output_units = "meters" - + The central wavelength setting in nm + """ # We assume that the central_wavelength keyword is in microns keyword = self._keyword_for('central_wavelength') - wave_in_microns = self.phu.get(keyword, -1) - # Convert to float if they saved it as a string - wave_in_microns = float(wave_in_microns) if isinstance(wave_in_microns, str) else wave_in_microns + wave_in_microns = float(self.phu.get(keyword, -1)) + if wave_in_microns < 0: return None - return gmu.convert_units('micrometers', wave_in_microns, - output_units) + return wave_in_microns @astro_data_descriptor def coadds(self): @@ -897,57 +870,27 @@ def disperser(self, stripID=False, pretty=False): stripID, pretty) @astro_data_descriptor - def dispersion(self, asMicrometers=False, asNanometers=False, asAngstroms=False): + @gmu.return_requested_units + def dispersion(self): """ Returns the dispersion in meters per pixel as a list (one value per extension) or a float if used on a single-extension slice. It is possible to control the units of wavelength using the input arguments. - 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 - Returns ------- list/float - The dispersion(s) + The dispersion(s) in nm """ - if self._keyword_for('dispersion') in self.hdr: - dispersion = self.hdr[self._keyword_for('dispersion')] - + keyword = self._keyword_for('dispersion') + if keyword in self.hdr: + dispersion = self.hdr[keyword] elif self._keyword_for('dispersion') in self.phu: - dispersion = self.phu[self._keyword_for('dispersion')] - - else: - dispersion = None - - unit_arg_list = [asMicrometers, asNanometers, asAngstroms] - 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" - else: - # Either none of the unit arguments were set to True or more than - # one of the unit arguments was set to True. In either case, - # return the central wavelength in the default units of meters. - output_units = "meters" - - if dispersion is not None: - - dispersion = gmu.convert_units('meters', dispersion, output_units) - + dispersion = self.phu[keyword] if not self.is_single: dispersion = [dispersion] * len(self) + else: + return None return dispersion diff --git a/gemini_instruments/ghost/adclass.py b/gemini_instruments/ghost/adclass.py index 824d47a1e4..4db3e2b60f 100644 --- a/gemini_instruments/ghost/adclass.py +++ b/gemini_instruments/ghost/adclass.py @@ -15,6 +15,8 @@ from gemini_instruments.gemini import AstroDataGemini from gemini_instruments.common import build_group_id +from .. import gmu + def return_dict_for_bundle(desc_fn): """ @@ -393,8 +395,8 @@ def calibration_key(self): # FIXME Remove once headers corrected @astro_data_descriptor - def central_wavelength(self, asMicrometers=False, asNanometers=False, - asAngstroms=False): # pragma: no cover + @gmu.return_selected_units + def central_wavelength(self): # pragma: no cover """ Dummy to work around current Gemini cal_mgr """ @@ -403,21 +405,13 @@ def central_wavelength(self, asMicrometers=False, asNanometers=False, if val is None: if self.arm() == 'red': - val = 7500. * 10**-10 + val = 0.75 elif self.arm() == 'blue': - val = 4400. * 10**-10 + val = 0.44 else: return None - - if asMicrometers: - val *= 10**6 - elif asNanometers: - val *= 10**9 - elif asAngstroms: - val *= 10**10 - - return float(val) + return val @astro_data_descriptor @return_dict_for_bundle diff --git a/gemini_instruments/gmos/adclass.py b/gemini_instruments/gmos/adclass.py index 549706ea70..095dff341d 100644 --- a/gemini_instruments/gmos/adclass.py +++ b/gemini_instruments/gmos/adclass.py @@ -207,43 +207,18 @@ def array_name(self): return self.hdr.get('AMPNAME') @astro_data_descriptor - def central_wavelength(self, asMicrometers=False, asNanometers=False, - asAngstroms=False, pretty=False): + @gmu.return_requested_units + def central_wavelength(self, pretty=False): """ - Returns the central wavelength in meters or specified units - - 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 - pretty : bool - If True, return a round up value to the nearest Angstrom. + Returns the central wavelength in microns Returns ------- float - The central wavelength setting - """ - unit_arg_list = [asMicrometers, asNanometers, asAngstroms] - 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" - else: - # Either none of the unit arguments were set to True or more than - # one of the unit arguments was set to True. In either case, - # return the central wavelength in the default units of meters. - output_units = "meters" + The central wavelength setting in um + """ # Keywords should be the same, but CENTWAVE was only added post-2007 + # Header value is in microns try: central_wavelength = self.phu['CENTWAVE'] except KeyError: @@ -251,18 +226,12 @@ def central_wavelength(self, asMicrometers=False, asNanometers=False, if central_wavelength <= 0.0: return None - else: - converted_central_wavelength = \ - gmu.convert_units('nanometers', central_wavelength, - output_units) - if pretty: - # round it up to the nearest Angstrom. - power = gmu.unitDict[output_units] - gmu.unitDict['angstroms'] - factor = math.pow(10, power) - converted_central_wavelength = round(converted_central_wavelength*factor)/factor - return converted_central_wavelength + if pretty: + # round it to the nearest Angstrom. + central_wavelength = round(10 * central_wavelength) / 10 + return central_wavelength @astro_data_descriptor def detector_name(self, pretty=False): @@ -461,43 +430,18 @@ def disperser(self, stripID=False, pretty=False): return disperser @astro_data_descriptor - def dispersion(self, asMicrometers=False, asNanometers=False, asAngstroms=False): + @gmu.return_requested_units + def dispersion(self): """ - Returns the dispersion in meters per binned pixel as a list (one value per + Returns the dispersion in microns per binned pixel as a list (one value per extension) or a float if used on a single-extension slice. It is possible to control the units of wavelength using the input arguments. - 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 - Returns ------- list/float The dispersion(s) """ - unit_arg_list = [asMicrometers, asNanometers, asAngstroms] - - 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" - else: - # Either none of the unit arguments were set to True or more than - # one of the unit arguments was set to True. In either case, - # return the central wavelength in the default units of meters. - output_units = "meters" - # This was breaking before try: grule = float(self.disperser(pretty=True)[1:]) @@ -530,8 +474,7 @@ def dispersion(self, asMicrometers=False, asNanometers=False, asAngstroms=False) if dispersion is not None: grating_order = self.phu.get('GRORDER', 1) - dispersion = gmu.convert_units('meters', dispersion / grating_order, - output_units) + dispersion = 1e-6 * dispersion / grating_order if not self.is_single: dispersion = [dispersion] * len(self) diff --git a/gemini_instruments/gmu.py b/gemini_instruments/gmu.py index 60ee6f8664..8b42f45172 100644 --- a/gemini_instruments/gmu.py +++ b/gemini_instruments/gmu.py @@ -2,7 +2,9 @@ import math import re -from astropy import coordinates, units +from functools import wraps + +from astropy import coordinates, units as u # The unitDict dictionary defines the factors for the function # convert_units @@ -103,6 +105,41 @@ def convert_units(input_units, input_value, output_units): if input_value is not None: return input_value * factor + +def return_requested_units(fn): + """ + Decorator that replaces the repeated code for asMicrometers, + asNanometers, asAngstroms. Should be replaced by a "units='nm'" + parameter, but time is limited. Keeping current coding to avoid + """ + @wraps(fn) + def gn(instance, asMicrometers=False, asNanometers=False, asAngstroms=False, + **kwargs): + unit_arg_list = [asMicrometers, asNanometers, asAngstroms] + output_units = u.m # 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 = u.um + elif asNanometers: + output_units = u.nm + else: + output_units = u.AA + + # Ensure we return a list, not an array + # nm are the "standard" DRAGONS wavelength unit + retval = fn(instance, **kwargs) + if retval is None: + return retval + if isinstance(retval, list): + return [None if v is None else (v * u.nm).to(output_units).value + for v in retval] + return (fn(instance) * u.nm).to(output_units).value + + return gn + + def toicrs(frame, ra, dec, equinox=2000.0, ut_datetime=None): # Utility function. Converts and RA and Dec in the specified reference frame # and equinox at ut_datetime into ICRS. This is used by the ra and dec descriptors. @@ -124,12 +161,12 @@ def toicrs(frame, ra, dec, equinox=2000.0, ut_datetime=None): # Try this with the passed frame but, if it doesn't work, convert to "cirs" # If that doesn't work, then raise an error try: - coords = coordinates.SkyCoord(ra=ra*units.degree, dec=dec*units.degree, + coords = coordinates.SkyCoord(ra=ra*u.degree, dec=dec*u.degree, frame=frame, equinox=equinox, obstime=ut_datetime) except ValueError: frame = 'cirs' - coords = coordinates.SkyCoord(ra=ra*units.degree, dec=dec*units.degree, + coords = coordinates.SkyCoord(ra=ra*u.degree, dec=dec*u.degree, frame=frame, equinox=equinox, obstime=ut_datetime) @@ -146,7 +183,7 @@ def toicrs(frame, ra, dec, equinox=2000.0, ut_datetime=None): astrom, eo = erfa.apci13(coords.obstime.jd1, coords.obstime.jd2) # eo comes back as a single element array in radians eo = float(eo) - eo = eo * units.radian + eo = eo * u.radian # re-create the coords frame object with the corrected ra coords = coordinates.SkyCoord(ra=coords.ra+eo, dec=coords.dec, frame=coords.frame.name, diff --git a/gemini_instruments/gnirs/adclass.py b/gemini_instruments/gnirs/adclass.py index 7843522f3f..798402608f 100644 --- a/gemini_instruments/gnirs/adclass.py +++ b/gemini_instruments/gnirs/adclass.py @@ -91,25 +91,17 @@ def array_name(self): return self.phu.get(self._keyword_for('array_name')) @astro_data_descriptor - def dispersion(self, asMicrometers=False, asNanometers=False, asAngstroms=False): + @gmu.return_requested_units + def dispersion(self,): """ Returns the dispersion in meters per pixel as a list (one value per extension) or a float if used on a single-extension slice. It is possible to control the units of wavelength using the input arguments. - 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 - Returns ------- list/float - The dispersion(s) + The dispersion(s) in microns """ grating = self._grating(pretty=True, stripID=True) @@ -122,29 +114,13 @@ def dispersion(self, asMicrometers=False, asNanometers=False, asAngstroms=False) camera = None filter = str(self.filter_name(pretty=True))[0] - config = f"{grating}, {camera}" - dispersion = dispersion_by_config.get(config, {}).get(filter) + dispersion = dispersion_by_config.get((grating, camera), {}).get(filter) if dispersion is None: return None - 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" - - if dispersion is not None: - dispersion = gmu.convert_units('angstroms', dispersion, output_units) - - if not self.is_single: - dispersion = [dispersion] * len(self) + if not self.is_single: + dispersion = [dispersion] * len(self) return dispersion diff --git a/gemini_instruments/graces/adclass.py b/gemini_instruments/graces/adclass.py index 3ab4c7d604..f2789f8af0 100644 --- a/gemini_instruments/graces/adclass.py +++ b/gemini_instruments/graces/adclass.py @@ -35,43 +35,17 @@ def _tag_bias(self): return TagSet(['BIAS', 'CAL']) @astro_data_descriptor - def central_wavelength(self, asMicrometers=False, asNanometers=False, - asAngstroms=False): + @gmu.return_requested_units + def central_wavelength(self): """ - Returns the central wavelength in meters or the specified units - - 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 + Returns the central wavelength in microns Returns ------- float The central wavelength setting - """ - unit_arg_list = [asMicrometers, asNanometers, asAngstroms] - 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" - else: - # Either none of the unit arguments were set to True or more than - # one of the unit arguments was set to True. In either case, - # return the central wavelength in the default units of meters. - output_units = "meters" - - return gmu.convert_units('micrometers', 0.7, output_units) + return 0.7 @astro_data_descriptor def dec(self): diff --git a/gemini_instruments/gsaoi/adclass.py b/gemini_instruments/gsaoi/adclass.py index f7699b794c..cdffca9ad9 100644 --- a/gemini_instruments/gsaoi/adclass.py +++ b/gemini_instruments/gsaoi/adclass.py @@ -67,48 +67,21 @@ def array_name(self): return self.phu.get('DETECTOR') @astro_data_descriptor - def central_wavelength(self, asMicrometers=False, asNanometers=False, - asAngstroms=False): + @gmu.return_requested_units + def central_wavelength(self): """ - Returns the central wavelength in meters or the specified units - - 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 + Returns the central wavelength in microns Returns ------- float - The central wavelength setting - + The central wavelength setting in um """ - unit_arg_list = [asMicrometers, asNanometers, asAngstroms] - 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" - else: - # Either none of the unit arguments were set to True or more than - # one of the unit arguments was set to True. In either case, - # return the central wavelength in the default units of meters. - output_units = "meters" - - central_wavelength = self.phu.get('WAVELENG', -1) + central_wavelength = self.phu.get('WAVELENG', -1) # in Angstroms if central_wavelength < 0.0: return None - else: - return gmu.convert_units('angstroms', central_wavelength, - output_units) + + return 0.1 * central_wavelength @returns_list @use_keyword_if_prepared diff --git a/gemini_instruments/niri/adclass.py b/gemini_instruments/niri/adclass.py index 2425903052..7795a3498f 100644 --- a/gemini_instruments/niri/adclass.py +++ b/gemini_instruments/niri/adclass.py @@ -78,41 +78,16 @@ def array_section(self, pretty=False): return build_ir_section(self, pretty) @astro_data_descriptor - def central_wavelength(self, asMicrometers=False, asNanometers=False, - asAngstroms=False): + @gmu.return_requested_units + def central_wavelength(self): """ - Returns the central wavelength in meters or the specified units - - 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 + Returns the central wavelength in microns Returns ------- float - The central wavelength setting - """ - unit_arg_list = [asMicrometers, asNanometers, asAngstroms] - 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" - else: - # Either none of the unit arguments were set to True or more than - # one of the unit arguments was set to True. In either case, - # return the central wavelength in the default units of meters. - output_units = "meters" - + The central wavelength setting in um + """ # Use the lookup dict, keyed on camera, focal_plane_mask and grism camera = self.camera() try: @@ -122,11 +97,9 @@ def central_wavelength(self, asMicrometers=False, asNanometers=False, fpmask = self.focal_plane_mask(stripID=True) try: - wave_in_angstroms = lookup.spec_wavelengths[camera, fpmask, disperser][0] + return lookup.spec_wavelengths[camera, fpmask, disperser].cenwave except KeyError: return None - return gmu.convert_units('angstroms', wave_in_angstroms, - output_units) @astro_data_descriptor def data_section(self, pretty=False): @@ -278,28 +251,18 @@ def disperser(self, stripID=False, pretty=False): return 'MIRROR' @astro_data_descriptor - def dispersion(self, asMicrometers=False, asNanometers=False, asAngstroms=False): + @gmu.return_requested_units + def dispersion(self): """ Returns the dispersion in meters per pixel as a list (one value per extension) or a float if used on a single-extension slice. It is possible to control the units of wavelength using the input arguments. - 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 - Returns ------- list/float The dispersion(s) - """ - camera = self.camera() try: disperser = self.disperser(stripID=True)[0:6] @@ -311,22 +274,7 @@ def dispersion(self, asMicrometers=False, asNanometers=False, asAngstroms=False) except KeyError: dispersion = None - 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" - - if dispersion is not None: - dispersion = gmu.convert_units('angstroms', dispersion, output_units) - - if not self.is_single: + if dispersion is not None and not self.is_single: dispersion = [dispersion] * len(self) return dispersion diff --git a/gemini_instruments/trecs/adclass.py b/gemini_instruments/trecs/adclass.py index d0dc68edbf..003adf680a 100644 --- a/gemini_instruments/trecs/adclass.py +++ b/gemini_instruments/trecs/adclass.py @@ -28,41 +28,16 @@ def _type_mode(self): return TagSet(['SPECT']) @astro_data_descriptor - def central_wavelength(self, asMicrometers=False, asNanometers=False, - asAngstroms=False): + @gmu.return_requested_units + def central_wavelength(self): """ - Returns the central wavelength in meters or specified units - - 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 + Returns the central wavelength in microns Returns ------- float The central wavelength setting """ - unit_arg_list = [asMicrometers, asNanometers, asAngstroms] - 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" - else: - # Either none of the unit arguments were set to True or more than - # one of the unit arguments was set to True. In either case, - # return the central wavelength in the default units of meters. - output_units = "meters" - disperser = self.disperser() if disperser is None: return None @@ -74,7 +49,7 @@ def central_wavelength(self, asMicrometers=False, asNanometers=False, wave_in_microns = self.phu.get('HRCENWL') else: return None - return gmu.convert_units('micrometers', wave_in_microns, output_units) + return wave_in_microns * 1000 @astro_data_descriptor def detector_x_offset(self): @@ -109,44 +84,18 @@ def detector_y_offset(self): return None @astro_data_descriptor - def dispersion(self, asMicrometers=False, asNanometers=False, - asAngstroms=False): + @gmu.return_requested_units + def dispersion(self): """ - Returns the dispersion in meters per pixel as a list (one value per + Returns the dispersion in microns per pixel as a list (one value per extension) or a float if used on a single-extension slice. It is possible to control the units of wavelength using the input arguments. - 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 - Returns ------- list/float The dispersion(s) """ - # Look for the relevant, which we assume is in meters per pixel - unit_arg_list = [asMicrometers, asNanometers, asAngstroms] - 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" - else: - # Either none of the unit arguments were set to True or more than - # one of the unit arguments was set to True. In either case, - # return the central wavelength in the default units of meters. - output_units = "meters" - disperser = self.disperser() if disperser == 'LowRes-10': dispersion = 0.022 @@ -155,8 +104,8 @@ def dispersion(self, asMicrometers=False, asNanometers=False, elif disperser.startswith('HighRes-10'): dispersion = 0.0019 else: - dispersion = None - return gmu.convert_units('micrometers', dispersion, output_units) + return None + return dispersion * 1000 @returns_list @astro_data_descriptor