コード例 #1
0
def test_sa_h5py_5():
    """
    Test querying if the HDF5 file is a storm-analysis file.
    """
    filename = "test_sa_hdf5.hdf5"
    h5_name = storm_analysis.getPathOutputTest(filename)
    storm_analysis.removeFile(h5_name)

    # Open empty file.
    with saH5Py.SAH5Py(h5_name, is_existing=False) as h5:
        pass
    assert (saH5Py.isSAHDF5(h5_name))

    # Create generic HDF5 file.
    f = h5py.File(h5_name, "w")
    f.close()
    assert (not saH5Py.isSAHDF5(h5_name))

    # Create Insight3 file.
    with i3w.I3Writer(h5_name) as i3:
        pass
    assert not (saH5Py.isSAHDF5(h5_name))
コード例 #2
0
def test_sa_h5py_5():
    """
    Test querying if the HDF5 file is a storm-analysis file.
    """
    filename = "test_sa_hdf5.hdf5"
    h5_name = storm_analysis.getPathOutputTest(filename)
    storm_analysis.removeFile(h5_name)

    # Open empty file.
    with saH5Py.SAH5Py(h5_name, is_existing = False) as h5:
        pass
    assert(saH5Py.isSAHDF5(h5_name))

    # Create generic HDF5 file.
    f = h5py.File(h5_name, "w")
    f.close()
    assert(not saH5Py.isSAHDF5(h5_name))

    # Create Insight3 file.
    with i3w.I3Writer(h5_name) as i3:
        pass
    assert not(saH5Py.isSAHDF5(h5_name))
コード例 #3
0
 def handleLoadLocs2(self):
     list_filename = QtWidgets.QFileDialog.getOpenFileName(
         self, "Load Localization List 2", self.directory,
         "*.bin *.hdf5")[0]
     if list_filename:
         if self.locs2_list is not None:
             self.locs2_list.cleanUp()
         self.directory = os.path.dirname(list_filename)
         if saH5Py.isSAHDF5(list_filename):
             self.locs2_list = MoleculeListHDF5(filename=list_filename,
                                                mtype="l2")
         else:
             self.locs2_list = MoleculeListI3(filename=list_filename,
                                              mtype="l2")
         self.locs2_table.showFields(self.locs2_list.getFields())
         self.incCurFrame(0)
コード例 #4
0
 def handleLoadLocs2(self):
     list_filename = QtWidgets.QFileDialog.getOpenFileName(self,
                                                           "Load Localization List 2",
                                                           self.directory,
                                                           "*.bin *.hdf5")[0]
     if list_filename:
         if self.locs2_list is not None:
             self.locs2_list.cleanUp()
         self.directory = os.path.dirname(list_filename)
         if saH5Py.isSAHDF5(list_filename):
             self.locs2_list = MoleculeListHDF5(filename = list_filename,
                                                mtype = "l2")
         else:
             self.locs2_list = MoleculeListI3(filename = list_filename,
                                              mtype = "l2")
         self.locs2_table.showFields(self.locs2_list.getFields())
         self.incCurFrame(0)
コード例 #5
0
ファイル: fitting.py プロジェクト: yanyuxiong/storm-analysis
def getPeakLocations(peak_filename, margin, pixel_size, sigma):
    """
    This is for if you already know where your want fitting to happen, as
    for example in a bead calibration movie and you just want to use the
    approximate locations as inputs for fitting.

    There are two choices for peak_locations file format:

    1. A text file with the peak x, y, height and background values as 
       white spaced columns (x and y positions are in pixels as determined 
       using visualizer).

       1.0 2.0 1000.0 100.0
       10.0 5.0 2000.0 200.0
       ...

    2. An HDF5 format localization file. This is treated in a similar
       fashion to the text file in that all of the locations are loaded.
       If the fields 'xsigma' or 'ysigma' exist they will be used for
       the initial X/Y sigma values of the localization.
    """
    if os.path.exists(peak_filename):
        print("Using peak starting locations specified in", peak_filename)
    elif os.path.exists(os.path.basename(peak_filename)):
        peak_filename = os.path.basename(peak_filename)
        print("Using peak starting locations specified in", peak_filename)

    # Check if the file is a storm-analysis HDF5 file.
    #
    if saH5Py.isSAHDF5(peak_filename):
        peak_locations_type = "hdf5"
        peak_locations = saH5Py.loadLocalizations(peak_filename)
        if not "ysigma" in peak_locations:
            if not "xsigma" in peak_locations:
                peak_locations["xsigma"] = numpy.ones(
                    peak_locations["x"].size) * sigma
            peak_locations["ysigma"] = peak_locations["xsigma"].copy()

    else:
        peak_locations_type = "text"

        # Load peak x,y locations.
        peak_locs = numpy.loadtxt(peak_filename, ndmin=2)

        # Create peak dictionary.
        peak_locations = {
            "background": peak_locs[:, 3],
            "height": peak_locs[:, 2],
            "x": peak_locs[:, 0],
            "y": peak_locs[:, 1]
        }

        peak_locations["xsigma"] = numpy.ones(peak_locations["x"].size) * sigma
        peak_locations["ysigma"] = numpy.ones(peak_locations["x"].size) * sigma
        peak_locations["z"] = numpy.zeros(peak_locations["x"].size)

    # Adjust positions for finding/fitting margin.
    peak_locations["x"] += margin
    peak_locations["y"] += margin

    print("Loaded", peak_locations["x"].size, "peak locations")
    #
    # We return is_text as the caller might want to do different things if
    # the file is text, like initialize the Z value.
    #
    return [peak_locations, peak_locations_type]