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

Default exposure types to be processed, added logs for skipped files. if not done, do logic now applies to outdir reroute. #496

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
36 changes: 30 additions & 6 deletions bin/wrap-fastframe
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ parser.add_argument('--mpi', action='store_true', help="use MPI parallelism")
parser.add_argument('--start', type=str, help="start date YEARMMDD")
parser.add_argument('--stop', type=str, help="stop date YEARMMDD")
parser.add_argument('--cframe', action='store_true', help="directly write cframe")
parser.add_argument('--exptypes', type=str, help="comma separated list of exposure types for processing", default='flat,science')
args = parser.parse_args()

#- Load MPI and establish communication
Expand Down Expand Up @@ -67,19 +68,39 @@ if rank == 0:
night = os.path.basename(os.path.dirname(os.path.dirname(filename)))
if (args.start <= night) & (night < args.stop):
flavor = fits.getval(filename, 'FLAVOR')

expid = fits.getval(filename, 'EXPID')
if flavor not in ('flat', 'science'):

if flavor not in tuple(args.exptypes.split(',')):
print('night {} expid {} is {}; skipping'.format(
night, expid, flavor))

logfile = filename.replace('simspec', 'fastframe').replace('.fits', '.log')

assert logfile != filename

if args.outdir:
## If outdir provided, log files inherit /night/exposure structure of simspec files but in outdir.
## Else placed in original dir. with simspecs.
logfile = logfile.replace(desisim.io.simdir(), args.outdir)

try:
os.makedirs(os.path.dirname(logfile), exist_ok=args.clobber)
except:
print('Pass --clobber to replace previously created logfile for {}.'.format(expid))

with open(logfile, "w") as openfile:
print('night {} expid {} is {}; skipping'.format(night, expid, flavor), file=openfile)

continue

#- This precheck could get slow; consider caching differently
done = True
for camera in cameras:
if args.cframe :
framefile = desispec.io.findfile('cframe', night, expid, camera)
framefile = desispec.io.findfile('cframe', night, expid, camera, specprod_dir=args.outdir)
else :
framefile = desispec.io.findfile('frame', night, expid, camera)
framefile = desispec.io.findfile('frame', night, expid, camera, specprod_dir=args.outdir)

if args.clobber or not os.path.exists(framefile):
simspecfiles.append( (flavor, filename) )
Expand All @@ -106,7 +127,7 @@ if rank < len(simspecfiles):
for flavor, filename in simspecfiles[rank::size]:
cmd = "fastframe --simspec {}".format(filename)
if args.outdir:
cmd = cmd + " --outdir {}".format(args.outdir)
cmd = cmd + " --outdir {}".format(args.outdir)
if args.clobber:
pass
## clobber not supported by fastframe (it clobbers by default)
Expand All @@ -130,7 +151,11 @@ if rank < len(simspecfiles):
## If outdir provided, log files inherit /night/exposure structure of simspec files but in outdir.
## Else placed in original dir. with simspecs.
logfile = logfile.replace(desisim.io.simdir(), args.outdir)

try:
os.makedirs(os.path.dirname(logfile), exist_ok=args.clobber)
except:
print('Pass --clobber to replace previously created logfile: {}.'.format(logfile))

#- Use subprocess.call instead of fastframe.main() to avoid
#- potential memory leaks and separate logging; this does incur
Expand Down Expand Up @@ -167,5 +192,4 @@ if rank == 0:
))

if comm is not None:
MPI.Finalize()

MPI.Finalize()