Esempio n. 1
0
def initFindAndFit(parameters):
    """
    Initialize and return a SplinerFinderFitter object.
    """
    # Create spline object.
    spline_fn = splineToPSF.loadSpline(parameters.getAttr("spline"))

    # Create peak finder.
    finder = fitting.PeakFinderArbitraryPSF(parameters=parameters,
                                            psf_object=spline_fn)

    # Create cubicFitC.CSplineFit object.
    mfitter = initFitter(finder, parameters, spline_fn)

    # Create peak fitter.
    fitter = fitting.PeakFitterArbitraryPSF(mfitter=mfitter,
                                            parameters=parameters)

    # Specify which properties we want from the analysis.
    properties = [
        "background", "error", "height", "iterations", "significance", "sum",
        "x", "y", "z"
    ]

    return fitting.PeakFinderFitter(peak_finder=finder,
                                    peak_fitter=fitter,
                                    properties=properties)
Esempio n. 2
0
    def __init__(self, parameters):
        fitting.PeakFinder.__init__(self, parameters)
        self.height_rescale = []
        self.mfilter = []
        self.mfilter_z = []
        self.z_value = []

        # Load the spline.
        self.s_to_psf = splineToPSF.loadSpline(parameters.getAttr("spline"))

        # Update margin based on the spline size.
        old_margin = self.margin
        self.margin = int((self.s_to_psf.getSize() + 1)/4 + 2)

        self.mfilter_z = parameters.getAttr("z_value", [0.0])
        for zval in self.mfilter_z:
            self.z_value.append(self.s_to_psf.getScaledZ(zval))

        if parameters.hasAttr("peak_locations"):

            # Correct for any difference in the margins.
            self.peak_locations[:,utilC.getXCenterIndex()] += self.margin - old_margin
            self.peak_locations[:,utilC.getYCenterIndex()] += self.margin - old_margin

            # Provide the "correct" starting z value.
            self.peak_locations[:,utilC.getZCenterIndex()] = self.z_value[0]
Esempio n. 3
0
    def __init__(self, parameters):
        self.fista_iterations = parameters.getAttr("fista_iterations")
        self.fista_lambda = parameters.getAttr("fista_lambda")
        self.fista_number_z = parameters.getAttr("fista_number_z")
        self.fista_threshold = parameters.getAttr("fista_threshold")
        self.fista_timestep = parameters.getAttr("fista_timestep")
        self.fista_upsample = parameters.getAttr("fista_upsample")
        self.spline_file = parameters.getAttr("spline")

        self.rball = None
        self.wbgr = None

        # Load spline to get size.
        self.spline_file = parameters.getAttr("spline")
        s_to_psf = splineToPSF.loadSpline(self.spline_file)

        # Update margin based on the spline size.
        self.margin = int((s_to_psf.getSize() + 1) / 4 + 2)

        if parameters.hasAttr("rb_radius"):
            self.rball = rollingBall.RollingBall(
                parameters.getAttr("rb_radius"),
                parameters.getAttr("rb_sigma"))
        else:
            self.wbgr_iterations = parameters.getAttr("wbgr_iterations")
            self.wbgr_threshold = parameters.getAttr("wbgr_threshold")
            self.wbgr_wavelet_level = parameters.getAttr("wbgr_wavelet_level")
            self.wbgr = waveletBGR.WaveletBGR()

        self.fdecon = None
    def __init__(self, parameters):
        fitting.PeakFinder.__init__(self, parameters)
        self.height_rescale = []
        self.mfilter = []
        self.mfilter_z = []
        self.z_value = []

        # Load the spline.
        self.s_to_psf = splineToPSF.loadSpline(parameters.getAttr("spline"))

        # Update margin based on the spline size.
        old_margin = self.margin
        self.margin = int((self.s_to_psf.getSize() + 1)/4 + 2)

        self.mfilter_z = parameters.getAttr("z_value", [0.0])
        for zval in self.mfilter_z:
            self.z_value.append(self.s_to_psf.getScaledZ(zval))

        if parameters.hasAttr("peak_locations"):

            # Correct for any difference in the margins.
            self.peak_locations[:,utilC.getXCenterIndex()] += self.margin - old_margin
            self.peak_locations[:,utilC.getYCenterIndex()] += self.margin - old_margin

            # Provide the "correct" starting z value.
            self.peak_locations[:,utilC.getZCenterIndex()] = self.z_value[0]
Esempio n. 5
0
    def __init__(self, parameters):
        self.fista_iterations = parameters.getAttr("fista_iterations")
        self.fista_lambda = parameters.getAttr("fista_lambda")
        self.fista_number_z = parameters.getAttr("fista_number_z")
        self.fista_threshold = parameters.getAttr("fista_threshold")
        self.fista_timestep = parameters.getAttr("fista_timestep")
        self.fista_upsample = parameters.getAttr("fista_upsample")
        self.spline_file = parameters.getAttr("spline")

        self.rball = None
        self.wbgr = None

        # Load spline to get size.
        self.spline_file = parameters.getAttr("spline")
        s_to_psf = splineToPSF.loadSpline(self.spline_file)

        # Update margin based on the spline size.
        self.margin = int((s_to_psf.getSize() + 1)/4 + 2)
        
        if parameters.hasAttr("rb_radius"):
            self.rball = rollingBall.RollingBall(parameters.getAttr("rb_radius"),
                                                 parameters.getAttr("rb_sigma"))
        else:
            self.wbgr_iterations = parameters.getAttr("wbgr_iterations")
            self.wbgr_threshold = parameters.getAttr("wbgr_threshold")
            self.wbgr_wavelet_level = parameters.getAttr("wbgr_wavelet_level")
            self.wbgr = waveletBGR.WaveletBGR()
            
        self.fdecon = None
def initFindAndFit(parameters):
    """
    Initialize and return a SplinerFISTAFinderFitter object.
    """
    # Create spline object.
    spline_fn = splineToPSF.loadSpline(parameters.getAttr("spline"))    
    
    # Create peak finder.
    finder = SplinerFISTAPeakFinder(parameters = parameters,
                                    psf_object = spline_fn)

    # Create cubicFitC.CSplineFit object.
    mfitter = findPeaksStd.initFitter(finder, parameters, spline_fn)
    
    # Create peak fitter.
    fitter = fitting.PeakFitterArbitraryPSF(mfitter = mfitter,
                                            parameters = parameters)

    # Specify which properties we want from the analysis.
    properties = ["background", "error", "height", "sum", "x", "y", "z"]
    
    return fitting.PeakFinderFitter(peak_finder = finder,
                                    peak_fitter = fitter,
                                    properties = properties)
Esempio n. 7
0
    def __init__(self,
                 image_size,
                 spline_file,
                 number_zvals,
                 timestep,
                 upsample=1,
                 check_psf=True):
        """
        Upsample is the multiplier to use for re-sizing the image,
        for example upsample = 2 means to enlarge by 2x.
        """

        self.background = numpy.zeros(image_size)
        self.psf_heights = []
        self.upsample = int(upsample)

        im_size_x, im_size_y = image_size
        size_x = im_size_x * self.upsample
        size_y = im_size_y * self.upsample

        # Load spline.
        s_to_psf = splineToPSF.loadSpline(spline_file)

        # Get size in X and Y.
        self.spline_size_x = self.spline_size_y = s_to_psf.getSize()

        # Calculate z values to use if 3D.
        if (s_to_psf.getType() == "3D"):
            self.z_min = s_to_psf.getZMin()
            self.z_max = s_to_psf.getZMax()
            z_step = (self.z_max - self.z_min) / float(number_zvals - 1.0)
            self.zvals = []
            for i in range(number_zvals):
                self.zvals.append(self.z_min + float(i) * z_step)
        else:
            self.z_min = 0.0
            self.z_max = 1.0
            self.zvals = [0.0]

        psfs = numpy.zeros((size_x, size_y, len(self.zvals)))

        # Add PSFs.
        for i in range(len(self.zvals)):
            psfs[:, :, i] = s_to_psf.getPSF(self.zvals[i],
                                            shape=(im_size_x, im_size_y),
                                            up_sample=upsample,
                                            normalize=True)
            self.psf_heights.append(numpy.max(psfs[:, :, i]))
            #print "fista_decon", i, numpy.max(psfs[:,:,i])

        # Check PSFs.
        if check_psf:
            import os
            import storm_analysis.sa_library.daxwriter as daxwriter

            psf_data = daxwriter.DaxWriter(
                os.path.join(os.path.dirname(spline_file),
                             "fista_decon_psf.dax"), psfs.shape[0],
                psfs.shape[1])
            for i in range(psfs.shape[2]):
                temp = psfs[:, :, i]
                psf_data.addFrame(1000.0 * temp / numpy.max(temp))
            psf_data.close()

        if 0:
            # Python solver (useful for debugging).
            print("Using Python solver.")
            self.fsolver = fista_3d.FISTA(psfs, timestep)
        else:
            # C solver (about 4x faster).
            print("Using C solver.")
            self.fsolver = fistaFFTC.FISTA(psfs, timestep)
Esempio n. 8
0
    parser.add_argument('--output', dest='output', type=str, required=True,
                        help = "The name of the .tif file to save the results in.")

    args = parser.parse_args()

    # Load parameters
    parameters = params.ParametersSplinerFISTA().initFromFile(args.settings)

    # Open movie and load the first frame.
    movie_data = datareader.inferReader(args.movie)
    [x_size, y_size, z_size] = movie_data.filmSize()
    image = (movie_data.loadAFrame(0) - parameters.getAttr("camera_offset"))/parameters.getAttr("camera_gain")
    image = image.astype(numpy.float)

    # Load spline.
    psf_object = splineToPSF.loadSpline(parameters.getAttr("spline"))
    
    # Do FISTA deconvolution.
    fdecon = FISTADecon(image.shape,
                        psf_object,
                        parameters.getAttr("fista_number_z"),
                        parameters.getAttr("fista_timestep"))

    if False:
        # Wavelet background removal.
        wbgr = waveletBGR.WaveletBGR()
        background = wbgr.estimateBG(image,
                                     parameters.getAttr("wbgr_iterations"),
                                     parameters.getAttr("wbgr_threshold"),
                                     parameters.getAttr("wbgr_wavelet_level"))
    else:
    def __init__(self, parameters):
        super(MPPeakFinder, self).__init__(parameters)

        self.atrans = [None]
        self.backgrounds = []
        self.bg_filter = None
        self.bg_filter_sigma = parameters.getAttr("bg_filter_sigma")
        self.check_mode = False
        self.height_rescale = []
        self.images = []
        self.mapping_filename = None
        self.mfilters = []
        self.mfilters_z = []
        self.mpu = None
        self.n_channels = 0
        self.s_to_psfs = []
        self.variances = []
        self.vfilters = []
        self.xt = []
        self.yt = []
        self.z_values = []

        # Print warning about check mode
        if self.check_mode:
            print("Warning: Running in check mode.")

        # Load the splines.
        for spline_attr in mpUtilC.getSplineAttrs(parameters):
            self.s_to_psfs.append(
                splineToPSF.loadSpline(parameters.getAttr(spline_attr)))
            self.n_channels += 1

        # Assert that all the splines are the same size.
        for i in range(1, len(self.s_to_psfs)):
            assert (self.s_to_psfs[0].getSize() == self.s_to_psfs[i].getSize())

        #
        # Update margin based on the spline size. Note the assumption
        # that all of the splines are the same size, or at least smaller
        # than the spline for plane 0.
        #
        old_margin = self.margin
        self.margin = int((self.s_to_psfs[0].getSize() + 1) / 4 + 2)

        # Load the plane to plane mapping data & create affine transform objects.
        mappings = {}
        if parameters.hasAttr("mapping"):
            if os.path.exists(parameters.getAttr("mapping")):
                self.mapping_filename = parameters.getAttr("mapping")
                with open(parameters.getAttr("mapping"), 'rb') as fp:
                    mappings = pickle.load(fp)

        # Use self.margin - 1, because we added 1 to the x,y coordinates when we saved them.
        for i in range(self.n_channels - 1):
            self.xt.append(
                mpUtilC.marginCorrect(mappings["0_" + str(i + 1) + "_x"],
                                      self.margin - 1))
            self.yt.append(
                mpUtilC.marginCorrect(mappings["0_" + str(i + 1) + "_y"],
                                      self.margin - 1))
            self.atrans.append(
                affineTransformC.AffineTransform(xt=self.xt[i], yt=self.yt[i]))

        #
        # Note the assumption that the splines for each plane all use
        # the same z scale / have the same z range.
        #
        self.mfilters_z = parameters.getAttr("z_value", [0.0])
        for zval in self.mfilters_z:
            self.z_values.append(self.s_to_psfs[0].getScaledZ(zval))

        if parameters.hasAttr("peak_locations"):

            # Correct for any difference in the margins.
            self.peak_locations[:, utilC.getXCenterIndex(
            )] += self.margin - old_margin
            self.peak_locations[:, utilC.getYCenterIndex(
            )] += self.margin - old_margin

            # Provide the "correct" starting z value.
            #
            # FIXME: Should also allow the user to specify the peak z location
            #        as any fixed value could be so far off for some of the
            #        localizations that the fitting will fail.
            #
            self.peak_locations[:, utilC.getZCenterIndex()] = self.z_values[0]