Avoid silent overwrite of existing spectrum/SRM FITS files#249
Conversation
…void silent overwrite Agent-Logs-Url: https://github.com/i4Ds/STIX-GSW/sessions/678aa8dc-f761-4c9a-9f08-e898b2c36990 Co-authored-by: ennosigaeus <649330+ennosigaeus@users.noreply.github.com>
ennosigaeus
left a comment
There was a problem hiding this comment.
You should be using the IDL routine "file_basename" to check for the name of the file and extension and not do that much manual work in stx_unique_filename. I would assume the entire routine become much shorter, so you may be able to integrate it with the main routine.
… of manual strpos Agent-Logs-Url: https://github.com/i4Ds/STIX-GSW/sessions/aa2ca532-d099-4c14-84c6-13c7ed4ce926 Co-authored-by: ennosigaeus <649330+ennosigaeus@users.noreply.github.com>
Refactored in 82e1881. |
There was a problem hiding this comment.
Pull request overview
This PR prevents repeated processing runs from silently overwriting previously written spectrum/SRM FITS outputs by introducing a helper that selects the next available filename and applying it during OSPEX conversion.
Changes:
- Added
stx_unique_filename.proto find an available output filename by appending an incrementing_<N>suffix before the extension. - Updated
stx_convert_science_data2ospex.proto run the finalized spectrum/SRM output paths throughstx_unique_filename, updatingfits_info_paramsand optionally printing a notice (unlesssilentis set).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
stix/idl/processing/spectrogram/stx_unique_filename.pro |
New helper function to pick a non-existing output filename by applying a numeric suffix. |
stix/idl/processing/spectrogram/stx_convert_science_data2ospex.pro |
Uses stx_unique_filename to avoid clobbering existing spectrum/SRM outputs and keeps fits_info_params in sync. |
Comments suppressed due to low confidence (1)
stix/idl/processing/spectrogram/stx_unique_filename.pro:56
stx_unique_filenamealways appends a new_<counter>suffix to the full base name. If the input already ends with an existing numeric suffix (e.g.foo_1.fits) and that file exists, this will generatefoo_1_1.fitsrather than incrementing tofoo_2.fitsas described in the header examples. Consider detecting a trailing_<int>in the base name and incrementing from that value (or stripping it before applying the counter).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
ennosigaeus
left a comment
There was a problem hiding this comment.
I like the approach, but the stx_unique_filename is in the wrong place. Maybe better in a more generic folder, like https://github.com/i4Ds/STIX-GSW/tree/master/stix/idl/util
Agent-Logs-Url: https://github.com/i4Ds/STIX-GSW/sessions/2fd4495a-54f7-40c6-9e21-56fca5e5f97b Co-authored-by: ennosigaeus <649330+ennosigaeus@users.noreply.github.com>
Moved to |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
ennosigaeus
left a comment
There was a problem hiding this comment.
LGTM, already gave feedback to copilot.
|
@paolomassa can you have a quick look and spin in IDL to see if this is fine? |
Repeated processing of the same observation produces identical default filenames (
stx_spectrum_<uid>.fits/stx_srm_<uid>.fits), silently clobbering any previously written files.Changes
New
stx_unique_filename.pro— helper function that returns the input path unchanged if free, or finds the next available name by appending_1,_2, … before the extension. Extension-agnostic (uses last.in the path).stx_convert_science_data2ospex.pro— after the output paths are finalised infits_info_params, both are resolved throughstx_unique_filename. If a name changes, the updated path is written back tofits_info_params(so the FITS writer and OSPEX object stay in sync) and a message is printed unlesssilentis set.Example behaviour