def dispersion(self, dataset, asMicrometers=False, asNanometers=False,
                asAngstroms=False, **args):
     # Currently for TRECS data, the dispersion is recorded in meters (?)
     input_units = "meters"
     
     # Determine the output units to use
     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
         # dispersion 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 dispersion in the default units of meters
         output_units = "meters"
     
     # Determine the dispersion keyword from the global keyword dictionary
     keyword = self.get_descriptor_key("key_dispersion")
     
     # Get the value of the dispersion keyword from the header of the PHU
     raw_dispersion = dataset.phu_get_key_value(keyword)
     
     if raw_dispersion is None:
         # The get_key_value() function returns None if a value cannot be
         # found and stores the exception info. Re-raise the exception. It
         # will be dealt with by the CalculatorInterface.
         if hasattr(dataset, "exception_info"):
             raise dataset.exception_info
     
     if disperser == "LowRes-10":
         dispersion = 0.022
     elif disperser == "LowRes-20":
         dispersion = 0.033
     elif disperser == "Mirror":
         raise Errors.DescriptorTypeError()
     else:
         raise Errors.CalcError()
     
     # Use the utilities function convert_units to convert the dispersion
     # value from the input units to the output units
     ret_dispersion = GemCalcUtil.convert_units(
         input_units=input_units, input_value=dispersion,
         output_units=output_units)
     
     # Instantiate the return DescriptorValue (DV) object
     ret_dv = DescriptorValue(ret_dispersion, name="dispersion", ad=dataset)
     
     return ret_dv
 def central_wavelength(self, dataset, asMicrometers=False,
                        asNanometers=False, asAngstroms=False, **args):
     # For TRECS data, the central wavelength is recorded in
     # micrometers - it's actually hardwired by disperser below.
     input_units = "micrometers"
     
     # Determine the output units to use
     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"
     
     # Determine the disperser keyword from the global keyword dictionary
     keyword = self.get_descriptor_key("key_disperser")
     
     # Get the value of the disperser keyword from the header of the PHU
     disperser = dataset.phu_get_key_value(keyword)
     
     if disperser is None:
         # The phu_get_key_value() function returns None if a value cannot
         # be found and stores the exception info. Re-raise the exception.
         # It will be dealt with by the CalculatorInterface.
         if hasattr(dataset, "exception_info"):
             raise dataset.exception_info
     
     if disperser == "LowRes-10":
         central_wavelength = 10.5
     elif disperser == "LowRes-20":
         central_wavelength = 20.0
     
     # Sometimes the header value takes the form "HighRes-10 + 230" or
     # similar
     elif disperser.startswith("HighRes-10"):
         
         # There is a HRCENWL keyword that contains the central wavelength
         # only if we are using the HighRes-10 grating
         central_wavelength = dataset.phu_get_key_value(
             self.get_descriptor_key("key_central_wavelength"))
     
     elif disperser == "Mirror":
         raise Errors.DescriptorTypeError()
     else:
         raise Errors.CalcError()
     
     # Use the utilities function convert_units to convert the central
     # wavelength value from the input units to the output units
     ret_central_wavelength = GemCalcUtil.convert_units(
         input_units=input_units, input_value=central_wavelength,
         output_units=output_units)
     
     # Instantiate the return DescriptorValue (DV) object
     ret_dv = DescriptorValue(ret_central_wavelength,
                              name="central_wavelength", ad=dataset)
     return ret_dv
 def central_wavelength(self, dataset, asMicrometers=False,
                        asNanometers=False, asAngstroms=False, **args):
     # Currently for NIRI data, the central wavelength is recorded in
     # angstroms
     input_units = "angstroms"
     
     # Determine the output units to use
     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 from nsappwave can only be obtained from data
     # that does not have an AstroData Type of IMAGE
     if "IMAGE" not in dataset.types:
         
         # Get the focal plane mask and disperser values using the
         # appropriate descriptors
         focal_plane_mask = dataset.focal_plane_mask()
         disperser = dataset.disperser(stripID=True)
         
         if focal_plane_mask is None or disperser is None:
             # The descriptor functions return None if a value cannot be
             # found and stores the exception info. Re-raise the exception.
             # It will be dealt with by the CalculatorInterface.
             if hasattr(dataset, "exception_info"):
                 raise dataset.exception_info
         
         # Get the central wavelength value from the nsappwave lookup
         # table
         count = 0
         for row in self.nsappwave.data:
             if (focal_plane_mask == row.field("MASK") and
                 disperser == row.field("GRATING")):
                 count += 1
                 if row.field("LAMBDA"):
                     raw_central_wavelength = float(row.field("LAMBDA"))
                 else:
                     raise Errors.TableValueError()
         if count == 0:
             raise Errors.TableKeyError()
         
         # Use the utilities function convert_units to convert the central
         # wavelength value from the input units to the output units
         ret_central_wavelength = GemCalcUtil.convert_units(
             input_units=input_units,
             input_value=float(raw_central_wavelength),
             output_units=output_units)
     else:
         raise Errors.DescriptorTypeError()
     
     # Instantiate the return DescriptorValue (DV) object
     ret_dv = DescriptorValue(ret_central_wavelength,
                              name="central_wavelength", ad=dataset)
     return ret_dv