Skip to content

Commit

Permalink
add VarianceUncertainty support
Browse files Browse the repository at this point in the history
  • Loading branch information
braingram committed Nov 6, 2024
1 parent 837fcbb commit 5b533f2
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 5 deletions.
3 changes: 2 additions & 1 deletion asdf_astropy/converters/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"NdarrayMixinConverter",
"StdDevUncertaintyConverter",
"UnknownUncertaintyConverter",
"VarianceUncertaintyConverter",
"TimeDeltaConverter",
"TimeConverter",
"CompoundConverter",
Expand Down Expand Up @@ -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 (
Expand Down
3 changes: 2 additions & 1 deletion asdf_astropy/converters/nddata/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
__all__ = [
"StdDevUncertaintyConverter",
"UnknownUncertaintyConverter",
"VarianceUncertaintyConverter",
]

from .uncertainty import StdDevUncertaintyConverter, UnknownUncertaintyConverter
from .uncertainty import StdDevUncertaintyConverter, UnknownUncertaintyConverter, VarianceUncertaintyConverter
14 changes: 12 additions & 2 deletions asdf_astropy/converters/nddata/tests/test_uncertainty.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand All @@ -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())
Expand All @@ -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
11 changes: 11 additions & 0 deletions asdf_astropy/converters/nddata/uncertainty.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
7 changes: 6 additions & 1 deletion asdf_astropy/extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -479,6 +483,7 @@
NdarrayMixinConverter(),
StdDevUncertaintyConverter(),
UnknownUncertaintyConverter(),
VarianceUncertaintyConverter(),
]

_COORDINATES_MANIFEST_URIS = [
Expand Down
5 changes: 5 additions & 0 deletions asdf_astropy/resources/manifests/astropy-1.2.0.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 5 additions & 0 deletions asdf_astropy/resources/manifests/astropy-1.3.0.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
@@ -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.*"

0 comments on commit 5b533f2

Please sign in to comment.