Skip to content

Commit

Permalink
Merge pull request #28 from prjemian/development
Browse files Browse the repository at this point in the history
fixes #27
  • Loading branch information
prjemian committed Jan 13, 2015
2 parents 2d025e7 + ad8e6a3 commit 0d9d705
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 89 deletions.
7 changes: 1 addition & 6 deletions docs/source/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,7 @@ Installation

Released versions of spec2nexus are available on `PyPI
<https://pypi.python.org/pypi/spec2nexus>`_. If you have the `Python Setup Tools
<https://pypi.python.org/pypi/setuptools>`_ installed, then you can install
using either::

$ pip install spec2nexus

or::
<https://pypi.python.org/pypi/setuptools>`_ installed, then you can install::

$ easy_install spec2nexus

Expand Down
4 changes: 2 additions & 2 deletions src/spec2nexus/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# The full license is in the file LICENSE.txt, distributed with this software.
#-----------------------------------------------------------------------------

__version__ = '2014.1228.1'
__version__ = '2015.0113.0'
__release__ = __version__
__author__ = 'Pete R. Jemian'
__email__ = 'prjemian@gmail.com'
Expand All @@ -28,7 +28,7 @@
__download_url__ = u'https://github.com/prjemian/spec2nexus/tarball/' + __version__
__keywords__ = ['SPEC', 'diffraction', 'data acquisition', 'NeXus', 'HDF5']

__install_requires__ = ('h5py','numpy', 'lxml' )
__install_requires__ = ('h5py','numpy', )
__classifiers__ = [
'Development Status :: 5 - Production/Stable',
'Environment :: Console',
Expand Down
86 changes: 86 additions & 0 deletions src/spec2nexus/dev_spec.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

'''development of the :mod:`spec` module'''


import os
from lxml import etree
import spec

def prettify(someXML):
#for more on lxml/XSLT see: http://lxml.de/xpathxslt.html#xslt-result-objects
xslt_tree = etree.XML('''\
<!-- XSLT taken from Comment 4 by Michael Kay found here:
http://www.dpawson.co.uk/xsl/sect2/pretty.html#d8621e19 -->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes" encoding="UTF-8"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<xsl:copy-of select="."/>
</xsl:template>
</xsl:stylesheet>''')
transform = etree.XSLT(xslt_tree)
result = transform(someXML)
return unicode(result)

def developer_test(spec_file_name = None):
"""
test the routines that read from the spec data file
:param str spec_file_name: if set, spec file name is given on command line
"""
if spec_file_name is None:
path = os.path.join(os.path.dirname(__file__), 'data')
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, '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')
os.chdir(spec_dir)
print '-'*70
# now open the file and read it
test = spec.SpecDataFile(spec_file_name)
scan = test.scans[1]
scan.interpret()
print scan.UXML_root

print prettify(scan.UXML_root)
if False:
# tell us about the test file
print 'file', test.fileName
print 'headers', len(test.headers)
print 'scans', len(test.scans)
#print 'positioners in first scan:'; print test.scans[0].positioner
for scan in test.scans.values():
# print scan.scanNum, scan.date, scan.column_first, scan.positioner[scan.column_first], 'eV', 1e3*scan.metadata['DCM_energy']
print scan.scanNum, scan.scanCmd
print 'first scan: ', test.getMinScanNumber()
print 'last scan: ', test.getMaxScanNumber()
print 'positioners in last scan:'
last_scan = test.getScan(-1)
print last_scan.positioner
pLabel = last_scan.column_first
dLabel = last_scan.column_last
if len(pLabel) > 0:
print last_scan.data[pLabel]
print len(last_scan.data[pLabel])
print pLabel, dLabel
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:
print 'command line of scan 5:', test.getScan(5).scanCmd
print '\n'.join(test.getScanCommands([5, 10, 15, 29, 40, 75]))
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))
81 changes: 0 additions & 81 deletions src/spec2nexus/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@
import os #@UnusedImport
import sys #@UnusedImport
from spec2nexus.utils import get_all_plugins
from lxml import etree


plugin_manager = None # will initialize when SpecDataFile is first called
Expand Down Expand Up @@ -496,83 +495,3 @@ def _unique_key(self, label, keylist):
if i == 1000:
raise RuntimeError, "cannot make unique key for duplicated column label!"
return key


#-------------------------------------------------------------------------------------------

def prettify(someXML):
#for more on lxml/XSLT see: http://lxml.de/xpathxslt.html#xslt-result-objects
xslt_tree = etree.XML('''\
<!-- XSLT taken from Comment 4 by Michael Kay found here:
http://www.dpawson.co.uk/xsl/sect2/pretty.html#d8621e19 -->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes" encoding="UTF-8"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<xsl:copy-of select="."/>
</xsl:template>
</xsl:stylesheet>''')
transform = etree.XSLT(xslt_tree)
result = transform(someXML)
return unicode(result)

def developer_test(spec_file_name = None):
"""
test the routines that read from the spec data file
:param str spec_file_name: if set, spec file name is given on command line
"""
if spec_file_name is None:
path = os.path.join(os.path.dirname(__file__), 'data')
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, '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')
os.chdir(spec_dir)
print '-'*70
# now open the file and read it
test = SpecDataFile(spec_file_name)
scan = test.scans[1]
scan.interpret()
print scan.UXML_root

print prettify(scan.UXML_root)
if False:
# tell us about the test file
print 'file', test.fileName
print 'headers', len(test.headers)
print 'scans', len(test.scans)
#print 'positioners in first scan:'; print test.scans[0].positioner
for scan in test.scans.values():
# print scan.scanNum, scan.date, scan.column_first, scan.positioner[scan.column_first], 'eV', 1e3*scan.metadata['DCM_energy']
print scan.scanNum, scan.scanCmd
print 'first scan: ', test.getMinScanNumber()
print 'last scan: ', test.getMaxScanNumber()
print 'positioners in last scan:'
last_scan = test.getScan(-1)
print last_scan.positioner
pLabel = last_scan.column_first
dLabel = last_scan.column_last
if len(pLabel) > 0:
print last_scan.data[pLabel]
print len(last_scan.data[pLabel])
print pLabel, dLabel
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:
print 'command line of scan 5:', test.getScan(5).scanCmd
print '\n'.join(test.getScanCommands([5, 10, 15, 29, 40, 75]))
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))

0 comments on commit 0d9d705

Please sign in to comment.