Skip to content

Commit

Permalink
Allow serializing and deserializing of named astropy units.
Browse files Browse the repository at this point in the history
  • Loading branch information
Carifio24 committed Jan 12, 2024
1 parent 5f38baf commit 0104030
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
11 changes: 11 additions & 0 deletions glue/core/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ def load(rec, context)
import numpy as np
from matplotlib.colors import Colormap
from matplotlib import cm
from astropy.units import NamedUnit, Unit
from astropy.wcs import WCS
import shapely

Expand Down Expand Up @@ -621,6 +622,16 @@ def _load_slice(rec, context):
return slice(rec['start'], rec['stop'], rec['step'])


@saver(NamedUnit)
def _save_named_unit(unit, context):
return dict(named_unit=unit.to_string())


@loader(NamedUnit)
def _load_named_unit(rec, context):
return Unit(rec["named_unit"])


@saver(WCS)
def _save_wcs(wcs, context):
return dict(header=wcs.to_header_string())
Expand Down
8 changes: 8 additions & 0 deletions glue/core/tests/test_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,14 @@ def test_datetime_component():
assert isinstance(c2.data[0], np.datetime64)


@requires_astropy
def test_astropy_units():
import astropy.units as u
unit = u.m
unit2 = clone(unit)
assert unit2 is unit


class DummyClass(object):
pass

Expand Down

0 comments on commit 0104030

Please sign in to comment.