I am attempting to cycle through a stack of ~60k images, each of size 32x32 and find the center of the Spitzer PSF that is expected to be at the dead center of the image (pixel 15x15).
def fit_least_asymmetry_centering(imageCube, yguess, xguess, asym_rad):
'''
imageCube : nD-array (assume: (60k, 32, 32))
yguess : initial y center guess (assume: 15)
xguess : initial x center guess (assume: 15)
asym_rad : width of asymmetry subframe -- attempt to control corner cases (assume: 5)
'''
y,x = 0,1
nFrames = imageCube.shape[0]
yinds0, xinds0 = indices(imageCube[0].shape)
nAsymParams = 2 # Xc, Yc
centering_LeastAsym = np.zeros((nFrames, nAsymParams))
for kframe in tqdm(range(nFrames), total=nFrames):
center_asym = least_asymmetry.actr(imageCube[kframe], [yguess, xguess], \
asym_rad=asym_rad, asym_size=5, maxcounts=2, method='gaus', \
half_pix=False, resize=False, weights=False)[0]
try:
centering_LeastAsym[kframe] = center_asym[::-1]
except:
print('Least Asymmetry FAILED: Setting centering_LeastAsym[%s] to Initial Guess: [%s,%s]' % (kframe, yguess, xguess))
centering_LeastAsym[kframe] = np.arange([yguess, xguess])
return centering_LeastAsym
from sklearn.externals import joblib
from pylab import *;ion()
import least_asymmetry
xgf_imageCube = joblib.load('xgf_image_cube_array.pickle') # input 60k x 32 x 32 nD-array
yguess = 15
xguess = 15
asym_rad = 5 # tried 8 before too
fit_least_asymmetry_centering(xgf_imageCube, yguess, xguess, asym_rad)
I can process about 1% of the images before this error is triggered. So I assume that the first 600 images worked fine, but then they 601st image breaks.
I tracked the error this far, but cannot figure out why it's happening.
Right now, I bypass the whole problem with a simple "try/except" in the python script.
Traceback (most recent call last):
File "least_asym_test.py", line 68, in <module>
fit_least_asymmetry_centering(xgf_imageCube, 15,15,8)
File "least_asym_test.py", line 51, in fit_least_asymmetry_centering
half_pix=False, resize=False, weights=False)[0]
File "/Users/jonathan/anaconda/lib/python3.6/site-packages/least_asymmetry-0.2-py3.6-macosx-10.7-x86_64.egg/least_asymmetry/asym.py", line 248, in actr
asym = np.array(list(map(make_asym, views, lb_views, w_truth_dup)))
RuntimeError: Arrays must be square