Beispiel #1
0
def initFitter(margin, parameters, roi_size, variances):
    """
    Create and return a mpFitDaoC.MPFitDao2D object.
    """
    sigma = parameters.getAttr("sigma")
    mfitter = mpFitDaoC.MPFitDao2D(n_channels=len(variances),
                                   roi_size=roi_size,
                                   sigma_range=[0.5 * sigma, 3.0 * sigma])

    # Pass variances to the fitting object.
    #
    for i in range(len(variances)):
        mfitter.setVariance(variances[i], i)

    # Load mappings.
    #
    if parameters.hasAttr("mapping"):
        if os.path.exists(parameters.getAttr("mapping")):
            mapping_filename = parameters.getAttr("mapping")
        else:
            raise Exception("Mapping file", parameters.getAttr("mapping"),
                            "does not exist.")

        mfitter.setMapping(*mpUtil.loadMappings(mapping_filename, margin))

    # Initialize weights.
    #
    mfitter.setWeights()

    return mfitter
def test_load_mappings_1():
    map_test_file = storm_analysis.getPathOutputTest("map.map")

    max_ch = 4
    mappings = {}
    for i in range(1,max_ch):
        j = i
        mappings[str(i) + "_0_x"] = numpy.arange(j,j+2.5,1.0)
        j += 0.1
        mappings[str(i) + "_0_y"] = numpy.arange(j,j+2.5,1.0)
        j += 0.1
        mappings["0_" + str(i) + "_x"] = numpy.arange(j,j+2.5,1.0)
        j += 0.1
        mappings["0_" + str(i) + "_y"] = numpy.arange(j,j+2.5,1.0)

    max_ch -= 1

    with open(map_test_file, 'wb') as fp:
        pickle.dump(mappings, fp)

    mappings = {}
    [xt_0toN, yt_0toN, xt_Nto0, yt_Nto0] = mpUtil.loadMappings(map_test_file, 0)
    assert(xt_0toN[0,0] == 0.0)
    assert(yt_0toN[0,0] == 0.0)
    assert(xt_Nto0[0,0] == 0.0)
    assert(yt_Nto0[0,0] == 0.0)

    assert(abs(xt_0toN[max_ch,2]-5.2) < 1.0e-6)
    assert(abs(yt_0toN[max_ch,2]-5.3) < 1.0e-6)
    assert(abs(xt_Nto0[max_ch,2]-5.0) < 1.0e-6)
    assert(abs(yt_Nto0[max_ch,2]-5.1) < 1.0e-6)
def initFitter(margin, parameters, roi_size, rqes, variances):
    """
    Create and return a mpFitDaoC.MPFitDao2D object.
    """
    # This fitter only supports 'MLE'
    assert (parameters.getAttr("fit_error_model") == 'MLE'
            ), "Only MLE fitting is supported."

    sigma = parameters.getAttr("sigma")
    mfitter = mpFitDaoC.MPFitDao2D(n_channels=len(variances),
                                   roi_size=roi_size,
                                   sigma_range=[0.5 * sigma, 3.0 * sigma])

    # Initialize fitters for each channel.
    #
    for i in range(len(variances)):
        mfitter.initializeChannel(rqes[i], variances[i], i)

    # Load mappings.
    #
    if parameters.hasAttr("mapping"):
        if os.path.exists(parameters.getAttr("mapping")):
            mapping_filename = parameters.getAttr("mapping")
        else:
            raise Exception("Mapping file", parameters.getAttr("mapping"),
                            "does not exist.")

        mfitter.setMapping(*mpUtil.loadMappings(mapping_filename, margin))

    # Initialize weights.
    #
    mfitter.setWeights()

    return mfitter
Beispiel #4
0
def test_load_mappings_1():
    map_test_file = storm_analysis.getPathOutputTest("map.map")

    max_ch = 4
    mappings = {}
    for i in range(1, max_ch):
        j = i
        mappings[str(i) + "_0_x"] = numpy.arange(j, j + 2.5, 1.0)
        j += 0.1
        mappings[str(i) + "_0_y"] = numpy.arange(j, j + 2.5, 1.0)
        j += 0.1
        mappings["0_" + str(i) + "_x"] = numpy.arange(j, j + 2.5, 1.0)
        j += 0.1
        mappings["0_" + str(i) + "_y"] = numpy.arange(j, j + 2.5, 1.0)

    max_ch -= 1

    with open(map_test_file, 'wb') as fp:
        pickle.dump(mappings, fp)

    mappings = {}
    [xt_0toN, yt_0toN, xt_Nto0,
     yt_Nto0] = mpUtil.loadMappings(map_test_file, 0)
    assert (xt_0toN[0, 0] == 0.0)
    assert (yt_0toN[0, 0] == 0.0)
    assert (xt_Nto0[0, 0] == 0.0)
    assert (yt_Nto0[0, 0] == 0.0)

    assert (abs(xt_0toN[max_ch, 2] - 5.2) < 1.0e-6)
    assert (abs(yt_0toN[max_ch, 2] - 5.3) < 1.0e-6)
    assert (abs(xt_Nto0[max_ch, 2] - 5.0) < 1.0e-6)
    assert (abs(yt_Nto0[max_ch, 2] - 5.1) < 1.0e-6)
Beispiel #5
0
def initFitter(margin, parameters, psf_objects, rqes, variances):
    """
    Create and return a mpFitArbC.MPXXFit object.
    """
    assert (len(psf_objects) == len(variances))
    #
    # FIXME: Not sure having two z ranges, one from the spline
    #        and one in the parameters is a good idea.
    #
    # Create the fitter object which will do the actual fitting. Unless specified
    # the fit for each channel is forced to have the same height.
    #
    if isinstance(psf_objects[0], psfFn.PSFFn):
        mfitter = mpFitArbC.MPPSFFnFit(independent_heights=parameters.getAttr(
            "independent_heights", 0),
                                       psf_objects=psf_objects)

    elif isinstance(psf_objects[0], pupilFn.PupilFunction):
        mfitter = mpFitArbC.MPPupilFnFit(
            independent_heights=parameters.getAttr("independent_heights", 0),
            psf_objects=psf_objects)

    elif isinstance(psf_objects[0], splineToPSF.SplineToPSF3D):
        mfitter = mpFitArbC.MPSplineFit(independent_heights=parameters.getAttr(
            "independent_heights", 0),
                                        psf_objects=psf_objects)

    # Initialize fitters for each channel.
    #
    for i in range(len(variances)):
        mfitter.initializeChannel(rqes[i], variances[i], i)

    # Load mappings.
    #
    if parameters.hasAttr("mapping"):
        if os.path.exists(parameters.getAttr("mapping")):
            mapping_filename = parameters.getAttr("mapping")
        else:
            raise Exception("Mapping file", parameters.getAttr("mapping"),
                            "does not exist.")

        mfitter.setMapping(*mpUtil.loadMappings(mapping_filename, margin))

    # Load channel Cramer-Rao weights if available.
    #
    weights = None
    if parameters.hasAttr("weights"):
        with open(parameters.getAttr("weights"), 'rb') as fp:
            weights = pickle.load(fp)
    mfitter.setWeights(weights)

    return mfitter
def initFitter(margin, parameters, psf_objects, rqes, variances):
    """
    Create and return a mpFitArbC.MPXXFit object.
    """
    # This fitter only supports 'MLE'
    assert (parameters.getAttr("fit_error_model") == 'MLE'), "Only MLE fitting is supported."
    
    assert(len(psf_objects) == len(variances))
    #
    # FIXME: Not sure having two z ranges, one from the spline
    #        and one in the parameters is a good idea.
    #
    # Create the fitter object which will do the actual fitting. Unless specified
    # the fit for each channel is forced to have the same height.
    #
    if isinstance(psf_objects[0], psfFn.PSFFn):
        mfitter = mpFitArbC.MPPSFFnFit(independent_heights = parameters.getAttr("independent_heights", 0),
                                       psf_objects = psf_objects)

    elif isinstance(psf_objects[0], pupilFn.PupilFunction):
        mfitter = mpFitArbC.MPPupilFnFit(independent_heights = parameters.getAttr("independent_heights", 0),
                                         psf_objects = psf_objects)

    elif isinstance(psf_objects[0], splineToPSF.SplineToPSF3D):
        mfitter = mpFitArbC.MPSplineFit(independent_heights = parameters.getAttr("independent_heights", 0),
                                        psf_objects = psf_objects)

    # Initialize fitters for each channel.
    #
    for i in range(len(variances)):
        mfitter.initializeChannel(rqes[i], variances[i], i)

    # Load mappings.
    #
    if parameters.hasAttr("mapping"):
        if os.path.exists(parameters.getAttr("mapping")):
            mapping_filename = parameters.getAttr("mapping")
        else:
            raise Exception("Mapping file", parameters.getAttr("mapping"), "does not exist.")

        mfitter.setMapping(*mpUtil.loadMappings(mapping_filename, margin))

    # Load channel Cramer-Rao weights if available.
    #
    weights = None
    if parameters.hasAttr("weights"):
        with open(parameters.getAttr("weights"), 'rb') as fp:
            weights = pickle.load(fp)
    mfitter.setWeights(weights)
    
    return mfitter
def test_load_mappings_2():
    [xt_0toN, yt_0toN, xt_Nto0, yt_Nto0] = mpUtil.loadMappings(None, 0)
    assert(xt_0toN.shape[0] == 1)
    assert(abs(xt_0toN[0,0]) < 1.0e-6)
    assert(abs(xt_0toN[0,1] - 1.0) < 1.0e-6)
    assert(abs(xt_0toN[0,2]) < 1.0e-6)
Beispiel #8
0
def test_load_mappings_2():
    [xt_0toN, yt_0toN, xt_Nto0, yt_Nto0] = mpUtil.loadMappings(None, 0)
    assert (xt_0toN.shape[0] == 1)
    assert (abs(xt_0toN[0, 0]) < 1.0e-6)
    assert (abs(xt_0toN[0, 1] - 1.0) < 1.0e-6)
    assert (abs(xt_0toN[0, 2]) < 1.0e-6)