Repository: spacetelescope/jwql

Issue:
Dark Monitor webpages not working for FGS, MIRI, NIRSpec, and NIRISS
I tried enabling the dark monitor for all instruments on the web app as part of #863, since theoretically the dark monitor should support all instruments.  The monitor webpages are only working for NIRCam.  

For FGS (https://jwql.stsci.edu/fgs/dark_monitor/) we see this traceback:

```
Traceback (most recent call last):
  File "envs/jwql-3.7/lib/python3.7/site-packages/django/core/handlers/exception.py", line 47, in inner
    response = get_response(request)
  File "envs/jwql-3.7/lib/python3.7/site-packages/django/core/handlers/base.py", line 181, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "jwql/website/apps/jwql/monitor_views.py", line 125, in dark_monitor
    tabs_components = bokeh_containers.dark_monitor_tabs(inst)
  File "/jwql/website/apps/jwql/bokeh_containers.py", line 241, in dark_monitor_tabs
    histogram_layout.sizing_mode = "scale_width"  # Make sure the sizing is adjustable

Exception Type: UnboundLocalError at /fgs/dark_monitor/
Exception Value: local variable 'histogram_layout' referenced before assignment
```

For NIRISS, NIRSpec, and MIRI we get this traceback:

```
Traceback (most recent call last):
  File "envs/jwql-3.7/lib/python3.7/site-packages/django/core/handlers/exception.py", line 47, in inner
    response = get_response(request)
  File "envs/jwql-3.7/lib/python3.7/site-packages/django/core/handlers/base.py", line 181, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "jwql/website/apps/jwql/monitor_views.py", line 125, in dark_monitor
    tabs_components = bokeh_containers.dark_monitor_tabs(inst)
  File "jwql/website/apps/jwql/bokeh_containers.py", line 279, in dark_monitor_tabs
    image = templates_all_apertures['NRCA3_FULL'].refs["mean_dark_image_figure"]

Exception Type: KeyError at /nirspec/dark_monitor/
Exception Value: 'NRCA3_FULL'
```


Discussion:

Resolving patch:
diff --git a/jwql/utils/constants.py b/jwql/utils/constants.py
--- a/jwql/utils/constants.py
+++ b/jwql/utils/constants.py
@@ -260,8 +260,8 @@
 MONITORS = {
     'fgs': [('Bad Pixel Monitor', '/fgs/bad_pixel_monitor'),
             ('Readnoise Monitor', '/fgs/readnoise_monitor'),
-            ('Dark Current Monitor', '#')],
-    'miri': [('Dark Current Monitor', '#'),
+            ('Dark Current Monitor', '/fgs/dark_monitor')],
+    'miri': [('Dark Current Monitor', '/miri/dark_monitor'),
              ('Data Trending', '#'),
              ('Bad Pixel Monitor', '/miri/bad_pixel_monitor'),
              ('Readnoise Monitor', '/miri/readnoise_monitor'),
@@ -282,7 +282,7 @@
                ('AMI Calibrator Monitor', '#'),
                ('TSO RMS Monitor', '#'),
                ('Bias Monitor', '/niriss/bias_monitor'),
-               ('Dark Current Monitor', '#')],
+               ('Dark Current Monitor', '/niriss/dark_monitor')],
     'nirspec': [('Optical Short Monitor', '#'),
                 ('Bad Pixel Monitor', '/nirspec/bad_pixel_monitor'),
                 ('Readnoise Monitor', '/nirspec/readnoise_monitor'),
@@ -294,7 +294,7 @@
                 ('Instrument Model Updates', '#'),
                 ('Failed-open Shutter Monitor', '#'),
                 ('Bias Monitor', '/nirspec/bias_monitor'),
-                ('Dark Monitor', '#')]}
+                ('Dark Monitor', '/nirspec/dark_monitor')]}
 
 # Possible suffix types for coronograph exposures
 NIRCAM_CORONAGRAPHY_SUFFIX_TYPES = ['psfstack', 'psfalign', 'psfsub']
diff --git a/jwql/website/apps/jwql/bokeh_containers.py b/jwql/website/apps/jwql/bokeh_containers.py
--- a/jwql/website/apps/jwql/bokeh_containers.py
+++ b/jwql/website/apps/jwql/bokeh_containers.py
@@ -232,7 +232,7 @@ def dark_monitor_tabs(instrument):
             [single_aperture]
         )
 
-    elif instrument == 'NIRSpec':
+    elif instrument in ['NIRSpec', 'FGS']:
         d1, d2 = histograms_all_apertures
         histogram_layout = layout(
             [d1, d2]
@@ -264,7 +264,7 @@ def dark_monitor_tabs(instrument):
             [single_aperture]
         )
 
-    elif instrument == 'NIRSpec':
+    elif instrument in ['NIRSpec', 'FGS']:
         d1, d2 = lines_all_apertures
         line_layout = layout(
             [d1, d2]
@@ -276,7 +276,7 @@ def dark_monitor_tabs(instrument):
     # Mean dark image tab
 
     # The three lines below work for displaying a single image
-    image = templates_all_apertures['NRCA3_FULL'].refs["mean_dark_image_figure"]
+    image = templates_all_apertures[full_apertures[0]].refs["mean_dark_image_figure"]
     image.sizing_mode = "scale_width"  # Make sure the sizing is adjustable
     image_layout = layout(image)
     image.height = 250  # Not working


Test patch: