andykee / lentil

Heart-healthy physical optics
https://andykee.github.io/lentil/
Other
14 stars 6 forks source link

Error in propagate when trying to place chips with large tilts #16

Closed andykee closed 3 years ago

andykee commented 3 years ago

The chip placement strategy in v0.5.0 beta 2 is failing when there are large tilts resulting in the chip being placed outside the canvas.

This is easily reproducible via

import numpy as np
import lentil as le

diameter = 1
focal_length = 20
wavelength = 500e-9
du = 5e-6

n = 256
s1 = le.util.circle((n, n), n // 5, shift=(0, -0.3 * n))
s2 = le.util.circle((n, n), n // 5, shift=(0, .3 * n))
amp = s1 + s2

segmask = np.array([s1, s2])

dx = diameter / n

phase = le.zernike.zernike(s1, 2)*5e-6

pupil = le.Pupil(diameter=1, focal_length=20, pixelscale=dx, amplitude=amp, phase=phase, segmask=segmask)
detector = le.Image(pixelscale=du)

le.propagate([pupil, detector], wave=620e-9, npix=64, npix_chip=32, oversample=5, rebin=False, tilt='angle')

The error is

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-12-12f639a9e090> in <module>
     22 detector = le.Image(pixelscale=du)
     23 
---> 24 a = le.propagate([pupil, detector], wave=620e-9, npix=64, npix_chip=32, oversample=5, rebin=False, tilt='angle')
     25 
     26 plt.imshow(a**0.5)

~/Dev/lentil/lentil/prop.py in propagate(planes, wave, weight, npix, npix_chip, oversample, rebin, tilt, interp_phasor, flatten, use_multiprocessing)
    125                     tiles.append(imtile(w.data[d], data_slice, chip_slice))
    126 
--> 127                 tiles = consolidate(tiles)
    128 
    129                 for tile in tiles:

~/Dev/lentil/lentil/prop.py in consolidate(tiles)
    500 def consolidate(tiles):
    501     for m, n in combinations(range(len(tiles)), 2):
--> 502         if overlap(tiles[m].slice, tiles[n].slice):
    503             tiles[m].join(tiles[n])
    504             tiles.pop(n)

~/Dev/lentil/lentil/prop.py in overlap(a, b)
    481 
    482 def overlap(a, b):
--> 483     return a[0].start <= b[0].stop and a[0].stop >= b[0].start and a[1].start <= b[1].stop and a[1].stop >= b[1].start
    484 
    485 

TypeError: 'NoneType' object is not subscriptable