2020-04-29 17:07:43 +02:00
|
|
|
from abc import ABC, abstractmethod
|
|
|
|
import astropy.units as u
|
2020-05-13 14:30:46 +02:00
|
|
|
from ..sensor.PixelMask import PixelMask
|
2020-04-29 17:07:43 +02:00
|
|
|
from typing import Union
|
2020-05-13 14:30:46 +02:00
|
|
|
import numpy as np
|
2020-04-29 17:07:43 +02:00
|
|
|
|
|
|
|
|
|
|
|
class IPSF(ABC):
|
|
|
|
"""
|
|
|
|
Interface for modelling a PSF
|
|
|
|
"""
|
|
|
|
@abstractmethod
|
2020-05-06 10:20:57 +02:00
|
|
|
def calcReducedObservationAngle(self, contained_energy: Union[str, int, float, u.Quantity],
|
2020-05-11 10:38:34 +02:00
|
|
|
jitter_sigma: u.Quantity = None, obstruction: float = 0.0) -> u.Quantity:
|
2020-04-29 17:07:43 +02:00
|
|
|
"""
|
|
|
|
Calculate the reduced observation angle in lambda / d_ap for the given contained energy.
|
|
|
|
|
|
|
|
Parameters
|
|
|
|
----------
|
|
|
|
contained_energy : Union[str, int, float, u.Quantity]
|
|
|
|
The percentage of energy to be contained within a circle with the diameter reduced observation angle.
|
2020-05-06 10:20:57 +02:00
|
|
|
jitter_sigma : Quantity
|
|
|
|
Sigma of the telescope's jitter in arcsec
|
2020-05-11 10:38:34 +02:00
|
|
|
obstruction : float
|
|
|
|
The central obstruction as ratio A_ob / A_ap
|
2020-04-29 17:07:43 +02:00
|
|
|
|
|
|
|
Returns
|
|
|
|
-------
|
|
|
|
reduced_observation_angle: Quantity
|
|
|
|
The reduced observation angle in lambda / d_ap
|
|
|
|
"""
|
|
|
|
pass
|
|
|
|
|
|
|
|
@abstractmethod
|
2020-05-14 15:01:36 +02:00
|
|
|
def mapToPixelMask(self, mask: PixelMask, jitter_sigma: u.Quantity = None, obstruction: float = 0.0) -> PixelMask:
|
2020-04-29 17:07:43 +02:00
|
|
|
"""
|
|
|
|
Map the integrated PSF values to a sensor grid.
|
|
|
|
|
|
|
|
Parameters
|
|
|
|
----------
|
2020-05-14 15:01:36 +02:00
|
|
|
obstruction
|
2020-05-13 14:31:32 +02:00
|
|
|
mask : PixelMask
|
|
|
|
The pixel mask to map the values to. The values will only be mapped onto entries with the value 1.
|
|
|
|
jitter_sigma : Quantity
|
|
|
|
Sigma of the telescope's jitter in arcsec
|
2020-05-14 15:01:36 +02:00
|
|
|
obstruction : float
|
|
|
|
The central obstruction as ratio A_ob / A_ap
|
2020-04-29 17:07:43 +02:00
|
|
|
|
|
|
|
Returns
|
|
|
|
-------
|
2020-05-13 14:31:32 +02:00
|
|
|
mask : PixelMask
|
|
|
|
The pixel mask with the integrated PSF values mapped onto each pixel.
|
2020-04-29 17:07:43 +02:00
|
|
|
"""
|
|
|
|
pass
|
2020-05-13 14:30:46 +02:00
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def rebin(arr: np.ndarray, factor: float):
|
|
|
|
"""
|
|
|
|
Rebin a 2D-array by summing or repeating the elements.
|
|
|
|
|
|
|
|
Parameters
|
|
|
|
----------
|
|
|
|
arr : ndarray
|
|
|
|
Input array.
|
|
|
|
factor : float
|
|
|
|
Rebinning factor
|
|
|
|
Returns
|
|
|
|
-------
|
|
|
|
rebinned_array : ndarray
|
|
|
|
If the factor is smaller than 1, the data is summed,
|
|
|
|
if the factor is bigger than 1, array elements are repeated
|
|
|
|
See Also
|
|
|
|
--------
|
|
|
|
resize : Return a new array with the specified factor.
|
|
|
|
"""
|
|
|
|
m, n = arr.shape
|
|
|
|
m_new, n_new = int(m * factor), int(n * factor)
|
|
|
|
if factor < 1:
|
|
|
|
res = arr.reshape((m_new, int(1 / factor), n_new, int(1 / factor))).sum(3).sum(1)
|
|
|
|
elif factor > 1:
|
|
|
|
res = np.repeat(np.repeat(arr, int(factor), axis=0), int(factor), axis=1)
|
|
|
|
else:
|
|
|
|
res = arr
|
|
|
|
if isinstance(arr, PixelMask):
|
|
|
|
res.pixel_size = res.pixel_size / factor
|
|
|
|
return res
|