[yt-svn] commit/yt: 3 new changesets
Bitbucket
commits-noreply at bitbucket.org
Fri Nov 2 14:01:16 PDT 2012
3 new commits in yt:
https://bitbucket.org/yt_analysis/yt/changeset/663fdee24975/
changeset: 663fdee24975
branch: yt
user: MatthewTurk
date: 2012-11-01 21:34:28
summary: Adding a TimeSeriesController class, which gets added to plot windows by
default. This lets you increment and decrement your plot window dataset
pointer. For instance:
from yt.mods import *
ts = TimeSeriesData.from_filenames("enzo_tiny_cosmology/DD*/*.hierarchy")
sl = SlicePlot(ts, "x", "Density")
sl.annotate_timestamp(-0.5, -0.4, units="years", size=24)
for i in range(len(ts)):
sl.show()
sl.controller.inc()
affected #: 3 files
diff -r b54dc03a34eec3fe3b472dcb993bd93dbd5f8f54 -r 663fdee249754c2827db0a2a47748b6a9cc7acce yt/funcs.py
--- a/yt/funcs.py
+++ b/yt/funcs.py
@@ -23,6 +23,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
+import __builtin__
import time, types, signal, inspect, traceback, sys, pdb, os
import contextlib
import warnings, struct, subprocess
@@ -310,7 +311,7 @@
maxval = max(maxval, 1)
from yt.config import ytcfg
if ytcfg.getboolean("yt", "suppressStreamLogging") or \
- ytcfg.getboolean("yt", "ipython_notebook") or \
+ "__IPYTHON__" in dir(__builtin__) or \
ytcfg.getboolean("yt", "__withintesting"):
return DummyProgressBar()
elif ytcfg.getboolean("yt", "__withinreason"):
diff -r b54dc03a34eec3fe3b472dcb993bd93dbd5f8f54 -r 663fdee249754c2827db0a2a47748b6a9cc7acce yt/utilities/parallel_tools/parallel_analysis_interface.py
--- a/yt/utilities/parallel_tools/parallel_analysis_interface.py
+++ b/yt/utilities/parallel_tools/parallel_analysis_interface.py
@@ -1058,3 +1058,47 @@
nextdim = (nextdim + 1) % 3
return cuts
+class GroupOwnership(ParallelAnalysisInterface):
+ def __init__(self, items):
+ ParallelAnalysisInterface.__init__(self)
+ self.num_items = len(items)
+ self.items = items
+ assert(self.num_items >= self.comm.size)
+ self.owned = range(self.comm.size)
+ self.pointer = 0
+ if parallel_capable:
+ communication_system.push_with_ids(range(self.size))
+
+ def __del__(self):
+ if parallel_capable:
+ communication_system.pop()
+
+ def inc(self, n=1):
+ old_item = self.item
+ for i in range(n):
+ if self.pointer >= self.num_items - self.comm.size: break
+ self.owned[self.pointer % self.comm.size] += self.comm.size
+ self.pointer += 1
+ if self.item is not old_item:
+ self.switch()
+
+ def dec(self, n=1):
+ old_item = self.item
+ for i in range(n):
+ if self.pointer == 0: break
+ self.owned[(self.pointer - 1) % self.comm.size] -= self.comm.size
+ self.pointer -= 1
+ if self.item is not old_item:
+ self.switch()
+
+ _last = None
+ @property
+ def item(self):
+ own = self.owned[self.comm.rank]
+ if self._last != own:
+ self._item = self.items[own]
+ self._last = own
+ return self._item
+
+ def switch(self):
+ pass
diff -r b54dc03a34eec3fe3b472dcb993bd93dbd5f8f54 -r 663fdee249754c2827db0a2a47748b6a9cc7acce yt/visualization/plot_window.py
--- a/yt/visualization/plot_window.py
+++ b/yt/visualization/plot_window.py
@@ -60,6 +60,10 @@
axis_labels
from yt.utilities.math_utils import \
ortho_find
+from yt.utilities.parallel_tools.parallel_analysis_interface import \
+ GroupOwnership
+from yt.data_objects.time_series import \
+ TimeSeriesData
def invalidate_data(f):
@wraps(f)
@@ -254,6 +258,13 @@
self.set_center(center)
self._initfinished = True
+ def _initialize_dataset(self, ts):
+ if not isinstance(ts, TimeSeriesData):
+ if not iterable(ts): ts = [ts]
+ ts = TimeSeriesData(ts)
+ self.controller = TimeSeriesPlotController(ts, self)
+ return self.controller.item
+
def __getitem__(self, item):
return self.plots[item]
@@ -987,6 +998,8 @@
>>> p.save('sliceplot')
"""
+ # tHis will handle time series data and controllers
+ pf = self._initialize_dataset(pf)
axis = fix_axis(axis)
(bounds,center) = GetBoundsAndCenter(axis, center, width, pf)
slc = pf.h.slice(axis, center[axis], fields=fields)
@@ -1493,3 +1506,18 @@
vmax = self.zmax, cmap = cmap)
self.image.axes.ticklabel_format(scilimits=(-4,3))
+class TimeSeriesPlotController(GroupOwnership):
+ def __init__(self, ts, pw):
+ GroupOwnership.__init__(self, ts)
+ self.pw = pw
+
+ def switch(self):
+ ds = self.pw.data_source
+ new_pf = self.item
+ name = ds._type_name
+ kwargs = dict((n, getattr(ds, n)) for n in ds._con_args)
+ new_ds = getattr(new_pf.h, name)(**kwargs)
+ self.pw.data_source = new_ds
+ self.pw._data_valid = self.pw._plot_valid = False
+ self.pw._recreate_frb()
+ self.pw._setup_plots()
https://bitbucket.org/yt_analysis/yt/changeset/37dc59a737a9/
changeset: 37dc59a737a9
branch: yt
user: MatthewTurk
date: 2012-11-02 21:16:24
summary: This changes how TimeSeriesData works with PlotWindow objects. Rather than the
.inc() method of the previous version, this now works by simple iteration:
http://paste.yt-project.org/show/2830/
The .piter() method is also available.
This also fixes what I believe is potentially a large bug that is rarely
encounteres, where parallelism would sometimes look for the shape of a None
object.
GroupOwnership is now orphaned and unless we find a use for it soon, deleted.
affected #: 2 files
diff -r 663fdee249754c2827db0a2a47748b6a9cc7acce -r 37dc59a737a99e4f27e6268c1672710af9b15eb6 yt/utilities/parallel_tools/parallel_analysis_interface.py
--- a/yt/utilities/parallel_tools/parallel_analysis_interface.py
+++ b/yt/utilities/parallel_tools/parallel_analysis_interface.py
@@ -581,7 +581,9 @@
ncols, size = data.shape
ncols = self.comm.allreduce(ncols, op=MPI.MAX)
if ncols == 0:
- data = np.zeros(0, dtype=dtype) # This only works for
+ data = np.zeros(0, dtype=dtype) # This only works for
+ elif data is None:
+ data = np.zeros((ncols, 0), dtype=dtype)
size = data.shape[-1]
sizes = np.zeros(self.comm.size, dtype='int64')
outsize = np.array(size, dtype='int64')
@@ -1067,14 +1069,15 @@
self.owned = range(self.comm.size)
self.pointer = 0
if parallel_capable:
- communication_system.push_with_ids(range(self.size))
+ communication_system.push_with_ids([self.comm.rank])
def __del__(self):
if parallel_capable:
communication_system.pop()
- def inc(self, n=1):
+ def inc(self, n = -1):
old_item = self.item
+ if n == -1: n = self.comm.size
for i in range(n):
if self.pointer >= self.num_items - self.comm.size: break
self.owned[self.pointer % self.comm.size] += self.comm.size
@@ -1082,8 +1085,9 @@
if self.item is not old_item:
self.switch()
- def dec(self, n=1):
+ def dec(self, n = -1):
old_item = self.item
+ if n == -1: n = self.comm.size
for i in range(n):
if self.pointer == 0: break
self.owned[(self.pointer - 1) % self.comm.size] -= self.comm.size
diff -r 663fdee249754c2827db0a2a47748b6a9cc7acce -r 37dc59a737a99e4f27e6268c1672710af9b15eb6 yt/visualization/plot_window.py
--- a/yt/visualization/plot_window.py
+++ b/yt/visualization/plot_window.py
@@ -262,8 +262,29 @@
if not isinstance(ts, TimeSeriesData):
if not iterable(ts): ts = [ts]
ts = TimeSeriesData(ts)
- self.controller = TimeSeriesPlotController(ts, self)
- return self.controller.item
+ return ts
+
+ def __iter__(self):
+ for pf in self.ts:
+ mylog.warning("Switching to %s", pf)
+ self._switch_pf(pf)
+ yield self
+
+ def piter(self, *args, **kwargs):
+ for pf in self.ts.piter(*args, **kwargs):
+ self._switch_pf(pf)
+ yield self
+
+ def _switch_pf(self, new_pf):
+ ds = self.data_source
+ name = ds._type_name
+ kwargs = dict((n, getattr(ds, n)) for n in ds._con_args)
+ new_ds = getattr(new_pf.h, name)(**kwargs)
+ self.pf = new_pf
+ self.data_source = new_ds
+ self._data_valid = self._plot_valid = False
+ self._recreate_frb()
+ self._setup_plots()
def __getitem__(self, item):
return self.plots[item]
@@ -284,7 +305,6 @@
self._frb._get_data_source_fields()
else:
for key in old_fields: self._frb[key]
- self.pf = self._frb.pf
self._data_valid = True
def _setup_plots(self):
@@ -999,9 +1019,11 @@
"""
# tHis will handle time series data and controllers
- pf = self._initialize_dataset(pf)
+ ts = self._initialize_dataset(pf)
+ self.ts = ts
+ pf = self.pf = ts[0]
axis = fix_axis(axis)
- (bounds,center) = GetBoundsAndCenter(axis, center, width, pf)
+ (bounds, center) = GetBoundsAndCenter(axis, center, width, pf)
slc = pf.h.slice(axis, center[axis], fields=fields)
PWViewerMPL.__init__(self, slc, bounds, origin=origin)
self.set_axes_unit(axes_unit)
@@ -1082,8 +1104,11 @@
>>> p.save('sliceplot')
"""
+ ts = self._initialize_dataset(pf)
+ self.ts = ts
+ pf = self.pf = ts[0]
axis = fix_axis(axis)
- (bounds,center) = GetBoundsAndCenter(axis,center,width,pf)
+ (bounds, center) = GetBoundsAndCenter(axis, center, width, pf)
proj = pf.h.proj(axis,fields,weight_field=weight_field,max_level=max_level,center=center)
PWViewerMPL.__init__(self,proj,bounds,origin=origin)
self.set_axes_unit(axes_unit)
@@ -1505,19 +1530,3 @@
norm = norm, vmin = self.zmin,
vmax = self.zmax, cmap = cmap)
self.image.axes.ticklabel_format(scilimits=(-4,3))
-
-class TimeSeriesPlotController(GroupOwnership):
- def __init__(self, ts, pw):
- GroupOwnership.__init__(self, ts)
- self.pw = pw
-
- def switch(self):
- ds = self.pw.data_source
- new_pf = self.item
- name = ds._type_name
- kwargs = dict((n, getattr(ds, n)) for n in ds._con_args)
- new_ds = getattr(new_pf.h, name)(**kwargs)
- self.pw.data_source = new_ds
- self.pw._data_valid = self.pw._plot_valid = False
- self.pw._recreate_frb()
- self.pw._setup_plots()
https://bitbucket.org/yt_analysis/yt/changeset/8e2150167715/
changeset: 8e2150167715
branch: yt
user: brittonsmith
date: 2012-11-02 22:01:14
summary: Merged in MatthewTurk/yt (pull request #322)
affected #: 2 files
diff -r d1f7280c3c79607e859605e02e5a296c2acfc4b6 -r 8e2150167715b63ab413670576ea18a08e9f72bd yt/utilities/parallel_tools/parallel_analysis_interface.py
--- a/yt/utilities/parallel_tools/parallel_analysis_interface.py
+++ b/yt/utilities/parallel_tools/parallel_analysis_interface.py
@@ -581,7 +581,9 @@
ncols, size = data.shape
ncols = self.comm.allreduce(ncols, op=MPI.MAX)
if ncols == 0:
- data = np.zeros(0, dtype=dtype) # This only works for
+ data = np.zeros(0, dtype=dtype) # This only works for
+ elif data is None:
+ data = np.zeros((ncols, 0), dtype=dtype)
size = data.shape[-1]
sizes = np.zeros(self.comm.size, dtype='int64')
outsize = np.array(size, dtype='int64')
@@ -1058,3 +1060,49 @@
nextdim = (nextdim + 1) % 3
return cuts
+class GroupOwnership(ParallelAnalysisInterface):
+ def __init__(self, items):
+ ParallelAnalysisInterface.__init__(self)
+ self.num_items = len(items)
+ self.items = items
+ assert(self.num_items >= self.comm.size)
+ self.owned = range(self.comm.size)
+ self.pointer = 0
+ if parallel_capable:
+ communication_system.push_with_ids([self.comm.rank])
+
+ def __del__(self):
+ if parallel_capable:
+ communication_system.pop()
+
+ def inc(self, n = -1):
+ old_item = self.item
+ if n == -1: n = self.comm.size
+ for i in range(n):
+ if self.pointer >= self.num_items - self.comm.size: break
+ self.owned[self.pointer % self.comm.size] += self.comm.size
+ self.pointer += 1
+ if self.item is not old_item:
+ self.switch()
+
+ def dec(self, n = -1):
+ old_item = self.item
+ if n == -1: n = self.comm.size
+ for i in range(n):
+ if self.pointer == 0: break
+ self.owned[(self.pointer - 1) % self.comm.size] -= self.comm.size
+ self.pointer -= 1
+ if self.item is not old_item:
+ self.switch()
+
+ _last = None
+ @property
+ def item(self):
+ own = self.owned[self.comm.rank]
+ if self._last != own:
+ self._item = self.items[own]
+ self._last = own
+ return self._item
+
+ def switch(self):
+ pass
diff -r d1f7280c3c79607e859605e02e5a296c2acfc4b6 -r 8e2150167715b63ab413670576ea18a08e9f72bd yt/visualization/plot_window.py
--- a/yt/visualization/plot_window.py
+++ b/yt/visualization/plot_window.py
@@ -60,6 +60,10 @@
axis_labels
from yt.utilities.math_utils import \
ortho_find
+from yt.utilities.parallel_tools.parallel_analysis_interface import \
+ GroupOwnership
+from yt.data_objects.time_series import \
+ TimeSeriesData
def invalidate_data(f):
@wraps(f)
@@ -254,6 +258,34 @@
self.set_center(center)
self._initfinished = True
+ def _initialize_dataset(self, ts):
+ if not isinstance(ts, TimeSeriesData):
+ if not iterable(ts): ts = [ts]
+ ts = TimeSeriesData(ts)
+ return ts
+
+ def __iter__(self):
+ for pf in self.ts:
+ mylog.warning("Switching to %s", pf)
+ self._switch_pf(pf)
+ yield self
+
+ def piter(self, *args, **kwargs):
+ for pf in self.ts.piter(*args, **kwargs):
+ self._switch_pf(pf)
+ yield self
+
+ def _switch_pf(self, new_pf):
+ ds = self.data_source
+ name = ds._type_name
+ kwargs = dict((n, getattr(ds, n)) for n in ds._con_args)
+ new_ds = getattr(new_pf.h, name)(**kwargs)
+ self.pf = new_pf
+ self.data_source = new_ds
+ self._data_valid = self._plot_valid = False
+ self._recreate_frb()
+ self._setup_plots()
+
def __getitem__(self, item):
return self.plots[item]
@@ -273,7 +305,6 @@
self._frb._get_data_source_fields()
else:
for key in old_fields: self._frb[key]
- self.pf = self._frb.pf
self._data_valid = True
def _setup_plots(self):
@@ -986,8 +1017,12 @@
>>> p.save('sliceplot')
"""
+ # tHis will handle time series data and controllers
+ ts = self._initialize_dataset(pf)
+ self.ts = ts
+ pf = self.pf = ts[0]
axis = fix_axis(axis)
- (bounds,center) = GetBoundsAndCenter(axis, center, width, pf)
+ (bounds, center) = GetBoundsAndCenter(axis, center, width, pf)
slc = pf.h.slice(axis, center[axis], fields=fields)
PWViewerMPL.__init__(self, slc, bounds, origin=origin)
self.set_axes_unit(axes_unit)
@@ -1068,8 +1103,11 @@
>>> p.save('sliceplot')
"""
+ ts = self._initialize_dataset(pf)
+ self.ts = ts
+ pf = self.pf = ts[0]
axis = fix_axis(axis)
- (bounds,center) = GetBoundsAndCenter(axis,center,width,pf)
+ (bounds, center) = GetBoundsAndCenter(axis, center, width, pf)
proj = pf.h.proj(axis,fields,weight_field=weight_field,max_level=max_level,center=center)
PWViewerMPL.__init__(self,proj,bounds,origin=origin)
self.set_axes_unit(axes_unit)
@@ -1491,4 +1529,3 @@
norm = norm, vmin = self.zmin,
vmax = self.zmax, cmap = cmap)
self.image.axes.ticklabel_format(scilimits=(-4,3))
-
Repository URL: https://bitbucket.org/yt_analysis/yt/
--
This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.
More information about the yt-svn
mailing list