[yt-svn] commit/yt: jzuhone: Merged in MatthewTurk/yt (pull request #2432)
commits-noreply at bitbucket.org
commits-noreply at bitbucket.org
Mon Dec 5 10:08:48 PST 2016
1 new commit in yt:
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