Repository: spacetelescope/jwql

Issue:
JWQL web app home page example query error
When submitting the example program number `86600` in the search field of the web app home page, an error is raised: 
<img width="1317" alt="screen shot 2019-02-27 at 15 48 59" src="https://user-images.githubusercontent.com/13909167/53521881-3d113c80-3aa7-11e9-9dc0-9269bb94c10e.png">



Discussion:
Thanks for opening an issue @Johannes-Sahlmann.  I suspect this has to do with the recent switch to an updated filesystem that I recently made (#292), and likely this will introduce some issues in various places.  
FYI, I switched the path to the `filesystem` back to what it was before #292.  Until we can figure out some of the issues associated with the updated filesystem, I will leave it there to avoid errors with the web app. 
Now that #315 is merged, the original error that @Johannes-Sahlmann reported appears to be solved, however there is a new error:

<img width="973" alt="screen shot 2019-03-04 at 16 15 48" src="https://user-images.githubusercontent.com/2250769/53763456-e33eb700-3e98-11e9-9fbf-564926f1d42c.png">

Weird stuff. I'll take a look!

Resolving patch:
diff --git a/jwql/utils/utils.py b/jwql/utils/utils.py
--- a/jwql/utils/utils.py
+++ b/jwql/utils/utils.py
@@ -35,7 +35,7 @@
 import re
 
 from jwql.utils import permissions
-from jwql.utils.constants import FILE_SUFFIX_TYPES
+from jwql.utils.constants import FILE_SUFFIX_TYPES, JWST_INSTRUMENT_NAMES_SHORTHAND
 
 __location__ = os.path.realpath(os.path.join(os.getcwd(), os.path.dirname(__file__)))
 
@@ -199,16 +199,32 @@ def filename_parser(filename):
 
         elements = re.compile(filename_type)
         jwst_file = elements.match(filename)
+
+        # Stop when you find a format that matches
         if jwst_file is not None:
             name_match = filename_type_name
             break
 
-    # Raise error if unable to parse the filename
     try:
+        # Convert the regex match to a dictionary
         filename_dict = jwst_file.groupdict()
+
+        # Add the filename type to that dict
         filename_dict['filename_type'] = name_match
+
+        # Also, add the instrument if not already there
+        if 'instrument' not in filename_dict.keys():
+            if name_match == 'guider':
+                filename_dict['instrument'] = 'fgs'
+            elif 'detector' in filename_dict.keys():
+                filename_dict['instrument'] = JWST_INSTRUMENT_NAMES_SHORTHAND[
+                    filename_dict['detector'][:3]
+                ]
+
+    # Raise error if unable to parse the filename
     except AttributeError:
-        jdox_url = 'https://jwst-docs.stsci.edu/display/JDAT/File+Naming+Conventions+and+Data+Products'
+        jdox_url = 'https://jwst-docs.stsci.edu/display/JDAT/' \
+                   'File+Naming+Conventions+and+Data+Products'
         raise ValueError('Provided file {} does not follow JWST naming conventions.  See {} for further information.'.format(filename, jdox_url))
 
     return filename_dict
diff --git a/jwql/website/apps/jwql/forms.py b/jwql/website/apps/jwql/forms.py
--- a/jwql/website/apps/jwql/forms.py
+++ b/jwql/website/apps/jwql/forms.py
@@ -100,13 +100,13 @@ def clean_search(self):
             if len(all_files) > 0:
                 all_instruments = []
                 for file in all_files:
-                    instrument = filename_parser(file)['detector']
-                    all_instruments.append(instrument[:3])
+                    instrument = filename_parser(file)['instrument']
+                    all_instruments.append(instrument)
                 if len(set(all_instruments)) > 1:
                     raise forms.ValidationError('Cannot return result for proposal with multiple '
                                                 'instruments.')
 
-                self.instrument = JWST_INSTRUMENT_NAMES_SHORTHAND[all_instruments[0]]
+                self.instrument = all_instruments[0]
             else:
                 raise forms.ValidationError('Proposal {} not in the filesystem.'.format(search))
 
@@ -211,7 +211,7 @@ class MnemonicQueryForm(forms.Form):
         delta_day = -7.
         range_day = 1.
         default_start_time = now + TimeDelta(delta_day, format='jd')
-        default_end_time = now + TimeDelta(delta_day+range_day, format='jd')
+        default_end_time = now + TimeDelta(delta_day + range_day, format='jd')
     else:
         # example for testing
         default_start_time = Time('2019-01-16 00:00:00.000', format='iso')


Test patch:
diff --git a/jwql/tests/test_utils.py b/jwql/tests/test_utils.py
--- a/jwql/tests/test_utils.py
+++ b/jwql/tests/test_utils.py
@@ -33,6 +33,7 @@
       'detector': 'nis',
       'exposure_id': '00001',
       'filename_type': 'stage_1_and_2',
+      'instrument': 'niriss',
       'observation': '001',
       'parallel_seq_id': '1',
       'program_id': '90002',
@@ -46,6 +47,7 @@
       'detector': 'nrca1',
       'exposure_id': '00002',
       'filename_type': 'stage_1_and_2',
+      'instrument': 'nircam',
       'observation': '001',
       'parallel_seq_id': '1',
       'program_id': '00327',
@@ -59,6 +61,7 @@
       'detector': 'nrca1',
       'exposure_id': '00002',
       'filename_type': 'stage_1_and_2',
+      'instrument': 'nircam',
       'observation': '001',
       'parallel_seq_id': '1',
       'program_id': '00327',
@@ -72,6 +75,7 @@
       'detector': 'mirimage',
       'exposure_id': '00001',
       'filename_type': 'stage_2c',
+      'instrument': 'miri',
       'observation': '002',
       'parallel_seq_id': '1',
       'program_id': '94015',
@@ -86,6 +90,7 @@
       'detector': 'nis',
       'exposure_id': '00001',
       'filename_type': 'stage_2c',
+      'instrument': 'niriss',
       'observation': '001',
       'parallel_seq_id': '1',
       'program_id': '90001',
@@ -168,6 +173,7 @@
       'detector': 'nrs1',
       'exposure_id': '00002',
       'filename_type': 'time_series',
+      'instrument': 'nirspec',
       'observation': '003',
       'parallel_seq_id': '1',
       'program_id': '00733',
@@ -182,6 +188,7 @@
       'detector': 'nrs1',
       'exposure_id': '00002',
       'filename_type': 'time_series',
+      'instrument': 'nirspec',
       'observation': '003',
       'parallel_seq_id': '1',
       'program_id': '00733',
@@ -195,6 +202,7 @@
       'filename_type': 'guider',
       'guide_star_attempt_id': '1',
       'guider_mode': 'id',
+      'instrument': 'fgs',
       'observation': '011',
       'program_id': '00729',
       'suffix': 'image_cal',
@@ -206,6 +214,7 @@
       'filename_type': 'guider',
       'guide_star_attempt_id': '2',
       'guider_mode': 'id',
+      'instrument': 'fgs',
       'observation': '001',
       'program_id': '00327',
       'visit': '001'}),
@@ -216,6 +225,7 @@
       'filename_type': 'guider',
       'guide_star_attempt_id': None,
       'guider_mode': 'fg',
+      'instrument': 'fgs',
       'observation': '048',
       'program_id': '86600',
       'suffix': 'stream',
@@ -227,6 +237,7 @@
       'filename_type': 'guider',
       'guide_star_attempt_id': None,
       'guider_mode': 'acq2',
+      'instrument': 'fgs',
       'observation': '011',
       'program_id': '00729',
       'visit': '001'})