Skip to content

Commit

Permalink
Modify Plane attribute mutability, cleaner handling of mask and slice
Browse files Browse the repository at this point in the history
Resolves #45
  • Loading branch information
andykee committed Feb 26, 2024
1 parent ed9fc18 commit 9ea56da
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 20 deletions.
48 changes: 30 additions & 18 deletions lentil/plane.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,35 @@ def __init__(self, amplitude=1, opd=0, mask=None, pixelscale=None, diameter=None

self.amplitude = np.asarray(amplitude)
self.opd = np.asarray(opd)
self.mask = mask
self.pixelscale = pixelscale
self.diameter = diameter
self.ptype = lentil.ptype(ptype)

# read-only attributes
if mask is not None:
self._mask = np.asarray(mask)
self._mask[self.mask != 0] = 1
else:
self._mask = None

self._slice = _plane_slice(self._mask)
self._pixelscale = None if pixelscale is None else np.broadcast_to(pixelscale, (2,))
self._diameter = diameter
self._ptype = lentil.ptype(ptype)

self.tilt = []

def __repr__(self):
return f'{self.__class__.__name__}()'

@property
def ptype(self):
"""Plane type
Returns
-------
:class:`~lentil.ptype`
"""

return self._ptype

@property
def amplitude(self):
"""Electric field amplitude transmission
Expand Down Expand Up @@ -148,10 +166,6 @@ def pixelscale(self):
"""
return self._pixelscale

@pixelscale.setter
def pixelscale(self, value):
self._pixelscale = None if value is None else np.broadcast_to(value, (2,))

@property
def diameter(self):
Expand All @@ -174,10 +188,6 @@ def diameter(self):
return np.max(np.max((rmax-rmin, cmax-cmin)) * self.pixelscale)
else:
return self._diameter

@diameter.setter
def diameter(self, value):
self._diameter = value

@property
def shape(self):
Expand Down Expand Up @@ -367,7 +377,7 @@ def rescale(self, scale):
plane.mask = plane.mask.astype(int)

if plane.pixelscale is not None:
plane.pixelscale = (plane.pixelscale[0]/scale, plane.pixelscale[1]/scale)
plane._pixelscale = (plane.pixelscale[0]/scale, plane.pixelscale[1]/scale)

return plane

Expand Down Expand Up @@ -590,15 +600,17 @@ class Pupil(Plane):
-----
By definition, a pupil is represented by a spherical wavefront. Any
aberrations in the optical system appear as deviations from this perfect
sphere. The primary use of :class:`Pupil` is to represent these aberrations
sphere. The primary use of :class:`Pupil` is to represent this spherical
wavefront.
"""

def __init__(self, focal_length=None, pixelscale=None, amplitude=1,
opd=0, mask=None, **kwargs):
def __init__(self, amplitude=1, opd=0, mask=None, pixelscale=None,
focal_length=None, diameter=None, **kwargs):

super().__init__(pixelscale=pixelscale, amplitude=amplitude, opd=opd,
mask=mask, ptype=lentil.pupil, **kwargs)
super().__init__(amplitude=amplitude, opd=opd, mask=mask,
pixelscale=pixelscale, diameter=diameter,
ptype=lentil.pupil, **kwargs)

self.focal_length = focal_length

Expand Down
4 changes: 2 additions & 2 deletions tests/test_propagate.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,9 @@ def __init__(self, npix, diameter=1, coeffs=None):
pixelscale=1/npix,
amplitude=amplitude,
opd=opd,
mask=mask)
mask=mask,
diameter=diameter)

self.diameter = diameter
self.coeffs = coeffs


Expand Down

0 comments on commit 9ea56da

Please sign in to comment.