Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions nxs/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,12 +236,12 @@
signal sample points, entry is file/path within the file to the data group and
title is the title of the group or the parent NXentry, if available.
"""
from __future__ import with_statement
from __future__ import absolute_import, with_statement, print_function
from copy import copy, deepcopy

import numpy as np
import napi
from napi import NeXusError
import nxs.napi as napi
from nxs.napi import NeXusError

#Memory in MB
NX_MEMORY = 500
Expand Down Expand Up @@ -792,7 +792,7 @@ def dir(self,attrs=False,recursive=False):
displayed. If 'recursive' is True, the contents of child groups are
also displayed.
"""
print self._str_tree(attrs=attrs,recursive=recursive)
print(self._str_tree(attrs=attrs,recursive=recursive))

@property
def tree(self):
Expand Down Expand Up @@ -1823,7 +1823,7 @@ def plot(self, signal, axes, title, errors, fmt,
for _dim in data.shape[2:]:
slab.append(0)
data = data[slab].view().reshape(data.shape[:2])
print "Warning: Only the top 2D slice of the data is plotted"
print("Warning: Only the top 2D slice of the data is plotted")

x = axis_data[0]
y = axis_data[1]
Expand Down Expand Up @@ -3240,7 +3240,7 @@ def demo(argv):
ls *.nxs
plot file.nxs entry.data
"""%(argv[0],)
print usage
print(usage)


if __name__ == "__main__":
Expand Down
4 changes: 2 additions & 2 deletions nxs/unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def __init__(self,name):
else:
self.scalemap = {'': 1}
self.scalebase = 1
#raise ValueError, "Unknown unit %s"%name
#raise ValueError("Unknown unit %s"%name)

def scale(self, units=""):
if units == "" or self.scalemap is None: return 1
Expand All @@ -181,7 +181,7 @@ def __call__(self, value, units=""):
raise KeyError("%s not in %s"%(units," ".join(self.scalemap.keys())))

def _check(expect,get):
if expect != get: raise ValueError, "Expected %s but got %s"%(expect,get)
if expect != get: raise ValueError("Expected %s but got %s"%(expect,get))
#print expect,"==",get

def test():
Expand Down
52 changes: 27 additions & 25 deletions nxstest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@
NeXus tests converted to python.
"""

from __future__ import print_function

import nxs,os,numpy,sys

def memfootprint():
import gc
objs = gc.get_objects()
classes = set( c.__class__ for c in gc.get_objects() if hasattr(c,'__class__') )
# print "\n".join([c.__name__ for c in classes])
print "#objects=",len(objs)
print "#classes=",len(classes)
# print("\n".join([c.__name__ for c in classes]))
print("#objects=",len(objs))
print("#classes=",len(classes))

def leak_test1(n = 1000, mode='w5'):
# import gc
Expand All @@ -25,10 +27,10 @@ def leak_test1(n = 1000, mode='w5'):
except OSError: pass
file = nxs.open(filename,mode)
file.close()
print "File should exist now"
print("File should exist now")
for i in range(n):
if i%100 == 0:
print "loop count %d"%i
print("loop count %d"%i)
memfootprint()
file.open()
file.close()
Expand All @@ -39,31 +41,31 @@ def _show(file, indent=0):
prefix = ' '*indent
link = file.link()
if link:
print "%(prefix)s-> %(link)s" % locals()
print("%(prefix)s-> %(link)s" % locals())
return
for attr,value in file.attrs():
print "%(prefix)s@%(attr)s: %(value)s" % locals()
print("%(prefix)s@%(attr)s: %(value)s" % locals())
for name,nxclass in file.entries():
if nxclass == "SDS":
shape,dtype = file.getinfo()
dims = "x".join([str(x) for x in shape])
print "%(prefix)s%(name)s %(dtype)s %(dims)s" % locals()
print("%(prefix)s%(name)s %(dtype)s %(dims)s" % locals())
link = file.link()
if link:
print " %(prefix)s-> %(link)s" % locals()
print(" %(prefix)s-> %(link)s" % locals())
else:
for attr,value in file.attrs():
print " %(prefix)s@%(attr)s: %(value)s" % locals()
print(" %(prefix)s@%(attr)s: %(value)s" % locals())
if numpy.prod(shape) < 8:
value = file.getdata()
print " %s%s"%(prefix,str(value))
print(" %s%s"%(prefix,str(value)))
else:
print "%(prefix)s%(name)s %(nxclass)s" % locals()
print("%(prefix)s%(name)s %(nxclass)s" % locals())
_show(file, indent+2)

def show_structure(filename):
file = nxs.open(filename)
print "=== File",file.inquirefile()
print("=== File",file.inquirefile())
_show(file)


Expand Down Expand Up @@ -168,7 +170,7 @@ def populate(filename,mode):
failures = 0
def fail(msg):
global failures
print "FAIL:",msg
print("FAIL:",msg)
failures += 1

def dicteq(a,b):
Expand All @@ -177,14 +179,14 @@ def dicteq(a,b):
"""
for k,v in a.iteritems():
if k not in b:
print k,"not in",b
print(k,"not in",b)
return False
if v != b[k]:
print v,"not equal",b[k]
print(v,"not equal",b[k])
return False
for k,v in b.iteritems():
if k not in a:
print k,"not in",a
print(k,"not in",a)
return False
return True

Expand Down Expand Up @@ -264,10 +266,10 @@ def check(filename, mode):
fail("returned string array info is incorrect")
if not (rawshape[0]==5 and rawshape[1]==4 and rawdtype=='char'):
fail("returned string array storage info is incorrect")
print rawshape,dtype
print(rawshape,dtype)
if not (get[0]=="abcd" and get[4]=="qrst"):
fail("returned string is incorrect")
print shape,dtype
print(shape,dtype)


# Check reading from compressed datasets
Expand All @@ -281,7 +283,7 @@ def check(filename, mode):
file.closegroup() #/entry/data
if not (get == expected).all():
fail("compressed data differs")
print get
print(get)

# Check strings
file.opengroup('sample','NXsample') #/entry/sample
Expand All @@ -293,13 +295,13 @@ def check(filename, mode):
file.closegroup() #/entry/sample
if not (shape[0]==12 and dtype=='char'):
fail("returned string info is incorrect")
print shape,dtype
print(shape,dtype)
if not (rawshape[0]==20 and rawdtype=='char'):
fail("returned string storage info is incorrect")
print shape,dtype
print(shape,dtype)
if not (get == "NeXus sample"):
fail("returned string is incorrect")
print shape,dtype
print(shape,dtype)

file.closegroup() #/entry

Expand Down Expand Up @@ -328,13 +330,13 @@ def check(filename, mode):
expected = comp_array[4:(4+5),4:(4+3)]
if not (get == expected).all():
fail("retrieved compressed slabs differ")
print get
print(get)
file.openpath('/entry/data/comp_data')
get = file.getslab([4,4],[5,3])
expected = comp_array[4:(4+5),4:(4+3)]
if not (get == expected).all():
fail("after reopen: retrieved compressed slabs differ")
print get
print(get)
file.openpath('../r8_data')
for k,v in file.attrs():
if k == 'target' and v != '/entry/r8_data':
Expand Down