API¶
gbeflow¶
-
class
gbeflow.
CziImport
(fpath, summary=True)¶ Bases:
object
Defines a class to wrap the czifile object Identifies data contained in each dimension Helps user extract desired data from multidimensional array
-
__init__
(fpath, summary=True)¶ Read in file using czifile
Parameters: fpath (str) – Complete or relative file path to czi file
-
print_summary
()¶ Prints a summary of data dimensions Assumes that the data is a standard brightfield timelapse collection, e.g. (?, roi, channel, time, z, x, y, ?)
-
squeeze_data
()¶ Uses np.squeeze to reduce dimenions of data according to input preference
-
-
class
gbeflow.
MaskEmbryo
(points)¶ Bases:
object
Fit an ellipse to an embryo and calculate mask
-
__init__
(points)¶ Calculate a first try ellipse using default parameters
Parameters: points (pd.DataFrame) – Contains the columns x and y with 2 rows Returns: self.ell, self.rell, self.fell
-
calc_ellipse
(center_x, center_y, radius_x, radius_y)¶ Calculate a parametrized ellipse based on input values
Parameters: - center_x (float) – Center point of the ellipse in x dimension
- center_y (float) – Center point of the ellipse in y dimension
- radius_x (float) – Radius of ellipse in x dimension
- radius_y (float) – Radius of ellipse in y dimension
Returns: Ellipse in a 400x2 array
-
calc_rotation
(ell=None, df=None)¶ Calculate angle of rotation and rotation matrix using -angle
Parameters: - ell (np.array, optional) – Ellipse array
- df (pd.DataFrame, optional) – Contains the columns x and y with 2 rows
Returns: self.rell
-
calc_start_ell
(scale=1.5, yradius=300, df=None)¶ Customize the fit of an ellipse to an embryo based on the selected endpoints
Parameters: - scale (float, optional) – Typically greater than 1 to extend the length between the two points beyond the ends of the embryo
- yradius (int, optional) – Y radius for initial ellipse, default=300
- df (pd.DataFrame, optional) – Contains the columns x and y with 2 rows
Returns: self.ell (array) – Array of shape 400x2 that contains position of custom ellipse
-
contour_embryo
(img, init=None, sigma=3)¶ Fit a contour to the embryo to separate the background
Parameters: - img (2D np.array) – 2D image from a single timepoint to mask
- init (400x2 ellipse array, optional) – Starting ellipse array that is bigger than the embryo
- sigma (int, optional) – Kernel size for the Gaussian smoothing step
Returns: Masked image where all background points = 0
-
mask_image
(img, mask)¶ Apply mask to image and return with background = 0
Parameters: - img (2D np.array) – 2D image from a single timepoint to mask
- mask (2D np.array) – 2D boolean array containing mask
-
shift_to_center
(rell=None, df=None)¶ Shift ellipse that started at (0,0) to the center of the embryo
Parameters: - rell (np.array, optional) – Ellipse array
- df (pd.DataFrame, optional) – Contains the columns x and y with 2 rows
Returns: self.fell
-
-
class
gbeflow.
VectorField
(name)¶ Bases:
object
Object to manage results and calculations from OpticalFlow.mat
See __init__ for more information
-
__init__
(name)¶ Initialize VectorField object by importing and transforming data
Parameters: name (str) – String specifying the name passed to OpticalFlowOutput Can include complete or partial path to file -
name
¶ str – Based on the parameter name
-
df
¶ pd.DataFrame – Dataframe of vectors produced by tidy_vector_data
-
tt
¶ np.array – Meshgrid for t dimension
-
xx
¶ np.array – Meshgrid for x dimension
-
yy
¶ np.array – Meshgrid for y dimension
-
vx
¶ np.array – X component of the velocity vector
-
vy
¶ np.array – Y component of the velocity vector
-
xval
¶ np.array – Sorted array of unique x values in xx meshgrid
-
yval
¶ np.array – Sorted array of unique y values in yy meshgrid
-
tval
¶ np.array – Sorted array of unique t values in tt meshgrid
-
starts
¶ pd.DataFrame – Dataframe initialized to contain starter points
-
-
add_image_data
(impath)¶ Imports a 3D (txy) dataset (czi or tiff) that matches the vector data
Parameters: impath (str) – Complete or relative path to image file Accepts either tif or czi file types -
img
¶ np.array – 3D array of image data
-
-
calc_track
(x0, y0, dt, tmin=0)¶ Calculate the trajectory of a single point through space and time
Parameters: - x0 (float) – X position of the starting point
- y0 (float) – Y position of the starting point
- dt (float) – Duration of time step
- trange (list or np.array) – Range of t values to iterate over for interpolation
Returns: track (np.array) – Array of dimension number_t_steps x 2
-
calc_track_set
(starts, dt, name='', timer=True, tmin=0)¶ Calculate trajectories for a set of points using a constant dt
Parameters: - starts (pd.DataFrame) – Dataframe with columns x and y containing one point per row
- dt (float) – Duration of time step
- name (str, optional) – Default, ‘’, encodes notes for a set of points
- timer (boolean, optional) – Default = True, activates tqdm progress timer
-
tracks
¶ pd.DataFrame – Dataframe with columns x,y,t,name,track Contains trajectories based on points in starts
-
initialize_interpolation
(timer=True)¶ Calculates interpolation of vx and vy for each timepoint Uses scipy.interpolate.RectBivariateSpline for optimal speed on meshgrid data
Parameters: timer (boolean, optional) – Default = True, activates tqdm progress timer -
Ldx
¶ list – List of dx interpolation objects for each t
-
Ldy
¶ list – List of dy interpolation objects for each t
-
interp_init
¶ boolean – Set to True after completion of interpolation for loop
-
-
pick_start_points
(notebook_url='localhost:8888')¶ Launches interactive bokeh plot to record user clicks
Parameters: notebook_url (str, optional) – Default ‘localhost:8888’, specifies jupyterlab url for interactive plotting Returns: p – Plotting object for bokeh plot
-
save_start_points
(p)¶ Uses the to_df method of the plotting object generated by pick_start_points to generate dataframe of click points
Parameters: p (object) – Generated by pick_start_points after clicks have been recorded -
starts
pd.DataFrame – Appends new recorded clicks to starts dataframe
-
-
-
gbeflow.
calc_embryo_theta
(line)¶ Given a line fit to each embryo, calculate the angle of rotation to align the embryo in the horizontal axis
Parameters: line (pd.DataFrame) – Dataframe returned by calc_line()
containing columns dy and dxReturns: line (pd.DataFrame) – Input dataframe with an additional column theta in degrees
-
gbeflow.
calc_flow_path
(xval, yval, vx, vy, x0, y0, dt, timer=True)¶ Calculate the trajectory of a point through the vector field over time
Parameters: - xval (np.array) – A list of unique x values that define the meshgrid of xx
- yval (np.array) – A corresponding list of unique y values that define the meshgrid of yy
- vx (np.array) – Array of shape (time,len(xval),len(yval)) containing the x velocity component
- vy (np.array) – Array of shape (time,len(xval),len(yval)) containing y velocity component
- dt (float) – Duration of the time step between intervals
- timer (boolean, optional) – Default true uses the tqdm timer as an iterator
Returns: Array of shape (time,2) containing x and y position of trajectory over time
-
gbeflow.
calc_line
(points)¶ Given two points calculate the line between the two points
Parameters: points (pd.DataFrame) – Dataframe containing the columns x, y, and ‘level_1’ (from df.reset_index()) Each row should contain data for a single point Returns: lines (pd.DataFrame) – Dataframe with columns that specify an equation for a line
-
gbeflow.
imshow
(img, figsize=(10, 8))¶ Show image using matplotlib and including colorbar
Parameters: - img (np.array) – 2D array to display
- figsize (tuple, optional) – Default = (10,8) Tuple passed to matplotlib to specify figure size
-
gbeflow.
load_avi_as_array
(path)¶ Use av module to load each frame from an avi movie into a numpy array
Parameters: path (str) – Complete or relative path to avi movie file for import Returns: np.array – Array with dimensions frames,x,y
-
gbeflow.
make_track_movie
(movie, df, c, name)¶ Plots the trajectory of points over time on each frame of an existing movie or array
Parameters: - movie (str) – Complete or relative path to the movie file to plot on
- df (pd.DataFrame) – Dataframe of tracks minimally with columns x,y,t
- c (str,color) – Currently only supports single color assignments, but data specific assignments could be possible
- name (str) – Root of filename for output file, without filetype
Returns: Saves a tif stack using path provided by name
-
gbeflow.
read_hyperstack
(fpath, dataset='channel1', tmax=166)¶ Read in an hdf5 hyperstack where each timepoint is a group containing two channels which are saved as datapoints
Warning
Doesn’t work on files that were written with
write_hyperstack()
. Tiff files are probably better.Parameters: - fpath (str) – Relative or absolute path to data file
- dataset (str, optional) – Default = ‘channel1’ Specifies the key to select a dataset from the h5 file
- tmax (int, optional) – Default = 166 Number of expected time frames
Returns: np.array – Array with h5 data in dimensions txy
-
gbeflow.
reshape_vector_data
(df)¶ Convert dataframe structure into a set of meshgrid arrays
Parameters: df (pd.DataFrame) – Dataframe with columns x,y,frame,vx,vy Returns: tt,xx,yy,vx,vy – Set of arrays of shape (len(T),len(X),len(Y))
-
gbeflow.
tidy_vector_data
(name)¶ Tidys csv files exported from matlab OpticalFlow
Parameters: name (str) – String specifying the name passed to OpticalFlowOutput Can include complete or partial path to file Returns: pd.DataFrame – Dataframe containing the following columns: frame, x, y, vx, vy
-
gbeflow.
write_hyperstack
(hst, fpath, dataset='channel1')¶ Write an h5 file in the same format as was read in
Parameters: - hst (np.array) – Array with dimensions txy
- fpath (str) – Complete path to output file with ‘.h5’
- dataset (str, optional) – Specifies name of the dataset in h5 file