sair package
Module contents
- class saibr.SaibrCalibrate(gfp: Optional[list] = None, af: Optional[list] = None, rfp: Optional[list] = None, roi: Optional[list] = None, paths: Optional[list] = None, gfp_regex: Optional[str] = '*488 SP 535-50*', af_regex: Optional[str] = '*488 SP 630-75*', rfp_regex: Optional[str] = None, roi_regex: Optional[str] = '*ROI*', sigma: float = 2.0, intercept0: bool = False, expand: float = 10.0, method: str = 'OLS')
Bases:
objectClass for performing SAIBR calibration
Two methods of specifying data - input the images directly as a list for each channel along with a list of ROIs - specify a list of paths and regular expressions for image files and ROIs (easier method if files are set up appropriately)
If rfp channel is not specified, will perform the normal two channel calibration
- Parameters
gfp – list of GFP channel images
af – list off AF channel images
rfp – list of RFP channel images
roi – list of ROIs
paths – list of paths containing n2 images
gfp_regex – regular expression found in gfp channel image files
af_regex – regular expression found in af channel image files
rfp_regex – regular expression found in rfp channel files (optional)
roi_regex – regular expression found in ROI files
sigma – gaussian blur to apply to images prior to regression
intercept0 – if True, force intercept of regression to go through zero. Not recommended
expand – expand ROIs by this many pixels (useful to include a portion of background)
method – fitting method, either ‘OLS’ for ordinary least squares or ‘ODR’ for orthogonal distance regression
To run regression, initialise class and run() SAIBR parameters will then be found at self.params
- plot_correlation(s: Optional[float] = None)
- plot_prediction(s: float = 0.001)
- plot_residuals(s: float = 0.001)
- run()
- saibr.direcslist(dest: str, levels: int = 0, exclude: Optional[tuple] = ('!',), exclusive: Optional[tuple] = None) list
Gives a list of directories within a given directory (full path) Todo: os.walk
- Parameters
dest – path of parent directory
levels – number of levels to go down. E.g. if 0, only return folders within the parent folder; if 1, return
folder (folders within folders within the parent) –
exclude – exclude directories containing any strings within this tuple
exclusive – exclude directories that don’t contain all the strings within this tuple
- Returns
list of directories
- saibr.load_image(filename: str) ndarray
Given the filename of a TIFF, creates numpy array with pixel intensities
- Parameters
filename – full path to the file to import (including extension)
- Returns
A numpy array of the image
- saibr.make_mask(shape: tuple, roi: ndarray) ndarray
- saibr.offset_coordinates(roi: ndarray, offsets: Union[ndarray, float], periodic: bool = True) ndarray
Reads in coordinates, adjusts according to offsets
- Parameters
roi – two column array containing x and y coordinates. e.g. coors = np.loadtxt(filename)
offsets – array the same length as coors. Direction?
periodic –
- Returns
array in same format as coors containing new coordinates. To save this in a fiji readable format: np.savetxt(filename, newcoors, fmt=’%.4f’, delimiter=’ ‘)
- saibr.saibr_correct(ch1: ndarray, ch2: ndarray, m: float, c: float) ndarray
Subtract ch2 from ch1 ch2 is first adjusted to m * ch2 + c
- Parameters
ch1 – numpy array of channel 1
ch2 – numpy array of channel 2
m – m parameter obtained from n2 data
c – c parameter obtained from n2 data
- Returns
numpy array of af corrected image
- saibr.saibr_correct_3channel(ch1: ndarray, ch2: ndarray, ch3: ndarray, m1: float, m2: float, c: float) ndarray
Subtract ch2 and ch3 from ch1 ch2 and ch3 are first adjusted to m1 * ch2 + m2 * ch3 + c
- Parameters
ch1 – numpy array of channel 1
ch2 – numpy array of channel 2
ch3 – numpy array of channel 3
m1 – m1 parameter obtained from n2 data
m2 – m2 parameter obtained from n2 data
c – c parameter obtained from n2 data
- Returns
numpy array of af corrected image
- saibr.saibr_correlation(img1: ndarray, img2: ndarray, mask: ndarray = None, intercept0: bool = False, method: str = 'OLS') Tuple[list, ndarray, ndarray]
Calculates pixel-by-pixel correlation between two channels Takes 3d image stacks shape [n, 512, 512]
- Parameters
img1 – gfp channel
img2 – af channel
mask – mask specifying region of images to use for regression, from make_mask function
intercept0 – if True, force the intercept to go through zero. Not recommended
method – fitting method, either ‘OLS’ for ordinary least squares or ‘ODR’ for orthogonal distance regression
- Returns
parameters from regression [m, c] numpy array of all af channel pixels used for regression numpy array of all gfp channel pixels used for regression
- saibr.saibr_correlation_3channel(img1: ndarray, img2: ndarray, img3: ndarray, mask: Optional[ndarray] = None, intercept0: bool = False, method: str = 'OLS') Tuple[list, ndarray, ndarray, ndarray]
Calculates pixel-by-pixel correlation between three channels Takes 3d image stacks shape [n, 512, 512]
- Parameters
img1 – gfp channel
img2 – af channel
img3 – third channel
mask – mask specifying region of images to use for regression, from make_mask function
intercept0 – if True, force the intercept to go through zero. Not recommended
method – fitting method, either ‘OLS’ for ordinary least squares or ‘ODR’ for orthogonal distance regression
- Returns
parameters from regression [m, c] numpy array of all af channel pixels used for regression numpy array of all third channel pixels used for regression numpy array of all gfp channel pixels used for regression
- saibr.save_img(img: ndarray, direc: str)
Saves 2D array as .tif file
- Parameters
img – numpy array of the image to save
direc – file path to save to (including ‘.tif’ extension)
- saibr.save_img_jpeg(img: ndarray, direc: str, cmin: Optional[float] = None, cmax: Optional[float] = None, cmap: str = 'gray')
Saves 2D array as jpeg, according to min and max pixel intensities
- Parameters
img – numpy array of the image to save
direc – file path to save to (including ‘.jpeg’ extension)
cmin – optional, sets intensity scaling (along with cmax)
cmax – optional, sets intensity scaling (along with cmin)
cmap – colour map (use string corresponding to matplotlib colormap)