LSSTApplications  10.0+286,10.0+36,10.0+46,10.0-2-g4f67435,10.1+152,10.1+37,11.0,11.0+1,11.0-1-g47edd16,11.0-1-g60db491,11.0-1-g7418c06,11.0-2-g04d2804,11.0-2-g68503cd,11.0-2-g818369d,11.0-2-gb8b8ce7
LSSTDataManagementBasePackage
Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
lsst.pipe.tasks.ingest.ParseTask Class Reference
Inheritance diagram for lsst.pipe.tasks.ingest.ParseTask:

Public Member Functions

def getInfo
 
def getInfoFromMetadata
 
def translate_date
 
def translate_filter
 
def getDestination
 

Static Public Member Functions

def getExtensionName
 

Static Public Attributes

 ConfigClass = ParseConfig
 

Detailed Description

Task that will parse the filename and/or its contents to get the required information
for putting the file in the correct location and populating the registry.

Definition at line 42 of file ingest.py.

Member Function Documentation

def lsst.pipe.tasks.ingest.ParseTask.getDestination (   self,
  butler,
  info,
  filename 
)
Get destination for the file

@param butler      Data butler
@param info        File properties, used as dataId for the butler
@param filename    Input filename
@return Destination filename

Definition at line 150 of file ingest.py.

151  def getDestination(self, butler, info, filename):
152  """Get destination for the file
153 
154  @param butler Data butler
155  @param info File properties, used as dataId for the butler
156  @param filename Input filename
157  @return Destination filename
158  """
159  raw = butler.get("raw_filename", info)[0]
160  # Ensure filename is devoid of cfitsio directions about HDUs
161  c = raw.find("[")
162  if c > 0:
163  raw = raw[:c]
164  return raw
def lsst.pipe.tasks.ingest.ParseTask.getExtensionName (   md)
static
Get the name of an extension.
@param md: PropertySet like one obtained from afwImage.readMetadata)
@return Name of the extension if it exists.  None otherwise.

Definition at line 79 of file ingest.py.

79 
80  def getExtensionName(md):
81  """ Get the name of an extension.
82  @param md: PropertySet like one obtained from afwImage.readMetadata)
83  @return Name of the extension if it exists. None otherwise.
84  """
85  try:
86  # This returns a tuple
87  ext = md.get("EXTNAME")
88  return ext[1]
90  return None
def lsst.pipe.tasks.ingest.ParseTask.getInfo (   self,
  filename 
)
Get information about the image from the filename and its contents

Here, we open the image and parse the header, but one could also look at the filename itself
and derive information from that, or set values from the configuration.

@param filename    Name of file to inspect
@return File properties; list of file properties for each extension

Definition at line 47 of file ingest.py.

47 
48  def getInfo(self, filename):
49  """Get information about the image from the filename and its contents
50 
51  Here, we open the image and parse the header, but one could also look at the filename itself
52  and derive information from that, or set values from the configuration.
53 
54  @param filename Name of file to inspect
55  @return File properties; list of file properties for each extension
56  """
57  md = afwImage.readMetadata(filename, self.config.hdu)
58  phuInfo = self.getInfoFromMetadata(md)
59  if len(self.config.extnames) == 0:
60  # No extensions to worry about
61  return phuInfo, [phuInfo]
62  # Look in the provided extensions
63  extnames = set(self.config.extnames)
64  extnum = 1
65  infoList = []
66  while len(extnames) > 0:
67  extnum += 1
68  try:
69  md = afwImage.readMetadata(filename, extnum)
70  except:
71  self.log.warn("Error reading %s extensions %s" % (filename, extnames))
72  break
73  ext = self.getExtensionName(md)
74  if ext in extnames:
75  infoList.append(self.getInfoFromMetadata(md, info=phuInfo.copy()))
76  extnames.discard(ext)
77  return phuInfo, infoList
boost::shared_ptr< daf::base::PropertySet > readMetadata(std::string const &fileName, int hdu=0, bool strip=false)
Return the metadata (header entries) from a FITS file.
def lsst.pipe.tasks.ingest.ParseTask.getInfoFromMetadata (   self,
  md,
  info = {} 
)
Attempt to pull the desired information out of the header

This is done through two mechanisms:
* translation: a property is set directly from the relevant header keyword
* translator: a property is set with the result of calling a method

The translator methods receive the header metadata and should return the
appropriate value, or None if the value cannot be determined.

@param md      FITS header
@param info    File properties, to be supplemented
@return info

Definition at line 91 of file ingest.py.

91 
92  def getInfoFromMetadata(self, md, info={}):
93  """Attempt to pull the desired information out of the header
94 
95  This is done through two mechanisms:
96  * translation: a property is set directly from the relevant header keyword
97  * translator: a property is set with the result of calling a method
98 
99  The translator methods receive the header metadata and should return the
100  appropriate value, or None if the value cannot be determined.
101 
102  @param md FITS header
103  @param info File properties, to be supplemented
104  @return info
105  """
106  for p, h in self.config.translation.iteritems():
107  if md.exists(h):
108  value = md.get(h)
109  if isinstance(value, basestring):
110  value = value.strip()
111  info[p] = value
112  elif p in self.config.defaults:
113  info[p] = self.config.defaults[p]
114  else:
115  self.log.warn("Unable to find value for %s (derived from %s)" % (p, h))
116  for p, t in self.config.translators.iteritems():
117  func = getattr(self, t)
118  try:
119  value = func(md)
120  except:
121  value = None
122  if value is not None:
123  info[p] = value
124  return info
def lsst.pipe.tasks.ingest.ParseTask.translate_date (   self,
  md 
)
Convert a full DATE-OBS to a mere date

Besides being an example of a translator, this is also generally useful.
It will only be used if listed as a translator in the configuration.

Definition at line 125 of file ingest.py.

126  def translate_date(self, md):
127  """Convert a full DATE-OBS to a mere date
128 
129  Besides being an example of a translator, this is also generally useful.
130  It will only be used if listed as a translator in the configuration.
131  """
132  date = md.get("DATE-OBS").strip()
133  c = date.find("T")
134  if c > 0:
135  date = date[:c]
136  return date
def lsst.pipe.tasks.ingest.ParseTask.translate_filter (   self,
  md 
)
Translate a full filter description into a mere filter name

Besides being an example of a translator, this is also generally useful.
It will only be used if listed as a translator in the configuration.

Definition at line 137 of file ingest.py.

138  def translate_filter(self, md):
139  """Translate a full filter description into a mere filter name
140 
141  Besides being an example of a translator, this is also generally useful.
142  It will only be used if listed as a translator in the configuration.
143  """
144  filterName = md.get("FILTER").strip()
145  filterName = filterName.strip()
146  c = filterName.find(" ")
147  if c > 0:
148  filterName = filterName[:c]
149  return filterName

Member Data Documentation

lsst.pipe.tasks.ingest.ParseTask.ConfigClass = ParseConfig
static

Definition at line 45 of file ingest.py.


The documentation for this class was generated from the following file: