Skip to content

Commit

Permalink
Merge pull request #154 from prjemian/LGTM-153
Browse files Browse the repository at this point in the history
fixes #153 : LGTM code review recommendations
  • Loading branch information
prjemian committed May 19, 2019
2 parents 9dfd203 + 575bb33 commit 3daa9c5
Show file tree
Hide file tree
Showing 16 changed files with 43 additions and 47 deletions.
3 changes: 1 addition & 2 deletions conda-recipe/run_test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin/env python

import os, sys, unittest
import spec2nexus
# import spec2nexus

# TODO: test something
print("test not implemented yet")
2 changes: 1 addition & 1 deletion create_release_notes.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from __future__ import print_function
from datetime import datetime
import os, sys
import os
import github # pip install pygithub or conda install -c conda-forge pygithub
import collections
import argparse
Expand Down
4 changes: 1 addition & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@
# The full license is in the file LICENSE, distributed with this software.
#-----------------------------------------------------------------------------

from setuptools import setup, find_packages
from setuptools import setup
import os
import re
import sys

import versioneer
Expand Down Expand Up @@ -44,7 +43,6 @@
install_requires = spec2nexus.__install_requires__,
package_dir = {'': 'src'},
packages = ['spec2nexus', 'spec2nexus.plugins', ],
#packages=find_packages(),
package_data = {
'spec2nexus': [
'data/02_03_setup_fly/*',
Expand Down
2 changes: 1 addition & 1 deletion src/spec2nexus/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ def get_versions():
# versionfile_source is the relative path from the top of the source
# tree (where the .git directory might live) to this file. Invert
# this to find the root from __file__.
for i in cfg.versionfile_source.split('/'):
for _i in cfg.versionfile_source.split('/'):
root = os.path.dirname(root)
except NameError:
return {"version": "0+unknown", "full-revisionid": None,
Expand Down
8 changes: 4 additions & 4 deletions src/spec2nexus/dev_datafile.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
if __name__ == '__main__':
pwd = os.path.abspath(os.getcwd())
prefix = os.path.abspath(os.path.join(pwd, 'data', 'APS_spec_data'))
file1 = prefix + '.dat'
# file1 = prefix + '.dat'
hfile = prefix + '.hdf5'
# lmn40.spe has two header sections, 2nd is just before "#S 8"
prefix = os.path.abspath(os.path.join(pwd, 'data', 'lmn40'))
file1 = prefix + '.spe'
# # lmn40.spe has two header sections, 2nd is just before "#S 8"
# prefix = os.path.abspath(os.path.join(pwd, 'data', 'lmn40'))
# file1 = prefix + '.spe'

# CdOsO has four header sections and two #S 1 scans
prefix = os.path.abspath(os.path.join(pwd, 'data', 'CdOsO'))
Expand Down
2 changes: 1 addition & 1 deletion src/spec2nexus/dev_extractSpecScan.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#args = 'data/APS_spec_data.dat -s 1 6 -c mr USAXS_PD I0 seconds'
#args = 'data/33id_spec.dat -s 1 6 -c H K L signal elastic I0 seconds'
#args = 'data/CdOsO -s 1 1.1 48 -c HerixE H K L T_control_LS340 T_sample_LS340 ICO-C PIN-D PIN-C Seconds'
args = 'data/02_03_setup.dat -s 46 1-3 -c ar ay dy Epoch seconds I0 USAXS_PD'
# args = 'data/02_03_setup.dat -s 46 1-3 -c ar ay dy Epoch seconds I0 USAXS_PD'
# args = 'data/02_03_setup.dat -s 47 -c mr seconds I0 USAXS_PD'
args = 'data/xpcs_plugin_sample.spec -s 7 -c img_n Epoch ccdc'

Expand Down
5 changes: 2 additions & 3 deletions src/spec2nexus/nexus.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@

__url__ = 'http://spec2nexus.readthedocs.org/en/latest/spec2nexus.html'

import os #@UnusedImport
import sys #@UnusedImport
import numpy as np #@UnusedImport
import os
import sys

if __name__ == "__main__":
# put us on the path for developers
Expand Down
11 changes: 4 additions & 7 deletions src/spec2nexus/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,10 @@
"""


import os #@UnusedImport
import sys #@UnusedImport
import imp #@UnusedImport
import inspect #@UnusedImport
import pprint #@UnusedImport
import re #@UnusedImport
from spec2nexus.utils import strip_first_word #@UnusedImport
import os
import imp
import inspect
import re


PLUGIN_SEARCH_PATH_ENVIRONMENT_VARIABLE = 'SPEC2NEXUS_PLUGIN_PATH'
Expand Down
6 changes: 3 additions & 3 deletions src/spec2nexus/plugins/XPCS_spec2nexus.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
SPEC data file control lines unique to the APS XPCS instrument
"""

from spec2nexus.plugin import ControlLineHandler, strip_first_word
from spec2nexus.plugin import ControlLineHandler
from spec2nexus.eznx import makeGroup
from spec2nexus.spec import SpecDataFileHeader
from spec2nexus.spec import SpecDataFileScan
from spec2nexus.spec import SpecDataFileHeader, SpecDataFileScan
from spec2nexus.utils import strip_first_word

class XPCS_VA(ControlLineHandler):
"""**#VA**"""
Expand Down
2 changes: 0 additions & 2 deletions src/spec2nexus/plugins/spec_common_spec2nexus.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@

from collections import OrderedDict
import datetime
import re
import time

from spec2nexus.eznx import write_dataset, makeGroup, openGroup
from spec2nexus.plugin import ControlLineHandler
Expand Down
3 changes: 2 additions & 1 deletion src/spec2nexus/scanf.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ def scanf(fmt, s=None):
or None if the format does not match.
"""

if s == None: s = sys.stdin
if s is None:
s = sys.stdin
if hasattr(s, "readline"):
s = s.readline()

Expand Down
5 changes: 1 addition & 4 deletions src/spec2nexus/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,7 @@
"""

from collections import OrderedDict
import datetime
import os #@UnusedImport
import re #@UnusedImport
import sys #@UnusedImport
import os
import time
from spec2nexus.utils import get_all_plugins

Expand Down
2 changes: 1 addition & 1 deletion src/spec2nexus/specplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,7 @@ def retrieve_plot_data(self):
axis1 = self.scan.data.get(label1)
axis2 = self.scan.data.get(label2)
intervals1, intervals2 = map(int, (intervals1, intervals2))
start1, end1, start2, end2, time = map(float, (start1, end1, start2, end2, time))
# unused: start1, end1, start2, end2, time = map(float, (start1, end1, start2, end2, time))

if len(axis1) < intervals1 and min(axis2) == max(axis2):
# stopped scan before second row started, 1-D plot is better (issue #82)
Expand Down
8 changes: 7 additions & 1 deletion src/spec2nexus/specplot_gallery.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@
from spec2nexus import spec
from spec2nexus import specplot

try:
FileNotFoundError
except NameError:
FileNotFoundError = IOError # py27 compatibility


MTIME_CACHE_FILE = 'mtime_cache.txt'
HTML_INDEX_FILE = 'index.html'
DOC_URL = 'http://spec2nexus.readthedocs.io/en/latest/specplot_gallery.html'
Expand Down Expand Up @@ -139,7 +145,7 @@ def plot_all_scans(self, specFile):
logger(' mtime_specFile: ' + str(mtime_specFile))
logger(' mtime_pngdir: ' + str(mtime_pngdir))
sd = specplot.openSpecFile(specFile)
except:
except FileNotFoundError:
return # could not open file, be silent about it
if len(sd.headers) == 0: # no scan header found, again, silence
return
Expand Down
10 changes: 4 additions & 6 deletions src/spec2nexus/uxml/uxml_spec2nexus.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@ class Dataset(object):

def __init__(self, xml_node):
self.name = xml_node.get('name')
ds = eznx.makeDataset(None, self.name, 'test')
pass
eznx.makeDataset(None, self.name, 'test')


class Group(object):
Expand All @@ -97,7 +96,6 @@ def __init__(self, xml_node):
# group = h5py.Group()
# group.create_group(self.name)
#openGroup(None, self.name, self.NX_class)
pass


class Hardlink(object):
Expand Down Expand Up @@ -156,11 +154,11 @@ def postprocess(self, scan, *args, **kws):

def writer(self, h5parent, writer, scan, *args, **kws):
"""Describe how to store this data in an HDF5 NeXus file"""
desc = 'UXML metadata'
#desc = 'UXML metadata'
#eznx.write_dataset(h5parent, "counting_basis", desc)
#eznx.write_dataset(h5parent, "T", float(scan.T), units='s', description = desc)
# TODO: parse the XML and store
selector = dict(dataset=Dataset, group=Group, hardlink=Hardlink)
for item in scan.UXML_root:
obj = selector[item.tag](item)
#print item.tag, item.get('name'), obj, obj.name
_obj = selector[item.tag](item)
#print item.tag, item.get('name'), _obj, obj.name
17 changes: 10 additions & 7 deletions src/spec2nexus/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def root_attributes(self):
c = header0.comments[0]
user = c[c.find('User = '):].split('=')[1].strip()
dd['SPEC_user'] = user
except:
except Exception:
pass
return dd

Expand All @@ -162,16 +162,19 @@ def save_data(self, nxdata, scan):
"""*internal*: store the scan data"""
scan_type = scan.scanCmd.split()[0]

signal, axes = '', ['',]
if scan_type in ('mesh', 'hklmesh'):
# hklmesh H 1.9 2.1 100 K 1.9 2.1 100 -800000
signal, axes = self.mesh(nxdata, scan)
elif scan_type in ('hscan', 'kscan', 'lscan', 'hklscan'):
# hklscan 1.00133 1.00133 1.00133 1.00133 2.85 3.05 200 -400000
h_0, h_N, k_0, k_N, l_0, l_N = scan.scanCmd.split()[1:7]
if h_0 != h_N: axes = ['H',]
elif k_0 != k_N: axes = ['K',]
elif l_0 != l_N: axes = ['L',]
# TODO: why bother defining axes here? Not used. issue #155
if h_0 != h_N:
axes = ['H',]
elif k_0 != k_N:
axes = ['K',]
elif l_0 != l_N:
axes = ['L',]
signal, axes = self.oneD(nxdata, scan)
else:
signal, axes = self.oneD(nxdata, scan)
Expand Down Expand Up @@ -234,6 +237,7 @@ def mca_spectra(self, nxdata, scan, primary_axis_label):
channels = np.arange(1, len(spectrum[0])+1, dtype=int)
_mca_x_ = a + channels * (b + channels * c)
self.write_ds(nxdata, ds_name + 'channel_', channels, units = 'channel')
self.write_ds(nxdata, ds_name + 'channel_scaled_x', _mca_x_, units = '')

def mesh(self, nxdata, scan):
"""*internal*: data parser for 2-D mesh and hklmesh"""
Expand All @@ -245,7 +249,6 @@ def mesh(self, nxdata, scan):
# hklmesh Q1 start1 end1 intervals1 Q2 start2 end2 intervals2 time
# mesh: data/33id_spec.dat scan 22
# hklmesh: data/33bm_spec.dat scan 17
signal, axes = '', ['',]

label1, start1, end1, intervals1, label2, start2, end2, intervals2, time = scan.scanCmd.split()[1:]
if label1 not in scan.data:
Expand All @@ -255,7 +258,7 @@ def mesh(self, nxdata, scan):
axis1 = scan.data.get(label1)
axis2 = scan.data.get(label2)
intervals1, intervals2 = map(int, (intervals1, intervals2))
start1, end1, start2, end2, time = map(float, (start1, end1, start2, end2, time))
# unused: start1, end1, start2, end2, time = map(float, (start1, end1, start2, end2, time))
if len(axis1) < intervals1: # stopped scan before second row started
signal, axes = self.oneD(nxdata, scan) # fallback support
else:
Expand Down

0 comments on commit 3daa9c5

Please sign in to comment.