In [1]:
# Import the usual libraries
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
#import matplotlib.patches as mpatches

# Enable inline plotting
%matplotlib inline

#from IPython.display import display, Latex, clear_output

In [2]:
# WebbPSF
import pynrc, webbpsf, os

# Interpolation and extrapolation
from scipy.interpolate import griddata, RegularGridInterpolator
from scipy.ndimage import rotate

# pySIAF stuff for plotting
from pysiaf.siaf import Siaf
from pysiaf.siaf import plot_main_apertures

# Astropy Tables and FITS
from astropy.table import Table, join
from astropy.io import fits
from astropy.io import ascii


[     pynrc:INFO]   jwst_backgrounds is not installed and will not be used for bg estimates.

In [3]:
# Directory and file information
outdir = pynrc.conf.path + 'opd_mod/'

# Read in measured SI Zernike data
data_dir = webbpsf.utils.get_webbpsf_data_path() + '/'
zernike_file = outdir + 'si_zernikes_coron_wfe.csv'

# Read in table data
ztable_full = ascii.read(zernike_file)  
ztable_full.rename_column('\ufeffinstrument', 'instrument')

# Zernike names
keys = np.array(ztable_full.keys())
ind_z = ['Zernike' in k for k in keys]
zkeys = keys[ind_z]

Convert .csv to .fits Table


In [7]:
zfile_fits = zernike_file[0:-4] + '.fits'
ztable_full.write(zfile_fits, format='fits')

In [8]:
tbl_wfe = Table.read(data_dir + 'si_zernikes_isim_cv3.fits')
tbl_coron = Table.read(zernike_file)

In [9]:
tbl_wfe


Out[9]:
Table length=93
instrumentfield_point_nameV2V3PIXEL_XPIXEL_YDETECTORWFE_RMSZernike_1Zernike_2Zernike_3Zernike_4Zernike_5Zernike_6Zernike_7Zernike_8Zernike_9Zernike_10Zernike_11Zernike_12Zernike_13Zernike_14Zernike_15Zernike_16Zernike_17Zernike_18Zernike_19Zernike_20Zernike_21Zernike_22Zernike_23Zernike_24Zernike_25Zernike_26Zernike_27Zernike_28Zernike_29Zernike_30Zernike_31Zernike_32Zernike_33Zernike_34Zernike_35Zernike_36origincomments
arcminarcminpixpixmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm
bytes10bytes10float64float64float64float64bytes11float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64bytes80bytes240
Guider1ASPAG1A4.243813001-12.2044810091711.01497.0FGS1_12.777925434872053e-082.1588991307404575e-093.0297333747465348e-099.990501956410384e-101.199701389475119e-081.2168427794656664e-08-3.5664944969981764e-092.017309406736293e-098.780562597373421e-093.2944179756947098e-091.190142399663702e-085.114966522662449e-09-1.514419166698998e-092.274620160271143e-09-1.3405283964280843e-08-4.875639483147028e-09-3.350583827906116e-101.0401901448432255e-09-7.3657696307605215e-09-3.78191222856489e-09-8.144748776917959e-10-2.790845111344189e-096.9812805050685904e-095.086871718483054e-091.5429133501686715e-09-3.0525679543588715e-10-5.147004134023554e-09-9.965849071981848e-10-2.7616239690617165e-092.8550913288910253e-09-2.60545879599318e-11-4.909398995559523e-09-2.240015377824439e-101.8591046586556508e-09-1.4456435007222208e-09-1.326176656920742e-09-1.1451565237369654e-09ISIM CV2 phase retrieval: Guider1/Guider1_ASPAG1A_Tricontagon_2.1um.fits
Guider1ASPAI74.098480105-12.1069387381588.0055331416.672665FGS1_12.229854171157994e-086.883642115358989e-101.6646576542782795e-092.7826450994759536e-09-9.384732815671355e-101.489500225687883e-09-1.0452444233832811e-087.58594723928376e-093.852862303410115e-095.291105992305623e-097.074938689705434e-096.062021055999103e-092.0987086694934101e-109.407960595457574e-10-8.249300139827171e-09-3.730033191035644e-097.857592583978706e-103.240344128108386e-10-2.3659760059886897e-09-6.310079742884713e-092.484468412364056e-09-2.8665830979847643e-096.460929414761501e-095.605448026696179e-098.265880362185475e-103.88791076239223e-09-3.3444095522799773e-09-7.35954039739629e-10-1.1216835985155513e-091.6127387751382922e-092.1976728387207173e-10-3.859353136107549e-095.401687107749045e-103.2738866480693397e-09-1.8886928528518997e-09-1.8964440197640023e-09-7.721843196282375e-10ISIM CV2 phase retrieval: Guider1/Guider1_ASPAI7_Tricontagon_2.1um.fits
Guider1ASPAI84.271962184-12.1057638151738.0416931413.350532FGS1_13.3625488758495295e-083.827898857269974e-092.7656794047047495e-092.1134496370034802e-102.6840819065774534e-08-9.505027332645373e-097.403295829827566e-102.4595057046339206e-099.485107639698239e-094.2457855658305486e-091.4880450892134903e-082.9767248620592094e-10-1.395179636785255e-091.0614311458246513e-09-6.139687590926382e-09-3.5934563856353293e-09-3.275722087785725e-09-2.2027045716849493e-09-4.7928191372859334e-09-3.740656419389296e-09-6.29967526811773e-102.617668148298865e-104.6738137947626054e-094.044632394544786e-093.1624871751208034e-092.7459691330224797e-09-1.207692037657669e-09-8.01798624881014e-10-5.117924580229427e-093.149105715519253e-098.712749383935974e-10-2.723516591803428e-09-1.3563667172346852e-091.5209937577930304e-09-1.5922834112517824e-09-8.491961453842397e-10-1.042051515221302e-09ISIM CV2 phase retrieval: Guider1/Guider1_ASPAI8_Tricontagon_2.1um.fits
Guider1ASPAI94.273972465-12.2790717231734.9026891559.308714FGS1_14.675765840826089e-085.248563194804689e-093.828828231094795e-092.4457873161797236e-092.8492921151333792e-082.758806829148747e-08-9.903169174205288e-098.357113509164014e-091.2935325458008041e-085.235308239738581e-091.121039438199568e-088.610987467113624e-09-2.5996986439894067e-091.3450157474670504e-09-1.0996373007028833e-08-4.662193033535901e-09-1.4034127816912187e-09-6.584684310585885e-10-3.3753164958653514e-09-3.7027060799570166e-09-2.203218774017835e-09-3.2385355497191876e-092.2259399942455575e-09-4.04777910322568e-095.2925239674464e-096.255881985709884e-091.967965568367643e-09-9.082939133007872e-10-4.840244594596228e-09-1.1758343826372188e-09-1.3758759134495861e-09-6.076060915005483e-092.5176712528584087e-093.3768560267548606e-09-1.9834733833260156e-09-1.8073095343325479e-09-1.015391761582862e-09ISIM CV2 phase retrieval: Guider1/Guider1_ASPAI9_Tricontagon_2.1um.fits
Guider1ISIM163.453836292-11.6736276779999991036.01054.0FGS1_15.4784247121878425e-08-2.685936673113709e-095.909369839188176e-104.407262233380107e-09-2.2559391643189697e-08-4.138287140483739e-081.7237426853281636e-081.2545308825434788e-08-1.9255022402110933e-095.61011164087561e-095.885800452232521e-093.6743497541023797e-09-3.2789122183197672e-092.566330391899097e-09-1.1183715486934464e-08-7.15210898071041e-093.45137913109938e-09-3.239139836691831e-099.879634733270097e-10-2.180256330812984e-096.290270544586738e-09-2.7370270104243446e-095.859715168824361e-096.941164820495241e-094.103414299681456e-098.802370498517744e-102.3603067448630325e-09-6.811650586817545e-11-1.9692198320075104e-102.5337476368998128e-093.8650873781492297e-10-3.2196385806109913e-096.690246090928027e-103.158773765502521e-09-2.1814811003423466e-09-1.9454290419537165e-09-1.3118032781352405e-09ISIM CV2 phase retrieval: Guider1/Guider1_ISIM16_Tricontagon_2.1um.fits
Guider1ISIM232.367101704-10.580044490.0106.0FGS1_15.02888519160343e-081.199334537990575e-092.575986042437245e-093.151221000526861e-101.7995092691779772e-08-9.928724786786409e-09-2.1310326039077427e-085.076729544671387e-113.689796839594598e-093.3058364297184726e-082.3431506993546042e-08-3.4376928010881164e-09-3.908103820168319e-09-9.391253917042065e-10-5.429217790903807e-09-1.1543539202498778e-081.7735744643783364e-09-2.374762010771239e-10-9.140589759714597e-09-2.49075783939652e-096.312081392999041e-09-5.434066529900045e-096.035002221236624e-093.0648167171255933e-09-1.1587891237617437e-098.508680142177869e-106.305990039956293e-103.127586965324948e-10-1.650095332279017e-094.255296476107124e-09-3.5884522361037e-10-1.720046161969208e-09-2.1163190526667957e-092.331778875095306e-09-3.0560928976158645e-09-1.2964177247004918e-09-2.7368442887981096e-09ISIM CV2 phase retrieval: Guider1/Guider1_ISIM23_Tricontagon_2.1um.fits
Guider1ISIM242.407340073-12.722804833100.01948.0FGS1_13.539282160221181e-082.587902278516334e-092.371391155420246e-095.179994152716618e-091.074376277701104e-08-1.9686751953457766e-086.975304034316664e-091.8154057176471033e-086.514813662860788e-09-4.601478924159434e-091.1175761132596301e-096.141562328752984e-09-5.963494059688675e-093.71087908219681e-09-1.0353512765752107e-08-8.708189845991747e-09-1.412555641520387e-09-2.565682683561683e-09-8.455183066220843e-12-5.919349603821407e-09-1.3211891720344796e-09-4.543073540140573e-107.449447118188073e-095.40617042719886e-106.937815690216945e-10-1.230520730015698e-092.269771431413271e-091.1087228073836759e-09-4.859525282127102e-095.458018705986147e-091.7175527544012953e-09-2.102202047215255e-09-4.151690763451941e-093.3461570782615697e-09-5.000900046812382e-10-2.371891192704515e-09-1.7219511414410977e-09ISIM CV2 phase retrieval: Guider1/Guider1_ISIM24_Tricontagon_2.1um.fits
Guider1ISIM254.483951427-10.5684106671960.090.0FGS1_16.053052809796053e-081.3604470981968152e-096.697813649737691e-11-1.8293328994225922e-097.217709656434562e-09-4.954354744293459e-088.314346923441158e-09-8.305194185123037e-09-1.3844090943880923e-092.656433092037007e-081.2272066333945914e-082.7139875813516487e-09-5.7118942719124896e-091.095965721645563e-08-7.025892729217559e-09-2.625652847291644e-096.5478461945013275e-09-2.6653909248193327e-10-2.6482510284287916e-094.4351791332196487e-106.647974515922675e-10-3.959067062685544e-096.1657306114220595e-092.201152464862172e-098.6742051353301e-10-1.5211666620092503e-091.326328655676239e-09-5.575481469039936e-10-3.2261234166221848e-092.7554388177597334e-09-8.779001774507187e-10-2.9714556915624693e-09-1.8086490878163729e-091.1467100114301443e-09-2.560166878605953e-10-5.631483694464562e-108.705089307542085e-11ISIM CV2 phase retrieval: Guider1/Guider1_ISIM25_Tricontagon_2.1um.fits
Guider1ISIM354.539288568-12.7507082271948.01948.0FGS1_19.603825371428518e-089.416184485608289e-095.240529149185559e-104.842238494814335e-106.979067617037384e-086.54895013598552e-081.8158976043356784e-085.099130601102238e-097.329478528832977e-10-1.7258724206388816e-081.7411314243690784e-085.164386801825055e-09-5.136778634789451e-092.8384663280393847e-10-1.2898758309324987e-08-1.5383497013748036e-09-6.312158231060547e-09-4.338701690661315e-09-3.571475363911216e-09-6.28861062689939e-091.4241978937824325e-094.137984229788962e-093.94674845535245e-092.914621246505594e-096.862363635261178e-096.591340077626639e-09-4.283505313002996e-09-1.7010668634585258e-09-8.00449791236889e-095.941658995260802e-093.669448570380674e-09-2.6183296558628384e-10-5.3563809960843974e-096.754896382119852e-10-1.470879955098032e-09-6.579365858787079e-10-1.2875835270879917e-09ISIM CV2 phase retrieval: Guider1/Guider1_ISIM35_Tricontagon_2.1um.fits
..........................................................................................................................................
NIRISSISIM19-3.83983712-12.5513424091965.01852.0TFI_15.655877133469672e-086.420892401302127e-092.1376584197502417e-09-4.287876112922073e-094.316418993368327e-08-3.4320258407283996e-08-1.1453049630401633e-08-4.20013496851147e-091.9902805457514573e-09-4.1527282563309935e-10-1.1071562676111087e-09-2.9346313956991334e-093.3715083401226706e-091.1959169686515644e-096.152017580098388e-09-5.51243850067098e-093.966464349101584e-09-6.476848564615388e-092.15128619499893e-09-2.9237266083971913e-091.663953378204197e-091.4643234727408544e-09-6.39551155950405e-094.076138216692083e-095.246030275382157e-09-1.313982336958069e-09-7.595691934057177e-09-6.799416246937251e-10-4.0154273767188e-099.522823285008201e-10-1.370413092770009e-092.1464853149593735e-094.930745846536349e-10-1.2405696605772113e-09-4.63079275434711e-101.7898042056003114e-09-1.0842053775741798e-09ISIM CV2 phase retrieval: NIRISS/NIRISS_ISIM19_Tricontagon_1.55um.fits
NIRISSISIM37-5.870361862-12.645758697100.01948.0TFI_14.237514723329288e-08-9.841174565275603e-101.4993920952101757e-09-1.3788844863058338e-09-2.26336708025073e-082.6592397582976936e-08-1.2807149156871618e-08-3.759231911412674e-095.325590753391036e-092.0289803092880507e-09-1.2998661861443643e-086.782519038557453e-096.440625370973812e-09-9.169757781026999e-09-5.705375147927161e-09-1.7079750109674463e-096.208443443890943e-10-3.514776898779435e-097.999317383595787e-09-2.8175463349890026e-091.188010257279995e-092.1044698035095252e-10-4.218956524778202e-094.2699815915398286e-09-3.2804923673380262e-09-1.5298372807731732e-093.2988079851192386e-09-3.242860290960549e-101.9158279827025993e-096.573552401124291e-101.8134752427067557e-093.888000767533062e-091.050082851590193e-09-7.027687304627675e-10-7.43507304456613e-101.0265690472625901e-09-7.050099990069609e-10ISIM CV2 phase retrieval: NIRISS/NIRISS_ISIM37_Tricontagon_1.55um.fits
NIRISSMIMF3-5.614537437-12.03845327330.01392.0TFI_12.41239382010512e-08-2.911684037487473e-091.319726325220822e-092.4870514127968317e-10-7.646997762018652e-094.144834639482808e-091.5991757664704745e-081.4867818955201907e-094.794508413366634e-10-1.1005783302388801e-08-4.0100437062891194e-09-7.14471763034039e-093.72947566074441e-092.7818047470887104e-09-2.8858470030928205e-10-7.065960200469566e-093.523057840362365e-09-4.9571494703074435e-09-3.854539090424639e-092.1147303102850164e-092.7385973222074234e-09-1.9112717819312238e-09-1.8816411273709276e-09-8.934438141994443e-104.3469268357061375e-11-7.106738120870325e-11-4.6177233963756344e-09-3.002217986347012e-102.426561351419661e-09-6.291977971282726e-102.476204023874861e-09-2.1359436921948663e-095.5231457977918085e-095.470622754173292e-10-1.20390588083652e-093.1811840128067757e-10-1.4297912850447785e-09ISIM CV2 phase retrieval: NIRISS/NIRISS_MIMF3_Tricontagon_1.55um.fits
NIRSpecISIM15.345660845-7.9021665551414.5990.5NIRSPEC_15.353854204543877e-086.5234748654413965e-09-4.708916200755137e-097.924480377712341e-091.8753831087494112e-08-8.325253871594866e-09-7.762492536000518e-093.32981166976287e-08-1.7018755673730952e-081.1740205483496392e-081.9548070269040087e-081.3898796024746404e-081.004851937965233e-08-2.848580694716945e-096.208635803776097e-091.1534086052566619e-09-2.706775900628211e-093.6279705237966e-10-5.837354147224223e-09-6.1221207576005025e-097.422867273670174e-10-3.912878096620447e-09-2.577891144105808e-099.631807087521811e-10-7.974481221933553e-09-1.7964791685245462e-099.862297421895885e-109.888223501282984e-107.141174659731995e-10-5.591500357855527e-095.140234515633962e-093.241224150291534e-099.452893656552068e-10-9.85796123611102e-107.401270948868599e-103.112668119631348e-10-1.5522872064975481e-09ISIM CV2 phase retrieval: NIRSpec/NIRSpec_ISIM1_Tricontagon_1.55um.fits
NIRSpecISIM24.070126822-7.1625180041134.4185.0NIRSPEC_17.845222376725125e-081.2490815161786666e-08-3.92695031728896e-093.802089380898017e-095.662836948771985e-08-6.564401691322186e-09-4.3971234611521795e-086.778605565678001e-09-1.3329193695761767e-082.6593050409083517e-092.3538302968281243e-082.1276984987542492e-089.25813010557444e-094.2611498201191375e-09-1.2330736982570526e-08-4.723223050256397e-092.241067266661772e-091.1392314671078321e-084.298285678451313e-09-9.274227183971445e-09-1.2700210562519966e-09-8.517311173164246e-104.916934228585217e-09-2.2730373524654508e-10-8.308119822372872e-10-6.953176546359097e-103.4138597607081425e-094.800333436068576e-094.531465947650807e-09-3.7273896884868e-09-1.7666110349270943e-095.923844276310431e-09-2.910632003856047e-09-1.238444656673858e-092.520591957702714e-101.1938659551650896e-10-1.202165256386946e-09ISIM CV2 phase retrieval: NIRSpec/NIRSpec_ISIM2_Tricontagon_1.55um.fits
NIRSpecISIM36.236961758-9.4317313081224.51967.2NIRSPEC_19.49424001741343e-081.3568590851396013e-08-1.1861080871213467e-082.939894367974372e-095.885988608992079e-08-3.446209169111191e-08-2.014770266872351e-086.351016310818877e-09-3.4213646892164475e-084.2289310000167324e-083.5396443122138405e-092.850264056477834e-081.26094895173696e-086.8256138699664024e-09-2.0440104824982736e-091.574733760341282e-09-8.109892090809648e-093.6985322954794707e-09-1.603166255405919e-08-1.7379141288747535e-08-7.348432742785694e-10-5.3502328517664e-092.7877719198977287e-091.5654689412327363e-09-7.126175710212344e-093.5915114930815947e-101.8397858798733036e-095.098791763578417e-093.1548194354846047e-09-4.417222757161778e-092.465369698403117e-09-2.532669612036933e-093.697928682281423e-09-2.6104550959559204e-09-7.717420833228847e-10-2.7054214730271862e-09-1.88637515675387e-09ISIM CV2 phase retrieval: NIRSpec/NIRSpec_ISIM3_Tricontagon_1.55um.fits
NIRSpecISIM48.317734217-7.2262741671276.1236.2NIRSPEC_21.3163101370241667e-071.3998777809952922e-08-1.126826747331802e-08-1.777451766533363e-089.282920061290047e-08-2.5116559713595312e-08-3.9538742389099604e-08-6.220703201161492e-08-3.882108934098951e-08-4.063524620825602e-08-5.9051736263408045e-095.89094747218698e-096.427016845690066e-09-3.2962454749957386e-09-7.0711289104962915e-09-1.1593665206979557e-086.378437773994672e-101.817960700885583e-091.6495728911036682e-091.578375354800468e-08-7.580074620472033e-09-1.3992869840806265e-09-7.922502298682294e-094.893002452161954e-09-4.641825542834868e-094.281712059580891e-098.944917814516052e-108.35514094836725e-092.0948330382060746e-097.177754503925563e-094.162747707403583e-091.6020831295073813e-091.87838915344695e-09-2.3153481236453446e-09-3.3853936470761316e-09-4.292084539460767e-093.554630947401746e-09ISIM CV2 phase retrieval: NIRSpec/NIRSpec_ISIM4_Tricontagon_1.55um.fits
NIRSpecISIM56.469618241-5.1023603521247.21838.9NIRSPEC_21.3608065167475605e-072.0720938674515756e-08-1.5478419046847363e-08-1.1760490999534465e-091.0331925510503456e-07-1.3885952010454422e-08-5.219716878191631e-081.435147359506178e-09-5.585736874618632e-087.761704751966607e-093.1186200704924803e-082.859805587789058e-082.9299879848469534e-086.451572632385206e-091.0409777568164689e-08-4.599503311841716e-099.015031379899377e-09-1.8451663089540634e-084.376863022011603e-091.5317122598125338e-09-4.036675851210016e-09-4.428834415649185e-09-5.471278222523101e-095.7453898187892485e-092.39424454397404e-111.5736174414607066e-096.464745160481136e-108.664643856001048e-094.2953714533888885e-092.504486164701739e-092.903505086130805e-091.5413561639962702e-093.383507971962388e-10-2.005279391599516e-09-9.76105141648335e-10-2.842529679065007e-09-3.010529002215893e-10ISIM CV2 phase retrieval: NIRSpec/NIRSpec_ISIM5_Tricontagon_1.55um.fits
NIRSpecQ1C6.788646557-7.31408554799999951970.5765.4NIRSPEC_28.640711569159014e-084.5490486096851125e-09-6.30016712362856e-09-9.678391645226977e-092.357090458397466e-09-3.0680862407757734e-08-4.7724077322555956e-08-3.7687582475816495e-08-2.370655276123827e-08-2.8300357760470504e-081.4678593923928897e-081.683133538355599e-081.7312722428715808e-08-3.23435288699256e-09-4.268359656912307e-09-1.176459992848537e-093.5771606781144255e-09-3.267935984832522e-09-5.2364441808494485e-091.7230178597656905e-08-4.493018317834863e-09-1.6187608984877132e-10-3.579257332194921e-094.074468184256875e-09-1.2874768009613126e-088.209618697115366e-101.1180952781849465e-095.188836699158453e-103.3725474126123534e-102.9949175039093456e-092.7022240360577552e-091.0645406573445432e-099.525688846818488e-10-1.6676016775202976e-10-2.1045251070816823e-09-2.1744281142165953e-091.800117209425415e-09ISIM CV2 phase retrieval: NIRSpec/NIRSpec_Q1C_Tricontagon_1.55um.fits
NIRSpecQ4C5.759170543-7.0455970451926.2781.1NIRSPEC_15.815610812078224e-085.2489711267982e-09-5.732827160867328e-096.6921114017498125e-091.0143836191738769e-08-1.0332284939231303e-08-3.143142862760935e-083.1693383584657654e-08-2.326300194071307e-08-8.499074265535e-096.123717272548213e-091.6929931422693202e-081.0580190567317722e-08-5.605308760567634e-09-4.9961927472728715e-09-2.027659585371193e-094.7897155458415675e-09-9.198323657354543e-10-5.375351886632042e-092.863199719698988e-091.9616725491585512e-09-3.971675746142428e-091.2161794289401725e-092.6227184436511557e-099.02305346950322e-101.3070525636876286e-102.141819821514465e-091.098897067505402e-097.142739727179683e-10-3.926961928315083e-091.8963859666219626e-092.8885707550466e-091.2962873698055796e-09-1.3275617609702052e-095.338717621611024e-10-1.698375713143438e-10-1.7423763016051105e-09ISIM CV2 phase retrieval: NIRSpec/NIRSpec_Q4C_Tricontagon_1.55um.fits

In [10]:
tbl_coron


Out[10]:
Table masked=True length=72
instrumentfield_point_nameV2V3PIXEL_XPIXEL_YDETECTORWFE_RMSZernike_1Zernike_2Zernike_3Zernike_4Zernike_5Zernike_6Zernike_7Zernike_8Zernike_9Zernike_10Zernike_11Zernike_12Zernike_13Zernike_14Zernike_15Zernike_16Zernike_17Zernike_18Zernike_19Zernike_20Zernike_21Zernike_22Zernike_23Zernike_24Zernike_25Zernike_26Zernike_27Zernike_28Zernike_29Zernike_30Zernike_31Zernike_32Zernike_33Zernike_34Zernike_35Zernike_36origincomments
str9str8float64float64int64int64str11float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64float64str11str54
NIRCamLWAISIM260.869-8.777535-231NIRCAMALW2.51e-07-1.4e-08-8.83e-101.52e-092.22e-07-1.01e-08-4.91e-081.22e-07-1.22e-09-1.22e-093.87e-101.39e-09-1.13e-09-1.58e-093.17e-114.41e-104.82e-10-6.2e-095.98e-10-2.73e-104.53e-111.42e-11-9.53e-09-3.96e-10-3.75e-10-7.74e-11-2.78e-125.17e-13-1.65e-121.02e-10-1.08e-103.65e-11-7.62e-119.69e-14-1.62e-13-6.14e-13-1.94e-13Zemax Model--
NIRCamLWAISIM270.453-8.389140127NIRCAMALW2.17e-07-1.15e-08-4.09e-102.34e-091.76e-07-1.86e-08-5.9e-081.2e-07-4.35e-09-1.13e-09-5.56e-111.82e-098.81e-10-2.37e-09-2.83e-101.11e-10-1.01e-09-6.04e-094.78e-102.81e-10-1.19e-112.8e-11-9.62e-09-6e-10-2.97e-11-1.59e-115.38e-119.37e-13-2.58e-136.13e-11-2.61e-10-3.37e-11-5.31e-11-1.62e-133.88e-13-4.85e-13-2.91e-13Zemax Model--
NIRCamLWAISIM281.598-9.2191218-639NIRCAMALW2.96e-07-1.62e-08-2.57e-092.73e-093.21e-07-2.31e-08-3.68e-081.27e-074.18e-09-3.07e-09-3.72e-111.92e-09-4.84e-092.29e-099.48e-10-7.44e-112.74e-09-5.21e-09-1.19e-10-1.13e-09-1.9e-11-9.53e-12-9.38e-091.24e-10-7.65e-101.97e-11-5.51e-111.07e-12-5.87e-111.87e-109.01e-115.35e-111.14e-115.34e-111.23e-12-2.07e-11-9.69e-14Zemax Model--
NIRCamLWAISIM292.404-8.0771984421NIRCAMALW1.43e-07-1.22e-081.15e-09-1.04e-097.48e-081.74e-08-2.13e-081.18e-075.16e-09-1.71e-093.69e-104.08e-091.01e-111.48e-09-6.33e-114.92e-111.11e-09-8.33e-10-7.64e-112.09e-108.56e-12-7.43e-13-9.33e-094.47e-101.64e-10-1.3e-111.69e-11-3.55e-136.46e-141.27e-102.99e-10-2.76e-115.94e-121.94e-13-4.2e-13-1.94e-132.26e-13Zemax Model--
NIRCamLWAISIM301.277-7.2639101194NIRCAMALW1.35e-07-1.22e-087.09e-114.22e-11-6.53e-08-3.64e-093.8e-081.14e-07-8.59e-10-9.08e-101.48e-105.11e-09-8.49e-103.01e-103.39e-125.49e-13-2.02e-09-2.88e-103.45e-119.01e-12-2.91e-13-1.94e-13-9.56e-093.33e-121.9e-109.69e-14-1.94e-130.0-1.29e-13-1.1e-10-9e-112.45e-121.87e-12-3.23e-140.03.23e-140.0Zemax Model--
NIRCamLWAISIM400.878-7.68533796NIRCAMALW1.2e-07-1.4e-086.78e-101.38e-09-8.57e-10-2.13e-08-2.17e-091.17e-07-2.07e-09-1.45e-091.19e-104.03e-09-2.39e-10-1.03e-10-8.14e-12-1.16e-12-1.44e-09-2.74e-093.12e-116.11e-11-6.46e-13-5.49e-13-9.68e-09-1.57e-101.82e-102.97e-121.65e-120.03.23e-14-3.2e-12-2.18e-10-4.78e-122.65e-121.29e-13-3.23e-14-1.62e-13-1.29e-13Zemax Model--
NIRCamLWAISIM412.0-8.7921597-246NIRCAMALW2.32e-07-1.65e-08-1.16e-091.31e-092.01e-07-1.6e-08-3.59e-081.22e-074.72e-09-1.36e-09-3.85e-112.47e-09-2.03e-092.86e-091.29e-10-3.13e-102.27e-09-3.8e-09-4.81e-10-3.4e-10-3.38e-112.84e-12-9.39e-094.15e-10-4.13e-105.6e-11-1.22e-11-1.94e-13-1e-121.89e-101.74e-103.74e-115.4e-11-4.2e-135.17e-13-5.49e-139.69e-14Zemax Model--
NIRCamLWAISIM421.985-7.6781588800NIRCAMALW1.21e-07-1.3e-08-6.94e-10-1.74e-09-2.01e-082.16e-081.05e-081.16e-072.69e-09-1.36e-09-1.39e-104.76e-09-4.31e-104.09e-10-9.37e-136.14e-12-5.92e-10-2.97e-101.51e-114.14e-113.55e-13-8.08e-13-9.44e-091.78e-102.05e-10-3.97e-121.1e-120.09.69e-143.45e-111.71e-10-5.3e-12-3.49e-121.29e-136.46e-14-6.46e-141.62e-13Zemax Model--
NIRCamLWAMIMF51.158-8.604805-70NIRCAMALW1.93e-07-1.74e-08-1.22e-092.52e-091.5e-07-1.16e-08-3.66e-081.2e-074.56e-10-1.16e-09-5.78e-111.92e-09-1.07e-09-2.25e-101.29e-101.79e-106.45e-10-5.29e-092.55e-10-2.95e-101.51e-11-6.36e-12-9.51e-09-1.83e-10-3.45e-10-2.71e-11-1.76e-113.55e-13-1.36e-121.59e-10-6.14e-113.45e-11-2.95e-111.62e-139.69e-14-5.17e-13-9.69e-14Zemax Model--
NIRCamLWAMIMF60.444-9.225144-643NIRCAMALW3.46e-07-8.51e-09-2.89e-091.58e-094.03e-072.53e-08-7.38e-081.31e-07-8.37e-09-1.3e-094.28e-092e-09-2.65e-09-6.35e-09-7.29e-111.25e-09-1.08e-10-7.25e-091.24e-09-4.94e-101.23e-103.4e-10-9.68e-09-5.02e-10-5.65e-10-2.39e-102.4e-10-4.52e-11-6.46e-113.26e-11-6.75e-11-9.22e-11-1.97e-105.47e-11-3.68e-11-1.1e-111.65e-11Zemax Model--
..........................................................................................................................................
NIRCamSWBMIMF5_B-1.158-8.60442955NIRCAMBSW_42.52e-071.49e-092.81e-093.93e-102.31e-07-1.8e-08-4.27e-081.15e-073.69e-09-1.34e-091.53e-10-6.66e-09-1.13e-105.59e-102.2e-103.47e-104.57e-10-1.5e-092.76e-10-2.95e-101.15e-10-3.92e-11-1.66e-09-7.45e-11-1.32e-10-1.24e-10-7.98e-112.97e-13-2.2e-12-6.67e-111.59e-119.04e-11-8.36e-112.12e-13-1.7e-13-5.72e-13-1.27e-13Zemax Model--
NIRCamSWBMIMF6_B-0.444-9.2251769-1113NIRCAMBSW_42.94e-074.03e-092.14e-103.26e-093.67e-07-3.68e-08-9.33e-081.1e-077.15e-092.17e-10-1.63e-09-1.56e-084.1e-096.4e-092.08e-09-3.69e-094.55e-09-8.6e-09-4.3e-097.68e-119.98e-101.78e-09-4.54e-092.53e-091.48e-09-1.16e-097.11e-10-1.26e-10-7.33e-11-1e-095.94e-10-4.76e-11-5.66e-106.51e-11-2.98e-11-9.75e-124.77e-11Zemax Model--
NIRCamSWBMIMF7_B-2.427-9.211265-1128NIRCAMBSW_22.98e-073.85e-094.1e-093.05e-093.24e-076.62e-09-6.89e-081.15e-072.09e-093.3e-10-2.98e-09-1.02e-081.71e-09-5.69e-103.82e-101.6e-09-1.89e-09-5.09e-092.19e-094.62e-10-8.86e-108.83e-10-3.52e-09-1.49e-091.16e-099.17e-102.69e-103.6e-114.69e-11-8.24e-10-4.01e-108.82e-114.53e-10-1.23e-11-9.12e-122.69e-11-2.14e-11Zemax Model--
NIRCamSWBMIMF8_B-2.397-7.2618141620NIRCAMBSW_11.61e-074.42e-094.26e-09-5.88e-109.21e-084.05e-083.79e-081.22e-07-1.49e-09-1.72e-09-3.13e-10-4.26e-09-9.61e-102.84e-108.2e-11-2.27e-10-1.24e-091.29e-092.38e-10-2.62e-10-4.85e-124.32e-11-1.53e-09-1.21e-102.2e-105.94e-11-2.25e-11-7.63e-132.65e-12-1.36e-114.99e-115.13e-11-3.69e-11-7.84e-131.8e-121.48e-133.39e-13Zemax Model--
NIRCamSWBMIMF9_B-0.521-7.3213861730NIRCAMBSW_31.78e-073.4e-09-6.53e-109.29e-111.3e-07-2.73e-081.41e-081.23e-073.25e-09-1.78e-097.2e-11-3.7e-09-1.1e-097.57e-101.16e-101.04e-109.27e-106.11e-10-2.44e-10-1.39e-101.62e-111.75e-11-1.63e-098.27e-112.46e-10-2.53e-11-3.01e-111.48e-131.97e-12-2.18e-11-9.25e-112.33e-113.73e-11-2.97e-13-1.19e-126.36e-14-3.39e-13Zemax Model--
NIRCamSWBZSWB_B-0.787-6.741882600NIRCAMBSW_31.58e-071.28e-091.88e-091.47e-097.27e-08-2.84e-086.27e-081.23e-077.21e-10-1.09e-091.18e-09-3.22e-09-9.14e-106.7e-10-1.96e-10-1.18e-102.85e-101.67e-092.6e-10-1.63e-10-8.52e-12-2.96e-11-1.56e-092.34e-10-2.64e-112.06e-114.55e-11-8.27e-13-1.78e-12-5.55e-11-4.88e-112.25e-11-5.01e-11-8.9e-131.21e-123.39e-13-2.76e-13Zemax ModelThese V2/V3 coordinates are not centerd on the B masks
NIRCamSWBZLWB_B-1.127-6.7451545598NIRCAMBSW_31.56e-071.28e-091.88e-091.47e-096.75e-08-5.72e-096.66e-081.24e-077.2e-10-5.87e-105.27e-10-3.24e-09-7.17e-105.18e-103.03e-11-1.39e-102.33e-121.98e-091.82e-107.44e-111.21e-11-2.76e-12-1.61e-091.39e-10-1.37e-102.42e-11-3.6e-12-8.48e-13-6.36e-13-8.97e-11-3.69e-11-1.72e-11-2.84e-112.12e-136.36e-132.12e-130.0Zemax ModelThese V2/V3 coordinates are not centerd on the B masks
NIRCamSWBZ430R_B-1.454-6.753-12609NIRCAMBSW_11.55e-071.28e-091.88e-091.47e-096.18e-081.19e-086.96e-081.24e-072.51e-10-4.37e-107.42e-13-3.36e-09-6.23e-106.5e-101.17e-101.71e-11-4.32e-102.14e-09-2.14e-111.56e-10-3.14e-129.35e-12-1.62e-09-1.68e-11-1.74e-10-5.41e-12-1.97e-112.54e-13-4.24e-13-9.6e-119.54e-13-2.89e-115.7e-125.94e-13-2.33e-133.39e-132.12e-14Zemax ModelThese V2/V3 coordinates are not centerd on the B masks
NIRCamSWBZ335R_B-1.792-6.759648627NIRCAMBSW_11.57e-071.28e-091.88e-091.47e-095.68e-082.86e-087.29e-081.23e-07-2.68e-10-4.81e-10-5.63e-10-3.64e-09-7.31e-107.56e-10-1.14e-111.57e-10-8.19e-102.11e-09-2.13e-103.59e-11-1.47e-11-1.19e-11-1.57e-09-1.59e-10-1.18e-10-3.34e-117.4e-121.21e-12-1.23e-12-7.3e-113.02e-11-1.1e-114.05e-11-8.48e-14-1.06e-123.39e-131.48e-13Zemax ModelThese V2/V3 coordinates are not centerd on the B masks
NIRCamSWBZ210R_B-2.121-6.7541292626NIRCAMBSW_11.61e-071.28e-091.88e-091.47e-095.21e-084.85e-087.58e-081.23e-07-3.59e-10-9.49e-10-1.29e-09-3.92e-09-8.63e-105.53e-10-2.6e-109.99e-11-1.01e-091.96e-09-2.61e-10-2.08e-102.16e-11-4.73e-11-1.51e-09-2.12e-10-9.05e-12-2.28e-117.19e-114.88e-13-2.63e-12-2.05e-111.76e-113.67e-116.42e-11-1.67e-12-1.34e-123.6e-133.18e-13Zemax ModelThese V2/V3 coordinates are not centerd on the B masks

V2/V3 Limits


In [4]:
def get_v2v3_limits():
    """
    V2/V3 Limits for a given module stored within an dictionary
    """
    
    names = ['SW', 'LW', 'SWA', 'LWA', 'SWB', 'LWB']
    apnames = ['NRCALL_FULL', 'NRCALL_FULL', 
               ['NRCA1_FULL', 'NRCA2_FULL', 'NRCA3_FULL', 'NRCA4_FULL'], 'NRCA5_FULL', 
               ['NRCB1_FULL', 'NRCB2_FULL', 'NRCB3_FULL', 'NRCB4_FULL'], 'NRCB5_FULL']
    
    siaf = Siaf('NIRCam')
    siaf.generate_toc()

    v2v3_limits = {}
    for i, name in enumerate(names):
       
        # Do all four apertures for each SWA & SWB
        if (name=='SWA') or (name=='SWB'):
            v2_vals = []
            v3_vals = []
            for apsw_name in apnames[i]:
                ap = siaf[apsw_name]
                v2_ref, v3_ref = ap.closed_polygon_points('tel', rederive=False)
                v2_vals.append(v2_ref)
                v3_vals.append(v3_ref)
            v2_ref = np.array(v2_vals).flatten()
            v3_ref = np.array(v3_vals).flatten()
        else:
            ap = siaf[apnames[i]]
            v2_ref, v3_ref = ap.closed_polygon_points('tel', rederive=False)
            
        # Add a 10" border margin
        v2_min = int(v2_ref.min()-10)
        v2_max = int(v2_ref.max()+10)
        v3_min = int(v3_ref.min()-10) + 50  # Offset by 50"
        v3_max = int(v3_ref.max()+10) + 50  # Offset by 50"
            
        v2v3_limits[name] = {'V2': [v2_min, v2_max],
                             'V3': [v3_min, v3_max]}
        
    return v2v3_limits

In [5]:
# V2/V3 Limits stored in a dictionary
v2v3_limits = get_v2v3_limits()

Interpolate within bounds of CV3 measurements


In [6]:
def gen_cv3_zgrid(ztable_full, v2v3_limits, mod, zkey):
    """Gridded data from CV3 only"""
    
    ind_nrc = ['NIRCam'+mod in row['instrument'] for row in ztable_full]
    ind_nrc = np.where(ind_nrc)

    # Grab V2/V3 coordinates
    # In units of arcmin
    v2 = ztable_full[ind_nrc]['V2']
    v3 = ztable_full[ind_nrc]['V3']

    # Create finer mesh grid
    v2_lims = np.array(v2v3_limits[mod]['V2']) / 60.
    v3_lims = np.array(v2v3_limits[mod]['V3']) / 60.
    dstep = 1. / 60. # 1" steps
    xgrid = np.arange(v2_lims[0], v2_lims[1]+dstep, dstep)
    ygrid = np.arange(v3_lims[0], v3_lims[1]+dstep, dstep)
    
    X, Y = np.meshgrid(xgrid,ygrid)
    
    ztable = ztable_full[ind_nrc]
    zvals = ztable[zkey]

    # There will be some NaNs along the outer borders
    zgrid = griddata((v2, v3), zvals, (X, Y), method='cubic')
    
    return xgrid, ygrid, zgrid

In [7]:
mod = 'LWA'
xgrid, ygrid, zgrid = gen_cv3_zgrid(ztable_full, v2v3_limits, mod, 'Zernike_4')

In [8]:
fig, ax = plt.subplots(1,1, figsize=(8,5))

zmin, zmax = np.nanmin(zgrid), np.nanmax(zgrid)
extent = np.array([xgrid.min(),xgrid.max(),ygrid.min(),ygrid.max()]) * 60
ax.imshow(zgrid, extent=extent, vmin=zmin, vmax=zmax)

siaf = Siaf('NIRCam')
ap = siaf['NRCA5_FULL_MASK430R']
ap.plot(ax=ax, fill=False, color='C1')

fig.tight_layout()


Extrapolate using RegularGridInterpolator


In [9]:
# To extrapolate outside the measured field points, we proceed 
# in two steps.  This first creates a fine-meshed cubic fit 
# over the known field points, fixes any NaN's using 
# RegularGridInterpolator, then again uses  RegularGridInterpolator 
# on the fixed data to extrapolate the requested field point.

# In principle, the first call of RegularGridInterpolator can be 
# used to extrapolate the requested field point to eliminate 
# the intermediate step, but this method enables use of all the 
# real data rather than the trimmed data set.

def _fix_zgrid_NaNs(xgrid, ygrid, zgrid_input, rot_ang=0):
    """Fix NaN's in Zernike Grid
    
    We trim NaN's within `zgrid`, then generate an extrapolation function
    using `RegularGridInterpolator`. A rotation angle can also be specified
    to maximize the number of remaining data points due to irregular
    polygons of the real `zgrid` data.
    
    Returns `zgrid` with the NaN's fixed using the extrapolation function.
    
    Parameter
    =========
    xgrid : ndarray
        1D V2 regular grid information
    ygrid : ndarray
        1D V3 regular grid information
    zgrid : ndarray
        2D Zernike grid
    rot_ang : float
        Option to rotate grid data for more optimal
        trimming of NaN's.
    """
            
    # Prevent this function from replacing original data
    zgrid = zgrid_input.copy()
        
    # Rotate zgrid
    if rot_ang != 0:
        zgrid = rotate(zgrid, rot_ang, reshape=False, order=1, cval=np.nan)
        
    # There will be some NaN's along the border that need to be replaced
    ind_nan = np.isnan(zgrid)
    # Remove rows/cols with NaN's
    xgrid2, ygrid2, zgrid2 = _trim_nan_image(xgrid, ygrid, zgrid)
    
    # Create regular grid interpolator function for extrapolation of NaN's
    func = RegularGridInterpolator((ygrid2,xgrid2), zgrid2, method='linear',
                                   bounds_error=False, fill_value=None)

    # Replace NaNs
    X, Y = np.meshgrid(xgrid,ygrid)
    pts = np.array([Y[ind_nan], X[ind_nan]]).transpose()
    zgrid[ind_nan] = func(pts)

    # De-rotate clipped zgrid image and redo RegularGridInterpolator
    if rot_ang != 0:
        # De-rotate
        zgrid = rotate(zgrid, -rot_ang, reshape=False, order=1, cval=np.nan)
        # There will be some NaNs along the border that need to be replaced
        ind_nan = np.isnan(zgrid)
        # Remove rows/cols 1 by 1 until no NaNs
        xgrid2, ygrid2, zgrid2 = _trim_nan_image(xgrid, ygrid, zgrid)

        # Create regular grid interpolator function for extrapolation of NaN's
        func = RegularGridInterpolator((ygrid2,xgrid2), zgrid2, method='linear',
                                       bounds_error=False, fill_value=None)

        # Replace NaNs
        pts = np.array([Y[ind_nan], X[ind_nan]]).transpose()
        zgrid[ind_nan] = func(pts)
        
    return zgrid

def _trim_nan_image(xgrid, ygrid, zgrid):
    """NaN Trimming of Image
    
    Remove rows/cols with NaN's while trying to preserve
    the maximum footprint of real data.
    """
    
    xgrid2, ygrid2, zgrid2 = xgrid, ygrid, zgrid
    
    # Create a mask of NaN'ed values
    nan_mask = np.isnan(zgrid2)
    nrows, ncols = nan_mask.shape
    # Determine number of NaN's along each row and col
    num_nans_cols = nan_mask.sum(axis=0)
    num_nans_rows = nan_mask.sum(axis=1)
    
    # First, crop all rows/cols that are only NaN's
    xind_good = np.where(num_nans_cols < nrows)[0]
    yind_good = np.where(num_nans_rows < ncols)[0]
    # get border limits
    x1, x2 = (xind_good.min(), xind_good.max()+1)
    y1, y2 = (yind_good.min(), yind_good.max()+1)
    # Trim of NaN borders
    xgrid2 = xgrid2[x1:x2]
    ygrid2 = ygrid2[y1:y2]
    zgrid2 = zgrid2[y1:y2,x1:x2]
    
    # Find a optimal rectangule subsection free of NaN's
    # Iterative cropping
    ndiff = 5
    while np.isnan(zgrid2.sum()):
        # Make sure ndiff is not negative
        if ndiff<0:
            break

        npix = zgrid2.size

        # Create a mask of NaN'ed values
        nan_mask = np.isnan(zgrid2)
        nrows, ncols = nan_mask.shape
        # Determine number of NaN's along each row and col
        num_nans_cols = nan_mask.sum(axis=0)
        num_nans_rows = nan_mask.sum(axis=1)

        # Look for any appreciable diff row-to-row/col-to-col
        col_diff = num_nans_cols - np.roll(num_nans_cols,-1) 
        row_diff = num_nans_rows - np.roll(num_nans_rows,-1)
        # For edge wrapping, just use last minus previous
        col_diff[-1] = col_diff[-2]
        row_diff[-1] = row_diff[-2]
        
        #print(npix, zgrid2.shape, num_nans_cols, num_nans_rows)

        # Keep rows/cols composed mostly of real data 
        # and where number of NaN's don't change dramatically
        xind_good = np.where( ( np.abs(col_diff) <= ndiff  ) & 
                              ( num_nans_cols < 0.5*nrows ) )[0]
        yind_good = np.where( ( np.abs(row_diff) <= ndiff  ) & 
                              ( num_nans_rows < 0.5*ncols ) )[0]
        # get border limits
        x1, x2 = (xind_good.min(), xind_good.max()+1)
        y1, y2 = (yind_good.min(), yind_good.max()+1)
    
        # Trim of NaN borders
        xgrid2 = xgrid2[x1:x2]
        ygrid2 = ygrid2[y1:y2]
        zgrid2 = zgrid2[y1:y2,x1:x2]
        
        # Check for convergence
        # If we've converged, reduce 
        if npix==zgrid2.size:
            ndiff -= 1
                
    # Last ditch effort in case there are still NaNs
    # If so, remove rows/cols 1 by 1 until no NaNs
    while np.isnan(zgrid2.sum()):
        xgrid2 = xgrid2[1:-1]
        ygrid2 = ygrid2[1:-1]
        zgrid2 = zgrid2[1:-1,1:-1]
            
    return xgrid2, ygrid2, zgrid2

In [10]:
# Fix NaN's via extrapolation
zgrid_fix = _fix_zgrid_NaNs(xgrid, ygrid, zgrid)

In [11]:
fig, ax = plt.subplots(1,1, figsize=(8,5))

#zmin, zmax = np.nanmin(zgrid), np.nanmax(zgrid)
extent = np.array([xgrid.min(),xgrid.max(),ygrid.min(),ygrid.max()]) * 60
ax.imshow(zgrid_fix, extent=extent, vmin=zmin, vmax=zmax)

siaf = Siaf('NIRCam')
ap = siaf['NRCA5_FULL_MASK430R']
ap.plot(ax=ax, fill=False, color='C1')

fig.tight_layout()


Do All Apertures


In [12]:
# for mod in ['SW', 'LW', 'SWA', 'LWA', 'SWB', 'LWB']:
for mod in ['SWA', 'LWA', 'SWB', 'LWB']:
    # Create a Zernike cube
    zcube = []
    for k in zkeys:
        xgrid, ygrid, zgrid = gen_cv3_zgrid(ztable_full, v2v3_limits, mod, k)
        zgrid_fix = _fix_zgrid_NaNs(xgrid, ygrid, zgrid)
        zcube.append(zgrid_fix)
        
    zube = np.array(zcube)
    
    hdu = fits.PrimaryHDU(zcube)
    hdr = hdu.header

    dstep = 1. / 60.
    hdr['units'] = 'meters'
    hdr['xunits'] = 'Arcmin'
    hdr['xmin'] = xgrid.min()
    hdr['xmax'] = xgrid.max()
    hdr['xdel'] = dstep
    hdr['yunits'] = 'Arcmin'
    hdr['ymin'] = ygrid.min()
    hdr['ymax'] = ygrid.max()
    hdr['ydel'] = dstep

    hdr['wave'] = 2.10 if 'SW' in mod else 3.23

    hdr['comment'] = 'X and Y values correspond to V2 and V3 coordinates (arcmin).'
    hdr['comment'] = 'Slices in the cube correspond to Zernikes 1 to 36.'
    hdr['comment'] = 'Zernike values calculated using 2D cubic interpolation'
    hdr['comment'] = 'and linear extrapolation outside gridded data.'

    fname = 'NIRCam{}_zernikes_coron.fits'.format(mod)
    hdu.writeto(outdir + fname, overwrite=True)

In [ ]: