From 81dee643b766951eb83c149847a7fa430c459041 Mon Sep 17 00:00:00 2001 From: Andrea Sabatucci Date: Fri, 5 Jul 2024 11:27:55 +0200 Subject: [PATCH 1/2] Added the Squid attribute to DetectorInfo() class. --- litebird_sim/detectors.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/litebird_sim/detectors.py b/litebird_sim/detectors.py index a489c13b..f2d0d981 100644 --- a/litebird_sim/detectors.py +++ b/litebird_sim/detectors.py @@ -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 @@ -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 @@ -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 @@ -175,6 +177,7 @@ def from_dict(dictionary: Dict[str, Any]): - ``pixel`` - ``pixtype`` - ``channel`` + - ``squid`` - ``bandcenter_ghz`` - ``bandwidth_ghz`` - ``band_freqs_ghz`` From a667ebf1c16aa9ad15b05c3bae71ddc4ad53ef58 Mon Sep 17 00:00:00 2001 From: Andrea Sabatucci Date: Fri, 5 Jul 2024 17:10:38 +0200 Subject: [PATCH 2/2] Added basic crosstalk functions --- litebird_sim/crosstalk.py | 83 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 litebird_sim/crosstalk.py diff --git a/litebird_sim/crosstalk.py b/litebird_sim/crosstalk.py new file mode 100644 index 00000000..0d81b055 --- /dev/null +++ b/litebird_sim/crosstalk.py @@ -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