Skip to content

Commit

Permalink
WIP: Apply black formatting to standalone_scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
nstelter-slac committed Mar 5, 2024
1 parent 3523e48 commit 75ddc47
Show file tree
Hide file tree
Showing 14 changed files with 387 additions and 384 deletions.
38 changes: 19 additions & 19 deletions standalone_scripts/5kHz.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@
import numpy as np

run = eval(sys.argv[1])
ds = DataSource(exp='rixx45619',run=run)
ds = DataSource(exp="rixx45619", run=run)
myrun = next(ds.runs())
det = myrun.Detector('epixhr')
timing = myrun.Detector('timing')
det = myrun.Detector("epixhr")
timing = myrun.Detector("timing")

print('pedestal means, 7 modes:',det.calibconst['pedestals'][0].mean(axis=(1,2,3)))
print('pedestal maxes, 7 modes:',det.calibconst['pedestals'][0].max(axis=(1,2,3)))
print("pedestal means, 7 modes:", det.calibconst["pedestals"][0].mean(axis=(1, 2, 3)))
print("pedestal maxes, 7 modes:", det.calibconst["pedestals"][0].max(axis=(1, 2, 3)))

fl = []
n = 0
n20 = []


desiredCode = {'120Hz':272, '4kHz':273, '5kHz':274}
desiredCode = {"120Hz": 272, "4kHz": 273, "5kHz": 274}

lastEventWas120Hz = False
nFoo = 0
Expand All @@ -26,35 +26,35 @@
if lastEventWas120Hz:
## do something
pass
if not allcodes[desiredCode['120Hz']]:
## print("found", allcodes, "not", desiredCode)
## print("no 120Hz")
if not allcodes[desiredCode["120Hz"]]:
## print("found", allcodes, "not", desiredCode)
## print("no 120Hz")
mean = det.raw.raw(evt).mean()
print("mean for event %d after 120Hz %0.3f" %(nFoo, mean))
print("mean for event %d after 120Hz %0.3f" % (nFoo, mean))

np.save("not120_%d.npy" %(nFoo), det.raw.raw(evt))
np.save("not120_%d.npy" % (nFoo), det.raw.raw(evt))
if lastEventWas120Hz:
print("mean for event after 120Hz %0.3f" %(mean))
np.save("lastEventWas120Hz_%d.npy" %(n120s-1), det.raw.raw(evt))
print("mean for event after 120Hz %0.3f" % (mean))
np.save("lastEventWas120Hz_%d.npy" % (n120s - 1), det.raw.raw(evt))
nFoo += 1
lastEventWas120Hz = False
continue
else:
print("found 120Hz after %d, %0.3f" %(nFoo, mean))
print("found 120Hz after %d, %0.3f" % (nFoo, mean))
mean = det.raw.raw(evt).mean()
np.save("thisEventWas120Hz_%d.npy" %(n120s), det.raw.raw(evt))
print("mean now %0.3f" %(mean))
np.save("thisEventWas120Hz_%d.npy" % (n120s), det.raw.raw(evt))
print("mean now %0.3f" % (mean))
nFoo = 0
n120s += 1
lastEventWas120Hz = True
##136 means NEH got the beam
##136 means NEH got the beam

rawFrames = det.raw.raw(evt)
frames = det.raw.calib(evt)
n20.append((frames>20).sum())
n20.append((frames > 20).sum())
fl.append(frames)
n += 1
if n%1000 == 0:
if n % 1000 == 0:
print(n)
fl = np.array(fl)
print(n)
Expand Down
36 changes: 19 additions & 17 deletions standalone_scripts/DamageCounter.py
Original file line number Diff line number Diff line change
@@ -1,47 +1,49 @@
from psana import DataSource
import os
import numpy as np
os.environ['PS_SMD_N_EVENTS'] = '50'
os.environ['PS_SRV_NODES']='1'

ds = DataSource(exp='rixc00121', run=32, intg_det='epixhr')
smd = ds.smalldata(filename='ts.h5')

os.environ["PS_SMD_N_EVENTS"] = "50"
os.environ["PS_SRV_NODES"] = "1"

ds = DataSource(exp="rixc00121", run=32, intg_det="epixhr")
smd = ds.smalldata(filename="ts.h5")
myrun = next(ds.runs())
epix = myrun.Detector('epixhr')
timeObj = myrun.Detector('timing')
nevt=0
epix = myrun.Detector("epixhr")
timeObj = myrun.Detector("timing")
nevt = 0
nBeam = 0
for nevt,evt in enumerate(myrun.events()):
for nevt, evt in enumerate(myrun.events()):
if evt is None:
continue
ec = timeObj.raw.eventcodes(evt)
if not ec[281]:
continue
nBeam += 1

frames = epix.raw.raw(evt)
if frames is None:
continue
smd.event(evt, ts=evt.datetime().timestamp(), nBeam=nBeam, nevt=nevt)

##if smd.summary:
## smd.save_summary(step_av) # this method accepts either a dictionary or kwargs
smd.done()

import matplotlib.pyplot as plt
import h5py

a = h5py.File("ts.h5")
mona_ts = a['timestamp'][()]
ts = a['ts'][()]
print(False in (ts ==mona_ts))
counter=np.arange(10000)
mona_ts = a["timestamp"][()]
ts = a["ts"][()]
print(False in (ts == mona_ts))
counter = np.arange(10000)
##plt.plot(counter[:400], ts[:400])
##plt.xlabel("entry")
##plt.ylabel("timestamp")
##plt.show()


nBeam = a['nBeam'][()]
nBeam = a["nBeam"][()]
print("nBeam max:", nBeam.max())
nevt = a['nevt'][()]
nevt = a["nevt"][()]
print("nevt max:", nevt.max())
Loading

0 comments on commit 75ddc47

Please sign in to comment.