def runPlaneWeighting(xml, output, background, photons, no_plots=False): """ xml - The analysis XML file. output - File name to save the weights in. background - Per pixel background in e- for each plane (as a list). photons - Integrated peak intensity in e-. no_plots - Don't show any plots. """ parameters = params.ParametersMultiplaneArb().initFromFile(xml) [weights, variances] = planeWeighting(parameters, background, photons) with open(output, 'wb') as fp: pickle.dump(weights, fp) # # Plot results. # if not no_plots: for i, name in enumerate(["bg", "h", "x", "y", "z"]): # Plot per channel standard deviation. sd = numpy.sqrt(variances[i]) x = numpy.arange(sd.shape[0]) fig = pyplot.figure() for j in range(sd.shape[1]): pyplot.plot(x, sd[:, j]) sd = 1.0 / numpy.sqrt(numpy.sum(1.0 / variances[i], axis=1)) pyplot.plot(x, sd, color="black") pyplot.title(name) pyplot.xlabel("scaled z") pyplot.ylabel("standard deviation (nm)") pyplot.ylim(ymin=0) pyplot.show()
def testingParametersMC(): """ Create a Multiplane parameters object. """ params = parameters.ParametersMultiplaneArb() params.setAttr("max_frame", "int", -1) params.setAttr("start_frame", "int", -1) params.setAttr("background_sigma", "float", 8.0) params.setAttr("find_max_radius", "int", 2) params.setAttr("independent_heights", "int", settings.independent_heights) params.setAttr("iterations", "int", settings.iterations) params.setAttr("mapping", "filename", "map.map") params.setAttr("no_fitting", "int", 0) params.setAttr("pixel_size", "float", settings.pixel_size) params.setAttr("sigma", "float", 1.5) params.setAttr("threshold", "float", 6.0) params.setAttr("weights", "filename", "weights.npy") params.setAttr("z_value", "float-array", settings.z_value) params.setAttr("channel0_cal", "filename", "calib.npy") params.setAttr("channel1_cal", "filename", "calib.npy") params.setAttr("channel2_cal", "filename", "calib.npy") params.setAttr("channel3_cal", "filename", "calib.npy") params.setAttr("channel0_ext", "string", "_c1.dax") params.setAttr("channel1_ext", "string", "_c2.dax") params.setAttr("channel2_ext", "string", "_c3.dax") params.setAttr("channel3_ext", "string", "_c4.dax") params.setAttr("channel0_offset", "int", 0) params.setAttr("channel1_offset", "int", 0) params.setAttr("channel2_offset", "int", 0) params.setAttr("channel3_offset", "int", 0) params.setAttr("spline0", "filename", "c1_psf.spline") params.setAttr("spline1", "filename", "c2_psf.spline") params.setAttr("spline2", "filename", "c3_psf.spline") params.setAttr("spline3", "filename", "c4_psf.spline") # Do tracking (localization color analysis depends on the tracks). params.setAttr("descriptor", "string", "1") params.setAttr("radius", "float", "1.0") params.setAttr("max_z", "float", str(0.001 * settings.psf_z_range)) params.setAttr("min_z", "float", str(-0.001 * settings.psf_z_range)) # Don't do drift-correction. params.setAttr("d_scale", "int", 2) params.setAttr("drift_correction", "int", 0) params.setAttr("frame_step", "int", 500) params.setAttr("z_correction", "int", 0) return params
def multiplaneXML(): """ Create a Multiplane parameters object. """ params = parameters.ParametersMultiplaneArb() params.setAttr("max_frame", "int", -1) params.setAttr("start_frame", "int", -1) params.setAttr("background_sigma", "float", 8.0) params.setAttr("find_max_radius", "int", 2) params.setAttr("independent_heights", "int", 0) params.setAttr("iterations", "int", 20) params.setAttr("mapping", "filename", "map.map") params.setAttr("no_fitting", "int", 0) params.setAttr("pixel_size", "float", pixel_size) params.setAttr("sigma", "float", 1.5) params.setAttr("threshold", "float", 6.0) params.setAttr("weights", "filename", "weights.npy") params.setAttr("z_value", "float-array", z_value) params.setAttr("channel0_cal", "filename", "calib.npy") params.setAttr("channel1_cal", "filename", "calib.npy") params.setAttr("channel0_ext", "string", "_c1.dax") params.setAttr("channel1_ext", "string", "_c2.dax") params.setAttr("channel0_offset", "int", 0) params.setAttr("channel1_offset", "int", 0) params.setAttr("spline0", "filename", "c1_psf.spline") params.setAttr("spline1", "filename", "c2_psf.spline") # Don't do tracking. params.setAttr("descriptor", "string", "1") params.setAttr("radius", "float", "0.0") params.setAttr("max_z", "float", str(spline_z_range + 0.001)) params.setAttr("min_z", "float", str(-(spline_z_range - 0.001))) # Don't do drift-correction. params.setAttr("d_scale", "int", 2) params.setAttr("drift_correction", "int", 0) params.setAttr("frame_step", "int", 500) params.setAttr("z_correction", "int", 0) params.toXMLFile("multiplane.xml")
def testingParameters(): """ Create a Multiplane parameters object. """ params = parameters.ParametersMultiplaneArb() params.setAttr("max_frame", "int", -1) params.setAttr("start_frame", "int", -1) params.setAttr("background_sigma", "float", 8.0) params.setAttr("find_max_radius", "int", 2) params.setAttr("independent_heights", "int", settings.independent_heights) params.setAttr("iterations", "int", settings.iterations) params.setAttr("mapping", "filename", "map.map") params.setAttr("no_fitting", "int", 0) params.setAttr("pixel_size", "float", settings.pixel_size) params.setAttr("sigma", "float", 1.5) params.setAttr("threshold", "float", 6.0) params.setAttr("weights", "filename", "weights.npy") params.setAttr("z_value", "float-array", settings.z_value) params.setAttr("channel0_cal", "filename", "calib.npy") params.setAttr("channel1_cal", "filename", "calib.npy") params.setAttr("channel0_ext", "string", "_c1.dax") params.setAttr("channel1_ext", "string", "_c2.dax") params.setAttr("channel0_offset", "int", 0) params.setAttr("channel1_offset", "int", 0) params.setAttr("pupilfn0", "filename", "c1_pupilfn.pfn") params.setAttr("pupilfn1", "filename", "c2_pupilfn.pfn") # Don't do tracking. params.setAttr("descriptor", "string", "1") params.setAttr("radius", "float", "0.0") params.setAttr("max_z", "float", str(settings.pupilfn_z_range)) params.setAttr("min_z", "float", str(-settings.pupilfn_z_range)) # Don't do drift-correction. params.setAttr("d_scale", "int", 2) params.setAttr("drift_correction", "int", 0) params.setAttr("frame_step", "int", 500) params.setAttr("z_correction", "int", 0) return params
def analyze(base_name, mlist_name, settings_name): # Load parameters. parameters = params.ParametersMultiplaneArb().initFromFile(settings_name) # Create finding and fitting object. finder = findPeaksStd.initFindAndFit(parameters) # Create multiplane (sCMOS) reader. reader = analysisIO.MPMovieReader(base_name = base_name, parameters = parameters) # Create multiplane localization file(s) writer. data_writer = analysisIO.MPDataWriter(data_file = mlist_name, parameters = parameters, sa_type = "Multiplane-Arb") stdAnalysis.standardAnalysis(finder, reader, data_writer, parameters)
def testingParameters(psf_model): """ Create a Multiplane parameters object. """ params = parameters.ParametersMultiplaneArb() params.setAttr("max_frame", "int", -1) params.setAttr("start_frame", "int", -1) params.setAttr("background_sigma", "float", 8.0) params.setAttr("find_max_radius", "int", 2) params.setAttr("independent_heights", "int", settings.independent_heights) params.setAttr("iterations", "int", settings.iterations) params.setAttr("mapping", "filename", "map.map") params.setAttr("no_fitting", "int", 0) params.setAttr("pixel_size", "float", settings.pixel_size) params.setAttr("sigma", "float", 1.5) params.setAttr("threshold", "float", 6.0) params.setAttr("weights", "filename", "weights.npy") params.setAttr("z_value", "float-array", settings.z_value) params.setAttr("channel0_cal", "filename", "calib.npy") params.setAttr("channel1_cal", "filename", "calib.npy") params.setAttr("channel0_ext", "string", "_c1.dax") params.setAttr("channel1_ext", "string", "_c2.dax") params.setAttr("channel0_offset", "int", 0) params.setAttr("channel1_offset", "int", 0) if (psf_model == "psf_fft"): params.setAttr("psf0", "filename", "c1_psf_fft.psf") params.setAttr("psf1", "filename", "c2_psf_fft.psf") elif (psf_model == "pupilfn"): params.setAttr("pupilfn0", "filename", "c1_pupilfn.pfn") params.setAttr("pupilfn1", "filename", "c2_pupilfn.pfn") elif (psf_model == "spline"): params.setAttr("spline0", "filename", "c1_psf.spline") params.setAttr("spline1", "filename", "c2_psf.spline") else: raise Exception("Unknown PSF model " + args.psf_model) # Don't do tracking. params.setAttr("descriptor", "string", "1") params.setAttr("radius", "float", "0.0") if (psf_model == "psf_fft"): params.setAttr("max_z", "float", str(settings.psf_z_range + 0.001)) params.setAttr("min_z", "float", str(-(settings.psf_z_range - 0.001))) elif (psf_model == "pupilfn"): params.setAttr("max_z", "float", str(settings.pupilfn_z_range)) params.setAttr("min_z", "float", str(-settings.pupilfn_z_range)) elif (psf_model == "spline"): params.setAttr("max_z", "float", str(settings.spline_z_range + 0.001)) params.setAttr("min_z", "float", str(-(settings.spline_z_range - 0.001))) # Don't do drift-correction. params.setAttr("d_scale", "int", 2) params.setAttr("drift_correction", "int", 0) params.setAttr("frame_step", "int", 500) params.setAttr("z_correction", "int", 0) # 'peak_locations' testing. if hasattr(settings, "peak_locations") and (settings.peak_locations is not None): params.setAttr("peak_locations", "filename", settings.peak_locations) return params