Add option to bin tof values, rebuild projections on file change, switch to hs01 serialization and give nicos config help

This commit is contained in:
2025-10-15 10:39:59 +02:00
parent 2d8d1c66c6
commit 4e5d085ad7
5 changed files with 55 additions and 12 deletions

View File

@@ -34,7 +34,7 @@ import numpy as np
import json
from time import time
from dataclasses import dataclass, asdict
from streaming_data_types import histogram_hs00
from streaming_data_types import histogram_hs01
from confluent_kafka import Producer, Consumer, TopicPartition
from uuid import uuid4
@@ -70,7 +70,7 @@ class HistogramMessage:
info: str
def serialize(self):
return histogram_hs00.serialise_hs00(asdict(self))
return histogram_hs01.serialise_hs01(asdict(self))
@dataclass
class CommandMessage:

View File

@@ -544,12 +544,12 @@ class TofZProjection(ProjectionInterface):
('err', np.float64),
])
def __init__(self, tau, foldback=False):
def __init__(self, tau, foldback=False, combine=1):
self.z = np.arange(Detector.nBlades*Detector.nWires+1)-0.5
if foldback:
self.tof = np.arange(0, tau, 0.0005)
self.tof = np.arange(0, tau, 0.0005*combine)
else:
self.tof = np.arange(0, 2*tau, 0.0005)
self.tof = np.arange(0, 2*tau, 0.0005*combine)
self.data = np.zeros((self.tof.shape[0]-1, self.z.shape[0]-1), dtype=self._dtype).view(np.recarray)
self.monitor = 0.

View File

@@ -46,11 +46,7 @@ class KafkaReduction:
self.event_actions |= eh.ApplyMask()
def reduce(self):
last_file_header = AmorHeader(self.current_file)
self.proj_yz = YZProjection()
self.proj_tofz = TofZProjection(last_file_header.timing.tau, foldback=True)
self.create_projections()
self.read_data()
self.add_data()
@@ -59,6 +55,11 @@ class KafkaReduction:
self.loop()
def create_projections(self):
file_header = AmorHeader(self.current_file)
self.proj_yz = YZProjection()
self.proj_tofz = TofZProjection(file_header.timing.tau, foldback=True, combine=2)
def read_data(self):
self.dataset = AmorEventData(self.current_file, max_events=self.config.reduction.max_events)
@@ -82,8 +83,7 @@ class KafkaReduction:
logging.warning(f"Preceding to next file {latest}")
self.current_file = new_file
self.proj_yz.clear()
self.proj_tofz.clear()
self.create_projections() # need to recreate projections, in case tau changed
self.read_data()
self.add_data()

42
nicos_config.md Normal file
View File

@@ -0,0 +1,42 @@
EOS-Service
===========
EOS can be used as histogram service to send images to the Nicos instrument control software.
For that you need to run it on the amor instrument computer:
```bash
amor-nicos {-vv}
```
The instrument config in Nicos needs to configure a Kafka JustBinItImage instance
for each histogram that should be used:
```python
hist_yz = device('nicos_sinq.devices.just_bin_it.JustBinItImage',
description = 'Detector pixel histogram over all times',
hist_topic = 'AMOR_histograms_YZ',
data_topic = 'AMOR_detector',
command_topic = 'AMOR_histCommands',
brokers = ['linkafka01.psi.ch:9092'],
unit = 'evts',
hist_type = '2-D SANSLLB',
det_width = 446,
det_height = 64,
),
hist_tofz = device('nicos_sinq.devices.just_bin_it.JustBinItImage',
description = 'Detector time of flight vs. z-pixel histogram over all y-values',
hist_topic = 'AMOR_histograms_TofZ',
data_topic = 'AMOR_detector',
command_topic = 'AMOR_histCommands',
brokers = ['linkafka01.psi.ch:9092'],
unit = 'evts',
hist_type = '2-D SANSLLB',
det_width = 118,
det_height = 446,
),
```
These images have then to be set in the detector configuration as _images_ items:
```
images=['hist_yz', 'hist_tofz'],
```

View File

@@ -35,3 +35,4 @@ Homepage = "https://github.com/jochenstahn/amor"
console_scripts =
eos = eos.__main__:main
events2histogram = eos.e2h:main
amor-nicos = eos.nicos:main