Tools_lib
- ArgMaxND(data)[source]
It finds the the maximum and the corresponding indeces of a N-dimensional array.
- Parameters:
data (ndarray) – N-dimensional array.
- Returns:
arg (ndarray(int)) – indeces of the maximum.
mx (float) – maximum value.
- CropEdge(dset, npx=10, edges='l', order: str = 'rzxytc')[source]
It crops an ISM dataset along the specified edges of the xy plane.
- Parameters:
dset (ndarray) – ISM dataset
npx (int, optional) – Number of pixel to crop from each edge. The default is 10.
edges (str, optional) – Cropped edges. The possible values are ‘l’ (left),’r’ (right), ‘u’ (up), and ‘d’ (down). Any combination is possible. The default is ‘l’.
order (str, optional) – Order of the dimensions of the dataset The default is ‘rzxytc’.
- Returns:
dset_cropped – ISM dataset cropped
- Return type:
ndarray
- DownSample(dset, ds: int = 2, order: str = 'rzxytc')[source]
It downsamples an ISM dataset on the xy plane.
- Parameters:
dset (ndarray) – ISM dataset.
ds (int, optional) – Downsampling factor. The default is 2.
order (str, optional) – Order of the dimensions of the dataset The default is ‘rzxytc’.
- Returns:
dset_ds – ISM dataset downsampled.
- Return type:
ndarray
- FWHM(x, y, height=0.5)[source]
It calculates the Full Width at Half Maximum of a 1D curve.
- Parameters:
x (ndarray) – Horizontal axis.
y (ndarray) – Curve.
- Returns:
FWHM – Full Width at Half Maximum of the y curve.
- Return type:
float
- GaussMultVar(X, Y, M1, M2)[source]
Multivariate Gaussian function.
- Parameters:
X (np.ndarray) – X axis.
Y (np.ndarray) – Y axis.
M1 (np.ndarray) – First momentum of the distribution (average)
M2 (np.ndarray) – Second momentum of the distribution (variance matrix)
- Returns:
g – Image of the multivariate Gaussian function
- Return type:
np.ndarray
- RadialSpectrum(img, pxsize: float = 1, normalize: bool = True)[source]
It calculates the radial spectrum of a 2D image.
- Parameters:
img (ndarray) – 2D image.
pxsize (float, optional) – Pixel size. The default is 1.
normalize (bool, optional) – If True, the result is divided by its maximum. The default is True.
- Returns:
ftR (ndarray) – Radial spectrum.
space_f (ndarray) – Frequency axis.
- Reorder(dset, inOrder: str, outOrder: str = 'rzxytc')[source]
It reorders a dataset to match the desired order of dimensions. If some dimensions are missing, it adds new dimensions.
- Parameters:
dset (ndarray) – ISM dataset.
inOrder (str) – Order of the dimension of the data. It can contain any letter of the outOrder string.
outOrder (str, optional) – Order of the output. The default is ‘rzxytc’.
- Returns:
data – ISM dataset reordered.
- Return type:
ndarray
- UpSample(dset, us: int = 2, npx: str = 'even', order: str = 'rzxytc')[source]
It upsamples an ISM dataset on the xy plane.
- Parameters:
dset (TYPE) – ISM dataset.
us (int, optional) – Upsampling factor. The default is 2.. The default is 2.
npx (str, optional) – Parity of the number of pixels on each axis. The default is ‘even’.
order (str, optional) – Order of the dimensions of the dataset The default is ‘rzxytc’.
- Returns:
dset_us – ISM dataset upsampled.
- Return type:
ndarray
- check_saturation(dset, sat_map=None)[source]
Checks each channel for saturation.
- Parameters:
dset (np.ndarray) – Raw ISM dataset. The channel dimension must be the last one.
sat_map (np.ndarray) – Saturation value for each channel (Nch).
- fingerprint(dset, volumetric=False)[source]
Calculate the fingerprint of an ISM dataset. The last dimension has to be the spad array channel.
- Parameters:
dset (np.array(Nz x Nx x Nx x ... x N*N)) – ISM dataset
volumetric (bool) – if true, a fingerprint is returned for each axial plane
- Returns:
Fingerprint – Finger print
- Return type:
np.array(Nz x N x N)
- fit_to_gaussian(img, pxsize, baseline=False, p0=None)[source]
Fit an image to a multivariate Gaussian function
- Parameters:
img (np.ndarray) – 2D image.
pxsize (float) – Size of the pixe of the image.
baseline (bool) – If True, the fit model adds to a constant baseline.
p0 (tuple) – Starting parameters for the fitting. The first two are the elements of the first moment vector. The next three are the elements of the second moment matrix. The next one is the amplitude. If next one is the baseline value (to be used only is baseline is True).
- Returns:
img_fit (np.ndarray) – Image of the result of the fit.
sigma_matrix_diag (np.ndarray) – Square root of the diagonalized variance matrix.
popt (np.ndarray) – Array of the fitted parameters.
- kl_divergence(ground_truth, reconstruction, remove_inf=True, intensity_offset=False, normalize_entries=False)[source]
Calculates the Kullback-Leibler divergence for each iteration of the reconstruction
- Parameters:
ground_truth (np.ndarray) – Reference image (Ny x Nx)
reconstruction (np.ndarray) – Stack of reconstructed images (N_iter x Ny x Nx)
remove_inf (bool) – If True, local infinity values are replaced with zeros
intensity_offset – If False, the divergence is calculated as the relative entropy. If true, it contains an additional term -x + y.
- Returns:
kl – KL divergence (N_iter)
- Return type:
np.ndarray
- low_pass(img: ndarray, T: float, S: float, data: str = 'real')[source]
It applies a low-pass sigmoidal filter to a 2D image.
- Parameters:
img (np.ndarray) – 2D image.
T (float) – Cut-off frequency.
S (float) – Sigmoid slope.
data (str, optional) – Domain of the image: It can be ‘real’ or ‘fourier’. The default is ‘real’.
- Returns:
img_filt – Filtered 2D image, in the domain specified by ‘data’.
- Return type:
np.ndarray
- normalized_absolute_difference(ground_truth, reconstruction)[source]
Calculates the normalized absolute difference between two images
- Parameters:
ground_truth (np.ndarray) – Reference image (Ny x Nx)
reconstruction (np.ndarray) – Reconstructed images (Ny x Nx)
- Returns:
nad – Normalized absolute difference
- Return type:
float