Skip to content
Snippets Groups Projects
Commit 7395a534 authored by Tamas Gal's avatar Tamas Gal :speech_balloon:
Browse files

Make rates settable

parent 6115b7f7
No related branches found
No related tags found
No related merge requests found
...@@ -51,10 +51,12 @@ class PMTRates(kp.Module): ...@@ -51,10 +51,12 @@ class PMTRates(kp.Module):
self.interval = self.get("interval", default=10) self.interval = self.get("interval", default=10)
self.plot_path = self.get("plot_path", default="plots") self.plot_path = self.get("plot_path", default="plots")
self.filename = self.get("filename", default="pmt_rates.png") self.filename = self.get("filename", default="pmt_rates.png")
self.lowest_rate = self.get("lowest_rate", default=5000)
self.highest_rate = self.get("highest_rate", default=15000)
self.max_x = 800 self.max_x = 800
self.index = 0 self.index = 0
self.rates = defaultdict(list) self.rates = defaultdict(list)
self.rates_matrix = np.full((18*31, self.max_x), np.nan) self.rates_matrix = np.full((18 * 31, self.max_x), np.nan)
self.lock = threading.Lock() self.lock = threading.Lock()
self.thread = threading.Thread(target=self.run, args=()) self.thread = threading.Thread(target=self.run, args=())
self.thread.daemon = True self.thread.daemon = True
...@@ -71,9 +73,9 @@ class PMTRates(kp.Module): ...@@ -71,9 +73,9 @@ class PMTRates(kp.Module):
self.rates = defaultdict(list) self.rates = defaultdict(list)
delta_t = (datetime.now() - now).total_seconds() delta_t = (datetime.now() - now).total_seconds()
remaining_t = self.interval - delta_t remaining_t = self.interval - delta_t
log.info("Delta t: {} -> waiting for {}s" log.info("Delta t: {} -> waiting for {}s".format(
.format(delta_t, self.interval - delta_t)) delta_t, self.interval - delta_t))
if(remaining_t < 0): if (remaining_t < 0):
log.error("Can't keep up with plot production. " log.error("Can't keep up with plot production. "
"Increase the interval!") "Increase the interval!")
interval = 1 interval = 1
...@@ -82,7 +84,7 @@ class PMTRates(kp.Module): ...@@ -82,7 +84,7 @@ class PMTRates(kp.Module):
def add_column(self): def add_column(self):
m = np.roll(self.rates_matrix, -1, 1) m = np.roll(self.rates_matrix, -1, 1)
y_range = 18*31 y_range = 18 * 31
mean_rates = np.full(y_range, np.nan) mean_rates = np.full(y_range, np.nan)
for i in range(y_range): for i in range(y_range):
if i not in self.rates: if i not in self.rates:
...@@ -103,20 +105,23 @@ class PMTRates(kp.Module): ...@@ -103,20 +105,23 @@ class PMTRates(kp.Module):
return datetime.utcfromtimestamp(timestamp).strftime("%H:%M") return datetime.utcfromtimestamp(timestamp).strftime("%H:%M")
m = self.rates_matrix m = self.rates_matrix
m[m > 15000] = 15000 m[m > self.highest_rate] = self.highest_rate
m[m < 5000] = 5000 m[m < self.lowest_rate] = self.lowest_rate
fig, ax = plt.subplots(figsize=(10, 8)) fig, ax = plt.subplots(figsize=(10, 8))
ax.imshow(m, origin='lower', interpolation='none') ax.imshow(m, origin='lower', interpolation='none')
ax.set_title("Mean PMT Rates (Monitoring Channel) for DetID-{} DU-{} " ax.set_title("Mean PMT Rates (Monitoring Channel) for DetID-{} DU-{} "
"- colours from 5kHz to 15kHz\n" "- colours from {:.1f}kHz to {:.1f}kHz\n"
"PMTs ordered from top to bottom - {}" "PMTs ordered from top to bottom - {}".format(
.format(self.detector.det_id, self.du, datetime.utcnow())) self.detector.det_id, self.du,
self.lowest_rate / 1000, self.highest_rate / 1000,
datetime.utcnow()))
ax.set_xlabel("UTC time [{}s/px]".format(interval)) ax.set_xlabel("UTC time [{}s/px]".format(interval))
plt.yticks([i*31 for i in range(18)], plt.yticks([i * 31 for i in range(18)],
["Floor {}".format(f) for f in range(1, 19)]) ["Floor {}".format(f) for f in range(1, 19)])
xtics_int = range(0, max_x, int(max_x/10)) xtics_int = range(0, max_x, int(max_x / 10))
plt.xticks([i for i in xtics_int], plt.xticks(
[xlabel_func(now-(max_x-i) * interval) for i in xtics_int]) [i for i in xtics_int],
[xlabel_func(now - (max_x - i) * interval) for i in xtics_int])
fig.tight_layout() fig.tight_layout()
plt.savefig(filename) plt.savefig(filename)
plt.close('all') plt.close('all')
...@@ -162,17 +167,19 @@ def main(): ...@@ -162,17 +167,19 @@ def main():
detector = kp.hardware.Detector(det_id=det_id) detector = kp.hardware.Detector(det_id=det_id)
pipe = kp.Pipeline(timeit=True) pipe = kp.Pipeline(timeit=True)
pipe.attach(kp.io.ch.CHPump, pipe.attach(
host=ligier_ip, kp.io.ch.CHPump,
port=ligier_port, host=ligier_ip,
tags='IO_MONIT', port=ligier_port,
timeout=60*60*24*7, tags='IO_MONIT',
max_queue=2000) timeout=60 * 60 * 24 * 7,
pipe.attach(PMTRates, max_queue=2000)
detector=detector, pipe.attach(
du=du, PMTRates,
interval=interval, detector=detector,
plot_path=plot_path) du=du,
interval=interval,
plot_path=plot_path)
pipe.drain() pipe.drain()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment