Skip to content

Commit

Permalink
Merge pull request #197 from prjemian/196-empty-P0
Browse files Browse the repository at this point in the history
handle empty empty #O0 or #P0 list
  • Loading branch information
prjemian committed Aug 15, 2019
2 parents d9e160c + a4158a2 commit 081f220
Show file tree
Hide file tree
Showing 4 changed files with 191 additions and 4 deletions.
23 changes: 19 additions & 4 deletions src/spec2nexus/plugins/spec_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,12 @@ def process(self, text, sdf_object, *args, **kws):
key = text.split()[0]
if key == "#O0":
sdf_object.O = [] # TODO: What if motor names are different?
sdf_object.O.append(split_column_labels(strip_first_word(text)))
content = strip_first_word(text).strip()
if content == '':
content = []
else:
content = split_column_labels(content)
sdf_object.O.append(content)


@six.add_metaclass(AutoRegister)
Expand All @@ -683,7 +688,12 @@ class SPEC_PositionerMnemonics(ControlLineHandler):
def process(self, text, header, *args, **kws):
if not hasattr(header, 'o'):
header.o = []
header.o.append( strip_first_word(text).split() )
content = strip_first_word(text).strip()
if content == '':
content = []
else:
content = content.split()
header.o.append(content)
header.addPostProcessor('positioner cross-referencing', self.postprocess)

def postprocess(self, header, *args, **kws):
Expand Down Expand Up @@ -740,7 +750,12 @@ class SPEC_Positioners(ControlLineHandler):
def process(self, text, scan, *args, **kws):
if isinstance(scan, SpecDataFileHeader):
scan = scan.getLatestScan()
scan.P.append( strip_first_word(text) )
content = strip_first_word(text)
if content == '':
content = []
else:
content = content.split()
scan.P.append(content)
scan.addPostProcessor('motor_positions', self.postprocess)

def postprocess(self, scan, *args, **kws):
Expand All @@ -754,7 +769,7 @@ def postprocess(self, scan, *args, **kws):
if row >= len(scan.header.O):
scan.add_interpreter_comment('#P%d found without #O%d' % (row, row))
continue
for col, val in enumerate(values.split()):
for col, val in enumerate(values):
if col >= len(scan.header.O[row]):
scan.add_interpreter_comment(
'extra value in #P%d position %d, no matching label in #O%d' % (row, col+1, row)
Expand Down
64 changes: 64 additions & 0 deletions tests/data/issue196_data.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#F /tmp/tmp165tf5wf/20190814-234607.dat
#E 1565844367
#D Wed Aug 14 23:46:07 2019
#C BlueSky user = mintadmin host = mint-vm
#O0
#o0

#S 108 tune_mr()
#D Thu May 02 17:45:33 2019
#C Thu May 02 17:45:33 2019. plan_type = generator
#C Thu May 02 17:45:33 2019. uid = 2ffe4d87-9f0c-464a-9d14-213ec71afaf7
#MD uid = 2ffe4d87-9f0c-464a-9d14-213ec71afaf7
#MD APSTOOLS_VERSION = 1.1.0
#MD BLUESKY_VERSION = 1.5.2
#MD EPICS_CA_MAX_ARRAY_BYTES = 1280000
#MD EPICS_HOST_ARCH = linux-x86_64
#MD OPHYD_VERSION = 1.3.3
#MD beamline_id = APS USAXS 9-ID-C
#MD datetime = 2019-05-02 17:45:33.904824
#MD detectors = ['I0_USAXS']
#MD login_id = usaxs@usaxscontrol.xray.aps.anl.gov
#MD motors = ['m_stage_r']
#MD pid = 29888
#MD proposal_id = testing Bluesky installation
#MD purpose = tuner
#MD tune_md = {'width': -0.004, 'initial_position': 8.824977, 'time_iso8601': '2019-05-02 17:45:33.923544'}
#MD tune_parameters = {'num': 31, 'width': -0.004, 'initial_position': 8.824977, 'peak_choice': 'com', 'x_axis': 'm_stage_r', 'y_axis': 'I0_USAXS'}
#P0
#N 9
#L m_stage_r Epoch_float Epoch scaler0_time scaler0_display_rate m_stage_r_user_setpoint m_stage_r_soft_limit_lo m_stage_r_soft_limit_hi I0_USAXS
8.826977 1.2477173805236816 1 0.1 5.0 8.826977000000001 -7.856115 37.143885 127.0
8.826844 1.6576123237609863 2 0.1 5.0 8.826843666666667 -7.856115 37.143885 126.0
8.826711 2.0573489665985107 2 0.1 5.0 8.826710333333335 -7.856115 37.143885 127.0
8.826577 2.473998785018921 2 0.1 5.0 8.826577 -7.856115 37.143885 126.0
8.826443999999999 2.8916513919830322 3 0.1 5.0 8.826443666666668 -7.856115 37.143885 127.0
8.826311 3.3084800243377686 3 0.1 5.0 8.826310333333334 -7.856115 37.143885 127.0
8.826177 3.7085142135620117 4 0.1 5.0 8.826177000000001 -7.856115 37.143885 127.0
8.826044 4.125398635864258 4 0.1 5.0 8.826043666666667 -7.856115 37.143885 127.0
8.825911 4.541856050491333 5 0.1 5.0 8.825910333333335 -7.856115 37.143885 127.0
8.825776999999999 4.960720539093018 5 0.1 5.0 8.825777 -7.856115 37.143885 127.0
8.825644 5.3609373569488525 5 0.1 5.0 8.825643666666668 -7.856115 37.143885 127.0
8.825510999999999 5.7742180824279785 6 0.1 5.0 8.825510333333334 -7.856115 37.143885 125.0
8.825377 6.225730657577515 6 0.1 5.0 8.825377000000001 -7.856115 37.143885 127.0
8.825244 6.642361402511597 7 0.1 5.0 8.825243666666667 -7.856115 37.143885 127.0
8.825111 7.057381868362427 7 0.1 5.0 8.825110333333335 -7.856115 37.143885 127.0
8.824977 7.45771598815918 7 0.1 5.0 8.824977 -7.856115 37.143885 126.0
8.824843999999999 7.875597953796387 8 0.1 5.0 8.824843666666666 -7.856115 37.143885 127.0
8.824711 8.304352283477783 8 0.1 5.0 8.824710333333334 -7.856115 37.143885 127.0
8.824577 8.72563123703003 9 0.1 5.0 8.824577 -7.856115 37.143885 127.0
8.824444 9.141692638397217 9 0.1 5.0 8.824443666666667 -7.856115 37.143885 127.0
8.824311 9.572316646575928 10 0.1 5.0 8.824310333333333 -7.856115 37.143885 125.0
8.824176999999999 9.975574493408203 10 0.1 5.0 8.824177 -7.856115 37.143885 128.0
8.824044 10.392260074615479 10 0.1 5.0 8.824043666666666 -7.856115 37.143885 128.0
8.823910999999999 10.808902025222778 11 0.1 5.0 8.823910333333334 -7.856115 37.143885 127.0
8.823777 11.225586652755737 11 0.1 5.0 8.823777 -7.856115 37.143885 127.0
8.823644 11.642327070236206 12 0.1 5.0 8.823643666666667 -7.856115 37.143885 127.0
8.823511 12.057403802871704 12 0.1 5.0 8.823510333333333 -7.856115 37.143885 127.0
8.823377 12.474164247512817 12 0.1 5.0 8.823377 -7.856115 37.143885 126.0
8.823243999999999 12.891609191894531 13 0.1 5.0 8.823243666666666 -7.856115 37.143885 127.0
8.823111 13.30853796005249 13 0.1 5.0 8.823110333333334 -7.856115 37.143885 127.0
8.822977 13.725494146347046 14 0.1 5.0 8.822977 -7.856115 37.143885 127.0
#C Thu May 02 17:45:48 2019. num_events_baseline = 2
#C Thu May 02 17:45:48 2019. num_events_primary = 31
#C Thu May 02 17:45:48 2019. exit_status = success
64 changes: 64 additions & 0 deletions tests/data/issue196_data2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#F /tmp/tmp165tf5wf/20190814-234607.dat
#E 1565844367
#D Wed Aug 14 23:46:07 2019
#C BlueSky user = mintadmin host = mint-vm
#O0 m_stage_r
#o0 mr

#S 108 tune_mr()
#D Thu May 02 17:45:33 2019
#C Thu May 02 17:45:33 2019. plan_type = generator
#C Thu May 02 17:45:33 2019. uid = 2ffe4d87-9f0c-464a-9d14-213ec71afaf7
#MD uid = 2ffe4d87-9f0c-464a-9d14-213ec71afaf7
#MD APSTOOLS_VERSION = 1.1.0
#MD BLUESKY_VERSION = 1.5.2
#MD EPICS_CA_MAX_ARRAY_BYTES = 1280000
#MD EPICS_HOST_ARCH = linux-x86_64
#MD OPHYD_VERSION = 1.3.3
#MD beamline_id = APS USAXS 9-ID-C
#MD datetime = 2019-05-02 17:45:33.904824
#MD detectors = ['I0_USAXS']
#MD login_id = usaxs@usaxscontrol.xray.aps.anl.gov
#MD motors = ['m_stage_r']
#MD pid = 29888
#MD proposal_id = testing Bluesky installation
#MD purpose = tuner
#MD tune_md = {'width': -0.004, 'initial_position': 8.824977, 'time_iso8601': '2019-05-02 17:45:33.923544'}
#MD tune_parameters = {'num': 31, 'width': -0.004, 'initial_position': 8.824977, 'peak_choice': 'com', 'x_axis': 'm_stage_r', 'y_axis': 'I0_USAXS'}
#P0 8.824977
#N 9
#L m_stage_r Epoch_float Epoch scaler0_time scaler0_display_rate m_stage_r_user_setpoint m_stage_r_soft_limit_lo m_stage_r_soft_limit_hi I0_USAXS
8.826977 1.2477173805236816 1 0.1 5.0 8.826977000000001 -7.856115 37.143885 127.0
8.826844 1.6576123237609863 2 0.1 5.0 8.826843666666667 -7.856115 37.143885 126.0
8.826711 2.0573489665985107 2 0.1 5.0 8.826710333333335 -7.856115 37.143885 127.0
8.826577 2.473998785018921 2 0.1 5.0 8.826577 -7.856115 37.143885 126.0
8.826443999999999 2.8916513919830322 3 0.1 5.0 8.826443666666668 -7.856115 37.143885 127.0
8.826311 3.3084800243377686 3 0.1 5.0 8.826310333333334 -7.856115 37.143885 127.0
8.826177 3.7085142135620117 4 0.1 5.0 8.826177000000001 -7.856115 37.143885 127.0
8.826044 4.125398635864258 4 0.1 5.0 8.826043666666667 -7.856115 37.143885 127.0
8.825911 4.541856050491333 5 0.1 5.0 8.825910333333335 -7.856115 37.143885 127.0
8.825776999999999 4.960720539093018 5 0.1 5.0 8.825777 -7.856115 37.143885 127.0
8.825644 5.3609373569488525 5 0.1 5.0 8.825643666666668 -7.856115 37.143885 127.0
8.825510999999999 5.7742180824279785 6 0.1 5.0 8.825510333333334 -7.856115 37.143885 125.0
8.825377 6.225730657577515 6 0.1 5.0 8.825377000000001 -7.856115 37.143885 127.0
8.825244 6.642361402511597 7 0.1 5.0 8.825243666666667 -7.856115 37.143885 127.0
8.825111 7.057381868362427 7 0.1 5.0 8.825110333333335 -7.856115 37.143885 127.0
8.824977 7.45771598815918 7 0.1 5.0 8.824977 -7.856115 37.143885 126.0
8.824843999999999 7.875597953796387 8 0.1 5.0 8.824843666666666 -7.856115 37.143885 127.0
8.824711 8.304352283477783 8 0.1 5.0 8.824710333333334 -7.856115 37.143885 127.0
8.824577 8.72563123703003 9 0.1 5.0 8.824577 -7.856115 37.143885 127.0
8.824444 9.141692638397217 9 0.1 5.0 8.824443666666667 -7.856115 37.143885 127.0
8.824311 9.572316646575928 10 0.1 5.0 8.824310333333333 -7.856115 37.143885 125.0
8.824176999999999 9.975574493408203 10 0.1 5.0 8.824177 -7.856115 37.143885 128.0
8.824044 10.392260074615479 10 0.1 5.0 8.824043666666666 -7.856115 37.143885 128.0
8.823910999999999 10.808902025222778 11 0.1 5.0 8.823910333333334 -7.856115 37.143885 127.0
8.823777 11.225586652755737 11 0.1 5.0 8.823777 -7.856115 37.143885 127.0
8.823644 11.642327070236206 12 0.1 5.0 8.823643666666667 -7.856115 37.143885 127.0
8.823511 12.057403802871704 12 0.1 5.0 8.823510333333333 -7.856115 37.143885 127.0
8.823377 12.474164247512817 12 0.1 5.0 8.823377 -7.856115 37.143885 126.0
8.823243999999999 12.891609191894531 13 0.1 5.0 8.823243666666666 -7.856115 37.143885 127.0
8.823111 13.30853796005249 13 0.1 5.0 8.823110333333334 -7.856115 37.143885 127.0
8.822977 13.725494146347046 14 0.1 5.0 8.822977 -7.856115 37.143885 127.0
#C Thu May 02 17:45:48 2019. num_events_baseline = 2
#C Thu May 02 17:45:48 2019. num_events_primary = 31
#C Thu May 02 17:45:48 2019. exit_status = success
44 changes: 44 additions & 0 deletions tests/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,50 @@ def test_geometry_plugin(self):
nxentry["instrument/monochromator/wavelength"],
nxentry["sample/beam/incident_wavelength"],
)

def test_empty_positioner(self):
"issue #196"
fname = os.path.join(_test_path, "tests", 'data', 'issue196_data.txt')
scan_number = 108
sdf = spec.SpecDataFile(fname)
scan = sdf.getScan(scan_number)

self.assertGreater(scan.header.raw.find("\n#O0 \n"), 0)
self.assertGreater(scan.header.raw.find("\n#o0 \n"), 0)
self.assertEqual(len(scan.header.O), 1)
self.assertEqual(len(scan.header.O[0]), 0)
self.assertEqual(len(scan.header.o), 1)
self.assertEqual(len(scan.header.o[0]), 0)
self.assertGreater(scan.raw.find("\n#P0 \n"), 0)
self.assertEqual(len(scan.P), 1)
self.assertEqual(len(scan.P[0]), 0)
self.assertEqual(len(scan.positioner), 0)

def test_nonempty_positioner(self):
"issue #196"
fname = os.path.join(_test_path, "tests", 'data', 'issue196_data2.txt')
scan_number = 108
sdf = spec.SpecDataFile(fname)
scan = sdf.getScan(scan_number)

self.assertEqual(scan.header.raw.find("\n#O0 \n"), -1)
self.assertEqual(scan.header.raw.find("\n#o0 \n"), -1)
self.assertGreater(scan.header.raw.find("\n#O0 m_stage_r\n"), 0)
self.assertGreater(scan.header.raw.find("\n#o0 mr\n"), 0)
self.assertEqual(len(scan.header.O), 1)
self.assertEqual(len(scan.header.O[0]), 1)
self.assertEqual(scan.header.O[0][0], "m_stage_r")
self.assertEqual(len(scan.header.o), 1)
self.assertEqual(len(scan.header.o[0]), 1)
self.assertEqual(scan.header.o[0][0], "mr")
self.assertEqual(scan.raw.find("\n#P0 \n"), -1)
self.assertGreater(scan.raw.find("\n#P0 8.824977\n"), 0)
self.assertEqual(len(scan.P), 1)
self.assertEqual(len(scan.P[0]), 1)
self.assertEqual(scan.P[0][0], "8.824977")
self.assertEqual(len(scan.positioner), 1)
self.assertTrue("m_stage_r" in scan.positioner)
self.assertEqual(scan.positioner["m_stage_r"], float("8.824977"))


def suite(*args, **kw):
Expand Down

0 comments on commit 081f220

Please sign in to comment.