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

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Tue Nov 22 14:52:17 PST 2016


6 new commits in yt:

https://bitbucket.org/yt_analysis/yt/commits/79d2723f658a/
Changeset:   79d2723f658a
Branch:      yt
User:        brittonsmith
Date:        2016-11-21 23:17:32+00:00
Summary:     Adding separate setup_particle_fields method for gizmo frontend to create all species fields.
Affected #:  1 file

diff -r 9f4dc27f7c8fd399a35e04d0423298753b2994c9 -r 79d2723f658a31a229c186d727c15381c4517cd1 yt/frontends/gizmo/fields.py
--- a/yt/frontends/gizmo/fields.py
+++ b/yt/frontends/gizmo/fields.py
@@ -14,15 +14,21 @@
 # The full license is in the file COPYING.txt, distributed with this software.
 #-----------------------------------------------------------------------------
 
+from yt.fields.field_info_container import \
+    FieldInfoContainer
 from yt.fields.particle_fields import \
     add_volume_weighted_smoothed_field
 from yt.fields.species_fields import \
-    add_species_field_by_density
+    add_species_field_by_density, \
+    setup_species_fields
 from yt.frontends.gadget.fields import \
     GadgetFieldInfo
 from yt.frontends.sph.fields import \
     SPHFieldInfo
 
+metal_elements = ["He", "C", "N", "O", "Ne",
+                  "Mg", "Si", "S", "Ca", "Fe"]
+
 class GizmoFieldInfo(GadgetFieldInfo):
     known_particle_fields = (
         ("Mass", ("code_mass", ["particle_mass"], None)),
@@ -58,8 +64,14 @@
     def __init__(self, *args, **kwargs):
         super(SPHFieldInfo, self).__init__(*args, **kwargs)
         if ("PartType0", "Metallicity_00") in self.field_list:
-            self.nuclei_names = ["He", "C", "N", "O", "Ne", "Mg", "Si", "S",
-                                 "Ca", "Fe"]
+            self.nuclei_names = metal_elements
+            self.species_names = ["H", "H_p1"] + metal_elements
+
+    def setup_particle_fields(self, ptype):
+        FieldInfoContainer.setup_particle_fields(self, ptype)
+        if ptype in ("PartType0",):
+            self.setup_gas_particle_fields(ptype)
+            setup_species_fields(self, ptype)
 
     def setup_gas_particle_fields(self, ptype):
         super(GizmoFieldInfo, self).setup_gas_particle_fields(ptype)


https://bitbucket.org/yt_analysis/yt/commits/ee3b017f6017/
Changeset:   ee3b017f6017
Branch:      yt
User:        brittonsmith
Date:        2016-11-21 23:18:23+00:00
Summary:     Making nuclei_density fields more robust to different field types and dependencies and optimizing.
Affected #:  1 file

diff -r 79d2723f658a31a229c186d727c15381c4517cd1 -r ee3b017f6017b3f6d879ef33c16b2c5b959388a5 yt/fields/species_fields.py
--- a/yt/fields/species_fields.py
+++ b/yt/fields/species_fields.py
@@ -145,32 +145,48 @@
     unit_system = registry.ds.unit_system
     elements = _get_all_elements(registry.species_names)
     for element in elements:
-        registry.add_field((ftype, "%s_nuclei_density" % element), sampling_type="cell", 
+        registry.add_field((ftype, "%s_nuclei_density" % element),
+                           sampling_type="cell",
                            function = _nuclei_density,
                            particle_type = particle_type,
                            units = unit_system["number_density"])
-    if len(elements) == 0:
-        for element in ["H", "He"]:
-            registry.add_field((ftype, "%s_nuclei_density" % element), sampling_type="cell", 
-                               function = _default_nuclei_density,
-                               particle_type = particle_type,
-                               units = unit_system["number_density"])
+
+    for element in ["H", "He"]:
+        if element in elements: continue
+        registry.add_field((ftype, "%s_nuclei_density" % element),
+                           sampling_type="cell",
+                           function = _default_nuclei_density,
+                           particle_type = particle_type,
+                           units = unit_system["number_density"])
 
 def _default_nuclei_density(field, data):
+    ftype = field.name[0]
     element = field.name[1][:field.name[1].find("_")]
-    return data["gas", "density"] * _primordial_mass_fraction[element] / \
+    return data[ftype, "density"] * _primordial_mass_fraction[element] / \
       ChemicalFormula(element).weight / amu_cgs
         
 def _nuclei_density(field, data):
+    ftype = field.name[0]
     element = field.name[1][:field.name[1].find("_")]
-    field_data = np.zeros_like(data["gas", "%s_number_density" % 
+
+    nuclei_mass_field = "%s_nuclei_mass_density" % element
+    if (ftype, nuclei_mass_field) in data.ds.field_info:
+        return data[(ftype, nuclei_mass_field)] / \
+          ChemicalFormula(element).weight / amu_cgs
+    metal_field = "%s_metallicity" % element
+    if (ftype, metal_field) in data.ds.field_info:
+        return data[ptype, "density"] * data[(ftype, metal_field)] / \
+          ChemicalFormula(element).weight / amu_cgs
+
+    field_data = np.zeros_like(data[ftype, "%s_number_density" %
                                     data.ds.field_info.species_names[0]])
     for species in data.ds.field_info.species_names:
         nucleus = species
         if "_" in species:
             nucleus = species[:species.find("_")]
         num = _get_element_multiple(nucleus, element)
-        field_data += num * data["gas", "%s_number_density" % species]
+        if num == 0: continue
+        field_data += num * data[ftype, "%s_number_density" % species]
     return field_data
 
 def _get_all_elements(species_list):


https://bitbucket.org/yt_analysis/yt/commits/d55db3a13c1d/
Changeset:   d55db3a13c1d
Branch:      yt
User:        brittonsmith
Date:        2016-11-21 23:56:53+00:00
Summary:     Removing groan-worthy one-liners.
Affected #:  1 file

diff -r ee3b017f6017b3f6d879ef33c16b2c5b959388a5 -r d55db3a13c1d77b5bbe23afdaa0b4228e1215525 yt/fields/species_fields.py
--- a/yt/fields/species_fields.py
+++ b/yt/fields/species_fields.py
@@ -152,7 +152,8 @@
                            units = unit_system["number_density"])
 
     for element in ["H", "He"]:
-        if element in elements: continue
+        if element in elements:
+            continue
         registry.add_field((ftype, "%s_nuclei_density" % element),
                            sampling_type="cell",
                            function = _default_nuclei_density,
@@ -185,7 +186,8 @@
         if "_" in species:
             nucleus = species[:species.find("_")]
         num = _get_element_multiple(nucleus, element)
-        if num == 0: continue
+        if num == 0:
+            continue
         field_data += num * data[ftype, "%s_number_density" % species]
     return field_data
 


https://bitbucket.org/yt_analysis/yt/commits/e67907fd7519/
Changeset:   e67907fd7519
Branch:      yt
User:        brittonsmith
Date:        2016-11-22 18:34:12+00:00
Summary:     Typo.
Affected #:  1 file

diff -r d55db3a13c1d77b5bbe23afdaa0b4228e1215525 -r e67907fd75198003d071465ba09748afefc6ba40 yt/fields/species_fields.py
--- a/yt/fields/species_fields.py
+++ b/yt/fields/species_fields.py
@@ -176,7 +176,7 @@
           ChemicalFormula(element).weight / amu_cgs
     metal_field = "%s_metallicity" % element
     if (ftype, metal_field) in data.ds.field_info:
-        return data[ptype, "density"] * data[(ftype, metal_field)] / \
+        return data[ftype, "density"] * data[(ftype, metal_field)] / \
           ChemicalFormula(element).weight / amu_cgs
 
     field_data = np.zeros_like(data[ftype, "%s_number_density" %


https://bitbucket.org/yt_analysis/yt/commits/d1e3655d3feb/
Changeset:   d1e3655d3feb
Branch:      yt
User:        brittonsmith
Date:        2016-11-22 21:35:57+00:00
Summary:     Adding comment.
Affected #:  1 file

diff -r e67907fd75198003d071465ba09748afefc6ba40 -r d1e3655d3febf9e8b7d410238bd33b7570dfff88 yt/fields/species_fields.py
--- a/yt/fields/species_fields.py
+++ b/yt/fields/species_fields.py
@@ -185,7 +185,10 @@
         nucleus = species
         if "_" in species:
             nucleus = species[:species.find("_")]
+        # num is the number of nuclei contributed by this species.
         num = _get_element_multiple(nucleus, element)
+        # Since this is a loop over all species existing in this dataset,
+        # we will encounter species that contribute nothing, so we skip them.
         if num == 0:
             continue
         field_data += num * data[ftype, "%s_number_density" % species]


https://bitbucket.org/yt_analysis/yt/commits/5499b32cce88/
Changeset:   5499b32cce88
Branch:      yt
User:        chummels
Date:        2016-11-22 22:51:50+00:00
Summary:     Merged in brittonsmith/yt (pull request #2442)

Making nuclei density fields more robust
Affected #:  2 files

diff -r 9373defa8ed5e8c707b5d36a1dc3568885807ea6 -r 5499b32cce889b3306cf6718b80bc55fa5ce9315 yt/fields/species_fields.py
--- a/yt/fields/species_fields.py
+++ b/yt/fields/species_fields.py
@@ -145,32 +145,53 @@
     unit_system = registry.ds.unit_system
     elements = _get_all_elements(registry.species_names)
     for element in elements:
-        registry.add_field((ftype, "%s_nuclei_density" % element), sampling_type="cell", 
+        registry.add_field((ftype, "%s_nuclei_density" % element),
+                           sampling_type="cell",
                            function = _nuclei_density,
                            particle_type = particle_type,
                            units = unit_system["number_density"])
-    if len(elements) == 0:
-        for element in ["H", "He"]:
-            registry.add_field((ftype, "%s_nuclei_density" % element), sampling_type="cell", 
-                               function = _default_nuclei_density,
-                               particle_type = particle_type,
-                               units = unit_system["number_density"])
+
+    for element in ["H", "He"]:
+        if element in elements:
+            continue
+        registry.add_field((ftype, "%s_nuclei_density" % element),
+                           sampling_type="cell",
+                           function = _default_nuclei_density,
+                           particle_type = particle_type,
+                           units = unit_system["number_density"])
 
 def _default_nuclei_density(field, data):
+    ftype = field.name[0]
     element = field.name[1][:field.name[1].find("_")]
-    return data["gas", "density"] * _primordial_mass_fraction[element] / \
+    return data[ftype, "density"] * _primordial_mass_fraction[element] / \
       ChemicalFormula(element).weight / amu_cgs
         
 def _nuclei_density(field, data):
+    ftype = field.name[0]
     element = field.name[1][:field.name[1].find("_")]
-    field_data = np.zeros_like(data["gas", "%s_number_density" % 
+
+    nuclei_mass_field = "%s_nuclei_mass_density" % element
+    if (ftype, nuclei_mass_field) in data.ds.field_info:
+        return data[(ftype, nuclei_mass_field)] / \
+          ChemicalFormula(element).weight / amu_cgs
+    metal_field = "%s_metallicity" % element
+    if (ftype, metal_field) in data.ds.field_info:
+        return data[ftype, "density"] * data[(ftype, metal_field)] / \
+          ChemicalFormula(element).weight / amu_cgs
+
+    field_data = np.zeros_like(data[ftype, "%s_number_density" %
                                     data.ds.field_info.species_names[0]])
     for species in data.ds.field_info.species_names:
         nucleus = species
         if "_" in species:
             nucleus = species[:species.find("_")]
+        # num is the number of nuclei contributed by this species.
         num = _get_element_multiple(nucleus, element)
-        field_data += num * data["gas", "%s_number_density" % species]
+        # Since this is a loop over all species existing in this dataset,
+        # we will encounter species that contribute nothing, so we skip them.
+        if num == 0:
+            continue
+        field_data += num * data[ftype, "%s_number_density" % species]
     return field_data
 
 def _get_all_elements(species_list):

diff -r 9373defa8ed5e8c707b5d36a1dc3568885807ea6 -r 5499b32cce889b3306cf6718b80bc55fa5ce9315 yt/frontends/gizmo/fields.py
--- a/yt/frontends/gizmo/fields.py
+++ b/yt/frontends/gizmo/fields.py
@@ -14,15 +14,21 @@
 # The full license is in the file COPYING.txt, distributed with this software.
 #-----------------------------------------------------------------------------
 
+from yt.fields.field_info_container import \
+    FieldInfoContainer
 from yt.fields.particle_fields import \
     add_volume_weighted_smoothed_field
 from yt.fields.species_fields import \
-    add_species_field_by_density
+    add_species_field_by_density, \
+    setup_species_fields
 from yt.frontends.gadget.fields import \
     GadgetFieldInfo
 from yt.frontends.sph.fields import \
     SPHFieldInfo
 
+metal_elements = ["He", "C", "N", "O", "Ne",
+                  "Mg", "Si", "S", "Ca", "Fe"]
+
 class GizmoFieldInfo(GadgetFieldInfo):
     known_particle_fields = (
         ("Mass", ("code_mass", ["particle_mass"], None)),
@@ -58,8 +64,14 @@
     def __init__(self, *args, **kwargs):
         super(SPHFieldInfo, self).__init__(*args, **kwargs)
         if ("PartType0", "Metallicity_00") in self.field_list:
-            self.nuclei_names = ["He", "C", "N", "O", "Ne", "Mg", "Si", "S",
-                                 "Ca", "Fe"]
+            self.nuclei_names = metal_elements
+            self.species_names = ["H", "H_p1"] + metal_elements
+
+    def setup_particle_fields(self, ptype):
+        FieldInfoContainer.setup_particle_fields(self, ptype)
+        if ptype in ("PartType0",):
+            self.setup_gas_particle_fields(ptype)
+            setup_species_fields(self, ptype)
 
     def setup_gas_particle_fields(self, ptype):
         super(GizmoFieldInfo, self).setup_gas_particle_fields(ptype)

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