spacetelescope / jwst

Python library for science observations from the James Webb Space Telescope
https://jwst-pipeline.readthedocs.io/en/latest/
Other
558 stars 164 forks source link

Non-deterministic spec3 output names for NIRSpec FS #8257

Open stscijgbot-jp opened 7 months ago

stscijgbot-jp commented 7 months ago

Issue JP-3530 was created on JIRA by Melanie Clarke:

Manually running the spec3 pipeline for some s1600a1 data, Charles Proffitt noticed that the filenames were sometimes coming out

  spec3_recal_s00001_s1600a1_cal.fits

and sometimes 

  spec3_recal_s1600a1_s00001_cal.fits

That is, sometimes the source ID appears first in the filename, and sometimes the slit name appears first.  The source ID should always appear first.

stscijgbot-jp commented 7 months ago

Comment by Melanie Clarke on JIRA:

This appears to be caused by a small bug in the spec3 code. 

Around line 215 in jwst/pipeline/calwebb_spec3.py, there is a formatting call:   self.output_file = format_product(output_file, source_id=source_id.lower(), slit_name=slit_name)   As written, the formatter just appends the provided values in the order they are passed, which is undetermined.  Instead, it should be told explicitly where to place the values in the output string.   Something like this should work:   output_file_format = outputfile + '\{sourceid}\{slit_name}' self.output_file = format_product(output_file_format, source_id=source_id.lower(), slit_name=slit_name)  

stscijgbot-jp commented 7 months ago

Comment by Jonathan Eisenhamer on JIRA:

Not necessarily a bug. Often output_file will already have the formatting applied. This is true when run with a ground-system-generated association. The above, where it is blindly adding more formatting, will produce even stranger results in those cases.

Agreed that consistency in formatting would be a good thing. However the heuristic for that consistency should be implemented in format_product. A simple option for ordering unspecified components is to order them alphabetically; other options are obviously in play.

stscijgbot-jp commented 7 months ago

Comment by Melanie Clarke on JIRA:

Ah, I see!  So this likely only occurs with manually produced association files.

I agree it still would be nice to apply some sorting for consistency, but this is much less urgent than I imagined.

I'll let Charles know the workaround to add the formatting to the product name in the association file.