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 Attributes | Static Private Attributes | List of all members
lsst.pipe.tasks.ingest.IngestTask Class Reference
Inheritance diagram for lsst.pipe.tasks.ingest.IngestTask:

Public Member Functions

def __init__
 
def parseAndRun
 
def ingest
 
def isBadFile
 
def isBadId
 
def run
 

Static Public Attributes

 ConfigClass = IngestConfig
 
 ArgumentParser = IngestArgumentParser
 

Static Private Attributes

string _DefaultName = "ingest"
 

Detailed Description

Task that will ingest images into the data repository

Definition at line 335 of file ingest.py.

Constructor & Destructor Documentation

def lsst.pipe.tasks.ingest.IngestTask.__init__ (   self,
  args,
  kwargs 
)

Definition at line 341 of file ingest.py.

342  def __init__(self, *args, **kwargs):
343  super(IngestTask, self).__init__(*args, **kwargs)
344  self.makeSubtask("parse")
345  self.makeSubtask("register")

Member Function Documentation

def lsst.pipe.tasks.ingest.IngestTask.ingest (   self,
  infile,
  outfile,
  mode = "move",
  dryrun = False 
)
Ingest a file into the image repository.

@param infile  Name of input file
@param outfile Name of output file (file in repository)
@param mode    Mode of ingest (copy/link/move/skip)
@param dryrun  Only report what would occur?
@param Success boolean

Definition at line 355 of file ingest.py.

356  def ingest(self, infile, outfile, mode="move", dryrun=False):
357  """Ingest a file into the image repository.
358 
359  @param infile Name of input file
360  @param outfile Name of output file (file in repository)
361  @param mode Mode of ingest (copy/link/move/skip)
362  @param dryrun Only report what would occur?
363  @param Success boolean
364  """
365  if mode == "skip":
366  return True
367  if dryrun:
368  self.log.info("Would %s from %s to %s" % (mode, infile, outfile))
369  return True
370  try:
371  outdir = os.path.dirname(outfile)
372  if not os.path.isdir(outdir):
373  try:
374  os.makedirs(outdir)
375  except:
376  # Silently ignore mkdir failures due to race conditions
377  if not os.path.isdir(outdir):
378  raise
379  if self.config.clobber and os.path.lexists(outfile):
380  os.unlink(outfile)
381  if mode == "copy":
382  assertCanCopy(infile, outfile)
383  shutil.copyfile(infile, outfile)
384  elif mode == "link":
385  os.symlink(os.path.abspath(infile), outfile)
386  elif mode == "move":
387  assertCanCopy(infile, outfile)
388  os.rename(infile, outfile)
389  else:
390  raise AssertionError("Unknown mode: %s" % mode)
391  print "%s --<%s>--> %s" % (infile, mode, outfile)
392  except Exception, e:
393  self.log.warn("Failed to %s %s to %s: %s" % (mode, infile, outfile, e))
394  if not self.config.allowError:
395  raise
396  return False
397  return True
def lsst.pipe.tasks.ingest.IngestTask.isBadFile (   self,
  filename,
  badFileList 
)
Return whether the file qualifies as bad

We match against the list of bad file patterns.

Definition at line 398 of file ingest.py.

399  def isBadFile(self, filename, badFileList):
400  """Return whether the file qualifies as bad
401 
402  We match against the list of bad file patterns.
403  """
404  filename = os.path.basename(filename)
405  if not badFileList:
406  return False
407  for badFile in badFileList:
408  if fnmatch(filename, badFile):
409  return True
410  return False
def lsst.pipe.tasks.ingest.IngestTask.isBadId (   self,
  info,
  badIdList 
)
Return whether the file information qualifies as bad

We match against the list of bad data identifiers.

Definition at line 411 of file ingest.py.

412  def isBadId(self, info, badIdList):
413  """Return whether the file information qualifies as bad
414 
415  We match against the list of bad data identifiers.
416  """
417  if not badIdList:
418  return False
419  for badId in badIdList:
420  if all(info[key] == value for key, value in badId.iteritems()):
421  return True
422  return False
bool all(CoordinateExpr< N > const &expr)
Return true if all elements are true.
def lsst.pipe.tasks.ingest.IngestTask.parseAndRun (   cls)
Parse the command-line arguments and run the Task

Definition at line 347 of file ingest.py.

348  def parseAndRun(cls):
349  """Parse the command-line arguments and run the Task"""
350  config = cls.ConfigClass()
351  parser = cls.ArgumentParser("ingest")
352  args = parser.parse_args(config)
353  task = cls(config=args.config)
354  task.run(args)
def lsst.pipe.tasks.ingest.IngestTask.run (   self,
  args 
)
Ingest all specified files and add them to the registry

Definition at line 423 of file ingest.py.

424  def run(self, args):
425  """Ingest all specified files and add them to the registry"""
426  filenameList = sum([glob(filename) for filename in args.files], [])
427  context = self.register.openRegistry(args.butler, create=args.create, dryrun=args.dryrun)
428  with context as registry:
429  for infile in filenameList:
430  if self.isBadFile(infile, args.badFile):
431  self.log.info("Skipping declared bad file %s" % infile)
432  continue
433  fileInfo, hduInfoList = self.parse.getInfo(infile)
434  if self.isBadId(fileInfo, args.badId.idList):
435  self.log.info("Skipping declared bad file %s: %s" % (infile, fileInfo))
436  continue
437  if self.register.check(registry, fileInfo):
438  self.log.warn("%s: already ingested: %s" % (infile, fileInfo))
439  outfile = self.parse.getDestination(args.butler, fileInfo, infile)
440  ingested = self.ingest(infile, outfile, mode=args.mode, dryrun=args.dryrun)
441  if not ingested:
442  continue
443  for info in hduInfoList:
444  self.register.addRow(registry, info, dryrun=args.dryrun, create=args.create)
445  self.register.addVisits(registry, dryrun=args.dryrun)
boost::enable_if< typename ExpressionTraits< Scalar >::IsScalar, Scalar >::type sum(Scalar const &scalar)
Definition: operators.h:1250

Member Data Documentation

string lsst.pipe.tasks.ingest.IngestTask._DefaultName = "ingest"
staticprivate

Definition at line 339 of file ingest.py.

lsst.pipe.tasks.ingest.IngestTask.ArgumentParser = IngestArgumentParser
static

Definition at line 338 of file ingest.py.

lsst.pipe.tasks.ingest.IngestTask.ConfigClass = IngestConfig
static

Definition at line 337 of file ingest.py.


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