# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python [conda env:astroconda]
#     language: python
#     name: conda-env-astroconda-py
# ---

# + deletable=true editable=true
import os
import sys
import numpy as np
import matplotlib
matplotlib.use('nbagg')
#from matplotlib import style
#style.use('ggplot')
import matplotlib.pyplot as plt

from skimage import feature
from scipy import stats, ndimage
from scipy.misc import factorial as fac

import photutils

from astropy import units as u
from astropy import stats
from astropy import visualization
from astropy import coordinates
from astropy.table import Table, vstack
from astropy.io import ascii, fits
from astropy.modeling import models, fitting, custom_model

# %load_ext autoreload
# %autoreload 2

# + deletable=true editable=true
ACT = 104
NODE = 3222
BRAD = 3228.5

# + deletable=true editable=true
NODE*ACT

# + deletable=true editable=true
# for each node, the influence from each actuator
surf2act = np.fromfile("../mmtwfs/data/Surf2ActTEL_32.bin", dtype=np.float32).reshape(NODE, ACT)
nodecoor = ascii.read("../mmtwfs/data/bcv_node_coordinates.dat", names=["bcv_id", "bcv_x", "bcv_y", "bcv_z"])
actcoor = ascii.read("../mmtwfs/data/actuator_coordinates.dat", names=["act_i", "act_x", "act_y", "act_type"])
for ax in ["bcv_x", "bcv_y"]:
    nodecoor[ax] /= BRAD
nodecoor['bcv_rho'] = np.sqrt(nodecoor['bcv_x']**2 + nodecoor['bcv_y']**2)
nodecoor['bcv_phi'] = np.arctan2(nodecoor['bcv_y'], nodecoor['bcv_x'])

# + deletable=true editable=true
actcoor['act_x'].unit = u.mm

# + deletable=true editable=true
actcoor

# + deletable=true editable=true
im = np.arange(90).reshape(9, 10)

# + deletable=true editable=true
np.indices(im.shape, dtype=float)

# + deletable=true editable=true
slopes = (np.indices(im.shape, dtype=float)/(np.r_[im.shape].reshape(-1, 1, 1))).reshape(2, -1)
slopes = np.vstack([slopes, np.ones(slopes.shape[1])])
slopes

# + deletable=true editable=true
pinv = np.linalg.pinv(slopes)

# + deletable=true editable=true
np.dot(im.reshape(1, -1), pinv).ravel()[:2]

# + deletable=true editable=true
im

# + deletable=true editable=true
import astropy.units as u

# + deletable=true editable=true
u.radian

# + deletable=true editable=true
a.to(u.nm).value

# + deletable=true editable=true
from mmtwfs.telescope import MMT

# + deletable=true editable=true
mmt = MMT()

# + deletable=true editable=true
mmt.diameter

# + deletable=true editable=true
mmt.obscuration

# + deletable=true editable=true
12e6/(128*128)

# + deletable=true editable=true
12e6/(4008*2672)

# + deletable=true editable=true
import poppy
# -

ap = poppy.HexagonAperture?

ap = poppy.HexagonAperture(side=1.0, rotation=30)

ap.display(colorbar=False)
plt.show()

arr = ap.to_fits(npix=27)[0].data.astype(float)

plt.imshow(arr)
plt.show()

from mmtwfs.telescope import MMT
from mmtwfs.zernike import ZernikeVector

t = MMT()

zv = ZernikeVector(Z05=-1000)

zv.plot_map()
plt.show()

print(zv)



StarcoderdataJupyterScriptsDedupFiltered