def disperser(self, dataset, stripID=False, pretty=False, **args):
     if pretty:
         stripID = True
     
     # GNIRS contains two dispersers - the grating and the prism. Get the
     # grating and the prism values using the appropriate descriptors
     grating = dataset.grating(stripID=stripID, pretty=pretty).as_pytype()
     prism = dataset.prism(stripID=stripID, pretty=pretty)
     
     if grating is None or prism 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
     
     if stripID:
         if pretty and prism.startswith("MIR"):
             # Return the stripped and pretty disperser string. If the
             # prism is a mirror, don't list it in the pretty disperser. 
             disperser = gmu.removeComponentID(grating)
         else:
             # Return the stripped disperser string
             disperser = "%s&%s" % (gmu.removeComponentID(grating),
                                    gmu.removeComponentID(prism))
     else:
         # Return the disperser string
         disperser = "%s&%s" % (grating, prism)
     
     ret_disperser = str(disperser)
     
     # Instantiate the return DescriptorValue (DV) object
     ret_dv = DescriptorValue(ret_disperser, name="disperser", ad=dataset)
     
     return ret_dv
 def filter_name(self, dataset, stripID=False, pretty=False, **args):
     if pretty:
         # To match against the lookup table to get the pretty name, we
         # need the component IDs attached
         stripID = False
     
     # Determine the three filter name keyword from the global keyword
     # dictionary
     keyword1 = self.get_descriptor_key("key_filter1")
     keyword2 = self.get_descriptor_key("key_filter2")
     keyword3 = self.get_descriptor_key("key_filter3")
     
     # Get the values of the three filter name keywords from the header of
     # the PHU
     filter1 = dataset.phu_get_key_value(keyword1)
     filter2 = dataset.phu_get_key_value(keyword2)
     filter3 = dataset.phu_get_key_value(keyword3)
     
     if filter1 is None or filter2 is None or filter3 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 stripID:
         filter1 = gmu.removeComponentID(filter1)
         filter2 = gmu.removeComponentID(filter2)
         filter3 = gmu.removeComponentID(filter3)
     
     # Create list of filter values
     filters = [filter1, filter2, filter3]
     
     if pretty:
         # To match against the lookup table, the filter list must be sorted
         filters.sort()
         filter_name = gmu.filternameFrom(filters)
         if filter_name in self.niriFilternameMap:
             ret_filter_name = str(self.niriFilternameMap[filter_name])
         else:
             ret_filter_name = str(filter_name)
     else:
         ret_filter_name = gmu.filternameFrom(filters)
     
     # Instantiate the return DescriptorValue (DV) object
     ret_dv = DescriptorValue(ret_filter_name, name="filter_name",
                              ad=dataset)
     return ret_dv
 def filter_name(self, dataset, stripID=False, pretty=False, **args):
     # Determine the filter name keyword from the global keyword dictionary
     keyword = self.get_descriptor_key("key_filter_name")
     
     # Get the value of the filter name keyword from the header of the PHU
     filter_name = dataset.phu_get_key_value(keyword)
     
     if filter_name 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 pretty:
         stripID = True
     if stripID:
         # Return the stripped filter name string
         ret_filter_name = gmu.removeComponentID(filter_name)
     else:
         # Return the filter name string
         ret_filter_name = str(filter_name)
     if filter_name == "Blocked":
         ret_filter_name = "blank"
     
     # Instantiate the return DescriptorValue (DV) object
     ret_dv = DescriptorValue(ret_filter_name, name="filter_name",
                              ad=dataset)
     return ret_dv
 def disperser(self, dataset, stripID=False, pretty=False, **args):
     if pretty:
         stripID = True
     
     # 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 stripID:
         # Return the stripped disperser string
         ret_disperser = gmu.removeComponentID(disperser)
     else:
         # Return the disperser string
         ret_disperser = str(disperser)
     
     # Instantiate the return DescriptorValue (DV) object
     ret_dv = DescriptorValue(ret_disperser, name="disperser", ad=dataset)
     
     return ret_dv
 def slit(self, dataset, stripID=False, pretty=False, **args):
     """
     Note that in GNIRS all the slits are machined into one physical piece
     of metal, which is on a slide - the mechanism simply slides the slide
     along to put the right slit in the beam. Thus all the slits have the
     same component ID as they're they same physical component.
     """
     # Determine the slit keyword from the global keyword dictionary
     keyword = self.get_descriptor_key("key_slit")
     
     # Get the value of the slit keyword from the header of the PHU
     slit = dataset.phu_get_key_value(keyword)
     
     if slit 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 stripID or pretty:
         ret_slit = gmu.removeComponentID(slit)
     else:
         ret_slit = str(slit)
     
     # Instantiate the return DescriptorValue (DV) object
     ret_dv = DescriptorValue(ret_slit, name="slit", ad=dataset)
     
     return ret_dv
 def prism(self, dataset, stripID=False, pretty=False, **args):
     """
     Note. A CC software change approx July 2010 changed the prism names to
     also include the camera, eg 32/mmSB_G5533 indicates the 32/mm grating
     with the Short Blue camera. This is unhelpful as if we wanted to know
     the camera, we'd call the camera descriptor. Thus, this descriptor
     function repairs the header values to only list the prism.
     """
     # Determine the prism keyword from the global keyword dictionary
     keyword = self.get_descriptor_key("key_prism")
     
     # Get the value of the prism keyword from the header of the PHU.
     prism = dataset.phu_get_key_value(keyword)
     
     if prism 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
     
     # The format of the prism string is currently (2011) [CAM+]prism_Gnnnn
     # CAM is the camera: {L|S}{B|R}[{L|S}[X]}
     # + is a literal "+"
     # prism is the actual prism name
     # nnnn is the 4 digit component ID.
     cre = re.compile("([LBSR]*\+)*([A-Z]*)(_G)(\d+)")
     m = cre.match(prism)
     if m:
         parts = m.groups()
         # parts is a tuple containing four elements, where the first
         # element is optional (i.e., it could be None). Contruct the
         # appropriate prism name.
         if parts[0] is not None:
             ret_prism = "%s%s%s%s" % (
               parts[0], parts[1], parts[2], parts[3])
         else:
             ret_prism = "%s%s%s" % (parts[1], parts[2], parts[3])
         if stripID or pretty:
             ret_prism = gmu.removeComponentID(ret_prism)
     else:
         ret_prism = prism
     
     # Instantiate the return DescriptorValue (DV) object
     ret_dv = DescriptorValue(ret_prism, name="prism", ad=dataset)
     
     return ret_dv
 def grating(self, dataset, stripID=False, pretty=False, **args):
     """
     Note. A CC software change approx July 2010 changed the grating names
     to also include the camera, eg 32/mmSB_G5533 indicates the 32/mm
     grating with the Short Blue camera. This is unhelpful as if we wanted
     to know the camera, we'd call the camera descriptor. Thus, this
     descriptor function repairs the header values to only list the grating.
     """
     # Determine the grating keyword from the global keyword dictionary
     keyword = self.get_descriptor_key("key_grating")
     
     # Get the value of the grating keyword from the header of the PHU
     grating = dataset.phu_get_key_value(keyword)
     
     if grating 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
     
     # The format of the grating string is currently (2011) nnn/mmCAM_Gnnnn
     # nnn is a 2 or 3 digit number (lines per mm)
     # /mm is literally "/mm"
     # CAM is the camera: {L|S}{B|R}[{L|S}[X]}
     # _G is literally "_G"
     # nnnn is the 4 digit component ID.
     cre = re.compile("([\d/m]+)([A-Z]*)(_G)(\d+)")
     m = cre.match(grating)
     if m:
         parts = m.groups()
         ret_grating = "%s%s%s" % (parts[0], parts[2], parts[3])
     else:
         # If the regex didn't match, just pass through the raw value
         ret_grating = grating
     if stripID or pretty:
         ret_grating = gmu.removeComponentID(ret_grating)
     
     # Instantiate the return DescriptorValue (DV) object
     ret_dv = DescriptorValue(ret_grating, name="grating", ad=dataset)
     
     return ret_dv
 def disperser(self, dataset, stripID=False, pretty=False, **args):
     if pretty:
         stripID = True
     
     # Disperser can only ever be in key_filter3 because the other two
     # wheels are in an uncollimated beam. Determine the filter name keyword
     # from the global keyword dictionary
     keyword = self.get_descriptor_key("key_filter3")
     
     # Get the value of the filter name keyword from the header of the PHU
     filter3 = dataset.phu_get_key_value(keyword)
     
     if filter3 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
     
     # Check if the filter name contains the string "grism". If it does, set
     # the disperser to the filter name value
     if "grism" in filter3:
         disperser = filter3
     else:
         # If the filter name value does not contain the string "grism",
         # return MIRROR like GMOS
         disperser = "MIRROR"
     
     if stripID and disperser is not "MIRROR":
         # Return the disperser string with the component ID stripped
         ret_disperser = gmu.removeComponentID(disperser)
     else:
         # Return the disperser string
         ret_disperser = str(disperser)
     
     # Instantiate the return DescriptorValue (DV) object
     ret_dv = DescriptorValue(ret_disperser, name="disperser", ad=dataset)
     
     return ret_dv
 def pupil_mask(self, dataset, stripID=False, pretty=False, **args):
     if pretty:
         stripID = True
     
     # Determine the filter name keyword from the global keyword dictionary
     keyword = self.get_descriptor_key("key_filter3")
     
     # Get the value of the filter name keyword from the header of the PHU
     filter3 = dataset.phu_get_key_value(keyword)
     
     if filter3 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
     
     # Check if the filter name contains the string "grism". If it does, set
     # the disperser to the filter name value
     if filter3.startswith("pup"):
         pupil_mask = filter3
     else:
         # If the filter name value does not contain the string "grism",
         # return MIRROR like GMOS
         pupil_mask = "MIRROR"
     
     if stripID and pupil_mask is not "MIRROR":
         # Return the pupil mask string with the component ID stripped
         ret_pupil_mask = gmu.removeComponentID(pupil_mask)
     else:
         # Return the pupil_mask string
         ret_pupil_mask = str(pupil_mask)
     
     # Instantiate the return DescriptorValue (DV) object
     ret_dv = DescriptorValue(ret_pupil_mask, name="pupil_mask", ad=dataset)
     
     return ret_dv
Example #10
0
 def lyot_stop(self, dataset, stripID=False, pretty=False, **args):
     # Determine the lyot stop keywords from the global keyword dictionary
     keyword = self.get_descriptor_key("key_lyot_stop")
     
     # Get the value of the lyot stop keywords from the header of the PHU 
     lyot_stop = dataset.phu_get_key_value(keyword)
     
     if lyot_stop 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 stripID or pretty:
         # Strip the component ID from the two filter name values
         ret_lyot_stop = gmu.removeComponentID(lyot_stop)
     else:
         ret_lyot_stop = lyot_stop
     
     # Instantiate the return DescriptorValue (DV) object
     ret_dv = DescriptorValue(ret_lyot_stop, name="lyot_stop", ad=dataset)
     
     return ret_dv
 def filter_name(self, dataset, stripID=False, pretty=False, **args):
     # Since this descriptor function accesses keywords in the headers of
     # the pixel data extensions, always construct a dictionary where the
     # key of the dictionary is an (EXTNAME, EXTVER) tuple.
     ret_filter_name = {}
     
     # For NICI, the red filter is defined in the first science extension,
     # while the blue filter is defined in the second science extension.
     #
     # Determine the filter name keyword from the global keyword dictionary 
     keyword1 = self.get_descriptor_key("key_filter_r")
     keyword2 = self.get_descriptor_key("key_filter_b")
     
     # Get the value of the filter name keyword from the header of each
     # pixel data extension as a dictionary where the key of the dictionary
     # is an ("*", EXTVER) tuple
     filter_dict = gmu.get_key_value_dict(adinput=dataset,
                                          keyword=[keyword1, keyword2])
     
     filter_r_dict = filter_dict[keyword1]
     filter_b_dict = filter_dict[keyword2]
     
     # The following code contains duplication so that the case when a user
     # loops over extensions in an AstroData object and calls the
     # filter_name descriptor on each extension, i.e.,
     #
     #   for ext in ad:
     #       print ext.filter_name()
     #
     # is handled appropriately. There may be a better way to do this ...
     if filter_r_dict is None:
         if filter_b_dict is None:
             # The get_key_value_dict() 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
         else:
             for ext_name_ver, filter_b in filter_b_dict.iteritems():
                 if filter_b is None:
                     raw_filter = None
                 else:
                     raw_filter = filter_b
                 
                 if pretty:
                     stripID = True
                 if stripID:
                     # Strip the component ID from the filter name value
                     if raw_filter is not None:
                         filter = gmu.removeComponentID(raw_filter)
                 else:
                     filter = raw_filter
                 
                 # Update the dictionary with the filter name value
                 ret_filter_name.update({ext_name_ver:filter})
     else:
         for ext_name_ver, filter_r in filter_r_dict.iteritems():
             if filter_b_dict is not None:
                 filter_b = filter_b_dict[ext_name_ver]
             else:
                 filter_b = None
             
             if filter_r is None and filter_b is None:
                 raw_filter = None
             elif filter_r is None and filter_b is not None:
                 raw_filter = filter_b
             elif filter_r is not None and filter_b is None:
                 raw_filter = filter_r
             else:
                 # Both filter_r and filter_b are defined for a single
                 # extension, which is incorrect 
                 raise Errors.CorruptDataError()
             
             if pretty:
                 stripID = True
             if stripID:
                 # Strip the component ID from the filter name value
                 if raw_filter is not None:
                     filter = gmu.removeComponentID(raw_filter)
             else:
                 filter = raw_filter
             
             # Update the dictionary with the filter name value
             ret_filter_name.update({ext_name_ver:filter})
     
     # Instantiate the return DescriptorValue (DV) object
     ret_dv = DescriptorValue(ret_filter_name, name="filter_name",
                              ad=dataset)
     return ret_dv
Example #12
0
 def filter_name(self, dataset, stripID=False, pretty=False, **args):
     # Get the UT date using the appropriate descriptor
     ut_date_dv = dataset.ut_date()
     
     if ut_date_dv.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
     
     ut_date = str(ut_date_dv)
     
     obs_ut_date = datetime(*strptime(ut_date, "%Y-%m-%d")[0:6])
     
     # Old commissioning data was taken before March 1, 2010
     old_ut_date = datetime(2010, 3, 1, 0, 0)
     
     if obs_ut_date > old_ut_date:
         # Determine the two filter name keywords from the global keyword
         # dictionary
         keyword1 = self.get_descriptor_key("key_filter1")
         keyword2 = self.get_descriptor_key("key_filter2")
         
     else:
         # Make sure the filter_name descriptor is backwards compatible with
         # old engineering data
         #
         # Determine the two filter name keywords from the global keyword
         # dictionary
         keyword1 = self.get_descriptor_key("key_old_filter1")
         keyword2 = self.get_descriptor_key("key_old_filter2")
         
     # Get the value of the two filter name keywords from the header of the
     # PHU 
     filter1 = dataset.phu_get_key_value(keyword1)
     filter2 = dataset.phu_get_key_value(keyword2)
     
     if None in [filter1, filter2]:
         # 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 stripID or pretty:
         # Strip the component ID from the two filter name values
         filter1 = gmu.removeComponentID(filter1)
         filter2 = gmu.removeComponentID(filter2)
     
     filter = []
     if pretty:
         # Remove any filters that have the value "open" or "Open"
         if "open" not in filter1 and "Open" not in filter1:
             filter.append(str(filter1))
         if "open" not in filter2 and "Open" not in filter2:
             filter.append(str(filter2))
         if len(filter) == 0:
             filter = ["open"]
         
         if "Block" in filter1 or "Block" in filter2:
             filter = ["blank"]
         if "Dark" in filter1 or "Dark" in filter2:
             filter = ["blank"]
         if "DK" in filter1 or "DK" in filter2:
             filter = ["dark"]
     else:
         filter = [filter1, filter2]
     
     if len(filter) > 1:
         # Concatenate the filter names with "&"
         ret_filter_name = "%s&%s" % (filter[0], filter[1])
     else:
         ret_filter_name = str(filter[0])
     
     # Instantiate the return DescriptorValue (DV) object
     ret_dv = DescriptorValue(ret_filter_name, name="filter_name",
                              ad=dataset)
     return ret_dv