Commits

Christopher Moody committed fda4112

fixed star field functionality

  • Participants
  • Parent commits 95cb567

Comments (0)

Files changed (2)

File yt/frontends/art/data_structures.py

                     self.parameters[k]=v
             self.parameters_particles = particle_header_vals
         if self.file_particle_stars:
-            self.particle_star_index = len(wspecies)-1
+            self.particle_star_index = len(self.parameters['wspecies'])-1
     
         #setup standard simulation yt expects to see
         self.current_redshift = self.parameters["aexpn"]**-1.0 - 1.0

File yt/frontends/art/io.py

             a=b
 
     def _load_stars(self,pf):
-        if self.particle_age is not None: return
+        if self.particle_data.get('particle_age',None) is not None: return
         (nstars_rs,), mass, imass, tbirth, metallicity1, metallicity2, \
                 ws_old,ws_oldi,tdum,adum \
              = read_stars(pf.file_particle_stars)
         self.nstars_rs = nstars_rs     
-        self.nstars_pa = b-a
         inconsistent=self.particle_data['particle_type']==pf.particle_star_index
         if not nstars_rs==np.sum(inconsistent):
-            mylog.info('WARNING!: nstars is inconsistent!')
+            pass
+            #mylog.info('WARNING!: nstars is inconsistent!')
         del inconsistent
+        nparticles = self.particle_data['particle_position_x'].shape[0]
         if nstars_rs > 0 :
             n=min(1e2,len(tbirth))
             birthtimes= b2t(tbirth,n=n)
             assert birthtimes.shape == tbirth.shape    
             birthtimes*= 1.0e9 #from Gyr to yr
             birthtimes*= 365*24*3600 #to seconds
-            ages = self.current_time-birthtimes
+            ages = pf.current_time-birthtimes
             spread = pf.spread_age
             if type(spread)==type(5.5):
                 ages = spread_ages(ages,spread=spread)
                 ages = spread_ages(ages)
             idx = self.particle_data['particle_type'] == pf.particle_star_index
             for psf in particle_star_fields:
-                if psf not in self.particle_data.keys():
-                    self.particle_data[psf] = \
-                            np.zeros(nparticles,dtype='float64')
-            self.particle_data['particle_age'][sa:sb] = ages
-            self.particle_data['particle_mass'][sa:sb] = mass
-            self.particle_data['particle_mass_initial'][sa:sb] = imass
-            self.particle_data['particle_creation_time'][sa:sb] = birthtimes
-            self.particle_data['particle_metallicity1'][sa:sb] = metallicity1
-            self.particle_data['particle_metallicity2'][sa:sb] = metallicity2
-            self.particle_data['particle_metallicity'][sa:sb]  = metallicity1\
+                self.particle_data[psf] = \
+                        np.zeros(nparticles,dtype='float64')
+            pt = self.particle_data['particle_type']
+            idx = np.where(pt == pf.particle_star_index)[0]
+            sa,sb = idx[0],idx[-1]
+            assert pt[sa]==pt[sb]==self.particle_star_index
+            import pdb; pdb.set_trace()
+            self.particle_data['particle_age'][sa:sb+1] = ages
+            self.particle_data['particle_mass'][sa:sb+1] = mass
+            self.particle_data['particle_mass_initial'][sa:sb+1] = imass
+            self.particle_data['particle_creation_time'][sa:sb+1] = birthtimes
+            self.particle_data['particle_metallicity1'][sa:sb+1] = metallicity1
+            self.particle_data['particle_metallicity2'][sa:sb+1] = metallicity2
+            self.particle_data['particle_metallicity'][sa:sb+1]  = metallicity1\
                                                   + metallicity2
 
     def _read_particle_field(self, grid, field):
         self._load_particles(grid.pf)
         assert self.particle_grid_indices is not None
-        if 'star' in field or field in particle_star_fields:
-            self._load_star(grid.pf)
+        if field in particle_star_fields:
+            self._load_stars(grid.pf)
             field = field.replace("star","particle")
             data = self.particle_data.get(field,None)
-            if 'star_indices' not in self.particle_data.keys():
-                star_idx = self.particle_data['particle_type']==\
-                        self.particle_star_index
-                self.particle_data['star_indices']
-            data = data[self.particle_data['star_indices']]
+            if 'star' in field:
+                if 'star_indices' not in self.particle_data.keys():
+                    star_idx = self.particle_data['particle_type']==\
+                            self.particle_star_index
+                    self.particle_data['star_indices']=star_idx
+                data = data[self.particle_data['star_indices']]
         else:
             data = self.particle_data.get(field,None)
         if data is None: