From 55c2417b7d1f4821484a0a8723b74635ef724a02 Mon Sep 17 00:00:00 2001 From: Andy Kee Date: Tue, 9 Jul 2024 08:13:24 -0700 Subject: [PATCH] freeze WIP --- lentil/plane.py | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/lentil/plane.py b/lentil/plane.py index 7f48fd9..1e676a6 100644 --- a/lentil/plane.py +++ b/lentil/plane.py @@ -75,6 +75,14 @@ def __init__(self, amplitude=1, opd=0, mask=None, pixelscale=None, diameter=None def __repr__(self): return f'{self.__class__.__name__}()' + + def __freeze__(self): + return Plane(amplitude=self.amplitude, + opd=self.opd, + mask=self.mask, + pixelscale=self.pixelscale, + diameter=self.diameter, + ptype=self.ptype) @property def ptype(self): @@ -261,6 +269,22 @@ def copy(self): :class:`~lentil.Plane` """ return copy.deepcopy(self) + + def freeze(self): + """ + Return a static copy of this object. + + Returns + ------- + :class:`~lentil.Plane` + + Notes + ----- + The behavior of this function can be changed (for example, to freeze + additional custom attributes in a subclass) by modifying the + ``Plane.__freeze__()`` method. + """ + return self.__freeze__() def fit_tilt(self, inplace=False): """ @@ -608,6 +632,14 @@ def __init__(self, amplitude=1, opd=0, mask=None, pixelscale=None, self.focal_length = focal_length + def __freeze__(self): + return Pupil(amplitude=self.amplitude, + opd=self.opd, + mask=self.mask, + pixelscale=self.pixelscale, + diameter=self.diameter, + focal_length=self.focal_length) + def multiply(self, wavefront): wavefront = super().multiply(wavefront) @@ -656,6 +688,14 @@ def __init__(self, amplitude=1, opd=0, mask=None, pixelscale=None, pixelscale=pixelscale, ptype=lentil.image, **kwargs) + def __freeze__(self): + return Image(amplitude=self.amplitude, + opd=self.opd, + mask=self.mask, + pixelscale=self.pixelscale, + diameter=self.diameter, + ptype=self.ptype) + def fit_tilt(self, *args, **kwargs): return self