Repository: spacetelescope/jwql

Issue:
Header display inconsistencies
While working on #664 I found what looks to be some inconsistencies/problems with the header display code. Currently, it looks like the header from the rate.fits file is displayed, regardless of the filetype chosen by the radio buttons.

In urls.py, the URL for the header display is given as:
/instrument/filename/header/

However, the change_filetype function in jwql.js specifies that:
fits_filename = file_root + '_' + type, where type is a suffix like rate, uncal, etc
It then sets the URL for viewing the header as:
'/' + inst + '/' + fits_filename + '/header/'
implying that the filename suffix is part of the URL.

The actual URL when looking at a header though is e.g. /FGS/jw86600008001_02101_00010_guider2/header/
so there is no suffix there (aka 'type' in the change_filetype function).

In view_image.html, when setting up the radio buttons for the different types of files, it is calling the change_filetype function and providing the suffix (e.g. rateints), so I would expect the resulting URL to be /FGS/jw86600008001_02101_00010_guider2_rateints/header/


Discussion:
Thanks for the nice description here @bhilbert4.  We will try to take care of this for the `v1.1` release. 

Resolving patch:
diff --git a/jwql/website/apps/jwql/data_containers.py b/jwql/website/apps/jwql/data_containers.py
--- a/jwql/website/apps/jwql/data_containers.py
+++ b/jwql/website/apps/jwql/data_containers.py
@@ -568,7 +568,7 @@ def get_filenames_by_rootname(rootname):
     return filenames
 
 
-def get_header_info(filename):
+def get_header_info(filename, filetype):
     """Return the header information for a given ``filename``.
 
     Parameters
@@ -576,6 +576,8 @@ def get_header_info(filename):
     filename : str
         The name of the file of interest, without the extension
         (e.g. ``'jw86600008001_02101_00007_guider2_uncal'``).
+    filetype : str
+        The type of the file of interest, (e.g. ``'uncal'``)
 
     Returns
     -------
@@ -587,7 +589,7 @@ def get_header_info(filename):
     header_info = {}
 
     # Open the file
-    fits_filepath = filesystem_path(filename, search='*_rate.fits')
+    fits_filepath = filesystem_path(filename, search=f'*_{filetype}.fits')
     hdulist = fits.open(fits_filepath)
 
     # Extract header information from file
diff --git a/jwql/website/apps/jwql/urls.py b/jwql/website/apps/jwql/urls.py
--- a/jwql/website/apps/jwql/urls.py
+++ b/jwql/website/apps/jwql/urls.py
@@ -82,7 +82,7 @@
     re_path(r'^(?P<inst>({}))/archive/$'.format(instruments), views.archived_proposals, name='archive'),
     re_path(r'^(?P<inst>({}))/unlooked/$'.format(instruments), views.unlooked_images, name='unlooked'),
     re_path(r'^(?P<inst>({}))/(?P<file_root>[\w]+)/$'.format(instruments), views.view_image, name='view_image'),
-    re_path(r'^(?P<inst>({}))/(?P<filename>.+)/header/$'.format(instruments), views.view_header, name='view_header'),
+    re_path(r'^(?P<inst>({}))/(?P<filename>.+)_(?P<filetype>.+)/header/'.format(instruments), views.view_header, name='view_header'),
     re_path(r'^(?P<inst>({}))/archive/(?P<proposal>[\d]{{1,5}})/$'.format(instruments), views.archive_thumbnails, name='archive_thumb'),
 
     # AJAX views
diff --git a/jwql/website/apps/jwql/views.py b/jwql/website/apps/jwql/views.py
--- a/jwql/website/apps/jwql/views.py
+++ b/jwql/website/apps/jwql/views.py
@@ -687,7 +687,7 @@ def unlooked_images(request, inst):
     pass
 
 
-def view_header(request, inst, filename):
+def view_header(request, inst, filename, filetype):
     """Generate the header view page
 
     Parameters
@@ -698,12 +698,15 @@ def view_header(request, inst, filename):
         Name of JWST instrument
     filename : str
         FITS filename of selected image in filesystem
+    filetype : str
+        Type of file (e.g. ``uncal``)
 
     Returns
     -------
     HttpResponse object
         Outgoing response sent to the webpage
     """
+
     # Ensure the instrument is correctly capitalized
     inst = JWST_INSTRUMENT_NAMES_MIXEDCASE[inst.lower()]
 
@@ -713,7 +716,8 @@ def view_header(request, inst, filename):
     context = {'inst': inst,
                'filename': filename,
                'file_root': file_root,
-               'header_info': get_header_info(filename)}
+               'file_type': filetype,
+               'header_info': get_header_info(filename, filetype)}
 
     return render(request, template, context)
 


Test patch: