def get_data(run=127, threshold=0.05, force=False, ishotref=0, ishotsam=1): fname = "../data/fig_focusing_run%04d.h5" % run if not os.path.isfile(fname) or force: # this functions splits the data based on FOM < 0.5 --> p1 is the ref, p2 is the sample data = xppl37_spectra.calcSpectraForRun(run, force) idx = data.run.results[0].fom < 0.5 E = data.run.E ref = ds.DataStorage(E=E, p1=data.p1[0], p2=data.p2[0]) sample = ds.DataStorage(E=E, p1=data.p1[1], p2=data.p2[1]) _, _, Abs = xppl37_spectra.calcAbs(ref, ref, threshold=threshold) ref.Abs = Abs _, _, Abs = xppl37_spectra.calcAbs(ref, sample, threshold=threshold) sample.Abs = Abs temp = ds.DataStorage(ref=ref, sample=sample) temp.info = "Abs calculated with threshold = %.3f" % threshold temp.save(fname) print('maybe forced to calculate again the Spectra to get idx_fom') data = ds.read(fname) ref = data.ref sample = data.sample _, _, Abs = xppl37_spectra.calcAbs(ref, ref, threshold=threshold) ref.Abs = Abs _, _, Abs = xppl37_spectra.calcAbs(ref, sample, threshold=threshold) sample.Abs = Abs data = ds.DataStorage(ref=ref, sample=sample) data["threshold"] = threshold return data, idx
def setup_filename(self, runno, name, overwrite): fname = '{}run_{}.h5'.format(self.dir_save, runno) if name: fname = '{}run_{}_{}.h5'.format(self.dir_save, runno, name) if os.path.isfile(fname): print('The file {} already exists'.format(fname)) if overwrite == 'question': mes = input('Do you want to remove (y,n) or rename (type new name):') if mes == 'y': mes = True elif mes == 'n': mes = False else: mes = overwrite print(mes) if mes: os.remove(fname) ds = self.setup_ds(fname) ds.save() elif not mes: ds = dsg.DataStorage(filename = fname) else: fname = '{}run_{}_{}.h5'.format(self.dir_save, runno, mes) ds = self.setup_ds(fname) ds.save() else: ds = self.setup_ds(fname) ds.save() print(fname) return ds, fname
def setup_ds(self, fname): ds = dsg.DataStorage(filename = fname) print('Setting up datastorage file') ds['config'] = self.cfg ds['channels'] = {} self.ds = ds ds.save() return ds
def saveAndRead(obj,fname="/tmp/test.h5",link_copy=False): obj = datastorage.DataStorage(obj) t0 = time.time() obj.save(fname,link_copy=link_copy,raiseError=True) t1 = time.time() obj1 = datastorage.read(fname) # for k in obj: # print(" %s %s %s"%(k,str(obj[k])[:10],str(obj1[k])[:10])) t2 = time.time() return t2-t1,t1-t0
def get_data(run=82,calib=1,threshold=0.02,force=False): fname = "../data/fig_fe_xas_run%04d.h5" % run if not os.path.isfile(fname) or force: E,p1,p2,Abs=xppl37_spectra.calcAbsForRun(run,merge_calibs=True,threshold=threshold) temp = ds.DataStorage( E=E,p1=p1,p2=p2,Abs=Abs) temp.info="Abs calculated with threshold = %.3f" % threshold temp.save(fname) data = ds.read(fname) # nan is saved as -1 for masked arrays for k in data.keys(): try: data[k][data[k]==-1] =np.nan except TypeError: pass return data
def get_data(runs=(155,156),threshold=0.02,force=False): run_hash = "_".join(map(str,runs)) fname = "../data/fig_fe_xas_runs_%s.h5" % run_hash if not os.path.isfile(fname) or force: E,p1,p2,Abs=xppl37_spectra.calcAbsForRun(runs,merge_calibs=True,threshold=threshold) temp = ds.DataStorage( E=E,p1=p1,p2=p2,Abs=Abs) temp.info="Abs calculated with threshold = %.3f" % threshold temp.save(fname) data = ds.read(fname) # nan is saved as -1 for masked arrays for k in data.keys(): try: data[k][data[k]==-1] =np.nan except TypeError: pass # for runs 155,156 the vernier stopped working after shots ~ 2000 if runs == (155,156): data.p1=data.p1[:2000] data.p2=data.p2[:2000] data.Abs=data.Abs[:2000] return data
def get_data(run, threshold=0.02, force=False): if run == 80: refCalibs = slice(1, None, 2) elif run == 84: refCalibs = slice(None, None, 2) elif run == 60: refCalibs = slice(None, None, 2) elif run == 76: refCalibs = slice(None, None) else: refCalibs = slice(None, None, 2) fname = "../data/fig_fel_modes_run%04d.h5" % run if not os.path.isfile(fname) or force: r = xanes_analyzeRun.AnalyzeRun(run=run) r.load() E = r.E calibs = list(r.results.keys()) calibs.sort() calibs = calibs[refCalibs] p1 = np.vstack([r.results[c].p1 for c in calibs]) p2 = np.vstack([r.results[c].p2 for c in calibs]) #temp = ds.DataStorage( E=E,p1=p1.astype(np.float16),p2=p2.astype(np.float16)) temp = ds.DataStorage(E=E, p1=p1, p2=p2) _, _, Abs = xppl37_spectra.calcAbs(temp, threshold=0.02) temp.Abs = Abs #.astype(np.float16) temp.info = "Abs calculated with threshold = 0.02" temp.save(fname) data = ds.read(fname) # nan is saved as -1 for masked arrays for k in data.keys(): try: data[k][data[k] == -1] = np.nan except (TypeError, AttributeError): pass print("Run %d → nshots = %d" % (run, len(data.p1))) p1, p2, Abs = xppl37_spectra.calcAbs(data, threshold=threshold) data.Abs = Abs return data
if bins is None: bin_center = motor_pos else: bin_center = bins bin_size = min(np.diff(bin_center)) bin_edges = np.append(bin_center[0] - 0.5 * bin_size, bin_center + 0.5 * bin_size) bin_target = np.digitize(motor_pos_tot, bin_edges) """ Loop through all bins """ print('Start bin loop. \n') for bin_count, step_pos in enumerate(bin_center): if (not np.in1d(bin_count, step)) & (not (step == None)): continue start = time.time() results = datastorage.DataStorage() print('\n\nAnalyze bin {} of {}'.format(bin_count, len(bin_center) - 1)) """ Find index for laser on/off shots in the bin """ idx_bin = bin_target == (bin_count + 1) eventIds_bin = eventIds[idx_bin] if config.laserReprate: laser_off = np.mod(eventIds_bin, int( 100 / config.laserReprate)) > 0 laser_on = np.logical_not(laser_off) else: laser_off = np.ones(eventIds_bin.shape) laser_on = np.zeros(eventIds_bin.shape) JFdata = dict() """ Analyze I0 detector """
def get_1b(): E,data=np.loadtxt("../data/Fe_1bunch.txt",unpack=True) return ds.DataStorage(E=E*1e3,data=data/2.05+0.07)