Here I will show you how to extract BeamCutouts. Saving these (fits) files before modeling will make entire process quicker. The BeamCutouts contain the orient information which is nessecary for better fitting models. Here's what Gabe says about this from his grizli notebooks:
To interact more closely with an individual object, its information can be extracted from the full exposure with the BeamCutout class. This object will contain the high-level GrismDisperser object useful for generating the model spectra and it will also have tools for analyzing and fitting the observed spectra.
It also makes detailed cutouts of the parent direct and grism images preserving the native WCS information.
In [6]:
from grizli import model
from grizli import multifit
import numpy as np
import matplotlib.pyplot as plt
from scipy.interpolate import interp1d
from shutil import copy
from astropy.table import Table
from astropy import wcs
from astropy.io import fits
from glob import glob
import os
## Seaborn is used to make plots look nicer.
## If you don't have it, you can comment it out and it won't affect the rest of the code
import seaborn as sea
sea.set(style='white')
sea.set(style='ticks')
sea.set_style({'xtick.direct'
'ion': 'in','xtick.top':True,'xtick.minor.visible': True,
'ytick.direction': "in",'ytick.right': True,'ytick.minor.visible': True})
%config InlineBackend.figure_format = 'retina'
%matplotlib inline
In [8]:
Grism_flts = glob('/Volumes/Vince_CLEAR/Data/Grism_fields/ERSPRIME/*GrismFLT.fits')
grp = multifit.GroupFLT(grism_files = Grism_flts, verbose=False)
In [10]:
beams = grp.get_beams(39170)
In [40]:
pa = -1
for BEAM in beams:
if pa != BEAM.get_dispersion_PA():
print('Instrument : {0}, ORIENT : {1}'.format(BEAM.grism.filter,BEAM.get_dispersion_PA()))
pa = BEAM.get_dispersion_PA()
In [39]:
# save out G102 - 345
BEAM = beams[16]
BEAM.write_fits(root='98', clobber=True)
fits.setval('98_39170.g102.A.fits', 'EXPTIME', ext=0,
value=fits.open('98_39170.g102.A.fits')[1].header['EXPTIME'])
# save out G102 - 78
BEAM = beams[4]
BEAM.write_fits(root='78', clobber=True)
fits.setval('78_39170.g102.A.fits', 'EXPTIME', ext=0,
value=fits.open('78_39170.g102.A.fits')[1].header['EXPTIME'])
# save out G102 - 48
BEAM = beams[8]
BEAM.write_fits(root='48', clobber=True)
fits.setval('48_39170.g102.A.fits', 'EXPTIME', ext=0,
value=fits.open('48_39170.g102.A.fits')[1].header['EXPTIME'])
# save out G141 - 345
BEAM = beams[0]
BEAM.write_fits(root='345', clobber=True)
fits.setval('345_39170.g141.A.fits', 'EXPTIME', ext=0,
value=fits.open('345_39170.g141.A.fits')[1].header['EXPTIME'])
In [46]:
## G102 cutouts
for i in glob('*.g102*'):
g102_beam = model.BeamCutout(fits_file=i)
plt.figure()
plt.imshow(g102_beam.beam.direct)
plt.xticks([])
plt.yticks([])
plt.title(i)
## G141 cutout
g141_beam = model.BeamCutout(fits_file='345_39170.g141.A.fits')
plt.figure()
plt.imshow(g141_beam.beam.direct)
plt.xticks([])
plt.yticks([])
plt.title('345_39170.g141.A.fits')
Out[46]:
In [62]:
## G102 cutouts
for i in glob('*.g102*'):
g102_beam = model.BeamCutout(fits_file=i)
plt.figure()
plt.imshow(g102_beam.grism.data['SCI']- g102_beam.contam, vmin = -0.1, vmax=0.5)
plt.xticks([])
plt.yticks([])
plt.title(i)
## G141 cutout
g141_beam = model.BeamCutout(fits_file='345_39170.g141.A.fits')
plt.figure()
plt.imshow(g141_beam.grism.data['SCI']- g141_beam.contam, vmin = -0.1, vmax=0.5)
plt.xticks([])
plt.yticks([])
plt.title('345_39170.g141.A.fits')
Out[62]:
In [ ]: