diff --git a/eos/kafka_serializer.py b/eos/kafka_serializer.py index d09773a..ebc9865 100644 --- a/eos/kafka_serializer.py +++ b/eos/kafka_serializer.py @@ -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: diff --git a/eos/projection.py b/eos/projection.py index 36b8e1e..d78ee5f 100644 --- a/eos/projection.py +++ b/eos/projection.py @@ -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. diff --git a/eos/reduction_kafka.py b/eos/reduction_kafka.py index 83f33fd..3fd035e 100644 --- a/eos/reduction_kafka.py +++ b/eos/reduction_kafka.py @@ -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() diff --git a/nicos_config.md b/nicos_config.md new file mode 100644 index 0000000..72e85de --- /dev/null +++ b/nicos_config.md @@ -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'], +``` \ No newline at end of file diff --git a/setup.cfg b/setup.cfg index 7a88dc9..2c9fa4a 100644 --- a/setup.cfg +++ b/setup.cfg @@ -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