Skip to content

Commit

Permalink
Synchronized nexpy and nexusformat tree.py
Browse files Browse the repository at this point in the history
  • Loading branch information
rayosborn committed Dec 22, 2014
1 parent 0cfd9bc commit ef1aa88
Showing 1 changed file with 31 additions and 10 deletions.
41 changes: 31 additions & 10 deletions src/nexusformat/nexus/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -2100,7 +2100,9 @@ def _getdata(self):
if np.prod(self.shape) * np.dtype(self.dtype).itemsize <= NX_MEMORY*1024*1024:
if self.nxfilemode:
self._value = self._get_filedata()
elif self._memfile:
elif self._uncopied_data:
self._get_uncopied_data()
if self._memfile:
self._value = self._get_memdata()
self._memfile = None
if self._value is not None:
Expand Down Expand Up @@ -2221,6 +2223,23 @@ def _getsize(self):
ndim = property(_getndim, doc="Property: No. of dimensions of NeXus field")
size = property(_getsize, doc="Property: Size of NeXus field")

@property
def plot_shape(self):
_shape = list(self.shape)
while 1 in _shape:
_shape.remove(1)
return _shape

@property
def plot_rank(self):
return len(self.plot_shape)

def is_plottable(self):
if self.plot_rank > 0:
return True
else:
return False

def plot(self, fmt='', xmin=None, xmax=None, ymin=None, ymax=None,
zmin=None, zmax=None, **opts):
"""
Expand All @@ -2245,19 +2264,16 @@ def plot(self, fmt='', xmin=None, xmax=None, ymin=None, ymax=None,

from nexpy.gui.plotview import plotview

# Check there is a plottable signal
if 'signal' in self.attrs.keys():
if self.is_plottable():
if 'axes' in self.attrs.keys():
axes = [getattr(self.nxgroup, name)
for name in _readaxes(self.axes)]
data = NXdata(self, axes, title=self.nxtitle)
else:
data = NXdata(self, title=self.nxtitle)
plotview.plot(data, fmt, xmin, xmax, ymin, ymax, zmin, zmax, **opts)
else:
raise NeXusError('No plottable signal defined')

# Plot with the available plotter
plotview.plot(data, fmt, xmin, xmax, ymin, ymax, zmin, zmax, **opts)
raise NeXusError('NXfield not plottable')

def oplot(self, fmt='', **opts):
"""
Expand Down Expand Up @@ -2574,9 +2590,7 @@ def __setattr__(self, name, value):

def __delattr__(self, name):
if name in self._entries:
if self.nxfilemode == 'r':
raise NeXusError('NeXus file opened as readonly')
self.__delitem__(name)
raise NeXusError('Members can only be deleted using the group dictionary')
else:
object.__delattr__(self, name)

Expand Down Expand Up @@ -3125,6 +3139,13 @@ def _getentries(self):
nxtitle = property(_title, "Property: Title for group plot")
entries = property(_getentries,doc="Property: NeXus objects within group")

def is_plottable(self):
plottable = False
for entry in self:
if self[entry].is_plottable():
plottable = True
return plottable

def plot(self, fmt='', xmin=None, xmax=None, ymin=None, ymax=None,
zmin=None, zmax=None, **opts):
"""
Expand Down

0 comments on commit ef1aa88

Please sign in to comment.