Skip to content

Instantly share code, notes, and snippets.

@kartheikiyer
Created May 4, 2023 15:18
Show Gist options
  • Select an option

  • Save kartheikiyer/d90f496cf0c13d4ed6d2aec4fde08028 to your computer and use it in GitHub Desktop.

Select an option

Save kartheikiyer/d90f496cf0c13d4ed6d2aec4fde08028 to your computer and use it in GitHub Desktop.
PRISM dispersion for JWST
# get the dispersion function from:
# https://jwst-docs.stsci.edu/jwst-near-infrared-spectrograph/nirspec-instrumentation/nirspec-dispersers-and-filters
# and put it in the _data_path folder
from astropy.table import Table
from sedpy.smoothing import smoothspec
_data_path = 'disp_curves/'
grating = 'prism'
disp = Table.read(f'{_data_path}jwst_nirspec_{grating}_disp.fits')
def convolve_with_disp(lam, spec, z, disp,
velocity_fwhm = 20, scale_disp = 1.3, FFTSMOOTH = False,
extra_sigma = 0.):
"""
lam in \AA
spec in F_lambda units
disp file loaded from above
"""
dv = np.sqrt(velocity_fwhm**2 + (3.e5/disp['R']/scale_disp)**2)
disp_ang = disp['WAVELENGTH']*1.e4
dlam_ang = disp_ang*dv/3.e5/2.35
def _lsf(wave):
return np.interp(wave,
disp_ang,
dlam_ang,
left=dlam_ang[0], right=dlam_ang[-1],
)
wobs = lam
clip = wobs > 0
lsf_func = _lsf
lsf_sigma = lsf_func(wobs[clip])/wobs[clip]*3.e5
lsf_func_name = 'user'
vel_sigma = np.sqrt(lsf_sigma**2 + extra_sigma**2)
smooth_lambda = vel_sigma / 3.e5 * wobs[clip]
_templ_flux = spec.copy()
smoothspec_kwargs={'fftsmooth':FFTSMOOTH}
flux_smooth = smoothspec(wobs[clip],
(_templ_flux)[clip],
lsf_func=_lsf,
resolution=smooth_lambda,
smoothtype='lsf',
**smoothspec_kwargs,
)
return flux_smooth
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment