##################################################
# Example of sensitivity function determination  #
##################################################
if do_sens:
    spec1dfile = os.path.join(
        os.getenv('HOME'),
        'Dropbox/PypeIt_Redux/XSHOOTER/spec1d_XSHOO.2017-11-23T08:25:54.754-LTT3218_XShooter_NIR_2017Nov23T082554.754.fits'
    )
    telgridfile = os.path.join(
        os.getenv('HOME'),
        'Dropbox/PypeIt_Redux/XSHOOTER/TelFit_Paranal_NIR_9800_25000_R25000.fits'
    )
    outfile = 'LTT3218_sens_tell.fits'
    TelSens = telluric.sensfunc_telluric(spec1dfile,
                                         telgridfile,
                                         outfile,
                                         mask_abs_lines=True,
                                         debug=False)

###############################
# Example of quasar model fit #
###############################
if do_qso:
    spec1dfluxfile = os.path.join(
        os.getenv('HOME'),
        'Dropbox/PypeIt_Redux/XSHOOTER/NIR_Stack/spec1d_stack_J0224-4711.fits')
    pca_file = os.path.join(os.getenv('HOME'),
                            'Dropbox/PypeIt_Redux//qso_pca_1200_3100.pckl')
    telgridfile = os.path.join(
        os.getenv('HOME'),
        'Dropbox/PypeIt_Redux/XSHOOTER/TelFit_Paranal_NIR_9800_25000_R25000.fits'
pix_per_R = 1.0 / resln_guess / (dloglam * np.log(10.0)) / (2.0 * np.sqrt(2.0 * np.log(2)))
'''
std1dfile = os.path.join(os.getenv('HOME'),'Dropbox/PypeIt_Redux/XSHOOTER/J0439/NIR/Science/spec1d_XSHOO.2018-10-16T08:34:05.508-LTT3218_XShooter_NIR_2018Oct16T083405.508.fits')

# get the pca pickle file and atmosphere model grid
pca_file = os.path.join(os.getenv('HOME'),'Dropbox/PypeIt_Redux//qso_pca_1200_3100.pckl')
telgridfile = os.path.join(os.getenv('HOME'),'Dropbox/PypeIt_Redux/XSHOOTER/TelFit_Paranal_NIR_9800_25000_R25000.fits')

# TODO: set sensfile=None if you want to derive sensfunc from std1dfile
sensfile = os.path.join(os.getenv('HOME'), 'Dropbox/PypeIt_Redux/XSHOOTER/LTT3218_sens_tell.fits')
if do_sens:
    if std1dfile is None:
        msgs.error('You need either give a std1dfile to derive sensfunc')
    else:
        # run telluric.sensfunc_telluric to get the sensfile
        TelSens = telluric.sensfunc_telluric(std1dfile, telgridfile, sensfile, mask_abs_lines=True, debug=debug)

## Apply the sensfunc to all spectra (only sensfunc but not tellluric)
# TODO: change show=False to show=show
#apply_sensfunc(fnames, sensfile, extinct_correct=False, tell_correct=False, debug=debug, show=False)

fnames_flux = [f.replace('.fits', '_flux.fits') for f in fnames]

## Let's coadd all the fluxed spectra
# you should get a coadded spectrum named as 'spec1d_stack_{:}.fits'.format(qsoname)
#                a straight merge of individual order stacked spectra named as 'spec1d_merge_{:}.fits'.format(qsoname)
#                a individual order stacked spectra (multi-extension) named as 'spec1d_order_{:}.fits'.format(qsoname)
# TODO: change the outfile to work with datapath. It's a hard coding on these names in coadd1d
wave_stack, flux_stack, ivar_stack, mask_stack = coadd1d.ech_combspec(fnames_flux[0:11], objids, sensfile=sensfile,
                                                                      ex_value='OPT', outfile=qsoname, show=show,
                                                                      show_exp=show_exp, debug=debug)
Exemplo n.º 3
0
#polyorder=6
#sens_dict = ech_sensfunc_telluric(spec1dfile, telgridfile, polyorder=polyorder, ra=header['RA'], dec=header['DEC'],
#                          star_mag=star_mag, star_type=star_type)
#sensfuncfile = 'EG274_sensfunc.json'
#save.save_sens_dict(sens_dict,sensfuncfile)
#sens_dict = load.load_sens_dict(sensfuncfile)


spec1dfile = os.path.join(os.getenv('HOME'),'Dropbox/PypeIt_Redux/XSHOOTER/J0020-3653/NIR/Science/spec1d_STD,FLUX_XShooter_NIR_2017Dec17T082243.751.fits')
telgridfile = os.path.join(os.getenv('HOME'),'Dropbox/PypeIt_Redux/XSHOOTER/TelFit_Paranal_NIR_9800_25000_R25000.fits')
outfile = 'LTT3218_sens_tell.fits'




telluric.sensfunc_telluric(spec1dfile, telgridfile, outfile)
sys.exit(-1)
#std_dict = flux.get_standard_spectrum(star_type=star_type, star_mag=star_mag, ra=star_ra, dec=star_dec)

#polyorder=8 # changed from 6
#norders = counts.shape[1]

#if np.size(polyorder) > 1:
#    if np.size(polyorder) != norders:
#        msgs.error('polyorder must have either have norder elements or be a scalar')
#    polyorder_vec = np.array(polyorder)
#else:
#    polyorder_vec = np.full(norders, polyorder)

#obj_params = dict(std_dict=std_dict, delta_coeff_bounds=(-20.0, 20.0),
#                  minmax_coeff_bounds=(-5.0, 5.0), polyorder_vec=polyorder_vec,
std1dfile = os.path.join(os.getenv('HOME'),
                          'Dropbox/PypeIt_Redux/GNIRS/BlueHawaii/spec1d_N20190531S0067-HIP56736_GNIRS_2019May31T073323.707.fits')

# get the pca pickle file and atmosphere model grid
pca_file = os.path.join(os.getenv('HOME'),'Dropbox/PypeIt_Redux/qso_pca_1200_3100.pckl')
telgridfile = os.path.join(os.getenv('HOME'),'Dropbox/PypeIt_Redux/TelFit_MaunaKea_3100_26100_R20000.fits')

# TODO: set sensfile=None if you want to derive sensfunc from std1dfile
sensfile = os.path.join(os.getenv('HOME'), 'Dropbox/PypeIt_Redux/GNIRS/HIP56736_sens_tell_gnirs.fits')
if do_sens:
    if std1dfile is None:
        msgs.error('You need either give a std1dfile to derive sensfunc')
    else:
        # run telluric.sensfunc_telluric to get the sensfile
        TelSens = telluric.sensfunc_telluric(std1dfile, telgridfile, sensfile, star_type='A0', star_mag=8.78,
                                             star_ra=None, star_dec=None, mask_abs_lines=True, debug=True)

## Apply the sensfunc to all spectra (only sensfunc but not tellluric)
# TODO: change show=False to show=show
apply_sensfunc(fnames, sensfile, extinct_correct=False, tell_correct=False, debug=debug, show=False)

fnames_flux = [f.replace('.fits', '_flux.fits') for f in fnames]

## Let's coadd all the fluxed spectra
# you should get a coadded spectrum named as 'spec1d_stack_{:}.fits'.format(qsoname)
#                a straight merge of individual order stacked spectra named as 'spec1d_merge_{:}.fits'.format(qsoname)
#                a individual order stacked spectra (multi-extension) named as 'spec1d_order_{:}.fits'.format(qsoname)
# TODO: change the outfile to work with datapath. It's a hard coding on these names in coadd1d
wave_stack, flux_stack, ivar_stack, mask_stack = coadd1d.ech_combspec(fnames_flux, objids, show=show, sensfile=sensfile,
                                                                      ex_value='OPT', outfile=qsoname, debug=debug)