Skip to content

Scripting

alexblaessle edited this page Mar 18, 2016 · 1 revision

Scripting PyFRAP

Having a lot of FRAP datasets often requires repetitive tasks. Here we explain how to set up a python script using the modules and classes provided in PyFRAP.

Import pyfrp

We first import the PyFRAP molecule class so that we can create PyFRAP data structures. We are also importing pyfrp_plot_module, so that we can launch the FRAP boundary selector later.

	from pyfrp.modules import pyfrp_plot_module
	from pyfrp.subclasses import pyfrp_molecule

Import FRAP dataset

Experiment specific parameters

We first have to define all microscope parameters from the experiment:

	center=[256,256]
	cylinderHeight=90.3332804037
	imagingRadius=294.103867936
	imagingDepth=40
	dataResMu=566.79
	frameInterval=1
	sideLengthBleachedMu=192.68488493739596

Setting up data structure

Now we create a root molecule to which we can add our new FRAP experiment:

	mol=pyfrp_molecule.molecule("TestMolecule")

We can create and add a new embryo by calling newEmbryo:

	emb=mol.newEmbryo("TestEmbryo")

Insert experiment properties into PyFRAP objects

Set filepath to folder containing time-lapse images and update file list:

	emb.setDataFolder("path/to/recover/files")
	emb.updateFileList()

Set data resolution (experiment specific) in mu/px:

	emb.setDataResMu(dataResMu)

Launch little dialog to crop center and radius of experiment:

	boundarySelector=pyfrp_plot_module.FRAPBoundarySelector(emb)
	center,imagingRadius=boundarySelector.getResults()

Define Sidelength of bleached ROI:

	emb.setSideLengthBleachedMu(sideLengthBleachedMu)

Define depth of imaging:

	emb.setSliceDepthMu(imagingDepth)

Set geometry to be cylindrical:

	emb.setGeometry2Cylinder(center,cylinderRadius,-cylinderHeight)

Update geometry properties in geo-file:

	emb.geometry.updateGeoFile()

Create default ROIs and create optimal All ROI:

	emb.genDefaultROIs(emb.geometry.getCenter(),imagingRadius)
	emb.getOptimalAllROI()

Set frame interval (experiment specific):

	emb.setFrameInterval(frameInterval)

Create Simulation:

	sim=emb.newSimulation()

Meshing and indexing

Set mesh volSize and generate mesh:

	sim.mesh.setVolSizePx(25.)
	sim.mesh.genMesh()

Compute Indices of ROIs:

	emb.computeROIIdxs() 

Analysis settings

Create analysis and turn on median and gaussian filter. Turn the rest off:

	emb.newAnalysis()
	emb.analysis.setNorm(False)
	emb.analysis.setGaussian(True)
	emb.analysis.setMedian(True)
	emb.analysis.setQuad(False)
	emb.analysis.setBkgd(False)
	emb.analysis.setFlatten(False)

Fitting settings

Create new fit:

	fit=emb.newFit('Testfit')

Add some ROIs to be fitted, turn on pinning and production fitting.

	fit.addROIByName('Bleached Square')
	fit.addROIByName('Slice')

	fit.setFitDegr(False)
	fit.setFitProd(True)

	fit.setEqu(True)
	fit.setFitPinned(True)

	fit.setOptMeth('Constrained Nelder-Mead')

Run Analysis

Run analysis, simulation and fitting:

	emb.quickAnalysis()

Inspect results

Plot fit and print out results:

	fit.plotFit()
	fit.printResults()