Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run quickquasars with eBOSS option #481

Merged
merged 23 commits into from
May 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
62c6332
Remove fastsim fiberloss setting and use_poisson
belaa Nov 5, 2018
4a4e496
Set default config file to "eboss"
belaa Nov 5, 2018
9064828
Fixed merge conflicts
belaa Nov 28, 2018
e09af38
Merge branch 'master' into eboss_quickquasars
belaa Dec 4, 2018
ce4d77f
Merge branch 'master' into eboss_quickquasars
londumas Jan 22, 2019
4956d5d
Merge branch 'master' into eboss_quickquasars
londumas Mar 25, 2019
f80bdbd
read yaml from desi or eboss
londumas Mar 25, 2019
f487731
Need to include use_poisson in generating random noise
belaa Mar 25, 2019
4e00ffc
Read in certain parameters only if specsim_config_file = 'desi'
belaa Mar 25, 2019
6ac50dc
Remove args
belaa Mar 25, 2019
8342ad0
Correct spacing
londumas Mar 26, 2019
712c04c
fix merging conflicts
londumas May 15, 2019
9011594
Merge branch 'master' into eboss_quickquasars
londumas May 16, 2019
090a477
update desitarget version for testing
sbailey Jun 7, 2019
91272cf
Merge branch 'master' into eboss_quickquasars
londumas Jun 20, 2019
ac41d18
Merge branch 'master' into eboss_quickquasars
belaa Jul 12, 2019
6860e9f
Return sim._eboss_camera_output and don't apply additional resolution…
belaa Dec 21, 2019
3933a13
Merge master into eboss_quickquasars
belaa Jan 16, 2020
ab0a2dc
Merge branch 'master' into eboss_quickquasars
belaa Apr 27, 2020
3a39b08
Updated wavemin & wavemax in sim_spectra
belaa May 27, 2020
62dcceb
Fix merge conflicts
belaa May 29, 2020
5b13edc
Update changelog
belaa May 29, 2020
4dc0538
Missing hyperlink
belaa May 29, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions doc/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ desisim change log
* Fix sky level Travis test failure (#534) and "low QSO flux" template unit test
failure (#507) (`PR #536`_).
* Add freeze_iers to more functions in simexp (direct to master).
* Add the option to run quickquasars in eBOSS mode (`PR #481`_)

.. _`PR #536`: https://github.com/desihub/desisim/pull/536
.. _`PR #481`: https://github.com/desihub/desisim/pull/481

0.35.1 (2020-04-15)
-------------------
Expand Down
13 changes: 10 additions & 3 deletions py/desisim/scripts/quickquasars.py
Original file line number Diff line number Diff line change
Expand Up @@ -690,9 +690,16 @@ def simulate_one_healpix(ifilename,args,model,obsconditions,decam_and_wise_filte
log.info("Dust extinction added")
log.info('exposure time adjusted to {}'.format(obsconditions['EXPTIME']))

sim_spectra(qso_wave,qso_flux, args.program, obsconditions=obsconditions, spectra_filename=ofilename,
sourcetype="qso", skyerr=args.skyerr, ra=metadata["RA"], dec=metadata["DEC"], targetid=targetid,
meta=specmeta, seed=seed, fibermap_columns=fibermap_columns, use_poisson=False, dwave_out=dwave_out) # use Poisson = False to get reproducible results.
if args.eboss:
specsim_config_file = 'eboss'
else:
specsim_config_file = 'desi'

### use Poisson = False to get reproducible results.
sim_spectra(qso_wave,qso_flux, args.program, obsconditions=obsconditions,spectra_filename=ofilename,
sourcetype="qso", skyerr=args.skyerr,ra=metadata["RA"],dec=metadata["DEC"],targetid=targetid,
meta=specmeta,seed=seed,fibermap_columns=fibermap_columns,use_poisson=False,
specsim_config_file=specsim_config_file, dwave_out=dwave_out)

### Keep input redshift
Z_spec = metadata['Z'].copy()
Expand Down
89 changes: 60 additions & 29 deletions py/desisim/scripts/quickspectra.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

def sim_spectra(wave, flux, program, spectra_filename, obsconditions=None,
sourcetype=None, targetid=None, redshift=None, expid=0, seed=0, skyerr=0.0, ra=None,
dec=None, meta=None, fibermap_columns=None, fullsim=False, use_poisson=True, dwave_out=None):
dec=None, meta=None, fibermap_columns=None, fullsim=False, use_poisson=True, specsim_config_file="desi", dwave_out=None):
"""
Simulate spectra from an input set of wavelength and flux and writes a FITS file in the Spectra format that can
be used as input to the redshift fitter.
Expand All @@ -51,7 +51,7 @@ def sim_spectra(wave, flux, program, spectra_filename, obsconditions=None,
fibermap_columns : add these columns to the fibermap
fullsim : if True, write full simulation data in extra file per camera
use_poisson : if False, do not use numpy.random.poisson to simulate the Poisson noise. This is useful to get reproducible random realizations.
"""
"""
log = get_logger()

if len(flux.shape)==1 :
Expand Down Expand Up @@ -141,6 +141,10 @@ def sim_spectra(wave, flux, program, spectra_filename, obsconditions=None,
wavemin = desimodel.io.load_throughput('b').wavemin
wavemax = desimodel.io.load_throughput('z').wavemax

if specsim_config_file == "eboss":
wavemin = 3500
wavemax = 10000

if wave[0] > wavemin:
log.warning('Minimum input wavelength {}>{}; padding with zeros'.format(
wave[0], wavemin))
Expand Down Expand Up @@ -177,7 +181,7 @@ def sim_spectra(wave, flux, program, spectra_filename, obsconditions=None,

sim = desisim.simexp.simulate_spectra(wave, flux, fibermap=frame_fibermap,
obsconditions=obsconditions, redshift=redshift, seed=seed,
psfconvolve=True, dwave_out=dwave_out)
psfconvolve=True, specsim_config_file=specsim_config_file, dwave_out=dwave_out)

random_state = np.random.RandomState(seed)
sim.generate_random_noise(random_state,use_poisson=use_poisson)
Expand All @@ -199,32 +203,59 @@ def sim_spectra(wave, flux, program, spectra_filename, obsconditions=None,
table.write(table_filename,format="fits",overwrite=True)
print("wrote",table_filename)

for table in sim.camera_output :

wave = table['wavelength'].astype(float)
flux = (table['observed_flux']+table['random_noise_electrons']*table['flux_calibration']).T.astype(float)
if np.any(skyscale):
flux += ((table['num_sky_electrons']*skyscale)*table['flux_calibration']).T.astype(float)
if specsim_config_file == "eboss":
for table in sim._eboss_camera_output:
wave = table['wavelength'].astype(float)
flux = (table['observed_flux']+table['random_noise_electrons']*table['flux_calibration']).T.astype(float)
if np.any(skyscale):
flux += ((table['num_sky_electrons']*skyscale)*table['flux_calibration']).T.astype(float)

ivar = table['flux_inverse_variance'].T.astype(float)

band = table.meta['name'].strip()[0]

flux = flux * scale
ivar = ivar / scale**2
mask = np.zeros(flux.shape).astype(int)

spec = Spectra([band], {band : wave}, {band : flux}, {band : ivar},
resolution_data={band : resolution[band]},
mask={band : mask},
fibermap=spectra_fibermap,
meta=meta,
single=True)

if specdata is None :
specdata = spec
else :
specdata.update(spec)
ivar = table['flux_inverse_variance'].T.astype(float)

band = table.meta['name'].strip()[0]

flux = flux * scale
ivar = ivar / scale**2
mask = np.zeros(flux.shape).astype(int)

spec = Spectra([band], {band : wave}, {band : flux}, {band : ivar},
resolution_data=None,
mask={band : mask},
fibermap=spectra_fibermap,
meta=meta,
single=True)

if specdata is None :
specdata = spec
else :
specdata.update(spec)

else:
for table in sim.camera_output :
wave = table['wavelength'].astype(float)
flux = (table['observed_flux']+table['random_noise_electrons']*table['flux_calibration']).T.astype(float)
if np.any(skyscale):
flux += ((table['num_sky_electrons']*skyscale)*table['flux_calibration']).T.astype(float)

ivar = table['flux_inverse_variance'].T.astype(float)

band = table.meta['name'].strip()[0]

flux = flux * scale
ivar = ivar / scale**2
mask = np.zeros(flux.shape).astype(int)

spec = Spectra([band], {band : wave}, {band : flux}, {band : ivar},
resolution_data={band : resolution[band]},
mask={band : mask},
fibermap=spectra_fibermap,
meta=meta,
single=True)

if specdata is None :
specdata = spec
else :
specdata.update(spec)

desispec.io.write_spectra(spectra_filename, specdata)
log.info('Wrote '+spectra_filename)
Expand Down Expand Up @@ -351,7 +382,7 @@ def main(args=None):
if sourcetype is not None and len(input_flux.shape)>1 :
nspec=input_flux.shape[0]
sourcetype=np.array([sourcetype for i in range(nspec)])

sim_spectra(input_wave, input_flux, args.program, obsconditions=obsconditions,
spectra_filename=args.out_spectra,seed=args.seed,sourcetype=sourcetype,
skyerr=args.skyerr,fullsim=args.fullsim)
Expand Down
6 changes: 4 additions & 2 deletions py/desisim/simexp.py
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,8 @@ def simulate_spectra(wave, flux, fibermap=None, obsconditions=None, redshift=Non
# source types are sky elg lrg qso bgs star , they
# are only used in specsim.fiberloss for the desi.instrument.fiberloss_method="table" method

desi.instrument.fiberloss_method = 'fastsim'
if specsim_config_file == "desi":
desi.instrument.fiberloss_method = 'fastsim'

log.debug('running simulation with {} fiber loss method'.format(desi.instrument.fiberloss_method))

Expand Down Expand Up @@ -621,7 +622,8 @@ def _specsim_config_for_wave(wave, dwave_out=None, specsim_config_file = "desi")

config.instrument.cameras.b.constants.output_pixel_size = "{:.3f} Angstrom".format(dwave_out)
config.instrument.cameras.r.constants.output_pixel_size = "{:.3f} Angstrom".format(dwave_out)
config.instrument.cameras.z.constants.output_pixel_size = "{:.3f} Angstrom".format(dwave_out)
if specsim_config_file == "desi":
config.instrument.cameras.z.constants.output_pixel_size = "{:.3f} Angstrom".format(dwave_out)

config.update()
return config
Expand Down