Skip to content

Commit

Permalink
bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
akremin committed Mar 10, 2023
1 parent ae81028 commit 387db5c
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 18 deletions.
9 changes: 6 additions & 3 deletions py/desispec/io/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -578,9 +578,12 @@ def camword_union(camwords, full_spectros_only=False):
camword = ''
if np.isscalar(camwords):
if not isinstance(camwords, str):
ValueError(f"camwords must be array-like or str. Received type: {type(camwords)}")
raise ValueError(f"camwords must be array-like or str. Received type: {type(camwords)}")
else:
camword = camwords
elif len(camwords) == 0:
raise ValueError("camwords must be nonzero length array-like or str:"
+ f"camwords={camwords}, type={type(camwords)}, len={len(camwords)}")
else:
cams = set(decode_camword(camwords[0]))
for camword in camwords[1:]:
Expand Down Expand Up @@ -720,7 +723,7 @@ def camword_to_spectros(camword, full_spectros_only=False):
spectros.add(int(char))
elif full_spectros_only and char in ['b','r','z']:
break
return list(spectros)
return sorted(spectros)

def spectros_to_camword(spectros):
"""
Expand All @@ -737,7 +740,7 @@ def spectros_to_camword(spectros):
spectros = sorted(spectros)
camword = "a" + "".join(str(sp) for sp in spectros)
check = camword_to_spectros(camword)
assert sorted(spectros) == check
assert spectros == check

return camword

Expand Down
48 changes: 34 additions & 14 deletions py/desispec/scripts/zprocdashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,13 +223,13 @@ def populate_night_zinfo(night, doem=True, doqso=True, dotileqa=True,
webpage = os.environ['DESI_DASHBOARD']
logpath = os.path.join(specproddir, 'run', 'scripts', 'tiles')

exptab, proctab, \
orig_exptab, proctab, \
unaccounted_for_expids,\
unaccounted_for_tileids = get_tables(night, check_on_disk=check_on_disk,
exptab_colnames=None)

exptab = exptab[((exptab['OBSTYPE'] == 'science')
& (exptab['LASTSTEP'] == 'all'))]
exptab = orig_exptab[((orig_exptab['OBSTYPE'] == 'science')
& (orig_exptab['LASTSTEP'] == 'all'))]

if proctab is None:
if len(exptab) == 0:
Expand Down Expand Up @@ -302,6 +302,33 @@ def populate_night_zinfo(night, doem=True, doqso=True, dotileqa=True,
ztype = str(row['JOBDESC'])
tileid = str(row['TILEID'])

zfild_expid = str(row['EXPID'][0]).zfill(8)
## files and dashboard are per night so these are unique without night
## in the key
if ztype == 'perexp':
unique_key = f'{zfild_expid}_{ztype}'
else:
unique_key = f'{tileid}_{ztype}'

## For those already marked as GOOD or NULL in cached rows, take that and move on
if night_json_zinfo is not None and unique_key in night_json_zinfo \
and night_json_zinfo[unique_key]["COLOR"] in ['GOOD', 'NULL']:
output[unique_key] = night_json_zinfo[unique_key]
continue

tilematches = exptab[exptab['TILEID'] == int(tileid)]
if len(tilematches) == 0:
if int(tileid) not in orig_exptab['TILEID']:
print(f"ERROR: Tile {tileid} found in processing table not present "
+ f"in exposure table.")
print(f"\texptab tileids: {np.unique(orig_exptab['TILEID'].data)}!")
print(f"\tproctab tileids: {np.unique(proctab['TILEID'].data)}!")
else:
print(f"WARNING: Tile {tileid} found in processing table no valid "
+ f"exposures still exist in the exposure table. Skipping this tile.")
continue
exptab_row = tilematches[0]

## Assign or derive proccamword and nspectros
if ztype == 'cumulative':
spectros = set()
Expand All @@ -328,18 +355,15 @@ def populate_night_zinfo(night, doem=True, doqso=True, dotileqa=True,
else:
proccamword = row['PROCCAMWORD']
spectros = camword_to_spectros(proccamword, full_spectros_only=True)

nspecs = len(spectros)

zfild_expid = str(row['EXPID'][0]).zfill(8)
## files and dashboard are per night so these are unique without night
## in the key
if ztype == 'perexp':
unique_key = f'{zfild_expid}_{ztype}'
logfiletemplate = os.path.join(logpath, '{ztype}', '{tileid}',
'ztile-{tileid}-{zexpid}{jobid}.{ext}')
else:
unique_key = f'{tileid}_{ztype}'
if ztype =='cumulative':
logfiletemplate = os.path.join(logpath, '{ztype}', '{tileid}',
'ztile-{tileid}-thru{night}{jobid}.{ext}')
Expand All @@ -348,12 +372,6 @@ def populate_night_zinfo(night, doem=True, doqso=True, dotileqa=True,
logfiletemplate = os.path.join(logpath, '{ztype}', '{tileid}',
'ztile-{tileid}-{night}{jobid}.{ext}')

## For those already marked as GOOD or NULL in cached rows, take that and move on
if night_json_zinfo is not None and unique_key in night_json_zinfo \
and night_json_zinfo[unique_key]["COLOR"] in ['GOOD', 'NULL']:
output[unique_key] = night_json_zinfo[unique_key]
continue

succinct_expid = ''
if len(row['EXPID']) == 1:
succinct_expid = str(row['EXPID'][0])
Expand All @@ -377,7 +395,9 @@ def populate_night_zinfo(night, doem=True, doqso=True, dotileqa=True,
tilematches = exptab[exptab['TILEID'] == int(tileid)]
if len(tilematches) == 0:
print(f"ERROR: Tile {tileid} found in processing table not present "
+ f"in exposure table: {np.unique(exptab['TILEID'])}!")
+ f"in exposure table.")
print(f"\texptab tileids: {np.unique(exptab['TILEID'].data)}!")
print(f"\tproctab tileids: {np.unique(proctab['TILEID'].data)}!")
continue
exptab_row = tilematches[0]
#exptime = np.round(exptab_row['EXPTIME'], decimals=1)
Expand Down
2 changes: 1 addition & 1 deletion py/desispec/workflow/proc_dashboard_funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ def write_json(output_data, filename_json):
## write out the night_info to json file
with open(filename_json, 'w') as json_file:
try:
json.dump(output_data, json_file)
json.dump(output_data, json_file, indent='\t')
except:
print(f"Error trying to dump {filename_json}, "
+ "not saving that information.")
Expand Down

0 comments on commit 387db5c

Please sign in to comment.