Skip to content

Commit

Permalink
Add logging messages in calling functions
Browse files Browse the repository at this point in the history
  • Loading branch information
bhilbert4 committed Aug 20, 2024
1 parent 76cfbc5 commit c371d5c
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 21 deletions.
20 changes: 14 additions & 6 deletions jwql/jwql_monitors/generate_preview_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,8 @@ def check_existence(file_list, outdir):

# If filename_parser() does not recognize the filename, return False
if not file_parts['recognized_filename']:
logging.warning((f'While running checking_existence() for a preview image for {file_list[0]}, '
'filename_parser() failed to recognize the file pattern.'))
return False

if file_parts['detector'].upper() in NIRCAM_SHORTWAVE_DETECTORS:
Expand Down Expand Up @@ -258,10 +260,13 @@ def create_dummy_filename(filelist):
modules = []
for filename in filelist:
indir, infile = os.path.split(filename)
try:
det_string = filename_parser(infile)['detector']
except KeyError:
parsed_filename = filename_parser(infile)
if parsed_filename['recognized_filename']:
det_string = parsed_filename['detector']
else:
# If filename_parser() does not recognize the file, skip it
logging.warning((f'While using {infile} to create a dummy filename in create_dummy_filename(), the '
'filename parser failed.'))
continue
det_string_list.append(det_string)
modules.append(det_string[3].upper())
Expand Down Expand Up @@ -316,10 +321,13 @@ def create_mosaic(filenames):
else:
diff_im = image.data
data.append(diff_im)
try:
detector.append(filename_parser(filename)['detector'].upper())
except KeyError:
file_info = filename_parser(filename)
if file_info['recognized_filename']:
detector.append(file_info['detector'].upper())
else:
# If filename_parser() does not recognize the file, skip it.
logging.warning((f'While running create_mosaic() using {file_list[0]}, '
'filename_parser() failed to recognize the file pattern.'))
pass
data_lower_left.append((image.xstart, image.ystart))

Expand Down
2 changes: 2 additions & 0 deletions jwql/jwql_monitors/monitor_filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ def gather_statistics(general_results_dict, instrument_results_dict):
if filename_dict['recognized_filename']:
filename_type = filename_dict['filename_type']
else:
logging.warning((f'While running gather_statistics() on the filesystem {filename}, '
'caused filename_parser() to fail.'))
break

# For MSA files, which do not have traditional suffixes, set the
Expand Down
2 changes: 1 addition & 1 deletion jwql/utils/monitor_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def monitor_template_main():
'jw{}{}{}'.format(filename_dict['program_id'], filename_dict['observation'], filename_dict['visit']),
filename_of_interest)
else:
raise KeyError(f'Filename {filename_of_interest} not recognized by filename_parser()')
raise KeyError(f'Filename {filename_of_interest} not recognized by filename_parser() in monitor_template_main')

# Example of reading in dataset using jwst.datamodels
im = datamodels.open(dataset)
Expand Down
2 changes: 2 additions & 0 deletions jwql/website/apps/jwql/archive_database_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ def get_updates(update_database):
if 'stage_3' not in filename_dict['filename_type']:
rootnames.append(rootname)
else:
logging.warning((f'While running get_updates() to update the RootfileInfo tables, {rootname}, '
'was not recognized by the filename_parser().'))
pass

if len(filenames) > 0:
Expand Down
42 changes: 28 additions & 14 deletions jwql/website/apps/jwql/data_containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1434,6 +1434,8 @@ def get_image_info(file_root):
suffix = parsed_fn['suffix']
else:
# If the filename parser does not recognize the file, skip it
logging.warning((f'While running get_image_info() on {filename}, the '
'filename_parser() failed to recognize the file pattern.'))
continue

# For crf or crfints suffixes, we need to also include the association value
Expand Down Expand Up @@ -1716,11 +1718,14 @@ def get_proposal_info(filepaths):

obsnums = []
for fname in files_for_proposal:
try:
obs = filename_parser(fname)['observation']
file_info = filename_parser(fname)
if file_info['recognized_filename']:
obs = file_info['observation']
obsnums.append(obs)
except KeyError:
pass
else:
logging.warning((f'While running get_proposal_info() for a program {proposal}, {fname} '
'was not recognized by the filename_parser().'))

obsnums = sorted(obsnums)
observations.extend(obsnums)
num_files.append(len(files_for_proposal))
Expand Down Expand Up @@ -2156,10 +2161,13 @@ def thumbnails_ajax(inst, proposal, obs_num=None):
# Wrap in try/except because level 3 rootnames won't have an observation
# number returned by the filename_parser. That's fine, we're not interested
# in those files anyway.
try:
all_obs.append(filename_parser(root)['observation'])
except KeyError:
pass
file_info = filename_parser(root)
if file_info['recognized_filename']:
all_obs.append(file_info['observation'])
else:
logging.warning((f'While running thumbnails_ajax() on root {root}, '
'filename_parser() failed to recognize the file pattern.'))

obs_list = sorted(list(set(all_obs)))

# Get the available files for the instrument
Expand All @@ -2179,14 +2187,13 @@ def thumbnails_ajax(inst, proposal, obs_num=None):
for rootname in rootnames:

# Parse filename
try:
filename_dict = filename_parser(rootname)

filename_dict = filename_parser(rootname)
if filename_dict['recognized_filename']:
# Weed out file types that are not supported by generate_preview_images
if 'stage_3' in filename_dict['filename_type']:
continue

except ValueError:
else:
# Temporary workaround for noncompliant files in filesystem
filename_dict = {'activity': rootname[17:19],
'detector': rootname[26:],
Expand All @@ -2197,6 +2204,8 @@ def thumbnails_ajax(inst, proposal, obs_num=None):
'visit': rootname[10:13],
'visit_group': rootname[14:16],
'group_root': rootname[:26]}
logging.warning((f'While running thumbnails_ajax() on rootname {rootname}, '
'filename_parser() failed to recognize the file pattern.'))

# Get list of available filenames and exposure start times. All files with a given
# rootname will have the same exposure start time, so just keep the first.
Expand Down Expand Up @@ -2343,6 +2352,8 @@ def thumbnails_query_ajax(rootnames):
# Add to list of all exposure groups
exp_groups.add(filename_dict['group_root'])
else:
logging.warning((f'While running thumbnails_query_ajax() on rootname {rootname}, '
'filename_parser() failed to recognize the file pattern.'))
continue

try:
Expand Down Expand Up @@ -2373,10 +2384,13 @@ def thumbnails_query_ajax(rootnames):
data_dict['file_data'][rootname]['pupil'] = pupil_type
data_dict['file_data'][rootname]['grating'] = grating_type
for filename in available_files:
suffix = filename_parser(filename)['suffix']
if suffix['recognized_filename']:
file_info = filename_parser(filename)
if file_info['recognized_filename']:
suffix = file_info['suffix']
data_dict['file_data'][rootname]['suffixes'].append(suffix)
else:
logging.warning((f'While running thumbnails_query_ajax() on filename {filename}, '
'filename_parser() failed to recognize the file pattern.'))
continue

data_dict['file_data'][rootname]['thumbnail'] = get_thumbnail_by_rootname(rootname)
Expand Down
2 changes: 2 additions & 0 deletions jwql/website/apps/jwql/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,8 @@ def clean_search(self):
all_observations[instrument].append(observation)
else:
# If the filename is not recognized by filename_parser(), skip it.
logging.warning((f'While running FileSearchForm.clean_search() on {file}, '
'filename_parser() failed to recognize the file pattern.'))
continue

# sort lists so first observation is available when link is clicked.
Expand Down

0 comments on commit c371d5c

Please sign in to comment.