Skip to content

Commit

Permalink
Clean up detection functions
Browse files Browse the repository at this point in the history
  • Loading branch information
jadball committed Nov 24, 2023
1 parent c9bb9bb commit 39abc06
Showing 1 changed file with 15 additions and 19 deletions.
34 changes: 15 additions & 19 deletions ImageD11/sinograms/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,47 +102,43 @@ def guess_detector(self):

# open the masterfile
hname = self.masterfile
detectors_seen = []
scan = "1.1"

with h5py.File( hname, 'r' ) as hin:
detectors_seen = []
# go through the first scan, and see what detectors we can see
scan = "1.1"
# scans = [scan for scan in list(hin['/']) if (scan.endswith('.1') and ('measurement' in hin[scan]))]
# for scan in scans:
for measurement in list(hin[scan]['measurement']):
if measurement in POSSIBLE_DETECTOR_NAMES:
detectors_seen.append(measurement)

unique_detectors_seen = list(set(detectors_seen))
if len(unique_detectors_seen) != 1:

if len(detectors_seen) != 1:
raise ValueError("More than one detector seen! Can't work out which one to process.")
else:
self.detector = unique_detectors_seen[0]
self.detector = detectors_seen[0]


def guess_motornames(self):
'''Guess which station we were using (Nanoscope or 3DXRD) from which motors are in instrument/positioners'''
from ImageD11.sinograms.assemble_label import HEADERMOTORS_NSCOPE, HEADERMOTORS_TDXRD, HEADERMOTORS
# open the masterfile
hname = self.masterfile
motors_seen = []
scan = "1.1"

with h5py.File( hname, 'r' ) as hin:
motors_seen = []
# go through all the scans, and see what motors we can see
# scans = [scan for scan in list(hin['/']) if (scan.endswith('.1') and ('measurement' in hin[scan]))]
scan = "1.1"
# for scan in scans:
# go through the first scan, and see what motors we can see
for positioner in list(hin[scan]['instrument/positioners']):
if positioner in HEADERMOTORS:
motors_seen.append(positioner)

unique_motors_seen = list(set(motors_seen))

using_nscope = False
using_tdxrd = False
for unique_motor in unique_motors_seen:
if unique_motor in HEADERMOTORS_NSCOPE:
for motor in motors_seen:
if motor in HEADERMOTORS_NSCOPE:
using_nscope = True
elif unique_motor in HEADERMOTORS_TDXRD:
elif motor in HEADERMOTORS_TDXRD:
using_tdxrd = True

if using_nscope and using_tdxrd:
raise ValueError("Found both nscope and tdxrd motors in positioners, not sure which one we were using!")

Expand Down

0 comments on commit 39abc06

Please sign in to comment.