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 | List of all members
lsst.pipe.base.argumentParser.IdValueAction Class Reference

argparse action callback to process a data ID into a dict More...

Inheritance diagram for lsst.pipe.base.argumentParser.IdValueAction:

Public Member Functions

def __call__
 Parse –id data and append results to namespace. More...
 

Detailed Description

argparse action callback to process a data ID into a dict

Definition at line 659 of file argumentParser.py.

Member Function Documentation

def lsst.pipe.base.argumentParser.IdValueAction.__call__ (   self,
  parser,
  namespace,
  values,
  option_string 
)

Parse –id data and append results to namespace.

<argument>.idList

Parameters
[in]parserargument parser (instance of ArgumentParser)
[in,out]namespaceparsed command (an instance of argparse.Namespace); updated values:
  • <idName>.idList, where <idName> is the name of the ID argument, for instance "id" for ID argument –id
[in]valuesa list of data IDs; see data format below
[in]option_stringoption value specified by the user (a str)

The data format is: key1=value1_1[^value1_2[^value1_3...] key2=value2_1[^value2_2[^value2_3...]...

The values (e.g. value1_1) may either be a string, or of the form "int..int" (e.g. "1..3") which is interpreted as "1^2^3" (inclusive, unlike a python range). So "0^2..4^7..9" is equivalent to "0^2^3^4^7^8^9". You may also specify a stride: "1..5:2" is "1^3^5"

The cross product is computed for keys with multiple values. For example: –id visit 1^2 ccd 1,1^2,2 results in the following data ID dicts being appended to namespace.<argument>.idList: {"visit":1, "ccd":"1,1"} {"visit":2, "ccd":"1,1"} {"visit":1, "ccd":"2,2"} {"visit":2, "ccd":"2,2"}

Definition at line 662 of file argumentParser.py.

663  def __call__(self, parser, namespace, values, option_string):
664  """!Parse --id data and append results to namespace.<argument>.idList
665 
666  @param[in] parser argument parser (instance of ArgumentParser)
667  @param[in,out] namespace parsed command (an instance of argparse.Namespace);
668  updated values:
669  - <idName>.idList, where <idName> is the name of the ID argument,
670  for instance "id" for ID argument --id
671  @param[in] values a list of data IDs; see data format below
672  @param[in] option_string option value specified by the user (a str)
673 
674  The data format is:
675  key1=value1_1[^value1_2[^value1_3...] key2=value2_1[^value2_2[^value2_3...]...
676 
677  The values (e.g. value1_1) may either be a string, or of the form "int..int" (e.g. "1..3")
678  which is interpreted as "1^2^3" (inclusive, unlike a python range). So "0^2..4^7..9" is
679  equivalent to "0^2^3^4^7^8^9". You may also specify a stride: "1..5:2" is "1^3^5"
680 
681  The cross product is computed for keys with multiple values. For example:
682  --id visit 1^2 ccd 1,1^2,2
683  results in the following data ID dicts being appended to namespace.<argument>.idList:
684  {"visit":1, "ccd":"1,1"}
685  {"visit":2, "ccd":"1,1"}
686  {"visit":1, "ccd":"2,2"}
687  {"visit":2, "ccd":"2,2"}
688  """
689  if namespace.config is None:
690  return
691  idDict = collections.OrderedDict()
692  for nameValue in values:
693  name, sep, valueStr = nameValue.partition("=")
694  if name in idDict:
695  parser.error("%s appears multiple times in one ID argument: %s" % (name, option_string))
696  idDict[name] = []
697  for v in valueStr.split("^"):
698  mat = re.search(r"^(\d+)\.\.(\d+)(?::(\d+))?$", v)
699  if mat:
700  v1 = int(mat.group(1))
701  v2 = int(mat.group(2))
702  v3 = mat.group(3); v3 = int(v3) if v3 else 1
703  for v in range(v1, v2 + 1, v3):
704  idDict[name].append(str(v))
705  else:
706  idDict[name].append(v)
707 
708  keyList = idDict.keys()
709  iterList = [idDict[key] for key in keyList]
710  idDictList = [collections.OrderedDict(zip(keyList, valList))
711  for valList in itertools.product(*iterList)]
712 
713  argName = option_string.lstrip("-")
714  ident = getattr(namespace, argName)
715  ident.idList += idDictList
716 
717 
def __call__
Parse –id data and append results to namespace.

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