[yt-svn] commit/yt: ChrisMalone: Merged in atmyers/yt (pull request #1230)
commits-noreply at bitbucket.org
commits-noreply at bitbucket.org
Thu Oct 2 16:16:28 PDT 2014
1 new commit in yt:
https://bitbucket.org/yt_analysis/yt/commits/bcb2b0862ef0/
Changeset: bcb2b0862ef0
Branch: yt
User: ChrisMalone
Date: 2014-10-02 23:16:20+00:00
Summary: Merged in atmyers/yt (pull request #1230)
Orion particle speedup
Affected #: 4 files
diff -r c0d6e31c64f3cd8029b911c36d2d08185434f713 -r bcb2b0862ef066031bee060107e06de5eda235ad yt/frontends/boxlib/data_structures.py
--- a/yt/frontends/boxlib/data_structures.py
+++ b/yt/frontends/boxlib/data_structures.py
@@ -683,7 +683,7 @@
with open(fn, 'r') as f:
lines = f.readlines()
self.num_stars = int(lines[0].strip()[0])
- for line in lines[1:]:
+ for num, line in enumerate(lines[1:]):
particle_position_x = float(line.split(' ')[1])
particle_position_y = float(line.split(' ')[2])
particle_position_z = float(line.split(' ')[3])
@@ -704,6 +704,12 @@
ind = np.where(self.grids == grid)[0][0]
self.grid_particle_count[ind] += 1
self.grids[ind].NumberOfParticles += 1
+
+ # store the position in the particle file for fast access.
+ try:
+ self.grids[ind]._particle_line_numbers.append(num + 1)
+ except AttributeError:
+ self.grids[ind]._particle_line_numbers = [num + 1]
return True
diff -r c0d6e31c64f3cd8029b911c36d2d08185434f713 -r bcb2b0862ef066031bee060107e06de5eda235ad yt/frontends/boxlib/io.py
--- a/yt/frontends/boxlib/io.py
+++ b/yt/frontends/boxlib/io.py
@@ -125,30 +125,36 @@
rv[ftype, fname] = np.concatenate((data, rv[ftype, fname]))
return rv
- def _read_particles(self, grid, field):
+ def _read_particles(self, grid, field):
"""
parses the Orion Star Particle text files
"""
- fn = self.particle_filename
+ particles = []
+
+ if grid.NumberOfParticles == 0:
+ return np.array(particles)
def read(line, field):
entry = line.strip().split(' ')[self.particle_field_index[field]]
return np.float(entry)
- with open(fn, 'r') as f:
- lines = f.readlines()
- particles = []
- for line in lines[1:]:
- if grid.NumberOfParticles > 0:
- coord = read(line, "particle_position_x"), \
- read(line, "particle_position_y"), \
- read(line, "particle_position_z")
- if ( (grid.LeftEdge <= coord).all() and
- (coord <= grid.RightEdge).all() ):
- particles.append(read(line, field))
- return np.array(particles)
+ try:
+ lines = self._cached_lines
+ for num in grid._particle_line_numbers:
+ line = lines[num]
+ particles.append(read(line, field))
+ return np.array(particles)
+ except AttributeError:
+ fn = self.particle_filename
+ with open(fn, 'r') as f:
+ lines = f.readlines()
+ self._cached_lines = lines
+ for num in grid._particle_line_numbers:
+ line = lines[num]
+ particles.append(read(line, field))
+ return np.array(particles)
class IOHandlerCastro(IOHandlerBoxlib):
diff -r c0d6e31c64f3cd8029b911c36d2d08185434f713 -r bcb2b0862ef066031bee060107e06de5eda235ad yt/frontends/chombo/data_structures.py
--- a/yt/frontends/chombo/data_structures.py
+++ b/yt/frontends/chombo/data_structures.py
@@ -540,14 +540,14 @@
with open(self.particle_filename, 'r') as f:
lines = f.readlines()
self.num_stars = int(lines[0].strip().split(' ')[0])
- for line in lines[1:]:
+ for num, line in enumerate(lines[1:]):
particle_position_x = float(line.split(' ')[1])
particle_position_y = float(line.split(' ')[2])
particle_position_z = float(line.split(' ')[3])
coord = [particle_position_x, particle_position_y, particle_position_z]
# for each particle, determine which grids contain it
# copied from object_finding_mixin.py
- mask=np.ones(self.num_grids)
+ mask = np.ones(self.num_grids)
for i in xrange(len(coord)):
np.choose(np.greater(self.grid_left_edge.d[:,i],coord[i]), (mask,0), mask)
np.choose(np.greater(self.grid_right_edge.d[:,i],coord[i]), (0,mask), mask)
@@ -562,6 +562,12 @@
self.grid_particle_count[ind] += 1
self.grids[ind].NumberOfParticles += 1
+ # store the position in the *.sink file for fast access.
+ try:
+ self.grids[ind]._particle_line_numbers.append(num + 1)
+ except AttributeError:
+ self.grids[ind]._particle_line_numbers = [num + 1]
+
class Orion2Dataset(ChomboDataset):
diff -r c0d6e31c64f3cd8029b911c36d2d08185434f713 -r bcb2b0862ef066031bee060107e06de5eda235ad yt/frontends/chombo/io.py
--- a/yt/frontends/chombo/io.py
+++ b/yt/frontends/chombo/io.py
@@ -69,11 +69,11 @@
self._particle_field_index = field_dict
return self._particle_field_index
- def _read_field_names(self,grid):
+ def _read_field_names(self, grid):
ncomp = int(self._handle.attrs['num_components'])
fns = [c[1] for c in f.attrs.items()[-ncomp-1:-1]]
- def _read_data(self,grid,field):
+ def _read_data(self, grid, field):
lstring = 'level_%i' % grid.Level
lev = self._handle[lstring]
dims = grid.ActiveDimensions
@@ -289,20 +289,27 @@
"""
+ particles = []
+
+ if grid.NumberOfParticles == 0:
+ return np.array(particles)
+
def read(line, field):
entry = line.strip().split(' ')[self.particle_field_index[field]]
return np.float(entry)
- fn = grid.ds.fullplotdir[:-4] + "sink"
- with open(fn, 'r') as f:
- lines = f.readlines()
- particles = []
- for line in lines[1:]:
- if grid.NumberOfParticles > 0:
- coord = read(line, "particle_position_x"), \
- read(line, "particle_position_y"), \
- read(line, "particle_position_z")
- if ((grid.LeftEdge <= coord).all() and
- (coord <= grid.RightEdge).all() ):
- particles.append(read(line, field))
- return np.array(particles)
+ try:
+ lines = self._cached_lines
+ for num in grid._particle_line_numbers:
+ line = lines[num]
+ particles.append(read(line, field))
+ return np.array(particles)
+ except AttributeError:
+ fn = grid.ds.fullplotdir[:-4] + "sink"
+ with open(fn, 'r') as f:
+ lines = f.readlines()
+ self._cached_lines = lines
+ for num in grid._particle_line_numbers:
+ line = lines[num]
+ particles.append(read(line, field))
+ return np.array(particles)
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