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

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Wed May 11 12:26:29 PDT 2016


10 new commits in yt:

https://bitbucket.org/yt_analysis/yt/commits/0bbd1eab3681/
Changeset:   0bbd1eab3681
Branch:      yt
User:        chummels
Date:        2016-05-05 01:32:12+00:00
Summary:     Making it so LightRay will accept a dataset instead of just the filename of a dataset.
Affected #:  1 file

diff -r 2f2c9e84c335e5d4be9c4eac86b1f67aed7e752f -r 0bbd1eab36818b307d83fb0bd9fc1829efdf9942 yt/analysis_modules/cosmological_observation/light_ray/light_ray.py
--- a/yt/analysis_modules/cosmological_observation/light_ray/light_ray.py
+++ b/yt/analysis_modules/cosmological_observation/light_ray/light_ray.py
@@ -31,6 +31,7 @@
     parallel_objects, \
     parallel_root_only
 from yt.utilities.physical_constants import speed_of_light_cgs
+from yt.data_objects.static_output import Dataset
 
 class LightRay(CosmologySplice):
     """
@@ -130,24 +131,34 @@
         self.light_ray_solution = []
         self._data = {}
 
-        # Make a light ray from a single, given dataset.
-        if simulation_type is None:
+        # The options here are:
+        # 1) User passed us a dataset: use it to make a simple ray
+        # 2) User passed us a dataset filename: use it to make a simple ray
+        # 3) User passed us a simulation filename: use it to make a compound ray
+
+        # Make a light ray from a single, given dataset: #1, #2
+        if simulation_type is None:     
             self.simulation_type = simulation_type
-            ds = load(parameter_filename, **self.load_kwargs)
-            if ds.cosmological_simulation:
-                redshift = ds.current_redshift
+            if isinstance(parameter_filename, Dataset):
+                self.ds = parameter_filename
+                self.parameter_filename = self.ds.basename
+            elif isinstance(parameter_filename, str):
+                self.ds = load(parameter_filename, **self.load_kwargs)
+            if self.ds.cosmological_simulation:
+                redshift = self.ds.current_redshift
                 self.cosmology = Cosmology(
-                    hubble_constant=ds.hubble_constant,
-                    omega_matter=ds.omega_matter,
-                    omega_lambda=ds.omega_lambda,
-                    unit_registry=ds.unit_registry)
+                    hubble_constant=self.ds.hubble_constant,
+                    omega_matter=self.ds.omega_matter,
+                    omega_lambda=self.ds.omega_lambda,
+                    unit_registry=self.ds.unit_registry)
             else:
                 redshift = 0.
             self.light_ray_solution.append({"filename": parameter_filename,
                                             "redshift": redshift})
 
-        # Make a light ray from a simulation time-series.
+        # Make a light ray from a simulation time-series. #3
         else:
+            self.ds = None
             # Get list of datasets for light ray solution.
             CosmologySplice.__init__(self, parameter_filename, simulation_type,
                                      find_outputs=find_outputs)
@@ -383,8 +394,12 @@
                                                        storage=all_ray_storage,
                                                        njobs=njobs):
 
-            # Load dataset for segment.
-            ds = load(my_segment['filename'], **self.load_kwargs)
+            # In case of simple rays, use the already loaded dataset: self.ds, 
+            # otherwise, load dataset for segment.
+            if self.ds is None:
+                ds = load(my_segment['filename'], **self.load_kwargs)
+            else:
+                ds = self.ds
 
             my_segment['unique_identifier'] = ds.unique_identifier
             if redshift is not None:
@@ -555,7 +570,7 @@
         Write light ray data to hdf5 file.
         """
         if self.simulation_type is None:
-            ds = load(self.parameter_filename, **self.load_kwargs)
+            ds = self.ds
         else:
             ds = {}
             ds["dimensionality"] = self.simulation.dimensionality


https://bitbucket.org/yt_analysis/yt/commits/3d126df4b1b6/
Changeset:   3d126df4b1b6
Branch:      yt
User:        chummels
Date:        2016-05-05 01:48:51+00:00
Summary:     Updating docstrings for LightRay to reflect changes.
Affected #:  1 file

diff -r 0bbd1eab36818b307d83fb0bd9fc1829efdf9942 -r 3d126df4b1b6d832cf447863c983e2ee80b6b562 yt/analysis_modules/cosmological_observation/light_ray/light_ray.py
--- a/yt/analysis_modules/cosmological_observation/light_ray/light_ray.py
+++ b/yt/analysis_modules/cosmological_observation/light_ray/light_ray.py
@@ -35,21 +35,22 @@
 
 class LightRay(CosmologySplice):
     """
-    LightRay(parameter_filename, simulation_type=None,
+    LightRay(dataset/filename, simulation_type=None,
              near_redshift=None, far_redshift=None,
              use_minimum_datasets=True, deltaz_min=0.0,
              minimum_coherent_box_fraction=0.0,
              time_data=True, redshift_data=True,
              find_outputs=False, load_kwargs=None):
 
-    Create a LightRay object.  A light ray is much like a light cone,
-    in that it stacks together multiple datasets in order to extend a
-    redshift interval.  Unlike a light cone, which does randomly
-    oriented projections for each dataset, a light ray consists of
-    randomly oriented single rays.  The purpose of these is to create
-    synthetic QSO lines of sight.
-
-    Light rays can also be made from single datasets.
+    A LightRay object is a one-dimensional object representing the trajectory 
+    of a ray of light as it passes through one or more datasets (simple and
+    compound rays respectively).  One can sample any of the fields intersected
+    by the LightRay object as it passed through the dataset(s).
+    
+    For compound rays, the LightRay stacks together multiple datasets in a time
+    series in order to approximate a LightRay's path through a volume
+    and redshift interval larger than a single simulation data output.
+    The outcome is something akin to a synthetic QSO line of sight.
 
     Once the LightRay object is set up, use LightRay.make_light_ray to
     begin making rays.  Different randomizations can be created with a
@@ -57,31 +58,32 @@
 
     Parameters
     ----------
-    parameter_filename : string
-        The path to the simulation parameter file or dataset.
+    dataset/filename : string or dataset
+        For simple rays, one must pass either a loaded dataset object or
+        the path and filename of a dataset.
+        For compound rays, one must pass the path and filename of the simulation
+        parameter file.
     simulation_type : optional, string
-        The simulation type.  If None, the first argument is assumed to
-        refer to a single dataset.
+        This refers to the simulation frontend type.  Do not use for simple 
+        rays.
         Default: None
     near_redshift : optional, float
         The near (lowest) redshift for a light ray containing multiple
-        datasets.  Do not use if making a light ray from a single
-        dataset.
+        datasets.  Do not use for simple rays.
         Default: None
     far_redshift : optional, float
         The far (highest) redshift for a light ray containing multiple
-        datasets.  Do not use if making a light ray from a single
-        dataset.
+        datasets.  Do not use for simple rays.
         Default: None
     use_minimum_datasets : optional, bool
         If True, the minimum number of datasets is used to connect the
         initial and final redshift.  If false, the light ray solution
         will contain as many entries as possible within the redshift
-        interval.
+        interval.  Do not use for simple rays.
         Default: True.
     deltaz_min : optional, float
         Specifies the minimum :math:`\Delta z` between consecutive
-        datasets in the returned list.
+        datasets in the returned list.  Do not use for simple rays.
         Default: 0.0.
     minimum_coherent_box_fraction : optional, float
         Used with use_minimum_datasets set to False, this parameter
@@ -89,23 +91,26 @@
         before rerandomizing the projection axis and center.  This
         was invented to allow light rays with thin slices to sample
         coherent large scale structure, but in practice does not work
-        so well.  Try setting this parameter to 1 and see what happens.
+        so well.  Try setting this parameter to 1 and see what happens.  
+        Do not use for simple rays.
         Default: 0.0.
     time_data : optional, bool
         Whether or not to include time outputs when gathering
-        datasets for time series.
+        datasets for time series.  Do not use for simple rays.
         Default: True.
     redshift_data : optional, bool
         Whether or not to include redshift outputs when gathering
-        datasets for time series.
+        datasets for time series.  Do not use for simple rays.
         Default: True.
     find_outputs : optional, bool
         Whether or not to search for datasets in the current
-        directory.
+        directory.  Do not use for simple rays.
         Default: False.
     load_kwargs : optional, dict
-        Optional dictionary of kwargs to be passed to the "load"
-        function, appropriate for use of certain frontends.  E.g.
+        If you are passing a filename of a dataset to LightRay rather than an 
+        already loaded dataset, then you can optionally provide this dictionary 
+        as keywords when the dataset is loaded by yt with the "load" function.
+        Necessary for use with certain frontends.  E.g.
         Tipsy using "bounding_box"
         Gadget using "unit_base", etc.
         Default : None
@@ -281,7 +286,7 @@
         Create a light ray and get field values for each lixel.  A light
         ray consists of a list of field values for cells intersected by
         the ray and the path length of the ray through those cells.
-        Light ray data can be written out to an hdf5 file.
+        Light ray data must be written out to an hdf5 file.
 
         Parameters
         ----------


https://bitbucket.org/yt_analysis/yt/commits/50dba45ad90f/
Changeset:   50dba45ad90f
Branch:      yt
User:        chummels
Date:        2016-05-05 02:33:16+00:00
Summary:     Adding tests for light_ray analysis module.
Affected #:  2 files

diff -r 3d126df4b1b6d832cf447863c983e2ee80b6b562 -r 50dba45ad90f881fbf8d0cdb5097e65614fcdbf1 yt/analysis_modules/cosmological_observation/light_ray/tests/test_light_ray.py
--- /dev/null
+++ b/yt/analysis_modules/cosmological_observation/light_ray/tests/test_light_ray.py
@@ -0,0 +1,104 @@
+"""
+Unit test for the light_ray analysis module
+"""
+
+#-----------------------------------------------------------------------------
+# Copyright (c) 2016, yt Development Team.
+#
+# Distributed under the terms of the Modified BSD License.
+#
+# The full license is in the file COPYING.txt, distributed with this software.
+#-----------------------------------------------------------------------------
+
+import numpy as np
+from yt.testing import \
+    assert_allclose_units, requires_file, requires_module, \
+    assert_almost_equal
+from yt.analysis_modules.absorption_spectrum.absorption_line import \
+    voigt_old, voigt_scipy
+from yt.analysis_modules.absorption_spectrum.api import AbsorptionSpectrum
+from yt.analysis_modules.cosmological_observation.api import LightRay
+from yt.utilities.answer_testing.framework import \
+    GenericArrayTest, \
+    requires_answer_testing
+import tempfile
+import os
+import shutil
+from yt.utilities.on_demand_imports import \
+    _h5py as h5
+from yt import load
+
+
+COSMO_PLUS = "enzo_cosmology_plus/AMRCosmology.enzo"
+COSMO_PLUS_SINGLE = "enzo_cosmology_plus/RD0009/RD0009"
+
+
+ at requires_file(COSMO_PLUS)
+def test_light_ray_cosmo():
+    """
+    This test generates a cosmological light ray
+    """
+    # Set up in a temp dir
+    tmpdir = tempfile.mkdtemp()
+    curdir = os.getcwd()
+    os.chdir(tmpdir)
+
+    lr = LightRay(COSMO_PLUS, 'Enzo', 0.0, 0.03)
+
+    lr.make_light_ray(seed=1234567,
+                      fields=['temperature', 'density', 'H_number_density'],
+                      data_filename='lightray.h5')
+
+    # clean up
+    os.chdir(curdir)
+    shutil.rmtree(tmpdir)
+
+
+ at requires_file(COSMO_PLUS_SINGLE)
+def test_light_ray_non_cosmo():
+    """
+    This test generates a non-cosmological light ray
+    """
+
+    # Set up in a temp dir
+    tmpdir = tempfile.mkdtemp()
+    curdir = os.getcwd()
+    os.chdir(tmpdir)
+
+    lr = LightRay(COSMO_PLUS_SINGLE)
+
+    ray_start = [0,0,0]
+    ray_end = [1,1,1]
+    lr.make_light_ray(start_position=ray_start, end_position=ray_end,
+                      fields=['temperature', 'density', 'H_number_density'],
+                      data_filename='lightray.h5')
+
+    # clean up
+    os.chdir(curdir)
+    shutil.rmtree(tmpdir)
+
+ at requires_file(COSMO_PLUS_SINGLE)
+def test_light_ray_non_cosmo_from_dataset():
+    """
+    This test generates a non-cosmological light ray created from an already
+    loaded dataset
+    """
+
+    # Set up in a temp dir
+    tmpdir = tempfile.mkdtemp()
+    curdir = os.getcwd()
+    os.chdir(tmpdir)
+
+    ds = load(COSMO_PLUS_SINGLE)
+    lr = LightRay(ds)
+
+    ray_start = [0,0,0]
+    ray_end = [1,1,1]
+    lr.make_light_ray(start_position=ray_start, end_position=ray_end,
+                      fields=['temperature', 'density', 'H_number_density'],
+                      data_filename='lightray.h5')
+
+    # clean up
+    os.chdir(curdir)
+    shutil.rmtree(tmpdir)
+


https://bitbucket.org/yt_analysis/yt/commits/bfa7b16eb9e0/
Changeset:   bfa7b16eb9e0
Branch:      yt
User:        chummels
Date:        2016-05-05 02:36:39+00:00
Summary:     Updating cookbook recipe to reflect new way to generate LightRays
Affected #:  1 file

diff -r 50dba45ad90f881fbf8d0cdb5097e65614fcdbf1 -r bfa7b16eb9e0532758d2acc2e933c992731fc4e0 doc/source/cookbook/single_dataset_light_ray.py
--- a/doc/source/cookbook/single_dataset_light_ray.py
+++ b/doc/source/cookbook/single_dataset_light_ray.py
@@ -3,8 +3,8 @@
 from yt.analysis_modules.cosmological_observation.api import \
     LightRay
 
-fn = "IsolatedGalaxy/galaxy0030/galaxy0030"
-lr = LightRay(fn)
+ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030")
+lr = LightRay(ds)
 
 # With a single dataset, a start_position and
 # end_position or trajectory must be given.


https://bitbucket.org/yt_analysis/yt/commits/4afcca78a729/
Changeset:   4afcca78a729
Branch:      yt
User:        chummels
Date:        2016-05-05 05:01:55+00:00
Summary:     Correcting typo in light_ray cookbook recipe.
Affected #:  1 file

diff -r bfa7b16eb9e0532758d2acc2e933c992731fc4e0 -r 4afcca78a7295accb48d89ac746d37028c6af85b doc/source/cookbook/single_dataset_light_ray.py
--- a/doc/source/cookbook/single_dataset_light_ray.py
+++ b/doc/source/cookbook/single_dataset_light_ray.py
@@ -17,7 +17,6 @@
 
 # Optionally, we can now overplot this ray on a projection of the source
 # dataset
-ds = yt.load(fn)
 p = yt.ProjectionPlot(ds, 'z', 'density')
 p.annotate_ray(lr)
 p.save()


https://bitbucket.org/yt_analysis/yt/commits/fad103b9515d/
Changeset:   fad103b9515d
Branch:      yt
User:        chummels
Date:        2016-05-05 05:04:38+00:00
Summary:     Getting rid of extra unused imports in test_light_ray test.
Affected #:  1 file

diff -r 4afcca78a7295accb48d89ac746d37028c6af85b -r fad103b9515d94e3523bbf8785e3a98242d84d6e yt/analysis_modules/cosmological_observation/light_ray/tests/test_light_ray.py
--- a/yt/analysis_modules/cosmological_observation/light_ray/tests/test_light_ray.py
+++ b/yt/analysis_modules/cosmological_observation/light_ray/tests/test_light_ray.py
@@ -10,29 +10,17 @@
 # The full license is in the file COPYING.txt, distributed with this software.
 #-----------------------------------------------------------------------------
 
-import numpy as np
 from yt.testing import \
-    assert_allclose_units, requires_file, requires_module, \
-    assert_almost_equal
-from yt.analysis_modules.absorption_spectrum.absorption_line import \
-    voigt_old, voigt_scipy
-from yt.analysis_modules.absorption_spectrum.api import AbsorptionSpectrum
+    requires_file
 from yt.analysis_modules.cosmological_observation.api import LightRay
-from yt.utilities.answer_testing.framework import \
-    GenericArrayTest, \
-    requires_answer_testing
-import tempfile
 import os
 import shutil
-from yt.utilities.on_demand_imports import \
-    _h5py as h5
 from yt import load
-
+import tempfile
 
 COSMO_PLUS = "enzo_cosmology_plus/AMRCosmology.enzo"
 COSMO_PLUS_SINGLE = "enzo_cosmology_plus/RD0009/RD0009"
 
-
 @requires_file(COSMO_PLUS)
 def test_light_ray_cosmo():
     """


https://bitbucket.org/yt_analysis/yt/commits/c390d655f2ff/
Changeset:   c390d655f2ff
Branch:      yt
User:        chummels
Date:        2016-05-06 00:16:24+00:00
Summary:     Correcting problems pointed out in PR comments.
Affected #:  1 file

diff -r fad103b9515d94e3523bbf8785e3a98242d84d6e -r c390d655f2ffd8dce3e49bba11ad7cae2ffb68d3 yt/analysis_modules/cosmological_observation/light_ray/light_ray.py
--- a/yt/analysis_modules/cosmological_observation/light_ray/light_ray.py
+++ b/yt/analysis_modules/cosmological_observation/light_ray/light_ray.py
@@ -35,13 +35,6 @@
 
 class LightRay(CosmologySplice):
     """
-    LightRay(dataset/filename, simulation_type=None,
-             near_redshift=None, far_redshift=None,
-             use_minimum_datasets=True, deltaz_min=0.0,
-             minimum_coherent_box_fraction=0.0,
-             time_data=True, redshift_data=True,
-             find_outputs=False, load_kwargs=None):
-
     A LightRay object is a one-dimensional object representing the trajectory 
     of a ray of light as it passes through one or more datasets (simple and
     compound rays respectively).  One can sample any of the fields intersected
@@ -58,10 +51,10 @@
 
     Parameters
     ----------
-    dataset/filename : string or dataset
-        For simple rays, one must pass either a loaded dataset object or
-        the path and filename of a dataset.
-        For compound rays, one must pass the path and filename of the simulation
+    parameter_filename : string or :class:`yt.data_objects.static_output.Dataset`
+        For simple rays, one may pass either a loaded dataset object or
+        the filename of a dataset.
+        For compound rays, one must pass the filename of the simulation
         parameter file.
     simulation_type : optional, string
         This refers to the simulation frontend type.  Do not use for simple 
@@ -144,11 +137,11 @@
         # Make a light ray from a single, given dataset: #1, #2
         if simulation_type is None:     
             self.simulation_type = simulation_type
-            if isinstance(parameter_filename, Dataset):
-                self.ds = parameter_filename
+            if isinstance(self.parameter_filename, Dataset):
+                self.ds = self.parameter_filename
                 self.parameter_filename = self.ds.basename
-            elif isinstance(parameter_filename, str):
-                self.ds = load(parameter_filename, **self.load_kwargs)
+            elif isinstance(self.parameter_filename, str):
+                self.ds = load(self.parameter_filename, **self.load_kwargs)
             if self.ds.cosmological_simulation:
                 redshift = self.ds.current_redshift
                 self.cosmology = Cosmology(
@@ -158,14 +151,15 @@
                     unit_registry=self.ds.unit_registry)
             else:
                 redshift = 0.
-            self.light_ray_solution.append({"filename": parameter_filename,
+            self.light_ray_solution.append({"filename": self.parameter_filename,
                                             "redshift": redshift})
 
         # Make a light ray from a simulation time-series. #3
         else:
             self.ds = None
+            assert isinstance(self.parameter_filename, str)
             # Get list of datasets for light ray solution.
-            CosmologySplice.__init__(self, parameter_filename, simulation_type,
+            CosmologySplice.__init__(self, self.parameter_filename, simulation_type,
                                      find_outputs=find_outputs)
             self.light_ray_solution = \
               self.create_cosmology_splice(self.near_redshift, self.far_redshift,


https://bitbucket.org/yt_analysis/yt/commits/75ae4d87e5bf/
Changeset:   75ae4d87e5bf
Branch:      yt
User:        chummels
Date:        2016-05-06 00:18:09+00:00
Summary:     Updating LightRay tests to not have a global yt import.
Affected #:  1 file

diff -r c390d655f2ffd8dce3e49bba11ad7cae2ffb68d3 -r 75ae4d87e5bfdbaf28159be0ce89af021121c4bd yt/analysis_modules/cosmological_observation/light_ray/tests/test_light_ray.py
--- a/yt/analysis_modules/cosmological_observation/light_ray/tests/test_light_ray.py
+++ b/yt/analysis_modules/cosmological_observation/light_ray/tests/test_light_ray.py
@@ -15,7 +15,7 @@
 from yt.analysis_modules.cosmological_observation.api import LightRay
 import os
 import shutil
-from yt import load
+from yt.utilities.answer_testing.framework import data_dir_load
 import tempfile
 
 COSMO_PLUS = "enzo_cosmology_plus/AMRCosmology.enzo"
@@ -77,7 +77,7 @@
     curdir = os.getcwd()
     os.chdir(tmpdir)
 
-    ds = load(COSMO_PLUS_SINGLE)
+    ds = data_dir_load(COSMO_PLUS_SINGLE)
     lr = LightRay(ds)
 
     ray_start = [0,0,0]


https://bitbucket.org/yt_analysis/yt/commits/3941e80752c7/
Changeset:   3941e80752c7
Branch:      yt
User:        chummels
Date:        2016-05-06 00:18:45+00:00
Summary:     Merging with tip.
Affected #:  2 files

diff -r 75ae4d87e5bfdbaf28159be0ce89af021121c4bd -r 3941e80752c732b9f0a58148610131764632a5a3 yt/geometry/oct_container.pyx
--- a/yt/geometry/oct_container.pyx
+++ b/yt/geometry/oct_container.pyx
@@ -317,6 +317,41 @@
         oinfo.level = level
         return cur
 
+    def locate_positions(self, np.float64_t[:,:] positions):
+        """
+        This routine, meant to be called by other internal routines, returns a
+        list of oct IDs and a dictionary of Oct info for all the positions
+        supplied.  Positions must be in code_length.
+        """
+        cdef np.float64_t factor = (1 << self.oref)
+        cdef dict all_octs = {}
+        cdef OctInfo oi
+        cdef Oct* o = NULL
+        cdef np.float64_t pos[3]
+        cdef np.ndarray[np.uint8_t, ndim=1] recorded
+        cdef np.ndarray[np.int64_t, ndim=1] oct_id
+        oct_id = np.ones(positions.shape[0], dtype="int64") * -1
+        recorded = np.zeros(self.nocts, dtype="uint8")
+        cdef np.int64_t i, j, k
+        for i in range(positions.shape[0]):
+            for j in range(3):
+                pos[j] = positions[i,j]
+            o = self.get(pos, &oi)
+            if o == NULL:
+                raise RuntimeError
+            if recorded[o.domain_ind] == 0:
+                left_edge = np.asarray(<np.float64_t[:3]>oi.left_edge).copy()
+                dds = np.asarray(<np.float64_t[:3]>oi.dds).copy()
+                right_edge = left_edge + dds*factor
+                all_octs[o.domain_ind] = dict(
+                    left_edge = left_edge,
+                    right_edge = right_edge,
+                    level = oi.level
+                )
+                recorded[o.domain_ind] = 1
+            oct_id[i] = o.domain_ind
+        return oct_id, all_octs
+
     def domain_identify(self, SelectorObject selector):
         cdef np.ndarray[np.uint8_t, ndim=1] domain_mask
         domain_mask = np.zeros(self.num_domains, dtype="uint8")

diff -r 75ae4d87e5bfdbaf28159be0ce89af021121c4bd -r 3941e80752c732b9f0a58148610131764632a5a3 yt/geometry/tests/test_particle_octree.py
--- a/yt/geometry/tests/test_particle_octree.py
+++ b/yt/geometry/tests/test_particle_octree.py
@@ -209,6 +209,24 @@
         i[0](*i[1:])
     time.sleep(1)
 
+def test_position_location():
+    np.random.seed(int(0x4d3d3d3))
+    pos = np.random.normal(0.5, scale=0.05, size=(NPART,3)) * (DRE-DLE) + DLE
+    # Now convert to integers
+    data = {}
+    bbox = []
+    for i, ax in enumerate('xyz'):
+        np.clip(pos[:,i], DLE[i], DRE[i], pos[:,i])
+        bbox.append([DLE[i], DRE[i]])
+        data["particle_position_%s" % ax] = pos[:,i]
+    bbox = np.array(bbox)
+    ds = load_particles(data, 1.0, bbox = bbox, over_refine_factor = 2)
+    oct_id, all_octs = ds.index.oct_handler.locate_positions(pos)
+    for oi in sorted(all_octs):
+        this_oct = pos[oct_id == oi]
+        assert(np.all(this_oct >= all_octs[oi]["left_edge"]))
+        assert(np.all(this_oct <= all_octs[oi]["right_edge"]))
+
 os33 = "snapshot_033/snap_033.0.hdf5"
 @requires_file(os33)
 def test_get_smallest_dx():


https://bitbucket.org/yt_analysis/yt/commits/5ffd0fbe9057/
Changeset:   5ffd0fbe9057
Branch:      yt
User:        ngoldbaum
Date:        2016-05-11 19:26:20+00:00
Summary:     Merged in chummels/yt (pull request #2158)

Enabling LightRay to accept loaded datasets instead of just filenames
Affected #:  4 files

diff -r de456d1efc0ecd2faa73ec9a309a40c5ee1ce393 -r 5ffd0fbe9057407dbb37fa2225906315695d569a doc/source/cookbook/single_dataset_light_ray.py
--- a/doc/source/cookbook/single_dataset_light_ray.py
+++ b/doc/source/cookbook/single_dataset_light_ray.py
@@ -3,8 +3,8 @@
 from yt.analysis_modules.cosmological_observation.api import \
     LightRay
 
-fn = "IsolatedGalaxy/galaxy0030/galaxy0030"
-lr = LightRay(fn)
+ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030")
+lr = LightRay(ds)
 
 # With a single dataset, a start_position and
 # end_position or trajectory must be given.
@@ -17,7 +17,6 @@
 
 # Optionally, we can now overplot this ray on a projection of the source
 # dataset
-ds = yt.load(fn)
 p = yt.ProjectionPlot(ds, 'z', 'density')
 p.annotate_ray(lr)
 p.save()

diff -r de456d1efc0ecd2faa73ec9a309a40c5ee1ce393 -r 5ffd0fbe9057407dbb37fa2225906315695d569a yt/analysis_modules/cosmological_observation/light_ray/light_ray.py
--- a/yt/analysis_modules/cosmological_observation/light_ray/light_ray.py
+++ b/yt/analysis_modules/cosmological_observation/light_ray/light_ray.py
@@ -31,24 +31,19 @@
     parallel_objects, \
     parallel_root_only
 from yt.utilities.physical_constants import speed_of_light_cgs
+from yt.data_objects.static_output import Dataset
 
 class LightRay(CosmologySplice):
     """
-    LightRay(parameter_filename, simulation_type=None,
-             near_redshift=None, far_redshift=None,
-             use_minimum_datasets=True, deltaz_min=0.0,
-             minimum_coherent_box_fraction=0.0,
-             time_data=True, redshift_data=True,
-             find_outputs=False, load_kwargs=None):
-
-    Create a LightRay object.  A light ray is much like a light cone,
-    in that it stacks together multiple datasets in order to extend a
-    redshift interval.  Unlike a light cone, which does randomly
-    oriented projections for each dataset, a light ray consists of
-    randomly oriented single rays.  The purpose of these is to create
-    synthetic QSO lines of sight.
-
-    Light rays can also be made from single datasets.
+    A LightRay object is a one-dimensional object representing the trajectory 
+    of a ray of light as it passes through one or more datasets (simple and
+    compound rays respectively).  One can sample any of the fields intersected
+    by the LightRay object as it passed through the dataset(s).
+    
+    For compound rays, the LightRay stacks together multiple datasets in a time
+    series in order to approximate a LightRay's path through a volume
+    and redshift interval larger than a single simulation data output.
+    The outcome is something akin to a synthetic QSO line of sight.
 
     Once the LightRay object is set up, use LightRay.make_light_ray to
     begin making rays.  Different randomizations can be created with a
@@ -56,31 +51,32 @@
 
     Parameters
     ----------
-    parameter_filename : string
-        The path to the simulation parameter file or dataset.
+    parameter_filename : string or :class:`yt.data_objects.static_output.Dataset`
+        For simple rays, one may pass either a loaded dataset object or
+        the filename of a dataset.
+        For compound rays, one must pass the filename of the simulation
+        parameter file.
     simulation_type : optional, string
-        The simulation type.  If None, the first argument is assumed to
-        refer to a single dataset.
+        This refers to the simulation frontend type.  Do not use for simple 
+        rays.
         Default: None
     near_redshift : optional, float
         The near (lowest) redshift for a light ray containing multiple
-        datasets.  Do not use if making a light ray from a single
-        dataset.
+        datasets.  Do not use for simple rays.
         Default: None
     far_redshift : optional, float
         The far (highest) redshift for a light ray containing multiple
-        datasets.  Do not use if making a light ray from a single
-        dataset.
+        datasets.  Do not use for simple rays.
         Default: None
     use_minimum_datasets : optional, bool
         If True, the minimum number of datasets is used to connect the
         initial and final redshift.  If false, the light ray solution
         will contain as many entries as possible within the redshift
-        interval.
+        interval.  Do not use for simple rays.
         Default: True.
     deltaz_min : optional, float
         Specifies the minimum :math:`\Delta z` between consecutive
-        datasets in the returned list.
+        datasets in the returned list.  Do not use for simple rays.
         Default: 0.0.
     minimum_coherent_box_fraction : optional, float
         Used with use_minimum_datasets set to False, this parameter
@@ -88,23 +84,26 @@
         before rerandomizing the projection axis and center.  This
         was invented to allow light rays with thin slices to sample
         coherent large scale structure, but in practice does not work
-        so well.  Try setting this parameter to 1 and see what happens.
+        so well.  Try setting this parameter to 1 and see what happens.  
+        Do not use for simple rays.
         Default: 0.0.
     time_data : optional, bool
         Whether or not to include time outputs when gathering
-        datasets for time series.
+        datasets for time series.  Do not use for simple rays.
         Default: True.
     redshift_data : optional, bool
         Whether or not to include redshift outputs when gathering
-        datasets for time series.
+        datasets for time series.  Do not use for simple rays.
         Default: True.
     find_outputs : optional, bool
         Whether or not to search for datasets in the current
-        directory.
+        directory.  Do not use for simple rays.
         Default: False.
     load_kwargs : optional, dict
-        Optional dictionary of kwargs to be passed to the "load"
-        function, appropriate for use of certain frontends.  E.g.
+        If you are passing a filename of a dataset to LightRay rather than an 
+        already loaded dataset, then you can optionally provide this dictionary 
+        as keywords when the dataset is loaded by yt with the "load" function.
+        Necessary for use with certain frontends.  E.g.
         Tipsy using "bounding_box"
         Gadget using "unit_base", etc.
         Default : None
@@ -130,26 +129,37 @@
         self.light_ray_solution = []
         self._data = {}
 
-        # Make a light ray from a single, given dataset.
-        if simulation_type is None:
+        # The options here are:
+        # 1) User passed us a dataset: use it to make a simple ray
+        # 2) User passed us a dataset filename: use it to make a simple ray
+        # 3) User passed us a simulation filename: use it to make a compound ray
+
+        # Make a light ray from a single, given dataset: #1, #2
+        if simulation_type is None:     
             self.simulation_type = simulation_type
-            ds = load(parameter_filename, **self.load_kwargs)
-            if ds.cosmological_simulation:
-                redshift = ds.current_redshift
+            if isinstance(self.parameter_filename, Dataset):
+                self.ds = self.parameter_filename
+                self.parameter_filename = self.ds.basename
+            elif isinstance(self.parameter_filename, str):
+                self.ds = load(self.parameter_filename, **self.load_kwargs)
+            if self.ds.cosmological_simulation:
+                redshift = self.ds.current_redshift
                 self.cosmology = Cosmology(
-                    hubble_constant=ds.hubble_constant,
-                    omega_matter=ds.omega_matter,
-                    omega_lambda=ds.omega_lambda,
-                    unit_registry=ds.unit_registry)
+                    hubble_constant=self.ds.hubble_constant,
+                    omega_matter=self.ds.omega_matter,
+                    omega_lambda=self.ds.omega_lambda,
+                    unit_registry=self.ds.unit_registry)
             else:
                 redshift = 0.
-            self.light_ray_solution.append({"filename": parameter_filename,
+            self.light_ray_solution.append({"filename": self.parameter_filename,
                                             "redshift": redshift})
 
-        # Make a light ray from a simulation time-series.
+        # Make a light ray from a simulation time-series. #3
         else:
+            self.ds = None
+            assert isinstance(self.parameter_filename, str)
             # Get list of datasets for light ray solution.
-            CosmologySplice.__init__(self, parameter_filename, simulation_type,
+            CosmologySplice.__init__(self, self.parameter_filename, simulation_type,
                                      find_outputs=find_outputs)
             self.light_ray_solution = \
               self.create_cosmology_splice(self.near_redshift, self.far_redshift,
@@ -270,7 +280,7 @@
         Create a light ray and get field values for each lixel.  A light
         ray consists of a list of field values for cells intersected by
         the ray and the path length of the ray through those cells.
-        Light ray data can be written out to an hdf5 file.
+        Light ray data must be written out to an hdf5 file.
 
         Parameters
         ----------
@@ -383,8 +393,12 @@
                                                        storage=all_ray_storage,
                                                        njobs=njobs):
 
-            # Load dataset for segment.
-            ds = load(my_segment['filename'], **self.load_kwargs)
+            # In case of simple rays, use the already loaded dataset: self.ds, 
+            # otherwise, load dataset for segment.
+            if self.ds is None:
+                ds = load(my_segment['filename'], **self.load_kwargs)
+            else:
+                ds = self.ds
 
             my_segment['unique_identifier'] = ds.unique_identifier
             if redshift is not None:
@@ -555,7 +569,7 @@
         Write light ray data to hdf5 file.
         """
         if self.simulation_type is None:
-            ds = load(self.parameter_filename, **self.load_kwargs)
+            ds = self.ds
         else:
             ds = {}
             ds["dimensionality"] = self.simulation.dimensionality

diff -r de456d1efc0ecd2faa73ec9a309a40c5ee1ce393 -r 5ffd0fbe9057407dbb37fa2225906315695d569a yt/analysis_modules/cosmological_observation/light_ray/tests/test_light_ray.py
--- /dev/null
+++ b/yt/analysis_modules/cosmological_observation/light_ray/tests/test_light_ray.py
@@ -0,0 +1,92 @@
+"""
+Unit test for the light_ray analysis module
+"""
+
+#-----------------------------------------------------------------------------
+# Copyright (c) 2016, yt Development Team.
+#
+# Distributed under the terms of the Modified BSD License.
+#
+# The full license is in the file COPYING.txt, distributed with this software.
+#-----------------------------------------------------------------------------
+
+from yt.testing import \
+    requires_file
+from yt.analysis_modules.cosmological_observation.api import LightRay
+import os
+import shutil
+from yt.utilities.answer_testing.framework import data_dir_load
+import tempfile
+
+COSMO_PLUS = "enzo_cosmology_plus/AMRCosmology.enzo"
+COSMO_PLUS_SINGLE = "enzo_cosmology_plus/RD0009/RD0009"
+
+ at requires_file(COSMO_PLUS)
+def test_light_ray_cosmo():
+    """
+    This test generates a cosmological light ray
+    """
+    # Set up in a temp dir
+    tmpdir = tempfile.mkdtemp()
+    curdir = os.getcwd()
+    os.chdir(tmpdir)
+
+    lr = LightRay(COSMO_PLUS, 'Enzo', 0.0, 0.03)
+
+    lr.make_light_ray(seed=1234567,
+                      fields=['temperature', 'density', 'H_number_density'],
+                      data_filename='lightray.h5')
+
+    # clean up
+    os.chdir(curdir)
+    shutil.rmtree(tmpdir)
+
+
+ at requires_file(COSMO_PLUS_SINGLE)
+def test_light_ray_non_cosmo():
+    """
+    This test generates a non-cosmological light ray
+    """
+
+    # Set up in a temp dir
+    tmpdir = tempfile.mkdtemp()
+    curdir = os.getcwd()
+    os.chdir(tmpdir)
+
+    lr = LightRay(COSMO_PLUS_SINGLE)
+
+    ray_start = [0,0,0]
+    ray_end = [1,1,1]
+    lr.make_light_ray(start_position=ray_start, end_position=ray_end,
+                      fields=['temperature', 'density', 'H_number_density'],
+                      data_filename='lightray.h5')
+
+    # clean up
+    os.chdir(curdir)
+    shutil.rmtree(tmpdir)
+
+ at requires_file(COSMO_PLUS_SINGLE)
+def test_light_ray_non_cosmo_from_dataset():
+    """
+    This test generates a non-cosmological light ray created from an already
+    loaded dataset
+    """
+
+    # Set up in a temp dir
+    tmpdir = tempfile.mkdtemp()
+    curdir = os.getcwd()
+    os.chdir(tmpdir)
+
+    ds = data_dir_load(COSMO_PLUS_SINGLE)
+    lr = LightRay(ds)
+
+    ray_start = [0,0,0]
+    ray_end = [1,1,1]
+    lr.make_light_ray(start_position=ray_start, end_position=ray_end,
+                      fields=['temperature', 'density', 'H_number_density'],
+                      data_filename='lightray.h5')
+
+    # clean up
+    os.chdir(curdir)
+    shutil.rmtree(tmpdir)
+

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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.spacepope.org/pipermail/yt-svn-spacepope.org/attachments/20160511/b53e473a/attachment-0002.htm>


More information about the yt-svn mailing list