[Yt-svn] yt-commit r1585 - branches/yt-1.6/yt/_amr_utils branches/yt-1.6/yt/lagos trunk/yt/_amr_utils trunk/yt/lagos
mturk at wrangler.dreamhost.com
mturk at wrangler.dreamhost.com
Thu Jan 21 20:35:15 PST 2010
Author: mturk
Date: Thu Jan 21 20:35:13 2010
New Revision: 1585
URL: http://yt.enzotools.org/changeset/1585
Log:
All the Python and non-generated Cython fixes for the unit tests (except for
nested extracted sets which still break) including corner detection in contours
and fixes for ParticleIO when convert functions are not explicitly supplied.
Modified:
branches/yt-1.6/yt/_amr_utils/ContourFinding.pyx
branches/yt-1.6/yt/lagos/BaseDataTypes.py
branches/yt-1.6/yt/lagos/ContourFinder.py
branches/yt-1.6/yt/lagos/HDF5LightReader.c
branches/yt-1.6/yt/lagos/ParticleIO.py
branches/yt-1.6/yt/lagos/UniversalFields.py
trunk/yt/_amr_utils/ContourFinding.pyx
trunk/yt/lagos/BaseDataTypes.py
trunk/yt/lagos/ContourFinder.py
trunk/yt/lagos/HDF5LightReader.c
trunk/yt/lagos/ParticleIO.py
trunk/yt/lagos/UniversalFields.py
Modified: branches/yt-1.6/yt/_amr_utils/ContourFinding.pyx
==============================================================================
--- branches/yt-1.6/yt/_amr_utils/ContourFinding.pyx (original)
+++ branches/yt-1.6/yt/_amr_utils/ContourFinding.pyx Thu Jan 21 20:35:13 2010
@@ -39,7 +39,7 @@
def construct_boundary_relationships(
np.ndarray[dtype=np.int64_t, ndim=3] contour_ids):
# We only look at the boundary and one cell in
- cdef int i, j, nx, ny, nz
+ cdef int i, j, nx, ny, nz, offset_i, offset_j, oi, oj
cdef np.int64_t c1, c2
tree = []
nx = contour_ids.shape[0]
@@ -48,33 +48,57 @@
# First x-pass
for i in range(ny):
for j in range(nz):
- c1 = contour_ids[0, i, j]
- c2 = contour_ids[1, i, j]
- if c1 > -1 and c2 > -1:
- tree.append((i64max(c1,c2), i64min(c1,c2)))
- c1 = contour_ids[nx-1, i, j]
- c2 = contour_ids[nx-2, i, j]
- if c1 > -1 and c2 > -1:
- tree.append((i64max(c1,c2), i64min(c1,c2)))
+ for offset_i in range(3):
+ oi = offset_i - 1
+ if i == 0 and oi == -1: continue
+ if i == ny - 1 and oj == 1: continue
+ for offset_j in range(3):
+ oj = offset_j - 1
+ if j == 0 and oj == -1: continue
+ if j == nz - 1 and oj == 1: continue
+ c1 = contour_ids[0, i, j]
+ c2 = contour_ids[1, i + oi, j + oj]
+ if c1 > -1 and c2 > -1:
+ tree.append((i64max(c1,c2), i64min(c1,c2)))
+ c1 = contour_ids[nx-1, i, j]
+ c2 = contour_ids[nx-2, i + oi, j + oj]
+ if c1 > -1 and c2 > -1:
+ tree.append((i64max(c1,c2), i64min(c1,c2)))
# Now y-pass
for i in range(nx):
for j in range(nz):
- c1 = contour_ids[i, 0, j]
- c2 = contour_ids[i, 1, j]
- if c1 > -1 and c2 > -1:
- tree.append((i64max(c1,c2), i64min(c1,c2)))
- c1 = contour_ids[i, ny-1, j]
- c2 = contour_ids[i, ny-2, j]
- if c1 > -1 and c2 > -1:
- tree.append((i64max(c1,c2), i64min(c1,c2)))
+ for offset_i in range(3):
+ oi = offset_i - 1
+ if i == 0 and oi == -1: continue
+ if i == nx - 1 and oj == 1: continue
+ for offset_j in range(3):
+ oj = offset_j - 1
+ if j == 0 and oj == -1: continue
+ if j == nz - 1 and oj == 1: continue
+ c1 = contour_ids[i, 0, j]
+ c2 = contour_ids[i + oi, 1, j + oj]
+ if c1 > -1 and c2 > -1:
+ tree.append((i64max(c1,c2), i64min(c1,c2)))
+ c1 = contour_ids[i, ny-1, j]
+ c2 = contour_ids[i + oi, ny-2, j + oj]
+ if c1 > -1 and c2 > -1:
+ tree.append((i64max(c1,c2), i64min(c1,c2)))
for i in range(nx):
for j in range(ny):
- c1 = contour_ids[i, j, 0]
- c2 = contour_ids[i, j, 1]
- if c1 > -1 and c2 > -1:
- tree.append((i64max(c1,c2), i64min(c1,c2)))
- c1 = contour_ids[i, j, nz-1]
- c2 = contour_ids[i, j, nz-2]
- if c1 > -1 and c2 > -1:
- tree.append((i64max(c1,c2), i64min(c1,c2)))
+ for offset_i in range(3):
+ oi = offset_i - 1
+ if i == 0 and oi == -1: continue
+ if i == nx - 1 and oj == 1: continue
+ for offset_j in range(3):
+ oj = offset_j - 1
+ if j == 0 and oj == -1: continue
+ if j == ny - 1 and oj == 1: continue
+ c1 = contour_ids[i, j, 0]
+ c2 = contour_ids[i + oi, j + oj, 1]
+ if c1 > -1 and c2 > -1:
+ tree.append((i64max(c1,c2), i64min(c1,c2)))
+ c1 = contour_ids[i, j, nz-1]
+ c2 = contour_ids[i + oi, j + oj, nz-2]
+ if c1 > -1 and c2 > -1:
+ tree.append((i64max(c1,c2), i64min(c1,c2)))
return tree
Modified: branches/yt-1.6/yt/lagos/BaseDataTypes.py
==============================================================================
--- branches/yt-1.6/yt/lagos/BaseDataTypes.py (original)
+++ branches/yt-1.6/yt/lagos/BaseDataTypes.py Thu Jan 21 20:35:13 2010
@@ -1762,6 +1762,7 @@
if cache: cached_fields = defaultdict(lambda: dict())
else: cached_fields = None
for level in range(num_levels):
+ self.clear_data()
contours[level] = {}
if cumulative:
mv = max_val
@@ -1871,6 +1872,11 @@
return True
return False
+ def _get_cut_mask(self, grid):
+ cm = na.zeros(grid.ActiveDimensions, dtype='bool')
+ cm[self._get_point_indices(grid, False)] = True
+ return cm
+
__empty_array = na.array([], dtype='bool')
def _get_point_indices(self, grid, use_child_mask=True):
# Yeah, if it's not true, we don't care.
Modified: branches/yt-1.6/yt/lagos/ContourFinder.py
==============================================================================
--- branches/yt-1.6/yt/lagos/ContourFinder.py (original)
+++ branches/yt-1.6/yt/lagos/ContourFinder.py Thu Jan 21 20:35:13 2010
@@ -262,11 +262,12 @@
total_contours = 0
tree = []
for gi,grid in enumerate(grids):
+ grid.clear_data()
pbar.update(gi+1)
cm = data_source._get_cut_mask(grid)
if cm is True: cm = na.ones(grid.ActiveDimensions, dtype='bool')
- local_ind = na.where( (min_val <= grid[field])
- & (grid[field] <= max_val) & cm )
+ local_ind = na.where( (grid[field] > min_val)
+ & (grid[field] < max_val) & cm )
if local_ind[0].size == 0: continue
kk = na.arange(cur_max_id, cur_max_id-local_ind[0].size, -1)
grid["tempContours"] = na.ones(grid.ActiveDimensions, dtype='int64') * -1
@@ -289,7 +290,7 @@
for gi,grid in enumerate(grids):
pbar.update(gi)
cg = grid.retrieve_ghost_zones(1, "tempContours", smoothed=False)
- set.update(set(cg._grids))
+ grid_set.update(set(cg._grids))
fd = cg["tempContours"].astype('int64')
tree += amr_utils.construct_boundary_relationships(fd)
pbar.finish()
@@ -310,7 +311,8 @@
del data_source.data["tempContours"] # Force a reload from the grids
data_source.get_data("tempContours", in_grids=True)
contour_ind = {}
- for i,contour_id in enumerate(na.unique(data_source["tempContours"])):
+ i = 0
+ for contour_id in na.unique(data_source["tempContours"]):
if contour_id == -1: continue
contour_ind[i] = na.where(data_source["tempContours"] == contour_id)
mylog.debug("Contour id %s has %s cells", i, contour_ind[i][0].size)
Modified: branches/yt-1.6/yt/lagos/HDF5LightReader.c
==============================================================================
--- branches/yt-1.6/yt/lagos/HDF5LightReader.c (original)
+++ branches/yt-1.6/yt/lagos/HDF5LightReader.c Thu Jan 21 20:35:13 2010
@@ -950,7 +950,7 @@
DW = (*(npy_float64*) PyArray_GETPTR1(domain_right_edge, i))
- (*(npy_float64*) PyArray_GETPTR1(domain_left_edge, i));
rv->period[i] = DW;
- fprintf(stderr, "Setting period equal to %lf\n", rv->period[i]);
+ //fprintf(stderr, "Setting period equal to %lf\n", rv->period[i]);
}
}
Modified: branches/yt-1.6/yt/lagos/ParticleIO.py
==============================================================================
--- branches/yt-1.6/yt/lagos/ParticleIO.py (original)
+++ branches/yt-1.6/yt/lagos/ParticleIO.py Thu Jan 21 20:35:13 2010
@@ -85,17 +85,17 @@
conv_factors = []
for field in fields:
f = self.pf.field_info[field]
+ to_add = f.get_dependencies(pf = self.pf).requested
+ to_add = list(na.unique(to_add))
+ if len(to_add) != 1: raise KeyError
+ fields_to_read += to_add
if f._particle_convert_function is None:
- fields_to_read.append(field)
- conv_factors.append(na.ones(len(grid_list), dtype='float64'))
+ func = f._convert_function
else:
- to_add = f.get_dependencies(pf = self.pf).requested
- to_add = list(na.unique(to_add))
- if len(to_add) != 1: raise KeyError
- fields_to_read += to_add
- conv_factors.append(
- na.fromiter((f.particle_convert(g) for g in grid_list),
- count=len(grid_list), dtype='float64'))
+ func = f.particle_convert
+ conv_factors.append(
+ na.fromiter((f.particle_convert(g) for g in grid_list),
+ count=len(grid_list), dtype='float64'))
conv_factors = na.array(conv_factors).transpose()
self.conv_factors = conv_factors
rv = self.pf.h.io._read_particles(
Modified: branches/yt-1.6/yt/lagos/UniversalFields.py
==============================================================================
--- branches/yt-1.6/yt/lagos/UniversalFields.py (original)
+++ branches/yt-1.6/yt/lagos/UniversalFields.py Thu Jan 21 20:35:13 2010
@@ -197,6 +197,10 @@
return particles
def _convertParticleMass(data):
return data.convert("Density")*(data.convert("cm")**3.0)
+def _IOLevelParticleMass(grid):
+ dd = dict(particle_mass = na.ones(1), CellVolumeCode=grid["CellVolumeCode"])
+ cf = (_ParticleMass(None, dd) * _convertParticleMass(grid))[0]
+ return cf
def _convertParticleMassMsun(data):
return data.convert("Density")*((data.convert("cm")**3.0)/1.989e33)
def _IOLevelParticleMassMsun(grid):
@@ -205,7 +209,8 @@
return cf
add_field("ParticleMass",
function=_ParticleMass, validators=[ValidateSpatial(0)],
- particle_type=True, convert_function=_convertParticleMass)
+ particle_type=True, convert_function=_convertParticleMass,
+ particle_convert_function=_IOLevelParticleMass)
add_field("ParticleMassMsun",
function=_ParticleMass, validators=[ValidateSpatial(0)],
particle_type=True, convert_function=_convertParticleMassMsun,
Modified: trunk/yt/_amr_utils/ContourFinding.pyx
==============================================================================
--- trunk/yt/_amr_utils/ContourFinding.pyx (original)
+++ trunk/yt/_amr_utils/ContourFinding.pyx Thu Jan 21 20:35:13 2010
@@ -39,7 +39,7 @@
def construct_boundary_relationships(
np.ndarray[dtype=np.int64_t, ndim=3] contour_ids):
# We only look at the boundary and one cell in
- cdef int i, j, nx, ny, nz
+ cdef int i, j, nx, ny, nz, offset_i, offset_j, oi, oj
cdef np.int64_t c1, c2
tree = []
nx = contour_ids.shape[0]
@@ -48,33 +48,57 @@
# First x-pass
for i in range(ny):
for j in range(nz):
- c1 = contour_ids[0, i, j]
- c2 = contour_ids[1, i, j]
- if c1 > -1 and c2 > -1:
- tree.append((i64max(c1,c2), i64min(c1,c2)))
- c1 = contour_ids[nx-1, i, j]
- c2 = contour_ids[nx-2, i, j]
- if c1 > -1 and c2 > -1:
- tree.append((i64max(c1,c2), i64min(c1,c2)))
+ for offset_i in range(3):
+ oi = offset_i - 1
+ if i == 0 and oi == -1: continue
+ if i == ny - 1 and oj == 1: continue
+ for offset_j in range(3):
+ oj = offset_j - 1
+ if j == 0 and oj == -1: continue
+ if j == nz - 1 and oj == 1: continue
+ c1 = contour_ids[0, i, j]
+ c2 = contour_ids[1, i + oi, j + oj]
+ if c1 > -1 and c2 > -1:
+ tree.append((i64max(c1,c2), i64min(c1,c2)))
+ c1 = contour_ids[nx-1, i, j]
+ c2 = contour_ids[nx-2, i + oi, j + oj]
+ if c1 > -1 and c2 > -1:
+ tree.append((i64max(c1,c2), i64min(c1,c2)))
# Now y-pass
for i in range(nx):
for j in range(nz):
- c1 = contour_ids[i, 0, j]
- c2 = contour_ids[i, 1, j]
- if c1 > -1 and c2 > -1:
- tree.append((i64max(c1,c2), i64min(c1,c2)))
- c1 = contour_ids[i, ny-1, j]
- c2 = contour_ids[i, ny-2, j]
- if c1 > -1 and c2 > -1:
- tree.append((i64max(c1,c2), i64min(c1,c2)))
+ for offset_i in range(3):
+ oi = offset_i - 1
+ if i == 0 and oi == -1: continue
+ if i == nx - 1 and oj == 1: continue
+ for offset_j in range(3):
+ oj = offset_j - 1
+ if j == 0 and oj == -1: continue
+ if j == nz - 1 and oj == 1: continue
+ c1 = contour_ids[i, 0, j]
+ c2 = contour_ids[i + oi, 1, j + oj]
+ if c1 > -1 and c2 > -1:
+ tree.append((i64max(c1,c2), i64min(c1,c2)))
+ c1 = contour_ids[i, ny-1, j]
+ c2 = contour_ids[i + oi, ny-2, j + oj]
+ if c1 > -1 and c2 > -1:
+ tree.append((i64max(c1,c2), i64min(c1,c2)))
for i in range(nx):
for j in range(ny):
- c1 = contour_ids[i, j, 0]
- c2 = contour_ids[i, j, 1]
- if c1 > -1 and c2 > -1:
- tree.append((i64max(c1,c2), i64min(c1,c2)))
- c1 = contour_ids[i, j, nz-1]
- c2 = contour_ids[i, j, nz-2]
- if c1 > -1 and c2 > -1:
- tree.append((i64max(c1,c2), i64min(c1,c2)))
+ for offset_i in range(3):
+ oi = offset_i - 1
+ if i == 0 and oi == -1: continue
+ if i == nx - 1 and oj == 1: continue
+ for offset_j in range(3):
+ oj = offset_j - 1
+ if j == 0 and oj == -1: continue
+ if j == ny - 1 and oj == 1: continue
+ c1 = contour_ids[i, j, 0]
+ c2 = contour_ids[i + oi, j + oj, 1]
+ if c1 > -1 and c2 > -1:
+ tree.append((i64max(c1,c2), i64min(c1,c2)))
+ c1 = contour_ids[i, j, nz-1]
+ c2 = contour_ids[i + oi, j + oj, nz-2]
+ if c1 > -1 and c2 > -1:
+ tree.append((i64max(c1,c2), i64min(c1,c2)))
return tree
Modified: trunk/yt/lagos/BaseDataTypes.py
==============================================================================
--- trunk/yt/lagos/BaseDataTypes.py (original)
+++ trunk/yt/lagos/BaseDataTypes.py Thu Jan 21 20:35:13 2010
@@ -1871,6 +1871,11 @@
return True
return False
+ def _get_cut_mask(self, grid):
+ cm = na.zeros(grid.ActiveDimensions, dtype='bool')
+ cm[self._get_point_indices(grid, False)] = True
+ return cm
+
__empty_array = na.array([], dtype='bool')
def _get_point_indices(self, grid, use_child_mask=True):
# Yeah, if it's not true, we don't care.
Modified: trunk/yt/lagos/ContourFinder.py
==============================================================================
--- trunk/yt/lagos/ContourFinder.py (original)
+++ trunk/yt/lagos/ContourFinder.py Thu Jan 21 20:35:13 2010
@@ -262,11 +262,12 @@
total_contours = 0
tree = []
for gi,grid in enumerate(grids):
+ grid.clear_data()
pbar.update(gi+1)
cm = data_source._get_cut_mask(grid)
if cm is True: cm = na.ones(grid.ActiveDimensions, dtype='bool')
- local_ind = na.where( (min_val <= grid[field])
- & (grid[field] <= max_val) & cm )
+ local_ind = na.where( (grid[field] > min_val)
+ & (grid[field] < max_val) & cm )
if local_ind[0].size == 0: continue
kk = na.arange(cur_max_id, cur_max_id-local_ind[0].size, -1)
grid["tempContours"] = na.ones(grid.ActiveDimensions, dtype='int64') * -1
@@ -289,7 +290,7 @@
for gi,grid in enumerate(grids):
pbar.update(gi)
cg = grid.retrieve_ghost_zones(1, "tempContours", smoothed=False)
- set.update(set(cg._grids))
+ grid_set.update(set(cg._grids))
fd = cg["tempContours"].astype('int64')
tree += amr_utils.construct_boundary_relationships(fd)
pbar.finish()
@@ -310,7 +311,8 @@
del data_source.data["tempContours"] # Force a reload from the grids
data_source.get_data("tempContours", in_grids=True)
contour_ind = {}
- for i,contour_id in enumerate(na.unique(data_source["tempContours"])):
+ i = 0
+ for contour_id in na.unique(data_source["tempContours"]):
if contour_id == -1: continue
contour_ind[i] = na.where(data_source["tempContours"] == contour_id)
mylog.debug("Contour id %s has %s cells", i, contour_ind[i][0].size)
Modified: trunk/yt/lagos/HDF5LightReader.c
==============================================================================
--- trunk/yt/lagos/HDF5LightReader.c (original)
+++ trunk/yt/lagos/HDF5LightReader.c Thu Jan 21 20:35:13 2010
@@ -950,7 +950,7 @@
DW = (*(npy_float64*) PyArray_GETPTR1(domain_right_edge, i))
- (*(npy_float64*) PyArray_GETPTR1(domain_left_edge, i));
rv->period[i] = DW;
- fprintf(stderr, "Setting period equal to %lf\n", rv->period[i]);
+ //fprintf(stderr, "Setting period equal to %lf\n", rv->period[i]);
}
}
Modified: trunk/yt/lagos/ParticleIO.py
==============================================================================
--- trunk/yt/lagos/ParticleIO.py (original)
+++ trunk/yt/lagos/ParticleIO.py Thu Jan 21 20:35:13 2010
@@ -85,17 +85,17 @@
conv_factors = []
for field in fields:
f = self.pf.field_info[field]
+ to_add = f.get_dependencies(pf = self.pf).requested
+ to_add = list(na.unique(to_add))
+ if len(to_add) != 1: raise KeyError
+ fields_to_read += to_add
if f._particle_convert_function is None:
- fields_to_read.append(field)
- conv_factors.append(na.ones(len(grid_list), dtype='float64'))
+ func = f._convert_function
else:
- to_add = f.get_dependencies(pf = self.pf).requested
- to_add = list(na.unique(to_add))
- if len(to_add) != 1: raise KeyError
- fields_to_read += to_add
- conv_factors.append(
- na.fromiter((f.particle_convert(g) for g in grid_list),
- count=len(grid_list), dtype='float64'))
+ func = f.particle_convert
+ conv_factors.append(
+ na.fromiter((f.particle_convert(g) for g in grid_list),
+ count=len(grid_list), dtype='float64'))
conv_factors = na.array(conv_factors).transpose()
self.conv_factors = conv_factors
rv = self.pf.h.io._read_particles(
Modified: trunk/yt/lagos/UniversalFields.py
==============================================================================
--- trunk/yt/lagos/UniversalFields.py (original)
+++ trunk/yt/lagos/UniversalFields.py Thu Jan 21 20:35:13 2010
@@ -197,6 +197,10 @@
return particles
def _convertParticleMass(data):
return data.convert("Density")*(data.convert("cm")**3.0)
+def _IOLevelParticleMass(grid):
+ dd = dict(particle_mass = na.ones(1), CellVolumeCode=grid["CellVolumeCode"])
+ cf = (_ParticleMass(None, dd) * _convertParticleMass(grid))[0]
+ return cf
def _convertParticleMassMsun(data):
return data.convert("Density")*((data.convert("cm")**3.0)/1.989e33)
def _IOLevelParticleMassMsun(grid):
@@ -205,7 +209,8 @@
return cf
add_field("ParticleMass",
function=_ParticleMass, validators=[ValidateSpatial(0)],
- particle_type=True, convert_function=_convertParticleMass)
+ particle_type=True, convert_function=_convertParticleMass,
+ particle_convert_function=_IOLevelParticleMass)
add_field("ParticleMassMsun",
function=_ParticleMass, validators=[ValidateSpatial(0)],
particle_type=True, convert_function=_convertParticleMassMsun,
More information about the yt-svn
mailing list