PYME.localization.Test.fitTestJigSCMOS module

PYME.localization.Test.fitTestJigSCMOS.IQR(x)
PYME.localization.Test.fitTestJigSCMOS.emg(v, rg)
class PYME.localization.Test.fitTestJigSCMOS.fitTestJig(metadata, fitModule=None)

Bases: object

A class for testing fits.

Reads both simulation and analysis settings out of a metadata file, looking for the special metadata keys:
“Test.DefaultParams” - a vector containing the mean values of each model parameter to use when generating the

test data.

“Test.ParamJitter” - a vector containing the magnitude of variation to add to each parameter. Each test image is

generated with a different the model parameters randomly jittered in the range [DefaultParams - ParamJitter : DefaultParams + ParamJitter]. To generate data with a fixed set of parameter values, set ParamJitter to zeros

“Test.ROISize” - the half-size fo the ROI to simulate “Test.SimModule” - the name of the module used to simulate the data (if different from the analysis module) “Test.Background” - an additional background to add before noise generation and then subtract, to be used with fits

which do not have a background parameter and rely on the running background subtraction to provide an essentially background free image (some of the 3D fits).

“Test.PSFFile” - the name of a PSF file to use for simulation if not simulating with the same PSF which is used

for analysis [3D fits].

“Test.VarianceMapID” - variance map to use for simulation (if different from analysis) “Test.DarkMapID” - dark map to use for simulation (if different from analysis) “Test.FlatfieldMapID” - dark map to use for simulation (if different from analysis)

Initialize the fit test jig from metadata file

Parameters
metadata - PYME.IO.MetadataHandler.MetaDataHandler object

The metadata containing simulation and analysis settings. See custom ‘Test.XX’ keys in class description

fitModule - sting [optional, deprecated]

The name of the fit module to use. This overrides the settings in the metadata, but is only retained for backwards compatibility. You should set the fit module in the metadata.

calcMEs()
error(varName)

Calculate the error (fitted - expected) for the parameter given by varName

Parameters
varName - string

the name of the parameter to calculate the error for

Returns
array of differences between fitted and model values

Notes

Errors in intensity related parameters (e.g. Amplitude, background) will be incorrect due to conversion between photons and ADUs in camera model.

evalParams(params=None, param_jit=None)

Evaluate the given parameters (including parameter jitter if given)

Parameters
params - array

The mean value of the parameters. Overrides settings in metadata if provided

param_jit - array

The amount of parameter jitter. Overrides settings in metadata if provided

Returns
data, x0, y0, z0, p
data is the array containing the evaluated model
x0, y0 and z0 are the associated x y and z coordinates returned from evaluating the model
p is the parameter set used to evaluate the model
The primary use of this routine is to test parameter choices in the setup of a simulation,
i.e. merely a convenience routine.
Note that this method has some code duplication with runTests which is a bit unwieldy,
ideally this should be turned into a helper method used by runTests.
classmethod fromMDFile(mdfile)

Create a new fit test jig from a metadata file

Parameters
mdfile - string

the filename of the metadata file to use. The file should be in PYMEs ‘SimpleMDHandler’ (*.md) format.

Returns
fitTestJig instance
plotRes(varName, showStartParams=True, errThreshold=None, nPlotEvents=500, y1range=None)

Plot a scatter plot of the fitted vs the simulated values.

Note that this version also attempts to plot the starting parameters used in the fit, so will not work with fits which do not record their starting parameters (e.g. latGaussFitFR)

Parameters
varName - string

the name of the parameter to plot

errThreshold - float

optional, error threshold to filter fitResults only for events with fitError < errThreshold default: None (no filtering)

Returns
plotResSimp(varName, subplot=False)

Plot a scatter plot of the fitted vs the simulated values (simple version).

This just plots the fitted vs model values without errorbars or starting positions, so should work for all fits.

Parameters
varName - string

the name of the parameter to plot

Returns
property result_params
property results
runTests(params=None, param_jit=None, nTests=100)

Simulate and fit multiple single molecules. The results are stored in the class itself and can be accessed by other methods.

Parameters
params - array

The mean value of the parameters. Overrides settings in metadata if provided

param_jit - array

The amount of parameter jitter. Overrides settings in metadata if provided

nTests - int

The number of molecules to simulate

Returns
self.sim_params contains the parameters used for simulation
self.results contains the full fit results
self.result_params contains the fitted params
self.d2 is a list of the simulated data frames
NB: the x and y params in both results and result_params will be offset by half the region of interest size. i.e.
simulation co-ordinates are taken from the ROI centre and fitting coordinates are taken from the top left corner.
property sim_params