-
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Consolidate all uncertainties into one
- Loading branch information
Showing
10 changed files
with
48 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,5 @@ | ||
__all__ = [ | ||
"StdDevUncertaintyConverter", | ||
"UnknownUncertaintyConverter", | ||
"VarianceUncertaintyConverter", | ||
"UncertaintyConverter", | ||
] | ||
|
||
from .uncertainty import StdDevUncertaintyConverter, UnknownUncertaintyConverter, VarianceUncertaintyConverter | ||
from .uncertainty import UncertaintyConverter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 0 additions & 20 deletions
20
asdf_astropy/resources/schemas/nddata/stddevuncertainty-1.0.0.yaml
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 0 additions & 20 deletions
20
asdf_astropy/resources/schemas/nddata/varianceuncertainty-1.0.0.yaml
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters