[yt-svn] commit/yt: 5 new changesets

Bitbucket commits-noreply at bitbucket.org
Tue May 1 03:09:18 PDT 2012


5 new commits in yt:


https://bitbucket.org/yt_analysis/yt/changeset/92b8f82c0e05/
changeset:   92b8f82c0e05
branch:      yt
user:        Andrew Myers
date:        2012-04-24 19:47:24
summary:     change fields to use NullFunc instead of lambda a, b: None
affected #:  1 file

diff -r bc2ffa01fa6867e41927150874c0ed7ac2c2d01a -r 92b8f82c0e057fbed2c45c3bdf5705ecd1ba7f1d yt/frontends/chombo/fields.py
--- a/yt/frontends/chombo/fields.py
+++ b/yt/frontends/chombo/fields.py
@@ -76,12 +76,12 @@
                   units=r"",display_name=r"B_z")
 KnownChomboFields["Z-magnfield"]._projected_units=r""
 
-add_chombo_field("energy-density", function=lambda a,b: None, take_log=True,
+add_chombo_field("energy-density", function=NullFunc, take_log=True,
                  validators = [ValidateDataField("energy-density")],
                  units=r"\rm{erg}/\rm{cm}^3")
 KnownChomboFields["energy-density"]._projected_units =r""
 
-add_chombo_field("radiation-energy-density", function=lambda a,b: None, take_log=True,
+add_chombo_field("radiation-energy-density", function=NullFunc, take_log=True,
                  validators = [ValidateDataField("radiation-energy-density")],
                  units=r"\rm{erg}/\rm{cm}^3")
 KnownChomboFields["radiation-energy-density"]._projected_units =r""



https://bitbucket.org/yt_analysis/yt/changeset/ec8abbd0280d/
changeset:   ec8abbd0280d
branch:      yt
user:        Andrew Myers
date:        2012-04-24 20:00:36
summary:     particle support for Orion 2
affected #:  3 files

diff -r 92b8f82c0e057fbed2c45c3bdf5705ecd1ba7f1d -r ec8abbd0280d10127dd2f34f3ae974e0a644d675 yt/frontends/chombo/data_structures.py
--- a/yt/frontends/chombo/data_structures.py
+++ b/yt/frontends/chombo/data_structures.py
@@ -121,8 +121,37 @@
         self.float_type = self._fhandle['/level_0']['data:datatype=0'].dtype.name
         self._levels = self._fhandle.keys()[1:]
         AMRHierarchy.__init__(self,pf,data_style)
+        self._read_particles()
         self._fhandle.close()
 
+    def _read_particles(self):
+        self.particle_filename = self.hierarchy_filename[:-4] + 'sink'
+        if not os.path.exists(self.particle_filename): return
+        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:]:
+                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
+
     def _initialize_data_storage(self):
         pass
 


diff -r 92b8f82c0e057fbed2c45c3bdf5705ecd1ba7f1d -r ec8abbd0280d10127dd2f34f3ae974e0a644d675 yt/frontends/chombo/fields.py
--- a/yt/frontends/chombo/fields.py
+++ b/yt/frontends/chombo/fields.py
@@ -33,6 +33,7 @@
     ValidateSpatial, \
     ValidateGridType
 import yt.data_objects.universal_fields
+import numpy as na
 
 KnownChomboFields = FieldInfoContainer()
 add_chombo_field = KnownChomboFields.add_field
@@ -125,3 +126,36 @@
     return data["Z-momentum"]/data["density"]
 add_field("z-velocity",function=_zVelocity, take_log=False,
           units=r'\rm{cm}/\rm{s}')
+
+def particle_func(p_field, dtype='float64'):
+    def _Particles(field, data):
+        io = data.hierarchy.io
+        if not data.NumberOfParticles > 0:
+            return na.array([], dtype=dtype)
+        else:
+            return io._read_particles(data, p_field).astype(dtype)
+        
+    return _Particles
+
+_particle_field_list = ["mass",
+                        "position_x",
+                        "position_y",
+                        "position_z",
+                        "momentum_x",
+                        "momentum_y",
+                        "momentum_z",
+                        "angmomen_x",
+                        "angmomen_y",
+                        "angmomen_z",
+                        "mlast",
+                        "mdeut",
+                        "n",
+                        "mdot",
+                        "burnstate",
+                        "id"]
+
+for pf in _particle_field_list:
+    pfunc = particle_func("particle_%s" % (pf))
+    add_field("particle_%s" % pf, function=pfunc,
+              validators = [ValidateSpatial(0)],
+              particle_type=True)


diff -r 92b8f82c0e057fbed2c45c3bdf5705ecd1ba7f1d -r ec8abbd0280d10127dd2f34f3ae974e0a644d675 yt/frontends/chombo/io.py
--- a/yt/frontends/chombo/io.py
+++ b/yt/frontends/chombo/io.py
@@ -25,6 +25,7 @@
 """
 import h5py
 import re
+import numpy as na
 
 from yt.utilities.io_handler import \
            BaseIOHandler
@@ -70,3 +71,41 @@
         sl[axis] = slice(coord, coord + 1)
         return self._read_data_set(grid,field)[sl]
 
+    def _read_particles(self, grid, field):
+        """
+        parses the Orion Star Particle text files
+             
+        """
+        index = {'particle_mass': 0,
+                 'particle_position_x': 1,
+                 'particle_position_y': 2,
+                 'particle_position_z': 3,
+                 'particle_momentum_x': 4,
+                 'particle_momentum_y': 5,
+                 'particle_momentum_z': 6,
+                 'particle_angmomen_x': 7,
+                 'particle_angmomen_y': 8,
+                 'particle_angmomen_z': 9,
+                 'particle_mlast': 10,
+                 'particle_mdeut': 11,
+                 'particle_n': 12,
+                 'particle_mdot': 13,
+                 'particle_burnstate': 14,
+                 'particle_id': 15}
+
+        def read(line, field):
+            return float(line.split(' ')[index[field]])
+
+        fn = grid.pf.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 na.array(particles)



https://bitbucket.org/yt_analysis/yt/changeset/469521796b74/
changeset:   469521796b74
branch:      yt
user:        Andrew Myers
date:        2012-04-30 21:40:34
summary:     fixing an indentation error in the chombo particle reader
affected #:  1 file

diff -r ec8abbd0280d10127dd2f34f3ae974e0a644d675 -r 469521796b7485cc4dc17a1d7f60439568759037 yt/frontends/chombo/data_structures.py
--- a/yt/frontends/chombo/data_structures.py
+++ b/yt/frontends/chombo/data_structures.py
@@ -141,16 +141,16 @@
                 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
+                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
 
     def _initialize_data_storage(self):
         pass



https://bitbucket.org/yt_analysis/yt/changeset/b1d2aec9e0e9/
changeset:   b1d2aec9e0e9
branch:      yt
user:        Andrew Myers
date:        2012-04-30 21:41:17
summary:     fixing an indentation error in the orion particle reader
affected #:  1 file

diff -r 469521796b7485cc4dc17a1d7f60439568759037 -r b1d2aec9e0e9f74dd6a9a7fee5a61d61cb3d0e1c yt/frontends/orion/data_structures.py
--- a/yt/frontends/orion/data_structures.py
+++ b/yt/frontends/orion/data_structures.py
@@ -163,16 +163,16 @@
                 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
+                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):



https://bitbucket.org/yt_analysis/yt/changeset/61acaf1be42b/
changeset:   61acaf1be42b
branch:      yt
user:        Andrew Myers
date:        2012-04-30 21:43:10
summary:     os.path.isfile -> os.path.exists (orion plt files are directories!)
affected #:  1 file

diff -r b1d2aec9e0e9f74dd6a9a7fee5a61d61cb3d0e1c -r 61acaf1be42b7e1923dea3f1441bbe0c21c58443 yt/convenience.py
--- a/yt/convenience.py
+++ b/yt/convenience.py
@@ -86,7 +86,7 @@
     candidates = []
     args = [os.path.expanduser(arg) if isinstance(arg, types.StringTypes)
             else arg for arg in args]
-    valid_file = [os.path.isfile(arg) if isinstance(arg, types.StringTypes) 
+    valid_file = [os.path.exists(arg) if isinstance(arg, types.StringTypes) 
             else False for arg in args]
     if not any(valid_file):
         mylog.error("None of the arguments provided to load() is a valid file")

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