<jupyter_start><jupyter_text>New LRISr Mark4 detector<jupyter_code># imports
import os, glob
import numpy as np

from matplotlib import pyplot as plt

from astropy.io import fits

from pypeit.core import parse
from pypeit.display import display
from pypeit import flatfield<jupyter_output><empty_output><jupyter_text>Load data<jupyter_code>dpath = '/scratch/REDUX/Keck/LRIS/new_LRISr'
rpath = os.path.join(dpath, 'Raw')
dfile = os.path.join(rpath, 'r211004_00003.fits')
hdul = fits.open(dfile)
hdul.info()
raw_data = hdul[0].data.astype(float)
raw_data.shape<jupyter_output><empty_output><jupyter_text>Load pixel file<jupyter_code>pix_file = os.path.join(dpath, 'pixelsL2U2L1U1_1_1.fits')
hdu_pix = fits.open(pix_file)
hdu_pix.info()
for ii in range(4):
    print(hdu_pix[0].header[f'DSEC{ii}'])<jupyter_output>[8:2064,2185:4248]
[8:2064,1:2064]
[2171:4227,2185:4248]
[2171:4227,1:2064]<jupyter_text>Overwrite header<jupyter_code>head0 = hdul[0].header
for card, value in hdu_pix[0].header.items():
    head0[card] = value<jupyter_output><empty_output><jupyter_text>Write<jupyter_code>hdul[0].header['BSEC4']
hdul.writeto(dfile.replace('.fits', '_upd.fits'))<jupyter_output>WARNING: VerifyWarning: Card is too long, comment will be truncated. [astropy.io.fits.card]<jupyter_text>Loop me<jupyter_code>rfiles = glob.glob(rpath+'/*.fits')
rfiles
for rfile in rfiles:
    hdul = fits.open(rfile)
    head0 = hdul[0].header
    for card, value in hdu_pix[0].header.items():
        head0[card] = value
    # Write
    hdul.writeto(rfile.replace('.fits', '_upd.fits'))<jupyter_output><empty_output><jupyter_text>Moved them to their own folder.. ----  Reudcin  Test pypeit_view_fits keck_lris_red_mark4 r211004_00003_upd.fits Looks good!  pypeit_view_fits keck_lris_red_mark4 r211004_00003_upd.fits --proc<jupyter_code>## Setup

##<jupyter_output><empty_output><jupyter_text>----  Extract me<jupyter_code>final_img = np.zeros((2064*2, 2057*2))<jupyter_output><empty_output><jupyter_text>Amp L1, aka AMPID3, aka readout sequence 2<jupyter_code>parse.load_sections(head0['DSEC3'], fmt_iraf=True)
slice3 = parse.sec2slice(head0['DSEC3'], one_indexed=True, include_end=True)
slice3
slice3b = (slice3[1], slice3[0])
slice3b
amp_l1 = raw_data[slice3b]
amp_l1.shape
display.show_image(amp_l1)<jupyter_output><empty_output><jupyter_text>Amp L2<jupyter_code>slice2 = parse.sec2slice(head0['DSEC2'], one_indexed=True, include_end=True)
slice2
slice2b = (slice2[1], slice2[0])
amp_l2 = raw_data[slice2b]
amp_l2.shape
display.show_image(amp_l2)<jupyter_output><empty_output><jupyter_text>----  Checking the gain  The following was for an original set of gain values. Use chk_lris_mark4_gain.py in the DevSuite repo (dev_algorithms/lris) for further analysis  Load a 4 amp flat<jupyter_code>rdx_path = '/scratch/REDUX/Keck/LRIS/new_LRISr/keck_lris_red_mark4_A'
master_file = os.path.join(rdx_path, 'Masters', 'MasterFlat_A_1_01.fits')
# Load
flatImages = flatfield.FlatImages.from_file(master_file)
flatImages.pixelflat_raw.shape<jupyter_output><empty_output><jupyter_text>Spectral cut<jupyter_code>spat_mid = flatImages.pixelflat_raw.shape[1]//2
spat_mid
left_spec = np.median(flatImages.pixelflat_raw[:,spat_mid-3:spat_mid], axis=1)
left_spec.size
right_spec = np.median(flatImages.pixelflat_raw[:,spat_mid:spat_mid+3], axis=1)<jupyter_output><empty_output><jupyter_text>Plot<jupyter_code>plt.clf()
ax = plt.gca()
ax.plot(left_spec, label='left')
ax.plot(left_spec, label='right')
ax.legend()
ax.set_xlabel('spec')
plt.show()
rtio_spec = left_spec/right_spec
plt.clf()
ax = plt.gca()
ax.plot(rtio_spec, label='ratio', color='k')
#ax.plot(left_spec, label='right')
ax.set_xlabel('spec')
ax.legend()
plt.savefig('ratio_spec.png', dpi=300)
plt.show()<jupyter_output><empty_output><jupyter_text>Spatial cuts<jupyter_code>spec_mid = flatImages.pixelflat_raw.shape[0]//2
spec_mid
bot_spat = np.median(flatImages.pixelflat_raw[spec_mid-3:spec_mid, :], axis=0)
top_spat = np.median(flatImages.pixelflat_raw[spec_mid:spec_mid+3, :], axis=0)
rtio_spat = top_spat/bot_spat
plt.clf()
ax = plt.gca()
ax.plot(rtio_spat, label='ratio', color='r')
#ax.plot(left_spec, label='right')
ax.set_xlabel('spat')
ax.set_xlim(1400, 2600)
ax.set_ylim(0.9, 1.1)
ax.legend()
plt.savefig('ratio_spat.png', dpi=300)

plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14550939893246692, 'fraction_numerical': 0.04362961243908099, 'mean_word_length': 7.88659793814433, 'pattern_counts': {'":': 0, '<': 55, '<?xml version=': 0, '>': 55, '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': '14', 'dir': 'jupyter-structured-clean-dedup', 'id': '64335', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 1949, 'n_tokens_neox': 1843, 'n_words': 259, 'path': 'doc/nb/LRIS_red_mark4.ipynb', 'repo_name': 'joaquinhernandezg/PypeIt', 'size': '4309'}