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

Exposure page: Default to show rate img, keep order of radio buttons constant #1111

Merged
5 changes: 5 additions & 0 deletions jwql/utils/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,11 @@
"pom": "NIS_IMAGE", "wfss": "NIS_WFSS"},
"fgs": {"imaging": "FGS_IMAGE"}}

EXPOSURE_PAGE_SUFFIX_ORDER = ['uncal', 'dark', 'trapsfilled', 'ramp', 'rate', 'rateints', 'fitopt', 'cal', 'calints',
'msa', 'crf', 'crfints', 'bsub', 'bsubints', 'i2d', 's2d', 's3d', 'x1d', 'x1dints',
'cat', 'segm', 'c1d', 'psfstack', 'psfalign', 'psfsub', 'amiavg', 'aminorm', 'ami',
'psf-amiavg', 'phot', 'whtlt', 'wfscmb']

# Filename Component Lengths
FILE_AC_CAR_ID_LEN = 4
FILE_AC_O_ID_LEN = 3
Expand Down
8 changes: 4 additions & 4 deletions jwql/website/apps/jwql/templates/view_image.html
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ <h3>{{ file_root }}</h3>
{% if index != 0 %}
<a role="button" class="btn btn-primary my-2" type="submit" href="{{ base_url }}/{{ inst }}/{{ file_root_list[obsnum][index-1] }}/" style="float: left;">< Previous</a>
{% endif %}

{% if index != file_root_list[obsnum]|length - 1 %}
<a role="button" class="btn btn-primary my-2" type="submit" href="{{ base_url }}/{{ inst }}/{{ file_root_list[obsnum][index+1] }}/" style="float: right;">Next ></a>
{% endif %}
Expand Down Expand Up @@ -115,10 +115,10 @@ <h5>Submit Anomaly</h5>
<script>update_viewed_button(false)</script>
{% endif %}
<!-- Determine which filetype should be shown on load -->
{% if 'cal' in suffixes %}
<script>change_filetype('cal', '{{file_root}}', '{{num_ints}}', "{{available_ints}}", "{{total_ints}}", '{{inst}}');</script>
{% elif 'rate' in suffixes %}
{% if 'rate' in suffixes %}
<script>change_filetype('rate', '{{file_root}}', '{{num_ints}}', "{{available_ints}}", "{{total_ints}}", '{{inst}}');</script>
{% elif 'dark' in suffixes %}
<script>change_filetype('dark', '{{file_root}}', '{{num_ints}}', "{{available_ints}}", "{{total_ints}}", '{{inst}}');</script>
{% elif 'uncal' in suffixes %}
<script>change_filetype('uncal', '{{file_root}}', '{{num_ints}}', "{{available_ints}}", "{{total_ints}}", '{{inst}}');</script>
{% elif suffixes|length == 1 %}
Expand Down
60 changes: 56 additions & 4 deletions jwql/website/apps/jwql/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,21 @@
"""

from collections import defaultdict
from copy import deepcopy
import csv
import logging
import os

from bokeh.layouts import layout
from bokeh.embed import components
from django.http import HttpResponse, JsonResponse
from django.shortcuts import redirect, render
import numpy as np

from jwql.database.database_interface import load_connection
from jwql.utils import anomaly_query_config
from jwql.utils import anomaly_query_config, monitor_utils
from jwql.utils.interactive_preview_image import InteractivePreviewImg
from jwql.utils.constants import JWST_INSTRUMENT_NAMES_MIXEDCASE, MONITORS, URL_DICT, THUMBNAIL_FILTER_LOOK
from jwql.utils.constants import EXPOSURE_PAGE_SUFFIX_ORDER, JWST_INSTRUMENT_NAMES_MIXEDCASE, MONITORS, URL_DICT, THUMBNAIL_FILTER_LOOK
from jwql.utils.utils import filename_parser, get_base_url, get_config, get_rootnames_for_instrument_proposal, query_unformat

from .data_containers import build_table
Expand Down Expand Up @@ -924,6 +927,55 @@ def view_image(request, inst, file_root, rewrite=False):
template = 'view_image.html'
image_info = get_image_info(file_root, rewrite)

# Put suffixes in a consistent order. Check if any of the
# suffixes are not in the list that specifies order.
# Reorder the list of filenames to match the reordered list
# of suffixes.
suffixes = []
all_files = []
untracked_suffixes = deepcopy(image_info['suffixes'])
untracked_files = deepcopy(image_info['all_files'])
for poss_suffix in EXPOSURE_PAGE_SUFFIX_ORDER:
if 'crf' not in poss_suffix:
if poss_suffix in image_info['suffixes']:
suffixes.append(poss_suffix)
loc = image_info['suffixes'].index(poss_suffix)
all_files.append(image_info['all_files'][loc])
untracked_suffixes.remove(poss_suffix)
untracked_files.remove(image_info['all_files'][loc])
else:
# EXPOSURE_PAGE_SUFFIX_ORDER contains crf and crfints, but the actual suffixes
# in the data will be e.g. o001_crf, and there may be more than one crf file
# in the list of suffixes. So in this case, we strip the e.g. o001 from the
# suffixes and check which list elements match.
suff_arr = np.array(image_info['suffixes'])
files_arr = np.array(image_info['all_files'])
splits = np.array([ele.split('_')[-1] for ele in image_info['suffixes']])
idxs = np.where(splits == poss_suffix)[0]
if len(idxs) > 0:
suff_entries = list(suff_arr[idxs])
file_entries = list(files_arr[idxs])
suffixes.extend(suff_entries)
all_files.extend(file_entries)

untracked_splits = np.array([ele.split('_')[-1] for ele in untracked_suffixes])
untracked_idxs = np.where(untracked_splits == poss_suffix)[0]
untracked_suffixes = list(np.delete(untracked_suffixes, untracked_idxs))
untracked_files = list(np.delete(untracked_files, untracked_idxs))

# If the data contain any suffixes that are not in the list that specifies the order
# to use, make a note in the log (so that they can be added to EXPOSURE_PAGE_SUFFIX_ORDER)
# later. Then add them to the end of the suffixes list. Their order will be random since
# they are not in EXPOSURE_PAGE_SUFFIX_ORDER.
if len(untracked_suffixes) > 0:
module = os.path.basename(__file__).strip('.py')
start_time, log_file = monitor_utils.initialize_instrument_monitor(module)
logging.warning((f'In view_image(), for {inst}, {file_root}, the following suffixes are present in the data, '
f'but not in EXPOSURE_PAGE_SUFFIX_ORDER in constants.py: {untracked_suffixes} '
'Please add them, so that they will appear in a consistent order on the webpage.'))
suffixes.extend(untracked_suffixes)
all_files.extend(untracked_files)

form = get_anomaly_form(request, inst, file_root)

prop_id = file_root[2:7]
Expand Down Expand Up @@ -954,8 +1006,8 @@ def view_image(request, inst, file_root, rewrite=False):
'obsnum': file_root[7:10],
'file_root': file_root,
'jpg_files': image_info['all_jpegs'],
'fits_files': image_info['all_files'],
'suffixes': image_info['suffixes'],
'fits_files': all_files,
'suffixes': suffixes,
'num_ints': image_info['num_ints'],
'available_ints': image_info['available_ints'],
'total_ints': image_info['total_ints'],
Expand Down