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

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Mon Dec 5 10:08:50 PST 2016


9 new commits in yt:

https://bitbucket.org/yt_analysis/yt/commits/3027dcf331b7/
Changeset:   3027dcf331b7
Branch:      yt
User:        MatthewTurk
Date:        2016-11-03 23:19:35+00:00
Summary:     Allow chunk_ind to be an argument to data_object.chunks

This lets us do sub-chunking with a simple argument.  By making this happen at
the outer most part of the loop, we can avoid reading any data.
Affected #:  1 file

diff -r 334cceb2c6e197acf1a8c7f273ee9dd0bd592f58 -r 3027dcf331b7fde84e63342ea8be36fcb5da32eb yt/data_objects/data_containers.py
--- a/yt/data_objects/data_containers.py
+++ b/yt/data_objects/data_containers.py
@@ -1189,7 +1189,13 @@
         # This is an iterator that will yield the necessary chunks.
         self.get_data() # Ensure we have built ourselves
         if fields is None: fields = []
-        for chunk in self.index._chunk(self, chunking_style, **kwargs):
+        chunk_ind = kwargs.pop("chunk_ind", None)
+        if chunk_ind is not None:
+            chunk_ind = ensure_list(chunk_ind)
+        for ci, chunk in enumerate(self.index._chunk(self, chunking_style,
+                                   **kwargs)):
+            if chunk_ind is not None and ci not in chunk_ind:
+                continue
             with self._chunked_read(chunk):
                 self.get_data(fields)
                 # NOTE: we yield before releasing the context


https://bitbucket.org/yt_analysis/yt/commits/29229d491bd8/
Changeset:   29229d491bd8
Branch:      yt
User:        MatthewTurk
Date:        2016-11-04 03:12:20+00:00
Summary:     Adding a .clone() method for data objects.
Affected #:  1 file

diff -r 3027dcf331b7fde84e63342ea8be36fcb5da32eb -r 29229d491bd8c569cafdf9ed7e25fd6356ea53e8 yt/data_objects/data_containers.py
--- a/yt/data_objects/data_containers.py
+++ b/yt/data_objects/data_containers.py
@@ -1040,6 +1040,34 @@
                      [self.field_parameters])
         return (_reconstruct_object, args)
 
+    def clone(self):
+        r"""Clone a data object.
+
+        This will make a duplicate of a data object; note that the
+        `field_parameters` may not necessarily be deeply-copied, so if you
+        modify any of them in place that modification may be carried through to
+        the cloned object.
+
+        Notes
+        -----
+        One use case for this is to have multiple identical data objects that
+        are being chunked over in different orders.
+
+        Examples
+        --------
+
+        >>> ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030")
+        >>> sp = ds.sphere("c", 0.1)
+        >>> sp_clone = sp.clone()
+        >>> sp["density"]
+        >>> print sp.field_data.keys()
+        [("gas", "density")]
+        >>> print sp_clone.field_data.keys()
+        []
+        """
+        args = self.__reduce__()
+        return args[0](self.ds, *args[1][1:])[1]
+
     def __repr__(self):
         # We'll do this the slow way to be clear what's going on
         s = "%s (%s): " % (self.__class__.__name__, self.ds)
@@ -1984,6 +2012,9 @@
     return narg
 
 def _get_ds_by_hash(hash):
+    from yt.data_objects.static_output import Dataset
+    if isinstance(hash, Dataset):
+        return hash
     from yt.data_objects.static_output import _cached_datasets
     for ds in _cached_datasets.values():
         if ds._hash() == hash: return ds


https://bitbucket.org/yt_analysis/yt/commits/5619d72c53ef/
Changeset:   5619d72c53ef
Branch:      yt
User:        MatthewTurk
Date:        2016-11-04 16:24:53+00:00
Summary:     Adding clone tests
Affected #:  1 file

diff -r 29229d491bd8c569cafdf9ed7e25fd6356ea53e8 -r 5619d72c53efe8c8ffed868c367e03b2bb1051f0 yt/data_objects/tests/test_clone.py
--- /dev/null
+++ b/yt/data_objects/tests/test_clone.py
@@ -0,0 +1,24 @@
+from yt.testing import \
+    fake_random_ds, \
+    assert_equal, \
+    assert_array_equal
+
+def test_clone_sphere()
+    # Now we test that we can get different radial velocities based on field
+    # parameters.
+
+    # Get the first sphere
+    ds = fake_random_ds(16, fields = ("density",
+      "velocity_x", "velocity_y", "velocity_z"))
+    sp0 = ds.sphere(ds.domain_center, 0.25)
+
+    assert_equal(sp0.keys(), [])
+
+    sp1 = sp0.clone()
+    sp0["density"]
+    assert_equal(sp0.keys(), (("gas","density"),))
+    assert_equal(sp1.keys(), [])
+
+    sp1["density"]
+
+    assert_array_equal(sp0["density"], sp1["density"])


https://bitbucket.org/yt_analysis/yt/commits/dc6aeb837224/
Changeset:   dc6aeb837224
Branch:      yt
User:        MatthewTurk
Date:        2016-11-04 16:35:30+00:00
Summary:     Adding comment
Affected #:  1 file

diff -r 5619d72c53efe8c8ffed868c367e03b2bb1051f0 -r dc6aeb837224b5db5278e757a73b4591edc05ae9 yt/data_objects/data_containers.py
--- a/yt/data_objects/data_containers.py
+++ b/yt/data_objects/data_containers.py
@@ -1217,6 +1217,9 @@
         # This is an iterator that will yield the necessary chunks.
         self.get_data() # Ensure we have built ourselves
         if fields is None: fields = []
+        # chunk_ind can be supplied in the keyword arguments.  If it's a
+        # scalar, that'll be the only chunk that gets returned; if it's a list,
+        # those are the ones that will be.
         chunk_ind = kwargs.pop("chunk_ind", None)
         if chunk_ind is not None:
             chunk_ind = ensure_list(chunk_ind)


https://bitbucket.org/yt_analysis/yt/commits/1dfd3dae2d46/
Changeset:   1dfd3dae2d46
Branch:      yt
User:        MatthewTurk
Date:        2016-11-04 16:36:28+00:00
Summary:     Changing some text
Affected #:  1 file

diff -r dc6aeb837224b5db5278e757a73b4591edc05ae9 -r 1dfd3dae2d460e0e3d8b6f53bf54db623a40cb49 yt/data_objects/data_containers.py
--- a/yt/data_objects/data_containers.py
+++ b/yt/data_objects/data_containers.py
@@ -1044,9 +1044,10 @@
         r"""Clone a data object.
 
         This will make a duplicate of a data object; note that the
-        `field_parameters` may not necessarily be deeply-copied, so if you
-        modify any of them in place that modification may be carried through to
-        the cloned object.
+        `field_parameters` may not necessarily be deeply-copied.  If you modify
+        the field parameters in-place, it may or may not be shared between the
+        objects, depending on the type of object that that particular field
+        parameter is.
 
         Notes
         -----


https://bitbucket.org/yt_analysis/yt/commits/5cad8b939fd5/
Changeset:   5cad8b939fd5
Branch:      yt
User:        MatthewTurk
Date:        2016-11-04 16:38:48+00:00
Summary:     Adding note about clone
Affected #:  1 file

diff -r 1dfd3dae2d460e0e3d8b6f53bf54db623a40cb49 -r 5cad8b939fd54fb467d403859756f091d00ff980 doc/source/analyzing/objects.rst
--- a/doc/source/analyzing/objects.rst
+++ b/doc/source/analyzing/objects.rst
@@ -64,6 +64,18 @@
        print("(%f,  %f,  %f)    %f" %
              (sp["x"][i], sp["y"][i], sp["z"][i], sp["temperature"][i]))
 
+Data objects can also be cloned; for instance:
+
+.. code-block:: python
+
+   import yt
+   ds = yt.load("RedshiftOutput0005")
+   sp = ds.sphere([0.5, 0.5, 0.5], (1, 'kpc'))
+   sp_copy = sp.clone()
+
+This can be useful for when manually chunking data or exploring different field
+parameters.
+
 .. _quickly-selecting-data:
 
 Slicing Syntax for Selecting Data


https://bitbucket.org/yt_analysis/yt/commits/38cef6fb1e24/
Changeset:   38cef6fb1e24
Branch:      yt
User:        MatthewTurk
Date:        2016-11-04 17:55:15+00:00
Summary:     Re-colon-izing this function declaration.
Affected #:  1 file

diff -r 5cad8b939fd54fb467d403859756f091d00ff980 -r 38cef6fb1e248638b44d226723af36253d0c73a7 yt/data_objects/tests/test_clone.py
--- a/yt/data_objects/tests/test_clone.py
+++ b/yt/data_objects/tests/test_clone.py
@@ -3,7 +3,7 @@
     assert_equal, \
     assert_array_equal
 
-def test_clone_sphere()
+def test_clone_sphere():
     # Now we test that we can get different radial velocities based on field
     # parameters.
 


https://bitbucket.org/yt_analysis/yt/commits/1e164db0c387/
Changeset:   1e164db0c387
Branch:      yt
User:        MatthewTurk
Date:        2016-11-04 19:52:39+00:00
Summary:     Py3 fix
Affected #:  1 file

diff -r 38cef6fb1e248638b44d226723af36253d0c73a7 -r 1e164db0c38766d969fd49da9a6c1f24bb5a4488 yt/data_objects/tests/test_clone.py
--- a/yt/data_objects/tests/test_clone.py
+++ b/yt/data_objects/tests/test_clone.py
@@ -12,12 +12,12 @@
       "velocity_x", "velocity_y", "velocity_z"))
     sp0 = ds.sphere(ds.domain_center, 0.25)
 
-    assert_equal(sp0.keys(), [])
+    assert_equal(list(sp0.keys()), [])
 
     sp1 = sp0.clone()
     sp0["density"]
-    assert_equal(sp0.keys(), (("gas","density"),))
-    assert_equal(sp1.keys(), [])
+    assert_equal(list(sp0.keys()), (("gas","density"),))
+    assert_equal(list(sp1.keys()), [])
 
     sp1["density"]
 


https://bitbucket.org/yt_analysis/yt/commits/d3f3ea8fe490/
Changeset:   d3f3ea8fe490
Branch:      yt
User:        jzuhone
Date:        2016-12-05 18:08:23+00:00
Summary:     Merged in MatthewTurk/yt (pull request #2432)

Adding data_object.clone() and chunk_ind
Affected #:  3 files

diff -r b9c09a2edd4e61caf2678093fcfdec8dceb0b20c -r d3f3ea8fe4906be938d683acbfbf60ed5a911d4a doc/source/analyzing/objects.rst
--- a/doc/source/analyzing/objects.rst
+++ b/doc/source/analyzing/objects.rst
@@ -64,6 +64,18 @@
        print("(%f,  %f,  %f)    %f" %
              (sp["x"][i], sp["y"][i], sp["z"][i], sp["temperature"][i]))
 
+Data objects can also be cloned; for instance:
+
+.. code-block:: python
+
+   import yt
+   ds = yt.load("RedshiftOutput0005")
+   sp = ds.sphere([0.5, 0.5, 0.5], (1, 'kpc'))
+   sp_copy = sp.clone()
+
+This can be useful for when manually chunking data or exploring different field
+parameters.
+
 .. _quickly-selecting-data:
 
 Slicing Syntax for Selecting Data

diff -r b9c09a2edd4e61caf2678093fcfdec8dceb0b20c -r d3f3ea8fe4906be938d683acbfbf60ed5a911d4a yt/data_objects/data_containers.py
--- a/yt/data_objects/data_containers.py
+++ b/yt/data_objects/data_containers.py
@@ -1040,6 +1040,35 @@
                      [self.field_parameters])
         return (_reconstruct_object, args)
 
+    def clone(self):
+        r"""Clone a data object.
+
+        This will make a duplicate of a data object; note that the
+        `field_parameters` may not necessarily be deeply-copied.  If you modify
+        the field parameters in-place, it may or may not be shared between the
+        objects, depending on the type of object that that particular field
+        parameter is.
+
+        Notes
+        -----
+        One use case for this is to have multiple identical data objects that
+        are being chunked over in different orders.
+
+        Examples
+        --------
+
+        >>> ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030")
+        >>> sp = ds.sphere("c", 0.1)
+        >>> sp_clone = sp.clone()
+        >>> sp["density"]
+        >>> print sp.field_data.keys()
+        [("gas", "density")]
+        >>> print sp_clone.field_data.keys()
+        []
+        """
+        args = self.__reduce__()
+        return args[0](self.ds, *args[1][1:])[1]
+
     def __repr__(self):
         # We'll do this the slow way to be clear what's going on
         s = "%s (%s): " % (self.__class__.__name__, self.ds)
@@ -1189,7 +1218,16 @@
         # This is an iterator that will yield the necessary chunks.
         self.get_data() # Ensure we have built ourselves
         if fields is None: fields = []
-        for chunk in self.index._chunk(self, chunking_style, **kwargs):
+        # chunk_ind can be supplied in the keyword arguments.  If it's a
+        # scalar, that'll be the only chunk that gets returned; if it's a list,
+        # those are the ones that will be.
+        chunk_ind = kwargs.pop("chunk_ind", None)
+        if chunk_ind is not None:
+            chunk_ind = ensure_list(chunk_ind)
+        for ci, chunk in enumerate(self.index._chunk(self, chunking_style,
+                                   **kwargs)):
+            if chunk_ind is not None and ci not in chunk_ind:
+                continue
             with self._chunked_read(chunk):
                 self.get_data(fields)
                 # NOTE: we yield before releasing the context
@@ -1978,6 +2016,9 @@
     return narg
 
 def _get_ds_by_hash(hash):
+    from yt.data_objects.static_output import Dataset
+    if isinstance(hash, Dataset):
+        return hash
     from yt.data_objects.static_output import _cached_datasets
     for ds in _cached_datasets.values():
         if ds._hash() == hash: return ds

diff -r b9c09a2edd4e61caf2678093fcfdec8dceb0b20c -r d3f3ea8fe4906be938d683acbfbf60ed5a911d4a yt/data_objects/tests/test_clone.py
--- /dev/null
+++ b/yt/data_objects/tests/test_clone.py
@@ -0,0 +1,24 @@
+from yt.testing import \
+    fake_random_ds, \
+    assert_equal, \
+    assert_array_equal
+
+def test_clone_sphere():
+    # Now we test that we can get different radial velocities based on field
+    # parameters.
+
+    # Get the first sphere
+    ds = fake_random_ds(16, fields = ("density",
+      "velocity_x", "velocity_y", "velocity_z"))
+    sp0 = ds.sphere(ds.domain_center, 0.25)
+
+    assert_equal(list(sp0.keys()), [])
+
+    sp1 = sp0.clone()
+    sp0["density"]
+    assert_equal(list(sp0.keys()), (("gas","density"),))
+    assert_equal(list(sp1.keys()), [])
+
+    sp1["density"]
+
+    assert_array_equal(sp0["density"], sp1["density"])

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