Detector response
Different matrices that charaterize the response of the instrument. These encode the effective area and the various detector effects seens in the data, and allow to compute the expected counts given a source hypothesis.
Classes
- class cosipy.response.PointSourceResponse(*args: Any, **kwargs: Any)[source]
Handles the multi-dimensional matrix that describes the expected response of the instrument for a particular point in the sky.
- Parameters:
axes (
histpy.Axes
) –Binning information for each variable. The following labels are expected:
Ei
: Real energyEm
: Measured energy. OptionalPhi
: Compton angle. Optional.PsiChi
: Location in the Compton Data Space (HEALPix pixel). Optional.SigmaTau
: Electron recoil angle (HEALPix pixel). Optional.Dist
: Distance from first interaction. Optional.
contents (array,
astropy.units.Quantity
orsparse.SparseArray
) – Array containing the differential effective area convolved with wht source exposure.unit (
astropy.units.Unit
, optional) – Physical units, if not specified as part ofcontents
. Units ofarea*time
are expected.
- property photon_energy_axis
Real energy bins (
Ei
).- Return type:
- class cosipy.response.DetectorResponse(*args: Any, **kwargs: Any)[source]
Handles the multi-dimensional matrix that describes the response of the instrument for a particular
SpacecraftFrame
coordinate location.- Parameters:
axes (
histpy.Axes
) –Binning information for each variable. The following labels are expected:
Ei
: Real energyEm
: Measured energyPhi
: Compton angle. Optional.PsiChi
: Location in the Compton Data Space (HEALPix pixel). Optional.SigmaTau
: Electron recoil angle (HEALPix pixel). Optional.Dist
: Distance from first interaction. Optional.
contents (array,
astropy.units.Quantity
orsparse.SparseArray
) – Array containing the differential effective area.unit (
astropy.units.Unit
, optional) – Physical area units, if not specified as part ofcontents
- get_spectral_response(copy=True)[source]
Reduced detector response, projected along the real and measured energy axes only. The Compton Data Space axes are not included.
- Parameters:
copy (bool) – If true, a copy of the cached spectral response will be returned.
- Return type:
- get_effective_area(energy=None, copy=True)[source]
Compute the effective area at a given energy. If no energy is specified, the output is a histogram for the effective area at each energy bin.
- Parameters:
energy (optional,
astropy.units.Quantity
) – Energy/energies at which to interpolate the linearly effective areacopy (bool) – If true, a copy of the cached effective will be returned.
- Return type:
- get_dispersion_matrix()[source]
Compute the energy dispersion matrix, also known as migration matrix. This holds the probability of an event with real energy
Ei
to be reconstructed with an measured energyEm
.- Return type:
- property photon_energy_axis
Real energy bins (
Ei
).- Return type:
- property measured_energy_axis
Measured energy bins (
Em
).- Return type:
- class cosipy.response.FullDetectorResponse(*args: Any, **kwargs: Any)[source]
Handles the multi-dimensional matrix that describes the full all-sky response of the instrument.
You can access the
DetectorResponse
at a given pixel using the[]
operator. Alternatively you can obtain the interpolated reponse usingget_interp_response()
.- classmethod open(filename, Spectrumfile=None, norm='Linear', single_pixel=False, alpha=0, emin=90, emax=10000, polarization=False)[source]
Open a detector response file.
- Parameters:
filename (str,
Path
).rsp) (Path to the response file (.h5 or)
Spectrumfile (str,) –
- path to the input spectrum file used
for the simulation (optional).
- normstr,
type of normalisation : file (then specify also SpectrumFile) ,powerlaw, Mono or Linear
- alphaint,
if the normalisation is “powerlaw”, value of the spectral index.
- single_pixelbool,
True if there is only one pixel and not full-sky.
- emin,emaxfloat
emin/emax used in the simulation source file.
- property is_sparse
- property axes
List of axes.
- Return type:
- property unit
Physical unit of the contents of the detector reponse.
- Return type:
- get_interp_response(coord)[source]
Get the bilinearly interpolated response at a given coordinate location.
- Parameters:
coord (
astropy.coordinates.SkyCoord
) – Coordinate in theSpacecraftFrame
- Return type:
- get_point_source_response(exposure_map=None, coord=None, scatt_map=None, Earth_occ=True)[source]
Convolve the all-sky detector response with exposure for a source at a given sky location.
Provide either a exposure map (aka dweel time map) or a combination of a sky coordinate and a spacecraft attitude map.
- Parameters:
exposure_map (
mhealpy.HealpixMap
) – Effective time spent by the source at each pixel location in spacecraft coordinatescoord (
astropy.coordinates.SkyCoord
) – Source coordinatescatt_map (
SpacecraftAttitudeMap
) – Spacecraft attitude mapEarth_occ (bool, optional) – Option to include Earth occultation in the respeonce. Default is True, in which case you can only pass one coord, which must be the same as was used for the scatt map.
- Return type:
- get_point_source_response_per_image_pixel(ipix_image, orientation, coordsys='galactic', nside_image=None, nside_scatt_map=None, Earth_occ=True)[source]
Generate point source response for a specific HEALPix pixel by convolving the all-sky detector response with exposure.
- Parameters:
ipix_image (int) – HEALPix pixel index
orientation (cosipy.spacecraftfile.SpacecraftFile) – Spacecraft attitude information
coordsys (str, default 'galactic') – Coordinate system (currently only ‘galactic’ is supported)
nside_image (int, optional) – NSIDE parameter for image reconstruction. If None, uses the detector response’s NSIDE.
nside_scatt_map (int, optional) – NSIDE parameter for scatt map generation. If None, uses the detector response’s NSIDE.
Earth_occ (bool, default True) – Whether to include Earth occultation in the response
- Returns:
Point source response for the specified pixel
- Return type:
- get_extended_source_response(orientation, coordsys='galactic', nside_image=None, nside_scatt_map=None, Earth_occ=True)[source]
Generate extended source response by convolving the all-sky detector response with exposure over the entire sky.
- Parameters:
orientation (cosipy.spacecraftfile.SpacecraftFile) – Spacecraft attitude information
coordsys (str, default 'galactic') – Coordinate system (currently only ‘galactic’ is supported)
nside_image (int, optional) – NSIDE parameter for image reconstruction. If None, uses the detector response’s NSIDE.
nside_scatt_map (int, optional) – NSIDE parameter for scatt map generation. If None, uses the detector response’s NSIDE.
Earth_occ (bool, default True) – Whether to include Earth occultation in the response
- Returns:
Extended source response covering the entire sky
- Return type:
- merge_psr_to_extended_source_response(basename, coordsys='galactic', nside_image=None)[source]
Create extended source response by merging multiple point source responses.
Reads point source response files matching the pattern basename + index + file_extension. For example, with basename=’histograms/hist_’, filenames are expected to be like ‘histograms/hist_00001.hdf5’.
- Parameters:
- Returns:
Combined extended source response
- Return type:
- class cosipy.response.ExtendedSourceResponse(*args: Any, **kwargs: Any)[source]
A class to represent and manipulate extended source response data.
This class provides methods to load data from HDF5 files, access contents, units, and axes information, and calculate expectations based on sky models.
- get_expectation_from_astromodel(source)[source]
Calculate expectation from an astronomical model source.
Notes
Currently, the axes of the response must be [‘NuLambda’, ‘Ei’, ‘Em’, ‘Phi’, ‘PsiChi’].
- classmethod open(filename, name='hist')[source]
Load data from an HDF5 file.
- Parameters:
- Returns:
A new instance of ExtendedSourceResponse with loaded data.
- Return type:
- Raises:
ValueError – If the shape of the contents does not match the axes.
- get_expectation(allsky_image_model)[source]
Calculate expectation based on an all-sky image model.
- Parameters:
allsky_image_model (Histogram) – The all-sky image model to use for calculation.
- Returns:
A histogram representing the calculated expectation.
- Return type:
Histogram
- get_expectation_from_astromodel(source)[source]
Calculate expectation from an astromodels extended source model.
This method creates an AllSkyImageModel based on the current axes configuration, sets its values from the provided astromodels extended source model, and then calculates the expectation using the get_expectation method.
- Parameters:
source (astromodels.ExtendedSource) – An astromodels extended source model object. This model represents the spatial and spectral distribution of an extended astronomical source.
- Returns:
A histogram representing the calculated expectation based on the provided extended source model.
- Return type:
Histogram