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

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Fri Dec 8 09:56:32 PST 2017


8 new commits in yt:

https://bitbucket.org/yt_analysis/yt/commits/c5717058ee00/
Changeset:   c5717058ee00
User:        Yi-Hao Chen
Date:        2017-08-03 19:04:39+00:00
Summary:     Add particle filter dependencies automatically
Affected #:  1 file

diff -r dca5e454d03e59c1f9ab4a52301e74dc12f245e7 -r c5717058ee008e12c4c93049d43aa5e720473463 yt/data_objects/static_output.py
--- a/yt/data_objects/static_output.py
+++ b/yt/data_objects/static_output.py
@@ -677,6 +677,15 @@
         return True
 
     def _setup_filtered_type(self, filter):
+        # Check if the filtered_type of this filter is known, 
+        # otherwise add it first if it is in the filter_registry
+        if filter.filtered_type not in self.known_filters.keys():
+            if filter.filtered_type in filter_registry:
+                add_success = self.add_particle_filter(filter.filtered_type)
+                if add_success:
+                    mylog.info("Added filter dependency '%s' for '%s'",
+                       filter.filtered_type, filter.name)
+
         if not filter.available(self.derived_field_list):
             raise YTIllDefinedParticleFilter(
                 filter, filter.missing(self.derived_field_list))


https://bitbucket.org/yt_analysis/yt/commits/6d807eeb0127/
Changeset:   6d807eeb0127
User:        Yi-Hao Chen
Date:        2017-11-14 21:17:53+00:00
Summary:     Avoid adding duplicated entries in particle_types and filtered_particle_types
Affected #:  1 file

diff -r c5717058ee008e12c4c93049d43aa5e720473463 -r 6d807eeb01271f09f1e68dedc7ee85893f7c1bae yt/data_objects/static_output.py
--- a/yt/data_objects/static_output.py
+++ b/yt/data_objects/static_output.py
@@ -702,8 +702,10 @@
                 # Now we append the dependencies
                 fd[filter.name, fn[1]] = fd[fn]
         if available:
-            self.particle_types += (filter.name,)
-            self.filtered_particle_types.append(filter.name)
+            if filter.name not in self.particle_types:
+                self.particle_types += (filter.name,)
+            if filter.name not in self.filtered_particle_types:
+                self.filtered_particle_types.append(filter.name)
             new_fields = self._setup_particle_types([filter.name])
             deps, _ = self.field_info.check_derived_fields(new_fields)
             self.field_dependencies.update(deps)


https://bitbucket.org/yt_analysis/yt/commits/f7a91e56f832/
Changeset:   f7a91e56f832
User:        Yi-Hao Chen
Date:        2017-11-15 00:00:58+00:00
Summary:     Update documentation for particle filters
Affected #:  1 file

diff -r 6d807eeb01271f09f1e68dedc7ee85893f7c1bae -r f7a91e56f8322bda4b1a1dac9b71a3300aa0ee7d doc/source/analyzing/filtering.rst
--- a/doc/source/analyzing/filtering.rst
+++ b/doc/source/analyzing/filtering.rst
@@ -127,6 +127,22 @@
 name is specified, the name for the particle type will be inferred from the name
 of the filter definition --- in this case the inferred name will be ``stars``.
 
+As an alternative syntax, you can also define a new particle filter via the
+:func:`~yt.data_objects.particle_filter.add_particle_filter` function.
+
+.. code-block:: python
+
+    def stars(pfilter, data):
+        filter = data[(pfilter.filtered_type, "particle_type")] == 2
+        return filter
+
+    yt.add_particle_filter("stars", function=stars, filtered_type='all',
+                        requires=["particle_type"])
+
+This is equivalent to our use of the ``particle_filter`` decorator above.  The
+choice to use either the ``particle_filter`` decorator or the
+``add_particle_filter`` function is a purely stylistic choice.
+
 Lastly, the filter must be applied to our dataset of choice.  Note that this
 filter can be added to as many datasets as we wish.  It will only actually
 create new filtered fields if the dataset has the required fields, though.
@@ -142,22 +158,34 @@
 it created some ``deposit`` fields, where the particles were deposited on to
 the grid as mesh fields.
 
-As an alternative syntax, you can also define a new particle filter via the
-:func:`~yt.data_objects.particle_filter.add_particle_filter` function.
+We can create additional filters building on top of the filters we have. 
+For example, we can identify the young stars based on their age, which is
+the difference between current time and their creation_time.
 
 .. code-block:: python
 
-
-    def Stars(pfilter, data):
-        filter = data[(pfilter.filtered_type, "particle_type")] == 2
+    def young_stars(pfilter, data):
+        age = data.ds.current_time - data[pfilter.filtered_type, "creation_time"]
+        filter = np.logical_and(age.in_units('Myr') <= 5, age >= 0)
         return filter
 
-    add_particle_filter("stars", function=Stars, filtered_type='all',
-                        requires=["particle_type"])
+    yt.add_particle_filter("young_stars", function=young_stars,
+                        filtered_type='stars', requires=["creation_time"])
 
-This is equivalent to our use of the ``particle_filter`` decorator above.  The
-choice to use either the ``particle_filter`` decorator or the
-``add_particle_filter`` function is a purely stylistic choice.
+If we properly define all the filters using the decorator ``yt.particle_filter`` 
+or the function ``yt.add_particle_filter`` in advance. We can add the filter
+we need to the dataset. If the ``filtered_type`` is already defined but not
+added to the dataset, it will automatically add the filter first. For example,
+if we add the ``young_stars`` filter, which is filtered from ``stars``, 
+to the dataset, it will also add ``stars`` filter to the dataset.
+
+.. code-block:: python
+
+    import yt
+    ds = yt.load('IsolatedGalaxy/galaxy0030/galaxy0030')
+    ds.add_particle_filter('young_stars')
+
+
 
 .. notebook:: particle_filter.ipynb
 


https://bitbucket.org/yt_analysis/yt/commits/817949a3c39e/
Changeset:   817949a3c39e
User:        Yi-Hao Chen
Date:        2017-11-15 00:21:07+00:00
Summary:     Update docstrings for add_particle_filter
Affected #:  2 files

diff -r f7a91e56f8322bda4b1a1dac9b71a3300aa0ee7d -r 817949a3c39e1cd52ffc6a5180670d74dd97932f yt/data_objects/particle_filters.py
--- a/yt/data_objects/particle_filters.py
+++ b/yt/data_objects/particle_filters.py
@@ -87,7 +87,9 @@
     A particle filter is a short name that corresponds to an algorithm for
     filtering a set of particles into a subset.  This is useful for creating new
     particle types based on a cut on a particle field, such as particle mass, ID
-    or type.
+    or type. After defining a new filter, it still needs to be added to the
+    dataset by calling
+    :func:`~yt.data_objects.static_output.add_particle_filter`.
 
     .. note::
        Alternatively, you can make use of the

diff -r f7a91e56f8322bda4b1a1dac9b71a3300aa0ee7d -r 817949a3c39e1cd52ffc6a5180670d74dd97932f yt/data_objects/static_output.py
--- a/yt/data_objects/static_output.py
+++ b/yt/data_objects/static_output.py
@@ -353,7 +353,7 @@
             return hashlib.md5(s.encode('utf-8')).hexdigest()
         except ImportError:
             return s.replace(";", "*")
-   
+
     _checksum = None
     @property
     def checksum(self):
@@ -655,6 +655,12 @@
         return len(new_fields)
 
     def add_particle_filter(self, filter):
+        """Add particle filter to the dataset.
+
+        Add ``filter`` to the dataset and set up relavent derived_field.
+        It will also add any ``filtered_type`` that the ``filter`` depends on.
+
+        """
         # This requires an index
         self.index
         # This is a dummy, which we set up to enable passthrough of "all"


https://bitbucket.org/yt_analysis/yt/commits/d4064c4675bd/
Changeset:   d4064c4675bd
User:        Yi-Hao Chen
Date:        2017-11-15 04:44:05+00:00
Summary:     Add a test for particle filter dependency
Affected #:  1 file

diff -r 817949a3c39e1cd52ffc6a5180670d74dd97932f -r d4064c4675bdcbdcca03b33bc1c3e078316cbc62 yt/data_objects/tests/test_particle_filter.py
--- a/yt/data_objects/tests/test_particle_filter.py
+++ b/yt/data_objects/tests/test_particle_filter.py
@@ -49,6 +49,32 @@
     assert True
 
 @requires_file(iso_galaxy)
+def test_particle_filter_dependency():
+    """
+    Test dataset add_particle_filter which should automatically add
+    the dependency of the filter.
+    """
+
+    @particle_filter(filtered_type='all', requires=['particle_type'])
+    def stars(pfilter, data):
+        filter = data[(pfilter.filtered_type, "particle_type")] == 2
+        return filter
+
+    @particle_filter(filtered_type='stars', requires=['creation_time'])
+    def young_stars(pfilter, data):
+        age = data.ds.current_time - data[pfilter.filtered_type, "creation_time"]
+        filter = np.logical_and(age.in_units('Myr') <= 5, age >= 0)
+        return filter
+
+    ds = yt.load(iso_galaxy)
+    ds.add_particle_filter('young_stars')
+    assert 'young_stars' in ds.particle_types
+    assert 'stars' in ds.particle_types
+    print(ds.derived_field_list)
+    assert ('deposit', 'young_stars_cic') in ds.derived_field_list
+    assert ('deposit', 'stars_cic') in ds.derived_field_list
+
+ at requires_file(iso_galaxy)
 def test_covering_grid_particle_filter():
     @particle_filter(requires=["particle_type"], filtered_type='all')
     def stars(pfilter, data):
@@ -61,7 +87,7 @@
 
     for grid in ds.index.grids[20:31]:
         cg = ds.covering_grid(grid.Level, grid.LeftEdge, grid.ActiveDimensions)
-        
+
         assert_equal(cg['stars', 'particle_ones'].shape[0],
                      grid['stars', 'particle_ones'].shape[0])
         assert_equal(cg['stars', 'particle_mass'].shape[0],


https://bitbucket.org/yt_analysis/yt/commits/0dbc2a9ad08f/
Changeset:   0dbc2a9ad08f
User:        Yi-Hao Chen
Date:        2017-11-15 20:48:41+00:00
Summary:     Add import numpy
Affected #:  1 file

diff -r d4064c4675bdcbdcca03b33bc1c3e078316cbc62 -r 0dbc2a9ad08fa590f33b955db654b9336bed0bb8 yt/data_objects/tests/test_particle_filter.py
--- a/yt/data_objects/tests/test_particle_filter.py
+++ b/yt/data_objects/tests/test_particle_filter.py
@@ -5,6 +5,7 @@
     requires_file
 from yt.data_objects.particle_filters import \
     add_particle_filter, particle_filter
+import numpy as np
 
 
 # Dataset required for this test


https://bitbucket.org/yt_analysis/yt/commits/0bfa9f239f2b/
Changeset:   0bfa9f239f2b
User:        Yi-Hao Chen
Date:        2017-11-16 19:28:47+00:00
Summary:     Remove print
Affected #:  1 file

diff -r 0dbc2a9ad08fa590f33b955db654b9336bed0bb8 -r 0bfa9f239f2b6cf081394830361b67f1cc42b195 yt/data_objects/tests/test_particle_filter.py
--- a/yt/data_objects/tests/test_particle_filter.py
+++ b/yt/data_objects/tests/test_particle_filter.py
@@ -71,7 +71,6 @@
     ds.add_particle_filter('young_stars')
     assert 'young_stars' in ds.particle_types
     assert 'stars' in ds.particle_types
-    print(ds.derived_field_list)
     assert ('deposit', 'young_stars_cic') in ds.derived_field_list
     assert ('deposit', 'stars_cic') in ds.derived_field_list
 


https://bitbucket.org/yt_analysis/yt/commits/0535ffa5fe9a/
Changeset:   0535ffa5fe9a
User:        ngoldbaum
Date:        2017-12-08 17:56:19+00:00
Summary:     Merge pull request #1624 from yihaochen/auto_add_particle_filter

Automatically add particle filter dependencies if already defined
Affected #:  4 files

diff -r 1529739c9636be39104b7b0824859a7ae66c7a99 -r 0535ffa5fe9afe653f5f53c85e65a1521769a8d3 doc/source/analyzing/filtering.rst
--- a/doc/source/analyzing/filtering.rst
+++ b/doc/source/analyzing/filtering.rst
@@ -127,6 +127,22 @@
 name is specified, the name for the particle type will be inferred from the name
 of the filter definition --- in this case the inferred name will be ``stars``.
 
+As an alternative syntax, you can also define a new particle filter via the
+:func:`~yt.data_objects.particle_filter.add_particle_filter` function.
+
+.. code-block:: python
+
+    def stars(pfilter, data):
+        filter = data[(pfilter.filtered_type, "particle_type")] == 2
+        return filter
+
+    yt.add_particle_filter("stars", function=stars, filtered_type='all',
+                        requires=["particle_type"])
+
+This is equivalent to our use of the ``particle_filter`` decorator above.  The
+choice to use either the ``particle_filter`` decorator or the
+``add_particle_filter`` function is a purely stylistic choice.
+
 Lastly, the filter must be applied to our dataset of choice.  Note that this
 filter can be added to as many datasets as we wish.  It will only actually
 create new filtered fields if the dataset has the required fields, though.
@@ -142,22 +158,34 @@
 it created some ``deposit`` fields, where the particles were deposited on to
 the grid as mesh fields.
 
-As an alternative syntax, you can also define a new particle filter via the
-:func:`~yt.data_objects.particle_filter.add_particle_filter` function.
+We can create additional filters building on top of the filters we have. 
+For example, we can identify the young stars based on their age, which is
+the difference between current time and their creation_time.
 
 .. code-block:: python
 
-
-    def Stars(pfilter, data):
-        filter = data[(pfilter.filtered_type, "particle_type")] == 2
+    def young_stars(pfilter, data):
+        age = data.ds.current_time - data[pfilter.filtered_type, "creation_time"]
+        filter = np.logical_and(age.in_units('Myr') <= 5, age >= 0)
         return filter
 
-    add_particle_filter("stars", function=Stars, filtered_type='all',
-                        requires=["particle_type"])
+    yt.add_particle_filter("young_stars", function=young_stars,
+                        filtered_type='stars', requires=["creation_time"])
 
-This is equivalent to our use of the ``particle_filter`` decorator above.  The
-choice to use either the ``particle_filter`` decorator or the
-``add_particle_filter`` function is a purely stylistic choice.
+If we properly define all the filters using the decorator ``yt.particle_filter`` 
+or the function ``yt.add_particle_filter`` in advance. We can add the filter
+we need to the dataset. If the ``filtered_type`` is already defined but not
+added to the dataset, it will automatically add the filter first. For example,
+if we add the ``young_stars`` filter, which is filtered from ``stars``, 
+to the dataset, it will also add ``stars`` filter to the dataset.
+
+.. code-block:: python
+
+    import yt
+    ds = yt.load('IsolatedGalaxy/galaxy0030/galaxy0030')
+    ds.add_particle_filter('young_stars')
+
+
 
 .. notebook:: particle_filter.ipynb
 

diff -r 1529739c9636be39104b7b0824859a7ae66c7a99 -r 0535ffa5fe9afe653f5f53c85e65a1521769a8d3 yt/data_objects/particle_filters.py
--- a/yt/data_objects/particle_filters.py
+++ b/yt/data_objects/particle_filters.py
@@ -87,7 +87,9 @@
     A particle filter is a short name that corresponds to an algorithm for
     filtering a set of particles into a subset.  This is useful for creating new
     particle types based on a cut on a particle field, such as particle mass, ID
-    or type.
+    or type. After defining a new filter, it still needs to be added to the
+    dataset by calling
+    :func:`~yt.data_objects.static_output.add_particle_filter`.
 
     .. note::
        Alternatively, you can make use of the

diff -r 1529739c9636be39104b7b0824859a7ae66c7a99 -r 0535ffa5fe9afe653f5f53c85e65a1521769a8d3 yt/data_objects/static_output.py
--- a/yt/data_objects/static_output.py
+++ b/yt/data_objects/static_output.py
@@ -353,7 +353,7 @@
             return hashlib.md5(s.encode('utf-8')).hexdigest()
         except ImportError:
             return s.replace(";", "*")
-   
+
     _checksum = None
     @property
     def checksum(self):
@@ -655,6 +655,12 @@
         return len(new_fields)
 
     def add_particle_filter(self, filter):
+        """Add particle filter to the dataset.
+
+        Add ``filter`` to the dataset and set up relavent derived_field.
+        It will also add any ``filtered_type`` that the ``filter`` depends on.
+
+        """
         # This requires an index
         self.index
         # This is a dummy, which we set up to enable passthrough of "all"
@@ -678,6 +684,15 @@
         return True
 
     def _setup_filtered_type(self, filter):
+        # Check if the filtered_type of this filter is known, 
+        # otherwise add it first if it is in the filter_registry
+        if filter.filtered_type not in self.known_filters.keys():
+            if filter.filtered_type in filter_registry:
+                add_success = self.add_particle_filter(filter.filtered_type)
+                if add_success:
+                    mylog.info("Added filter dependency '%s' for '%s'",
+                       filter.filtered_type, filter.name)
+
         if not filter.available(self.derived_field_list):
             raise YTIllDefinedParticleFilter(
                 filter, filter.missing(self.derived_field_list))
@@ -694,8 +709,10 @@
                 # Now we append the dependencies
                 fd[filter.name, fn[1]] = fd[fn]
         if available:
-            self.particle_types += (filter.name,)
-            self.filtered_particle_types.append(filter.name)
+            if filter.name not in self.particle_types:
+                self.particle_types += (filter.name,)
+            if filter.name not in self.filtered_particle_types:
+                self.filtered_particle_types.append(filter.name)
             new_fields = self._setup_particle_types([filter.name])
             deps, _ = self.field_info.check_derived_fields(new_fields)
             self.field_dependencies.update(deps)

diff -r 1529739c9636be39104b7b0824859a7ae66c7a99 -r 0535ffa5fe9afe653f5f53c85e65a1521769a8d3 yt/data_objects/tests/test_particle_filter.py
--- a/yt/data_objects/tests/test_particle_filter.py
+++ b/yt/data_objects/tests/test_particle_filter.py
@@ -5,6 +5,7 @@
     requires_file
 from yt.data_objects.particle_filters import \
     add_particle_filter, particle_filter
+import numpy as np
 
 
 # Dataset required for this test
@@ -93,6 +94,31 @@
     assert True
 
 @requires_file(iso_galaxy)
+def test_particle_filter_dependency():
+    """
+    Test dataset add_particle_filter which should automatically add
+    the dependency of the filter.
+    """
+
+    @particle_filter(filtered_type='all', requires=['particle_type'])
+    def stars(pfilter, data):
+        filter = data[(pfilter.filtered_type, "particle_type")] == 2
+        return filter
+
+    @particle_filter(filtered_type='stars', requires=['creation_time'])
+    def young_stars(pfilter, data):
+        age = data.ds.current_time - data[pfilter.filtered_type, "creation_time"]
+        filter = np.logical_and(age.in_units('Myr') <= 5, age >= 0)
+        return filter
+
+    ds = yt.load(iso_galaxy)
+    ds.add_particle_filter('young_stars')
+    assert 'young_stars' in ds.particle_types
+    assert 'stars' in ds.particle_types
+    assert ('deposit', 'young_stars_cic') in ds.derived_field_list
+    assert ('deposit', 'stars_cic') in ds.derived_field_list
+
+ at requires_file(iso_galaxy)
 def test_covering_grid_particle_filter():
     @particle_filter(requires=["particle_type"], filtered_type='all')
     def stars(pfilter, data):

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