Debian Codegraph @

asdf_astropy/converters/wcs/slicedwcs.py

raw
1 from asdf.extension import Converter
2
3
4 class SlicedWCSConverter(Converter):
5 tags = ("tag:astropy.org:astropy/wcs/slicedwcs-*",)
6 types = ("astropy.wcs.wcsapi.wrappers.sliced_wcs.SlicedLowLevelWCS",)
7
8 def from_yaml_tree(self, node, tag, ctx):
9 from astropy.wcs.wcsapi.wrappers.sliced_wcs import SlicedLowLevelWCS
10
11 wcs = node["wcs"]
12 slice_array = [
13 s if isinstance(s, int) else slice(s["start"], s["stop"], s["step"]) for s in node["slices_array"]
14 ]
15 return SlicedLowLevelWCS(wcs, slice_array)
16
17 def to_yaml_tree(self, sl, tag, ctx):
18 slices_array = []
19
20 for s in sl._slices_array:
21 if isinstance(s, slice):
22 slices_array.append(
23 {
24 "start": s.start,
25 "stop": s.stop,
26 "step": s.step,
27 },
28 )
29 else:
30 slices_array.append(s)
31 return {
32 "wcs": sl._wcs,
33 "slices_array": slices_array,
34 }