From 16a0cb0faf4208e5286910736710a6bf482e4ffd Mon Sep 17 00:00:00 2001 From: lemke_h Date: Sat, 12 Sep 2026 15:13:30 +0200 Subject: [PATCH] Remove redundant det_jf; add dummy 2D test fixture; fix mesh-scan repetitions crash; add eco-escape-test - Remove det_jf: now that det_diff was fixed to JF01T03V01 (previous commit), det_jf was a second device pointing at the same physical Jungfrau, otherwise unreferenced anywhere. - Add bernina.dummy (DummyMexicanHat): x, y (DummyAdjustable) + imex (DetectorGet reading a live 2D Mexican-hat signal of their current values, (1-r^2)*exp(-r^2/2), r=sqrt(x^2+y^2) -- stays within [-1, 1] for any x, y, small Gaussian noise by default). No real hardware; for testing grid-scan / live 2D counter-grid machinery. - Fix Scans.meshscan(..., repetitions=N>1): grid_specs["index_plan"] is built once, for a single pass over the grid, before StepScan.__init__ repeats `values`/`pulses_per_step` by `repetitions` -- so do_next_step()'s gridspecs["index_plan"][self.next_step] indexed past the end (IndexError) the moment the scan entered its second repetition. Now repeats index_plan the same way. - Add scripts/eco-escape-test: like eco-dev, but also prepends a sibling escape-fel checkout to PYTHONPATH (assumed to live next to this eco checkout), for testing local checkouts of both together instead of whatever's installed. Co-Authored-By: Claude Sonnet 5 --- eco/acquisition/scan.py | 8 +++++++ eco/bernina/bernina.py | 13 ---------- eco/bernina/bernina_status_log.py | 40 +++++++++++++++++++++++++++++++ scripts/eco-escape-test | 31 ++++++++++++++++++++++++ 4 files changed, 79 insertions(+), 13 deletions(-) create mode 100755 scripts/eco-escape-test diff --git a/eco/acquisition/scan.py b/eco/acquisition/scan.py index 59d7885..de0ee3d 100755 --- a/eco/acquisition/scan.py +++ b/eco/acquisition/scan.py @@ -125,6 +125,14 @@ class StepScan(Assembly): if repetitions > 1: values = values * repetitions self.pulses_per_step = self.pulses_per_step * repetitions + if gridspecs is not None: + # index_plan has one entry per step of a *single* pass over + # the grid (built once, in meshscan(), before repetitions + # was applied here) -- without repeating it too, + # do_next_step()'s gridspecs["index_plan"][self.next_step] + # indexes past the end (IndexError) the moment the scan + # enters its second repetition. + gridspecs = dict(gridspecs, index_plan=gridspecs["index_plan"] * repetitions) print( f"Repeating scan {repetitions} times. Total steps: {len(values)}, {len(values)/repetitions} per repetition." ) diff --git a/eco/bernina/bernina.py b/eco/bernina/bernina.py index 292a4b4..b894bf1 100644 --- a/eco/bernina/bernina.py +++ b/eco/bernina/bernina.py @@ -937,19 +937,6 @@ class XrayWaveplate(Assembly): # is_display=True, # ) - self._append( - Jungfrau, - "JF01T03V01", - config_adj=daq.config_JFs, - pgroup_adj=config_bernina.pgroup, - event_master=NamespaceComponent(namespace, "event_master"), - detectors_event_code=50, - name="det_jf", - is_setting=True, - is_status=True, - # is_display="recursive", - ) - self._append( DigitizerIoxosBoxcarChannel, "SARES20-LSCP9-FNS:CH1", name="diode_side" ) diff --git a/eco/bernina/bernina_status_log.py b/eco/bernina/bernina_status_log.py index fa1186e..36ce383 100644 --- a/eco/bernina/bernina_status_log.py +++ b/eco/bernina/bernina_status_log.py @@ -1,5 +1,10 @@ +import numpy as np + from eco.bernina.bernina import namespace from eco.utilities.config import NamespaceComponent +from eco.elements.assembly import Assembly +from eco.elements.adjustable import DummyAdjustable +from eco.elements.detector import DetectorGet import eco namespace.append_obj( @@ -58,6 +63,41 @@ namespace.append_obj( name="dummy_adjustable", ) + +class DummyMexicanHat(Assembly): + """Test fixture: two independent DummyAdjustables (x, y) plus a + detector (imex) reading a live 2D Mexican-hat (Ricker wavelet) signal + of their current values -- no real hardware, for testing grid-scan / + live 2D counter-grid machinery (Stream/Array Grid support, live 2D + plotting, 2D peak finding, ...) without needing real hardware. + + imex = (1 - r**2) * exp(-r**2 / 2), r = sqrt(x**2 + y**2): peaks at + 1.0 at the origin (x=y=0), crosses zero at r=1, and reaches its most + negative value (~-0.44) around r=sqrt(3) -- stays within [-1, 1] for + any x, y. A little Gaussian noise is added by default (see + noise_amplitude) so it behaves like a real noisy detector rather than + an exact deterministic function. + """ + + def __init__(self, name=None, limits=(-3, 3), noise_amplitude=0.02): + super().__init__(name=name) + self._noise_amplitude = noise_amplitude + self._append(DummyAdjustable, name="x", limits=list(limits)) + self._append(DummyAdjustable, name="y", limits=list(limits)) + self._append(DetectorGet, self._get_imex, name="imex", is_setting=False) + + def _get_imex(self): + x = self.x.get_current_value() + y = self.y.get_current_value() + r2 = x**2 + y**2 + value = (1 - r2) * np.exp(-r2 / 2) + if self._noise_amplitude: + value += np.random.normal(0, self._noise_amplitude) + return float(value) + + +namespace.append_obj(DummyMexicanHat, name="dummy", lazy=True) + namespace.append_obj( "set_global_memory_dir", "/sf/bernina/code/gac-bernina/eco_cnf_bernina/memory", diff --git a/scripts/eco-escape-test b/scripts/eco-escape-test new file mode 100755 index 0000000..0e8d9fc --- /dev/null +++ b/scripts/eco-escape-test @@ -0,0 +1,31 @@ +#!/bin/bash +# Dev entry point for testing this eco checkout together with a sibling +# escape-fel checkout -- like scripts/eco-dev, but also prepends a local +# escape-fel checkout to PYTHONPATH, ahead of whatever `escape`/`escape-fel` +# is installed in the environment (bpy312), so `import escape` resolves to +# that checkout instead of the installed release. +# +# Assumes the escape-fel checkout lives right next to this eco checkout, +# i.e. as a sibling directory under the same parent (e.g. ~/drv/eco and +# ~/drv/escape-fel) -- resolved from this script's own location the same +# way eco-dev resolves the eco checkout, so it works from any eco checkout +# with such a sibling, not just this one. +# +# Usage: same as eco-dev, e.g. +# eco-escape-test -s bernina -l --ui shell +# +# See eco-dev's own header comment for why PYTHONPATH specifically (not +# just sys.path) is what needs prepending here. +source bpy-env + +ECO_CHECKOUT="$(dirname "$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")")" +ESCAPE_CHECKOUT="$(dirname "$ECO_CHECKOUT")/escape-fel" + +if [ ! -d "$ESCAPE_CHECKOUT/escape" ]; then + echo "eco-escape-test: no escape-fel checkout found at $ESCAPE_CHECKOUT" >&2 + echo " (expected as a sibling directory of this eco checkout: $ECO_CHECKOUT)" >&2 + exit 1 +fi + +export PYTHONPATH="${ESCAPE_CHECKOUT}:${ECO_CHECKOUT}${PYTHONPATH:+:$PYTHONPATH}" +exec python "${ECO_CHECKOUT}/eco_cli.py" "$@"