Improve unit tracking (API change)
Right now, units are specified for each column, but no checks are made, and this can lead to mistakes. Ideally it would be best to require units in the values when using the classes, and have them checked against the assigned unit. This would change the current API to require units in the values ```python # Current usage, with no unit checking (just documentation) t = TrackingCoverage(elevation_min=12.0 ...) # Proposed usage t = TrackingCoverage(elevation_min=12.0*u.deg, ...) ``` But this still leaves open how to serialize those values. Right now we serialize to a bare float `elevation_min: 12.0`, and the unit is just documentation that appears in the FITS header, which currently looks like: ``` ALT_MIN = -30.573454373136034 / [deg] Minimum elevation above horizon ``` ### AstropydanticQuantity serialization: Currently serializes to `elevation_min: {unit: "deg", value:12.0}` That breaks the serialization to FITS keys, as it introduces two keys for each value, which is not what we want. Maybe there is a way to change this to use a single string serialization? ```python class Example(dm.ModelBase): q: AstroPydanticQuantity["TeV"] dm.flatten_model_instance(Example(q=10*u.TeV)) ``` ``` {'q.value': 10.0, 'q.unit': 'TeV'} ``` ### String serialization Use a string serialization for quantity metadata, e.g. serialize them as `elevation_min: "12.0 deg"`. The FITS header then becomes a string, not float: ``` ALT_MIN = '-30.57345 deg ' / [deg] Minimum elevation above horizon ``` ### Float serialization, with Unit checks Keep the serialization as is (unit quantities serialize to floats), but check/convert the units when flattening the model and strip them. That would not use AstropydanticQuantity at all, just check the field's unit against the given unit.
issue

Imprint | Data Privacy | Conditions of Use