Skip to content

Commit

Permalink
Merge pull request #412 from desihub/nside-and-overwrite-options
Browse files Browse the repository at this point in the history
add nside and overwrite options to wrap-newexp and obs.new_exposure, resp.
  • Loading branch information
sbailey committed Sep 10, 2018
2 parents 10617d7 + 8f8c83c commit 2362b20
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 13 deletions.
5 changes: 3 additions & 2 deletions bin/wrap-newexp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ parser.add_argument('--mockdir', type=str, help="directory with mock targets and
#- Optional
parser.add_argument('--outdir', type=str, help="output directory")
parser.add_argument('--tilefile', type=str, help="ASCII file with subset of tiles to process")
parser.add_argument('--nside', help='healpixel organization scheme of the mock spectra', type=int, default=64)
parser.add_argument('--force', action='store_true', help="force re-processing to overwrite pre-existing output files")
parser.add_argument('--nonuniform', action='store_true', help="simulate non-uniform calibration screen illumination")
parser.add_argument('--dryrun', action='store_true', help="print commands but don't run them")
Expand Down Expand Up @@ -124,8 +125,8 @@ if rank < len(todo):
for thisobs in todo[rank::size]:
assert thisobs['FLAVOR'] in ('science', 'arc', 'flat')
if thisobs['FLAVOR'] == 'science':
cmd = "newexp-mock --obslist {} --fiberassign {} --mockdir {}".format(
args.obslist, args.fiberassign, args.mockdir)
cmd = "newexp-mock --obslist {} --fiberassign {} --mockdir {} --nside {}".format(
args.obslist, args.fiberassign, args.mockdir, args.nside)
if args.outdir is not None:
cmd = cmd + " --outdir {}".format(args.outdir)
cmd = cmd + " --clobber --expid {}".format(thisobs['EXPID'])
Expand Down
11 changes: 7 additions & 4 deletions doc/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,23 @@ desisim change log
0.30.1 (unreleased)
-------------------

* No changes yet.
* Add optional `nside` and `overwrite` arguments to `wrap-newexp` and
`obs.new_exposure`, respectively (`PR #412`_).
* Major (and backwards-incompatible) refactor of how the template/simulated
metadata are returned by desisim.templates (`PR #409`_).

.. _`PR #409`: https://github.com/desihub/desisim/pull/409
.. _`PR #412`: https://github.com/desihub/desisim/pull/412

0.30.0 (2018-08-09)
-------------------

* Major (and backwards-incompatible) refactor of how the template/simulated
metadata are returned by desisim.templates (`PR #409`_).
* Update templates to DR7+ standard-star designation (FSTD-->STD) (`PR #400`_).
* Update standard star bit name again STD -> STD_FAINT;
requires desitarget 0.23.0 (`PR #402`_).

.. _`PR #400`: https://github.com/desihub/desisim/pull/400
.. _`PR #402`: https://github.com/desihub/desisim/pull/402
.. _`PR #409`: https://github.com/desihub/desisim/pull/409

0.29.0 (2018-07-26)
-------------------
Expand Down
9 changes: 5 additions & 4 deletions py/desisim/obs.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def new_exposure(program, nspec=5000, night=None, expid=None, tileid=None,
nproc=None, seed=None, obsconditions=None,
specify_targets=dict(), testslit=False, exptime=None,
arc_lines_filename=None, flat_spectrum_filename=None,
outdir=None):
outdir=None, overwrite=False):
"""
Create a new exposure and output input simulation files.
Does not generate pixel-level simulations or noisy spectra.
Expand All @@ -55,6 +55,7 @@ def new_exposure(program, nspec=5000, night=None, expid=None, tileid=None,
arc_lines_filename (str, optional): use alternate arc lines filename (used if program="arc")
flat_spectrum_filename (str, optional): use alternate flat spectrum filename (used if program="flat")
outdir (str, optional): output directory
overwrite (bool, optional): optionally clobber existing files
Returns:
science: sim, fibermap, meta, obsconditions, objmeta
Expand Down Expand Up @@ -125,7 +126,7 @@ def new_exposure(program, nspec=5000, night=None, expid=None, tileid=None,
wave, phot, fibermap = desisim.simexp.simarc(arcdata, nspec=nspec, testslit=testslit)

header['EXPTIME'] = exptime
desisim.io.write_simspec_arc(outsimspec, wave, phot, header, fibermap=fibermap)
desisim.io.write_simspec_arc(outsimspec, wave, phot, header, fibermap=fibermap, overwrite=overwrite)

fibermap.meta['NIGHT'] = night
fibermap.meta['EXPID'] = expid
Expand All @@ -147,7 +148,7 @@ def new_exposure(program, nspec=5000, night=None, expid=None, tileid=None,
header['EXPTIME'] = exptime
header['FLAVOR'] = 'flat'
desisim.io.write_simspec(sim, truth=None, fibermap=fibermap, obs=None,
expid=expid, night=night, header=header, filename=outsimspec)
expid=expid, night=night, header=header, filename=outsimspec, overwrite=overwrite)

fibermap.meta['NIGHT'] = night
fibermap.meta['EXPID'] = expid
Expand Down Expand Up @@ -207,7 +208,7 @@ def new_exposure(program, nspec=5000, night=None, expid=None, tileid=None,

simfile = io.write_simspec(sim, meta, fibermap, obsconditions,
expid, night, objmeta=objmeta, header=hdr,
filename=outsimspec)
filename=outsimspec, overwrite=overwrite)

if not isinstance(fibermap, table.Table):
fibermap = table.Table(fibermap)
Expand Down
3 changes: 2 additions & 1 deletion py/desisim/scripts/newexp_mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def parse(options=None):
parser.add_argument('--expid', type=int, required=True, help="exposure ID")

#- Optional
parser.add_argument('--nside', help='healpixel organization scheme of the mock spectra', type=int, default=64)
parser.add_argument('--outdir', type=str, help="output directory")
parser.add_argument('--nspec', type=int, default=None, help="number of spectra to include")
parser.add_argument('--clobber', action='store_true', help="overwrite any pre-existing output files")
Expand Down Expand Up @@ -72,7 +73,7 @@ def main(args=None):

log.info('Simulating night {} expid {} tile {}'.format(night, args.expid, tileid))
try:
flux, wave, meta = get_mock_spectra(fiberassign, mockdir=args.mockdir)
flux, wave, meta = get_mock_spectra(fiberassign, mockdir=args.mockdir, nside=args.nside)
except Exception as err:
log.fatal('Failed expid {} fiberassign {} tile {}'.format(
args.expid, args.fiberassign, tileid))
Expand Down
4 changes: 2 additions & 2 deletions py/desisim/simexp.py
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,7 @@ def testslit_fibermap():
#- MOVE THESE TO desitarget.mocks.io (?)
#-------------------------------------------------------------------------

def get_mock_spectra(fiberassign, mockdir=None):
def get_mock_spectra(fiberassign, mockdir=None, nside=64):
'''
Args:
fiberassign: table loaded from fiberassign tile file
Expand All @@ -764,7 +764,7 @@ def get_mock_spectra(fiberassign, mockdir=None):
## TODO: check desi_mask.NO_TARGET once that bit exists

for truthfile, targetids in zip(*targets2truthfiles(
fiberassign[~unassigned], basedir=mockdir)):
fiberassign[~unassigned], basedir=mockdir, nside=nside)):

#- Sky fibers aren't in the truth files
ok = ~np.in1d(targetids, skyids)
Expand Down

0 comments on commit 2362b20

Please sign in to comment.