Additional modules

MIRAG.affichage

Module for displaying the results of the ADMM in its sparse and separation form

MIRAG.affichage.cmap_perso(Q)[source]

Creation of a divergent custom colormap centered on the mean of the Q matrix

Parameters

Q (float) – Matrix to display (mainly sum of C_k) (Nx,Ny)

Returns

cmap – associated cmap object

Return type

obj

MIRAG.affichage.plot_atomNSM(atm2, paraDic)[source]

Display of an atom from the physical dictionary with the right dimensions (m and ns)

Parameters
  • atm2 (float) – matrix of the atom (Nx * Ny)

  • paraDic (dic) – dictionary of the parameters of the atom (size nsm) necessary key : “size_ns_m

Return type

None

Examples

>>> paraDic={}
>>> paraDic["size_ns_m"]=[900,45]
>>> plot_atomNSM(atoms,paraDic)
MIRAG.affichage.plot_ckmap(alpha, duo=False, t=60, x=128, title=['_', '_'], nfile='_', save=False)[source]

Display one or 2 C_k maps from a personal divergent cmap

Parameters
  • alpha (float) – Matrix (M x N)(mainly sum of C_k or detail of a C_k)

  • duo (bool{False}, optional) – Display of one or 2 cards.

  • t (int{60}, optional) – central position (pixel) of the hyperbolas used (ordinate)

  • x (int{128}, optional) – central position (pixel) of the used hyperbolas (abscissa)

  • title (list{["_","_"]}, optional) – Titles of the graphs

  • nfile (str{"_"}, optional) – Name of the file for the record

  • save (bool{False}, optional) – Save the file.

Return type

None

MIRAG.affichage.plot_ckmap_img(T, ck=False, title=['_', '_'], nfile='_', save=False, t=60, x=128)[source]

Displaying the sum of C_k and the dimensional image

Parameters
  • T (float) – array [C_k , img] ([(Nx * Ny * K) , (Nx * Ny)]) or ([(Nx * Ny), (Nx * Ny)])

  • ck (bool{False}, optional) – If the corrections/sum on the C_k have been done

  • title (list{["_","_"]}, optional) – Titles of the graphs

  • nfile (str{"_"}, optional) – Name of the file for the record

  • save (bool{False}, optional) – Save the file.

  • t (int{60}, optional) – central position (pixel) of the hyperbolas used (ordinate)

  • x (int{128}, optional) – central position (pixel) of the hyperbolas used (abscissa)

Return type

None

MIRAG.affichage.plot_recon(Dal, Dico=None, name='_', save=False, compute=True)[source]

Displays the reconstruction of an image using the dictionary and maps of the C_k

Parameters
  • Dal (float) – Either the already computed reconstruction (Nx * Ny) or the C_k tensor (Nx * Ny * K).

  • Dico (float{None}, optional) – dictionary necessary for the calculation of the reconstruction (if not already computed) (Nx * Ny * K).

  • name (str{"_"}, optional) – name of the file to save.

  • save (bool{False}, optional) – save or not the image.

  • compute (bool{True}, optional) – reconstruction already computed or not.

Return type

None

MIRAG.affichage.roc_curve_plot(mask, img, name)[source]

Plot ROC curve

Parameters
  • mask (float) – mask of the image

  • img (array offloat) – array to be roc-curve plotted

  • name (str) – name of the plot

MIRAG.affichage.scale_0_1(img)[source]

Scale an image between 0 and 1

Parameters

img (numpy.ndarray) – Image to scale

Returns

img – Scaled image

Return type

numpy.ndarray

MIRAG.filtrage_func

Module for filtering reconstructions by thresholding / dropping atoms from the dictionary

MIRAG.filtrage_func.SVD_gpr(ref, rank)[source]

Make a SVD of the reference image and put to zero the first rank singular values.

Parameters
  • ref (float) – Reference image (Nx,Ny)

  • rank (int) – Rank of the SVD to set to zero.

Returns

ref_svd – Reference image with the first rank singular values set to zero.

Return type

float

MIRAG.filtrage_func.dropR(C, Dic, p_acond=500, acond=0.1)[source]

Removes after ADMM the unwanted atoms for reconstruction

Warning

To be used specifically for the constrained ADMM 1 (ADMM 2 or Source separation uses the hollow matrix L)

Parameters
  • C (float) – Maps of the coefficients to be reduced (Nx,Ny,K) with K the number of atoms, Nx,Ny the dimensions of the reconstruction.

  • Dic (float) – Dictionary to be reduced (Nx,Ny,K) with K the number of atoms, Nx,Ny the dimensions of the reconstruction.

  • p_acond (int{500}, optional) – condition on the parameter p of the dictionary. Keep all the atoms tq \(a/p < p_{cond}\).

  • acond (float{0.1}, optional) – condition on the parameter a of the dictionary. Keep all atoms tq \(a > a_{cond}\).

Returns

  • Cprim (float) – Maps of the reduced coefficients (Nx,Ny,K’) with K’<K

  • Hprim (float) – Lightweight dictionary (Nx,Ny,K’) with K’<K

MIRAG.filtrage_func.submax_Ck(Csec, seuil=0.1)[source]

Thresholding of C_k cards. Keeps only the values that meet the conditions:

\[0.5\cdot\mathrm{threshold}*1000< \mathrm{signal}<1000*(1- 0.5\cdot\mathrm{threshold})\]

Useful to highlight weak signals (mainly ADMM1).

Parameters
  • Csec (float) – C_k tensor to threshold (dynamic 0-1) (Nx,Ny,K)

  • threshold (float{0.1}, optional) – threshold of the values (between 0 and 1).

Returns

Cfin – Thresholded coefficient map tensor (Nx,Ny,K)

Return type

float

MIRAG.filtrage_func.thresh_Ck(Cprim, seuil=0.45)[source]

Thresholding of C_k cards. Sets to zero the values which respect the following conditions for a signal sliced in histogram with 1000 slices:

\[0.5\cdot\mathrm{threshold}*1000< \mathrm{signal}<1000*(1- 0.5\cdot\mathrm{threshold})\]
Parameters
  • Cprim (float) – C_k tensor to threshold (dynamic 0-1) (Nx,Ny,K)

  • threshold (float{0.45}, optional) – threshold of the values (between 0 and 1).

Returns

Cter – Thresholded coefficient map tensor (Nx,Ny,K)

Return type

float

MIRAG.metrique

Metric calculation module to quantify the reconstruction quality of radargrams

MIRAG.metrique.center_mask(mask, erode=True, sz=20)[source]

Extract from a mask the positions of the clusters Allows to apply an erosion or not on the image (allowing a better detection of masks)

Parameters
  • mask (int) – array of masks

  • erode (bool{True}, optional) – activate erosion of masks.

  • size (int{20}, optional) – size of the erosion kernel if selected.

Returns

centroid – Coordinates of cluster centers

Return type

int

MIRAG.metrique.centroid_adjust_win(centroid, y_mask, dim_rec)[source]

Returns the centers of the adjusted masks The adjustment is made in relation to the size of the image, to avoid overflows.

Parameters
  • centroid (float) – array of mask centers

  • y_mask (int) – dimension Y of the mask image

  • dim_rec (int) – array of dimensions of the used image (often smaller than the mask)

Returns

cent – center of the masks adjusted to the reconstructed image

Return type

int

MIRAG.metrique.comp_metric(Iorg, Irec, Ck, path_mask, erode=True, sz=20, pos_rec=[0, 100, 0, 600], dim_win=[80, 40], out_win_S=False, v_seuil=3, plot_check=False)[source]

Metric of detection of reconstructed hyperbolas/ground truth Main function of the hyperbola detection calculation with respect to a mask

Parameters
  • Iorg (float) – array original normalized image (0-1) (MxN)

  • Irec (float) – array normalized reconstructed image (0-1)(MxN)

  • Ck (float) – matrix of the sum of the normalized coefficient maps (MxN)

  • path_mask (str) – path of the mask

  • erode (bool {True}, optional) – activate the erosion of the mask

  • sz (int {20}, optional:) – kernel size for erosion.

  • pos_rec (list {[0,100,0,600]}, optional) – position of the original image in relation to the mask.

  • dim_win (list{[80,40]}, optional) – size of the detection window in pixels.

  • out_win_S (bool{False}, optional) – return the thresholded window or not

  • v_threshold (int{3}, optional) – Value of the threshold in relation to the standard deviation of C_k. By default set to 0 of C_K.mean-3*C_K.std<C_k< 3*C_K.std+C_K.mean

  • plot_check (bool{False},optional) – Activate the display of the centroids positions on the mask

Returns

score – structure of the scores and metrics computed for a reconstruction from its mask

Return type

dic

Notes

  • score[‘MSE_local_max’] (float) : maximum MeanSquareError for each mask between the reconstructed and the original image

  • score[‘MSE_global’] (float) : global MeanSquareError between the reconstructed image and the original one.

  • score[‘SSI_local_min’] (float) : minimum Structural similarity index for each mask between the reconstructed image and the original one

  • score[‘SSI_global’] (float): Global structural similarity index between the reconstructed image and the original one.

  • score[‘TruePositive’] (float) : number of hyperbola detected in the provided image.

  • score[‘N_terrain’] (float): theoretical number of hyperbolas from the mask.

  • score[“FalseNegative”] (float) : hyperbolas not created by the reconstruction but present in the masks

  • score[“FalsePositive”] (float) : hyperbolas created by the reconstruction but not present in the masks

  • score[“precision”] (float) : TruePositive/(TruePositive+FalsePositive)

  • score[“recall”] (float) : TruePositive/(TruePositive+FalseNegative)

  • score[“F1_score”] (float) : (precision*recall)/(precision+recall)

MIRAG.metrique.detect_Nhyper_rec(ck_stats, Ck, v_seuil=3)[source]

Detects the total number of hyperbolas constructed by the algorithm subject to a threshold

Parameters
  • ck_stats ([type]) – [description]

  • Ck ([type]) – [description]

  • v_threshold (int{3}, optional) – Value of the threshold with respect to the standard deviation of C_k. By default set to 0 of C_K.mean-3*C_K.std<C_k< 3*C_K.std+C_K.mean

Returns

norm_C0_glob – total number of hyperbolas detected

Return type

int

MIRAG.metrique.fenetre(cen, img, dim)[source]

Returns a window centered on a point of total dimension dim (LxH)

Parameters
  • cen (int) – center of the window

  • img (float) – image to center

  • dim (int) – total dimension of the window LxH

Returns

out – window extracted from the initial image

Return type

float

MIRAG.metrique.get_available_masks(name)[source]

Gets the list of all masks in a .h5 file

Parameters

name (str) – absolute path of the .h5 file

Returns

masks_available – dictionary of available masks names for a .h5 file

Return type

str

MIRAG.metrique.load_mask(filename)[source]

Loads the mask from an .h5 file

Parameters

filename (str) – absolute path of the .h5 file

Returns

mask – 2D array of masks

Return type

float

MIRAG.metrique.mask2scatter(mask, erode=True, size=20)[source]

Transforms an array of masks into a scatter x,y Allows to apply an erosion or not on the image (allowing a better detection of masks)

Parameters
  • mask (int) – array of masks

  • erode (bool{True}, optional) – activate erosion of masks.

  • size (int{20}, optional) – size of the erosion kernel if selected.

Returns

  • mask_scatter (int) – scatter x,y of masks

  • ero (int) – masks eroded or not

MIRAG.metrique.stats_reconstruction(Iorg, Irec, MSE_ce, C0_ce, SSI_ce, centroid, c_sta, Ck, v_seuil)[source]

Calculates statistics and metrics (local and global) from the reconstruction.

Parameters
  • Iorg (float) – array original normalized image (0-1) (MxN)

  • Irec (float) – array normalized reconstructed image (0-1)(MxN)

  • MSE_ce (float) – array of local MSE on all mask objects

  • C0_ce (float) – array of detections on all objects of the mask

  • SSI_ce (float) – array of local SSI on all mask objects

  • centroid (int) – Number of hyperbola detected on the mask

  • c_sta (dic) – characteristic of the matrix Ck. c_sta[“mean”] and c_sta[“std”]

  • Ck (float) – matrix of the sum of the normalized coefficient maps (MxN)

  • v_threshold (int{3}, optional) – Value of the threshold with respect to the standard deviation of C_k. By default set to 0 of C_K.mean-3*C_K.std<C_k< 3*C_K.std+C_K.mean

Returns

stat_strc – dictionary of statistics and metrics calculated on the reconstruction.

Return type

dic

MIRAG.metrique.stats_win(ck_stats, ck_s, org_s, rec_s, win_S=False, v_seuil=3)[source]

Performs statistics on a mask in image namely the number of hyperbola detected (C0 norm), the MeanSquareError between the original image and the original one at the mask level.

Parameters
  • ck_stats (float) – dictionary of the mean and standard deviation of the c_k maps

  • ck_s (float) – window of C_k given by the window function for a given mask

  • org_s (float) – window of the original image given by the window function for a given mask

  • rec_s (float) – window of the reconstructed image given by the window function for a given mask

  • win_S (bool{True}, optional) – returns the window thresholded or not

  • v_threshold (int{3}, optional) – Value of the threshold in relation to the standard deviation of the C_k. By default set to 0 of C_K.mean-3*C_K.std<C_k< 3*C_K.std+C_K.mean

Returns

  • MSE (float) – MeanSquareError between the reconstructed image and the original one.

  • norm_C0 (int) – norm 0 of C_k on the window (>0 = detection).

  • ssim_loc (float) – local similarity index

  • ws (float,optionnal) – thresholded window C_k