diff --git a/ImageD11/sinograms/dataset.py b/ImageD11/sinograms/dataset.py index 1ec1497e..67f55644 100644 --- a/ImageD11/sinograms/dataset.py +++ b/ImageD11/sinograms/dataset.py @@ -102,21 +102,19 @@ 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): @@ -124,25 +122,23 @@ def guess_motornames(self): 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!")