[yt-svn] commit/yt: MatthewTurk: Refactoring orion particle reading.
Bitbucket
commits-noreply at bitbucket.org
Fri Feb 24 09:22:50 PST 2012
1 new commit in yt:
https://bitbucket.org/yt_analysis/yt/changeset/97ff2eaa879f/
changeset: 97ff2eaa879f
branch: yt
user: MatthewTurk
date: 2012-02-24 15:44:02
summary: Refactoring orion particle reading.
affected #: 1 file
diff -r 628a21c5a006843c58c4c3ee893f2c1d2366be69 -r 97ff2eaa879ff06284ab7359af0fab1bd14ab0ea yt/frontends/orion/data_structures.py
--- a/yt/frontends/orion/data_structures.py
+++ b/yt/frontends/orion/data_structures.py
@@ -139,46 +139,40 @@
"""
self.grid_particle_count = na.zeros(len(self.grids))
-
- if self._readOrionParticleFile(self.pf.fullplotdir + "/StarParticles"):
- pass
- elif self._readOrionParticleFile(self.pf.fullplotdir + "/SinkParticles"):
- pass
- else:
- mylog.warning("No particles found.")
- def _readOrionParticleFile(self, fn):
+ for particle_filename in ["StarParticles", "SinkParticles"]:
+ fn = os.path.join(self.pf.fullplotdir, particle_filename)
+ if os.path.exists(fn): self._read_particle_file(fn)
+
+ def _read_particle_file(self, fn):
"""actually reads the orion particle data file itself.
"""
- try:
- with open(fn, 'r') as f:
- lines = f.readlines()
- self.num_stars = int(lines[0].strip())
- for line in 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=na.ones(self.num_grids)
- for i in xrange(len(coord)):
- na.choose(na.greater(self.grid_left_edge[:,i],coord[i]), (mask,0), mask)
- na.choose(na.greater(self.grid_right_edge[:,i],coord[i]), (0,mask), mask)
- ind = na.where(mask == 1)
- selected_grids = self.grids[ind]
- # in orion, particles always live on the finest level.
- # so, we want to assign the particle to the finest of
- # the grids we just found
- if len(selected_grids) != 0:
- grid = sorted(selected_grids, key=lambda grid: grid.Level)[-1]
- ind = na.where(self.grids == grid)[0][0]
- self.grid_particle_count[ind] += 1
- self.grids[ind].NumberOfParticles += 1
- except IOError:
- return None
-
+ if not os.path.exists(fn): return
+ with open(fn, 'r') as f:
+ lines = f.readlines()
+ self.num_stars = int(lines[0].strip())
+ for line in 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=na.ones(self.num_grids)
+ for i in xrange(len(coord)):
+ na.choose(na.greater(self.grid_left_edge[:,i],coord[i]), (mask,0), mask)
+ na.choose(na.greater(self.grid_right_edge[:,i],coord[i]), (0,mask), mask)
+ ind = na.where(mask == 1)
+ selected_grids = self.grids[ind]
+ # in orion, particles always live on the finest level.
+ # so, we want to assign the particle to the finest of
+ # the grids we just found
+ if len(selected_grids) != 0:
+ grid = sorted(selected_grids, key=lambda grid: grid.Level)[-1]
+ ind = na.where(self.grids == grid)[0][0]
+ self.grid_particle_count[ind] += 1
+ self.grids[ind].NumberOfParticles += 1
return True
def readGlobalHeader(self,filename,paranoid_read):
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