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

zproc run group_spectra vs. coadd_spectra #2383

Merged
merged 1 commit into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 4 additions & 4 deletions py/desispec/scripts/coadd_spectra.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from __future__ import absolute_import, division, print_function

import os,sys
import argparse
import numpy as np
from astropy.table import Table
import fitsio
Expand All @@ -19,7 +20,6 @@
from desispec.specscore import compute_coadd_scores

def parse(options=None):
import argparse

parser = argparse.ArgumentParser("Coadd all spectra per target, and optionally resample on linear or logarithmic wavelength grid")
parser.add_argument("-i","--infile", type=str, nargs='+',
Expand Down Expand Up @@ -54,11 +54,11 @@ def parse(options=None):
return args

def main(args=None):

log = get_logger()

if args is None:
args = parse()
#- Parse None or list of strings of command line opts
if not isinstance(args, argparse.Namespace):
args = parse(options=args)

if args.lin_step is not None and args.log10_step is not None :
log.critical("cannot have both linear and logarthmic bins :-), choose either --lin-step or --log10-step")
Expand Down
43 changes: 28 additions & 15 deletions py/desispec/scripts/zproc.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
camword_to_spectros, columns_to_goodcamword, difference_camwords
from desispec.io.util import validate_badamps, get_tempfilename, backup_filename
from desispec.util import runcmd
from desispec.scripts import group_spectra
from desispec.scripts import group_spectra, coadd_spectra
from desispec.parallel import stdouterr_redirected
from desispec.workflow import batch
from desispec.workflow.exptable import get_exposure_table_pathname, \
Expand Down Expand Up @@ -529,30 +529,43 @@ def main(args=None, comm=None):
splog = findfile('spectra', logfile=True, **findfileopts)
coaddfile = findfile('coadd', **findfileopts)

cmd = f"desi_group_spectra --inframes {' '.join(cframes)} " \
+ f"--outfile {spectrafile} " \
+ f"--coaddfile {coaddfile} "
if os.path.exists(spectrafile):
log.info(f'Spectra file {os.path.basename(spectrafile)} already exists; only running coaddition')
group_func = coadd_spectra.main
inputs = [spectrafile,]
outputs = [coaddfile,]
cmd = f"desi_coadd_spectra -i {spectrafile} -o {coaddfile}"
if groupname != 'healpix':
cmd += ' --onetile'

if groupname == 'healpix':
cmd += f"--healpix {healpix} "
cmd += f"--header SURVEY={args.survey} PROGRAM={args.program} "
else:
cmd += "--onetile "
cmd += (f"--header SPGRP={groupname} SPGRPVAL={thrunight} "
f"NIGHT={thrunight} TILEID={tileid} SPECTRO={spectro} PETAL={spectro} ")
group_func = group_spectra.main
inputs = cframes
outputs = [spectrafile, coaddfile]
cmd = f"desi_group_spectra --inframes {' '.join(cframes)} " \
+ f"--outfile {spectrafile} " \
+ f"--coaddfile {coaddfile} "

if groupname == 'healpix':
cmd += f"--healpix {healpix} "
cmd += f"--header SURVEY={args.survey} PROGRAM={args.program} "
else:
cmd += "--onetile "
cmd += (f"--header SPGRP={groupname} SPGRPVAL={thrunight} "
f"NIGHT={thrunight} TILEID={tileid} SPECTRO={spectro} PETAL={spectro} ")

if groupname == 'perexp':
cmd += f'EXPID={expids[0]} '
if groupname == 'perexp':
cmd += f'EXPID={expids[0]} '

cmdargs = cmd.split()[1:]
if args.dryrun:
if rank == 0:
log.info(f"dryrun: Would have run {cmd}")
else:
with stdouterr_redirected(splog):
result, success = runcmd(group_spectra.main,
args=cmdargs, inputs=cframes,
outputs=[spectrafile, coaddfile])
result, success = runcmd(group_func,
args=cmdargs, inputs=inputs,
outputs=outputs)

if not success:
log.error(f'desi_group_spectra petal {spectro} failed; see {splog}')
Expand Down
Loading