Skip to content

Instantly share code, notes, and snippets.

@jhunkeler
Created April 14, 2018 22:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jhunkeler/f08783ca2da7bfd1f8e9ee1d207da5ff to your computer and use it in GitHub Desktop.
Save jhunkeler/f08783ca2da7bfd1f8e9ee1d207da5ff to your computer and use it in GitHub Desktop.
import re
elements = \
re.compile(r"[a-z]+"
"(?P<program_id>\d{5})"
"(?P<observation>\d{3})"
"(?P<visit>\d{3})"
"_(?P<visit_group>\d{2})"
"(?P<parallel_seq_id>\d{1})"
"(?P<activity>\d{2})"
"_(?P<exposure_id>\d+)"
"_(?P<detector>\w+)"
"_(?P<suffix>\w+).*")
filename = "jw94015001001_02102_00001_nrcb1_uncal.fits"
jwst_file = elements.match(filename)
if jwst_file is not None:
filename_dict = jwst_file.groupdict()
for key, value in filename_dict.items():
print('{:<15s} = {:s}'.format(key, value))
@jhunkeler
Copy link
Author

Output:

program_id      = 94015
observation     = 001
visit           = 001
visit_group     = 02
parallel_seq_id = 1
activity        = 02
exposure_id     = 00001
detector        = nrcb1
suffix          = uncal

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment