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

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Wed Feb 24 09:33:24 PST 2016


1 new commit in yt:

https://bitbucket.org/yt_analysis/yt/commits/aaa54f6b1a1b/
Changeset:   aaa54f6b1a1b
Branch:      yt
User:        MatthewTurk
Date:        2016-02-24 17:33:18+00:00
Summary:     Merged in ngoldbaum/yt (pull request #1915)

[bugfix] Avoid creating particle unions for particle types that have no common fields
Affected #:  2 files

diff -r 737f924d071e578fff7e5d756502b8260f1b84c4 -r aaa54f6b1a1b1f98ea52b203fccce7c51a1ccc91 yt/data_objects/static_output.py
--- a/yt/data_objects/static_output.py
+++ b/yt/data_objects/static_output.py
@@ -435,7 +435,9 @@
         if "all" not in self.particle_types:
             mylog.debug("Creating Particle Union 'all'")
             pu = ParticleUnion("all", list(self.particle_types_raw))
-            self.add_particle_union(pu)
+            nfields = self.add_particle_union(pu)
+            if nfields == 0:
+                mylog.debug("zero common fields: skipping particle union 'all'")
         self.field_info.setup_extra_union_fields()
         mylog.debug("Loading field plugins.")
         self.field_info.load_all_plugins()
@@ -487,9 +489,17 @@
     def add_particle_union(self, union):
         # No string lookups here, we need an actual union.
         f = self.particle_fields_by_type
-        fields = set_intersection([f[s] for s in union
-                                   if s in self.particle_types_raw
-                                   and len(f[s]) > 0])
+
+        # find fields common to all particle types in the union
+        fields = set_intersection(
+            [f[s] for s in union if s in self.particle_types_raw]
+        )
+
+        if len(fields) == 0:
+            # don't create this union if no fields are common to all
+            # particle types
+            return len(fields)
+
         for field in fields:
             units = set([])
             for s in union:
@@ -508,6 +518,7 @@
         # ...if we can't find them, we set them up as defaults.
         new_fields = self._setup_particle_types([union.name])
         self.field_info.find_dependencies(new_fields)
+        return len(new_fields)
 
     def add_particle_filter(self, filter):
         # This requires an index

diff -r 737f924d071e578fff7e5d756502b8260f1b84c4 -r aaa54f6b1a1b1f98ea52b203fccce7c51a1ccc91 yt/frontends/enzo/tests/test_outputs.py
--- a/yt/frontends/enzo/tests/test_outputs.py
+++ b/yt/frontends/enzo/tests/test_outputs.py
@@ -1,5 +1,5 @@
 """
-Enzo frontend tests using moving7
+Enzo frontend tests
 
 
 
@@ -33,6 +33,13 @@
 _fields = ("temperature", "density", "velocity_magnitude",
            "velocity_divergence")
 
+two_sphere_test = 'ActiveParticleTwoSphere/DD0011/DD0011'
+active_particle_cosmology = 'ActiveParticleCosmology/DD0046/DD0046'
+ecp = "enzo_cosmology_plus/DD0046/DD0046"
+g30 = "IsolatedGalaxy/galaxy0030/galaxy0030"
+enzotiny = "enzo_tiny_cosmology/DD0046/DD0046"
+
+
 def check_color_conservation(ds):
     species_names = ds.field_info.species_names
     dd = ds.all_data()
@@ -68,7 +75,6 @@
         test_moving7.__name__ = test.description
         yield test
 
-g30 = "IsolatedGalaxy/galaxy0030/galaxy0030"
 @requires_ds(g30, big_data=True)
 def test_galaxy0030():
     ds = data_dir_load(g30)
@@ -78,7 +84,6 @@
         test_galaxy0030.__name__ = test.description
         yield test
 
-enzotiny = "enzo_tiny_cosmology/DD0046/DD0046"
 @requires_ds(enzotiny)
 def test_simulated_halo_mass_function():
     ds = data_dir_load(enzotiny)
@@ -91,7 +96,6 @@
     for fit in range(1, 6):
         yield AnalyticHaloMassFunctionTest(ds, fit)
 
-ecp = "enzo_cosmology_plus/DD0046/DD0046"
 @requires_ds(ecp, big_data=True)
 def test_ecp():
     ds = data_dir_load(ecp)
@@ -116,3 +120,33 @@
 @requires_file(enzotiny)
 def test_EnzoDataset():
     assert isinstance(data_dir_load(enzotiny), EnzoDataset)
+
+ at requires_file(two_sphere_test)
+ at requires_file(active_particle_cosmology)
+def test_active_particle_datasets():
+    two_sph = data_dir_load(two_sphere_test)
+    assert 'AccretingParticle' in two_sph.particle_types_raw
+    assert_equal(len(two_sph.particle_unions), 0)
+    pfields = ['GridID', 'creation_time', 'dynamical_time',
+               'identifier', 'level', 'metallicity', 'particle_mass']
+    pfields += ['particle_position_%s' % d for d in 'xyz']
+    pfields += ['particle_velocity_%s' % d for d in 'xyz']
+
+    acc_part_fields = \
+        [('AccretingParticle', pf) for pf in ['AccretionRate'] + pfields]
+
+    real_acc_part_fields = sorted(
+        [f for f in two_sph.field_list if f[0] == 'AccretingParticle'])
+    assert_equal(acc_part_fields, real_acc_part_fields)
+
+
+    apcos = data_dir_load(active_particle_cosmology)
+    assert_equal(['CenOstriker', 'DarkMatter'], apcos.particle_types_raw)
+    assert 'all' in apcos.particle_unions
+
+    apcos_fields = [('CenOstriker', pf) for pf in pfields]
+
+    real_apcos_fields = sorted(
+        [f for f in apcos.field_list if f[0] == 'CenOstriker'])
+
+    assert_equal(apcos_fields, real_apcos_fields)

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