def loadI3FileNumpy(filename, verbose=True): with open(filename, "rb") as fp: # Read header, this also moves the file pointer to # the start of the (binary) localization data. [frames, molecules, version, status] = readHeader(fp, verbose) # Read in the localizations. # # This could include garbage at the end if the file # was created by Insight3 or has meta-data. # data = numpy.fromfile(fp, dtype=i3dtype.i3DataType()) # # If the analysis crashed, the molecule list may still # be valid, but the molecule number could be incorrect. # # Note: This will get confused in the hopefully unlikely # event that there is meta-data but the molecules # field was not properly updated. # if (molecules == 0): print("File appears empty, trying to load anyway.") return data # Return only the valid localization data. return data[:][0:molecules]
def loadI3FileNumpy(filename, verbose = True): with open(filename, "rb") as fp: # Read header. # # This also moves the file pointer to the start of the # (binary) localization data. # [frames, molecules, version, status] = readHeader(fp, verbose) # Check status. # # If this is not 6 then this file was not closed # properly, so we'll just stop here. # if (status != 6): print(filename, "was not closed properly, possibly corrupted.") return None # Read in the localizations. # # This could include garbage at the end if the file # was created by Insight3 or has meta-data. # data = numpy.fromfile(fp, dtype=i3dtype.i3DataType()) # Return only the valid localization data. return data[:][0:molecules]
def getMolecule(self, molecule): if (molecule < self.molecules): if (type(self.localizations) == type(numpy.array([]))): return self.localizations[molecule:molecule + 1] else: cur = self.fp.tell() self.fp.seek(16 + molecule * self.record_size) data = numpy.fromfile(self.fp, dtype=i3dtype.i3DataType(), count=1) self.fp.seek(cur) return data
def getMolecule(self, molecule): if(molecule < self.molecules): if (type(self.localizations) == type(numpy.array([]))): return self.localizations[molecule:molecule+1] else: cur = self.fp.tell() self.fp.seek(16 + molecule*self.record_size) data = numpy.fromfile(self.fp, dtype=i3dtype.i3DataType(), count=1) self.fp.seek(cur) return data
def getMoleculesInFrameRange(self, start, stop, good_only=True): start_mol_num = self.findFrame(start) stop_mol_num = self.findFrame(stop) if (type(self.localizations) == type(numpy.array([]))): data = self.localizations[start_mol_num:stop_mol_num] else: cur = self.fp.tell() self.fp.seek(16 + start_mol_num * self.record_size) size = stop_mol_num - start_mol_num data = numpy.fromfile(self.fp, dtype=i3dtype.i3DataType(), count=size) self.fp.seek(cur) if good_only: return i3dtype.maskData(data, (data['c'] != 9)) else: return data
def getMoleculesInFrameRange(self, start, stop, good_only = True): start_mol_num = self.findFrame(start) stop_mol_num = self.findFrame(stop) if (type(self.localizations) == type(numpy.array([]))): data = self.localizations[start_mol_num:stop_mol_num] else: cur = self.fp.tell() self.fp.seek(16 + start_mol_num*self.record_size) size = stop_mol_num - start_mol_num data = numpy.fromfile(self.fp, dtype=i3dtype.i3DataType(), count=size) self.fp.seek(cur) if good_only: return i3dtype.maskData(data, (data['c'] != 9)) else: return data
def loadI3FileNumpy(filename, verbose=1): fp = open(filename, "rb") # Read header [frames, molecules, version, status] = readHeader(fp, verbose) data = numpy.fromfile(fp, dtype=i3dtype.i3DataType()) # If the analysis crashed, the molecule list may still # be valid, but the molecule number will be incorrect. if (molecules == 0): print("File appears empty, trying to load anyway.") try: molecules = numpy.max(data['fr']) except: molecules = 0 data = data[:][0:molecules] fp.close() return data
def loadI3FileNumpy(filename, verbose = 1): fp = open(filename, "rb") # Read header [frames, molecules, version, status] = readHeader(fp, verbose) data = numpy.fromfile(fp, dtype=i3dtype.i3DataType()) # If the analysis crashed, the molecule list may still # be valid, but the molecule number will be incorrect. if(molecules==0): print("File appears empty, trying to load anyway.") try: molecules = numpy.max(data['fr']) except: molecules = 0 data = data[:][0:molecules] fp.close() return data
def nextBlock(self, block_size=400000, good_only=True): # check if we have read all the molecules. if (self.cur_molecule >= self.molecules): return False size = block_size # adjust size if we'll read past the end of the file. if ((self.cur_molecule + size) > self.molecules): size = self.molecules - self.cur_molecule self.cur_molecule += size # read the data data = numpy.fromfile(self.fp, dtype=i3dtype.i3DataType(), count=size) if good_only: return i3dtype.maskData(data, (data['c'] != 9)) else: return data
def nextBlock(self, block_size = 400000, good_only = True): # check if we have read all the molecules. if(self.cur_molecule>=self.molecules): return False size = block_size # adjust size if we'll read past the end of the file. if((self.cur_molecule+size)>self.molecules): size = self.molecules - self.cur_molecule self.cur_molecule += size # read the data data = numpy.fromfile(self.fp, dtype=i3dtype.i3DataType(), count=size) if good_only: return i3dtype.maskData(data, (data['c'] != 9)) else: return data