Skip to content

Interfaces refactoring#369

Merged
israelmcmc merged 320 commits intocositools:developfrom
israelmcmc:interfaces
Mar 9, 2026
Merged

Interfaces refactoring#369
israelmcmc merged 320 commits intocositools:developfrom
israelmcmc:interfaces

Conversation

@israelmcmc
Copy link
Copy Markdown
Collaborator

@israelmcmc israelmcmc commented Jun 30, 2025

Work in progress...

This is a major refactoring of cosipy to make it more modular, using interfaces (protocols) to decouple the inputs/outputs of different classes from their implementation.

There are currently three examples that serve as an entry point to see the interfaces usage:

Presentations:

20250630-CosipyInterfacesUpdate-Israel.pdf (at version 214f2ae)

Installation notes and troubleshooting:

TODO list:

  • Binned analysis toy example
  • GRB spectral fit (using dwel time map / local coordinates)
  • Crab spectral fit (using scatt map / galactic coordinate)
  • Unbinned analysis toy example
  • Extended source response
  • Propagate to source injector
  • Propagate to TS map
  • Propagate to imaging deconvolution
  • Merge with Jeremy's and other recent PRs
  • Update all notebooks
  • Fix all tests

Signed-off-by: Israel Martinez <imc@umd.edu>
Signed-off-by: Israel Martinez <imc@umd.edu>
…ecessary.

Signed-off-by: Israel Martinez <imc@umd.edu>
- Use same path variable for inputs and fetch_wasabi.
- Commit dataio yaml config files.

Signed-off-by: Israel Martinez <imc@umd.edu>
…hood and moving to implementation's __init__

Signed-off-by: Israel Martinez <imc@umd.edu>
Signed-off-by: Israel Martinez <imc@umd.edu>
- remove get_bin_data from interfaces
- add event metadata

Signed-off-by: Israel Martinez <imc@umd.edu>
- add profiles
- fix hidden issue before separating main()

Signed-off-by: Israel Martinez <imc@umd.edu>
Signed-off-by: Israel Martinez <imc@umd.edu>
… implementation

Signed-off-by: Israel Martinez <imc@umd.edu>
Signed-off-by: Israel Martinez <imc@umd.edu>
# Conflicts:
#	cosipy/__init__.py
#	cosipy/response/FullDetectorResponse.py
#	cosipy/response/PointSourceResponse.py
#	cosipy/response/__init__.py
#	cosipy/spacecraftfile/SpacecraftFile.py
#	cosipy/threeml/COSILike.py
#	cosipy/ts_map/TSMap.py
#	docs/tutorials/image_deconvolution/511keV/GalacticCDS/511keV-Galactic-ImageDeconvolution.ipynb
#	docs/tutorials/image_deconvolution/511keV/ScAttBinning/511keV-ScAtt-DataReduction.ipynb
#	docs/tutorials/image_deconvolution/511keV/ScAttBinning/511keV-ScAtt-ImageDeconvolution.ipynb
#	docs/tutorials/ts_map/TS_map_fitting.ipynb
#	tests/polarization/test_polarization_asad.py
#	tests/source_injector/test_source_injector.py
#	tests/spacecraftfile/test_spacecraftfile.py
Signed-off-by: Israel Martinez <imc@umd.edu>
israelmcmc and others added 18 commits March 4, 2026 10:36
- Move get_lctutorial_data.py to speclc_grbdc3_prep.ipynb
- Use fetch_wasabi with checksum instead of custom get_data (wasabipath,outpath,unzip)
- No need for unzipping step

Signed-off-by: Israel Martinez <imc@umd.edu>
Signed-off-by: Israel Martinez <imc@umd.edu>
# Conflicts:
#	cosipy/pipeline/src/io.py
#	cosipy/pipeline/task/task.py
… mistakes and missed some calculations while trying to refactor the GRB tutorial based off the Crab tutorial. Those issues are fixed now and the last plot looks better.
- Use .fits orientation file from develop instead of .ori from DC2
- Add missing poisson_conf_interval import
- Use updated response file from develop instead of DC2

Signed-off-by: Israel Martinez <imc@umd.edu>
# Conflicts:
#	docs/tutorials/spectral_fits/continuum_fit/grb/SpectralFit_GRB.ipynb
- The source variable was not updated after the transform_to(self._gcrs) call (is not an inplace operation)
- ez_cart was not normalized before taking the dot product to compare to the cos(angle)

Signed-off-by: Israel Martinez <imc@umd.edu>
Signed-off-by: Israel Martinez <imc@umd.edu>
# Conflicts:
#	cosipy/source_injector/source_injector.py
#	docs/tutorials/source_injector/Point_source_injector.ipynb
@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 9, 2026

Codecov Report

❌ Patch coverage is 54.20208% with 1455 lines in your changes missing coverage. Please review.
✅ Project coverage is 70.84%. Comparing base (23fd2fb) to head (dac7455).
⚠️ Report is 321 commits behind head on develop.

Files with missing lines Patch % Lines
cosipy/response/ideal_response.py 0.00% 465 Missing ⚠️
cosipy/data_io/EmCDSUnbinnedData.py 40.57% 104 Missing ⚠️
cosipy/response/relative_coordinates.py 0.00% 103 Missing ⚠️
cosipy/threeml/psr_fixed_ei.py 0.00% 83 Missing ⚠️
cosipy/event_selection/time_selection.py 0.00% 62 Missing ⚠️
cosipy/spacecraftfile/spacecraft_file.py 85.08% 61 Missing ⚠️
cosipy/interfaces/instrument_response_interface.py 44.23% 58 Missing ⚠️
cosipy/interfaces/data_interface.py 61.01% 46 Missing ⚠️
cosipy/interfaces/photon_parameters.py 64.61% 46 Missing ⚠️
...kground_estimation/free_norm_threeml_binned_bkg.py 69.28% 43 Missing ⚠️
... and 23 more
Files with missing lines Coverage Δ
...osipy/background_estimation/ContinuumEstimation.py 42.75% <ø> (ø)
cosipy/background_estimation/__init__.py 100.00% <100.00%> (ø)
cosipy/data_io/UnBinnedData.py 92.53% <100.00%> (-0.32%) ⬇️
cosipy/data_io/__init__.py 100.00% <100.00%> (ø)
cosipy/image_deconvolution/scatt_exposure_table.py 98.41% <100.00%> (+0.02%) ⬆️
.../image_deconvolution/time_binned_exposure_table.py 93.68% <100.00%> (+0.20%) ⬆️
cosipy/interfaces/__init__.py 100.00% <100.00%> (ø)
cosipy/interfaces/background_interface.py 100.00% <100.00%> (ø)
cosipy/interfaces/likelihood_interface.py 100.00% <100.00%> (ø)
cosipy/interfaces/source_response_interface.py 100.00% <100.00%> (ø)
... and 45 more

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Signed-off-by: Israel Martinez <imc@umd.edu>
@israelmcmc israelmcmc marked this pull request as ready for review March 9, 2026 16:37
@israelmcmc
Copy link
Copy Markdown
Collaborator Author

All unit tests and all tutorials are now working!

This includes a lot of new code, some of which is not yet covered by the unit tests. While it would be ideal to wait to improve the unit tests, it'll be hard to continue to work with two branch. I'm going to merge this now and work on the units test during the clean up.

I made a tag of the last version of the develop before merging interfaces:
https://github.com/cositools/cosipy/tree/v0.4.0dev0

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

Labels

Feature / Enhancement New functionality or improvement refactoring Code refactoring and API changes.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Interfaces refactoring

9 participants