-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add converter and schema for basic astropy.wcs.WCS objects
- Loading branch information
1 parent
dab5b4d
commit d7bbee8
Showing
7 changed files
with
98 additions
and
1 deletion.
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
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from asdf.extension import Converter | ||
|
||
|
||
class FitsWCSConverter(Converter): | ||
""" | ||
Converter for serializing and deserializing `astropy.wcs.WCS` objects. | ||
This converter currently supports the serialization of simple WCS objects | ||
by preserving the `wcs.to_header()` data. It does not support complex WCS objects | ||
such as tabular or distortion WCSes. | ||
Future work: | ||
- Until the support for tabular and distortion WCSes is added, throw error for such WCSes when passed through in the converter | ||
- Implement mechanisms to detect tabular and distortion WCSes and support their serialization | ||
""" | ||
tags = ("tag:astropy.org:astropy/fits/fitswcs-*",) | ||
types = ("astropy.wcs.wcs.WCS", ) | ||
|
||
def from_yaml_tree(self, node, tag, ctx): | ||
from astropy.wcs import WCS | ||
|
||
header = node["header"] | ||
wcs = WCS(header) | ||
return wcs | ||
|
||
def to_yaml_tree(self, wcs, tag, ctx): | ||
node = {} | ||
node["header"] = dict(wcs.to_header()) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import asdf | ||
import pytest | ||
from astropy.wcs import WCS | ||
|
||
|
||
def create_wcs(): | ||
header = { | ||
'CTYPE1': 'TIME', | ||
'CUNIT1': 'min', | ||
'CDELT1': 0.4, | ||
'CRPIX1': 0, | ||
'CRVAL1': 0, | ||
'CTYPE2': 'WAVE', | ||
'CUNIT2': 'Angstrom', | ||
'CDELT2': 0.2, | ||
'CRPIX2': 0, | ||
'CRVAL2': 0, | ||
'CTYPE3': 'HPLT-TAN', | ||
'CUNIT3': 'arcsec', | ||
'CDELT3': 20, | ||
'CRPIX3': 0, | ||
'CRVAL3': 0, | ||
'CTYPE4': 'HPLN-TAN', | ||
'CUNIT4': 'arcsec', | ||
'CDELT4': 5, | ||
'CRPIX4': 5, | ||
'CRVAL4': 0, | ||
} | ||
return WCS(header) | ||
|
||
@pytest.mark.parametrize("wcs", [create_wcs()]) | ||
def test_wcs_serialization(wcs, tmp_path): | ||
file_path = tmp_path / "test_wcs.asdf" | ||
with asdf.AsdfFile() as af: | ||
af["wcs"] = wcs | ||
af.write_to(file_path) | ||
|
||
with asdf.open(file_path) as af: | ||
loaded_wcs = af["wcs"] | ||
|
||
assert wcs.to_header() == loaded_wcs.to_header() |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
%YAML 1.1 | ||
--- | ||
$schema: "http://stsci.edu/schemas/yaml-schema/draft-01" | ||
id: "http://astropy.org/schemas/astropy/fits/fitswcs-1.0.0" | ||
|
||
title: | ||
Represents the fits object | ||
|
||
description: | ||
Represents the fits object | ||
|
||
allOf: | ||
- tag: "tag:astropy.org:astropy/fits/fitswcs-1.0.0" | ||
- type: object | ||
properties: | ||
header: | ||
type: object |