<jupyter_start><jupyter_text>Comparing HiCAT E2E vs. matrix PASTIS contrast<jupyter_code>from astropy.io import fits
import astropy.units as u
import matplotlib.pyplot as plt
import numpy as np

from config import CONFIG_PASTIS
from e2e_simulators.hicat_imaging import set_up_hicat
import util as util
nb_seg = CONFIG_PASTIS.getint('HiCAT', 'nb_subapertures')
# HiCAT direct PSF and normalization
hicat = set_up_hicat(apply_continuous_dm_maps=True)
hicat.include_fpm = False
data = hicat.calc_psf()
psf = data[0].data
norm = psf.max()
print(norm)

plt.imshow(np.log(psf))
# HiCAT coronagraph floor
hicat = set_up_hicat(apply_continuous_dm_maps=True)
hicat.include_fpm = True
data = hicat.calc_psf()
coro = data[0].data / norm

iwa = CONFIG_PASTIS.getfloat('HiCAT', 'IWA')
owa = CONFIG_PASTIS.getfloat('HiCAT', 'OWA')
sampling = CONFIG_PASTIS.getfloat('HiCAT', 'sampling')

dh_mask = util.create_dark_hole(coro, iwa=iwa, owa=owa, samp=sampling)
coro_floor = util.dh_mean(coro, dh_mask)
print(f'Coro floor: {coro_floor}')
# Load the matrix
matrix = fits.getdata('/Users/ilaginja/data_from_repos/pastis_data/2020-08-26T11-44-28_hicat/matrix_numerical/PASTISmatrix_num_piston_Noll1.fits')
print(matrix.shape)
plt.imshow(matrix)<jupyter_output><empty_output><jupyter_text>Create aberation<jupyter_code># Create random aberrations normalized to a certain WFE rms value
rms_norm = 2 *u.nm
print(rms_norm)
aber = np.random.random([nb_seg]) 
rms_init = util.rms(aber)
aber *= rms_norm.value / rms_init
aber *= u.nm
print(aber)
aber -= np.mean(aber)
print(aber)<jupyter_output><empty_output><jupyter_text>E2E contrast<jupyter_code># Put aberration on Iris AO and calculate PSF
plt.figure(figsize=(12, 10))
for nseg in range(nb_seg):
    hicat.iris_dm.set_actuator(nseg, aber[nseg], 0, 0)

psf_hicat = hicat.calc_psf(display=True, return_intermediates=False)
psf_hicat = psf_hicat[0].data / norm
plt.figure(figsize=(10,10))
plt.imshow(np.log10(psf_hicat))
plt.colorbar()
contrast_e2e = util.dh_mean(psf_hicat, dh_mask)
print(rms_norm)
print(contrast_e2e)<jupyter_output><empty_output><jupyter_text>PASTIS contrast<jupyter_code>contrast_pastis = util.pastis_contrast(aber, matrix) + coro_floor
print(contrast_pastis)
print(matrix)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11788256227758007, 'fraction_numerical': 0.01601423487544484, 'mean_word_length': 7.65, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, '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': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '52307', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 986, 'n_tokens_neox': 917, 'n_words': 160, 'path': 'notebooks/HiCAT/9_Contrast calculation E2E vs PASTIS.ipynb', 'repo_name': 'spacetelescope/PASTIS', 'size': '2248'}