From 489ef173e48277972bfc63700ac6abc42b8537cb Mon Sep 17 00:00:00 2001 From: ViciousEagle03 Date: Wed, 21 Aug 2024 21:29:43 +0530 Subject: [PATCH 01/10] Add serialization logic for uncertainty objects --- asdf_astropy/converters/__init__.py | 4 ++ .../converters/uncertainty/__init__.py | 7 ++++ .../converters/uncertainty/tests/__init__.py | 0 .../uncertainty/tests/test_uncertainty.py | 27 +++++++++++++ .../converters/uncertainty/uncertainty.py | 40 +++++++++++++++++++ asdf_astropy/extensions.py | 8 ++++ .../resources/manifests/astropy-1.0.0.yaml | 15 +++++++ .../uncertainty/stddevuncertainty-1.0.0.yaml | 22 ++++++++++ .../uncertainty/uncertainty-1.0.0.yaml | 21 ++++++++++ .../uncertainty/unknownuncertainty-1.0.0.yaml | 22 ++++++++++ 10 files changed, 166 insertions(+) create mode 100644 asdf_astropy/converters/uncertainty/__init__.py create mode 100644 asdf_astropy/converters/uncertainty/tests/__init__.py create mode 100644 asdf_astropy/converters/uncertainty/tests/test_uncertainty.py create mode 100644 asdf_astropy/converters/uncertainty/uncertainty.py create mode 100644 asdf_astropy/resources/schemas/uncertainty/stddevuncertainty-1.0.0.yaml create mode 100644 asdf_astropy/resources/schemas/uncertainty/uncertainty-1.0.0.yaml create mode 100644 asdf_astropy/resources/schemas/uncertainty/unknownuncertainty-1.0.0.yaml diff --git a/asdf_astropy/converters/__init__.py b/asdf_astropy/converters/__init__.py index e18b0b0a..80dfc7e9 100644 --- a/asdf_astropy/converters/__init__.py +++ b/asdf_astropy/converters/__init__.py @@ -19,6 +19,9 @@ "AstropyTableConverter", "AsdfTableConverter", "NdarrayMixinConverter", + "UncertaintyConverter", + "StdDevUncertaintyConverter", + "UnknownUncertaintyConverter", "TimeDeltaConverter", "TimeConverter", "CompoundConverter", @@ -73,4 +76,5 @@ TransformConverterBase, UnitsMappingConverter, ) +from .uncertainty import StdDevUncertaintyConverter, UncertaintyConverter, UnknownUncertaintyConverter from .unit import EquivalencyConverter, MagUnitConverter, QuantityConverter, UnitConverter diff --git a/asdf_astropy/converters/uncertainty/__init__.py b/asdf_astropy/converters/uncertainty/__init__.py new file mode 100644 index 00000000..7f2f9167 --- /dev/null +++ b/asdf_astropy/converters/uncertainty/__init__.py @@ -0,0 +1,7 @@ +__all__ = [ + "UncertaintyConverter", + "StdDevUncertaintyConverter", + "UnknownUncertaintyConverter", +] + +from .uncertainty import StdDevUncertaintyConverter, UncertaintyConverter, UnknownUncertaintyConverter diff --git a/asdf_astropy/converters/uncertainty/tests/__init__.py b/asdf_astropy/converters/uncertainty/tests/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/asdf_astropy/converters/uncertainty/tests/test_uncertainty.py b/asdf_astropy/converters/uncertainty/tests/test_uncertainty.py new file mode 100644 index 00000000..6d71a192 --- /dev/null +++ b/asdf_astropy/converters/uncertainty/tests/test_uncertainty.py @@ -0,0 +1,27 @@ +import asdf +import numpy as np +import pytest +from astropy import units as u +from astropy.nddata import StdDevUncertainty, UnknownUncertainty + + +def create_uncertainty(): + uncert = np.arange(100).reshape(10, 10) + uncertainty_stddev_1 = StdDevUncertainty(uncert, unit="m") + uncertainty_stddev_2 = StdDevUncertainty([2], unit="m") + uncertainty_unknown_1 = UnknownUncertainty(uncert, unit="m") + uncertainty_unknown_2 = UnknownUncertainty([0.4], unit=u.adu) + return [uncertainty_stddev_1, uncertainty_stddev_2, uncertainty_unknown_1, uncertainty_unknown_2] + + +@pytest.mark.parametrize("uncertainty", create_uncertainty()) +def test_uncertainty_serialization(uncertainty, tmp_path): + file_path = tmp_path / "test_uncertainty.asdf" + with asdf.AsdfFile() as af: + af["uncertainty"] = uncertainty + af.write_to(file_path) + + with asdf.open(file_path) as af: + loaded_uncert = af["uncertainty"] + assert (loaded_uncert._array == uncertainty._array).all() + assert loaded_uncert.unit == uncertainty.unit diff --git a/asdf_astropy/converters/uncertainty/uncertainty.py b/asdf_astropy/converters/uncertainty/uncertainty.py new file mode 100644 index 00000000..485147af --- /dev/null +++ b/asdf_astropy/converters/uncertainty/uncertainty.py @@ -0,0 +1,40 @@ +from asdf.extension import Converter + + +class UncertaintyConverter(Converter): + tags = ("tag:astropy.org:astropy/uncertainty/uncertainty-*",) + types = ("astropy.nddata.nduncertainty.Uncertainty",) + + def from_yaml_tree(self, node, tag, ctx): + return (node["array"], node.get("unit")) + + def to_yaml_tree(self, nddata_uncertainty, tag, ctx): + node = {} + + node["array"] = nddata_uncertainty.array + if nddata_uncertainty.unit is not None: + node["unit"] = nddata_uncertainty.unit + + return node + + +class StdDevUncertaintyConverter(UncertaintyConverter): + tags = ("tag:astropy.org:astropy/uncertainty/stddevuncertainty-*",) + types = ("astropy.nddata.nduncertainty.StdDevUncertainty",) + + def from_yaml_tree(self, node, tag, ctx): + from astropy.nddata import StdDevUncertainty + + array, unit = super().from_yaml_tree(node, tag, ctx) + return StdDevUncertainty(array=array, unit=unit) + + +class UnknownUncertaintyConverter(UncertaintyConverter): + tags = ("tag:astropy.org:astropy/uncertainty/unknownuncertainty-*",) + types = ("astropy.nddata.nduncertainty.UnknownUncertainty",) + + def from_yaml_tree(self, node, tag, ctx): + from astropy.nddata import UnknownUncertainty + + array, unit = super().from_yaml_tree(node, tag, ctx) + return UnknownUncertainty(array=array, unit=unit) diff --git a/asdf_astropy/extensions.py b/asdf_astropy/extensions.py index e3ea27e5..57ef24f9 100644 --- a/asdf_astropy/extensions.py +++ b/asdf_astropy/extensions.py @@ -26,6 +26,11 @@ from .converters.transform.rotations import Rotate3DConverter, RotationSequenceConverter from .converters.transform.spline import SplineConverter from .converters.transform.tabular import TabularConverter +from .converters.uncertainty.uncertainty import ( + StdDevUncertaintyConverter, + UncertaintyConverter, + UnknownUncertaintyConverter, +) from .converters.unit.equivalency import EquivalencyConverter from .converters.unit.magunit import MagUnitConverter from .converters.unit.quantity import QuantityConverter @@ -476,6 +481,9 @@ AstropyTableConverter(), AstropyFitsConverter(), NdarrayMixinConverter(), + UncertaintyConverter(), + StdDevUncertaintyConverter(), + UnknownUncertaintyConverter(), ] _COORDINATES_MANIFEST_URIS = [ diff --git a/asdf_astropy/resources/manifests/astropy-1.0.0.yaml b/asdf_astropy/resources/manifests/astropy-1.0.0.yaml index 4f6d25b7..c0ed2cc1 100644 --- a/asdf_astropy/resources/manifests/astropy-1.0.0.yaml +++ b/asdf_astropy/resources/manifests/astropy-1.0.0.yaml @@ -49,3 +49,18 @@ tags: This transform operates on the units of the input, first converting to the expected input units, then assigning replacement output units without further conversion. +- tag_uri: tag:astropy.org:astropy/uncertainty/uncertainty-1.0.0 + schema_uri: http://astropy.org/schemas/astropy/uncertainty/uncertainty-1.0.0 + title: Represent the nddata.uncertainty.NDUncertainty object + description: |- + Represents an instance of the nddata.uncertainty.NDUncertainty object +- tag_uri: tag:astropy.org:astropy/uncertainty/unknownuncertainty-1.0.0 + schema_uri: http://astropy.org/schemas/astropy/uncertainty/unknownuncertainty-1.0.0 + title: Represent the nddata.uncertainty.UnknownUncertainty object + description: |- + Represents an instance of the nddata.uncertainty.UnknownUncertainty object +- tag_uri: tag:astropy.org:astropy/uncertainty/stddevuncertainty-1.0.0 + schema_uri: http://astropy.org/schemas/astropy/uncertainty/stddevuncertainty-1.0.0 + title: Represent the nddata.uncertainty.StdDevUncertainty object + description: |- + Represents an instance of the nddata.uncertainty.StdDevUncertainty object diff --git a/asdf_astropy/resources/schemas/uncertainty/stddevuncertainty-1.0.0.yaml b/asdf_astropy/resources/schemas/uncertainty/stddevuncertainty-1.0.0.yaml new file mode 100644 index 00000000..84d548a5 --- /dev/null +++ b/asdf_astropy/resources/schemas/uncertainty/stddevuncertainty-1.0.0.yaml @@ -0,0 +1,22 @@ +%YAML 1.1 +--- +$schema: "http://stsci.edu/schemas/yaml-schema/draft-01" +id: "http://astropy.org/schemas/astropy/uncertainty/stddevuncertainty-1.0.0" + +title: + Represents the astropy.nddata.StdDevUncertainty class + +description: + This object represents the `StdDevUncertainty` class, which is a subclass + of the `NDUncertainty` class from `astropy.nddata` + +allOf: + - tag: "tag:astropy.org:astropy/uncertainty/stddevuncertainty-1.0.0" + - type: object + properties: + array: + type: object + unit: + anyOf: + - tag: "tag:stsci.edu:asdf/unit/unit-*" + - tag: "tag:astropy.org:astropy/units/unit-1.*" diff --git a/asdf_astropy/resources/schemas/uncertainty/uncertainty-1.0.0.yaml b/asdf_astropy/resources/schemas/uncertainty/uncertainty-1.0.0.yaml new file mode 100644 index 00000000..af03a01b --- /dev/null +++ b/asdf_astropy/resources/schemas/uncertainty/uncertainty-1.0.0.yaml @@ -0,0 +1,21 @@ +%YAML 1.1 +--- +$schema: "http://stsci.edu/schemas/yaml-schema/draft-01" +id: "http://astropy.org/schemas/astropy/uncertainty/uncertainty-1.0.0" + +title: + Represents the astropy.nddata.NDUncertainty object + +description: + Represents the astropy.nddata.NDUncertainty object + +allOf: + - tag: "tag:astropy.org:astropy/uncertainty/uncertainty-1.0.0" + - type: object + properties: + array: + type: object + unit: + anyOf: + - tag: "tag:stsci.edu:asdf/unit/unit-*" + - tag: "tag:astropy.org:astropy/units/unit-1.*" diff --git a/asdf_astropy/resources/schemas/uncertainty/unknownuncertainty-1.0.0.yaml b/asdf_astropy/resources/schemas/uncertainty/unknownuncertainty-1.0.0.yaml new file mode 100644 index 00000000..355c7973 --- /dev/null +++ b/asdf_astropy/resources/schemas/uncertainty/unknownuncertainty-1.0.0.yaml @@ -0,0 +1,22 @@ +%YAML 1.1 +--- +$schema: "http://stsci.edu/schemas/yaml-schema/draft-01" +id: "http://astropy.org/schemas/astropy/uncertainty/unknownuncertainty-1.0.0" + +title: + Represents the astropy.nddata.UnknownUncertainty class + +description: + This object represents the `UnknownUncertainty` class, which is a subclass + of the `NDUncertainty` class from `astropy.nddata` + +allOf: + - tag: "tag:astropy.org:astropy/uncertainty/unknownuncertainty-1.0.0" + - type: object + properties: + array: + type: object + unit: + anyOf: + - tag: "tag:stsci.edu:asdf/unit/unit-*" + - tag: "tag:astropy.org:astropy/units/unit-1.*" From cdfe2b630c7d919e821db6fe7d8cdbecc3d25013 Mon Sep 17 00:00:00 2001 From: ViciousEagle03 Date: Sun, 25 Aug 2024 15:37:09 +0530 Subject: [PATCH 02/10] Add changelog --- CHANGES.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES.rst b/CHANGES.rst index df832402..f434ea87 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -10,6 +10,8 @@ - require asdf 2.14.4 [#241] +- Add support for astropy.nddata.StdDevUncertainty and astropy.nddata.UnknownUncertainty[#239] + 0.6.1 (2024-04-05) ------------------ From ba5b9dfb26e10f5036ffc345293c686d88809074 Mon Sep 17 00:00:00 2001 From: Brett Date: Wed, 6 Nov 2024 12:24:31 -0500 Subject: [PATCH 03/10] reorg manifest, remove missing Uncertainty --- asdf_astropy/converters/__init__.py | 3 +- .../converters/uncertainty/__init__.py | 3 +- .../converters/uncertainty/uncertainty.py | 12 +--- asdf_astropy/extensions.py | 8 +-- .../resources/manifests/astropy-1.2.0.yaml | 30 ++++++--- .../resources/manifests/astropy-1.3.0.yaml | 66 +++++++++++++++++++ .../uncertainty/stddevuncertainty-1.0.0.yaml | 1 - .../uncertainty/unknownuncertainty-1.0.0.yaml | 1 - 8 files changed, 93 insertions(+), 31 deletions(-) create mode 100644 asdf_astropy/resources/manifests/astropy-1.3.0.yaml diff --git a/asdf_astropy/converters/__init__.py b/asdf_astropy/converters/__init__.py index 80dfc7e9..4cb722fb 100644 --- a/asdf_astropy/converters/__init__.py +++ b/asdf_astropy/converters/__init__.py @@ -19,7 +19,6 @@ "AstropyTableConverter", "AsdfTableConverter", "NdarrayMixinConverter", - "UncertaintyConverter", "StdDevUncertaintyConverter", "UnknownUncertaintyConverter", "TimeDeltaConverter", @@ -76,5 +75,5 @@ TransformConverterBase, UnitsMappingConverter, ) -from .uncertainty import StdDevUncertaintyConverter, UncertaintyConverter, UnknownUncertaintyConverter +from .uncertainty import StdDevUncertaintyConverter, UnknownUncertaintyConverter from .unit import EquivalencyConverter, MagUnitConverter, QuantityConverter, UnitConverter diff --git a/asdf_astropy/converters/uncertainty/__init__.py b/asdf_astropy/converters/uncertainty/__init__.py index 7f2f9167..43921e8d 100644 --- a/asdf_astropy/converters/uncertainty/__init__.py +++ b/asdf_astropy/converters/uncertainty/__init__.py @@ -1,7 +1,6 @@ __all__ = [ - "UncertaintyConverter", "StdDevUncertaintyConverter", "UnknownUncertaintyConverter", ] -from .uncertainty import StdDevUncertaintyConverter, UncertaintyConverter, UnknownUncertaintyConverter +from .uncertainty import StdDevUncertaintyConverter, UnknownUncertaintyConverter diff --git a/asdf_astropy/converters/uncertainty/uncertainty.py b/asdf_astropy/converters/uncertainty/uncertainty.py index 485147af..ce951f1b 100644 --- a/asdf_astropy/converters/uncertainty/uncertainty.py +++ b/asdf_astropy/converters/uncertainty/uncertainty.py @@ -1,10 +1,4 @@ -from asdf.extension import Converter - - -class UncertaintyConverter(Converter): - tags = ("tag:astropy.org:astropy/uncertainty/uncertainty-*",) - types = ("astropy.nddata.nduncertainty.Uncertainty",) - +class _UncertaintyBaseConverter: def from_yaml_tree(self, node, tag, ctx): return (node["array"], node.get("unit")) @@ -18,7 +12,7 @@ def to_yaml_tree(self, nddata_uncertainty, tag, ctx): return node -class StdDevUncertaintyConverter(UncertaintyConverter): +class StdDevUncertaintyConverter(_UncertaintyBaseConverter): tags = ("tag:astropy.org:astropy/uncertainty/stddevuncertainty-*",) types = ("astropy.nddata.nduncertainty.StdDevUncertainty",) @@ -29,7 +23,7 @@ def from_yaml_tree(self, node, tag, ctx): return StdDevUncertainty(array=array, unit=unit) -class UnknownUncertaintyConverter(UncertaintyConverter): +class UnknownUncertaintyConverter(_UncertaintyBaseConverter): tags = ("tag:astropy.org:astropy/uncertainty/unknownuncertainty-*",) types = ("astropy.nddata.nduncertainty.UnknownUncertainty",) diff --git a/asdf_astropy/extensions.py b/asdf_astropy/extensions.py index 57ef24f9..16bfeea2 100644 --- a/asdf_astropy/extensions.py +++ b/asdf_astropy/extensions.py @@ -26,11 +26,7 @@ from .converters.transform.rotations import Rotate3DConverter, RotationSequenceConverter from .converters.transform.spline import SplineConverter from .converters.transform.tabular import TabularConverter -from .converters.uncertainty.uncertainty import ( - StdDevUncertaintyConverter, - UncertaintyConverter, - UnknownUncertaintyConverter, -) +from .converters.uncertainty.uncertainty import StdDevUncertaintyConverter, UnknownUncertaintyConverter from .converters.unit.equivalency import EquivalencyConverter from .converters.unit.magunit import MagUnitConverter from .converters.unit.quantity import QuantityConverter @@ -481,7 +477,6 @@ AstropyTableConverter(), AstropyFitsConverter(), NdarrayMixinConverter(), - UncertaintyConverter(), StdDevUncertaintyConverter(), UnknownUncertaintyConverter(), ] @@ -501,6 +496,7 @@ _ASTROPY_EXTENSION_MANIFEST_URIS = [ + "asdf://astropy.org/astropy/manifests/astropy-1.3.0", "asdf://astropy.org/astropy/manifests/astropy-1.2.0", "asdf://astropy.org/astropy/manifests/astropy-1.1.0", "asdf://astropy.org/astropy/manifests/astropy-1.0.0", diff --git a/asdf_astropy/resources/manifests/astropy-1.2.0.yaml b/asdf_astropy/resources/manifests/astropy-1.2.0.yaml index a3429f33..696f8f4b 100644 --- a/asdf_astropy/resources/manifests/astropy-1.2.0.yaml +++ b/asdf_astropy/resources/manifests/astropy-1.2.0.yaml @@ -6,15 +6,15 @@ description: |- model classes, which are handled by an implementation of the ASDF transform extension. asdf_standard_requirement: - gte: 1.6.0 + gte: 1.1.0 tags: -- tag_uri: tag:astropy.org:astropy/time/timedelta-1.1.0 - schema_uri: http://astropy.org/schemas/astropy/time/timedelta-1.1.0 +- tag_uri: tag:astropy.org:astropy/time/timedelta-1.0.0 + schema_uri: http://astropy.org/schemas/astropy/time/timedelta-1.0.0 title: Represents an instance of TimeDelta from astropy description: |- Represents the time difference between two times. -- tag_uri: tag:astropy.org:astropy/fits/fits-1.1.0 - schema_uri: http://astropy.org/schemas/astropy/fits/fits-1.1.0 +- tag_uri: tag:astropy.org:astropy/fits/fits-1.0.0 + schema_uri: http://astropy.org/schemas/astropy/fits/fits-1.0.0 title: A FITS file inside of an ASDF file. description: |- This schema is useful for distributing ASDF files that can @@ -28,12 +28,12 @@ tags: be accessible in its proper form in the ASDF file. Only image and binary table extensions are supported. -- tag_uri: tag:astropy.org:astropy/table/table-1.2.0 - schema_uri: http://astropy.org/schemas/astropy/table/table-1.2.0 +- tag_uri: tag:astropy.org:astropy/table/table-1.1.0 + schema_uri: http://astropy.org/schemas/astropy/table/table-1.1.0 title: A table. description: |- A table is represented as a list of columns, where each entry is a - [column](ref:http://stsci.edu/schemas/asdf/table/column-1.1.0) + [column](ref:http://stsci.edu/schemas/asdf/core/column-1.0.0) object, containing the data and some additional information. The data itself may be stored inline as text, or in binary in either @@ -42,8 +42,8 @@ tags: Each column in the table must have the same first (slowest moving) dimension. -- tag_uri: tag:astropy.org:astropy/transform/units_mapping-1.1.0 - schema_uri: http://astropy.org/schemas/astropy/transform/units_mapping-1.1.0 +- tag_uri: tag:astropy.org:astropy/transform/units_mapping-1.0.0 + schema_uri: http://astropy.org/schemas/astropy/transform/units_mapping-1.0.0 title: Mapper that operates on the units of the input. description: |- This transform operates on the units of the input, first converting to @@ -54,3 +54,13 @@ tags: title: NdarrayMixin column. description: |- Represents an astropy.table.NdarrayMixin instance. +- tag_uri: tag:astropy.org:astropy/uncertainty/unknownuncertainty-1.0.0 + schema_uri: http://astropy.org/schemas/astropy/uncertainty/unknownuncertainty-1.0.0 + title: Represent the nddata.uncertainty.UnknownUncertainty object + description: |- + Represents an instance of the nddata.uncertainty.UnknownUncertainty object +- tag_uri: tag:astropy.org:astropy/uncertainty/stddevuncertainty-1.0.0 + schema_uri: http://astropy.org/schemas/astropy/uncertainty/stddevuncertainty-1.0.0 + title: Represent the nddata.uncertainty.StdDevUncertainty object + description: |- + Represents an instance of the nddata.uncertainty.StdDevUncertainty object diff --git a/asdf_astropy/resources/manifests/astropy-1.3.0.yaml b/asdf_astropy/resources/manifests/astropy-1.3.0.yaml new file mode 100644 index 00000000..161a7c16 --- /dev/null +++ b/asdf_astropy/resources/manifests/astropy-1.3.0.yaml @@ -0,0 +1,66 @@ +id: asdf://astropy.org/astropy/manifests/astropy-1.3.0 +extension_uri: asdf://astropy.org/astropy/extensions/astropy-1.3.0 +title: Astropy extension 1.3.0 +description: |- + A set of tags for serializing astropy objects. This does not include most + model classes, which are handled by an implementation of the ASDF + transform extension. +asdf_standard_requirement: + gte: 1.6.0 +tags: +- tag_uri: tag:astropy.org:astropy/time/timedelta-1.1.0 + schema_uri: http://astropy.org/schemas/astropy/time/timedelta-1.1.0 + title: Represents an instance of TimeDelta from astropy + description: |- + Represents the time difference between two times. +- tag_uri: tag:astropy.org:astropy/fits/fits-1.1.0 + schema_uri: http://astropy.org/schemas/astropy/fits/fits-1.1.0 + title: A FITS file inside of an ASDF file. + description: |- + This schema is useful for distributing ASDF files that can + automatically be converted to FITS files by specifying the exact + content of the resulting FITS file. + + Not all kinds of data in FITS are directly representable in ASDF. + For example, applying an offset and scale to the data using the + `BZERO` and `BSCALE` keywords. In these cases, it will not be + possible to store the data in the native format from FITS and also + be accessible in its proper form in the ASDF file. + + Only image and binary table extensions are supported. +- tag_uri: tag:astropy.org:astropy/table/table-1.2.0 + schema_uri: http://astropy.org/schemas/astropy/table/table-1.2.0 + title: A table. + description: |- + A table is represented as a list of columns, where each entry is a + [column](ref:http://stsci.edu/schemas/asdf/table/column-1.1.0) + object, containing the data and some additional information. + + The data itself may be stored inline as text, or in binary in either + row- or column-major order by use of the `strides` property on the + individual column arrays. + + Each column in the table must have the same first (slowest moving) + dimension. +- tag_uri: tag:astropy.org:astropy/transform/units_mapping-1.1.0 + schema_uri: http://astropy.org/schemas/astropy/transform/units_mapping-1.1.0 + title: Mapper that operates on the units of the input. + description: |- + This transform operates on the units of the input, first converting to + the expected input units, then assigning replacement output units without + further conversion. +- tag_uri: tag:astropy.org:astropy/table/ndarraymixin-1.0.0 + schema_uri: http://astropy.org/schemas/astropy/table/ndarraymixin-1.0.0 + title: NdarrayMixin column. + description: |- + Represents an astropy.table.NdarrayMixin instance. +- tag_uri: tag:astropy.org:astropy/uncertainty/unknownuncertainty-1.0.0 + schema_uri: http://astropy.org/schemas/astropy/uncertainty/unknownuncertainty-1.0.0 + title: Represent the nddata.uncertainty.UnknownUncertainty object + description: |- + Represents an instance of the nddata.uncertainty.UnknownUncertainty object +- tag_uri: tag:astropy.org:astropy/uncertainty/stddevuncertainty-1.0.0 + schema_uri: http://astropy.org/schemas/astropy/uncertainty/stddevuncertainty-1.0.0 + title: Represent the nddata.uncertainty.StdDevUncertainty object + description: |- + Represents an instance of the nddata.uncertainty.StdDevUncertainty object diff --git a/asdf_astropy/resources/schemas/uncertainty/stddevuncertainty-1.0.0.yaml b/asdf_astropy/resources/schemas/uncertainty/stddevuncertainty-1.0.0.yaml index 84d548a5..0e3490af 100644 --- a/asdf_astropy/resources/schemas/uncertainty/stddevuncertainty-1.0.0.yaml +++ b/asdf_astropy/resources/schemas/uncertainty/stddevuncertainty-1.0.0.yaml @@ -11,7 +11,6 @@ description: of the `NDUncertainty` class from `astropy.nddata` allOf: - - tag: "tag:astropy.org:astropy/uncertainty/stddevuncertainty-1.0.0" - type: object properties: array: diff --git a/asdf_astropy/resources/schemas/uncertainty/unknownuncertainty-1.0.0.yaml b/asdf_astropy/resources/schemas/uncertainty/unknownuncertainty-1.0.0.yaml index 355c7973..62f6c6a8 100644 --- a/asdf_astropy/resources/schemas/uncertainty/unknownuncertainty-1.0.0.yaml +++ b/asdf_astropy/resources/schemas/uncertainty/unknownuncertainty-1.0.0.yaml @@ -11,7 +11,6 @@ description: of the `NDUncertainty` class from `astropy.nddata` allOf: - - tag: "tag:astropy.org:astropy/uncertainty/unknownuncertainty-1.0.0" - type: object properties: array: From 837fcbba1e0c8fc4486d7575cfba394c7a19ef21 Mon Sep 17 00:00:00 2001 From: Brett Date: Wed, 6 Nov 2024 12:30:56 -0500 Subject: [PATCH 04/10] rename uncertainty to nddata --- asdf_astropy/converters/__init__.py | 2 +- .../{uncertainty => nddata}/__init__.py | 0 .../{uncertainty => nddata}/tests/__init__.py | 0 .../tests/test_uncertainty.py | 0 .../{uncertainty => nddata}/uncertainty.py | 4 ++-- asdf_astropy/extensions.py | 2 +- .../resources/manifests/astropy-1.0.0.yaml | 15 ------------- .../resources/manifests/astropy-1.2.0.yaml | 8 +++---- .../resources/manifests/astropy-1.3.0.yaml | 8 +++---- .../stddevuncertainty-1.0.0.yaml | 2 +- .../unknownuncertainty-1.0.0.yaml | 2 +- .../uncertainty/uncertainty-1.0.0.yaml | 21 ------------------- 12 files changed, 14 insertions(+), 50 deletions(-) rename asdf_astropy/converters/{uncertainty => nddata}/__init__.py (100%) rename asdf_astropy/converters/{uncertainty => nddata}/tests/__init__.py (100%) rename asdf_astropy/converters/{uncertainty => nddata}/tests/test_uncertainty.py (100%) rename asdf_astropy/converters/{uncertainty => nddata}/uncertainty.py (88%) rename asdf_astropy/resources/schemas/{uncertainty => nddata}/stddevuncertainty-1.0.0.yaml (86%) rename asdf_astropy/resources/schemas/{uncertainty => nddata}/unknownuncertainty-1.0.0.yaml (86%) delete mode 100644 asdf_astropy/resources/schemas/uncertainty/uncertainty-1.0.0.yaml diff --git a/asdf_astropy/converters/__init__.py b/asdf_astropy/converters/__init__.py index 4cb722fb..f2536557 100644 --- a/asdf_astropy/converters/__init__.py +++ b/asdf_astropy/converters/__init__.py @@ -54,6 +54,7 @@ SpectralCoordConverter, ) from .fits import AsdfFitsConverter, AstropyFitsConverter, FitsConverter +from .nddata import StdDevUncertaintyConverter, UnknownUncertaintyConverter from .table import AsdfTableConverter, AstropyTableConverter, ColumnConverter, NdarrayMixinConverter from .time import TimeConverter, TimeDeltaConverter from .transform import ( @@ -75,5 +76,4 @@ TransformConverterBase, UnitsMappingConverter, ) -from .uncertainty import StdDevUncertaintyConverter, UnknownUncertaintyConverter from .unit import EquivalencyConverter, MagUnitConverter, QuantityConverter, UnitConverter diff --git a/asdf_astropy/converters/uncertainty/__init__.py b/asdf_astropy/converters/nddata/__init__.py similarity index 100% rename from asdf_astropy/converters/uncertainty/__init__.py rename to asdf_astropy/converters/nddata/__init__.py diff --git a/asdf_astropy/converters/uncertainty/tests/__init__.py b/asdf_astropy/converters/nddata/tests/__init__.py similarity index 100% rename from asdf_astropy/converters/uncertainty/tests/__init__.py rename to asdf_astropy/converters/nddata/tests/__init__.py diff --git a/asdf_astropy/converters/uncertainty/tests/test_uncertainty.py b/asdf_astropy/converters/nddata/tests/test_uncertainty.py similarity index 100% rename from asdf_astropy/converters/uncertainty/tests/test_uncertainty.py rename to asdf_astropy/converters/nddata/tests/test_uncertainty.py diff --git a/asdf_astropy/converters/uncertainty/uncertainty.py b/asdf_astropy/converters/nddata/uncertainty.py similarity index 88% rename from asdf_astropy/converters/uncertainty/uncertainty.py rename to asdf_astropy/converters/nddata/uncertainty.py index ce951f1b..ae4d6802 100644 --- a/asdf_astropy/converters/uncertainty/uncertainty.py +++ b/asdf_astropy/converters/nddata/uncertainty.py @@ -13,7 +13,7 @@ def to_yaml_tree(self, nddata_uncertainty, tag, ctx): class StdDevUncertaintyConverter(_UncertaintyBaseConverter): - tags = ("tag:astropy.org:astropy/uncertainty/stddevuncertainty-*",) + tags = ("tag:astropy.org:astropy/nddata/stddevuncertainty-*",) types = ("astropy.nddata.nduncertainty.StdDevUncertainty",) def from_yaml_tree(self, node, tag, ctx): @@ -24,7 +24,7 @@ def from_yaml_tree(self, node, tag, ctx): class UnknownUncertaintyConverter(_UncertaintyBaseConverter): - tags = ("tag:astropy.org:astropy/uncertainty/unknownuncertainty-*",) + tags = ("tag:astropy.org:astropy/nddata/unknownuncertainty-*",) types = ("astropy.nddata.nduncertainty.UnknownUncertainty",) def from_yaml_tree(self, node, tag, ctx): diff --git a/asdf_astropy/extensions.py b/asdf_astropy/extensions.py index 16bfeea2..f574dc44 100644 --- a/asdf_astropy/extensions.py +++ b/asdf_astropy/extensions.py @@ -12,6 +12,7 @@ from .converters.coordinates.sky_coord import SkyCoordConverter from .converters.coordinates.spectral_coord import SpectralCoordConverter from .converters.fits.fits import AsdfFitsConverter, AstropyFitsConverter +from .converters.nddata.uncertainty import StdDevUncertaintyConverter, UnknownUncertaintyConverter from .converters.table.table import AsdfTableConverter, AstropyTableConverter, ColumnConverter, NdarrayMixinConverter from .converters.time.time import TimeConverter from .converters.time.time_delta import TimeDeltaConverter @@ -26,7 +27,6 @@ from .converters.transform.rotations import Rotate3DConverter, RotationSequenceConverter from .converters.transform.spline import SplineConverter from .converters.transform.tabular import TabularConverter -from .converters.uncertainty.uncertainty import StdDevUncertaintyConverter, UnknownUncertaintyConverter from .converters.unit.equivalency import EquivalencyConverter from .converters.unit.magunit import MagUnitConverter from .converters.unit.quantity import QuantityConverter diff --git a/asdf_astropy/resources/manifests/astropy-1.0.0.yaml b/asdf_astropy/resources/manifests/astropy-1.0.0.yaml index c0ed2cc1..4f6d25b7 100644 --- a/asdf_astropy/resources/manifests/astropy-1.0.0.yaml +++ b/asdf_astropy/resources/manifests/astropy-1.0.0.yaml @@ -49,18 +49,3 @@ tags: This transform operates on the units of the input, first converting to the expected input units, then assigning replacement output units without further conversion. -- tag_uri: tag:astropy.org:astropy/uncertainty/uncertainty-1.0.0 - schema_uri: http://astropy.org/schemas/astropy/uncertainty/uncertainty-1.0.0 - title: Represent the nddata.uncertainty.NDUncertainty object - description: |- - Represents an instance of the nddata.uncertainty.NDUncertainty object -- tag_uri: tag:astropy.org:astropy/uncertainty/unknownuncertainty-1.0.0 - schema_uri: http://astropy.org/schemas/astropy/uncertainty/unknownuncertainty-1.0.0 - title: Represent the nddata.uncertainty.UnknownUncertainty object - description: |- - Represents an instance of the nddata.uncertainty.UnknownUncertainty object -- tag_uri: tag:astropy.org:astropy/uncertainty/stddevuncertainty-1.0.0 - schema_uri: http://astropy.org/schemas/astropy/uncertainty/stddevuncertainty-1.0.0 - title: Represent the nddata.uncertainty.StdDevUncertainty object - description: |- - Represents an instance of the nddata.uncertainty.StdDevUncertainty object diff --git a/asdf_astropy/resources/manifests/astropy-1.2.0.yaml b/asdf_astropy/resources/manifests/astropy-1.2.0.yaml index 696f8f4b..c5f0ca27 100644 --- a/asdf_astropy/resources/manifests/astropy-1.2.0.yaml +++ b/asdf_astropy/resources/manifests/astropy-1.2.0.yaml @@ -54,13 +54,13 @@ tags: title: NdarrayMixin column. description: |- Represents an astropy.table.NdarrayMixin instance. -- tag_uri: tag:astropy.org:astropy/uncertainty/unknownuncertainty-1.0.0 - schema_uri: http://astropy.org/schemas/astropy/uncertainty/unknownuncertainty-1.0.0 +- tag_uri: tag:astropy.org:astropy/nddata/unknownuncertainty-1.0.0 + schema_uri: http://astropy.org/schemas/astropy/nddata/unknownuncertainty-1.0.0 title: Represent the nddata.uncertainty.UnknownUncertainty object description: |- Represents an instance of the nddata.uncertainty.UnknownUncertainty object -- tag_uri: tag:astropy.org:astropy/uncertainty/stddevuncertainty-1.0.0 - schema_uri: http://astropy.org/schemas/astropy/uncertainty/stddevuncertainty-1.0.0 +- tag_uri: tag:astropy.org:astropy/nddata/stddevuncertainty-1.0.0 + schema_uri: http://astropy.org/schemas/astropy/nddata/stddevuncertainty-1.0.0 title: Represent the nddata.uncertainty.StdDevUncertainty object description: |- Represents an instance of the nddata.uncertainty.StdDevUncertainty object diff --git a/asdf_astropy/resources/manifests/astropy-1.3.0.yaml b/asdf_astropy/resources/manifests/astropy-1.3.0.yaml index 161a7c16..630406bc 100644 --- a/asdf_astropy/resources/manifests/astropy-1.3.0.yaml +++ b/asdf_astropy/resources/manifests/astropy-1.3.0.yaml @@ -54,13 +54,13 @@ tags: title: NdarrayMixin column. description: |- Represents an astropy.table.NdarrayMixin instance. -- tag_uri: tag:astropy.org:astropy/uncertainty/unknownuncertainty-1.0.0 - schema_uri: http://astropy.org/schemas/astropy/uncertainty/unknownuncertainty-1.0.0 +- tag_uri: tag:astropy.org:astropy/nddata/unknownuncertainty-1.0.0 + schema_uri: http://astropy.org/schemas/astropy/nddata/unknownuncertainty-1.0.0 title: Represent the nddata.uncertainty.UnknownUncertainty object description: |- Represents an instance of the nddata.uncertainty.UnknownUncertainty object -- tag_uri: tag:astropy.org:astropy/uncertainty/stddevuncertainty-1.0.0 - schema_uri: http://astropy.org/schemas/astropy/uncertainty/stddevuncertainty-1.0.0 +- tag_uri: tag:astropy.org:astropy/nddata/stddevuncertainty-1.0.0 + schema_uri: http://astropy.org/schemas/astropy/nddata/stddevuncertainty-1.0.0 title: Represent the nddata.uncertainty.StdDevUncertainty object description: |- Represents an instance of the nddata.uncertainty.StdDevUncertainty object diff --git a/asdf_astropy/resources/schemas/uncertainty/stddevuncertainty-1.0.0.yaml b/asdf_astropy/resources/schemas/nddata/stddevuncertainty-1.0.0.yaml similarity index 86% rename from asdf_astropy/resources/schemas/uncertainty/stddevuncertainty-1.0.0.yaml rename to asdf_astropy/resources/schemas/nddata/stddevuncertainty-1.0.0.yaml index 0e3490af..bf288538 100644 --- a/asdf_astropy/resources/schemas/uncertainty/stddevuncertainty-1.0.0.yaml +++ b/asdf_astropy/resources/schemas/nddata/stddevuncertainty-1.0.0.yaml @@ -1,7 +1,7 @@ %YAML 1.1 --- $schema: "http://stsci.edu/schemas/yaml-schema/draft-01" -id: "http://astropy.org/schemas/astropy/uncertainty/stddevuncertainty-1.0.0" +id: "http://astropy.org/schemas/astropy/nddata/stddevuncertainty-1.0.0" title: Represents the astropy.nddata.StdDevUncertainty class diff --git a/asdf_astropy/resources/schemas/uncertainty/unknownuncertainty-1.0.0.yaml b/asdf_astropy/resources/schemas/nddata/unknownuncertainty-1.0.0.yaml similarity index 86% rename from asdf_astropy/resources/schemas/uncertainty/unknownuncertainty-1.0.0.yaml rename to asdf_astropy/resources/schemas/nddata/unknownuncertainty-1.0.0.yaml index 62f6c6a8..ee8b9983 100644 --- a/asdf_astropy/resources/schemas/uncertainty/unknownuncertainty-1.0.0.yaml +++ b/asdf_astropy/resources/schemas/nddata/unknownuncertainty-1.0.0.yaml @@ -1,7 +1,7 @@ %YAML 1.1 --- $schema: "http://stsci.edu/schemas/yaml-schema/draft-01" -id: "http://astropy.org/schemas/astropy/uncertainty/unknownuncertainty-1.0.0" +id: "http://astropy.org/schemas/astropy/nddata/unknownuncertainty-1.0.0" title: Represents the astropy.nddata.UnknownUncertainty class diff --git a/asdf_astropy/resources/schemas/uncertainty/uncertainty-1.0.0.yaml b/asdf_astropy/resources/schemas/uncertainty/uncertainty-1.0.0.yaml deleted file mode 100644 index af03a01b..00000000 --- a/asdf_astropy/resources/schemas/uncertainty/uncertainty-1.0.0.yaml +++ /dev/null @@ -1,21 +0,0 @@ -%YAML 1.1 ---- -$schema: "http://stsci.edu/schemas/yaml-schema/draft-01" -id: "http://astropy.org/schemas/astropy/uncertainty/uncertainty-1.0.0" - -title: - Represents the astropy.nddata.NDUncertainty object - -description: - Represents the astropy.nddata.NDUncertainty object - -allOf: - - tag: "tag:astropy.org:astropy/uncertainty/uncertainty-1.0.0" - - type: object - properties: - array: - type: object - unit: - anyOf: - - tag: "tag:stsci.edu:asdf/unit/unit-*" - - tag: "tag:astropy.org:astropy/units/unit-1.*" From 5b533f2b4926ec77563a6386b20f3d690a3cbf3a Mon Sep 17 00:00:00 2001 From: Brett Date: Wed, 6 Nov 2024 13:36:47 -0500 Subject: [PATCH 05/10] add VarianceUncertainty support --- asdf_astropy/converters/__init__.py | 3 ++- asdf_astropy/converters/nddata/__init__.py | 3 ++- .../nddata/tests/test_uncertainty.py | 14 +++++++++++-- asdf_astropy/converters/nddata/uncertainty.py | 11 ++++++++++ asdf_astropy/extensions.py | 7 ++++++- .../resources/manifests/astropy-1.2.0.yaml | 5 +++++ .../resources/manifests/astropy-1.3.0.yaml | 5 +++++ .../nddata/varianceuncertainty-1.0.0.yaml | 21 +++++++++++++++++++ 8 files changed, 64 insertions(+), 5 deletions(-) create mode 100644 asdf_astropy/resources/schemas/nddata/varianceuncertainty-1.0.0.yaml diff --git a/asdf_astropy/converters/__init__.py b/asdf_astropy/converters/__init__.py index f2536557..714240d5 100644 --- a/asdf_astropy/converters/__init__.py +++ b/asdf_astropy/converters/__init__.py @@ -21,6 +21,7 @@ "NdarrayMixinConverter", "StdDevUncertaintyConverter", "UnknownUncertaintyConverter", + "VarianceUncertaintyConverter", "TimeDeltaConverter", "TimeConverter", "CompoundConverter", @@ -54,7 +55,7 @@ SpectralCoordConverter, ) from .fits import AsdfFitsConverter, AstropyFitsConverter, FitsConverter -from .nddata import StdDevUncertaintyConverter, UnknownUncertaintyConverter +from .nddata import StdDevUncertaintyConverter, UnknownUncertaintyConverter, VarianceUncertaintyConverter from .table import AsdfTableConverter, AstropyTableConverter, ColumnConverter, NdarrayMixinConverter from .time import TimeConverter, TimeDeltaConverter from .transform import ( diff --git a/asdf_astropy/converters/nddata/__init__.py b/asdf_astropy/converters/nddata/__init__.py index 43921e8d..4fc4aa94 100644 --- a/asdf_astropy/converters/nddata/__init__.py +++ b/asdf_astropy/converters/nddata/__init__.py @@ -1,6 +1,7 @@ __all__ = [ "StdDevUncertaintyConverter", "UnknownUncertaintyConverter", + "VarianceUncertaintyConverter", ] -from .uncertainty import StdDevUncertaintyConverter, UnknownUncertaintyConverter +from .uncertainty import StdDevUncertaintyConverter, UnknownUncertaintyConverter, VarianceUncertaintyConverter diff --git a/asdf_astropy/converters/nddata/tests/test_uncertainty.py b/asdf_astropy/converters/nddata/tests/test_uncertainty.py index 6d71a192..5e4c817f 100644 --- a/asdf_astropy/converters/nddata/tests/test_uncertainty.py +++ b/asdf_astropy/converters/nddata/tests/test_uncertainty.py @@ -2,7 +2,7 @@ import numpy as np import pytest from astropy import units as u -from astropy.nddata import StdDevUncertainty, UnknownUncertainty +from astropy.nddata import StdDevUncertainty, UnknownUncertainty, VarianceUncertainty def create_uncertainty(): @@ -11,7 +11,16 @@ def create_uncertainty(): uncertainty_stddev_2 = StdDevUncertainty([2], unit="m") uncertainty_unknown_1 = UnknownUncertainty(uncert, unit="m") uncertainty_unknown_2 = UnknownUncertainty([0.4], unit=u.adu) - return [uncertainty_stddev_1, uncertainty_stddev_2, uncertainty_unknown_1, uncertainty_unknown_2] + uncertainty_variance_1 = VarianceUncertainty(uncert, unit="m") + uncertainty_variance_2 = VarianceUncertainty([0.4], unit=u.adu) + return [ + uncertainty_stddev_1, + uncertainty_stddev_2, + uncertainty_unknown_1, + uncertainty_unknown_2, + uncertainty_variance_1, + uncertainty_variance_2, + ] @pytest.mark.parametrize("uncertainty", create_uncertainty()) @@ -23,5 +32,6 @@ def test_uncertainty_serialization(uncertainty, tmp_path): with asdf.open(file_path) as af: loaded_uncert = af["uncertainty"] + assert type(loaded_uncert) == type(uncertainty) assert (loaded_uncert._array == uncertainty._array).all() assert loaded_uncert.unit == uncertainty.unit diff --git a/asdf_astropy/converters/nddata/uncertainty.py b/asdf_astropy/converters/nddata/uncertainty.py index ae4d6802..29135f2e 100644 --- a/asdf_astropy/converters/nddata/uncertainty.py +++ b/asdf_astropy/converters/nddata/uncertainty.py @@ -32,3 +32,14 @@ def from_yaml_tree(self, node, tag, ctx): array, unit = super().from_yaml_tree(node, tag, ctx) return UnknownUncertainty(array=array, unit=unit) + + +class VarianceUncertaintyConverter(_UncertaintyBaseConverter): + tags = ("tag:astropy.org:astropy/nddata/varianceuncertainty-*",) + types = ("astropy.nddata.nduncertainty.VarianceUncertainty",) + + def from_yaml_tree(self, node, tag, ctx): + from astropy.nddata import VarianceUncertainty + + array, unit = super().from_yaml_tree(node, tag, ctx) + return VarianceUncertainty(array=array, unit=unit) diff --git a/asdf_astropy/extensions.py b/asdf_astropy/extensions.py index f574dc44..79ea9019 100644 --- a/asdf_astropy/extensions.py +++ b/asdf_astropy/extensions.py @@ -12,7 +12,11 @@ from .converters.coordinates.sky_coord import SkyCoordConverter from .converters.coordinates.spectral_coord import SpectralCoordConverter from .converters.fits.fits import AsdfFitsConverter, AstropyFitsConverter -from .converters.nddata.uncertainty import StdDevUncertaintyConverter, UnknownUncertaintyConverter +from .converters.nddata.uncertainty import ( + StdDevUncertaintyConverter, + UnknownUncertaintyConverter, + VarianceUncertaintyConverter, +) from .converters.table.table import AsdfTableConverter, AstropyTableConverter, ColumnConverter, NdarrayMixinConverter from .converters.time.time import TimeConverter from .converters.time.time_delta import TimeDeltaConverter @@ -479,6 +483,7 @@ NdarrayMixinConverter(), StdDevUncertaintyConverter(), UnknownUncertaintyConverter(), + VarianceUncertaintyConverter(), ] _COORDINATES_MANIFEST_URIS = [ diff --git a/asdf_astropy/resources/manifests/astropy-1.2.0.yaml b/asdf_astropy/resources/manifests/astropy-1.2.0.yaml index c5f0ca27..2116d839 100644 --- a/asdf_astropy/resources/manifests/astropy-1.2.0.yaml +++ b/asdf_astropy/resources/manifests/astropy-1.2.0.yaml @@ -64,3 +64,8 @@ tags: title: Represent the nddata.uncertainty.StdDevUncertainty object description: |- Represents an instance of the nddata.uncertainty.StdDevUncertainty object +- tag_uri: tag:astropy.org:astropy/nddata/varianceuncertainty-1.0.0 + schema_uri: http://astropy.org/schemas/astropy/nddata/varianceuncertainty-1.0.0 + title: Represent the nddata.uncertainty.VarianceUncertainty object + description: |- + Represents an instance of the nddata.uncertainty.VarianceUncertainty object diff --git a/asdf_astropy/resources/manifests/astropy-1.3.0.yaml b/asdf_astropy/resources/manifests/astropy-1.3.0.yaml index 630406bc..58412328 100644 --- a/asdf_astropy/resources/manifests/astropy-1.3.0.yaml +++ b/asdf_astropy/resources/manifests/astropy-1.3.0.yaml @@ -64,3 +64,8 @@ tags: title: Represent the nddata.uncertainty.StdDevUncertainty object description: |- Represents an instance of the nddata.uncertainty.StdDevUncertainty object +- tag_uri: tag:astropy.org:astropy/nddata/varianceuncertainty-1.0.0 + schema_uri: http://astropy.org/schemas/astropy/nddata/varianceuncertainty-1.0.0 + title: Represent the nddata.uncertainty.VarianceUncertainty object + description: |- + Represents an instance of the nddata.uncertainty.VarianceUncertainty object diff --git a/asdf_astropy/resources/schemas/nddata/varianceuncertainty-1.0.0.yaml b/asdf_astropy/resources/schemas/nddata/varianceuncertainty-1.0.0.yaml new file mode 100644 index 00000000..d1a36df5 --- /dev/null +++ b/asdf_astropy/resources/schemas/nddata/varianceuncertainty-1.0.0.yaml @@ -0,0 +1,21 @@ +%YAML 1.1 +--- +$schema: "http://stsci.edu/schemas/yaml-schema/draft-01" +id: "http://astropy.org/schemas/astropy/nddata/varianceuncertainty-1.0.0" + +title: + Represents the astropy.nddata.VarianceUncertainty class + +description: + This object represents the `VarianceUncertainty` class, which is a subclass + of the `NDUncertainty` class from `astropy.nddata` + +allOf: + - type: object + properties: + array: + type: object + unit: + anyOf: + - tag: "tag:stsci.edu:asdf/unit/unit-*" + - tag: "tag:astropy.org:astropy/units/unit-1.*" From aaa5fa452600dc9e71d2f7ea7485896a8681818d Mon Sep 17 00:00:00 2001 From: Brett Date: Wed, 6 Nov 2024 14:02:01 -0500 Subject: [PATCH 06/10] update changelog --- CHANGES.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES.rst b/CHANGES.rst index f434ea87..4027b550 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -10,7 +10,7 @@ - require asdf 2.14.4 [#241] -- Add support for astropy.nddata.StdDevUncertainty and astropy.nddata.UnknownUncertainty[#239] +- Add support for astropy.nddata.uncertainty classes [#239] 0.6.1 (2024-04-05) ------------------ From 09df40af5ea59acb6f76ea515c11d425fa90d990 Mon Sep 17 00:00:00 2001 From: Brett Date: Wed, 6 Nov 2024 14:15:19 -0500 Subject: [PATCH 07/10] add schema to docs --- .../schemas/nddata/stddevuncertainty-1.0.0.yaml | 5 ++--- .../schemas/nddata/unknownuncertainty-1.0.0.yaml | 5 ++--- .../schemas/nddata/varianceuncertainty-1.0.0.yaml | 5 ++--- docs/asdf-astropy/schemas.rst | 15 +++++++++++++++ 4 files changed, 21 insertions(+), 9 deletions(-) diff --git a/asdf_astropy/resources/schemas/nddata/stddevuncertainty-1.0.0.yaml b/asdf_astropy/resources/schemas/nddata/stddevuncertainty-1.0.0.yaml index bf288538..514cf61f 100644 --- a/asdf_astropy/resources/schemas/nddata/stddevuncertainty-1.0.0.yaml +++ b/asdf_astropy/resources/schemas/nddata/stddevuncertainty-1.0.0.yaml @@ -3,10 +3,9 @@ $schema: "http://stsci.edu/schemas/yaml-schema/draft-01" id: "http://astropy.org/schemas/astropy/nddata/stddevuncertainty-1.0.0" -title: - Represents the astropy.nddata.StdDevUncertainty class +title: Represents the astropy.nddata.StdDevUncertainty class -description: +description: >- This object represents the `StdDevUncertainty` class, which is a subclass of the `NDUncertainty` class from `astropy.nddata` diff --git a/asdf_astropy/resources/schemas/nddata/unknownuncertainty-1.0.0.yaml b/asdf_astropy/resources/schemas/nddata/unknownuncertainty-1.0.0.yaml index ee8b9983..b384ff66 100644 --- a/asdf_astropy/resources/schemas/nddata/unknownuncertainty-1.0.0.yaml +++ b/asdf_astropy/resources/schemas/nddata/unknownuncertainty-1.0.0.yaml @@ -3,10 +3,9 @@ $schema: "http://stsci.edu/schemas/yaml-schema/draft-01" id: "http://astropy.org/schemas/astropy/nddata/unknownuncertainty-1.0.0" -title: - Represents the astropy.nddata.UnknownUncertainty class +title: Represents the astropy.nddata.UnknownUncertainty class -description: +description: >- This object represents the `UnknownUncertainty` class, which is a subclass of the `NDUncertainty` class from `astropy.nddata` diff --git a/asdf_astropy/resources/schemas/nddata/varianceuncertainty-1.0.0.yaml b/asdf_astropy/resources/schemas/nddata/varianceuncertainty-1.0.0.yaml index d1a36df5..7ccb46d4 100644 --- a/asdf_astropy/resources/schemas/nddata/varianceuncertainty-1.0.0.yaml +++ b/asdf_astropy/resources/schemas/nddata/varianceuncertainty-1.0.0.yaml @@ -3,10 +3,9 @@ $schema: "http://stsci.edu/schemas/yaml-schema/draft-01" id: "http://astropy.org/schemas/astropy/nddata/varianceuncertainty-1.0.0" -title: - Represents the astropy.nddata.VarianceUncertainty class +title: Represents the astropy.nddata.VarianceUncertainty class -description: +description: >- This object represents the `VarianceUncertainty` class, which is a subclass of the `NDUncertainty` class from `astropy.nddata` diff --git a/docs/asdf-astropy/schemas.rst b/docs/asdf-astropy/schemas.rst index 5c60b849..ba6be745 100644 --- a/docs/asdf-astropy/schemas.rst +++ b/docs/asdf-astropy/schemas.rst @@ -30,6 +30,21 @@ fits/fits-1.0.0 fits/fits-1.0.0 +NDData +------ + +The following schemas are associated with **astropy** objects from the +:ref:`astropy_nddata` submodule: + +units/equivalency-1.0.0 +^^^^^^^^^^^^^^^^^^^^^^^ + +.. asdf-autoschemas:: + + nddata/stddevuncertainty-1.0.0 + nddata/unknownuncertainty-1.0.0 + nddata/varianceuncertainty-1.0.0 + Table ----- From 34da76e132b24c327fb821dd5519fc535668a4cd Mon Sep 17 00:00:00 2001 From: Brett Date: Thu, 7 Nov 2024 10:29:22 -0500 Subject: [PATCH 08/10] Consolidate all uncertainties into one --- asdf_astropy/converters/__init__.py | 6 +- asdf_astropy/converters/nddata/__init__.py | 6 +- asdf_astropy/converters/nddata/uncertainty.py | 66 ++++++++----------- asdf_astropy/extensions.py | 10 +-- .../resources/manifests/astropy-1.2.0.yaml | 18 ++--- .../resources/manifests/astropy-1.3.0.yaml | 18 ++--- .../nddata/stddevuncertainty-1.0.0.yaml | 20 ------ ...inty-1.0.0.yaml => uncertainty-1.0.0.yaml} | 8 ++- .../nddata/varianceuncertainty-1.0.0.yaml | 20 ------ pyproject.toml | 1 + 10 files changed, 48 insertions(+), 125 deletions(-) delete mode 100644 asdf_astropy/resources/schemas/nddata/stddevuncertainty-1.0.0.yaml rename asdf_astropy/resources/schemas/nddata/{unknownuncertainty-1.0.0.yaml => uncertainty-1.0.0.yaml} (65%) delete mode 100644 asdf_astropy/resources/schemas/nddata/varianceuncertainty-1.0.0.yaml diff --git a/asdf_astropy/converters/__init__.py b/asdf_astropy/converters/__init__.py index 714240d5..92d7730a 100644 --- a/asdf_astropy/converters/__init__.py +++ b/asdf_astropy/converters/__init__.py @@ -19,9 +19,7 @@ "AstropyTableConverter", "AsdfTableConverter", "NdarrayMixinConverter", - "StdDevUncertaintyConverter", - "UnknownUncertaintyConverter", - "VarianceUncertaintyConverter", + "UncertaintyConverter", "TimeDeltaConverter", "TimeConverter", "CompoundConverter", @@ -55,7 +53,7 @@ SpectralCoordConverter, ) from .fits import AsdfFitsConverter, AstropyFitsConverter, FitsConverter -from .nddata import StdDevUncertaintyConverter, UnknownUncertaintyConverter, VarianceUncertaintyConverter +from .nddata import UncertaintyConverter from .table import AsdfTableConverter, AstropyTableConverter, ColumnConverter, NdarrayMixinConverter from .time import TimeConverter, TimeDeltaConverter from .transform import ( diff --git a/asdf_astropy/converters/nddata/__init__.py b/asdf_astropy/converters/nddata/__init__.py index 4fc4aa94..641fc093 100644 --- a/asdf_astropy/converters/nddata/__init__.py +++ b/asdf_astropy/converters/nddata/__init__.py @@ -1,7 +1,5 @@ __all__ = [ - "StdDevUncertaintyConverter", - "UnknownUncertaintyConverter", - "VarianceUncertaintyConverter", + "UncertaintyConverter", ] -from .uncertainty import StdDevUncertaintyConverter, UnknownUncertaintyConverter, VarianceUncertaintyConverter +from .uncertainty import UncertaintyConverter diff --git a/asdf_astropy/converters/nddata/uncertainty.py b/asdf_astropy/converters/nddata/uncertainty.py index 29135f2e..e807a2c7 100644 --- a/asdf_astropy/converters/nddata/uncertainty.py +++ b/asdf_astropy/converters/nddata/uncertainty.py @@ -1,45 +1,35 @@ -class _UncertaintyBaseConverter: - def from_yaml_tree(self, node, tag, ctx): - return (node["array"], node.get("unit")) - - def to_yaml_tree(self, nddata_uncertainty, tag, ctx): - node = {} - - node["array"] = nddata_uncertainty.array - if nddata_uncertainty.unit is not None: - node["unit"] = nddata_uncertainty.unit - - return node - - -class StdDevUncertaintyConverter(_UncertaintyBaseConverter): - tags = ("tag:astropy.org:astropy/nddata/stddevuncertainty-*",) - types = ("astropy.nddata.nduncertainty.StdDevUncertainty",) +class UncertaintyConverter: + tags = ("tag:astropy.org:astropy/nddata/uncertainty-*",) + types = ( + "astropy.nddata.nduncertainty.StdDevUncertainty", + "astropy.nddata.nduncertainty.UnknownUncertainty", + "astropy.nddata.nduncertainty.VarianceUncertainty", + ) + + # Mapping of uncertainty class name (attribute of astropy.nddata) + # and code "name" stored in the data file. + # This will need to be separately versioned if the schema is updated. + _class_name_to_code = { + "StdDevUncertainty": "stddev", + "UnknownUncertainty": "unknown", + "VarianceUncertainty": "variance", + } + _class_code_to_name = {v: k for k, v in _class_name_to_code.items()} def from_yaml_tree(self, node, tag, ctx): - from astropy.nddata import StdDevUncertainty + import astropy.nddata - array, unit = super().from_yaml_tree(node, tag, ctx) - return StdDevUncertainty(array=array, unit=unit) + class_name = self._class_code_to_name[node["name"]] + return getattr(astropy.nddata, class_name)(node["array"], unit=node.get("unit")) -class UnknownUncertaintyConverter(_UncertaintyBaseConverter): - tags = ("tag:astropy.org:astropy/nddata/unknownuncertainty-*",) - types = ("astropy.nddata.nduncertainty.UnknownUncertainty",) + def to_yaml_tree(self, obj, tag, ctx): + node = { + "name": self._class_name_to_code[obj.__class__.__name__], + "array": obj.array, + } - def from_yaml_tree(self, node, tag, ctx): - from astropy.nddata import UnknownUncertainty - - array, unit = super().from_yaml_tree(node, tag, ctx) - return UnknownUncertainty(array=array, unit=unit) - - -class VarianceUncertaintyConverter(_UncertaintyBaseConverter): - tags = ("tag:astropy.org:astropy/nddata/varianceuncertainty-*",) - types = ("astropy.nddata.nduncertainty.VarianceUncertainty",) + if obj.unit is not None: + node["unit"] = obj.unit - def from_yaml_tree(self, node, tag, ctx): - from astropy.nddata import VarianceUncertainty - - array, unit = super().from_yaml_tree(node, tag, ctx) - return VarianceUncertainty(array=array, unit=unit) + return node diff --git a/asdf_astropy/extensions.py b/asdf_astropy/extensions.py index 79ea9019..ffaf0904 100644 --- a/asdf_astropy/extensions.py +++ b/asdf_astropy/extensions.py @@ -12,11 +12,7 @@ from .converters.coordinates.sky_coord import SkyCoordConverter from .converters.coordinates.spectral_coord import SpectralCoordConverter from .converters.fits.fits import AsdfFitsConverter, AstropyFitsConverter -from .converters.nddata.uncertainty import ( - StdDevUncertaintyConverter, - UnknownUncertaintyConverter, - VarianceUncertaintyConverter, -) +from .converters.nddata.uncertainty import UncertaintyConverter from .converters.table.table import AsdfTableConverter, AstropyTableConverter, ColumnConverter, NdarrayMixinConverter from .converters.time.time import TimeConverter from .converters.time.time_delta import TimeDeltaConverter @@ -481,9 +477,7 @@ AstropyTableConverter(), AstropyFitsConverter(), NdarrayMixinConverter(), - StdDevUncertaintyConverter(), - UnknownUncertaintyConverter(), - VarianceUncertaintyConverter(), + UncertaintyConverter(), ] _COORDINATES_MANIFEST_URIS = [ diff --git a/asdf_astropy/resources/manifests/astropy-1.2.0.yaml b/asdf_astropy/resources/manifests/astropy-1.2.0.yaml index 2116d839..80f63bb1 100644 --- a/asdf_astropy/resources/manifests/astropy-1.2.0.yaml +++ b/asdf_astropy/resources/manifests/astropy-1.2.0.yaml @@ -54,18 +54,8 @@ tags: title: NdarrayMixin column. description: |- Represents an astropy.table.NdarrayMixin instance. -- tag_uri: tag:astropy.org:astropy/nddata/unknownuncertainty-1.0.0 - schema_uri: http://astropy.org/schemas/astropy/nddata/unknownuncertainty-1.0.0 - title: Represent the nddata.uncertainty.UnknownUncertainty object +- tag_uri: tag:astropy.org:astropy/nddata/uncertainty-1.0.0 + schema_uri: http://astropy.org/schemas/astropy/nddata/uncertainty-1.0.0 + title: Represent an astropy.nddata uncertainty description: |- - Represents an instance of the nddata.uncertainty.UnknownUncertainty object -- tag_uri: tag:astropy.org:astropy/nddata/stddevuncertainty-1.0.0 - schema_uri: http://astropy.org/schemas/astropy/nddata/stddevuncertainty-1.0.0 - title: Represent the nddata.uncertainty.StdDevUncertainty object - description: |- - Represents an instance of the nddata.uncertainty.StdDevUncertainty object -- tag_uri: tag:astropy.org:astropy/nddata/varianceuncertainty-1.0.0 - schema_uri: http://astropy.org/schemas/astropy/nddata/varianceuncertainty-1.0.0 - title: Represent the nddata.uncertainty.VarianceUncertainty object - description: |- - Represents an instance of the nddata.uncertainty.VarianceUncertainty object + Represents an instance of an astropy.nddata uncertainty diff --git a/asdf_astropy/resources/manifests/astropy-1.3.0.yaml b/asdf_astropy/resources/manifests/astropy-1.3.0.yaml index 58412328..53c3720a 100644 --- a/asdf_astropy/resources/manifests/astropy-1.3.0.yaml +++ b/asdf_astropy/resources/manifests/astropy-1.3.0.yaml @@ -54,18 +54,8 @@ tags: title: NdarrayMixin column. description: |- Represents an astropy.table.NdarrayMixin instance. -- tag_uri: tag:astropy.org:astropy/nddata/unknownuncertainty-1.0.0 - schema_uri: http://astropy.org/schemas/astropy/nddata/unknownuncertainty-1.0.0 - title: Represent the nddata.uncertainty.UnknownUncertainty object +- tag_uri: tag:astropy.org:astropy/nddata/uncertainty-1.0.0 + schema_uri: http://astropy.org/schemas/astropy/nddata/uncertainty-1.0.0 + title: Represent an astropy.nddata uncertainty description: |- - Represents an instance of the nddata.uncertainty.UnknownUncertainty object -- tag_uri: tag:astropy.org:astropy/nddata/stddevuncertainty-1.0.0 - schema_uri: http://astropy.org/schemas/astropy/nddata/stddevuncertainty-1.0.0 - title: Represent the nddata.uncertainty.StdDevUncertainty object - description: |- - Represents an instance of the nddata.uncertainty.StdDevUncertainty object -- tag_uri: tag:astropy.org:astropy/nddata/varianceuncertainty-1.0.0 - schema_uri: http://astropy.org/schemas/astropy/nddata/varianceuncertainty-1.0.0 - title: Represent the nddata.uncertainty.VarianceUncertainty object - description: |- - Represents an instance of the nddata.uncertainty.VarianceUncertainty object + Represents an instance of an astropy.nddata uncertainty diff --git a/asdf_astropy/resources/schemas/nddata/stddevuncertainty-1.0.0.yaml b/asdf_astropy/resources/schemas/nddata/stddevuncertainty-1.0.0.yaml deleted file mode 100644 index 514cf61f..00000000 --- a/asdf_astropy/resources/schemas/nddata/stddevuncertainty-1.0.0.yaml +++ /dev/null @@ -1,20 +0,0 @@ -%YAML 1.1 ---- -$schema: "http://stsci.edu/schemas/yaml-schema/draft-01" -id: "http://astropy.org/schemas/astropy/nddata/stddevuncertainty-1.0.0" - -title: Represents the astropy.nddata.StdDevUncertainty class - -description: >- - This object represents the `StdDevUncertainty` class, which is a subclass - of the `NDUncertainty` class from `astropy.nddata` - -allOf: - - type: object - properties: - array: - type: object - unit: - anyOf: - - tag: "tag:stsci.edu:asdf/unit/unit-*" - - tag: "tag:astropy.org:astropy/units/unit-1.*" diff --git a/asdf_astropy/resources/schemas/nddata/unknownuncertainty-1.0.0.yaml b/asdf_astropy/resources/schemas/nddata/uncertainty-1.0.0.yaml similarity index 65% rename from asdf_astropy/resources/schemas/nddata/unknownuncertainty-1.0.0.yaml rename to asdf_astropy/resources/schemas/nddata/uncertainty-1.0.0.yaml index b384ff66..ddced424 100644 --- a/asdf_astropy/resources/schemas/nddata/unknownuncertainty-1.0.0.yaml +++ b/asdf_astropy/resources/schemas/nddata/uncertainty-1.0.0.yaml @@ -3,18 +3,20 @@ $schema: "http://stsci.edu/schemas/yaml-schema/draft-01" id: "http://astropy.org/schemas/astropy/nddata/unknownuncertainty-1.0.0" -title: Represents the astropy.nddata.UnknownUncertainty class +title: Represents an astropy.nddata uncertainty class description: >- - This object represents the `UnknownUncertainty` class, which is a subclass - of the `NDUncertainty` class from `astropy.nddata` + This object represents an uncertainty. allOf: - type: object properties: + name: + enum: ["stddev", "unknown", "variance"] array: type: object unit: anyOf: - tag: "tag:stsci.edu:asdf/unit/unit-*" - tag: "tag:astropy.org:astropy/units/unit-1.*" + required: [name, array] diff --git a/asdf_astropy/resources/schemas/nddata/varianceuncertainty-1.0.0.yaml b/asdf_astropy/resources/schemas/nddata/varianceuncertainty-1.0.0.yaml deleted file mode 100644 index 7ccb46d4..00000000 --- a/asdf_astropy/resources/schemas/nddata/varianceuncertainty-1.0.0.yaml +++ /dev/null @@ -1,20 +0,0 @@ -%YAML 1.1 ---- -$schema: "http://stsci.edu/schemas/yaml-schema/draft-01" -id: "http://astropy.org/schemas/astropy/nddata/varianceuncertainty-1.0.0" - -title: Represents the astropy.nddata.VarianceUncertainty class - -description: >- - This object represents the `VarianceUncertainty` class, which is a subclass - of the `NDUncertainty` class from `astropy.nddata` - -allOf: - - type: object - properties: - array: - type: object - unit: - anyOf: - - tag: "tag:stsci.edu:asdf/unit/unit-*" - - tag: "tag:astropy.org:astropy/units/unit-1.*" diff --git a/pyproject.toml b/pyproject.toml index 8855a8ff..5cfadc13 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -96,6 +96,7 @@ extend-ignore = [ # Individually ignored checks "SLF001", # private-member-access "FBT001", # boolean positional arguments in function definition + "RUF012", # mutable class attributes should be annotated with typing.ClassVar ] extend-exclude = ["docs/*"] From 8d0137eefd1da130ca828151c7e805ced8baf8a1 Mon Sep 17 00:00:00 2001 From: Brett Date: Fri, 8 Nov 2024 10:36:51 -0500 Subject: [PATCH 09/10] fix docs --- docs/asdf-astropy/schemas.rst | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/docs/asdf-astropy/schemas.rst b/docs/asdf-astropy/schemas.rst index ba6be745..30d5ea4c 100644 --- a/docs/asdf-astropy/schemas.rst +++ b/docs/asdf-astropy/schemas.rst @@ -36,14 +36,12 @@ NDData The following schemas are associated with **astropy** objects from the :ref:`astropy_nddata` submodule: -units/equivalency-1.0.0 -^^^^^^^^^^^^^^^^^^^^^^^ +nddata/uncertainty-1.0.0 +^^^^^^^^^^^^^^^^^^^^^^^^ .. asdf-autoschemas:: - nddata/stddevuncertainty-1.0.0 - nddata/unknownuncertainty-1.0.0 - nddata/varianceuncertainty-1.0.0 + nddata/uncertainty-1.0.0 Table ----- From 5a2f7cfdb7662a0fe1c5c2c8b7ed71bc7eb7eff4 Mon Sep 17 00:00:00 2001 From: Brett Date: Fri, 8 Nov 2024 10:38:02 -0500 Subject: [PATCH 10/10] fix schema id --- asdf_astropy/resources/schemas/nddata/uncertainty-1.0.0.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/asdf_astropy/resources/schemas/nddata/uncertainty-1.0.0.yaml b/asdf_astropy/resources/schemas/nddata/uncertainty-1.0.0.yaml index ddced424..63d10b45 100644 --- a/asdf_astropy/resources/schemas/nddata/uncertainty-1.0.0.yaml +++ b/asdf_astropy/resources/schemas/nddata/uncertainty-1.0.0.yaml @@ -1,7 +1,7 @@ %YAML 1.1 --- $schema: "http://stsci.edu/schemas/yaml-schema/draft-01" -id: "http://astropy.org/schemas/astropy/nddata/unknownuncertainty-1.0.0" +id: "http://astropy.org/schemas/astropy/nddata/uncertainty-1.0.0" title: Represents an astropy.nddata uncertainty class