Skip to content

Interfaces refactoring#369

Draft
israelmcmc wants to merge 149 commits intocositools:developfrom
israelmcmc:interfaces
Draft

Interfaces refactoring#369
israelmcmc wants to merge 149 commits intocositools:developfrom
israelmcmc:interfaces

Conversation

@israelmcmc
Copy link
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

…fore failing tutorials were showing as passing.

Signed-off-by: Israel Martinez <imc@umd.edu>
Signed-off-by: Israel Martinez <imc@umd.edu>
Signed-off-by: Israel Martinez <imc@umd.edu>
Signed-off-by: Israel Martinez <imc@umd.edu>
Signed-off-by: Israel Martinez <imc@umd.edu>
Signed-off-by: Israel Martinez <imc@umd.edu>
…ean log file handler

Signed-off-by: Israel Martinez <imc@umd.edu>
Signed-off-by: Israel Martinez <imc@umd.edu>
Signed-off-by: Israel Martinez <imc@umd.edu>
Signed-off-by: Israel Martinez <imc@umd.edu>
Signed-off-by: Israel Martinez <imc@umd.edu>
Signed-off-by: Israel Martinez <imc@umd.edu>
Signed-off-by: Israel Martinez <imc@umd.edu>
Signed-off-by: Israel Martinez <imc@umd.edu>
Signed-off-by: Israel Martinez <imc@umd.edu>
Signed-off-by: Israel Martinez <imc@umd.edu>
Signed-off-by: Israel Martinez <imc@umd.edu>
Signed-off-by: Israel Martinez <imc@umd.edu>
Signed-off-by: Israel Martinez <imc@umd.edu>
Signed-off-by: Israel Martinez <imc@umd.edu>
…e multiple instances of the latter, once per source

Signed-off-by: Israel Martinez <imc@umd.edu>
…_scatt_map > SC file refactoring

Signed-off-by: Israel Martinez <imc@umd.edu>
Signed-off-by: Israel Martinez <imc@umd.edu>
Signed-off-by: Israel Martinez <imc@umd.edu>
Signed-off-by: Israel Martinez <imc@umd.edu>
…r open the official FITS file, or parse the .ori file. It's better to keep it generic for now.

Signed-off-by: Israel Martinez <imc@umd.edu>
Signed-off-by: Israel Martinez <imc@umd.edu>
Signed-off-by: Israel Martinez <imc@umd.edu>
Signed-off-by: Israel Martinez <imc@umd.edu>
Signed-off-by: Israel Martinez <imc@umd.edu>
Signed-off-by: Israel Martinez <imc@umd.edu>
Added the method apply_gti to SpacecraftHistory
…_gti

Revert "Added the method apply_gti to SpacecraftHistory"
Signed-off-by: Israel Martinez <imc@umd.edu>
Signed-off-by: Israel Martinez <imc@umd.edu>
Signed-off-by: Israel Martinez <imc@umd.edu>
Signed-off-by: Israel Martinez <imc@umd.edu>
Signed-off-by: Israel Martinez <imc@umd.edu>
Signed-off-by: Israel Martinez <imc@umd.edu>
Signed-off-by: Israel Martinez <imc@umd.edu>
Signed-off-by: Israel Martinez <imc@umd.edu>
Signed-off-by: Israel Martinez <imc@umd.edu>
…n it was called SpacecraftFile) by jdbuhler in PR cositools#378 (using SLERP)

Signed-off-by: Israel Martinez <imc@umd.edu>
# Conflicts:
#	cosipy/data_io/UnBinnedData.py
#	cosipy/event_selection/good_time_interval.py
#	cosipy/image_deconvolution/coordsys_conversion_matrix.py
#	cosipy/polarization/polarization_angle.py
#	cosipy/polarization_fitting/polarization_asad.py
#	cosipy/response/PointSourceResponse.py
#	cosipy/spacecraftfile/SpacecraftFile.py
#	cosipy/spacecraftfile/__init__.py
#	cosipy/test_data/image_deconvolution/unit_test_file.ipynb
#	cosipy/threeml/COSILike.py
#	cosipy/ts_map/fast_ts_fit.py
#	docs/tutorials/response/DetectorResponse.ipynb
#	docs/tutorials/response/PSR_with_Earth_occultation_example.ipynb
#	docs/tutorials/response/SpacecraftFile.ipynb
#	docs/tutorials/spectral_fits/extended_source_fit/diffuse_511_spectral_fit.ipynb
#	tests/image_deconvolution/test_coordsys_conversion_matrix.py
#	tests/image_deconvolution/test_exposure_table.py
#	tests/polarization/test_polarization_asad.py
#	tests/spacecraftfile/test_spacecraftfile.py
#	tests/ts_map/test_fast_ts_map.py
Signed-off-by: Israel Martinez <imc@umd.edu>
Signed-off-by: Israel Martinez <imc@umd.edu>
@israelmcmc israelmcmc force-pushed the interfaces branch 2 times, most recently from 87d3286 to 317ab82 Compare January 28, 2026 14:55
# Conflicts:
#	cosipy/data_io/BinnedData.py
#	cosipy/data_io/UnBinnedData.py
#	cosipy/image_deconvolution/exposure_table.py
#	cosipy/source_injector/source_injector.py
#	cosipy/test_data/image_deconvolution/unit_test_file.ipynb
#	cosipy/threeml/COSILike.py
#	docs/tutorials/source_injector/Extended_source_injector.ipynb
#	docs/tutorials/source_injector/Point_source_injector.ipynb
#	docs/tutorials/spectral_fits/continuum_fit/crab/SpectralFit_Crab.ipynb
#	docs/tutorials/spectral_fits/extended_source_fit/diffuse_511_spectral_fit.ipynb
#	tests/image_deconvolution/test_exposure_table.py
Signed-off-by: Israel Martinez <imc@umd.edu>
…herical coordinates.

Signed-off-by: Israel Martinez <imc@umd.edu>
* Change all Iterable[EventInterface] and Iterable[PhotonInterface] to EventDataInterface and PhotonListInterface.
* EventSelection interface no longer defined __call__ and mask(). select() gained the early_stop parameter.
* `direction_lon_radians` was renamed `direction_lon_rad_sc`. This is to make it consistent with other properties that define the coordinate or convention in the name, to make it less error-prone
* Similarly, `polarization_angle_rad` changed to `polarization_angle_rad_stereo`

Signed-off-by: Israel Martinez <imc@umd.edu>
… numpy arrays. The helper from_astropy class methods is provided (old init)

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

* New intermediate class called PhotonListWithDirectionInSCFrame. The corresponding interface is the input of FarFieldInstrumentResponseFunctionInterface
* FarFieldSpectralInstrumentResponseFunctionInterface with input PhotonListWithDirectionAndEnergyInSCFrame
* Similar for polarization IRF

Signed-off-by: Israel Martinez <imc@umd.edu>
Signed-off-by: Israel Martinez <imc@umd.edu>
Signed-off-by: Israel Martinez <imc@umd.edu>
Signed-off-by: Israel Martinez <imc@umd.edu>
Allow implementation to use already cached numpy arrays.
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

4 participants