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

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Mon Sep 19 09:32:03 PDT 2016


1 new commit in yt:

https://bitbucket.org/yt_analysis/yt/commits/a61d336de1d8/
Changeset:   a61d336de1d8
Branch:      yt
User:        ngoldbaum
Date:        2016-09-19 16:31:36+00:00
Summary:     Merged in MatthewTurk/yt-exper (pull request #2224)

Add sampling_type to derived field and prefer over particle_type
Affected #:  6 files

diff -r 9117a13f556156c853cb5983fb8752a068657c75 -r a61d336de1d82ffff73485333120e95e717a7d5e yt/data_objects/data_containers.py
--- a/yt/data_objects/data_containers.py
+++ b/yt/data_objects/data_containers.py
@@ -310,7 +310,7 @@
         with self._field_type_state(ftype, finfo):
             if fname in self._container_fields:
                 tr = self._generate_container_field(field)
-            if finfo.particle_type:
+            if finfo.particle_type: # This is a property now
                 tr = self._generate_particle_field(field)
             else:
                 tr = self._generate_fluid_field(field)

diff -r 9117a13f556156c853cb5983fb8752a068657c75 -r a61d336de1d82ffff73485333120e95e717a7d5e yt/fields/derived_field.py
--- a/yt/fields/derived_field.py
+++ b/yt/fields/derived_field.py
@@ -13,6 +13,7 @@
 
 import contextlib
 import inspect
+import warnings
 
 from yt.extern.six import string_types, PY2
 from yt.funcs import \
@@ -66,8 +67,14 @@
        Describes whether the field should be logged
     validators : list
        A list of :class:`FieldValidator` objects
+    sampling_type : string, default = "cell"
+        How is the field sampled?  This can be one of the following options at
+        present: "cell" (cell-centered), "discrete" (or "particle") for
+        discretely sampled data.
     particle_type : bool
-       Is this a particle (1D) field?
+       (Deprecated) Is this a particle (1D) field?  This is deprecated. Use
+       sampling_type = "discrete" or sampling_type = "particle".  This will
+       *override* sampling_type.
     vector_field : bool
        Describes the dimensionality of the field.  Currently unused.
     display_field : bool
@@ -85,8 +92,8 @@
        for error checking.
     """
     def __init__(self, name, function, units=None,
-                 take_log=True, validators=None,
-                 particle_type=False, vector_field=False, display_field=True,
+                 take_log=True, validators=None, sampling_type = "mesh",
+                 particle_type=None, vector_field=False, display_field=True,
                  not_in_all=False, display_name=None, output_units=None,
                  dimensions=None, ds=None):
         self.name = name
@@ -94,7 +101,12 @@
         self.display_name = display_name
         self.not_in_all = not_in_all
         self.display_field = display_field
-        self.particle_type = particle_type
+        if particle_type is True:
+            warnings.warn("particle_type for derived fields "
+                          "has been replaced with sampling_type = 'particle'",
+                          DeprecationWarning)
+            sampling_type = "particle"
+        self.sampling_type = sampling_type
         self.vector_field = vector_field
         self.ds = ds
 
@@ -136,13 +148,17 @@
         dd['units'] = self.units
         dd['take_log'] = self.take_log
         dd['validators'] = list(self.validators)
-        dd['particle_type'] = self.particle_type
+        dd['sampling_type'] = self.sampling_type
         dd['vector_field'] = self.vector_field
         dd['display_field'] = True
         dd['not_in_all'] = self.not_in_all
         dd['display_name'] = self.display_name
         return dd
 
+    @property
+    def particle_type(self):
+        return self.sampling_type in ("discrete", "particle")
+
     def get_units(self):
         if self.ds is not None:
             u = Unit(self.units, registry=self.ds.unit_registry)

diff -r 9117a13f556156c853cb5983fb8752a068657c75 -r a61d336de1d82ffff73485333120e95e717a7d5e yt/fields/field_info_container.py
--- a/yt/fields/field_info_container.py
+++ b/yt/fields/field_info_container.py
@@ -98,7 +98,7 @@
             if (ptype, f) not in self.field_list:
                 continue
             self.add_output_field((ptype, f),
-                units = units, particle_type = True,
+                units = units, sampling_type = "particle",
                 display_name = dn, output_units = output_units)
             for alias in aliases:
                 self.alias((ptype, alias), (ptype, f), units = output_units)
@@ -136,7 +136,7 @@
                 continue
             self.add_output_field(field, 
                                   units = self.ds.field_units.get(field, ""),
-                                  particle_type = True)
+                                  sampling_type = "particle")
         self.setup_smoothed_fields(ptype, 
                                    num_neighbors=num_neighbors,
                                    ftype=ftype)
@@ -311,7 +311,7 @@
         self.field_aliases[alias_name] = original_name
         self.add_field(alias_name,
             function = TranslationFunc(original_name),
-            particle_type = self[original_name].particle_type,
+            sampling_type = self[original_name].sampling_type,
             display_name = self[original_name].display_name,
             units = units)
 

diff -r 9117a13f556156c853cb5983fb8752a068657c75 -r a61d336de1d82ffff73485333120e95e717a7d5e yt/fields/particle_fields.py
--- a/yt/fields/particle_fields.py
+++ b/yt/fields/particle_fields.py
@@ -191,7 +191,7 @@
 
     registry.add_field((ptype, "particle_ones"),
                        function = particle_ones,
-                       particle_type = True,
+                       sampling_type = "particle",
                        units = "",
                        display_name = r"Particle Count")
 
@@ -207,7 +207,7 @@
             function = particle_mesh_ids,
             validators = [ValidateSpatial()],
             units = '',
-            particle_type = True)
+            sampling_type = "particle")
 
     return list(set(registry.keys()).difference(orig))
 
@@ -228,10 +228,10 @@
     for axi, ax in enumerate("xyz"):
         v, p = _get_coord_funcs(axi, ptype)
         registry.add_field((ptype, "particle_velocity_%s" % ax),
-            particle_type = True, function = v,
+            sampling_type = "particle", function = v,
             units = "code_velocity")
         registry.add_field((ptype, "particle_position_%s" % ax),
-            particle_type = True, function = p,
+            sampling_type = "particle", function = p,
             units = "code_length")
 
 def particle_vector_functions(ptype, coord_names, vel_names, registry):
@@ -318,7 +318,7 @@
         f, v = _get_spec_ang_mom_comp(axi, ax, ptype)
         registry.add_field(
             (ptype, "particle_specific_angular_momentum_%s" % ax),
-            particle_type = True, function=f, units=unit_system["specific_angular_momentum"],
+            sampling_type = "particle", function=f, units=unit_system["specific_angular_momentum"],
             validators=[ValidateParameter("center")]
         )
         registry.add_field((ptype, "particle_angular_momentum_%s" % ax),
@@ -406,10 +406,10 @@
     for axi, ax in enumerate("xyz"):
         v, p = _get_coord_funcs_relative(axi, ptype)
         registry.add_field((ptype, "particle_velocity_relative_%s" % ax),
-            particle_type = True, function = v,
+            sampling_type = "particle", function = v,
             units = "code_velocity")
         registry.add_field((ptype, "particle_position_relative_%s" % ax),
-            particle_type = True, function = p,
+            sampling_type = "particle", function = p,
             units = "code_length")
 
 
@@ -835,7 +835,7 @@
         return distances
     registry.add_field(field_name, function = _nth_neighbor,
                        validators = [ValidateSpatial(0)],
-                       particle_type = True,
+                       sampling_type = "particle",
                        units = "code_length")
     return [field_name]
 

diff -r 9117a13f556156c853cb5983fb8752a068657c75 -r a61d336de1d82ffff73485333120e95e717a7d5e yt/frontends/chombo/fields.py
--- a/yt/frontends/chombo/fields.py
+++ b/yt/frontends/chombo/fields.py
@@ -88,7 +88,7 @@
         for ax in 'xyz':
             self.add_field((ptype, "particle_velocity_%s" % ax), 
                            function=_get_vel(ax),
-                           particle_type=True,
+                           sampling_type = "particle",
                            units="code_length/code_time")
 
         super(Orion2FieldInfo, self).setup_particle_fields(ptype)
@@ -200,7 +200,7 @@
             if (ptype, f) not in self.field_list:
                 continue
             self.add_output_field((ptype, f),
-                units = units, particle_type = True,
+                units = units, sampling_type = "particle",
                 display_name = dn, output_units = output_units, take_log=False)
             for alias in aliases:
                 self.alias((ptype, alias), (ptype, f), units = output_units)
@@ -221,7 +221,7 @@
                 continue
             self.add_output_field(field, 
                                   units = self.ds.field_units.get(field, ""),
-                                  particle_type = True)
+                                  sampling_type = "particle")
         self.setup_smoothed_fields(ptype,
                                    num_neighbors=num_neighbors,
                                    ftype=ftype)
@@ -266,11 +266,11 @@
 
         for ptype in particle_field_types:                
             self.add_field((ptype, "particle_position_z"), function = _dummy_position,
-                           particle_type = True,
+                           sampling_type = "particle",
                            units = "code_length")
 
             self.add_field((ptype, "particle_velocity_z"), function = _dummy_velocity,
-                           particle_type = True,
+                           sampling_type = "particle",
                            units = "code_length / code_time")
 
 
@@ -298,16 +298,16 @@
 
         for ptype in particle_field_types:
             self.add_field((ptype, "particle_position_y"), function = _dummy_position,
-                           particle_type = True,
+                           sampling_type = "particle",
                            units = "code_length")
             self.add_field((ptype, "particle_position_z"), function = _dummy_position,
-                           particle_type = True,
+                           sampling_type = "particle",
                            units = "code_length")
             self.add_field((ptype, "particle_velocity_y"), function = _dummy_velocity,
-                           particle_type = True,
+                           sampling_type = "particle",
                            units = "code_length / code_time")
             self.add_field((ptype, "particle_velocity_z"), function = _dummy_velocity,
-                           particle_type = True,
+                           sampling_type = "particle",
                            units = "code_length / code_time")
 
 

diff -r 9117a13f556156c853cb5983fb8752a068657c75 -r a61d336de1d82ffff73485333120e95e717a7d5e yt/frontends/enzo/fields.py
--- a/yt/frontends/enzo/fields.py
+++ b/yt/frontends/enzo/fields.py
@@ -242,7 +242,7 @@
         def _age(field, data):
             return data.ds.current_time - data["creation_time"]
         self.add_field((ptype, "age"), function = _age,
-                           particle_type = True,
+                           sampling_type = "particle",
                            units = "yr")
 
         super(EnzoFieldInfo, self).setup_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