[yt-svn] commit/yt: MatthewTurk: Merged in brittonsmith/yt (pull request #1650)

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Thu Jul 23 09:37:04 PDT 2015


1 new commit in yt:

https://bitbucket.org/yt_analysis/yt/commits/7a90988f403f/
Changeset:   7a90988f403f
Branch:      yt
User:        MatthewTurk
Date:        2015-07-23 16:36:51+00:00
Summary:     Merged in brittonsmith/yt (pull request #1650)

Adding ability to create union fields from alias fields
Affected #:  6 files

diff -r f5d20191a6e277fa4b3028052806d82023bd6c65 -r 7a90988f403f1033700be711f34c4d461d0dd8d4 yt/data_objects/static_output.py
--- a/yt/data_objects/static_output.py
+++ b/yt/data_objects/static_output.py
@@ -375,6 +375,7 @@
             mylog.debug("Creating Particle Union 'all'")
             pu = ParticleUnion("all", list(self.particle_types_raw))
             self.add_particle_union(pu)
+        self.field_info.setup_extra_union_fields()
         mylog.info("Loading field plugins.")
         self.field_info.load_all_plugins()
         deps, unloaded = self.field_info.check_derived_fields()

diff -r f5d20191a6e277fa4b3028052806d82023bd6c65 -r 7a90988f403f1033700be711f34c4d461d0dd8d4 yt/fields/field_info_container.py
--- a/yt/fields/field_info_container.py
+++ b/yt/fields/field_info_container.py
@@ -29,6 +29,7 @@
 from .field_plugin_registry import \
     field_plugins
 from .particle_fields import \
+    add_union_field, \
     particle_deposition_functions, \
     particle_vector_functions, \
     particle_scalar_functions, \
@@ -47,6 +48,7 @@
     fallback = None
     known_other_fields = ()
     known_particle_fields = ()
+    extra_union_fields = ()
 
     def __init__(self, ds, field_list, slice_info = None):
         self._show_field_errors = []
@@ -117,6 +119,13 @@
                                    num_neighbors=num_neighbors,
                                    ftype=ftype)
 
+    def setup_extra_union_fields(self, ptype="all"):
+        if ptype != "all":
+            raise RuntimeError("setup_extra_union_fields is currently" + 
+                               "only enabled for particle type \"all\".")
+        for units, field in self.extra_union_fields:
+            add_union_field(self, ptype, field, units)
+
     def setup_smoothed_fields(self, ptype, num_neighbors = 64, ftype = "gas"):
         # We can in principle compute this, but it is not yet implemented.
         if (ptype, "density") not in self:

diff -r f5d20191a6e277fa4b3028052806d82023bd6c65 -r 7a90988f403f1033700be711f34c4d461d0dd8d4 yt/fields/particle_fields.py
--- a/yt/fields/particle_fields.py
+++ b/yt/fields/particle_fields.py
@@ -839,4 +839,17 @@
                        units = "g/cm**3")
     return [field_name]
 
+def add_union_field(registry, ptype, field_name, units):
+    """
+    Create a field that is the concatenation of multiple particle types.
+    This allows us to create fields for particle unions using alias names.
+    """
 
+    def _cat_field(field, data):
+        return uconcatenate([data[dep_type, field_name]
+                             for dep_type in data.ds.particle_types_raw])
+
+    registry.add_field((ptype, field_name),
+                       function=_cat_field,
+                       particle_type=True,
+                       units=units)

diff -r f5d20191a6e277fa4b3028052806d82023bd6c65 -r 7a90988f403f1033700be711f34c4d461d0dd8d4 yt/frontends/gadget_fof/data_structures.py
--- a/yt/frontends/gadget_fof/data_structures.py
+++ b/yt/frontends/gadget_fof/data_structures.py
@@ -95,7 +95,7 @@
         # This is an attribute that means these particle types *actually*
         # exist.  As in, they are real, in the dataset.
         ds.field_units.update(units)
-        ds.particle_types_raw = ds.particle_types
+        ds.particle_types_raw = tuple(sorted(ds.particle_types))
             
     def _setup_geometry(self):
         super(GadgetFOFParticleIndex, self)._setup_geometry()

diff -r f5d20191a6e277fa4b3028052806d82023bd6c65 -r 7a90988f403f1033700be711f34c4d461d0dd8d4 yt/frontends/gadget_fof/fields.py
--- a/yt/frontends/gadget_fof/fields.py
+++ b/yt/frontends/gadget_fof/fields.py
@@ -45,4 +45,17 @@
         ("SubhaloVel_2", (v_units, ["Subhalo", "particle_velocity_z"], None)),
         ("SubhaloMass",  (m_units, ["Subhalo", "particle_mass"], None)),
         ("SubhaloLen",   ("",      ["Subhalo", "particle_number"], None)),
-)
+    )
+
+    # these are extra fields to be created for the "all" particle type
+    extra_union_fields = (
+        (p_units, "particle_position_x"),
+        (p_units, "particle_position_y"),
+        (p_units, "particle_position_z"),
+        (v_units, "particle_velocity_x"),
+        (v_units, "particle_velocity_y"),
+        (v_units, "particle_velocity_z"),
+        (m_units, "particle_mass"),
+        ("",      "particle_number"),
+        ("",      "particle_ones"),
+    )

diff -r f5d20191a6e277fa4b3028052806d82023bd6c65 -r 7a90988f403f1033700be711f34c4d461d0dd8d4 yt/frontends/gadget_fof/tests/test_outputs.py
--- a/yt/frontends/gadget_fof/tests/test_outputs.py
+++ b/yt/frontends/gadget_fof/tests/test_outputs.py
@@ -23,13 +23,10 @@
     data_dir_load
 from yt.frontends.gadget_fof.api import GadgetFOFDataset
 
-p_types  = ("Group", "Subhalo")
-p_fields = ("particle_position_x", "particle_position_y",
-            "particle_position_z", "particle_velocity_x",
-            "particle_velocity_y", "particle_velocity_z",
-            "particle_mass", "particle_identifier")
-_fields = tuple([(p_type, p_field) for p_type in p_types
-                                   for p_field in p_fields])
+_fields = ("particle_position_x", "particle_position_y",
+           "particle_position_z", "particle_velocity_x",
+           "particle_velocity_y", "particle_velocity_z",
+           "particle_mass", "particle_identifier")
 
 # a dataset with empty files
 g5 = "gadget_fof_halos/groups_005/fof_subhalo_tab_005.0.hdf5"

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