class UnitManipulationAdapter(HasTraits): (source)
Known subclasses: codetools.contexts.adapter.unit_apply_adapter.UnitApplyAdapter
, codetools.contexts.adapter.unit_conversion_adapter.UnitConversionAdapter
, codetools.contexts.adapter.unit_corrector_adapter.UnitCorrectorAdapter
Bi-directional unit conversion of values. This adapter converts values to a different unit system based on their name. There is a name->units mapper for getitem conversions and a separate name->units adapter for setitem conversions so that read/write can result in different unit conversions. This is useful when, for example, you want a context to preserve its current units for all its variables, but something using this context ( a shell or plot, or whatever) wants the values in another unit system. If units aren't found for a particular name, the converter silently lets the variable pass through. If units are found, but a converter isn't, or the converter fails, a ConversionError is raised. Users can pass in a dictionary of converters functions to be used for unit conversion.
Method | adapt |
Convert 'value' to the desired units for objects of the given 'name' |
Method | adapt |
Convert 'value' to the desired units for objects of the given 'name' |
Class Variable | converters |
Undocumented |
Class Variable | getitem |
Undocumented |
Class Variable | setitem |
Undocumented |
Method | _convert |
Find a converter for value and convert it to new_units. |
Convert 'value' to the desired units for objects of the given 'name' The getitem_units name->units mapper is used to look up the proper units. If no units are found for 'name', the value passes through unaltered. If a units are found, but an appropriate converter is not, or the conversion fails, a ConversionError is raised.
Convert 'value' to the desired units for objects of the given 'name' The setitem_units name->units mapper is used to look up the proper units. If no units are found for 'name', the value passes through unaltered. If a units are found, but an appropriate converter is not, or the conversion fails, a ConversionError is raised.