def grad_Y(self, u, Y): NYs = self.iYobs.size NY = Y.size cols = self.iYobs rows = np.arange(NYs) vals = np.full(NYs, 1.0) Hy = sps.coo_matrix((vals, (rows, cols)), shape=(NYs, NY)) return sps.vstack([-Hy, np.sqrt(self.gamma) * self.L]) if __name__ == '__main__': L = np.array([1.0, 1.0]) N = np.array([32, 32]) g = Geom(L, N) g.calculate() ul = 2.0 ur = 1.0 bc = BC(g) bc.dirichlet(g, "left", ul) bc.dirichlet(g, "right", ur) # Hydraulic conductivity npr.seed(0) se = SEKernel(std_dev=1.0, cor_len=0.15, std_dev_noise=0.0) CY = se.covar(g.cells.centroids.T, g.cells.centroids.T) Nc = np.prod(N) Y = se.sample(CY, npr.randn(Nc)) K = np.exp(Y)
def __init__(self, streamfile, mainThread=None): super(CrystFELStreamLight, self).__init__() self.streamfile = streamfile self.mainThread = mainThread self.geometry = Geom()
def parse_stream(self): crystal = 0 count_shots = 0 count_crystals = 0 self.frames = [] self.header = '' geom = Geom() stream = open(self.streamfile) all_reflections = [] head_check = 0 REFLECTIONS = 0 PEAKS = 0 GEOM_FLAG = 0 self.geom = '' self.filenames = [] self.indexed = [] emit = 0 for index, line in enumerate(stream): prt = 0 ### GEt header while (head_check == 0): self.header += line if '----- Begin geometry file -----' in line: GEOM_FLAG = 1 if GEOM_FLAG: self.geom += line # if GEOM_FLAG: # if line.startswith('clen'): # #print line.split('=') # geom.distance = float(line.split('=')[1].split(';')[0].strip()) # if 'corner_x' in line: # geom.bx = -1 * float(line.split('=')[1].split(';')[0].strip()) # if 'corner_y' in line: # geom.by = -1 * float(line.split('=')[1].split(';')[0].strip()) # if 'res' in line: # geom.ps = 1 / float(line.split('=')[1].split(';')[0].strip()) # if 'photon_energy' in line: # geom.energy = float(line.split('=')[1].split(';')[0].strip()) # geom.wl = 12398.425 / geom.energy # if 'max_fs' in line: # geom.max_fs = float(line.split('=')[1].split(';')[0].strip()) # if 'max_ss' in line: # geom.max_ss = float(line.split('=')[1].split(';')[0].strip()) if '----- End geometry file -----' in line: GEOM_FLAG = 0 self.sendGEOM.emit(self.geom) break ### Get beginning of an image if 'Begin chunk' in line: count_shots += 1 append = 1 head_check = 1 # frame_stream.append(l) ### If elif 'Image filename' in line: frame = Frame() frame.filename = line.split()[2].strip() self.filenames.append(frame.filename) # The division by 10 is to convert from nm-1 to Angstrom-1 elif 'indexed_by' in line: if 'none' not in line: count_crystals += 1 crystal = 1 frame.indexing = line.split()[2].strip() self.indexed.append(frame.filename) else: frame.indexing = 'none' elif 'diffraction_resolution_limit' in line: res = float(line.split()[5]) frame.res = res elif 'Cell parameters' in line: a0, b0, c0 = line.split()[2:5] frame.a = float(a0) frame.b = float(b0) frame.c = float(c0) elif 'astar' in line: x, y, z = line.split()[2:5] frame.astar[0] = float(x) / 10 frame.astar[1] = float(y) / 10 frame.astar[2] = float(z) / 10 elif 'bstar' in line: x, y, z = line.split()[2:5] frame.bstar[0] = float(x) / 10 frame.bstar[1] = float(y) / 10 frame.bstar[2] = float(z) / 10 elif 'cstar' in line: x, y, z = line.split()[2:5] frame.cstar[0] = float(x) / 10 frame.cstar[1] = float(y) / 10 frame.cstar[2] = float(z) / 10 elif 'End of reflections' in line: REFLECTIONS = 0 elif 'End of peak list' in line: PEAKS = 0 elif "End chunk" in line: prt = 1 if crystal == 1: # frame_stream.append(line) # frame.all = frame_stream self.frames.append(frame) crystal = 0 if REFLECTIONS: h, k, l, I, SIG, P, BKG, X, Y, panel = line.split()[0:10] frame.reflections.append([ int(h), int(k), int(l), float(I), float(SIG), float(BKG), float(X), float(Y), str(panel) ]) # geom.get_resolution(float(x), float(y)) ]) # frame.hkl_stream.append(line) # if append == 1: frame_stream.append(line) if PEAKS: X, Y, RES, I, panel = line.split() frame.peaks.append( [float(X), float(Y), float(RES), float(I), str(panel)]) if ' h k l I sigma(I)' in line: REFLECTIONS = 1 # append = 0 if ' fs/px ss/px (1/d)/nm^-1 Intensity' in line: PEAKS = 1 if count_shots % 500 == 0 and count_shots > 500 and prt == 1: prt = 0 print('%7i frames parsed, %7i crystals found' % (count_shots, count_crystals)) if emit == 0: self.update.emit([self.filenames, self.indexed]) emit += 1 if emit % 4 == 0: self.info.emit((count_shots, count_crystals)) sys.stdout.flush() print('%7i frames parsed, %7i crystals found\r' % (count_shots, count_crystals)) #sys.stdout.flush() self.info.emit((count_shots, count_crystals)) self.moveToThread(self.mainThread) self.finished.emit() self.update.emit([self.filenames, self.indexed])
def parse_stream(streamfile): append = 0 crystal = 0 count_shots = 0 count_crystals = 0 frame_stream = [] frames = [] head_check = 0 header = '' geom = Geom() stream = open(streamfile) all_reflections = [] REFLECTIONS = 0 PEAKS = 0 GEOM_FLAG = 0 geom = '' filenames = [] indexed = [] for index, line in enumerate(stream): ### GEt header while (head_check == 0): header += line if '----- Begin geometry file -----' in line: GEOM_FLAG = 1 if GEOM_FLAG: geom += line #if GEOM_FLAG: # if line.startswith('clen'): # #print line.split('=') # geom.distance = float(line.split('=')[1].split(';')[0].strip()) # if 'corner_x' in line: # geom.bx = -1 * float(line.split('=')[1].split(';')[0].strip()) # if 'corner_y' in line: # geom.by = -1 * float(line.split('=')[1].split(';')[0].strip()) # if 'res' in line: # geom.ps = 1 / float(line.split('=')[1].split(';')[0].strip()) # if 'photon_energy' in line: # geom.energy = float(line.split('=')[1].split(';')[0].strip()) # geom.wl = 12398.425 / geom.energy # if 'max_fs' in line: # geom.max_fs = float(line.split('=')[1].split(';')[0].strip()) # if 'max_ss' in line: # geom.max_ss = float(line.split('=')[1].split(';')[0].strip()) if '----- End geometry file -----' in line: GEOM_FLAG = 0 break ### Get beginning of an image if 'Begin chunk' in line: count_shots += 1 append = 1 head_check = 1 # frame_stream.append(l) ### If elif 'Image filename' in line: frame = Frame() frame.filename = line.split()[2].strip() filenames.append(frame.filename) # The division by 10 is to convert from nm-1 to Angstrom-1 elif 'indexed_by' in line: if 'none' not in line: count_crystals += 1 crystal = 1 frame.indexing = line.split()[2].strip() indexed.append(frame.filename) else: frame.indexing = 'none' #SACLA specific - not needed # try: # f = os.path.split(filename)[1] # tag = os.path.splitext(f)[0].split('tag_')[1] # frame.timeline = tag #except: # pass elif 'diffraction_resolution_limit' in line: res = float(line.split()[5]) frame.res = res elif 'Cell parameters' in line: a0, b0, c0 = line.split()[2:5] frame.a = float(a0) frame.b = float(b0) frame.c = float(c0) elif 'astar' in line: x, y, z = line.split()[2:5] frame.astar[0] = float(x) / 10 frame.astar[1] = float(y) / 10 frame.astar[2] = float(z) / 10 elif 'bstar' in line: x, y, z = line.split()[2:5] frame.bstar[0] = float(x) / 10 frame.bstar[1] = float(y) / 10 frame.bstar[2] = float(z) / 10 elif 'cstar' in line: x, y, z = line.split()[2:5] frame.cstar[0] = float(x) / 10 frame.cstar[1] = float(y) / 10 frame.cstar[2] = float(z) / 10 elif 'End of reflections' in line: REFLECTIONS = 0 elif 'End of peak list' in line: PEAKS = 0 elif "End chunk" in line: if crystal == 1: #frame_stream.append(line) #frame.all = frame_stream frames.append(frame) append = 0 frame_stream = [] crystal = 0 if REFLECTIONS: h, k, l, I, SIG, P, BKG, X, Y = line.split()[0:9] # bkg, x, y = line.split()[6:9] # SNR = float(line.split()[3]) / float(line.split()[4]) frame.reflections.append([ int(h), int(k), int(l), float(I), float(SIG), float(BKG), float(X), float(Y) ]) # geom.get_resolution(float(x), float(y)) ]) #frame.hkl_stream.append(line) #if append == 1: frame_stream.append(line) if PEAKS: X, Y, RES, I, panel = line.split() frame.peaks.append( [float(X), float(Y), float(RES), float(I), str(panel)]) if ' h k l I sigma(I)' in line: REFLECTIONS = 1 #append = 0 if ' fs/px ss/px (1/d)/nm^-1 Intensity' in line: PEAKS = 1 #if count_shots % 1000 == 0: print '%7i frames parsed, %7i crystals found\r' % (count_shots, count_crystals), sys.stdout.flush() #print '%7i frames parsed, %7i crystals found\r' % (count_shots, count_crystals), #sys.stdout.flush() #print return header, frames, geom, all_reflections