Skip to content

Commit

Permalink
Set internal attrs directly in Plane constructor (resolves #53)
Browse files Browse the repository at this point in the history
  • Loading branch information
andykee committed Mar 25, 2024
1 parent 20ac09d commit e34e368
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lentil/plane.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,13 @@ def __init__(self, amplitude=1, opd=0, mask=None, pixelscale=None, diameter=None
"which are aliases of one another")
amplitude = kwargs['amp']

self.amplitude = np.asarray(amplitude)
self.opd = np.asarray(opd)
# directly set internal attributes rather relying on property setter
# see: https://github.com/andykee/lentil/issues/53
self._amplitude = np.asarray(amplitude)
self._opd = np.asarray(opd)

if mask is None:
mask = np.copy(self.amplitude)
mask = np.copy(self._amplitude)

mask[mask != 0] = 1
self._mask = mask
Expand Down
28 changes: 28 additions & 0 deletions tests/test_plane.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,34 @@ def test_amp_alias_error():
with pytest.raises(TypeError):
lentil.Plane(amplitude=10, amp=10)


class PlaneAttributeOverload(lentil.Plane):
def __init__(self):
super().__init__()

@property
def amplitude(self):
return np.array(1)

@property
def opd(self):
return np.array(2)


def test_plane_overload_propertyes():
p = PlaneAttributeOverload()

assert p.amplitude == 1
assert p.opd == 2
assert p.mask == 1

with pytest.raises(AttributeError):
p.opd = 5

with pytest.raises(AttributeError):
p.amplitude = 5


def test_plane_fit_tilt_inplace():
p = RandomPlane()
p_copy = p.fit_tilt(inplace=False)
Expand Down

0 comments on commit e34e368

Please sign in to comment.