Repository: spacetelescope/jwql

Issue:
File does not match filename conventions
In the latest run of generate_preview_images, the filename parser crashed with:

ValueError: Provided file jw01141001001_gs-id_12_stacked_uncal.fits does not follow JWST naming conventions.

The filename parser is being used to identify guide star observations, which are then skipped by geneerate_preview_images.


Discussion:
The filename parser is failing because of the "12" in the filename. It currently uses FILE_GUIDESTAR_ATTMPT_LEN from constants.py to define the length of that string, and that value is currently set to 1.

Resolving patch:
diff --git a/jwql/utils/constants.py b/jwql/utils/constants.py
--- a/jwql/utils/constants.py
+++ b/jwql/utils/constants.py
@@ -176,7 +176,8 @@
 FILE_ACT_LEN = 2
 FILE_DATETIME_LEN = 13
 FILE_EPOCH_LEN = 1
-FILE_GUIDESTAR_ATTMPT_LEN = 1
+FILE_GUIDESTAR_ATTMPT_LEN_MIN = 1
+FILE_GUIDESTAR_ATTMPT_LEN_MAX = 3
 FILE_OBS_LEN = 3
 FILE_PARALLEL_SEQ_ID_LEN = 1
 FILE_PROG_ID_LEN = 5
diff --git a/jwql/utils/utils.py b/jwql/utils/utils.py
--- a/jwql/utils/utils.py
+++ b/jwql/utils/utils.py
@@ -38,10 +38,10 @@
 
 from jwql.utils import permissions
 from jwql.utils.constants import FILE_AC_CAR_ID_LEN, FILE_AC_O_ID_LEN, FILE_ACT_LEN, \
-                                 FILE_DATETIME_LEN, FILE_EPOCH_LEN, FILE_GUIDESTAR_ATTMPT_LEN, \
-                                 FILE_OBS_LEN, FILE_PARALLEL_SEQ_ID_LEN, FILE_PROG_ID_LEN, \
-                                 FILE_SEG_LEN, FILE_SOURCE_ID_LEN, FILE_SUFFIX_TYPES, FILE_TARG_ID_LEN, \
-                                 FILE_VISIT_GRP_LEN, FILE_VISIT_LEN, FILETYPE_WO_STANDARD_SUFFIX, \
+                                 FILE_DATETIME_LEN, FILE_EPOCH_LEN, FILE_GUIDESTAR_ATTMPT_LEN_MIN, \
+                                 FILE_GUIDESTAR_ATTMPT_LEN_MAX, FILE_OBS_LEN, FILE_PARALLEL_SEQ_ID_LEN, \
+                                 FILE_PROG_ID_LEN, FILE_SEG_LEN, FILE_SOURCE_ID_LEN, FILE_SUFFIX_TYPES, \
+                                 FILE_TARG_ID_LEN, FILE_VISIT_GRP_LEN, FILE_VISIT_LEN, FILETYPE_WO_STANDARD_SUFFIX, \
                                  JWST_INSTRUMENT_NAMES_SHORTHAND
 
 __location__ = os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
@@ -380,7 +380,7 @@ def filename_parser(filename):
         r"(?P<observation>\d{" + f"{FILE_OBS_LEN}" + "})" \
         r"(?P<visit>\d{" + f"{FILE_VISIT_LEN}" + "})" \
         r"_gs-(?P<guider_mode>(id|acq1|acq2|track|fg))" \
-        r"_((?P<date_time>\d{" + f"{FILE_DATETIME_LEN}" + r"})|(?P<guide_star_attempt_id>\d{" + f"{FILE_GUIDESTAR_ATTMPT_LEN}" + "}))"
+        r"_((?P<date_time>\d{" + f"{FILE_DATETIME_LEN}" + r"})|(?P<guide_star_attempt_id>\d{" + f"{FILE_GUIDESTAR_ATTMPT_LEN_MIN},{FILE_GUIDESTAR_ATTMPT_LEN_MAX}" + "}))"
 
     # Segment guider filenames
     # e.g. "jw01118005001_gs-fg_2022150070312-seg002_uncal.fits"
@@ -390,7 +390,7 @@ def filename_parser(filename):
         r"(?P<observation>\d{" + f"{FILE_OBS_LEN}" + "})" \
         r"(?P<visit>\d{" + f"{FILE_VISIT_LEN}" + "})" \
         r"_gs-(?P<guider_mode>(id|acq1|acq2|track|fg))" \
-        r"_((?P<date_time>\d{" + f"{FILE_DATETIME_LEN}" + r"})|(?P<guide_star_attempt_id>\d{" + f"{FILE_GUIDESTAR_ATTMPT_LEN}" + "}))" \
+        r"_((?P<date_time>\d{" + f"{FILE_DATETIME_LEN}" + r"})|(?P<guide_star_attempt_id>\d{" + f"{FILE_GUIDESTAR_ATTMPT_LEN_MIN},{FILE_GUIDESTAR_ATTMPT_LEN_MAX}" + "}))" \
         r"-seg(?P<segment>\d{" + f"{FILE_SEG_LEN}" + "})"
 
     # Build list of filename types


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
@@ -220,6 +220,18 @@
       'suffix': 'image_cal',
       'visit': '001'}),
 
+    # Test full guider ID filename with 2-digit attempts
+    ('jw00729011001_gs-id_12_image_cal.fits',
+     {'date_time': None,
+      'filename_type': 'guider',
+      'guide_star_attempt_id': '12',
+      'guider_mode': 'id',
+      'instrument': 'fgs',
+      'observation': '011',
+      'program_id': '00729',
+      'suffix': 'image_cal',
+      'visit': '001'}),
+
     # Test root guider ID filename
     ('jw00327001001_gs-id_2',
      {'date_time': None,
@@ -231,6 +243,17 @@
       'program_id': '00327',
       'visit': '001'}),
 
+    # Test root guider ID filename with 2-digit attempts
+    ('jw00327001001_gs-id_12',
+     {'date_time': None,
+      'filename_type': 'guider',
+      'guide_star_attempt_id': '12',
+      'guider_mode': 'id',
+      'instrument': 'fgs',
+      'observation': '001',
+      'program_id': '00327',
+      'visit': '001'}),
+
     # Test full guider non-ID filename
     ('jw86600048001_gs-fg_2016018175411_stream.fits',
      {'date_time': '2016018175411',