Skip to content

Change SourceInjector API to accept a generic ThreeMLModelFoldingInterface #528

Description

@israelmcmc

Currently, SourceInjector accepts all the inputs to initialize a FullDetectorResponse:

Parameters
----------
response : str or pathlib.Path
The path to the response file
response_frame : str, optional
The frame of the Compton data space (CDS) of the
response. It only accepts `spacecraftframe` or
"galactic". (the default is `spacecraftframe`, which means
the CDS is in the detector frame.)
pa_convention : str, optional
Polarization angle convention for polarization-enabled
detector-frame responses. Must be one of ('RelativeX',
'RelativeY', 'RelativeZ') when the response includes a
`Pol` axis and `response_frame="spacecraftframe"`.

At first order, SourceInjector should accept a FullDetectorResponse object instead, to avoid opening multiple time.

However, now that we have the interfaces refactoring, we can go further and accept a generic ThreeMLModelFoldingInterface, and use it to convolve a generic model:

@runtime_checkable
class ThreeMLModelFoldingInterface(Protocol):
def set_model(self, model: Model):
"""
The model is passed as a reference and it's parameters
can change. Remember to check if it changed since the
last time the user called expectation.
"""
@runtime_checkable
class UnbinnedThreeMLModelFoldingInterface(ThreeMLModelFoldingInterface, ExpectationDensityInterface, Protocol):
"""
No new methods. Just the inherited ones.
"""
@runtime_checkable
class BinnedThreeMLModelFoldingInterface(ThreeMLModelFoldingInterface, BinnedExpectationInterface, Protocol):
"""
No new methods. Just the inherited ones.
"""

Out current standard implementation of this interface is BinnedThreeMLPointSourceResponse. You can see an usage example in the Crab fit tutorial.

This is also related to #499: if the user passes a UnbinnedThreeMLModelFoldingInterface, we can inject event data right from the same class.

Metadata

Metadata

Assignees

No one assigned
    No fields configured for Feature / Enhancement.

    Projects

    Status
    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions