Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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