23 __all__ = [
"Key",
"Field",
"SchemaItem"]
32 from lsst.utils import continueClass, TemplateMeta
34 from .schema
import _Key, _Field, _SchemaItem, Schema
50 class Key(metaclass=TemplateMeta):
54 class Field(metaclass=TemplateMeta):
62 def _registerInstantiations(abc, types):
63 """Iterate over a private dict (filled by template instantiations in C++) 64 to register template instantiations a TemplateMeta ABCs. 66 If an entry for the type string exists in _dtypes, we use that instead of 67 the string as the key, and use the string as an alias. 69 for k, v
in types.items():
70 dtype = _dtypes.get(k,
None)
72 abc.register(dtype, v)
80 _registerInstantiations(Key, _Key)
81 _registerInstantiations(Field, _Field)
82 _registerInstantiations(SchemaItem, _SchemaItem)
86 Key.alias(float, _Key[
"D"])
87 Field.alias(float, _Field[
"D"])
88 SchemaItem.alias(float, _SchemaItem[
"D"])
95 """Return a list of field names in the order the fields were added to the Schema. 100 names.append(item.field.getName())
105 """Iterate over the items in the Schema. 108 self.forEach(items.append)
112 """Check that all units in the Schema are valid Astropy unit strings. 115 astropy.units.Unit(item.field.getUnits(),
116 parse_strict=parse_strict)
119 def addField(self, field, type=None, doc="", units="", size=None,
120 doReplace=False, parse_strict="raise"):
121 """Add a field to the Schema. 126 The string name of the Field, or a fully-constructed Field object. 127 If the latter, all other arguments besides doReplace are ignored. 129 The type of field to create. Valid types are the keys of the 130 afw.table.Field dictionary. 132 Documentation for the field. 134 Units for the field, or an empty string if unitless. 136 Size of the field; valid for string and array fields only. 138 If a field with this name already exists, replace it instead of 139 raising pex.exceptions.InvalidParameterError. 141 One of 'raise' (default), 'warn', or 'strict', indicating how to 142 handle unrecognized unit strings. See also astropy.units.Unit. 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)
151 Extract a dictionary of {<name>: <schema-item>} in which the field names 152 match the given shell-style glob pattern(s). 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. 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. 165 A replacement string (see re.MatchObject.expand) used to set the 166 dictionary keys of any fields matched by regex. 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. 173 if kwds.pop(
"ordered",
False):
174 d = collections.OrderedDict()
177 regex = kwds.pop(
"regex",
None)
178 sub = kwds.pop(
"sub",
None)
179 if sub
is not None and regex
is None:
181 "'sub' keyword argument to extract is invalid without 'regex' argument")
184 "Unrecognized keyword arguments for extract: %s" %
", ".join(kwds.keys()))
186 trueName = item.field.getName()
188 for alias, target
in self.getAliasMap().
items():
189 if trueName.startswith(target):
190 names.append(trueName.replace(target, alias, 1))
192 if regex
is not None:
193 m = re.match(regex, name)
199 for pattern
in patterns:
200 if fnmatch.fnmatchcase(name, pattern):
206 """For pickle support.""" 209 fields.append(item.field)
210 return (makeSchemaFromFields, (fields,))
214 """Create a Schema from a sequence of Fields. For pickle support. 218 fields : `tuple` ['lsst.afw.table.Field'] 219 The fields to construct the new Schema from. 223 schema : `lsst.afw.table.Schema` 224 The constructed Schema. 228 schema.addField(field)
def extract(self, patterns, kwds)
A class representing an angle.
def getOrderedNames(self)
def makeSchemaFromFields(fields)
def addField(self, field, type=None, doc="", units="", size=None, doReplace=False, parse_strict="raise")
std::vector< SchemaItem< Flag > > * items
def checkUnits(self, parse_strict='raise')