27 from ._schema
import Field, Schema
28 from ._table
import SchemaMapper
35 doReplace=False, parse_strict="raise"):
36 """Add an un-mapped field to the output Schema.
40 field : `str` or `~lsst.afw.table.Field`
41 The string name of the `Field`, or a fully-constructed
42 `Field` object. If the latter, all other arguments
43 besides doReplace are ignored.
45 The type of field to create. Valid types are the keys of the
46 afw.table.Field dictionary.
48 Documentation for the field.
50 Units for the field, or an empty string if unitless.
52 Size of the field; valid for string and array fields only.
54 If a field with this name already exists, replace it instead of
55 raising pex.exceptions.InvalidParameterError.
57 One of 'raise' (default), 'warn', or 'strict', indicating how to
58 handle unrecognized unit strings. See also astropy.units.Unit.
62 key : `~lsst.afw.table.Key`
63 The key of the field added.
65 if isinstance(field, str):
66 field = Field[type](field, doc=doc, units=units,
67 size=size, parse_strict=parse_strict)
68 return field._addTo(self.editOutputSchema(), doReplace)
70 def addMapping(self, input, output=None, doReplace=True):
71 """Add a mapped field to the output schema.
75 input : `~lsst.afw.table.Key`
76 A `Key` from the input schema whose values will be mapped to the new
78 output : `str` or `~lsst.afw.table.Field`
79 A `Field` object that describes the new field to be added to the
80 output schema, or the name of the field (with documentation and
81 units copied from the input schema). May be None to copy everything
82 from the input schema.
84 If a field with this name already exists in the output schema,
85 replace it instead of raising `pex.exceptions.InvalidParameterError`.
89 key : `~lsst.afw.table.Key`
90 The key for the new mapped field.
95 if output
is True or output
is False:
98 return input._addMappingTo(self, output, doReplace)
101 """SchemaMappers are equal if their respective input and output
102 schemas are identical, and they have the same mappings defined.
104 Note: It was simpler to implement equality in python than in C++.
106 iSchema = self.getInputSchema()
107 oSchema = self.getOutputSchema()
108 if (
not (iSchema.compare(other.getInputSchema(), Schema.IDENTICAL) == Schema.IDENTICAL
109 and oSchema.compare(other.getOutputSchema(), Schema.IDENTICAL) == Schema.IDENTICAL)):
113 if self.isMapped(item.key)
and other.isMapped(item.key):
114 if (self.getMapping(item.key) == other.getMapping(item.key)):
118 elif (
not self.isMapped(item.key))
and (
not other.isMapped(item.key)):
126 """To support pickle."""
128 for item
in self.getInputSchema():
130 key = self.getMapping(item.key)
134 mappings[item.key] = self.getOutputSchema().find(key).field
135 return (makeSchemaMapper, (self.getInputSchema(), self.getOutputSchema(), mappings))
139 """Build a mapper from two Schemas and the mapping between them.
144 input : `lsst.afw.table.Schema`
145 The input schema for the mapper.
146 output : `lsst.afw.table.Schema`
147 The output schema for the mapper.
148 mappings : `dict` [`lsst.afw.table.Key`, `lsst.afw.table.Key`]
149 The mappings to define between the input and output schema.
153 mapper : `lsst.afw.table.SchemaMapper`
154 The constructed SchemaMapper.
157 for key, value
in mappings.items():
158 mapper.addMapping(key, value)