def makeDataSourceAndSmallData(experimentNameAndRun, h5FileName, ttDevice, ttCode): global ttAnalyze smldata = "None" if (ttDevice is not None): print("setting up time tool.") print("Device = " + ttDevice) print("bykick code = " + str(ttCode)) ttOptions = TimeTool.AnalyzeOptions(get_key=ttDevice, eventcode_nobeam=ttCode) ttAnalyze = TimeTool.PyAnalyze(ttOptions) print("loading experiment data using standard small data") myDataSource = psana.MPIDataSource(experimentNameAndRun, module=ttAnalyze) print("defining small data") if (h5FileName != "None"): smldata = myDataSource.small_data(h5FileName) else: print("loading mpi data source") myDataSource = psana.MPIDataSource(experimentNameAndRun) print("defining small data. hook in place ") if (h5FileName != "None"): smldata = myDataSource.small_data(h5FileName) return (myDataSource, smldata)
def main(exp, run, configFileName): experimentNameAndRun = "exp=%s:run=%d"%(exp, run) print("current working directory"+str(os.curdir)) os.system('mkdir config') print("creating libraries") os.system('touch config/__init__.py') print("initializing") myDataSource = psana.MPIDataSource(experimentNameAndRun) f = open('./config/'+configFileName,'w') print("writing libraries") f.write('##########################\n') f.write('#######DAQ DEVICES########\n') f.write('##########################\n') for thisDetectorName in psana.DetNames(): #f.write('#detectorStart, ') f.write('#') for i in thisDetectorName: f.write(str(i)+', ') #f.write(' detectorFinish') f.write('\n') f.write('##########################\n') f.write('#######EPICS PVs##########\n') f.write('##########################\n') for thisDetectorName in psana.DetNames('epics'): f.write('#') for i in thisDetectorName: f.write(str(i)+', ') #f.write(' epicsPvFinish') f.write('\n') f.close()
def main(argd): if (False == argd['shared_mem']): experimentNameAndRun = "exp=%s:run=%d:smd" % (argd['exp'], argd['run']) myDataSource = psana.MPIDataSource(experimentNameAndRun + ":smd") else: experimentNameAndRun = "shmem=psana.0:stop=no" myDataSource = psana.DataSource(experimentNameAndRun) myEnumeratedEvents = enumerate(myDataSource.events()) smldata = myDataSource.small_data("test.h5") for eventNumber, thisEvent in myEnumeratedEvents: if eventNumber < argd['start']: continue if eventNumber > argd['final']: break if (eventNumber % 200 == 1): print eventNumber my_dict = {"test": eventNumber} #smldata.event(my_dict) #smldata.save() IPython.embed()
def main(fileName): global my_dict my_hdf5_object = h5py.File("hdf5/xpptut15run440.h5", 'r') #convert hdf5 to dict my_list = [] def func(name, obj): my_list.append(name) my_hdf5_object.visititems(func) my_dict = {} for i in my_list: try: my_dict[i] = array(my_hdf5_object[i]) except: #IPython.embed() pass my_hdf5_object.close() #%matplotlib acqiris_alias = "Acq02" eigen_basis_file = "hdf5/xpptut15run440_eigen_basis.h5" experiment_name = "xpptut15" run_number = "440" channel_number = 3 event_number = int(200 * rand()) print("event number number for testing: " + str(event_number)) #################### ##################### my_eigen_basis = h5py.File(eigen_basis_file) eig_bas = array( my_eigen_basis['summary/nonMeaningfulCoreNumber0/' + acqiris_alias + '/ch' + str(channel_number) + '/norm_eigen_wave_forms']) import psana my_data_source = psana.MPIDataSource("exp=" + experiment_name + ":run=" + run_number + ":smd") acq_det_obj = psana.Detector(acqiris_alias) my_enum_events = enumerate(my_data_source.events()) for evt_num, this_event in my_enum_events: if evt_num > event_number: break my_index = argmax((this_event.get( psana.EventId).fiducials() == my_dict['fiducials']).astype(int)) #plot(acq_det_obj(this_event)[0][channel_number]-mean(acq_det_obj(this_event)[0][channel_number][:300])) plot( acq_det_obj(this_event)[0][channel_number] - mean(acq_det_obj(this_event)[0][channel_number][:300])) plot( dot( my_dict[acqiris_alias + '/ch' + str(channel_number) + '/weightings'][my_index], eig_bas), 'r.') ylim(-0.06, 0.0) xlim(1100, 1400) show()
def makeDataSourceAndSmallData(experimentNameAndRun, h5FileName, ttDevice, ttCode, shared_memory): global ttAnalyze smldata = "None" small_hdf5_dir = "hdf5" os.system("mkdir " + small_hdf5_dir) if (ttDevice is not None): print("setting up time tool.") print("Device = " + ttDevice) print("bykick code = " + str(ttCode)) ttOptions = TimeTool.AnalyzeOptions(get_key=ttDevice, eventcode_nobeam=ttCode) ttAnalyze = TimeTool.PyAnalyze(ttOptions) print("loading experiment data using standard small data") myDataSource = psana.MPIDataSource(experimentNameAndRun, module=ttAnalyze) print("defining small data") if (h5FileName != "None"): smldata = myDataSource.small_data(small_hdf5_dir + "/" + h5FileName, gather_interval=10) else: print("loading mpi data source") if (shared_memory): myDataSource = psana.DataSource('shmem=psana.0:stop=no') else: myDataSource = psana.MPIDataSource(experimentNameAndRun) print("defining small data. hook in place ") if (h5FileName != "None"): smldata = myDataSource.small_data(small_hdf5_dir + "/" + h5FileName, gather_interval=10) return (myDataSource, smldata)
def main(exp, run, configFileName): experimentNameAndRun = "exp=%s:run=%d" % (exp, run) print("current working directory" + str(os.curdir)) os.system('mkdir config') print("creating libraries") os.system('touch config/__init__.py') print("initializing") myDataSource = psana.MPIDataSource(experimentNameAndRun) write_config_file(configFileName, "default") write_config_file("make_acq_eigen_basis.cfg", "make_acq_basis") write_config_file("acqiris_eigen_analysis.cfg", "use_acq_basis")
def intensityROI(): ds = psana.MPIDataSource('exp=cxi02116:run=257:smd') det = psana.Detector('DsaCsPad') for nevent,evt in enumerate(ds.events()): raw_calib = np.array(det.calib(evt)) test = np.array(det.image(evt)) print(raw_calib.shape) print(test.shape) roi_approx = raw_calib[750:950, 775:975] print(roi_approx) roi_final = sum(sum(sum(roi_approx[65:176,42:154]))) print(roi_final)
def setup(self): self.filename = '/tmp/' + str(uuid4()) + '.h5' self.gather_interval = 2 dstr = 'exp=sxrk4816:run=66:smd:dir=/reg/g/psdm/data_test/multifile/test_028_sxrk4816' self.dsource = psana.MPIDataSource(dstr) self.smldata = self.dsource.small_data(self.filename, gather_interval=5) self.gather_after = 3 # events (for each core) self.end_after = 5 # events (for each core) #self.dsource.break_after(self.end_after * size) assert self.gather_after > 2, 'gather after should be >= 3' assert self.gather_after < self.end_after return
def makeCenter(): ds = psana.MPIDataSource('exp=cxi02116:run=257:smd') det = psana.Detector('DsaCsPad') for nevent, evt in enumerate(ds.events()): #Figure out coordinates first img = np.array(det.image(evt)) test = np.array(det.calib(evt)) #Y-coords, then X-coords when slciing approximate = img[750:950, 775:975] real = approximate[65:176, 42:154] print(img.shape) print(test.shape) print(img) print(test) yo = np.reshape(test, (1451, 1745)) print(yo)
def __init__(self, exp='cxip10016', run='1', gain_fnam=None, mask_fnam=None): """ By default gain = 1 and the mask is obtained from psana. For example: gain_fnam = '/reg/data/ana04/cxi/cxilt1417/scratch/gain/gain_prelim.npy' mask_fnam = '/reg/data/ana04/cxi/cxilt1417/scratch/masks/better_mask.npy' """ # # Initialize variables # print "Debug: loading psanabb" self.dsname_smd = 'exp=' + exp + ':run=' + run + ':smd' self.ds_smd = psana.MPIDataSource(self.dsname_smd) self.env_smd = self.ds_smd.env() self.evt = self.ds_smd.events().next() print "Debug: loading psanabb idx events" self.dsname_idx = 'exp=' + exp + ':run=' + run + ':idx' self.ds_idx = psana.DataSource(self.dsname_idx) self.env_idx = self.ds_idx.env() # # get event times # self.run = self.ds_idx.runs().next() self.times = self.run.times() self.nevents = len(self.times) print "Debug: loading cspad info" # load information self.loadCspad(gain_fnam=gain_fnam, mask_fnam=mask_fnam) self.wavelength = self.get_wavelength(self.evt) self.energy = self.get_photon_beam_energy(self.evt)
Interp = InterpSimple(cent[0], cent[1], interp_rmax, interp_rmin, nphi, img_sh) pmask = Interp.nearest(mask).astype(int).astype(float) pmask_bn = bin_ndarray(pmask, binned_pol_img_sh) # print pmask.shape,pmask_bn.shape # if (rbin_fct==1 and phibin_fct==1): # print('not binning polar img') # sys.exit() #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #~~~ data get parameters #load the data events for the given run ds_str = 'exp=cxilr6716:run=%d:smd' % run ds = psana.MPIDataSource(ds_str) events = ds.events() # open the detector obj cspad = psana.Detector('DsaCsPad') # make some output dir outdir = args.out_dir if not os.path.exists(outdir): os.makedirs(outdir) # make output file if args.fname is None: prefix = 'BigAzzData-run%d-maxEvent%d-start%d.hdf5' % (run, args.maxcount, args.start) else:
import time runNum = sys.argv[1] eventRange = int(sys.argv[2]) #runNum = "38" myString = "sxrlq7615:run=" + str(runNum) + "evntRange=" + str( eventRange) + ".txt" try: os.remove(myString) except OSError: print("no previous files to delete") #ds = psana.DataSource('exp=xpptut15:run=340') #test data from AMO runs 10, 15, and 19 #ds = psana.DataSource('exp=sxrm2316:run=103') #real data from specified experiment (sxrm2316) ds = psana.MPIDataSource('exp=sxrlq7615:run=' + runNum) #ds = psana.MPIDataSource('exp=sxrlq7615:run='+runNum+':smd') #ds = psana.MPIDataSource('exp=xpptut15:run='+str(runNum)) #psana.DetNames() aquiris2 = psana.Detector("Acq01") det = psana.Detector('pnccd') #for LQ76 and test amo data #det = psana.Detector('andor') #for sxrm2316 #smldata = ds.small_data('run'+str(runNum)+'.h5') yTotal = 0 imgTotal = 0 #stackOfROIImagesForMatt = []
def make_basis(exp_name, run, det_name, nWaveforms=500, b=None, n_c=2, roi=None): """ Create the SVD basis for the waveform fitting. THe output is saved in a h5 file stored in the calib directory of the relevant experiment Args: exp_name (str): experiment name run (int): run number det_name (str): psana name for the detector (alias) nWaveforms (int): number of waveform to use to build the basis b (int): background index. np.mean(waveform[:b]) will be subtracted roi (list, array): two index specifying the region of interest of the waveform """ hutch = exp_name[:3] savePath = Path('/reg/d/psdm/{}/{}/calib'.format(hutch, exp_name)) dstr = 'exp={}:run={}'.format(exp_name, run) print('\n' + dstr + '\n') ds = ps.MPIDataSource(dstr) det = dobj.DetObject(det_name, ds.env(), int(run)) """ ---------------------------- GET BASIS ---------------------------- """ waveforms = [] ii = 0 for nevt, evt in enumerate(ds.events()): if ii > nWaveforms: break try: det.getData(evt) wave = np.squeeze(det.evt.dat) # print(wave.shape) except: continue if b is not None: wave = wave - np.mean(wave[:b]) if roi is not None: wave = wave[roi[0]:roi[1]] waveforms.append(wave) ii += 1 waveforms = np.asarray(waveforms) # print(waveforms.shape) A, proj, svd = proc.get_basis_and_projector(waveforms, n_components=n_c) """ ---------------------------- SAVE DATA ---------------------------- """ fname = 'wave_basis_' + det_name + '_' + datetime.datetime.now().strftime( "%Y%m%d_%H%M%S") + '.h5' print(fname) fname = savePath / fname # fname = Path('./') / fname with h5.File(fname, 'w') as f: dset = f.create_dataset("A", data=A) dset = f.create_dataset("projector", data=proj) dset = f.create_dataset("components", data=svd.components_) dset = f.create_dataset("singular_values", data=svd.singular_values_) dset = f.create_dataset("ref_waveforms", data=waveforms) dset = f.create_dataset("roi", data=roi) dset = f.create_dataset("background_index", data=b) print('Basis file saved as {}.'.format(fname)) return fname
dsname='exp='+expname+':run='+run+':smd' if args.offline: dsname='exp='+expname+':run='+run+':smd' if args.gather: gatherInterval=args.gather if args.nevt: maxNevt=args.nevt if args.dir: dirname=args.dir if dirname[-1]=='/': dirname=dirname[:-1] debug = True time_ev_sum = 0. try: ds = psana.MPIDataSource(dsname) except: print 'failed to make MPIDataSource for ',dsname import sys sys.exit() try: if dirname is None: dirname = '/reg/d/psdm/%s/%s/hdf5/smalldata'%(hutch.lower(),expname) smldataFile = '%s/%s_Run%03d.h5'%(dirname,expname,int(run)) smldata = ds.small_data(smldataFile,gather_interval=gatherInterval) if args.live: smldata.connect_redis() except: print 'failed making the output file ',smldataFile
history import psana from pylab import from pylab import * myDataSource = psana.MPIDataSource("exp=sxr10116:run=73") psana.DetNames() andorDetectorObject = psana.Detector('andor') myEnumeratedEvents = enumerate(myDataSource.events()) eventNumber,thisEvent = next(myEnumeratedEvents) andorDetectorObject(thisEvent) andorDetectorObject.image(thisEvent) eventNumber,thisEvent = next(myEnumeratedEvents) andorDetectorObject.image(thisEvent) eventNumber,thisEvent = next(myEnumeratedEvents) andorDetectorObject.image(thisEvent) eventNumber,thisEvent = next(myEnumeratedEvents) andorDetectorObject.image(thisEvent) eventNumber,thisEvent = next(myEnumeratedEvents) andorDetectorObject.image(thisEvent) eventNumber,thisEvent = next(myEnumeratedEvents) andorDetectorObject.image(thisEvent) eventNumber,thisEvent = next(myEnumeratedEvents) andorDetectorObject.image(thisEvent) eventNumber,thisEvent = next(myEnumeratedEvents) zeros([5,5]) if i in enumeratedEvents: tempImage = andorDetectorObject.image(thisEvent) if(tempImage is not None): print i for i in enumeratedEvents: tempImage = andorDetectorObject.image(thisEvent)
delay_range_upper = args.time_high # in units of ps # count how many events are skipped skipctr = 0 count = 0 #ds = psana.DataSource('exp=' + expname + ':run=%s:smd'%run_num) # ds = psana.MPIDataSource('exp=' + expname + ':run=%s:smd'%run_num) # psana.DataSource('dir=/reg/d/ffb/xpp/xpph6615/xtc/:exp=xpph6615:run=%s:idx'%run) if args.custom_calibration_directory != '': print('Using a custom calibration directory: ' + args.custom_calibration_directory) psana.setOption('psana.calib-dir', args.custom_calibration_directory) if pull_from_ffb == 0: ds = psana.MPIDataSource('exp=' + expname + ':run=%s:smd' % run_num) else: ds = psana.MPIDataSource('exp=' + expname + ':run=%s:smd:dir=/cds/data/drpsrcf/xpp/' % run_num + expname + '/xtc') epics = ds.env().epicsStore() configStore = ds.env().configStore() evr2skip = laseroffevr total_events = 0 ipm2_src = psana.Source('BldInfo(XPP-SB2-BMMON)') ipm3_src = psana.Source('BldInfo(XPP-SB3-BMMON)') evr_src = psana.Source("NoDetector.0:Evr.0") cspadDet = psana.Detector('jungfrau1M', ds.env())
#!/usr/bin/env python print 'Use command: mpirun -n 8 python hexanode/examples/ex-09-MPIDataSource.py' from time import time import psana from pyimgalgos.GlobalUtils import print_ndarr #ds = psana.DataSource('exp=xpptut15:run=390') # :smd ? #det = psana.Detector('AmoETOF.0:Acqiris.0') dsource = psana.MPIDataSource('exp=xpptut15:run=54:smd') cspaddet = psana.Detector('cspad') smldata = dsource.small_data('run54.h5', gather_interval=100) partial_run_sum = None for nevt, evt in enumerate(dsource.events()): calib = cspaddet.calib(evt) if calib is None: continue cspad_sum = calib.sum() # number cspad_roi = calib[0][0][3:5] # array if partial_run_sum is None: partial_run_sum = cspad_roi else: partial_run_sum += cspad_roi # save per-event data smldata.event(cspad_sum=cspad_sum, cspad_roi=cspad_roi) if nevt > 3: break
import matplotlib.pyplot as plt import h5py as h5 from scipy.signal import savgol_filter as savgol from scipy.interpolate import interp1d import IPython #from importlib import reload import psana as ps import ana_fun as ana reload(ana) """ ---------------------------- """ exp_name = 'sxri0414' run = 60 dstr = 'exp={}:run={}:smd'.format(exp_name, run) dsource = ps.MPIDataSource(dstr) #h5_dir = '/reg/d/psdm/SXR/sxri0414/hdf5' h5_dir = './' fh5 = h5_dir + 'test.h5' smldata = dsource.small_data(fh5, gather_interval=100) #save file for nevt,evt in enumerate(dsource.events()): if nevt==50: break if not (nevt % 100): print('Running event number {}\n'.format(nevt)) #try: dl = ps.Detector('SXR:LAS:MCN1:08.RBV')()
def smooth(x, beta=10.0, window_size=11): """a nice recipe""" if window_size % 2 == 0: window_size += 1 s = np.r_[x[window_size - 1:0:-1], x, x[-1:-window_size:-1]] w = np.kaiser(window_size, beta) y = np.convolve(w / w.sum(), s, mode='valid') b = (window_size - 1) / 2 smoothed = y[b:len(y) - b] return smoothed ds = psana.MPIDataSource("exp=%s:run=%d:smd" % (exp, run)) smldata = ds.small_data(outname) # , gather_interval=100) # for finding the max position(s) in power spectrum # we use Kmeans k_for_max = KMeans(n_clusters=2) events = ds.events() #### # first iterate and figure out how long the traces are has_mpi = True Npts = None for i_ev, ev in enumerate(events): xx.processEvent(ev) pulse_t, pulse_power = xx.xRayPower() if pulse_power is not None: Npts = pulse_power[0].shape[0] break
#%matplotlib acqiris_alias = "Acq02" eigen_basis_file = "eigen_traces.h5" experiment_name = "sxrx21715" run_number = "193" channel_number = 3 event_number = 80 #################### ##################### my_eigen_basis = h5py.File(eigen_basis_file) eig_bas = array( my_eigen_basis['summary/nonMeaningfulCoreNumber0/' + acqiris_alias + '/ch' + str(channel_number) + '/norm_eigen_wave_forms']) import psana my_data_source = psana.MPIDataSource("exp=" + experiment_name + ":run=" + run_number + ":smd") acq_det_obj = psana.Detector(acqiris_alias) my_enum_events = enumerate(my_data_source.events()) for evt_num, this_event in my_enum_events: if evt_num > event_number: break my_index = argmax((this_event.get( psana.EventId).fiducials() == my_dict['fiducials']).astype(int)) #plot(acq_det_obj(this_event)[0][channel_number]-mean(acq_det_obj(this_event)[0][channel_number][:300])) plot( acq_det_obj(this_event)[0][channel_number] - mean(acq_det_obj(this_event)[0][channel_number][:300])) plot( dot( my_dict[acqiris_alias + '/ch' + str(channel_number) +
import psana import sys import numpy as np import matplotlib.pyplot as plt run = int(sys.argv[-1]) # make me better yash def tt_correction(edge): a = -1.527864480143 b = 0.003652900467 c = -0.000001106143 return (a + b * edge + c * edge**2) / 1000. ds = psana.MPIDataSource('exp=cxilr3816:run=%d' % run) smd = ds.small_data('run%d_data.h5' % run) evr = psana.Detector('NoDetector.0:Evr.1') acq = psana.Detector('Acqiris') las_dly = psana.Detector('LAS:FS5:VIT:FS_TGT_TIME_DIAL') tt_edge = psana.Detector('CXI:TTSPEC:FLTPOS') tt_fwhm = psana.Detector('CXI:TTSPEC:FLTPOSFWHM') tt_famp = psana.Detector('CXI:TTSPEC:AMPL') tt_stage_pos = psana.Detector('CXI:LAS:MMN:04') # convert me from mm to ns for n, evt in enumerate(ds.events()): try:
from pylab import * import psana ############################################# ############standard intro################### #Live data during beamtime #dsource = psana.MPIDataSource('exp=sxr22915:run=104:smd:dir=/reg/d/ffb/sxr/sxro5916/xtc:live') #After beamtime dsource = psana.MPIDataSource("exp=sxrx22915:run=104") #smldata = dsource.small_data('run104.h5') smldata = dsource.small_data('run104c.h5') f = open("manualWriteRun104.dat", "w") psana.DetNames() ############################################# ############defining detector objects######## kbFluorescenceMontior = psana.Detector("Acq02") imagingDetectorObject = psana.Detector("pnccd") #xSampleAxis = psana.Detector("SXR:RCI:MZM:SMP:x.RBV") ############################################# ############enumerating events############### enumeratedEvents = enumerate(dsource.events()) eventNumber, myEvent = next(enumeratedEvents) MCP = kbFluorescenceMontior(myEvent)[0][3]
import psana from pylab import * my_list = arange(71,118) for i in my_list: myDataSource = psana.MPIDataSource("exp=sxrlr0716:run="+str(i)) my_events = myDataSource.events() evt = next(my_events) env = myDataSource.env() configs = env.configStore() configs.keys() andor_config = configs.get(psana.Andor.ConfigV2) print("run = "+str(i)+ " readout speed = "+str(andor_config.readoutSpeedIndex()))
import psana import numpy as np from matplotlib import pyplot as plt ds = psana.MPIDataSource('exp=cxilr3816:run=8:smd') smd = ds.small_data('run8_acq_data.h5') las_dly = psana.Detector('LAS:FS5:VIT:FS_TGT_TIME_DIAL', ds.env()) tt_edge = psana.Detector('CXI:TTSPEC:FLTPOS', ds.env()) delayArray = [] edgeArray = [] for evt in ds.events(): delayArray.append(las_dly(evt)) edgeArray.append(tt_edge(evt)) edgeArray = np.array(edgeArray[0:19800]) delayArray = np.array(delayArray[0:19800]) for n, evt in enumerate(ds.events()): try: diode = np.sum(acq(evt)[0][0, 760:860]) except: diode = None delay = las_delay(evt) smd.event(acqiris=diode, las_delay=delay) if smd.master:
def main(fileName): #global myDict global my_dict #f = h5py.File("sxr10116run73.h5",'r') #f = h5py.File(fileName,'r') my_hdf5_object = h5py.File("sxrx30116run6.h5", 'r') #f = h5py.File("sxrx24615run21.h5",'r') #for i in f: # print(str(i)) # print(str(array(f[i])[:10])) #f.close() #myDict= hdf5_to_dict(f) #convert hdf5 to dict my_list = [] def func(name, obj): my_list.append(name) my_hdf5_object.visititems(func) my_dict = {} for i in my_list: try: my_dict[i] = array(my_hdf5_object[i]) except: #IPython.embed() pass my_hdf5_object.close() #%matplotlib acqiris_alias = "Acq01" eigen_basis_file = "eigen_traces.h5" experiment_name = "sxrx30116" run_number = "6" channel_number = 3 event_number = 80 #################### ##################### my_eigen_basis = h5py.File(eigen_basis_file) eig_bas = array( my_eigen_basis['summary/nonMeaningfulCoreNumber0/' + acqiris_alias + '/ch' + str(channel_number) + '/norm_eigen_wave_forms']) import psana my_data_source = psana.MPIDataSource("exp=" + experiment_name + ":run=" + run_number + ":smd") acq_det_obj = psana.Detector(acqiris_alias) my_enum_events = enumerate(my_data_source.events()) for evt_num, this_event in my_enum_events: if evt_num > event_number: break my_index = argmax((this_event.get( psana.EventId).fiducials() == my_dict['fiducials']).astype(int)) #plot(acq_det_obj(this_event)[0][channel_number]-mean(acq_det_obj(this_event)[0][channel_number][:300])) plot( acq_det_obj(this_event)[0][channel_number] - mean(acq_det_obj(this_event)[0][channel_number][:300])) plot( dot( my_dict[acqiris_alias + '/ch' + str(channel_number) + '/weightings'][evt_num], eig_bas), 'r.') show()
#runNum = sys.argv[1] runNum = "38" #ds = psana.DataSource('exp=xpptut15:run=340') #test data from AMO runs 10, 15, and 19 #ds = psana.DataSource('exp=sxrm2316:run=103') #real data from specified experiment (sxrm2316) #ds = psana.DataSource('exp=sxrlq7615:run='+runNum) #ds = psana.MPIDataSource('exp=sxrlq7615:run='+runNum+':smd') #ds = psana.MPIDataSource('exp=sxrlq7615:run='+runNum+':smd') #ds = psana.MPIDataSource('exp=xpptut15:run='+str(runNum)) #myDataSource = psana.MPIDataSource('exp=sxrk3016:run=118:smd') #myDataSource = psana.MPIDataSource('exp=sxr10116:run=73:smd') #myDataSource = psana.MPIDataSource('exp=sxri0414:run=60:smd',module=ttAnalyze) #myDataSource = psana.MPIDataSource('exp=amolp0515:run=105:smd',module=ttAnalyze) #myDataSource = psana.MPIDataSource('exp=sxrlp2615:run=6:smd') myDataSource = psana.MPIDataSource('exp=xpptut15:run=360') #psana.DetNames() #acqirisDetectorObject = psana.Detector("Acq02") andorDetectorObject = psana.Detector('andor') #pnccdDetectorObject = psana.Detector('pnccdFront') #tssOpalDetectorObject = psana.Detector('TSS_OPAL') myEnumeratedEvents = enumerate(myDataSource.events()) myImage = 0 myHist = 0 for eventNumber, thisEvent in myEnumeratedEvents:
import psana import sys import numpy as np from matplotlib import pyplot as plt from decimal import Decimal from random import randint run = int(sys.argv[-1]) ds = psana.MPIDataSource('exp=cxix29016:run=%d' % run) det = psana.Detector('DsaCsPad') gas_det = psana.Detector('FEEGasDetEnergy') phot_energy = psana.Detector('EBeam') low_filter_PE = 0.95 high_filter_PE = 1.05 low_filter_I = 0.9 high_filter_I = 1.1 def accessData(run): photon_energies = [] intensities = [] pulse_energies = [] total_events = [] low_limit = 0.90 high_limit = 1.10
if args.gather: gatherInterval=args.gather if args.nevt: maxNevt=args.nevt if args.dir: dirname=args.dir if dirname[-1]=='/': dirname=dirname[:-1] if args.norecorder: dsname=dsname+':stream=0-79' debug = True time_ev_sum = 0. try: ds = psana.MPIDataSource(str(dsname)) except: print('failed to make MPIDataSource for ',dsname) import sys sys.exit() try: if dirname is None: dirname = '/reg/d/psdm/%s/%s/hdf5/smalldata'%(hutch.lower(),expname) smldataFile = '%s/%s_Run%03d.h5'%(dirname,expname,int(run)) smldata = ds.small_data(smldataFile,gather_interval=gatherInterval) except: print('failed making the output file ',smldataFile) import sys
if nevent > 10: cspad_data=cspadDet.image(ev) if cspad_data is None: print("*** missing cspad data. Skipping event...") continue break cspad_data_shape = cspad_data.shape else: cspad_data_shape = None # print(cspad_data_shape) comm.Barrier() cspad_data_shape = comm.bcast(cspad_data_shape, root=0) #### ds = psana.MPIDataSource('exp=' + expname + ':run=%s:smd'%run_num) # psana.DataSource('dir=/reg/d/ffb/xpp/xpph6615/xtc/:exp=xpph6615:run=%s:idx'%run) epics = ds.env().epicsStore() configStore = ds.env().configStore() total_events = 0 cspadDet = psana.Detector('jungfrau1M',ds.env()) ipm2_src = psana.Source('BldInfo(XPP-SB2-BMMON)') ipm3_src = psana.Source('BldInfo(XPP-SB3-BMMON)') evr_src = psana.Source("DetInfo(NoDetector.0:Evr.0)") def mpi_message(msg): if rank == 0: print(msg)
level=myloglevel) EXPSTR = 'exp=mfxx32516:run=%d:smd' % (args.run[0]) # EXPSTR = 'exp=mfxx32516:run=%d:smd:dir=/reg/d/ffb/mfx/mfxx32516/xtc:live' % (args.run[0]) # 'MfxEndstation.0:Epix10ka.0' # spaghetti # 'MfxEndstation.0:Epix10ka.1' # meatballs # 'MfxEndstation.0:Epix10ka.2' # cheese # filename = "".join([c for c in EXPSTR if c.isalnum()]).rstrip() + '.h5' filename = "run_%d.h5" % (args.run[0]) comm = MPI.COMM_WORLD rank = comm.Get_rank() size = comm.Get_size() dsrc = pa.MPIDataSource(EXPSTR) detNames = pa.DetNames() # detector names mdets = [] # list of detectors mdets_sname = [] # list of short detector names mdets_idx = [] # list of detector indicies # only archive detectors of interest for idx, detname in enumerate(detNames): sdet = detname[0].lower() if "epix10ka" in sdet or "beammon" in sdet or "acqiris" in sdet or "wave8" in sdet: mdets.append(detname[0]) mdets_sname.append(detname[1]) mdets_idx.append(idx) # lists to keep track of detectors mdets_d = []