nanopyx.methods.esrrf.eSRRF_workflow
1from ..workflow import Workflow 2from ...core.transform import eSRRF_ST 3from ...core.transform.mpcorrector import macro_pixel_corrector 4from ...core.transform.sr_temporal_correlations import ( 5 calculate_eSRRF_temporal_correlations, 6) 7import numpy as np 8 9# TODO check correlations and error map 10 11 12def eSRRF( 13 image, 14 magnification: int = 5, 15 radius: float = 1.5, 16 sensitivity: float = 1, 17 frames_per_timepoint: int = 0, 18 temporal_correlation: str = "AVG", 19 doIntensityWeighting: bool = True, 20 macro_pixel_correction: bool = True, 21 pad_edges: bool = False, 22 _force_run_type=None, 23): 24 """ 25 Perform eSRRF analysis on an image. 26 27 Args: 28 image (numpy.ndarray): The input image for eSRRF analysis. 29 magnification (int, optional): Magnification factor (default is 5). 30 radius (float, optional): Radius parameter for eSRRF analysis (default is 1.5). 31 sensitivity (float, optional): Sensitivity parameter for eSRRF analysis (default is 1). 32 frames_per_timepoint (int, optional): Number of frames per timepoint (default is 0, which means all frames are used). 33 temporal_correlation (str, optional): Type of temporal correlation to calculate. Options are: AVG, VAR or TAC2 (default is "AVG"). 34 doIntensityWeighting (bool, optional): Enable intensity weighting (default is True). 35 macro_pixel_correction (bool, optional): Enable macro pixel correction (default is True). 36 pad_edges (bool, optional): Enable edge padding for borders calculation instead of setting the edges to 0 (default is False). 37 _force_run_type (str, optional): Force a specific run type for the analysis (default is None). 38 39 Returns: 40 numpy.ndarray: The result of eSRRF analysis, typically representing the localizations. 41 42 Example: 43 result = eSRRF(image, magnification=5, radius=1.5, sensitivity=1, doIntensityWeighting=True) 44 45 Note: 46 - eSRRF (enhanced Super-Resolution Radial Fluctuations) is a method for super-resolution localization microscopy. 47 - This function sets up a workflow to perform eSRRF analysis on the input image. 48 - The workflow includes eSRRF_ST as a step and can be customized with various parameters. 49 - The result is typically a numpy array representing the localized points. 50 51 See Also: 52 - eSRRF_ST: The eSRRF step that performs the actual analysis. 53 - Workflow: The class used to define and run analysis workflows. 54 """ 55 56 if frames_per_timepoint == 0: 57 frames_per_timepoint = image.shape[0] 58 elif frames_per_timepoint > image.shape[0]: 59 frames_per_timepoint = image.shape[0] 60 61 number_of_timepoints = image.shape[0] // frames_per_timepoint 62 if image.shape[0] % frames_per_timepoint != 0: 63 number_of_timepoints += 1 64 65 output_array = np.zeros( 66 ( 67 number_of_timepoints, 68 image.shape[1] * magnification, 69 image.shape[2] * magnification, 70 ), 71 dtype=np.float32, 72 ) 73 74 for i in range(number_of_timepoints): 75 76 _eSRRF = Workflow( 77 ( 78 eSRRF_ST(verbose=False), 79 ( 80 image[ 81 frames_per_timepoint 82 * i : frames_per_timepoint 83 * (i + 1) 84 ], 85 ), 86 { 87 "magnification": magnification, 88 "radius": radius, 89 "sensitivity": sensitivity, 90 "doIntensityWeighting": doIntensityWeighting, 91 "pad_edges": pad_edges, 92 }, 93 ) 94 ) 95 if macro_pixel_correction: 96 output_array[i] = macro_pixel_corrector( 97 np.expand_dims( 98 np.asarray( 99 calculate_eSRRF_temporal_correlations( 100 _eSRRF.calculate(_force_run_type=_force_run_type)[ 101 0 102 ], 103 temporal_correlation, 104 ) 105 ), 106 axis=0, 107 ), 108 magnification=magnification, 109 ) 110 else: 111 output_array[i] = np.asarray( 112 calculate_eSRRF_temporal_correlations( 113 _eSRRF.calculate(_force_run_type=_force_run_type)[0], 114 temporal_correlation, 115 ) 116 ) 117 118 return np.squeeze(output_array.astype(np.float32))
13def eSRRF( 14 image, 15 magnification: int = 5, 16 radius: float = 1.5, 17 sensitivity: float = 1, 18 frames_per_timepoint: int = 0, 19 temporal_correlation: str = "AVG", 20 doIntensityWeighting: bool = True, 21 macro_pixel_correction: bool = True, 22 pad_edges: bool = False, 23 _force_run_type=None, 24): 25 """ 26 Perform eSRRF analysis on an image. 27 28 Args: 29 image (numpy.ndarray): The input image for eSRRF analysis. 30 magnification (int, optional): Magnification factor (default is 5). 31 radius (float, optional): Radius parameter for eSRRF analysis (default is 1.5). 32 sensitivity (float, optional): Sensitivity parameter for eSRRF analysis (default is 1). 33 frames_per_timepoint (int, optional): Number of frames per timepoint (default is 0, which means all frames are used). 34 temporal_correlation (str, optional): Type of temporal correlation to calculate. Options are: AVG, VAR or TAC2 (default is "AVG"). 35 doIntensityWeighting (bool, optional): Enable intensity weighting (default is True). 36 macro_pixel_correction (bool, optional): Enable macro pixel correction (default is True). 37 pad_edges (bool, optional): Enable edge padding for borders calculation instead of setting the edges to 0 (default is False). 38 _force_run_type (str, optional): Force a specific run type for the analysis (default is None). 39 40 Returns: 41 numpy.ndarray: The result of eSRRF analysis, typically representing the localizations. 42 43 Example: 44 result = eSRRF(image, magnification=5, radius=1.5, sensitivity=1, doIntensityWeighting=True) 45 46 Note: 47 - eSRRF (enhanced Super-Resolution Radial Fluctuations) is a method for super-resolution localization microscopy. 48 - This function sets up a workflow to perform eSRRF analysis on the input image. 49 - The workflow includes eSRRF_ST as a step and can be customized with various parameters. 50 - The result is typically a numpy array representing the localized points. 51 52 See Also: 53 - eSRRF_ST: The eSRRF step that performs the actual analysis. 54 - Workflow: The class used to define and run analysis workflows. 55 """ 56 57 if frames_per_timepoint == 0: 58 frames_per_timepoint = image.shape[0] 59 elif frames_per_timepoint > image.shape[0]: 60 frames_per_timepoint = image.shape[0] 61 62 number_of_timepoints = image.shape[0] // frames_per_timepoint 63 if image.shape[0] % frames_per_timepoint != 0: 64 number_of_timepoints += 1 65 66 output_array = np.zeros( 67 ( 68 number_of_timepoints, 69 image.shape[1] * magnification, 70 image.shape[2] * magnification, 71 ), 72 dtype=np.float32, 73 ) 74 75 for i in range(number_of_timepoints): 76 77 _eSRRF = Workflow( 78 ( 79 eSRRF_ST(verbose=False), 80 ( 81 image[ 82 frames_per_timepoint 83 * i : frames_per_timepoint 84 * (i + 1) 85 ], 86 ), 87 { 88 "magnification": magnification, 89 "radius": radius, 90 "sensitivity": sensitivity, 91 "doIntensityWeighting": doIntensityWeighting, 92 "pad_edges": pad_edges, 93 }, 94 ) 95 ) 96 if macro_pixel_correction: 97 output_array[i] = macro_pixel_corrector( 98 np.expand_dims( 99 np.asarray( 100 calculate_eSRRF_temporal_correlations( 101 _eSRRF.calculate(_force_run_type=_force_run_type)[ 102 0 103 ], 104 temporal_correlation, 105 ) 106 ), 107 axis=0, 108 ), 109 magnification=magnification, 110 ) 111 else: 112 output_array[i] = np.asarray( 113 calculate_eSRRF_temporal_correlations( 114 _eSRRF.calculate(_force_run_type=_force_run_type)[0], 115 temporal_correlation, 116 ) 117 ) 118 119 return np.squeeze(output_array.astype(np.float32))
Perform eSRRF analysis on an image.
Args: image (numpy.ndarray): The input image for eSRRF analysis. magnification (int, optional): Magnification factor (default is 5). radius (float, optional): Radius parameter for eSRRF analysis (default is 1.5). sensitivity (float, optional): Sensitivity parameter for eSRRF analysis (default is 1). frames_per_timepoint (int, optional): Number of frames per timepoint (default is 0, which means all frames are used). temporal_correlation (str, optional): Type of temporal correlation to calculate. Options are: AVG, VAR or TAC2 (default is "AVG"). doIntensityWeighting (bool, optional): Enable intensity weighting (default is True). macro_pixel_correction (bool, optional): Enable macro pixel correction (default is True). pad_edges (bool, optional): Enable edge padding for borders calculation instead of setting the edges to 0 (default is False). _force_run_type (str, optional): Force a specific run type for the analysis (default is None).
Returns: numpy.ndarray: The result of eSRRF analysis, typically representing the localizations.
Example: result = eSRRF(image, magnification=5, radius=1.5, sensitivity=1, doIntensityWeighting=True)
Note: - eSRRF (enhanced Super-Resolution Radial Fluctuations) is a method for super-resolution localization microscopy. - This function sets up a workflow to perform eSRRF analysis on the input image. - The workflow includes eSRRF_ST as a step and can be customized with various parameters. - The result is typically a numpy array representing the localized points.
See Also: - eSRRF_ST: The eSRRF step that performs the actual analysis. - Workflow: The class used to define and run analysis workflows.