utils package¶
Module contents¶
This is a collection of helper code for various python utilities.
Submodules¶
utils.display module¶
Functions for the purposing displaying data. Most of this work is based on matplotlib, but provides more convenient wrappers.
-
utils.display.
get_color
(name, tuple_type=True)¶ Returns the RGBa values in array for plot colors using the solarized pallette.
- Parameters
name (str) – Color name
tuple_type (bool) – Whether or not to return a tuple or array
- Returns
color_rgb – Color RGBa value in array form
- Return type
array_like
-
utils.display.
gif
(data, file_name, dpi=80, interval=100)¶ This function will take an array with a temporal dimension (y, x, t) and save an animated gif.
- Parameters
data (array_like) – The input data array (y, x, t)
file_name (str) – The input file name
dpi (int) – The saved image DPI
interval (int) – The frame rate interval
-
utils.display.
im_movie
(data, duration=0.05, cm='gray')¶ Takes a 3D array (y, x, t) and displays the data as movie.
Note: this still needs to call the plt.show() command after running this command to get the stuff to display.
- Parameters
data (array_like) – 3D array to be displayed (y, x, t)
duration (float) – Duration of pause between frames
cm (str) – Colormap type
-
utils.display.
render
(X, colormap='gray', vmax=None, vmin=None)¶ This function takes a 3D array
X
and creates a tiled montage image.- Parameters
X (array_like) – 3D array (y, x, z)
colormap (str) – Colormap to be used
vmax (float) – Maximum value in display
vmin (float) – Minimum value in display
-
utils.display.
save_image
(data, cm, fn)¶ This function tries to save the image without borders for publication purposes. (Not sure if it works.)
- Parameters
data (array_like) – The image to be displayed
cm (str) – The colormap to be used
fn (str) – The saved image filename
-
utils.display.
set_plot
()¶ This function will generate figures with properly thick lines and large fonts.
utils.matutils module¶
-
utils.matutils.
matreader
(filename, keyName=None, memberName=None, verbose=False, save=False)¶ Reader for matlab .mat files.
- Parameters
filename (str) – Name of mat file being read
keyName (str, optional) – Name of the key that you are reading in
memberName (str, optional) – Name of the member if the underlining object is a Matlab struct
verbose (bool, optional) – Whether or not you want verbose output
save (bool, optional) – Option to save the file to a numpy file
- Returns
data – The data from the mat file in some form of numpy array
- Return type
array_like
utils.mkdir module¶
-
utils.mkdir.
create_tree
(pathName)¶ This function will take a folder saved in a different location and create an identical tree at a different location. These are controlled by the
names
variable, which is a dictionary that is hardcoded at the moment.- Parameters
pathName (str) – The path to the folder that you want to relocate
- Returns
pathName – The new folder full path
- Return type
str
-
utils.mkdir.
get_patient_number
(path)¶ Takes the path name form the DiBella pathname convention.
- Parameters
path (str) – The path to be analyzed
- Returns
patientNumber – The patient number
- Return type
str
utils.readhdf5 module¶
-
utils.readhdf5.
read_hdf5
(fileName, varName)¶ Read HDF5 file with some variable name as a dictionary key.
- Parameters
fileName (str) – The hdf5 file name
varName (str) – The hdf5 dictionary key name
- Returns
data – The data returned in a numpy array
- Return type
array_like
utils.roiselector module¶
Classes and functions that provide the ability to select some arbitrary region of interest (ROI) and return some statistics over that region.
-
class
utils.roiselector.
PolygonSelect
(data, zMiddle=None)¶ Bases:
object
This class reads in an image an allows the user to graphically select and ROI to generate statistics based on the underlying pixel values.
To do the selection: 1. Select points in the figure by enclosing them within a polygon. 2. Press the ‘esc’ key to start a new polygon. 3. Try holding the ‘shift’ key to move all of the vertices. 4. Try holding the ‘ctrl’ key to move a single vertex.
- Parameters
data (array_like) – Image data to be analyzed. Can be 2D (y,x) or 3D (y,x,t). The ROI is selected from a single frame and is applied to all time images subsequently
zMiddle (int) – The time frame to be used if the image is 3D
-
display_roi
(saveName=None)¶ Displays the ROI overlayed on top of the image used for the selection. Not displayed until plt.show() is called.
- Parameters
saveName (str) – The filename of the figure being saved
-
generate_mask
()¶ Generates a 2D (x,y) mask from the selected ROI.
- Returns
mask – Mask (y,x) of the selected ROI in 1’s (selection) and 0’s (not-selected)
- Return type
array_like
-
polygon_mean
()¶ Generate the mean values based on the selected ROI. Will calculated the mean on a per frame basis. If the input image is 2D, then a scalar is given. If it is 3D, then the means will be calculated over the ROI at each time frame and a 1D array will be given.
- Returns
meanValues – Mean values calculated over the ROI for each time frame
- Return type
str or array_like
-
utils.roiselector.
polygon_mean
(data, mask)¶ Given some input image and the mask of the ROI desired (1’s are pixels of interest and 0’s are not), find the mean value.
This function assumes a 2D image can calculates the mean as a scalar, but a temporal dimension can also be added. In that case, the same ROI is used at each time frame, and the output is given as a 1D array.
- Parameters
data (array_like) – 2D (y,x) or 3D (y,x,t) data array
mask (array_like) – 2D (y,x) array of 1’s and 0’s, pixels of 1’s are the pixels that are ultimately counted in the mean
- Returns
meanValues – Array of mean values if the input is 3D (temporal), a float is given it is strictly 2D
- Return type
array_like (or float)
-
utils.roiselector.
rectangle_mean
(image, zMiddle=None)¶ Based on some input image, calculate the mean over some selected rectangular ROI.
While this function does allow 3D images, the ROI is selected over one image and used for all images in the third dimension.
- Parameters
image (array_like) – Image used. Can be 2D (y,x) or 3D (y,x,z)
zMiddle (int) – The image used in the selection of the rectangle
- Returns
meanValue – The mean value for the ROI
- Return type
float or array_like
-
utils.roiselector.
rectangle_select
(image)¶ Do a mouseclick somewhere, move the mouse to some destination, release the button. This class gives click- and release-events and also draws a line or a box from the click-point to the actual mouseposition (within the same axes) until the button is released. Within the method ‘self.ignore()’ it is checked whether the button from eventpress and eventrelease are the same.
- Parameters
image (array_like) – 2D (y,x) or 3D (y,x,t) image to be analyzed. The ROI is drawn on only one frame, however
- Returns
coordinates – The vertices of the selection (x1, x2, y1, y2)
- Return type
tuple