<jupyter_start><jupyter_text>SOG center X=296, Y=253<jupyter_code>p1000_set1_files = [
    "sog_ff_cal_img_2017.1207.083225.fits",
    "sog_ff_cal_img_2017.1207.083329.fits",
    "sog_ff_cal_img_2017.1207.083411.fits"
]
m1000_set1_files = [
    "sog_ff_cal_img_2017.1207.083508.fits",
    "sog_ff_cal_img_2017.1207.083545.fits",
    "sog_ff_cal_img_2017.1207.083625.fits"
]
m1000_set2_files = [
    "sog_ff_cal_img_2017.1207.083737.fits",
    "sog_ff_cal_img_2017.1207.083813.fits",
    "sog_ff_cal_img_2017.1207.083848.fits"
]
p1000_set2_files = [
    "sog_ff_cal_img_2017.1207.083948.fits",
    "sog_ff_cal_img_2017.1207.084024.fits",
    "sog_ff_cal_img_2017.1207.084059.fits"
]
p1000_set1_data = []
for f in p1000_set1_files:
    hdu = fits.open(f)
    data = hdu[1].data
    header = hdu[1].header
    p1000_set1_data.append(data)
p1000_set1_data = np.array(p1000_set1_data)

p1000_set2_data = []
for f in p1000_set2_files:
    hdu = fits.open(f)
    data = hdu[1].data
    header = hdu[1].header
    p1000_set2_data.append(data)
p1000_set2_data = np.array(p1000_set2_data)
    
m1000_set1_data = []
for f in m1000_set1_files:
    hdu = fits.open(f)
    data = hdu[1].data
    header = hdu[1].header
    m1000_set1_data.append(data)
m1000_set1_data = np.array(m1000_set1_data)

m1000_set2_data = []
for f in m1000_set2_files:
    hdu = fits.open(f)
    data = hdu[1].data
    header = hdu[1].header
    m1000_set2_data.append(data)
m1000_set2_data = np.array(m1000_set2_data)<jupyter_output><empty_output><jupyter_text>Note: at a rotator angle of 0 North is to the right and West is down in sky motion.  With cassegrain flip, the pupil north is then to the left and east is up. This means the wavefront needs to be derotated by -90 deg - rotator angle.<jupyter_code>plt.imshow(p1000_set2_data[0][253-128:253+128, 296-128:296+128], origin="lower")
plt.show()
size = 90
inner = 15
y, x = np.ogrid[-size:size, -size:size]
mask_in = x*x + y*y <= inner*inner
mask_out = x*x + y*y >= size*size
p1000_set1_med = np.median(p1000_set1_data, axis=0)[260-size:260+size,289-size:289+size]
p1000_set2_med = np.median(p1000_set2_data, axis=0)[260-size:260+size,289-size:289+size]
m1000_set1_med = np.median(m1000_set1_data, axis=0)[260-size:260+size,289-size:289+size]
m1000_set2_med = np.median(m1000_set2_data, axis=0)[260-size:260+size,289-size:289+size]
for im in [p1000_set1_med, p1000_set2_med, m1000_set1_med, m1000_set2_med]:
    im -= np.median(im[:,:10])
    im[im < 0] = 0.
#    im[mask_in] = 0.
#|    im[mask_out] = 0.
plt.imshow(p1000_set1_med - m1000_set1_med, origin="lower")
plt.show()
p1000_set2_med.shape
set1 = p1000_set1_med - m1000_set1_med
set2 = p1000_set2_med - m1000_set2_med
fits.writeto("p1000_s1.fits", p1000_set1_med, overwrite=True)
fits.writeto("p1000_s2.fits", p1000_set2_med, overwrite=True)
fits.writeto("m1000_s1.fits", m1000_set1_med, overwrite=True)
fits.writeto("m1000_s2.fits", m1000_set2_med, overwrite=True)
fieldXY = [0., 0.]
I1 = Image(readFile("p1000_s2.fits"), fieldXY, Image.INTRA)
I2 = Image(readFile("m1000_s2.fits"), fieldXY, Image.EXTRA)
d = fits.open("p1000_s1.fits")[-1].data
Image(d, fieldXY, Image.INTRA)
fig, ax = plt.subplots()
im = ax.imshow(I1.image, origin='lower', cmap='RdBu')
cbar = fig.colorbar(im)
fig.show()
t = MMT()
pup_mask = t.pupil_mask(size=125)
x, y, cfig = center_pupil(I1.image, pup_mask)
print(int(np.round(x)), int(np.round(y)))
cfig.show()
plt.imshow(pup_mask)
plt.show()
mmt = Instrument('mmto', I1.sizeinPix)
# this is a hack. 0.0 doesn't work, but this will yield annular zernike solution that is very close to circular.
mmt.obscuration = 0.01
algo = Algorithm('exp', mmt, 3)
algo.runIt(mmt, I1, I2, 'onAxis')
print(algo.zer4UpNm)
plots.plotZer(algo.zer4UpNm, 'nm')
zv = ZernikeVector()
zv.from_array(algo.zer4UpNm, modestart=4, normalized=True)
zv.denormalize()
zv
zv.fringe_bar_chart().show()
plots.plotImage(algo.Wconverge, "Final wavefront", show=False)
I1 = Image(readFile("p1000_s2.fits"), fieldXY, Image.INTRA)
I2 = Image(readFile("m1000_s2.fits"), fieldXY, Image.EXTRA)
algo2 = Algorithm('fft', mmt, 3)
algo2.itr0(mmt, I1, I2, 'onAxis')
plots.plotImage(algo2.S, 'wavefront signal')
plt.close('all')
mmt.offset
fig, ax = plt.subplots()
plt.imshow(algo.Wconverge, origin="lower")
plt.show()<jupyter_output><empty_output><jupyter_text>-15" of CC_Y went to +15" of CC_X; +10" of CC_X went to -10" of CC_Y<jupyter_code>ax.set_title?
im = fits.open("/Users/tim/MMT/wfsdat/20180209/sog_ff_cal_img_2018.0209.021854.fits")[-1].data
plt.imshow(im, origin='lower')
plt.show()
t = MMT()
pup_mask = t.pupil_mask(size=120)
x, y, f = center_pupil(im, pup_mask, threshold=0.8)
x, y
f.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14990390775144138, 'fraction_numerical': 0.133888532991672, 'mean_word_length': 5.416438356164384, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '80820', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 2529, 'n_tokens_neox': 2112, 'n_words': 339, 'path': 'notebooks/Curvature Wavefront Sensing.ipynb', 'repo_name': 'tepickering/mmtwfs', 'size': '4683'}