[yt-svn] commit/yt-3.0: 2 new changesets
Bitbucket
commits-noreply at bitbucket.org
Thu Aug 9 15:11:39 PDT 2012
2 new commits in yt-3.0:
https://bitbucket.org/yt_analysis/yt-3.0/changeset/76af5fc89b76/
changeset: 76af5fc89b76
branch: yt-3.0
user: MatthewTurk
date: 2012-08-09 23:39:50
summary: Adding an active particle count array
affected #: 2 files
diff -r 724a9fbc17aacebb698578044e17e07faee2c884 -r 76af5fc89b76ea54a9a19519c2c23e620becfe6e yt/frontends/enzo/data_structures.py
--- a/yt/frontends/enzo/data_structures.py
+++ b/yt/frontends/enzo/data_structures.py
@@ -294,6 +294,11 @@
si, ei, LE, RE, fn, np = [], [], [], [], [], []
all = [si, ei, LE, RE, fn]
pbar = get_pbar("Parsing Hierarchy", self.num_grids)
+ if self.parameter_file.parameters["VersionNumber"] > 2.0:
+ active_particles = True
+ nap = []
+ else:
+ active_particles = False
for grid_id in xrange(self.num_grids):
pbar.update(grid_id)
# We will unroll this list
@@ -305,6 +310,9 @@
fn.append(["-1"])
if nb > 0: fn[-1] = _next_token_line("BaryonFileName", f)
np.append(int(_next_token_line("NumberOfParticles", f)[0]))
+ if active_particles:
+ ta = int(_next_token_line( "NumberOfActiveParticles", f)[0])
+ nap.append(ta)
if nb == 0 and np[-1] > 0: fn[-1] = _next_token_line("ParticleFileName", f)
for line in f:
if len(line) < 2: break
@@ -320,13 +328,20 @@
self._store_binary_hierarchy()
t2 = time.time()
- def _fill_arrays(self, ei, si, LE, RE, np):
+ def _initialize_grid_arrays(self):
+ super(EnzoHierarchy, self)._initialize_grid_arrays()
+ self.grid_active_particle_count = na.zeros((self.num_grids,1), 'int32')
+
+ def _fill_arrays(self, ei, si, LE, RE, np, nap = None):
self.grid_dimensions.flat[:] = ei
self.grid_dimensions -= na.array(si, self.float_type)
self.grid_dimensions += 1
self.grid_left_edge.flat[:] = LE
self.grid_right_edge.flat[:] = RE
self.grid_particle_count.flat[:] = np
+ if nap is not None:
+ self.grid_active_particle_count.flat[:] = nap
+
def __pointer_handler(self, m):
sgi = int(m[2])-1
diff -r 724a9fbc17aacebb698578044e17e07faee2c884 -r 76af5fc89b76ea54a9a19519c2c23e620becfe6e yt/frontends/enzo/io.py
--- a/yt/frontends/enzo/io.py
+++ b/yt/frontends/enzo/io.py
@@ -60,10 +60,9 @@
chunks = list(chunks)
# Now we have to do something unpleasant
dobj = chunks[0].dobj
- if "particle_type" not in dobj.pf.h.field_list and \
- any((ftype != "all" for ftype, fname in fields)):
- raise NotImplementedError("Sorry, but you'll have to manually " +
- "discriminate without a particle_type field")
+ if any((ftype != "all" for ftype, fname in fields)):
+ return self._read_particle_selection_by_type(
+ chunks, selector, fields)
mylog.debug("First pass: counting particles.")
xn, yn, zn = ("particle_position_%s" % ax for ax in 'xyz')
size = 0
@@ -93,7 +92,7 @@
for ax in 'xyz')
mask = g.select_particles(selector, x, y, z)
if mask is None: continue
- for field in fields:
+ for field in set(fields):
ftype, fname = field
gdata = data[g.id].pop(fname)[mask]
rv[field][ind:ind+gdata.size] = gdata
https://bitbucket.org/yt_analysis/yt-3.0/changeset/3b093c03ed2b/
changeset: 3b093c03ed2b
branch: yt-3.0
user: MatthewTurk
date: 2012-08-10 00:11:23
summary: Adding ActiveParticle parsing and initial field detection to Enzo reader.
Fields now detect properly but still will not read.
affected #: 1 file
diff -r 76af5fc89b76ea54a9a19519c2c23e620becfe6e -r 3b093c03ed2b4290bde5fdf8129b38c44960c2f4 yt/frontends/enzo/data_structures.py
--- a/yt/frontends/enzo/data_structures.py
+++ b/yt/frontends/enzo/data_structures.py
@@ -299,6 +299,7 @@
nap = []
else:
active_particles = False
+ nap = None
for grid_id in xrange(self.num_grids):
pbar.update(grid_id)
# We will unroll this list
@@ -320,7 +321,7 @@
vv = patt.findall(line)[0]
self.__pointer_handler(vv)
pbar.finish()
- self._fill_arrays(ei, si, LE, RE, np)
+ self._fill_arrays(ei, si, LE, RE, np, nap)
temp_grids = na.empty(self.num_grids, dtype='object')
temp_grids[:] = self.grids
self.grids = temp_grids
@@ -332,7 +333,7 @@
super(EnzoHierarchy, self)._initialize_grid_arrays()
self.grid_active_particle_count = na.zeros((self.num_grids,1), 'int32')
- def _fill_arrays(self, ei, si, LE, RE, np, nap = None):
+ def _fill_arrays(self, ei, si, LE, RE, np, nap):
self.grid_dimensions.flat[:] = ei
self.grid_dimensions -= na.array(si, self.float_type)
self.grid_dimensions += 1
@@ -342,7 +343,6 @@
if nap is not None:
self.grid_active_particle_count.flat[:] = nap
-
def __pointer_handler(self, m):
sgi = int(m[2])-1
if sgi == -1: return # if it's 0, then we're done with that lineage
@@ -464,10 +464,32 @@
del self.filenames # No longer needed.
self.max_level = self.grid_levels.max()
+ def _detect_active_particle_fields(self):
+ gs = self.grids[self.grid_active_particle_count.flat > 0]
+ grids = sorted((g for g in gs), key = lambda a: a.filename)
+ handle = last = None
+ ap_list = self.parameter_file.parameters["AppendActiveParticleType"]
+ _fields = dict((ap, []) for ap in ap_list)
+ fields = []
+ for g in grids:
+ # We inspect every grid, for now, until we have a list of
+ # attributes in a defined location.
+ if last != g.filename:
+ if handle is not None: handle.close()
+ handle = h5py.File(g.filename)
+ node = handle["/Grid%08i/ActiveParticles/" % g.id]
+ for ptype in (str(p) for p in node):
+ for field in (str(f) for f in node[ptype]):
+ _fields[ptype].append(field)
+ fields += [(ptype, field) for field in _fields.pop(ptype)]
+ if len(_fields) == 0: break
+ if handle is not None: handle.close()
+ return set(fields)
+
def _detect_fields(self):
self.field_list = []
# Do this only on the root processor to save disk work.
- if self.comm.rank == 0 or self.comm.rank == None:
+ if self.comm.rank in (0, None):
field_list = self.get_data("/", "DataFields")
if field_list is None:
mylog.info("Gathering a field list (this may take a moment.)")
@@ -482,6 +504,9 @@
continue
mylog.debug("Grid %s has: %s", grid.id, gf)
field_list = field_list.union(gf)
+ if "AppendActiveParticleType" in self.parameter_file.parameters:
+ ap_fields = self._detect_active_particle_fields()
+ field_list = field_list.union(ap_fields)
else:
field_list = None
field_list = self.comm.mpi_bcast(field_list)
@@ -842,7 +867,12 @@
vals = pcast(vals[0])
else:
vals = na.array([pcast(i) for i in vals if i != "-99999"])
- self.parameters[param] = vals
+ if param.startswith("Append") and param not in self.parameters:
+ self.parameters[param] = []
+ if param.startswith("Append"):
+ self.parameters[param].append(vals)
+ else:
+ self.parameters[param] = vals
for p, v in self._parameter_override.items():
self.parameters[p] = v
for p, v in self._conversion_override.items():
Repository URL: https://bitbucket.org/yt_analysis/yt-3.0/
--
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