[Yt-svn] commit/yt: 6 new changesets
Bitbucket
commits-noreply at bitbucket.org
Sun Mar 20 17:38:08 PDT 2011
6 new changesets in yt:
http://bitbucket.org/yt_analysis/yt/changeset/a0528a05b1c3/
changeset: r3855:a0528a05b1c3
branch: yt
user: samskillman
date: 2011-02-26 00:22:40
summary: Adding direction keyword to the streamline integrator. Will now
integrate backwards from a set of final locations.
affected #: 1 file (222 bytes)
--- a/yt/visualization/streamlines.py Fri Feb 25 10:18:52 2011 -0700
+++ b/yt/visualization/streamlines.py Fri Feb 25 16:22:40 2011 -0700
@@ -58,6 +58,9 @@
length : float, optional
Optionally specify the length of integration.
Default: na.max(self.pf.domain_right_edge-self.pf.domain_left_edge)
+ direction : real, optional
+ Specifies the direction of integration. The magnitude of this
+ value has no effect, only the sign.
Examples
--------
@@ -84,13 +87,14 @@
>>> pl.savefig('streamlines.png')
"""
def __init__(self, pf, positions, xfield, yfield, zfield, volume=None,
- dx=None, length=None):
+ dx=None, length=None, direction=1):
self.pf = pf
self.start_positions = positions
self.N = self.start_positions.shape[0]
self.xfield = xfield
self.yfield = yfield
self.zfield = zfield
+ self.direction = na.sign(direction)
if volume is None:
volume = AMRKDTree(self.pf, fields=[self.xfield,self.yfield,self.zfield],
log_fields=[False,False,False], merge_trees=True)
@@ -129,7 +133,7 @@
self.volume.get_brick_data(node)
brick = node.brick
stream[-step+1] = stream[-step]
- brick.integrate_streamline(stream[-step+1], self.dx)
+ brick.integrate_streamline(stream[-step+1], self.direction*self.dx)
if na.any(stream[-step+1,:] <= self.pf.domain_left_edge) | \
na.any(stream[-step+1,:] >= self.pf.domain_right_edge):
return 0
@@ -141,6 +145,6 @@
return step
-
+
http://bitbucket.org/yt_analysis/yt/changeset/364b9b6a8489/
changeset: r3856:364b9b6a8489
branch: yt
user: samskillman
date: 2011-03-01 17:13:55
summary: Adding a clean function that "cuts" of the ends where all the values
are zero (streamline went out of the box). Also make sure the positions are an array.
affected #: 1 file (231 bytes)
--- a/yt/visualization/streamlines.py Fri Feb 25 16:22:40 2011 -0700
+++ b/yt/visualization/streamlines.py Tue Mar 01 09:13:55 2011 -0700
@@ -89,7 +89,7 @@
def __init__(self, pf, positions, xfield, yfield, zfield, volume=None,
dx=None, length=None, direction=1):
self.pf = pf
- self.start_positions = positions
+ self.start_positions = na.array(positions)
self.N = self.start_positions.shape[0]
self.xfield = xfield
self.yfield = yfield
@@ -144,7 +144,11 @@
step -= 1
return step
-
+ def clean_streamlines(self):
+ temp = na.empty(self.N, dtype='object')
+ for i,stream in enumerate(self.streamlines):
+ temp[i] = stream[na.all(stream != 0.0, axis=1)]
+ self.streamlines = temp
http://bitbucket.org/yt_analysis/yt/changeset/bb4f52a2c472/
changeset: r3857:bb4f52a2c472
branch: yt
user: samskillman
date: 2011-03-20 15:33:41
summary: Intermediate commit of the streamline AMR1DData.
affected #: 2 files (3.2 KB)
--- a/yt/data_objects/data_containers.py Tue Mar 01 09:13:55 2011 -0700
+++ b/yt/data_objects/data_containers.py Sun Mar 20 10:33:41 2011 -0400
@@ -633,6 +633,81 @@
self._ts[grid.id] = na.abs(ts)
return mask
+class AMRStreamlineBase(AMR1DData):
+ _type_name = "streamline"
+ _con_args = ('positions')
+ sort_by = 't'
+ def __init__(self, positions, fields=None, pf=None, **kwargs):
+ """
+ This is an arbitrarily-aligned ray cast through the entire domain, at a
+ specific coordinate.
+
+ This object is typically accessed through the `ray` object that hangs
+ off of hierarchy objects. The resulting arrays have their
+ dimensionality reduced to one, and an ordered list of points at an
+ (x,y) tuple along `axis` are available, as is the `t` field, which
+ corresponds to a unitless measurement along the ray from start to
+ end.
+
+ Parameters
+ ----------
+ start_point : array-like set of 3 floats
+ The place where the ray starts.
+ end_point : array-like set of 3 floats
+ The place where the ray ends.
+ fields : list of strings, optional
+ If you want the object to pre-retrieve a set of fields, supply them
+ here. This is not necessary.
+ kwargs : dict of items
+ Any additional values are passed as field parameters that can be
+ accessed by generated fields.
+
+ Examples
+ --------
+
+ >>> pf = load("RedshiftOutput0005")
+ >>> ray = pf.h._ray((0.2, 0.74), (0.4, 0.91))
+ >>> print ray["Density"], ray["t"]
+ """
+ AMR1DData.__init__(self, pf, fields, **kwargs)
+ self.positions = positions
+ self.dts = na.empty_like(positions)
+ self.dts[:-1] = na.sqrt(na.sum((self.positions[1:]-
+ self.positions[:-1])**2,axis=0))
+ self.dts[-1] = self.dts[-1]
+ self.ts = na.add.accumulate(dts)
+ self._set_center(self.positions[0])
+ self.set_field_parameter('center', self.start_point)
+ self._dts, self._ts = {}, {}
+ #self._refresh_data()
+
+ def _get_data_from_grid(self, grid, field):
+ mask = na.logical_and(self._get_cut_mask(grid),
+ grid.child_mask)
+ if field == 'dts': return self._dts[grid.id][mask]
+ if field == 't': return self._ts[grid.id][mask]
+ return grid[field][mask]
+
+ @cache_mask
+ def _get_cut_mask(self, grid):
+ mask = na.zeros(grid.ActiveDimensions, dtype='int')
+ points_in_grid = na.all(self.positions >= grid.LeftEdge, axis=0) & \
+ na.all(self.positions < grid.LeftEdge, axis=0)
+ self._dts[grid.id] = self.dts[points_in_grid]
+ self._ts[grid.id] = self.positions[points_in_grid]
+ for i, pos in enumerate(self.positions[points_in_grid]):
+ cx = (pos[0]-grid.LeftEdge[0])/grid.dds[0]
+ cy = (pos[1]-grid.LeftEdge[1])/grid.dds[1]
+ cz = (pos[2]-grid.LeftEdge[2])/grid.dds[2]
+ if mask[cx,cy,cz]:
+ continue
+ mask[cx,cy,cz] = 1
+ dts[cx,cy,cz] = self.dts[i]
+ ts[cx,cy,cz] = self.ts[i]
+ self._dts = dts
+ self._ts = ts
+ return mask
+
class AMR2DData(AMRData, GridPropertiesMixin, ParallelAnalysisInterface):
_key_fields = ['px','py','pdx','pdy']
"""
--- a/yt/visualization/streamlines.py Tue Mar 01 09:13:55 2011 -0700
+++ b/yt/visualization/streamlines.py Sun Mar 20 10:33:41 2011 -0400
@@ -28,7 +28,8 @@
from yt.utilities.parallel_tools.parallel_analysis_interface import \
ParallelAnalysisInterface, parallel_passthrough
from yt.utilities.amr_kdtree.api import AMRKDTree
-
+from yt.data_objects.data_containers import AMRStreamlineBase
+
class Streamlines(ParallelAnalysisInterface):
r"""A collection of streamlines that flow through the volume
@@ -107,7 +108,7 @@
self.length = length
self.steps = int(length/dx)
self.streamlines = na.zeros((self.N,self.steps,3), dtype='float64')
-
+
def integrate_through_volume(self):
nprocs = self._mpi_get_size()
my_rank = self._mpi_get_rank()
@@ -123,12 +124,13 @@
pbar.finish()
self._finalize_parallel(None)
-
+
@parallel_passthrough
def _finalize_parallel(self,data):
self.streamlines = self._mpi_allsum(self.streamlines)
- def _integrate_through_brick(self, node, stream, step, periodic=False):
+ def _integrate_through_brick(self, node, stream, step,
+ periodic=False):
while (step > 1):
self.volume.get_brick_data(node)
brick = node.brick
@@ -149,6 +151,11 @@
for i,stream in enumerate(self.streamlines):
temp[i] = stream[na.all(stream != 0.0, axis=1)]
self.streamlines = temp
+
+ def path(self, streamline_id):
+ return AMRStreamlineBase(self.streamlines[streamline_id])
+
+
http://bitbucket.org/yt_analysis/yt/changeset/7d14d4f54808/
changeset: r3858:7d14d4f54808
branch: yt
user: samskillman
date: 2011-03-21 01:09:28
summary: Merging in changes to streamlines AMR1DData object. See Streamlines.path docs for details.
affected #: 2 files (5.2 KB)
--- a/yt/data_objects/data_containers.py Fri Mar 18 17:23:40 2011 -0700
+++ b/yt/data_objects/data_containers.py Sun Mar 20 20:09:28 2011 -0400
@@ -59,6 +59,7 @@
NeedsDataField, \
NeedsProperty, \
NeedsParameter
+import pdb
def restore_grid_state(func):
"""
@@ -639,6 +640,97 @@
self._ts[grid.id] = na.abs(ts)
return mask
+class AMRStreamlineBase(AMR1DData):
+ _type_name = "streamline"
+ _con_args = ('positions')
+ sort_by = 't'
+ def __init__(self, positions, fields=None, pf=None, **kwargs):
+ """
+ This is a streamline, which is a set of points defined as
+ being parallel to some vector field.
+
+ This object is typically accessed through the Streamlines.path
+ function. The resulting arrays have their dimensionality
+ reduced to one, and an ordered list of points at an (x,y)
+ tuple along `axis` are available, as is the `t` field, which
+ corresponds to a unitless measurement along the ray from start
+ to end.
+
+ Parameters
+ ----------
+ positions : array-like
+ List of streamline positions
+ fields : list of strings, optional
+ If you want the object to pre-retrieve a set of fields, supply them
+ here. This is not necessary.
+ pf : Parameter file object
+ Passed in to access the hierarchy
+ kwargs : dict of items
+ Any additional values are passed as field parameters that can be
+ accessed by generated fields.
+
+ Examples
+ --------
+
+ >>> from yt.visualization.api import Streamlines
+ >>> streamlines = Streamlines(pf, [0.5]*3)
+ >>> streamlines.integrate_through_volume()
+ >>> stream = streamlines.path(0)
+ >>> matplotlib.pylab.semilogy(stream['t'], stream['Density'], '-x')
+
+ """
+ AMR1DData.__init__(self, pf, fields, **kwargs)
+ self.positions = positions
+ self.dts = na.empty_like(positions[:,0])
+ self.dts[:-1] = na.sqrt(na.sum((self.positions[1:]-
+ self.positions[:-1])**2,axis=1))
+ self.dts[-1] = self.dts[-1]
+ self.ts = na.add.accumulate(self.dts)
+ self._set_center(self.positions[0])
+ self.set_field_parameter('center', self.positions[0])
+ self._dts, self._ts = {}, {}
+ #self._refresh_data()
+
+ def _get_list_of_grids(self):
+ # Get the value of the line at each LeftEdge and RightEdge
+ LE = self.pf.h.grid_left_edge
+ RE = self.pf.h.grid_right_edge
+ # Check left faces first
+ min_streampoint = na.min(self.positions, axis=0)
+ max_streampoint = na.max(self.positions, axis=0)
+ p = na.all((min_streampoint <= RE) & (max_streampoint > LE), axis=1)
+ self._grids = self.hierarchy.grids[p]
+
+ def _get_data_from_grid(self, grid, field):
+ mask = na.logical_and(self._get_cut_mask(grid),
+ grid.child_mask)
+ if field == 'dts': return self._dts[grid.id][mask]
+ if field == 't': return self._ts[grid.id][mask]
+ return grid[field][mask]
+
+ @cache_mask
+ def _get_cut_mask(self, grid):
+ mask = na.zeros(grid.ActiveDimensions, dtype='int')
+ dts = na.zeros(grid.ActiveDimensions, dtype='float64')
+ ts = na.zeros(grid.ActiveDimensions, dtype='float64')
+ #pdb.set_trace()
+ points_in_grid = na.all(self.positions > grid.LeftEdge, axis=1) & \
+ na.all(self.positions <= grid.RightEdge, axis=1)
+ pids = na.where(points_in_grid)[0]
+ for i, pos in zip(pids, self.positions[points_in_grid]):
+ if not points_in_grid[i]: continue
+ ci = ((pos - grid.LeftEdge)/grid.dds).astype('int')
+ for j in range(3):
+ ci[j] = min(ci[j], grid.ActiveDimensions[j]-1)
+ if mask[ci[0], ci[1], ci[2]]:
+ continue
+ mask[ci[0], ci[1], ci[2]] = 1
+ dts[ci[0], ci[1], ci[2]] = self.dts[i]
+ ts[ci[0], ci[1], ci[2]] = self.ts[i]
+ self._dts[grid.id] = dts
+ self._ts[grid.id] = ts
+ return mask
+
class AMR2DData(AMRData, GridPropertiesMixin, ParallelAnalysisInterface):
_key_fields = ['px','py','pdx','pdy']
"""
--- a/yt/visualization/streamlines.py Fri Mar 18 17:23:40 2011 -0700
+++ b/yt/visualization/streamlines.py Sun Mar 20 20:09:28 2011 -0400
@@ -28,7 +28,8 @@
from yt.utilities.parallel_tools.parallel_analysis_interface import \
ParallelAnalysisInterface, parallel_passthrough
from yt.utilities.amr_kdtree.api import AMRKDTree
-
+from yt.data_objects.data_containers import AMRStreamlineBase
+
class Streamlines(ParallelAnalysisInterface):
r"""A collection of streamlines that flow through the volume
@@ -41,12 +42,15 @@
This is the parameter file to streamline
pos : array_like
An array of initial starting positions of the streamlines.
- xfield: field
+ xfield: field, optional
The x component of the vector field to be streamlined.
- yfield: field
+ Default:'x-velocity'
+ yfield: field, optional
The y component of the vector field to be streamlined.
- zfield: field
+ Default:'y-velocity'
+ zfield: field, optional
The z component of the vector field to be streamlined.
+ Default:'z-velocity'
volume : `yt.extensions.volume_rendering.HomogenizedVolume`, optional
The volume to be streamlined. Can be specified for
finer-grained control, but otherwise will be automatically
@@ -58,6 +62,9 @@
length : float, optional
Optionally specify the length of integration.
Default: na.max(self.pf.domain_right_edge-self.pf.domain_left_edge)
+ direction : real, optional
+ Specifies the direction of integration. The magnitude of this
+ value has no effect, only the sign.
Examples
--------
@@ -83,14 +90,16 @@
>>> ax.plot3D(stream[:,0], stream[:,1], stream[:,2], alpha=0.1)
>>> pl.savefig('streamlines.png')
"""
- def __init__(self, pf, positions, xfield, yfield, zfield, volume=None,
- dx=None, length=None):
+ def __init__(self, pf, positions, xfield='x-velocity', yfield='x-velocity',
+ zfield='x-velocity', volume=None,
+ dx=None, length=None, direction=1):
self.pf = pf
- self.start_positions = positions
+ self.start_positions = na.array(positions)
self.N = self.start_positions.shape[0]
self.xfield = xfield
self.yfield = yfield
self.zfield = zfield
+ self.direction = na.sign(direction)
if volume is None:
volume = AMRKDTree(self.pf, fields=[self.xfield,self.yfield,self.zfield],
log_fields=[False,False,False], merge_trees=True)
@@ -103,7 +112,7 @@
self.length = length
self.steps = int(length/dx)
self.streamlines = na.zeros((self.N,self.steps,3), dtype='float64')
-
+
def integrate_through_volume(self):
nprocs = self._mpi_get_size()
my_rank = self._mpi_get_rank()
@@ -119,17 +128,18 @@
pbar.finish()
self._finalize_parallel(None)
-
+
@parallel_passthrough
def _finalize_parallel(self,data):
self.streamlines = self._mpi_allsum(self.streamlines)
- def _integrate_through_brick(self, node, stream, step, periodic=False):
+ def _integrate_through_brick(self, node, stream, step,
+ periodic=False):
while (step > 1):
self.volume.get_brick_data(node)
brick = node.brick
stream[-step+1] = stream[-step]
- brick.integrate_streamline(stream[-step+1], self.dx)
+ brick.integrate_streamline(stream[-step+1], self.direction*self.dx)
if na.any(stream[-step+1,:] <= self.pf.domain_left_edge) | \
na.any(stream[-step+1,:] >= self.pf.domain_right_edge):
return 0
@@ -140,7 +150,35 @@
step -= 1
return step
-
+ def clean_streamlines(self):
+ temp = na.empty(self.N, dtype='object')
+ for i,stream in enumerate(self.streamlines):
+ temp[i] = stream[na.all(stream != 0.0, axis=1)]
+ self.streamlines = temp
+ def path(self, streamline_id):
+ """
+ Returns an AMR1DData object defined by a streamline.
+ Parameters
+ ----------
+ streamline_id : int
+ This defines which streamline from the Streamlines object
+ that will define the AMR1DData object.
+
+ Returns
+ -------
+ An AMRStreamlineBase AMR1DData object
+
+ Examples
+ --------
+
+ >>> from yt.visualization.api import Streamlines
+ >>> streamlines = Streamlines(pf, [0.5]*3)
+ >>> streamlines.integrate_through_volume()
+ >>> stream = streamlines.path(0)
+ >>> matplotlib.pylab.semilogy(stream['t'], stream['Density'], '-x')
+ """
+ return AMRStreamlineBase(self.streamlines[streamline_id], pf=self.pf)
+
http://bitbucket.org/yt_analysis/yt/changeset/b4605fe73b00/
changeset: r3859:b4605fe73b00
branch: yt
user: samskillman
date: 2011-03-21 01:18:51
summary: Remove pdb import.
affected #: 1 file (11 bytes)
--- a/yt/data_objects/data_containers.py Sun Mar 20 20:09:28 2011 -0400
+++ b/yt/data_objects/data_containers.py Sun Mar 20 20:18:51 2011 -0400
@@ -59,7 +59,6 @@
NeedsDataField, \
NeedsProperty, \
NeedsParameter
-import pdb
def restore_grid_state(func):
"""
http://bitbucket.org/yt_analysis/yt/changeset/bb3a4bfdbe2e/
changeset: r3860:bb3a4bfdbe2e
branch: yt
user: samskillman
date: 2011-03-21 01:35:55
summary: Merging.
affected #: 2 files (0 bytes)
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