Skip to content

Commit

Permalink
landscape.io
Browse files Browse the repository at this point in the history
  • Loading branch information
prjemian committed Sep 8, 2017
1 parent 5b3f849 commit 4daebb5
Show file tree
Hide file tree
Showing 27 changed files with 460 additions and 418 deletions.
2 changes: 1 addition & 1 deletion demo/usaxs_flyscan.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def plottable(self):


def debugging_setup():
import os, sys
import sys
import shutil
sys.path.insert(0, os.path.join('..', 'src'))
path = '__usaxs__'
Expand Down
2 changes: 1 addition & 1 deletion src/spec2nexus/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: iso-8859-1 -*-

'''command-line tool to convert SPEC data files to NeXus HDF5'''
"""command-line tool to convert SPEC data files to NeXus HDF5"""

#-----------------------------------------------------------------------------
# :author: Pete R. Jemian
Expand Down
12 changes: 6 additions & 6 deletions src/spec2nexus/charts.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#!/usr/bin/env python

'''
"""
charting for spec2nexus
.. autosummary::
~make_png
~xy_plot
'''
"""

import datetime
import numpy
Expand Down Expand Up @@ -38,7 +38,7 @@ def make_png(
cmap=COLORMAP,
xtitle=None, ytitle=None,
timestamp_str=None):
'''
"""
read the image from the named HDF5 file and make a PNG file
Test that the HDF5 file exists and that the path to the data exists in that file.
Expand All @@ -54,7 +54,7 @@ def make_png(
:return str: *image_file*
The HDF5 file could be a NeXus file, or some other layout.
'''
"""

# replace masked data with min good value
image_data = numpy.ma.masked_less_equal(image, 0)
Expand Down Expand Up @@ -116,7 +116,7 @@ def xy_plot(
hsize=PLOT_H_INT,
vsize=PLOT_V_INT,
timestamp_str=None):
r'''
r"""
with MatPlotLib, generate a plot of a scan (as if data from a scan in a SPEC file)
:param [float] x: horizontal axis data
Expand All @@ -141,7 +141,7 @@ def xy_plot(
Here's the fix used in this module:
http://stackoverflow.com/questions/16334588/create-a-figure-that-is-reference-counted/16337909#16337909
'''
"""
fig = matplotlib.figure.Figure(figsize=(hsize, vsize))
fig.clf()

Expand Down
2 changes: 1 addition & 1 deletion src/spec2nexus/dev_datafile.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

'''Process specific data file(s)'''
"""Process specific data file(s)"""

# TODO: fold into the unit test suite

Expand Down
2 changes: 1 addition & 1 deletion src/spec2nexus/dev_extractSpecScan.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

'''developer test for extractSpecScan'''
"""developer test for extractSpecScan"""

# TODO: fold into the unit test suite

Expand Down
2 changes: 1 addition & 1 deletion src/spec2nexus/dev_h5toText.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

'''developer test for h5toText'''
"""developer test for h5toText"""

# TODO: fold into the unit test suite

Expand Down
2 changes: 1 addition & 1 deletion src/spec2nexus/dev_nexus.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

'''developer test for nexus'''
"""developer test for nexus"""

# TODO: fold into the unit test suite

Expand Down
6 changes: 3 additions & 3 deletions src/spec2nexus/dev_spec.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

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

# TODO: fold into the unit test suite

Expand All @@ -12,7 +12,7 @@

def prettify(someXML):
#for more on lxml/XSLT see: http://lxml.de/xpathxslt.html#xslt-result-objects
xslt_tree = etree.XML('''\
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">
Expand All @@ -21,7 +21,7 @@ def prettify(someXML):
<xsl:template match="/">
<xsl:copy-of select="."/>
</xsl:template>
</xsl:stylesheet>''')
</xsl:stylesheet>""")
transform = etree.XSLT(xslt_tree)
result = transform(someXML)
return str(result)
Expand Down
14 changes: 7 additions & 7 deletions src/spec2nexus/extractSpecScan.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#-----------------------------------------------------------------------------


'''
"""
Save columns from SPEC data file scan(s) to TSV files
.. note:: TSV: tab-separated values
Expand All @@ -24,7 +24,7 @@
.. note:: sdpecified column names **MUST** appear in all chosen scans
Compatible with Python 2.7+
'''
"""

from __future__ import print_function

Expand All @@ -47,7 +47,7 @@


def makeOutputFileName(specFile, scanNum):
'''
"""
return an output file name based on specFile and scanNum
:param str specFile: name of existing SPEC data file to be read
Expand All @@ -68,7 +68,7 @@ def makeOutputFileName(specFile, scanNum):
CeCoIn5.dat scan 77 CeCoIn5_77.dat
CeCoIn5.dat scan 5.1 CeCoIn5_5_1.dat
=========== ======== ===============
'''
"""
name_parts = os.path.splitext(specFile)
scan_number = str(scanNum).replace('.', '_')
outFile = name_parts[0] + '_' + scan_number + name_parts[1]
Expand All @@ -93,7 +93,7 @@ def expand_scan_range_terms(scans):


def get_user_parameters():
'''configure user's command line parameters from sys.argv'''
"""configure user's command line parameters from sys.argv"""
import argparse
from spec2nexus._version import get_versions
version = get_versions()['version']
Expand Down Expand Up @@ -190,7 +190,7 @@ def get_user_parameters():


def main():
'''
"""
read the data file, find each scan, find the columns, save the data
:param [str] cmdArgs: Namespace from argparse, returned from get_user_parameters()
Expand All @@ -210,7 +210,7 @@ def main():
1.9725 64845 352
1.9975 65449 478
'''
"""
cmdArgs = get_user_parameters()

if cmdArgs.reporting_level in (REPORTING_STANDARD, REPORTING_VERBOSE):
Expand Down
24 changes: 12 additions & 12 deletions src/spec2nexus/eznx.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#-----------------------------------------------------------------------------


'''
"""
(Easy NeXus) support reading & writing NeXus HDF5 files using h5py
:predecessor: NeXus h5py example code: ``my_lib.py`` [#]_
Expand Down Expand Up @@ -71,7 +71,7 @@
.. rubric:: Classes and Methods
'''
"""


import h5py # HDF5 support
Expand Down Expand Up @@ -117,13 +117,13 @@ def makeGroup(parent, name, nxclass, **attr):


def openGroup(parent, name, nx_class, **attr):
'''open or create the NeXus/HDF5 group, return the object
"""open or create the NeXus/HDF5 group, return the object
:param obj parent: h5py parent object
:param str name: valid NeXus group name to open or create
:param str nxclass: valid NeXus class name (base class or application definition)
:param dict attr: optional dictionary of attributes
'''
"""
try:
group = parent[name]
addAttributes(group, **attr)
Expand All @@ -133,7 +133,7 @@ def openGroup(parent, name, nx_class, **attr):


def makeDataset(parent, name, data = None, **attr):
'''
"""
create and write data to a dataset in the HDF5 file hierarchy
Any named parameters in the call to this method
Expand All @@ -144,7 +144,7 @@ def makeDataset(parent, name, data = None, **attr):
:param obj data: the information to be written
:param dict attr: optional dictionary of attributes
:return: h5py dataset object
'''
"""
if data is None:
obj = parent.create_dataset(name)
else:
Expand All @@ -158,13 +158,13 @@ def makeDataset(parent, name, data = None, **attr):


def write_dataset(parent, name, data, **attr):
'''write to the NeXus/HDF5 dataset, create it if necessary, return the object
"""write to the NeXus/HDF5 dataset, create it if necessary, return the object
:param obj parent: h5py parent object
:param str name: valid NeXus dataset name to write
:param obj data: the information to be written
:param dict attr: optional dictionary of attributes
'''
"""
try:
dset = parent[name]
dset[:] = data
Expand Down Expand Up @@ -227,13 +227,13 @@ def addAttributes(parent, **attr):


def read_nexus_field(parent, dataset_name, astype=None):
'''
"""
get a dataset from the HDF5 parent group
:param obj parent: h5py parent object
:param str dataset_name: name of the dataset (NeXus field) to be read
:param obj astype: option to return as different data type
'''
"""
try:
dataset = parent[dataset_name]
except KeyError:
Expand All @@ -250,7 +250,7 @@ def read_nexus_field(parent, dataset_name, astype=None):


def read_nexus_group_fields(parent, name, fields):
'''
"""
return the fields in the NeXus group as a dict(name=dataset)
This routine provides a mass way to read a directed list
Expand All @@ -261,6 +261,6 @@ def read_nexus_group_fields(parent, name, fields):
:param [name] fields: list of field names to be read
:returns: dictionary of {name:dataset}
:raises KeyError: if a field is not found
'''
"""
group = parent[name]
return {key: read_nexus_field(group, key) for key in fields}
8 changes: 4 additions & 4 deletions src/spec2nexus/eznx_example.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

'''
"""
Writes a simple NeXus HDF5 file using h5py with links.
This example is based on ``writer_2_1`` of the NeXus Manual:
http://download.nexusformat.org/doc/html/examples/h5py/index.html
'''
"""

from spec2nexus import eznx


HDF5_FILE = 'eznx_example.hdf5'

I_v_TTH_DATA = '''
I_v_TTH_DATA = """
17.92608 1037
17.92558 2857
17.92508 23819
Expand All @@ -25,7 +25,7 @@
17.92208 29315
17.92158 6622
17.92108 1321
'''
"""
#---------------------------

tthData, countsData = zip(*[map(float,_.split()) for _ in I_v_TTH_DATA.strip().splitlines()])
Expand Down

0 comments on commit 4daebb5

Please sign in to comment.