Commit d2f2e654 authored by Jan Kotanski's avatar Jan Kotanski
Browse files

New upstream version 0.4.20

parent 88ed97d7
......@@ -54,3 +54,6 @@ Icon?
# Emacs backup files
*~
# Virtual Studio Code
.vscode
package:
name: nexusformat
version: "0.4.18"
version: "0.4.19"
source:
git_url: https://github.com/nexpy/nexusformat.git
git_tag: v0.4.18
git_tag: v0.4.19
build:
entry_points:
......
......@@ -20,8 +20,8 @@ def get_keywords():
# setup.py/versioneer.py will grep for the variable names, so they must
# each be defined on a line of their own. _version.py will just call
# get_keywords().
git_refnames = " (HEAD -> master, tag: v0.4.18)"
git_full = "b9de7f7dba7e2b4c623aa05f19bee12fbc4ec3a9"
git_refnames = " (tag: v0.4.20)"
git_full = "e1e6689b1651b8b7217158528336b80d8f126113"
keywords = {"refnames": git_refnames, "full": git_full}
return keywords
......
......@@ -71,7 +71,8 @@ class PylabPlotter(object):
Matplotlib plotter class for NeXus data.
"""
def plot(self, data_group, fmt, xmin, xmax, ymin, ymax, zmin, zmax, **opts):
def plot(self, data_group, fmt='', xmin=None, xmax=None, ymin=None, ymax=None,
vmin=None, vmax=None, **opts):
"""
Plot the data entry.
......@@ -159,18 +160,18 @@ class PylabPlotter(object):
y = boundaries(axes[-2], data.shape[-2])
xlabel, ylabel = label(axes[-1]), label(axes[-2])
if not zmin:
zmin = np.nanmin(data[data>-np.inf])
if not zmax:
zmax = np.nanmax(data[data<np.inf])
if not vmin:
vmin = np.nanmin(data[data>-np.inf])
if not vmax:
vmax = np.nanmax(data[data<np.inf])
if not image:
if log:
zmin = max(zmin, 0.01)
zmax = max(zmax, 0.01)
opts["norm"] = LogNorm(zmin, zmax)
vmin = max(vmin, 0.01)
vmax = max(vmax, 0.01)
opts["norm"] = LogNorm(vmin, vmax)
else:
opts["norm"] = Normalize(zmin, zmax)
opts["norm"] = Normalize(vmin, vmax)
ax = plt.gca()
if image:
......
......@@ -28,7 +28,7 @@ data.
Example 1: Loading a NeXus file
-------------------------------
The following commands loads NeXus data from a file, displays (some of) the
contents as a tree, and then accesses individual data items.
contents as a tree, and then accesses individual data items
>>> from nexusformat import nexus as nx
>>> a=nx.load('sns/data/ARCS_7326.nxs')
......@@ -83,7 +83,7 @@ file. The data are first created as Numpy arrays
>>> z=np.sin(X)*np.sin(Y)
Then, a NeXus data group is created and the data inserted to produce a
NeXus-compliant structure that can be saved to a file.
NeXus-compliant structure that can be saved to a file
>>> root=nx.NXroot(NXentry())
>>> print root.tree
......@@ -369,7 +369,7 @@ class NXFile(object):
elif not os.path.exists(os.path.dirname(name)):
raise NeXusError("'%s/' does not exist"
% os.path.dirname(name))
elif mode == 'w' or mode == 'w-' or mode == 'w5':
elif mode == 'w' or mode == 'w-' or mode == 'w5' or mode == 'a':
if mode == 'w5':
mode = 'w'
self._file = self.h5.File(name, mode, **opts)
......@@ -892,7 +892,7 @@ def _getvalue(value, dtype=None, shape=None):
_dtype = _getdtype(dtype)
if _dtype.kind == 'S':
value = text(value).encode('utf-8')
return np.asscalar(np.array(value, dtype=_dtype)), _dtype, ()
return np.array(value, dtype=_dtype).item(), _dtype, ()
except Exception:
raise NeXusError("The value is incompatible with the dtype")
else:
......@@ -909,7 +909,14 @@ def _getvalue(value, dtype=None, shape=None):
else:
_value = np.asarray(value) #convert subclasses of ndarray
else:
_value = np.asarray(value)
try:
_value = [np.asarray(v) for v in value]
if len(set([v.shape for v in _value])) > 1:
raise NeXusError(
"Cannot assign an iterable with items of multiple shapes")
_value = np.asarray(_value)
except TypeError:
_value = np.asarray(value)
if _value.dtype.kind == 'S' or _value.dtype.kind == 'U':
_value = _value.astype(string_dtype)
if dtype is not None:
......@@ -927,7 +934,7 @@ def _getvalue(value, dtype=None, shape=None):
except ValueError:
raise NeXusError("The value is incompatible with the shape")
if _value.shape == ():
return np.asscalar(_value), _value.dtype, _value.shape
return _value.item(), _value.dtype, _value.shape
else:
return _value, _value.dtype, _value.shape
......@@ -1161,7 +1168,7 @@ class NXattr(object):
else:
return [text(value) for value in self._value[()]]
elif self.shape == (1,):
return np.asscalar(self._value)
return self._value.item()
else:
return self._value
......@@ -1967,7 +1974,7 @@ class NXfield(NXobject):
"""
idx = convert_index(idx, self)
if len(self) == 1:
result = self
result = self.nxvalue
elif self._value is None:
if self._uncopied_data:
self._get_uncopied_data()
......@@ -2320,8 +2327,10 @@ class NXfield(NXobject):
def __long__(self):
"""
Casts a scalar field as a long integer
The use of the 'long' function is not valid in Python 3 and no longer useful in Python 2
"""
return long(self.nxvalue)
return int(self.nxvalue)
def __float__(self):
"""
......@@ -2723,7 +2732,7 @@ class NXfield(NXobject):
else:
return [text(value) for value in _value[()]]
elif self.shape == (1,):
return np.asscalar(_value)
return _value.item()
else:
return _value
......@@ -2931,7 +2940,9 @@ class NXfield(NXobject):
@property
def maxshape(self):
if self.nxfilemode:
if self._maxshape is not None:
return self._maxshape
elif self.nxfilemode:
with self.nxfile as f:
_maxshape = f[self.nxfilepath].maxshape
elif self._memfile:
......@@ -2992,7 +3003,7 @@ class NXfield(NXobject):
return False
def plot(self, fmt='', xmin=None, xmax=None, ymin=None, ymax=None,
zmin=None, zmax=None, **opts):
vmin=None, vmax=None, **opts):
"""
Plot data if the signal attribute is defined.
......@@ -3031,7 +3042,8 @@ class NXfield(NXobject):
else:
signal_path = self.nxpath
data.nxsignal.attrs['signal_path'] = signal_path
plotview.plot(data, fmt, xmin, xmax, ymin, ymax, zmin, zmax, **opts)
plotview.plot(data, fmt, xmin=None, xmax=None, ymin=None, ymax=None,
vmin=None, vmax=None, **opts)
else:
raise NeXusError("NXfield not plottable")
......@@ -3042,23 +3054,23 @@ class NXfield(NXobject):
self.plot(fmt=fmt, over=True, **opts)
def logplot(self, fmt='', xmin=None, xmax=None, ymin=None, ymax=None,
zmin=None, zmax=None, **opts):
vmin=None, vmax=None, **opts):
"""
Plots the data intensity contained within the group on a log scale.
"""
self.plot(fmt=fmt, log=True,
xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
zmin=zmin, zmax=zmax, **opts)
vmin=vmin, vmax=vmax, **opts)
def implot(self, fmt='', xmin=None, xmax=None, ymin=None, ymax=None,
zmin=None, zmax=None, **opts):
vmin=None, vmax=None, **opts):
"""
Plots the data intensity as an RGB(A) image.
"""
if self.plot_rank > 2 and (self.shape[-1] == 3 or self.shape[-1] == 4):
self.plot(fmt=fmt, image=True,
xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
zmin=zmin, zmax=zmax, **opts)
vmin=vmin, vmax=vmax, **opts)
else:
raise NeXusError("Invalid shape for RGB(A) image")
......@@ -3595,7 +3607,7 @@ class NXgroup(NXobject):
"""
Returns true if a NeXus object with the specified name is in the group.
"""
return self.entries.has_key(name)
return name in self.entries
def copy(self):
"""
......@@ -3741,30 +3753,30 @@ class NXgroup(NXobject):
"""
return self.sum(axis, averaged=True)
def moment(self, order=1):
def moment(self, order=1, center=None):
"""
Returns an NXfield containing the moments of the NXdata group
Returns an NXfield containing the central moments of the NXdata group
assuming the signal is one-dimensional.
Currently, the first two moments have been defined (order =1 or 2).
"""
if self.nxsignal is None:
signal, axes = self.nxsignal, self.nxaxes
if signal is None:
raise NeXusError("No signal to calculate")
elif len(self.nxsignal.shape) > 1:
elif len(signal.shape) > 1:
raise NeXusError(
"Operation only possible on one-dimensional signals")
elif order > 2:
raise NeXusError("Higher moments not yet implemented")
if not hasattr(self,"nxclass"):
if not hasattr(self, "nxclass"):
raise NeXusError(
"Operation not allowed for groups of unknown class")
y = self.nxsignal
x = centers(y, self.nxaxes)[0]
mean = (y * x).sum() / y.sum()
y = signal / signal.sum()
x = centers(y, axes)[0]
if center:
c = center
else:
c = (y * x).sum()
if order == 1:
return mean
elif order == 2:
return ((y * x**2).sum() / y.sum()) - mean**2
return c
else:
return (y * (x - c)**order).sum()
def mean(self):
"""
......@@ -4618,7 +4630,7 @@ class NXdata(NXgroup):
idx, axes = self.slab(key)
removed_axes = []
for axis in axes:
if axis.shape == () or axis.shape == (1,):
if axis.shape == () or axis.shape == (0,) or axis.shape == (1,):
removed_axes.append(axis)
axes = [ax for ax in axes if ax not in [rax for rax in removed_axes
if rax is ax]]
......@@ -4877,8 +4889,8 @@ class NXdata(NXgroup):
else:
ind = convert_index(ind, axes[i])
slices.append(ind)
if (signal.shape[i] < axes[i].shape[0] and
isinstance(ind, slice) and ind.stop is not None):
if (isinstance(ind, slice) and ind.stop is not None
and signal.shape[i] < axes[i].shape[0]):
ind = slice(ind.start, ind.stop+1, ind.step)
axes[i] = axes[i][ind]
return tuple(slices), axes
......@@ -4924,7 +4936,7 @@ class NXdata(NXgroup):
return None
def plot(self, fmt='', xmin=None, xmax=None, ymin=None, ymax=None,
zmin=None, zmax=None, **opts):
vmin=None, vmax=None, **opts):
"""
Plot data contained within the group.
......@@ -4966,7 +4978,8 @@ class NXdata(NXgroup):
except ImportError:
from .plot import plotview
plotview.plot(self, fmt, xmin, xmax, ymin, ymax, zmin, zmax, **opts)
plotview.plot(self, fmt, xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
vmin=vmin, vmax=vmax, **opts)
def oplot(self, fmt='', **opts):
"""
......@@ -4975,16 +4988,16 @@ class NXdata(NXgroup):
self.plot(fmt=fmt, over=True, **opts)
def logplot(self, fmt='', xmin=None, xmax=None, ymin=None, ymax=None,
zmin=None, zmax=None, **opts):
vmin=None, vmax=None, **opts):
"""
Plots the data intensity contained within the group on a log scale.
"""
self.plot(fmt=fmt, log=True,
xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
zmin=zmin, zmax=zmax, **opts)
vmin=vmin, vmax=vmax, **opts)
def implot(self, fmt='', xmin=None, xmax=None, ymin=None, ymax=None,
zmin=None, zmax=None, **opts):
vmin=None, vmax=None, **opts):
"""
Plots the data intensity as an image.
"""
......@@ -4992,7 +5005,7 @@ class NXdata(NXgroup):
(self.nxsignal.shape[-1] == 3 or self.nxsignal.shape[-1] == 4)):
self.plot(fmt=fmt, image=True,
xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
zmin=zmin, zmax=zmax, **opts)
vmin=vmin, vmax=vmax, **opts)
else:
raise NeXusError("Invalid shape for RGB(A) image")
......
This diff is collapsed.
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment