Commits

Christopher Moody committed 8585424

particle fields still not working.

Comments (0)

Files changed (5)

yt/frontends/art/data_structures.py

 
 from yt.utilities.physical_constants import \
     mass_hydrogen_cgs
+    
+from yt.frontends.art.definitions import art_particle_field_names
 
 from yt.frontends.art.io import read_particles
 from yt.frontends.art.io import read_stars
                             'Pressure','Gamma','GasEnergy',
                             'Metal_DensitySNII', 'Metal_DensitySNIa',
                             'Potential_New','Potential_Old']
+        #self.field_list += art_particle_field_names
     
     def _setup_classes(self):
         dd = self._get_data_reader_dict()
                 a=b
             pbar.finish()
             
+            self.pf.particle_star_index = lspecies[-2]
             
             if self.pf.file_star_data:
                 nstars, mass, imass, tbirth, metals1, metals2 \
                      = read_stars(self.pf.file_star_data,nstars,Nrow)
                 n=min(1e2,len(tbirth))
-                pbar = get_pbar("Stellar ages          ",n)
+                pbar = get_pbar("Stellar Ages        ",n)
                 self.pf.particle_star_ages = b2t(tbirth,n=n,logger=lambda x: pbar.update(x))
                 pbar.finish()
                 self.pf.particle_star_metallicity1 = metals1/mass
                 self.pf.particle_star_metallicity2 = metals2/mass
                 self.pf.particle_star_mass_initial = imass*um
-                self.pf.particle_star_mass_current = mass*um
+                self.pf.particle_mass[-nstars:] = mass*um
                 
             
             pbar = get_pbar("Gridding  Particles ",len(grids))
                 idx = na.logical_and(na.all(le < self.pf.particle_position,axis=1),
                                      na.all(re > self.pf.particle_position,axis=1))
                 g.particle_indices = idx
+                g.NumberOfParticles = idx.sum()
                 self.grids[gi] = g
                 pbar.update(gi)
             pbar.finish()
             g._prepare_grid()
             g._setup_dx()
         self.max_level = self.grid_levels.max()
+        
+    def _setup_field_list(self):
+        if self.parameter_file.use_particles:
+            # We know which particle fields will exist -- pending further
+            # changes in the future.
+            for field in art_particle_field_names:
+                def external_wrapper(f):
+                    def _convert_function(data):
+                        return data.convert(f)
+                    return _convert_function
+                cf = external_wrapper(field)
+                # Note that we call add_field on the field_info directly.  This
+                # will allow the same field detection mechanism to work for 1D,
+                # 2D and 3D fields.
+                self.pf.field_info.add_field(field, NullFunc,
+                                             convert_function=cf,
+                                             take_log=False, particle_type=True)
 
     def _setup_derived_fields(self):
         self.derived_field_list = []
                  file_particle_header=None, 
                  file_particle_data=None,
                  file_star_data=None,
-                 discover_particles=False):
+                 discover_particles=False,
+                 use_particles=True):
         import yt.frontends.ramses._ramses_reader as _ramses_reader
         
         
                     self.file_star_data = loc
                     mylog.info("Discovered stellar data:    %s",os.path.basename(loc))
         
+        self.use_particles = any([self.file_particle_header,
+            self.file_star_data, self.file_particle_data])
         StaticOutput.__init__(self, filename, data_style)
         
         self.dimensionality = 3

yt/frontends/art/definitions.py

+"""
+Definitions specific to ART
+
+Author: Christopher E. Moody <cemoody@ucsc.ed>
+Affiliation: UC Santa Cruz
+Homepage: http://yt-project.org/
+License:
+  Copyright (C) 2011 Christopher E. Moody.  All Rights
+  Reserved.
+
+  This file is part of yt.
+
+  yt is free software; you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published by
+  the Free Software Foundation; either version 3 of the License, or
+  (at your option) any later version.
+
+  This program is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public License
+  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+"""
+
+art_particle_field_names = ['particle_position','particle_mass','particle_velocity',
+                            'particle_ages','particle_metallicity1',
+                            'particle_metallicity2','particle_mass_initial']

yt/frontends/art/fields.py

                     "Pressure":"pressure",
                     "Metallicity":"metallicity",
                     "GasEnergy":"GasEnergy"
+                    #"ParticleMass": "particle_mass"
                    }
 
 for f,v in translation_dict.items():
+    pfield = v.startswith("particle")
     add_art_field(v, function=NullFunc, take_log=False,
-                  validators = [ValidateDataField(v)])
-    add_art_field(f, function=TranslationFunc(v), take_log=True)
+                  validators = [ValidateDataField(v)],
+                  particle_type = pfield)
+    add_art_field(f, function=TranslationFunc(v), take_log=True,
+                  particle_type = pfield)
+    
 
 #def _convertMetallicity(data):
 #    return data.convert("Metal_Density1")
 add_art_field("Metal_Density", function=_Metal_Density, units = r"\mathrm{K}")
 KnownARTFields["Metal_Density"]._units = r"\mathrm{K}"
 KnownARTFields["Metal_Density"]._convert_function=_convert_Metal_Density
+
+
+#Particle Fields
+
+import pdb; pdb.set_trace()
+
+
+# pm=add_art_field("particle_mass", particle_type=True,
+#     validators = [ValidateDataField("particle_mass")])
+# pm.particle_type = True
+
+#               
+# def _convertParticleMassMsun(data):
+#     return (1/1.989e33)
+# def _particle_mass_m_sun(field, data):
+#     import pdb; pdb.set_trace()
+#     return data['ParticleMass']
+# add_art_field("ParticleMassMsun", function=_particle_mass_m_sun,
+#           particle_type=True, convert_function=_convertParticleMassMsun,
+#           take_log=True, units=r"\rm{M_{\odot}}")
+
+def _convertParticleMassMsun(data):
+    return (1/1.989e33)
+def _particle_mass_m_sun(field, data):
+    import pdb;pdb.set_trace()
+    return data["particle_mass"]
+add_field("ParticleMassMsun", function=_particle_mass_m_sun,
+          validators=[ValidateSpatial(0), ValidateDataField("particle_mass")],
+          particle_type=True, convert_function=_convertParticleMassMsun,
+          take_log=True, units=r"\rm{M_{\odot}}")
+

yt/frontends/art/io.py

     BaseIOHandler
 import yt.utilities.amr_utils as au
 
+from yt.frontends.art.definitions import art_particle_field_names
+
 class IOHandlerART(BaseIOHandler):
     _data_style = "art"
 
 
     def clear_level(self, level):
         self.level_data.pop(level, None)
+
+    def _read_particle_field(self, grid, field):
+        import pdb; pdb.set_trace()
+        idx = grid.particle_indices
+        if field == 'particle_position':
+            return grid.pf.particle_position[idx]
+        if field == 'particle_mass':
+            return grid.pf.particle_mass[idx]
+        if field == 'particle_velocity':
+            return grid.pf.particle_velocity[idx]
+        sidx = idx-self.pf.particle_star_index
+        sidx = sidx[sidx>=0]
+        if field == 'particle_ages':
+            tr = na.zeros(grid.NumberOfParticles, dtype='float64')-1.0
+            tr[idx] = grid.pf.particle_star_ages[sidx]
+            return tr
+        if field == 'particle_metallicity1':
+            tr = na.zeros(grid.NumberOfParticles, dtype='float64')-1.0
+            tr[idx] = grid.pf.particle_star_metallicity1[sidx]
+            return tr
+        if field == 'particle_metallicity2':
+            tr = na.zeros(grid.NumberOfParticles, dtype='float64')-1.0
+            tr[idx] = grid.pf.particle_star_metallicity2[sidx]
+            return tr
+        if field == 'particle_mass_initial':
+            tr = na.zeros(grid.NumberOfParticles, dtype='float64')-1.0
+            tr[idx] = grid.pf.particle_star_mass_initial[sidx]
+            return tr
+        raise 'Should have matched one of the particle fields...'
+
         
     def _read_data_set(self, grid, field):
+        if field in art_particle_field_names:
+            return self._read_particle_field(grid, field)
         pf = grid.pf
         field_id = grid.pf.h.field_list.index(field)
         if grid.Level == 0: # We only have one root grid

yt/frontends/ramses/data_structures.py

     def _detect_fields(self):
         self.field_list = self.tree_proxy.field_names[:]
     
+    def _setup_field_list(self):
+        if self.parameter_file.use_particles:
+            # We know which particle fields will exist -- pending further
+            # changes in the future.
+            for field in art_particle_field_names:
+                def external_wrapper(f):
+                    def _convert_function(data):
+                        return data.convert(f)
+                    return _convert_function
+                cf = external_wrapper(field)
+                # Note that we call add_field on the field_info directly.  This
+                # will allow the same field detection mechanism to work for 1D,
+                # 2D and 3D fields.
+                self.pf.field_info.add_field(field, NullFunc,
+                                             convert_function=cf,
+                                             take_log=False, particle_type=True)
+
     def _setup_classes(self):
         dd = self._get_data_reader_dict()
         AMRHierarchy._setup_classes(self, dd)