Skip to content

Commit

Permalink
Merge pull request #31 from prjemian/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
prjemian committed Jan 25, 2015
2 parents 17854ea + 23bed05 commit 6412de4
Show file tree
Hide file tree
Showing 6 changed files with 158 additions and 25 deletions.
4 changes: 2 additions & 2 deletions src/spec2nexus/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
# The full license is in the file LICENSE.txt, distributed with this software.
#-----------------------------------------------------------------------------

__version__ = '2015.0113.0'
__version__ = '2015.0125.0'
__release__ = __version__
__author__ = 'Pete R. Jemian'
__email__ = 'prjemian@gmail.com'
__copyright__ = '2014, Pete R. Jemian'
__copyright__ = '2015, Pete R. Jemian'

__package_name__ = 'spec2nexus'
__license_url__ = 'http://creativecommons.org/licenses/by/4.0/deed.en_US'
Expand Down
3 changes: 3 additions & 0 deletions src/spec2nexus/data/README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,7 @@ lmn40.spe SPEC scans 1-D & 2-D scans (hklmesh), t
writer_1_3.h5 NeXus HDF5 1-D NeXus User Manual example
YSZ011_ALDITO_Fe2O3_planar_fired_1.spc SPEC scans 1-D scans, text in #V metadata, also has #UIM control lines
03_06_JanTest.dat SPEC scans 1-D scans, USAXS scans, Fly scans, #O+#o and #J+#j control lines
user6idd.dat SPEC scans 1-D scans, aborted scan, control lines: #R #UB #UE #UX #UX1 #UX2 #X,
single-space separators in #L lines,
non-default format in #X and #L lines
====================================== ========== ==========================================================================
119 changes: 119 additions & 0 deletions src/spec2nexus/data/user6idd.dat
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
#F ~/data/user6idd.dat
#E 1383072022
#D Tue Oct 29 13:40:22 2013
#C psic6IDD User = user6idd
#O0 Delta Eta Chi Phi Nu Mu tt_y tt_z
#O1 m1_om m1_chi m1_phi m2_om m2_chi m2_phi m1_filter mot43
#O2 m1_bend m2_bend m1_x m1_y m2_z xs zs ys
#O3 tta oma chia phia xm ym xd yd
#O4 sl1_t sl1_b sl1_o sl1_i sl2_t sl2_b sl2_o sl2_i
#O5 sl4_t sl4_b sl4_o sl4_i sl5_t sl5_b sl5_o sl5_i
#O6 sl3_t sl3_b sl3_o sl3_i sl3_r dummy aux_y aux_x_base
#O7 aux_th aux_x x_detector

#S 1 rotscan testing dummy 0 0 100 0.1 5
#D Tue Oct 29 14:05:53 2013
#T 0.1 (Seconds)
#G0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0
#G1 1.54 1.54 1.54 90 90 90 4.079990459 4.079990459 4.079990459 90 90 90 1 0 0 0 1 0 60 30 0 0 0 0 60 30 0 -90 0 0 1.54 1.54
#G3 4.079990459 -6.865325574e-16 -6.561207576e-16 -3.041179982e-17 -4.079990459 2.49819112e-16 0 0 -4.079990459
#G4 0 0 0 0.1235653136 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -180 -180 -180 -180 -180 -180 -180 -180 -180 0 0 0 0 0 0 0 0 0 0 0 0
#Q 0 0 0
#P0 0 0 90 -3 0 0 700 700
#P1 2.162381 -0.12024 -0.909126 2.162131 -0.80976 -0.799578 86.365625 0
#P2 -5.99 -5.99 1 4.6500032 2.8633327e-05 0 0 0
#P3 0 0 0 0 0 -3.5 0 0
#P4 0.25 -0.25 0.25 -0.25 0.35 -0.35 0.35 -0.35
#P5 2 -2 2 -2 2.84 -1.16 0.845 -3.155
#P6 0 -5 0 0 0 0 0 -21.95
#P7 0 21.74875 0
#UE 100.339 0.123565 179.998 42.1688 (Energy in keV, Lambda in Angstroem, Undulator Gap + Energy)
#X 0 -273.15 (Temperature Setpoint in K and C)
#UX 0 0 1 100.339 (All Banks: Filter, Thickness in mm, Transmission, calculated for energy)
#UX1 0 0 1 0 (Bank 1:Filter, Thickness in mm, Transmission, calculated for energy)
#UX2 0 0 1 0 (Bank 2:Filter, Thickness in mm, Transmission, calculated for energy)
#UB 4.07999 -6.86533e-16 -6.56121e-16 -3.04118e-17 -4.07999 2.49819e-16 0 0 -4.07999
#N 25
#L dummy Time DelTime Index Dropped H K L DegK_reg DegK_sample Epoch Seconds RingCurrent moa mob coa cob MCA_Detector MCA_Total AD_ROI1_Total AD_ROI1_Max scu0_cur MCA_Compton Monitor Detector
#C Tue Oct 29 14:05:53 2013. Scan aborted after 0 points.

#S 2 rotscan testing dummy 0 0 100 0.1 5
#D Tue Oct 29 14:06:25 2013
#T 0.1 (Seconds)
#G0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0
#G1 1.54 1.54 1.54 90 90 90 4.079990459 4.079990459 4.079990459 90 90 90 1 0 0 0 1 0 60 30 0 0 0 0 60 30 0 -90 0 0 1.54 1.54
#G3 4.079990459 -6.865325574e-16 -6.561207576e-16 -3.041179982e-17 -4.079990459 2.49819112e-16 0 0 -4.079990459
#G4 0 0 0 0.1235653136 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -180 -180 -180 -180 -180 -180 -180 -180 -180 0 0 0 0 0 0 0 0 0 0 0 0
#Q 0 0 0
#P0 0 0 90 -3 0 0 700 700
#P1 2.162381 -0.12024 -0.909126 2.162131 -0.80976 -0.799578 86.365625 0
#P2 -5.99 -5.99 1 4.6500032 2.8633327e-05 0 0 0
#P3 0 0 0 0 0 -3.5 0 0
#P4 0.25 -0.25 0.25 -0.25 0.35 -0.35 0.35 -0.35
#P5 2 -2 2 -2 2.84 -1.16 0.845 -3.155
#P6 0 -5 0 0 0 0 0 -21.95
#P7 0 21.74875 0
#UE 100.339 0.123565 179.998 42.1688 (Energy in keV, Lambda in Angstroem, Undulator Gap + Energy)
#X 0 -273.15 (Temperature Setpoint in K and C)
#UX 0 0 1 100.339 (All Banks: Filter, Thickness in mm, Transmission, calculated for energy)
#UX1 0 0 1 0 (Bank 1:Filter, Thickness in mm, Transmission, calculated for energy)
#UX2 0 0 1 0 (Bank 2:Filter, Thickness in mm, Transmission, calculated for energy)
#UB 4.07999 -6.86533e-16 -6.56121e-16 -3.04118e-17 -4.07999 2.49819e-16 0 0 -4.07999
#N 25
#L dummy Time DelTime Index Dropped H K L DegK_reg DegK_sample Epoch Seconds RingCurrent moa mob coa cob MCA_Detector MCA_Total AD_ROI1_Total AD_ROI1_Max scu0_cur MCA_Compton Monitor Detector
0 1383073585.374759 -0.000759 2 0 0 0 0 0 0 1563 0.1 0.0102 1 1 1 1 141 11699 0 0 0 3848 1 0
0 1383073585.578769 -0.000769 4 0 0 0 0 0 0 1563 0.1 0.0102 1 1 1 1 141 11699 0 0 0 3848 1 0
0 1383073585.703298 -0.000298 5 0 0 0 0 0 0 1563 0.1 0.0102 1 1 1 1 141 11699 0 0 0 3848 1 0
0 1383073585.889650 -0.000650 7 0 0 0 0 0 0 1563 0.1 0.0102 1 1 1 1 141 11699 0 0 0.12207404 3848 1 0
0 1383073586.028877 0.000123 8 0 0 0 0 0 0 1564 0.1 0.0102 1 1 1 1 141 11699 0 0 0.12207404 3848 1 0
0 1383073586.242838 -0.000838 10 0 0 0 0 0 0 1564 0.1 0.0102 1 1 1 1 141 11699 0 0 0.12207404 3848 1 0
0 1383073586.401895 0.000105 12 0 0 0 0 0 0 1564 0.1 0.0102 1 1 1 1 141 11699 0 0 -0.12207404 3848 1 0
0 1383073586.617823 0.000177 14 0 0 0 0 0 0 1564 0.1 0.0102 1 1 1 1 141 11699 0 0 -0.12207404 3848 1 0
0 1383073586.773157 -0.000157 15 0 0 0 0 0 0 1564 0.1 0.0102 1 1 1 1 141 11699 0 0 -0.12207404 3848 1 0
0 1383073586.987346 -0.000346 18 0 0 0 0 0 0 1565 0.1 0.0102 1 1 1 1 141 11699 0 0 -0.12207404 3848 1 0
0 1383073587.111611 -0.000611 19 0 0 0 0 0 0 1565 0.1 0.0102 1 1 1 1 141 11699 0 0 -0.12207404 3848 1 0
0 1383073587.235586 -0.000586 20 0 0 0 0 0 0 1565 0.1 0.0102 1 1 1 1 141 11699 0 0 -0.12207404 3848 1 0
0 1383073587.396767 0.000233 22 0 0 0 0 0 0 1565 0.1 0.0102 1 1 1 1 141 11699 0 0 0.15259255 3848 1 0
0 1383073587.558454 -0.000454 23 0 0 0 0 0 0 1565 0.1 0.0102 1 1 1 1 141 11699 0 0 0.15259255 3848 1 0
0 1383073587.773534 -0.000534 26 0 0 0 0 0 0 1565 0.1 0.0102 1 1 1 1 141 11699 0 0 0.15259255 3848 1 0
0 1383073587.949097 -0.000097 27 0 0 0 0 0 0 1566 0.1 0.0102 1 1 1 1 141 11699 0 0 0.15259255 3848 1 0
0 1383073588.158376 -0.000376 29 0 0 0 0 0 0 1566 0.1 0.0102 1 1 1 1 141 11699 0 0 0.15259255 3848 1 0
0 1383073588.327235 -0.000235 31 0 0 0 0 0 0 1566 0.1 0.0102 1 1 1 1 141 11699 0 0 -0.091555528 3848 1 0
0 1383073588.532477 -0.000477 33 0 0 0 0 0 0 1566 0.1 0.0102 1 1 1 1 141 11699 0 0 -0.091555528 3848 1 0
0 1383073588.679982 0.000018 35 0 0 0 0 0 0 1566 0.1 0.0102 1 1 1 1 141 11699 0 0 -0.091555528 3848 1 0
0 1383073588.888847 0.000153 37 0 0 0 0 0 0 1566 0.1 0.0102 1 1 1 1 141 11699 0 0 0.030518509 3848 1 0
0 1383073589.070463 -0.000463 38 0 0 0 0 0 0 1567 0.1 0.0102 1 1 1 1 141 11699 0 0 0.030518509 3848 1 0
0 1383073589.282489 -0.000489 41 0 0 0 0 0 0 1567 0.1 0.0102 1 1 1 1 141 11699 0 0 0.030518509 3848 1 0
0 1383073589.439304 -0.000304 42 0 0 0 0 0 0 1567 0.1 0.0102 1 1 1 1 141 11699 0 0 -0.18311106 3848 1 0
0 1383073589.657698 -0.000698 44 0 0 0 0 0 0 1567 0.1 0.0102 1 1 1 1 141 11699 0 0 -0.18311106 3848 1 0
0 1383073589.822744 -0.000744 46 0 0 0 0 0 0 1567 0.1 0.0102 1 1 1 1 141 11699 0 0 -0.061037019 3848 1 0
0 1383073590.036854 0.000146 48 0 0 0 0 0 0 1568 0.1 0.0102 1 1 1 1 141 11699 0 0 -0.061037019 3848 1 0
0 1383073590.195998 0.000002 50 2 0 0 0 0 0 1568 0.1 0.0102 1 1 1 1 141 11699 0 0 -0.061037019 3848 1 0
0 1383073590.403124 -0.000124 52 4 0 0 0 0 0 1568 0.1 0.0102 1 1 1 1 141 11699 0 0 -0.45777764 3848 1 0
0 1383073590.561602 -0.000602 53 4 0 0 0 0 0 1568 0.1 0.0102 1 1 1 1 141 11699 0 0 -0.45777764 3848 1 0
0 1383073590.774385 -0.000385 55 7 0 0 0 0 0 1568 0.1 0.0102 1 1 1 1 141 11699 0 0 -0.45777764 3848 1 0
0 1383073590.937098 -0.000098 57 8 0 0 0 0 0 1568 0.1 0.0102 1 1 1 1 141 11699 0 0 0.030518509 3848 1 0
0 1383073591.382668 -0.000668 62 12 0 0 0 0 0 1569 0.1 0.0102 1 1 1 1 141 11699 0 0 -0.21362957 3848 1 0
0 1383073591.546547 -0.000547 63 13 0 0 0 0 0 1569 0.1 0.0102 1 1 1 1 141 11699 0 0 -0.21362957 3848 1 0
0 1383073591.761622 -0.000622 65 15 0 0 0 0 0 1569 0.1 0.0102 1 1 1 1 141 11699 0 0 -0.21362957 3848 1 0
0 1383073591.923105 -0.000105 67 16 0 0 0 0 0 1570 0.1 0.0102 1 1 1 1 141 11699 0 0 -0.061037019 3848 1 0
0 1383073592.134837 0.000163 69 18 0 0 0 0 0 1570 0.1 0.0102 1 1 1 1 141 11699 0 0 -0.061037019 3848 1 0
0 1383073592.306965 0.000035 71 21 0 0 0 0 0 1570 0.1 0.0102 1 1 1 1 141 11699 0 0 -0.061037019 3848 1 0
0 1383073592.504328 -0.000328 73 23 0 0 0 0 0 1570 0.1 0.0102 1 1 1 1 141 11699 0 0 0.061037019 3848 1 0
0 1383073592.666886 0.000114 74 23 0 0 0 0 0 1570 0.1 0.0102 1 1 1 1 141 11699 0 0 0.061037019 3848 1 0
0 1383073592.875718 0.000282 76 25 0 0 0 0 0 1570 0.1 0.0102 1 1 1 1 141 11699 0 0 -0.15259255 3848 1 0
0 1383073593.034075 -0.000075 78 26 0 0 0 0 0 1571 0.1 0.0102 1 1 1 1 141 11699 0 0 -0.15259255 3848 1 0
0 1383073593.245451 -0.000451 80 29 0 0 0 0 0 1571 0.1 0.0102 1 1 1 1 141 11699 0 0 -0.15259255 3848 1 0
0 1383073593.418504 -0.000504 82 32 0 0 0 0 0 1571 0.1 0.0102 1 1 1 1 141 11699 0 0 -0.30518509 3848 1 0
0 1383073593.634928 0.000072 84 34 0 0 0 0 0 1571 0.1 0.0102 1 1 1 1 141 11699 0 0 -0.30518509 3848 1 0
0 1383073593.795867 0.000133 86 36 0 0 0 0 0 1571 0.1 0.0102 1 1 1 1 141 11699 0 0 -0.30518509 3848 1 0
0 1383073594.005156 -0.000156 88 38 0 0 0 0 0 1572 0.1 0.0102 1 1 1 1 141 11699 0 0 0.061037019 3848 1 0
0 1383073594.160503 -0.000503 89 38 0 0 0 0 0 1572 0.1 0.0102 1 1 1 1 141 11699 0 0 0.061037019 3848 1 0
0 1383073594.375008 -0.000008 91 41 0 0 0 0 0 1572 0.1 0.0102 1 1 1 1 141 11699 0 0 -0.091555528 3848 1 0
0 1383073594.528036 -0.000036 93 42 0 0 0 0 0 1572 0.1 0.0102 1 1 1 1 141 11699 0 0 -0.091555528 3848 1 0
0 1383073594.737089 -0.000089 95 45 0 0 0 0 0 1572 0.1 0.0102 1 1 1 1 141 11699 0 0 -0.091555528 3848 1 0
0 1383073594.908258 -0.000258 97 48 0 0 0 0 0 1573 0.1 0.0102 1 1 1 1 141 11699 0 0 0.18311106 3848 1 0
0 1383073595.126488 -0.000488 99 50 0 0 0 0 0 1573 0.1 0.0102 1 1 1 1 141 11699 0 0 0.18311106 3848 1 0
0 1383073595.267593 -0.000593 100 51 0 0 0 0 0 1573 0.1 0.0102 1 1 1 1 141 11699 0 0 0.18311106 3848 1 0
0 1383073595.478344 -0.000344 102 52 0 0 0 0 0 1573 0.1 0.0102 1 1 1 1 141 11699 0 0 0 3848 1 0
#R 2
19 changes: 11 additions & 8 deletions src/spec2nexus/dev_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,22 @@ def developer_test(spec_file_name = None):
spec_dir = os.path.abspath(path)
#spec_file_name = os.path.join(spec_dir, 'APS_spec_data.dat')
#spec_file_name = os.path.join(spec_dir, '03_05_UImg.dat')
spec_file_name = os.path.join(spec_dir, '33id_spec.dat')
#spec_file_name = os.path.join(spec_dir, '33id_spec.dat')
#spec_file_name = os.path.join(spec_dir, '33bm_spec.dat')
#spec_file_name = os.path.join(spec_dir, 'CdSe')
#spec_file_name = os.path.join(spec_dir, 'lmn40.spe')
#spec_file_name = os.path.join(spec_dir, 'YSZ011_ALDITO_Fe2O3_planar_fired_1.spc')
#spec_file_name = os.path.join(spec_dir, '130123B_2.spc')
spec_file_name = os.path.join(spec_dir, 'user6idd.dat')
os.chdir(spec_dir)
print '-'*70
# now open the file and read it
test = spec.SpecDataFile(spec_file_name)
scan = test.scans[1]
scan = test.scans[2]
scan.interpret()
print scan.UXML_root

print prettify(scan.UXML_root)
#print scan.UXML_root
#print prettify(scan.UXML_root)

if False:
# tell us about the test file
print 'file', test.fileName
Expand All @@ -73,14 +74,16 @@ def developer_test(spec_file_name = None):
for i in range(len(last_scan.data[pLabel])):
print last_scan.data[pLabel][i], last_scan.data[dLabel][i]
print 'labels in scan 1:', test.getScan(1).L
if test.getScan(5) is not None:
if test.getScan(1) is not None:
print 'command line of scan 5:', test.getScan(5).scanCmd
print '\n'.join(test.getScanCommands([5, 10, 15, 29, 40, 75]))
print '\n'.join(test.getScanCommands([1, 2]))
pass


if __name__ == "__main__":
fname = 'test_3.spec'
spec_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), 'data', 'uxml', ))
os.environ['SPEC2NEXUS_PLUGIN_PATH'] = spec_dir
developer_test(os.path.join(spec_dir, fname))
full_name = os.path.join(spec_dir, fname)
full_name = None
developer_test(full_name)
34 changes: 22 additions & 12 deletions src/spec2nexus/plugins/spec_common_spec2nexus.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,8 @@ def process(self, part, spec_obj, *args, **kws):
scan = SpecDataFileScan(spec_obj.headers[-1], part, parent=spec_obj)
text = part.splitlines()[0].strip()
scan.S = strip_first_word(text)
pos = scan.S.find(' ')
scan.scanNum = int(scan.S[0:pos])
scan.scanCmd = strip_first_word(scan.S[pos+1:])
scan.scanNum = int(scan.S.split()[0])
scan.scanCmd = strip_first_word(scan.S)
if scan.scanNum in spec_obj.scans:
msg = str(scan.scanNum) + ' in ' + spec_obj.fileName
raise DuplicateSpecScanNumber(msg)
Expand Down Expand Up @@ -359,6 +358,15 @@ class SPEC_Labels(ControlLineHandler):
def process(self, text, scan, *args, **kws):
# Some folks use more than two spaces! Use regular expression(re) module
scan.L = re.split(" +", strip_first_word(text))

if len(scan.L) == 1 and hasattr(scan, 'N') and scan.N[0] > 1:
# BUT: some folks only use a single-space as a separator!
# perhaps #L was written with single-space separators.?
# Unusual for scan to have only 1 column, but possible
labels = strip_first_word(text).split()
if len(labels) == scan.N[0]:
scan.L = labels

scan.column_first = scan.L[0]
scan.column_last = scan.L[-1]

Expand Down Expand Up @@ -599,7 +607,7 @@ def writer(self, h5parent, writer, scan, *args, **kws):

class SPEC_TemperatureSetPoint(ControlLineHandler):
'''
**#X** -- Temperature
**#X** -- Temperature Set Point (desired temperature)
The default declaration of the #X control line is written::
Expand All @@ -626,16 +634,18 @@ def Fheader '_cols++;printf("#X %gKohm (%gC)\\n",TEMP_SP,DEGC_SP)'
'''

key = '#X'
# TODO: Needs an example data file to test

def process(self, text, scan, *args, **kws):
fmt = "#X %fKohm (%fC)"
try:
# This looks fragile!
scan.TEMP_SP, scan.DEGC_SP = scanf(fmt, text)
scan.addH5writer(self.key, self.writer)
except:
pass
# Try a list of formats until one succeeds
format_list = ["#X %fKohm (%fC)",
# "#X %g %g", # note: %g specifier is not available
"#X %f %f",
]
for fmt in format_list:
result = scanf(fmt, text)
if result is not None:
scan.TEMP_SP, scan.DEGC_SP = result
scan.addH5writer(self.key, self.writer)

def writer(self, h5parent, writer, scan, nxclass=None, *args, **kws):
'''Describe how to store this data in an HDF5 NeXus file'''
Expand Down
4 changes: 1 addition & 3 deletions src/spec2nexus/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,9 +442,7 @@ def interpret(self):
__s__ = '<' + line + '>'
msg = "scan %d, line %d: unknown key, ignored text: %s" % (self.scanNum, i, line)
#raise UnknownSpecFilePart(msg)
elif key == '#S':
pass # avoid recursion
else:
elif key != '#S': # avoid recursion
# most of the work is done here
self.parent.plugin_manager.process(key, line, self)

Expand Down

0 comments on commit 6412de4

Please sign in to comment.