LSSTApplications  18.1.0
LSSTDataManagementBasePackage
Public Member Functions | List of all members
lsst.afw.table.schema.schemaContinued.Schema Class Reference

Public Member Functions

def getOrderedNames (self)
 
def __iter__ (self)
 
def checkUnits (self, parse_strict='raise')
 
def addField (self, field, type=None, doc="", units="", size=None, doReplace=False, parse_strict="raise")
 
def extract (self, patterns, kwds)
 
def __reduce__ (self)
 

Detailed Description

Definition at line 92 of file schemaContinued.py.

Member Function Documentation

◆ __iter__()

def lsst.afw.table.schema.schemaContinued.Schema.__iter__ (   self)
Iterate over the items in the Schema.

Definition at line 104 of file schemaContinued.py.

104  def __iter__(self):
105  """Iterate over the items in the Schema.
106  """
107  items = []
108  self.forEach(items.append)
109  return iter(items)
110 

◆ __reduce__()

def lsst.afw.table.schema.schemaContinued.Schema.__reduce__ (   self)
For pickle support.

Definition at line 205 of file schemaContinued.py.

205  def __reduce__(self):
206  """For pickle support."""
207  fields = []
208  for item in self:
209  fields.append(item.field)
210  return (makeSchemaFromFields, (fields,))
211 
212 

◆ addField()

def lsst.afw.table.schema.schemaContinued.Schema.addField (   self,
  field,
  type = None,
  doc = "",
  units = "",
  size = None,
  doReplace = False,
  parse_strict = "raise" 
)
Add a field to the Schema.

Parameters
----------
field : str,Field
    The string name of the Field, or a fully-constructed Field object.
    If the latter, all other arguments besides doReplace are ignored.
type\n : str,type
    The type of field to create.  Valid types are the keys of the
    afw.table.Field dictionary.
doc : str
    Documentation for the field.
unit : str
    Units for the field, or an empty string if unitless.
size : int
    Size of the field; valid for string and array fields only.
doReplace : bool
    If a field with this name already exists, replace it instead of
    raising pex.exceptions.InvalidParameterError.
parse_strict : str
    One of 'raise' (default), 'warn', or 'strict', indicating how to
    handle unrecognized unit strings.  See also astropy.units.Unit.

Definition at line 120 of file schemaContinued.py.

120  doReplace=False, parse_strict="raise"):
121  """Add a field to the Schema.
122 
123  Parameters
124  ----------
125  field : str,Field
126  The string name of the Field, or a fully-constructed Field object.
127  If the latter, all other arguments besides doReplace are ignored.
128  type\n : str,type
129  The type of field to create. Valid types are the keys of the
130  afw.table.Field dictionary.
131  doc : str
132  Documentation for the field.
133  unit : str
134  Units for the field, or an empty string if unitless.
135  size : int
136  Size of the field; valid for string and array fields only.
137  doReplace : bool
138  If a field with this name already exists, replace it instead of
139  raising pex.exceptions.InvalidParameterError.
140  parse_strict : str
141  One of 'raise' (default), 'warn', or 'strict', indicating how to
142  handle unrecognized unit strings. See also astropy.units.Unit.
143  """
144  if isinstance(field, str):
145  field = Field[type](field, doc=doc, units=units,
146  size=size, parse_strict=parse_strict)
147  return field._addTo(self, doReplace)
148 

◆ checkUnits()

def lsst.afw.table.schema.schemaContinued.Schema.checkUnits (   self,
  parse_strict = 'raise' 
)
Check that all units in the Schema are valid Astropy unit strings.

Definition at line 111 of file schemaContinued.py.

111  def checkUnits(self, parse_strict='raise'):
112  """Check that all units in the Schema are valid Astropy unit strings.
113  """
114  def func(item):
115  astropy.units.Unit(item.field.getUnits(),
116  parse_strict=parse_strict)
117  self.forEach(func)
118 

◆ extract()

def lsst.afw.table.schema.schemaContinued.Schema.extract (   self,
  patterns,
  kwds 
)
Extract a dictionary of {<name>: <schema-item>} in which the field names
match the given shell-style glob pattern(s).

Any number of glob patterns may be passed; the result will be the union of all
the result of each glob considered separately.

Additional Keyword Arguments
----------------------------
regex : `str` or `re` pattern
    A regular expression to be used in addition to any glob patterns
    passed as positional arguments.  Note that this will be compared
    with re.match, not re.search.

sub : `str`
    A replacement string (see re.MatchObject.expand) used to set the
    dictionary keys of any fields matched by regex.

ordered : `bool`
    If True, a collections.OrderedDict will be returned instead of a
    standard dict, with the order corresponding to the definition
    order of the Schema. Default is False.

Definition at line 149 of file schemaContinued.py.

149  def extract(self, *patterns, **kwds):
150  """
151  Extract a dictionary of {<name>: <schema-item>} in which the field names
152  match the given shell-style glob pattern(s).
153 
154  Any number of glob patterns may be passed; the result will be the union of all
155  the result of each glob considered separately.
156 
157  Additional Keyword Arguments
158  ----------------------------
159  regex : `str` or `re` pattern
160  A regular expression to be used in addition to any glob patterns
161  passed as positional arguments. Note that this will be compared
162  with re.match, not re.search.
163 
164  sub : `str`
165  A replacement string (see re.MatchObject.expand) used to set the
166  dictionary keys of any fields matched by regex.
167 
168  ordered : `bool`
169  If True, a collections.OrderedDict will be returned instead of a
170  standard dict, with the order corresponding to the definition
171  order of the Schema. Default is False.
172  """
173  if kwds.pop("ordered", False):
174  d = collections.OrderedDict()
175  else:
176  d = dict()
177  regex = kwds.pop("regex", None)
178  sub = kwds.pop("sub", None)
179  if sub is not None and regex is None:
180  raise ValueError(
181  "'sub' keyword argument to extract is invalid without 'regex' argument")
182  if kwds:
183  raise ValueError(
184  "Unrecognized keyword arguments for extract: %s" % ", ".join(kwds.keys()))
185  for item in self:
186  trueName = item.field.getName()
187  names = [trueName]
188  for alias, target in self.getAliasMap().items():
189  if trueName.startswith(target):
190  names.append(trueName.replace(target, alias, 1))
191  for name in names:
192  if regex is not None:
193  m = re.match(regex, name)
194  if m is not None:
195  if sub is not None:
196  name = m.expand(sub)
197  d[name] = item
198  continue # continue middle loop so we don't match the same name twice
199  for pattern in patterns:
200  if fnmatch.fnmatchcase(name, pattern):
201  d[name] = item
202  break # break inner loop so we don't match the same name twice
203  return d
204 
std::vector< SchemaItem< Flag > > * items

◆ getOrderedNames()

def lsst.afw.table.schema.schemaContinued.Schema.getOrderedNames (   self)
Return a list of field names in the order the fields were added to the Schema.

Definition at line 94 of file schemaContinued.py.

94  def getOrderedNames(self):
95  """Return a list of field names in the order the fields were added to the Schema.
96  """
97  names = []
98 
99  def func(item):
100  names.append(item.field.getName())
101  self.forEach(func)
102  return names
103 

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