def wfc3_qso(outfil='Figures/wfc3_qso.pdf'): """ Show a QSO that is transmissive at the Lyman limit """ # WFC3 wfc3, _ = pyicq.wfc3_continuum(0) #zem = 4. # Start the plot xmnx = (650, 1300) pp = PdfPages(outfil) fig = plt.figure(figsize=(8.0, 5.0)) plt.clf() gs = gridspec.GridSpec(1, 1) # Lya line ax = plt.subplot(gs[0]) #ax.xaxis.set_minor_locator(plt.MultipleLocator(0.5)) #ax.xaxis.set_major_locator(plt.MultipleLocator(20.)) #ax.yaxis.set_minor_locator(plt.MultipleLocator(0.1)) #ax.yaxis.set_major_locator(plt.MultipleLocator(0.2)) ax.set_xlim(xmnx) ax.set_ylim(0., 70) ax.set_ylabel('Relative Flux') ax.set_xlabel('Rest wavelength') lw = 2. # Data ax.plot(wfc3.wavelength, wfc3.flux, 'k', linewidth=lw, label='SDSS QSOs (z=4)') # Label csz = 17 ax.text(0.10, 0.80, 'HST/WFC3: QSO spectrum (z~2)', color='black', transform=ax.transAxes, size=csz, ha='left') xputils.set_fontsize(ax, 17.) # Layout and save print('Writing {:s}'.format(outfil)) plt.tight_layout(pad=0.2, h_pad=0.0, w_pad=0.4) plt.subplots_adjust(hspace=0) pp.savefig(bbox_inches='tight') plt.close() # Finish pp.close()
def wfc3_qso(outfil='Figures/wfc3_qso.pdf'): """ Show a QSO that is transmissive at the Lyman limit """ # WFC3 wfc3, _ = pyicq.wfc3_continuum(0) #zem = 4. # Start the plot xmnx = (650, 1300) pp = PdfPages(outfil) fig = plt.figure(figsize=(8.0, 5.0)) plt.clf() gs = gridspec.GridSpec(1,1) # Lya line ax = plt.subplot(gs[0]) #ax.xaxis.set_minor_locator(plt.MultipleLocator(0.5)) #ax.xaxis.set_major_locator(plt.MultipleLocator(20.)) #ax.yaxis.set_minor_locator(plt.MultipleLocator(0.1)) #ax.yaxis.set_major_locator(plt.MultipleLocator(0.2)) ax.set_xlim(xmnx) ax.set_ylim(0., 70) ax.set_ylabel('Relative Flux') ax.set_xlabel('Rest wavelength') lw = 2. # Data ax.plot(wfc3.wavelength, wfc3.flux, 'k', linewidth=lw, label='SDSS QSOs (z=4)') # Label csz = 17 ax.text(0.10, 0.80, 'HST/WFC3: QSO spectrum (z~2)', color='black', transform=ax.transAxes, size=csz, ha='left') xputils.set_fontsize(ax, 17.) # Layout and save print('Writing {:s}'.format(outfil)) plt.tight_layout(pad=0.2,h_pad=0.0,w_pad=0.4) plt.subplots_adjust(hspace=0) pp.savefig(bbox_inches='tight') plt.close() # Finish pp.close()
def mk_mock(wave, zem, fN_model, out_spec=None, add_conti=True, out_tbl=None, s2n=15., fwhm=3., seed=None): """ Generate a mock Parameters ---------- wave : Quantity array zem : float fN_model out_spec : str, optional out_tbl : str, optional s2n : float, optional fwhm : float, optional seed : int, optional Returns ------- full_mock : XSpectrum1D of the mock HI_comps : Table of the components misc : tuple Other bits and pieces [may deprecate] """ # Init rstate=np.random.RandomState(seed) # Wavelength Range wvmin = np.min(wave) #(1+zem)*912.*u.AA - 1000*u.AA wvmax = np.max(wave) dwv = np.median(wave - np.roll(wave,1)) # zrange for Lya zmin = (wvmin/(1215.6700*u.AA))-1. # Components HI_comps = monte_HIcomp((zmin,zem), fN_model, rstate=rstate) # Main call HIlines = mock_HIlines(HI_comps, (wvmin,wvmax)) # Optical depth sub_wave, tot_tau = generate_tau(wave, HIlines, HI_comps) dwv_sub = np.median(sub_wave-np.roll(sub_wave,1)) # Normalized mock spectrum (sub-grid of wavelengths) sub_flux = np.exp(-1.*tot_tau) sub_mock = XSpectrum1D.from_tuple( (sub_wave,sub_flux) ) # Smooth smooth_mock = sub_mock.gauss_smooth(fwhm=fwhm*(dwv/dwv_sub)) # Rebin mock = smooth_mock.rebin(wave) # Add noise mock.sig = np.ones(len(mock.flux))/s2n noisy_mock = mock.add_noise(rstate=rstate) # Continuum if add_conti: conti, wfc3_idx = pycq.wfc3_continuum(zqso=zem,wave=wave,rstate=rstate) cflux = conti.flux else: cflux = np.ones_like(noisy_mock.flux) wfc3_idx = -1 # Full full_mock = XSpectrum1D.from_tuple((wave,noisy_mock.flux*cflux, cflux*np.ones(len(noisy_mock.flux))/s2n)) # Write spectrum (as desired) full_mock.meta.update(dict(zQSO=zem, S2N=s2n, seed=seed, fN_gamma=fN_model.gamma, fN_type=fN_model.fN_mtype, conti=wfc3_idx)) if out_spec is not None: full_mock.write_to_fits(out_spec, clobber=True) # Save HI data (as desired) if out_tbl is not None: HI_comps.write(out_tbl, overwrite=True) # Return return full_mock, HI_comps, (sub_mock, tot_tau, mock)
def test_wfc3_conti(): wfc3, _ = pyicq.wfc3_continuum(wfc3_indx=0, zqso=2.) np.testing.assert_allclose(wfc3.flux[100].value, 18.405926715695372)