Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement a way to add Crosstalk effects on TODs. #326

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 83 additions & 0 deletions litebird_sim/crosstalk.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import numpy as np
from astropy.io import ascii
from .detectors import DetectorInfo


"""
Generate a random crosstalk matrix
Input:

dim := number of detectors

"""


def GenerateXtalk(dim: int):
M = np.zeros((dim, dim))
M = M + np.eye(dim)
for i in range(dim):
for j in range(dim):
if j != i:
rng = np.random.default_rng()
a = rng.uniform(-10, 0)
M[i, j] = 1.0e-5 * a
return M


"""Implement the crosstalk over the TOD
Input:
tods:= List of time ordered data
X := Crosstalk matrix

"""


def Compute_Xtalk_TOD(tods: np.ndarray, X: np.ndarray):
tods_x = X.dot(tods)
return tods_x


"""
Function that reads the full crosstalk matrix
written on an external file.
It returns the crosstalk matrix Xtalk
and the dictionary d such that
d[detector_name]=i
where detector_name is a string specifying the name of the
detetcor and i is the index of that detetctor in the
crosstalk matrix.
"""


def Get_Xtalk_from_file(path_matrix: str, path_dictionary: str):
Xtalk = np.loadtxt(path_matrix, delimiter=",", unpack=True)
d = ascii.read(path_dictionary)
return (Xtalk, d)


"""
This function takes as input a crosstalk matrix for a given squid,
its related dictionary d[det.name]=idx, with idx the corresponding index
in the matrix file, and a list of detectors wichi can be a subset
of the set of detectors related by the full crosstalk matrix.
It returns a smaller matrix with the crosstalk of this subset of detectors.
Input:
matrix := the full crosstalk matrix
d := the associated dictionary
detector_list:= list of detectors we want to consider
"""


def create_submatrix(
matrix: np.ndarray, det_dict: dict[str, int], detector_list: list[DetectorInfo]
):
N2 = np.size(detector_list)
array = np.zeros(N2)
dnames = [detector_list[i].name for i in range(N2)]
for i, key in enumerate(dnames):
array[i] = int(det_dict[key])
newmatrix = np.zeros((N2, N2))
for i in range(N2):
for j in range(N2):
newmatrix[i, j] = matrix[int(array[i]), int(array[j])]
return newmatrix
7 changes: 5 additions & 2 deletions litebird_sim/detectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ class DetectorInfo:

- channel (Union[str, None]): The channel. The default is None

- squid (Union[int, None]): The squid number of the detector.
The default value is None.

- sampling_rate_hz (float): The sampling rate of the ADC
associated with this detector. The default is 0.0

Expand Down Expand Up @@ -136,6 +139,7 @@ class DetectorInfo:
pixel: Union[int, None] = None
pixtype: Union[str, None] = None
channel: Union[str, None] = None
squid: Union[int, None] = None
sampling_rate_hz: float = 0.0
fwhm_arcmin: float = 0.0
ellipticity: float = 0.0
Expand All @@ -148,8 +152,6 @@ class DetectorInfo:
fknee_mhz: float = 0.0
fmin_hz: float = 0.0
alpha: float = 0.0
bandcenter_ghz: float = 0.0
bandwidth_ghz: float = 0.0
pol: Union[str, None] = None
orient: Union[str, None] = None
quat: Any = None
Expand All @@ -175,6 +177,7 @@ def from_dict(dictionary: Dict[str, Any]):
- ``pixel``
- ``pixtype``
- ``channel``
- ``squid``
- ``bandcenter_ghz``
- ``bandwidth_ghz``
- ``band_freqs_ghz``
Expand Down