def addMoleculesWithXYCatF(self, x, y, cat,f): i3data = i3dtype.createDefaultI3Data(x.size) i3dtype.posSet(i3data, 'x', x) i3dtype.posSet(i3data, 'y', y) i3dtype.setI3Field(i3data, 'c', cat) i3dtype.setI3Field(i3data, 'fr', f) self.addMolecules(i3data)
def addDAOSTORMMolecules(self, frame, xc, yc, br, be, msky, niter, sharp, chi, err): # # DAOSTORM -> Insight3 format mapping. # # xc - xcenter # yc - ycenter # br - brightness -> peak height # be - brightness error (?) -> peak area # msky - background -> peak background # niter - fit iterations # sharp - sharpness (?) -> peak angle # chi - fit quality -> peak width # err - error flag -> link # i3data = i3dtype.createDefaultI3Data(xc.size) i3dtype.posSet(i3data, 'x', xc) i3dtype.posSet(i3data, 'y', yc) i3dtype.setI3Field(i3data, 'h', br) i3dtype.setI3Field(i3data, 'a', be) i3dtype.setI3Field(i3data, 'bg', msky) i3dtype.setI3Field(i3data, 'fi', niter) i3dtype.setI3Field(i3data, 'phi', sharp) i3dtype.setI3Field(i3data, 'w', chi) i3dtype.setI3Field(i3data, 'lk', err) self.addMolecules(i3data)
def addMoleculesWithXYAFrame(self, x, y, pa, frame): i3data = i3dtype.createDefaultI3Data(x.size) i3dtype.posSet(i3data, 'x', x) i3dtype.posSet(i3data, 'y', y) i3dtype.setI3Field(i3data, 'a', pa) i3dtype.setI3Field(i3data, 'fr', frame) self.addMolecules(i3data)
def addMoleculesWithXYZCat(self, x, y, z, cat): i3data = i3dtype.createDefaultI3Data(x.size) i3dtype.posSet(i3data, 'x', x) i3dtype.posSet(i3data, 'y', y) i3dtype.posSet(i3data, 'z', z) i3dtype.setI3Field(i3data, 'c', cat) self.addMolecules(i3data)
def addMoleculesWithXYCatF(self, x, y, cat, f): i3data = i3dtype.createDefaultI3Data(x.size) i3dtype.posSet(i3data, 'x', x) i3dtype.posSet(i3data, 'y', y) i3dtype.setI3Field(i3data, 'c', cat) i3dtype.setI3Field(i3data, 'fr', f) self.addMolecules(i3data)
def addMoleculesWithXYZIFrame(self, x, y, z, pi, f): i3data = i3dtype.createDefaultI3Data(x.size) i3dtype.posSet(i3data, 'x', x) i3dtype.posSet(i3data, 'y', y) i3dtype.posSet(i3data, 'z', z) i3dtype.setI3Field(i3data, 'i', pi) i3dtype.setI3Field(i3data, 'fr', f) self.addMolecules(i3data)
def addMoleculesWithXYIWFrame(self, x, y, pi, width, frame): i3data = i3dtype.createDefaultI3Data(x.size) i3dtype.posSet(i3data, 'x', x) i3dtype.posSet(i3data, 'y', y) i3dtype.setI3Field(i3data, 'i', pi) i3dtype.setI3Field(i3data, 'w', width) i3dtype.setI3Field(i3data, 'fr', frame) self.addMolecules(i3data)
def addMultiFitMolecules(self, molecules, x_size, y_size, frame, nm_per_pixel, inverted=False): n_molecules = molecules.shape[0] h = molecules[:, 0] if inverted: xc = y_size - molecules[:, 1] yc = x_size - molecules[:, 3] wx = 2.0 * molecules[:, 2] * nm_per_pixel wy = 2.0 * molecules[:, 4] * nm_per_pixel else: xc = molecules[:, 3] + 1 yc = molecules[:, 1] + 1 wx = 2.0 * molecules[:, 4] * nm_per_pixel wy = 2.0 * molecules[:, 2] * nm_per_pixel bg = molecules[:, 5] zc = molecules[:, 6] * 1000.0 # fitting is done in um, insight works in nm st = numpy.round(molecules[:, 7]) err = molecules[:, 8] # calculate peak area, which is saved in the "a" field. parea = 2.0 * 3.14159 * h * molecules[:, 2] * molecules[:, 4] ax = wy / wx ww = numpy.sqrt(wx * wy) i3data = i3dtype.createDefaultI3Data(xc.size) i3dtype.posSet(i3data, 'x', xc) i3dtype.posSet(i3data, 'y', yc) i3dtype.posSet(i3data, 'z', zc) i3dtype.setI3Field(i3data, 'h', h) i3dtype.setI3Field(i3data, 'bg', bg) i3dtype.setI3Field(i3data, 'fi', st) i3dtype.setI3Field(i3data, 'a', parea) i3dtype.setI3Field(i3data, 'w', ww) i3dtype.setI3Field(i3data, 'ax', ax) i3dtype.setI3Field(i3data, 'fr', frame) i3dtype.setI3Field(i3data, 'i', err) self.addMolecules(i3data)
def addMultiFitMolecules(self, molecules, x_size, y_size, frame, nm_per_pixel, inverted=False): n_molecules = molecules.shape[0] h = molecules[:,0] if inverted: xc = y_size - molecules[:,1] yc = x_size - molecules[:,3] wx = 2.0*molecules[:,2]*nm_per_pixel wy = 2.0*molecules[:,4]*nm_per_pixel else: xc = molecules[:,3] + 1 yc = molecules[:,1] + 1 wx = 2.0*molecules[:,4]*nm_per_pixel wy = 2.0*molecules[:,2]*nm_per_pixel bg = molecules[:,5] zc = molecules[:,6] * 1000.0 # fitting is done in um, insight works in nm st = np.round(molecules[:,7]) err = molecules[:,8] # calculate peak area, which is saved in the "a" field. sum = 2.0*3.14159*h*molecules[:,2]*molecules[:,4] ax = wy/wx ww = np.sqrt(wx*wy) i3data = i3dtype.createDefaultI3Data(xc.size) i3dtype.posSet(i3data, 'x', xc) i3dtype.posSet(i3data, 'y', yc) i3dtype.posSet(i3data, 'z', zc) i3dtype.setI3Field(i3data, 'h', h) i3dtype.setI3Field(i3data, 'bg', bg) i3dtype.setI3Field(i3data, 'fi', st) i3dtype.setI3Field(i3data, 'a', sum) i3dtype.setI3Field(i3data, 'w', ww) i3dtype.setI3Field(i3data, 'ax', ax) i3dtype.setI3Field(i3data, 'fr', frame) i3dtype.setI3Field(i3data, 'i', err) self.addMolecules(i3data)
def merge_SVC_bin_files(self): i3multi = readinsight3.I3Reader(self.i3TestIndivSVCBinNames['multi']) i3single = readinsight3.I3Reader(self.i3TestIndivSVCBinNames['single']) num_frames = int(np.max([i3multi.getNumberFrames(),i3single.getNumberFrames()])) i3out = writeinsight3.I3Writer(self.i3TestCombSVCBinName, frames=num_frames) im1 = i3multi.getMoleculesInFrameRange(0,num_frames+1) is1 = i3single.getMoleculesInFrameRange(0,num_frames+1) n_mol0 = im1.shape[0] n_mol1 = is1.shape[0] i3new = i3dtype.createDefaultI3Data(n_mol0+n_mol1) for i in range(n_mol0): i3new[i] = im1[i] for j in range(n_mol1): i3new[n_mol0+j] = is1[j] i3new = np.sort(i3new,order=['fr','x','y']) i3out.addMoleculesWithXYZHCatFrame(i3new['x'],i3new['y'],i3new['z'],i3new['h'],i3new['c'],i3new['fr']) i3multi.close() i3single.close() i3out.close() im1 = None is1 = None i3new = None return True
if (field[0] != 'Z Rejected'): if (field[0] not in channelNames): channelNames.append(field[0]) frameNumber = int(field[12]) if (frameNumber > MaxFrameNumber): MaxFrameNumber = frameNumber print(channelNames, MaxFrameNumber) binWriter = writeinsight3new.I3Writer(file_path + ".bin", MaxFrameNumber) for idx, line in enumerate(lines): p1["value"] = idx / len(lines) * 100 root.update() if idx > 0: data = i3dtype.createDefaultI3Data(1) field = line.split('\t') x = float(field[1]) y = float(field[2]) xc = float(field[3]) yc = float(field[4]) h = float(field[5]) a = float(field[6]) w = float(field[7]) phi = float(field[8]) ax = float(field[9]) bg = float(field[10]) i = float(field[11]) c = 1 # default to 1 channelName = field[0]
def addMoleculesWithXY(self, x, y): i3data = i3dtype.createDefaultI3Data(x.size) i3dtype.posSet(i3data, 'x', x) i3dtype.posSet(i3data, 'y', y) self.addMolecules(i3data)
def addMoleculesWithXYI(self, x, y, pi): i3data = i3dtype.createDefaultI3Data(x.size) i3dtype.posSet(i3data, 'x', x) i3dtype.posSet(i3data, 'y', y) i3dtype.setI3Field(i3data, 'i', pi) self.addMolecules(i3data)