Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optimize cuts tool errors when setting fits.gz as output file #2693

Open
maxnoe opened this issue Feb 4, 2025 · 0 comments
Open

optimize cuts tool errors when setting fits.gz as output file #2693

maxnoe opened this issue Feb 4, 2025 · 0 comments
Labels
bug module:core issues related to ctapipe.core

Comments

@maxnoe
Copy link
Member

maxnoe commented Feb 4, 2025

Describe the bug

The tool currently raises an error that append is not supported for fits.gz files

To Reproduce

❯ ctapipe-optimize-event-selection --proton-file ../../data/grid-prod6/v0.23.x/prod6/CTAO-North-Alpha/proton_20deg_0deg_run001319___cta-prod6-2156m-LaPalma-dark+magic.01_alpha_test_applied.DL2.h5 --electron-file ../../data/grid-prod6/v0.23.x/prod6/CTAO-North-Alpha/electron_20deg_0deg_run000001___cta-prod6-2156m-LaPalma-dark+magic.01_alpha_test_applied.DL2.h5 --output cut_optimization_result.fits.gz --log-level=info
❯ ctapipe-optimize-event-selection --gamma-file ../../data/grid-prod6/v0.23.x/prod6/CTAO-North-Alpha/gamma_20deg_0deg_run002016___cta-prod6-2156m-LaPalma-dark+magic_cone10.01_alpha_test_applied.DL2.h5 --proton-file ../../data/grid-prod6/v0.23.x/prod6/CTAO-North-Alpha/proton_20deg_0deg_run001319___cta-prod6-2156m-LaPalma-dark+magic.01_alpha_test_applied.DL2.h5 --electron-file ../../data/grid-prod6/v0.23.x/prod6/CTAO-North-Alpha/electron_20deg_0deg_run000001___cta-prod6-2156m-LaPalma-dark+magic.01_alpha_test_applied.DL2.h5 --output cut_optimization_result.fits.gz --log-level=INFO
2025-02-04 16:52:36,200 INFO [ctapipe.ctapipe-optimize-event-selection] (tool.initialize): Loading config from '[]'
2025-02-04 16:52:36,201 INFO [ctapipe.ctapipe-optimize-event-selection] (tool.initialize): ctapipe version 0.23.3.dev222+g14cb49acd
2025-02-04 16:54:01,720 INFO [ctapipe.ctapipe-optimize-event-selection] (optimize_event_selection.start): Optimizing cuts using 1560712 signal and 3305146 background events
2025-02-04 16:54:02,044 INFO [ctapipe.ctapipe-optimize-event-selection.PointSourceSensitivityOptimizer] (optimize.__call__): Optimizing G/H separation cut for best sensitivity
100%|█████████████████████████████████████████████████████████████████████████████████████████████| 8/8 [00:04<00:00,  1.90it/s]
2025-02-04 16:54:06,756 INFO [ctapipe.ctapipe-optimize-event-selection] (optimize_event_selection.finish): Writing results to /home/maxnoe/Uni/CTA/dpps/tutorial-cppm/cut_optimization_result.fits.gz
/home/maxnoe/Uni/CTA/ctapipe/src/ctapipe/core/provenance.py:234: MissingReferenceMetadata: Could not read reference metadata for input file: /home/maxnoe/Uni/CTA/dpps/tutorial-cppm/cut_optimization_result.fits.gz
  warnings.warn(
2025-02-04 16:54:06,769 ERROR [ctapipe.ctapipe-optimize-event-selection] (tool.run): Caught unexpected exception: 'append' mode is not supported with gzip files.Use 'update' mode instead
Traceback (most recent call last):
  File "/home/maxnoe/Uni/CTA/ctapipe/src/ctapipe/core/tool.py", line 440, in run
    self.finish()
  File "/home/maxnoe/Uni/CTA/ctapipe/src/ctapipe/tools/optimize_event_selection.py", line 218, in finish
    self.result.write(self.output_path, self.overwrite)
  File "/home/maxnoe/Uni/CTA/ctapipe/src/ctapipe/irf/optimize.py", line 116, in write
    table.write(output_name, format="fits", append=True)
  File "/home/maxnoe/.local/conda/envs/cta-dev/lib/python3.11/site-packages/astropy/table/connect.py", line 130, in __call__
    self.registry.write(instance, *args, **kwargs)
  File "/home/maxnoe/.local/conda/envs/cta-dev/lib/python3.11/site-packages/astropy/io/registry/core.py", line 386, in write
    return writer(data, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/maxnoe/.local/conda/envs/cta-dev/lib/python3.11/site-packages/astropy/io/fits/connect.py", line 458, in write_table_fits
    fits_append(output, table_hdu.data, table_hdu.header, verify=False)
  File "/home/maxnoe/.local/conda/envs/cta-dev/lib/python3.11/site-packages/astropy/io/fits/convenience.py", line 737, in append
    f = _File(filename, mode="append")
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/maxnoe/.local/conda/envs/cta-dev/lib/python3.11/site-packages/astropy/io/fits/file.py", line 218, in __init__
    self._open_filename(fileobj, mode, overwrite)
  File "/home/maxnoe/.local/conda/envs/cta-dev/lib/python3.11/site-packages/astropy/io/fits/file.py", line 650, in _open_filename
    if not self._try_read_compressed(self.name, magic, mode, ext=ext):
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/maxnoe/.local/conda/envs/cta-dev/lib/python3.11/site-packages/astropy/io/fits/file.py", line 530, in _try_read_compressed
    raise OSError(
OSError: 'append' mode is not supported with gzip files.Use 'update' mode instead
2025-02-04 16:54:06,779 INFO [ctapipe.ctapipe-optimize-event-selection] (tool.write_provenance): Output: /home/maxnoe/Uni/CTA/dpps/tutorial-cppm/cut_optimization_result.fits.gz
2025-02-04 16:54:06,782 INFO [ctapipe.ctapipe-optimize-event-selection] (tool.run): Finished ctapipe-optimize-event-selection
@maxnoe maxnoe added the bug label Feb 4, 2025
@kosack kosack added the module:core issues related to ctapipe.core label Feb 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug module:core issues related to ctapipe.core
Projects
None yet
Development

No branches or pull requests

2 participants