Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 19 additions & 29 deletions src/dashpva/consumers/hpc/analysis/hpc_rsm_consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import numpy as np
import pvaccess as pva
import xrayutilities as xu
from pvaccess import PvObject, NtAttribute
from pvaccess import PvObject
from pvapy.hpc.adImageProcessor import AdImageProcessor
from pvapy.utility.floatWithUnits import FloatWithUnits
from pvapy.utility.timeUtility import TimeUtility
Expand Down Expand Up @@ -150,7 +150,7 @@ def configure(self, configDict):
)

self.config = config
self.hkl_config = self.config.get('HKL') or {}
self.hkl_config = self.config.get('HKL', {})
self.hkl_pv_channels = set()
for section in self.hkl_config.values():
if isinstance(section, dict):
Expand Down Expand Up @@ -206,25 +206,16 @@ def get_sample_and_detector_circles(self, hkl_attr: dict):
return sample_circle_directions, sample_circle_positions, det_circle_directions, det_circle_positions

def get_axis_directions(self, hkl_attr: dict):
"""Get beam / reference / surface-normal direction triplets from hkl_attr.
# Get beam and reference directions
if len(hkl_attr) == len(self.hkl_pv_channels):
primary_beam_directions = [hkl_attr.get(f'PrimaryBeamDirection:AxisNumber{i}', None) for i in range(1,4)]
inplane_beam_direction = [hkl_attr.get(f'InplaneReferenceDirection:AxisNumber{i}', None) for i in range(1,4)]
sample_surface_normal_direction = [hkl_attr.get(f'SampleSurfaceNormalDirection:AxisNumber{i}', None) for i in range(1,4)]

PV names come from the active HKL config (which includes any prefix the
IOC publishes under), not hardcoded — so this works for `xidb:`,
`6idb:`, or unprefixed schemas without code changes.
"""
if len(hkl_attr) != len(self.hkl_pv_channels):
return primary_beam_directions, inplane_beam_direction, sample_surface_normal_direction
else:
return None, None, None

def _triplet(section_name):
section = self.hkl_config.get(section_name, {}) or {}
return [hkl_attr.get(section.get(f'AXIS_NUMBER_{i}', ''), None) for i in range(1, 4)]

primary_beam_directions = _triplet('PRIMARY_BEAM_DIRECTION')
# Section names match the (typo'd) keys used elsewhere in the config schema.
inplane_beam_direction = _triplet('INPLANE_REFERENCE_DIRECITON')
sample_surface_normal_direction = _triplet('SAMPLE_SURFACE_NORMAL_DIRECITON')
return primary_beam_directions, inplane_beam_direction, sample_surface_normal_direction

def get_ub_matrix(self, hkl_attr: dict):
ub_matrix_key = self.hkl_config['SPEC'].get('UB_MATRIX_VALUE', '')

Expand Down Expand Up @@ -259,18 +250,17 @@ def create_rsm(self, hkl_attr: dict, shape: tuple):
en=energy,
qconv=q_conv)

# Set up detector parameters — look up by the PV name in the active
# HKL config so any prefix (xidb:, 6idb:, none) works without edits.
ds_cfg = self.hkl_config.get('DETECTOR_SETUP', {}) or {}
# Set up detector parameters
roi = [0, shape[0], 0, shape[1]]
pixel_dir1 = hkl_attr[ds_cfg['PIXEL_DIRECTION_1']]
pixel_dir2 = hkl_attr[ds_cfg['PIXEL_DIRECTION_2']]
cch1, cch2 = hkl_attr[ds_cfg['CENTER_CHANNEL_PIXEL']][:2]
nch1, nch2 = shape[0], shape[1]
size_xy = hkl_attr[ds_cfg['SIZE']]
pixel_width1 = size_xy[0] / nch1
pixel_width2 = size_xy[1] / nch2
distance = hkl_attr[ds_cfg['DISTANCE']]
pixel_dir1 = hkl_attr['DetectorSetup:PixelDirection1']
pixel_dir2 = hkl_attr['DetectorSetup:PixelDirection2']
cch1 = hkl_attr['DetectorSetup:CenterChannelPixel'][0]
cch2 = hkl_attr['DetectorSetup:CenterChannelPixel'][1]
nch1 = shape[0]
nch2 = shape[1]
pixel_width1 = hkl_attr['DetectorSetup:Size'][0] / nch1
pixel_width2 = hkl_attr['DetectorSetup:Size'][1] / nch2
distance = hkl_attr['DetectorSetup:Distance']

hxrd.Ang2Q.init_area(
pixel_dir1, pixel_dir2,
Expand Down
34 changes: 7 additions & 27 deletions src/dashpva/consumers/hpc/meta/hpc_metadata_consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,6 @@ def __init__(self, configDict={}):
# The last object time
self.lastFrameTimestamp = 0

# Throttling for noisy timestamp-tolerance warnings
self._lastToleranceWarnTime = 0.0
self._toleranceWarnSuppressed = 0
self._toleranceWarnIntervalSec = 60.0
# Silent tally of "Metadata channel X not found" occurrences. Was
# previously logged at ERROR level, which the associator subprocess
# piped into the workflow GUI text box on every frame. Counting only —
# inspect self._mdMissingChannels if you need the per-channel tallies.
self._mdMissingChannels = {} # channel -> total count

# COPIED FROM hpc_rsm_consumer.py - Type mapping for compression
self.CODEC_PARAMETERS_MAP = {
np.dtype('uint8'): pva.UBYTE,
Expand Down Expand Up @@ -140,7 +130,7 @@ def configure(self, configDict):
with open(self.path, "r") as config_file:
self.config = toml.load(config_file)

self.hkl_config = self.config.get('HKL') or {}
self.hkl_config = self.config.get('HKL', {})
self.hkl_pv_channels = set()
for section in self.hkl_config.values():
if isinstance(section, dict):
Expand All @@ -161,11 +151,9 @@ def configure(self, configDict):
def associateMetadata(self, mdChannel, frameId, frameTimestamp, frameAttributes):
# self.logger.debug(f" current metadata map: {self.currentMetadataMap}") #modified since 3.8 env isn't working for me, works w/ 3.8
if mdChannel not in self.currentMetadataMap:
# Count silently — no logger.error, no print. The associator
# subprocess captures any ERROR-level output and pushes it into
# the workflow GUI text box on every frame, so logging here
# floods the UI.
self._mdMissingChannels[mdChannel] = self._mdMissingChannels.get(mdChannel, 0) + 1
self.logger.error(f'Metadata channel {mdChannel} not found in current metadata map')
print(f'Metadata channel {mdChannel} not found in current metadata map')

return False

mdObject = self.currentMetadataMap[mdChannel]
Expand Down Expand Up @@ -207,17 +195,9 @@ def associateMetadata(self, mdChannel, frameId, frameTimestamp, frameAttributes)
diff = abs(frameTimestamp - mdTimestamp2)
self.logger.debug(f'Metadata {mdChannel} has value of {mdValue}, timestamp: {mdTimestamp} (with offset: {mdTimestamp2}), timestamp diff: {diff}')
if diff > self.timestampTolerance:
now = time.time()
if now - self._lastToleranceWarnTime >= self._toleranceWarnIntervalSec:
suppressed = self._toleranceWarnSuppressed
suffix = f' ({suppressed} similar warnings suppressed)' if suppressed else ''
self.logger.warning(
f'[Metadata Associator] Rejecting {mdChannel}: timestamp diff {diff:.6f}s exceeds tolerance {self.timestampTolerance}s{suffix}'
)
self._lastToleranceWarnTime = now
self._toleranceWarnSuppressed = 0
else:
self._toleranceWarnSuppressed += 1
self.logger.warning(
f'[Metadata Associator] Rejecting {mdChannel}: timestamp diff {diff:.6f}s exceeds tolerance {self.timestampTolerance}s'
)
self.nMetadataDiscarded += 1
return False
self.nMetadataProcessed += 1
Expand Down
6 changes: 3 additions & 3 deletions src/dashpva/workflow/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -2078,7 +2078,7 @@ def run_associator_consumers(self):
self._save_meta_assoc_last()

cmd = [
sys.executable, '-m', 'pvapy.cli.hpcConsumer',
'pvapy-hpc-consumer',
'--input-channel', self.lineEditInputChannelAssociator.text(),
'--control-channel', self.lineEditControlChannelAssociator.text(),
'--status-channel', self.lineEditStatusChannelAssociator.text(),
Expand Down Expand Up @@ -2225,7 +2225,7 @@ def run_collector(self):
producer_id_list = ','.join(producer_id_list)

cmd = [
sys.executable, '-m', 'pvapy.cli.hpcConsumer',
'pvapy-hpc-collector',
'--collector-id', str(self.spinBoxCollectorId.value()),
'--producer-id-list', producer_id_list,
'--input-channel', self.lineEditInputChannelCollector.text(),
Expand Down Expand Up @@ -2286,7 +2286,7 @@ def run_analysis_consumer(self):
self._save_analysis_last()

cmd = [
sys.executable, '-m', 'pvapy.cli.hpcConsumer',
'pvapy-hpc-consumer',
'--input-channel', self.lineEditInputChannelAnalysis.text(),
'--control-channel', self.lineEditControlChannelAnalysis.text(),
'--status-channel', self.lineEditStatusChannelAnalysis.text(),
Expand Down
44 changes: 0 additions & 44 deletions tests/unit/test_pvapy_resolves.py

This file was deleted.