[yt-svn] commit/yt: 9 new changesets
commits-noreply at bitbucket.org
commits-noreply at bitbucket.org
Wed Mar 23 13:55:47 PDT 2016
9 new commits in yt:
http://link.bitbucket.org/wf/click?upn=8USRlNyft-2BCzk2l4Ywl6gDx2lD2xxoS9E7MwXb2SMR-2BXcTD42YocdnOFkyGBVHOUkzHY-2FbmFICjM5L-2BBCzVmMcg1h6BzxZOgVlNF5ciqKXs-3D_ll4ctv0L-2ByeRZFC1LslHcg6aJmnQ70VruLbmeLQr27Aj2-2FK8naRflL58kCj2hbg1VA4Edf0afvjvTnnfHsAVkSZO9g5V52v7nHD8XiENND1oTP19OYIzUOhzjWZD9QIW1jAt4ZQXpuJ4GSTOtwBadNXWePxDM4gKz-2FPWaC7qaFhpi9tJJbVMFydwXxdgfp8viEqR7vf5R5Y-2F-2F2SgL0vslyBNgQV7-2FfX9nXzxOU3-2Fhj4-3D
Changeset: 6f895adc2643
Branch: yt
User: brittonsmith
Date: 2016-03-21 20:03:13+00:00
Summary: Adding analysis recipes.
Affected #: 3 files
diff -r e870ed5eb0e897bbaf4be9da9c78dbf0e0fcdd42 -r 6f895adc26439bc216158de7467d1a83aca7774f yt/analysis_modules/halo_analysis/halo_callbacks.py
--- a/yt/analysis_modules/halo_analysis/halo_callbacks.py
+++ b/yt/analysis_modules/halo_analysis/halo_callbacks.py
@@ -76,7 +76,7 @@
factor : float
Factor to be multiplied by the base radius for defining
the radius of the sphere.
- Defautl: 1.0.
+ Default: 1.0.
field_parameters : dict
Dictionary of field parameters to be set with the sphere
created.
@@ -166,8 +166,7 @@
bin_fields : list of strings
The binning fields for the profile.
profile_fields : string or list of strings
- The fields to be propython
- filed.
+ The fields to be profiled.
n_bins : int or list of ints
The number of bins in each dimension. If None, 32 bins for
each bin are used for each bin field.
diff -r e870ed5eb0e897bbaf4be9da9c78dbf0e0fcdd42 -r 6f895adc26439bc216158de7467d1a83aca7774f yt/analysis_modules/halo_analysis/halo_catalog.py
--- a/yt/analysis_modules/halo_analysis/halo_catalog.py
+++ b/yt/analysis_modules/halo_analysis/halo_catalog.py
@@ -35,6 +35,8 @@
finding_method_registry
from .halo_quantities import \
quantity_registry
+from .halo_recipes import \
+ recipe_registry
class HaloCatalog(ParallelAnalysisInterface):
r"""Create a HaloCatalog: an object that allows for the creation and association
@@ -257,6 +259,46 @@
halo_filter = filter_registry.find(halo_filter, *args, **kwargs)
self.actions.append(("filter", halo_filter))
+ def add_recipe(self, recipe, *args, **kwargs):
+ r"""
+ Add a recipe to the halo catalog action list.
+
+ A recipe is an operation consisting of a series of callbacks, quantities,
+ and/or filters called in succession. Recipes can be used to store a more
+ complex series of analysis tasks as a single entity.
+
+ Parameters
+ ----------
+ halo_recipe : string
+ The name of the recipe.
+
+ Examples
+ --------
+
+ >>> import yt
+ >>> from yt.analysis_modules.halo_analysis.api import HaloCatalog
+ >>>
+ >>> data_ds = yt.load('Enzo_64/RD0006/RedshiftOutput0006')
+ >>> halos_ds = yt.load('rockstar_halos/halos_0.0.bin')
+ >>> hc = HaloCatalog(data_ds=data_ds, halos_ds=halos_ds)
+ >>>
+ >>> # Filter out less massive halos
+ >>> hc.add_filter("quantity_value", "particle_mass", ">", 1e14, "Msun")
+ >>>
+ >>> # Calculate virial radii
+ >>> hc.add_recipe("calculate_virial_quantities", ["radius", "matter_mass"])
+ >>>
+ >>> hc.create()
+
+ Available Recipes
+ -----------------
+ calculate_virial_quantities
+
+ """
+
+ halo_recipe = recipe_registry.find(recipe, *args, **kwargs)
+ halo_recipe(self)
+
def create(self, save_halos=False, save_catalog=True, njobs=-1, dynamic=False):
r"""
Create the halo catalog given the callbacks, quantities, and filters that
diff -r e870ed5eb0e897bbaf4be9da9c78dbf0e0fcdd42 -r 6f895adc26439bc216158de7467d1a83aca7774f yt/analysis_modules/halo_analysis/halo_recipes.py
--- /dev/null
+++ b/yt/analysis_modules/halo_analysis/halo_recipes.py
@@ -0,0 +1,110 @@
+"""
+Halo recipe object
+
+
+
+"""
+
+#-----------------------------------------------------------------------------
+# 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
+import os
+
+from yt.utilities.logger import ytLogger as \
+ mylog
+from yt.utilities.operator_registry import \
+ OperatorRegistry
+
+recipe_registry = OperatorRegistry()
+
+def add_recipe(name, function):
+ recipe_registry[name] = HaloRecipe(function)
+
+class HaloRecipe(object):
+ r"""
+ A HaloRecipe is a function that minimally takes in a Halo object
+ and performs some analysis on it. This function may attach attributes
+ to the Halo object, write out data, etc, but does not return anything.
+ """
+ def __init__(self, function, args=None, kwargs=None):
+ self.function = function
+ self.args = args
+ if self.args is None: self.args = []
+ self.kwargs = kwargs
+ if self.kwargs is None: self.kwargs = {}
+
+ def __call__(self, halo_catalog):
+ return self.function(halo_catalog, *self.args, **self.kwargs)
+
+def calculate_virial_quantities(hc, fields,
+ weight_field=None, accumulation=True,
+ radius_field="virial_radius", factor=2.0,
+ overdensity_field=("gas", "overdensity"),
+ critical_overdensity=200):
+ r"""
+ Calculate virial quantities with the following procedure:
+ 1. Create a sphere data container.
+ 2. Create 1D radial profiles of overdensity and any requested fields.
+ 3. Call virial_quantities callback to interpolate profiles for
+ value of critical overdensity.
+ 4. Delete profile and sphere objects from halo.
+
+ Parameters
+ ----------
+ halo : Halo object
+ The Halo object to be provided by the HaloCatalog.
+ weight_field : string
+ Weight field for profiling.
+ Default : "cell_mass"
+ accumulation : bool or list of bools
+ If True, the profile values for a bin n are the cumulative sum of
+ all the values from bin 0 to n. If -True, the sum is reversed so
+ that the value for bin n is the cumulative sum from bin N (total bins)
+ to n. If the profile is 2D or 3D, a list of values can be given to
+ control the summation in each dimension independently.
+ Default: False.
+ radius_field : string
+ Field to be retrieved from the quantities dictionary as
+ the basis of the halo radius.
+ Default: "virial_radius".
+ factor : float
+ Factor to be multiplied by the base radius for defining
+ the radius of the sphere.
+ Default: 2.0.
+ overdensity_field : string or tuple of strings
+ The field used as the overdensity from which interpolation is done to
+ calculate virial quantities.
+ Default: ("gas", "overdensity")
+ critical_overdensity : float
+ The value of the overdensity at which to evaulate the virial quantities.
+ Overdensity is with respect to the critical density.
+ Default: 200
+
+ """
+
+ storage = "virial_quantities_profiles"
+ pfields = [field for field in fields if field != "radius"]
+
+ hc.add_callback("sphere", factor=factor)
+ if pfields:
+ hc.add_callback("profile", ["radius"], pfields,
+ weight_field=weight_field,
+ accumulation=accumulation,
+ storage=storage)
+ hc.add_callback("profile", ["radius"], [overdensity_field],
+ weight_field="cell_volume", accumulation=True,
+ storage=storage)
+ hc.add_callback("virial_quantities", fields,
+ overdensity_field=overdensity_field,
+ critical_overdensity=critical_overdensity,
+ profile_storage=storage)
+ hc.add_callback("delete_attribute", storage)
+ hc.add_callback("delete_attribute", "data_object")
+
+add_recipe("calculate_virial_quantities", calculate_virial_quantities)
http://link.bitbucket.org/wf/click?upn=8USRlNyft-2BCzk2l4Ywl6gDx2lD2xxoS9E7MwXb2SMR-2BXcTD42YocdnOFkyGBVHOUR8xtei8gmYohCcw0IKuwG15hMYXvW41CJ3v0Ff8dR5c-3D_ll4ctv0L-2ByeRZFC1LslHcg6aJmnQ70VruLbmeLQr27Aj2-2FK8naRflL58kCj2hbg1VA4Edf0afvjvTnnfHsAVkV5L5TXABL2WxpJAl9VS-2FeXkH7aTNAtV0y5yawL0p-2Fy5RlkDWGGJhQ3XpryB4pFazXjsBNV8VsKPRDeNu80Ry7JVlNHdVqjMn7GY8ikMbFM0Fz3lBDsSE9WQWDeYMVhPTMyiIzT9aYISFbLKGyXHhoQ-3D
Changeset: bbb57fb4b250
Branch: yt
User: brittonsmith
Date: 2016-03-21 20:20:24+00:00
Summary: Adding to docstring.
Affected #: 1 file
diff -r 6f895adc26439bc216158de7467d1a83aca7774f -r bbb57fb4b25044b8354847216c6d19d5ce0da430 yt/analysis_modules/halo_analysis/halo_recipes.py
--- a/yt/analysis_modules/halo_analysis/halo_recipes.py
+++ b/yt/analysis_modules/halo_analysis/halo_recipes.py
@@ -59,6 +59,8 @@
----------
halo : Halo object
The Halo object to be provided by the HaloCatalog.
+ fields: string or list of strings
+ The fields for which virial values are to be calculated.
weight_field : string
Weight field for profiling.
Default : "cell_mass"
http://link.bitbucket.org/wf/click?upn=8USRlNyft-2BCzk2l4Ywl6gDx2lD2xxoS9E7MwXb2SMR-2BXcTD42YocdnOFkyGBVHOUYjkhufGrNieTatHevOzFarlacdyEdWsQyrBTgKSAFVs-3D_ll4ctv0L-2ByeRZFC1LslHcg6aJmnQ70VruLbmeLQr27Aj2-2FK8naRflL58kCj2hbg1VA4Edf0afvjvTnnfHsAVkbo7xTiiNbITpucdZ24toHPQ-2Br7GZSjbaVk5TZGb-2BGSa52v1LrpWiFsC-2BmBSK3Gc7c-2B2wlpu-2F2-2BJS0m0SBPgNZDlcK2ud8zGPY5HWYmzmd1-2FzEs3VesuTC2-2BhxM1ufkBN-2FlxhhRezeXOeANmI4GOtFU-3D
Changeset: c9f355a81716
Branch: yt
User: brittonsmith
Date: 2016-03-22 02:18:54+00:00
Summary: Updating cookbook recipe.
Affected #: 1 file
diff -r bbb57fb4b25044b8354847216c6d19d5ce0da430 -r c9f355a817165e3ea1f4ab0cb0bc8e754b2c0710 doc/source/cookbook/halo_profiler.py
--- a/doc/source/cookbook/halo_profiler.py
+++ b/doc/source/cookbook/halo_profiler.py
@@ -12,26 +12,16 @@
# Filter out less massive halos
hc.add_filter("quantity_value", "particle_mass", ">", 1e14, "Msun")
-# attach a sphere object to each halo whose radius extends
-# to twice the radius of the halo
-hc.add_callback("sphere", factor=2.0)
+# This recipe creates a spherical data container, computes
+# radial profiles, and calculates r_200 and M_200.
+hc.add_recipe("calculate_virial_quantities", ["radius", "matter_mass"])
-# use the sphere to calculate radial profiles of gas density
-# weighted by cell volume in terms of the virial radius
-hc.add_callback("profile", ["radius"],
- [("gas", "overdensity")],
- weight_field="cell_volume",
- accumulation=True,
- storage="virial_quantities_profiles")
-
-
-hc.add_callback("virial_quantities", ["radius"],
- profile_storage="virial_quantities_profiles")
-hc.add_callback('delete_attribute', 'virial_quantities_profiles')
-
+# Create a sphere container with radius 5x r_200.
field_params = dict(virial_radius=('quantity', 'radius_200'))
hc.add_callback('sphere', radius_field='radius_200', factor=5,
field_parameters=field_params)
+
+# Compute profiles of T vs. r/r_200
hc.add_callback('profile', ['virial_radius_fraction'],
[('gas', 'temperature')],
storage='virial_profiles',
http://link.bitbucket.org/wf/click?upn=8USRlNyft-2BCzk2l4Ywl6gDx2lD2xxoS9E7MwXb2SMR-2BXcTD42YocdnOFkyGBVHOUIKsR1N6sI3agPebc5vJlYjU6KBNIzSKvXryVyTYTFwc-3D_ll4ctv0L-2ByeRZFC1LslHcg6aJmnQ70VruLbmeLQr27Aj2-2FK8naRflL58kCj2hbg1VA4Edf0afvjvTnnfHsAVkafQXiiPIeJ36iJ9Wa-2Bf9DDvNTx0XcrCRlVfWwOoJB0UOusESEGP1OA8L2ntTsqDeaFQIUAAGBPkvNErCEMpIx6cKdrTEM6vPnk6caBlmXRptDGMshHG6qeNgIQ8-2Bh8qmvapfI2EAMbKPBIiZemMlFc-3D
Changeset: f0035e2c421b
Branch: yt
User: brittonsmith
Date: 2016-03-22 02:22:38+00:00
Summary: Removing import.
Affected #: 1 file
diff -r c9f355a817165e3ea1f4ab0cb0bc8e754b2c0710 -r f0035e2c421b68f2928804fb96fe88eac4e27821 yt/analysis_modules/halo_analysis/halo_recipes.py
--- a/yt/analysis_modules/halo_analysis/halo_recipes.py
+++ b/yt/analysis_modules/halo_analysis/halo_recipes.py
@@ -16,8 +16,6 @@
import numpy as np
import os
-from yt.utilities.logger import ytLogger as \
- mylog
from yt.utilities.operator_registry import \
OperatorRegistry
http://link.bitbucket.org/wf/click?upn=8USRlNyft-2BCzk2l4Ywl6gDx2lD2xxoS9E7MwXb2SMR-2BXcTD42YocdnOFkyGBVHOUeTYwljk8QXNyRShB4vQLWfRbVljGp9dhvDEPV12v2Wo-3D_ll4ctv0L-2ByeRZFC1LslHcg6aJmnQ70VruLbmeLQr27Aj2-2FK8naRflL58kCj2hbg1VA4Edf0afvjvTnnfHsAVkUKZtuajnAfNfVyj4fWQyoG6ggWWAF17-2Bi5YZ5IWa92cNVUgz8Y7rMut8jBdqeFUpfinqt3aXJIR5n5t24BTFMc17UnneE5j68L630gDKeszd8knz6Sk-2Fe9n2ubByVxqYeWVKDNAJho3yzPF4o7LvhY-3D
Changeset: be024db57716
Branch: yt
User: brittonsmith
Date: 2016-03-22 15:36:19+00:00
Summary: Adding to api import.
Affected #: 1 file
diff -r f0035e2c421b68f2928804fb96fe88eac4e27821 -r be024db57716b453e7f14ad006ad2f9aa82a05f1 yt/analysis_modules/halo_analysis/api.py
--- a/yt/analysis_modules/halo_analysis/api.py
+++ b/yt/analysis_modules/halo_analysis/api.py
@@ -15,16 +15,19 @@
from .halo_catalog import \
- HaloCatalog
+ HaloCatalog
from .halo_callbacks import \
- add_callback
+ add_callback
from .halo_finding_methods import \
- add_finding_method
+ add_finding_method
from .halo_filters import \
- add_filter
+ add_filter
from .halo_quantities import \
- add_quantity
+ add_quantity
+
+from .halo_recipes import \
+ add_recipe
http://link.bitbucket.org/wf/click?upn=8USRlNyft-2BCzk2l4Ywl6gDx2lD2xxoS9E7MwXb2SMR-2BXcTD42YocdnOFkyGBVHOUX6m4ryOiTQ88NNwBSk4ig-2FpGm3X9BdjyapBT-2Fcj75d4-3D_ll4ctv0L-2ByeRZFC1LslHcg6aJmnQ70VruLbmeLQr27Aj2-2FK8naRflL58kCj2hbg1VA4Edf0afvjvTnnfHsAVkSATnIQazN4Dqg51vpMzjSKag6jQLn-2FjbvVw9GLzqZQeTkw5p1UrDlWqEZfC6v6vj1zN4xGjeylwMyP4Bhs4j5lf9fdR7xwIDjAHwCNtDwVOfy6BZnVrem2V6TmYF84IKFtTr8XcQSRTSgFXawYuLaM-3D
Changeset: 01579a237ef5
Branch: yt
User: brittonsmith
Date: 2016-03-22 15:36:42+00:00
Summary: Adding docs.
Affected #: 2 files
diff -r be024db57716b453e7f14ad006ad2f9aa82a05f1 -r 01579a237ef5787d3d70a791a071055e12609e19 doc/source/analyzing/analysis_modules/halo_catalogs.rst
--- a/doc/source/analyzing/analysis_modules/halo_catalogs.rst
+++ b/doc/source/analyzing/analysis_modules/halo_catalogs.rst
@@ -65,12 +65,13 @@
Analysis is done by adding actions to the
:class:`~yt.analysis_modules.halo_analysis.halo_catalog.HaloCatalog`.
-Each action is represented by a callback function that will be run on each halo.
-There are three types of actions:
+Each action is represented by a callback function that will be run on
+each halo. There are four types of actions:
* Filters
* Quantities
* Callbacks
+* Recipes
A list of all available filters, quantities, and callbacks can be found in
:ref:`halo_analysis_ref`.
@@ -213,6 +214,50 @@
# ... Later on in your script
hc.add_callback("my_callback")
+Recipes
+^^^^^^^
+
+Recipes allow you to create analysis tasks that consist of a series of
+callbacks, quantities, and filters that are run in succession. An example
+of this is
+:func:`yt.analysis_modules.halo_analysis.halo_recipes.calculate_virial_quantities`,
+which calculates virial quantities by first creating a sphere container,
+performing 1D radial profiles, and then interpolating to get values at a
+specified threshold overdensity. All of these operations are separate
+callbacks, but the recipes allow you to add them to your analysis pipeline
+with one call. For example,
+
+.. code-block:: python
+
+ hc.add_recipe("calculate_virial_quantities", ["radius", "matter_mass"])
+
+The available recipes are located in
+``yt/analysis_modules/halo_analysis/halo_recipes.py``. New recipes can be
+created in the following manner:
+
+.. code-block:: python
+
+ def my_recipe(halo_catalog, fields, weight_field=None):
+ # create a sphere
+ halo_catalog.add_callback("sphere")
+ # make profiles
+ halo_catalog.add_callback("profile", ["radius"], fields,
+ weight_field=weight_field)
+ # save the profile data
+ halo_catalog.add_callback("save_profiles", output_dir="profiles")
+
+ # add recipe to the registry of recipes
+ add_recipe("profile_and_save", my_recipe)
+
+
+ # ... Later on in your script
+ hc.add_recipe("profile_and_save", ["density", "temperature"],
+ weight_field="cell_mass")
+
+Note, that unlike callback, filter, and quantity functions that take a ``Halo``
+object as the first argument, recipe functions should take a ``HaloCatalog``
+object as the first argument.
+
Running Analysis
----------------
diff -r be024db57716b453e7f14ad006ad2f9aa82a05f1 -r 01579a237ef5787d3d70a791a071055e12609e19 doc/source/reference/api/api.rst
--- a/doc/source/reference/api/api.rst
+++ b/doc/source/reference/api/api.rst
@@ -472,6 +472,8 @@
~yt.analysis_modules.halo_analysis.halo_quantities.HaloQuantity
~yt.analysis_modules.halo_analysis.halo_quantities.bulk_velocity
~yt.analysis_modules.halo_analysis.halo_quantities.center_of_mass
+ ~yt.analysis_modules.halo_analysis.halo_recipes.HaloRecipe
+ ~yt.analysis_modules.halo_analysis.halo_recipes.calculate_virial_quantities
Halo Finding
^^^^^^^^^^^^
http://link.bitbucket.org/wf/click?upn=8USRlNyft-2BCzk2l4Ywl6gDx2lD2xxoS9E7MwXb2SMR-2BXcTD42YocdnOFkyGBVHOUA17u5AqTRMdB1Nn8TfiacjSYFYbINZ88sfpZNctV4Nc-3D_ll4ctv0L-2ByeRZFC1LslHcg6aJmnQ70VruLbmeLQr27Aj2-2FK8naRflL58kCj2hbg1VA4Edf0afvjvTnnfHsAVkbYCVB0B3GivfjdYZU-2BwlHARv8dcdl4oY2Syp98MRyVVbLh4SUqHNgEEHwDrZPsiUXzZN-2FXqxB-2Bew23D7v2tbk2t8JAZbbXTcfxQq-2BHoX-2BgeEa6Z3nsFxd-2FpWQX1tWycBab18gJO2hNc2BIHeNmyrEU-3D
Changeset: 29621968fb99
Branch: yt
User: brittonsmith
Date: 2016-03-22 17:18:14+00:00
Summary: Removing imports.
Affected #: 1 file
diff -r 01579a237ef5787d3d70a791a071055e12609e19 -r 29621968fb99123a5103613aab4f9a55a4898e57 yt/analysis_modules/halo_analysis/halo_recipes.py
--- a/yt/analysis_modules/halo_analysis/halo_recipes.py
+++ b/yt/analysis_modules/halo_analysis/halo_recipes.py
@@ -13,9 +13,6 @@
# The full license is in the file COPYING.txt, distributed with this software.
#-----------------------------------------------------------------------------
-import numpy as np
-import os
-
from yt.utilities.operator_registry import \
OperatorRegistry
http://link.bitbucket.org/wf/click?upn=8USRlNyft-2BCzk2l4Ywl6gDx2lD2xxoS9E7MwXb2SMR-2BXcTD42YocdnOFkyGBVHOUyN2-2BGU4KHRHgM4xwOs-2B5cHoZUsME-2F7YN5cEmWLk5sb0-3D_ll4ctv0L-2ByeRZFC1LslHcg6aJmnQ70VruLbmeLQr27Aj2-2FK8naRflL58kCj2hbg1VA4Edf0afvjvTnnfHsAVkSGuLnx3RgY31dNt1dFhfLTfO8ZknqWw-2F2-2FtfCgcCP-2FBMzEhKuI3bFSuQkhilzWymHCu8Cd3-2BV7QhM105wyqGQ7SnCV86FrLjkwwAW7DE7wGDbN5suIgqu8m2wxfR-2BzfXzPpHLBBEp8J2xFCeCPweV4-3D
Changeset: d7067e63cc21
Branch: yt
User: brittonsmith
Date: 2016-03-22 20:16:09+00:00
Summary: Changing how link shows up in docs.
Affected #: 1 file
diff -r 29621968fb99123a5103613aab4f9a55a4898e57 -r d7067e63cc21eb0a1c735a9203e19d97e13a79b5 doc/source/analyzing/analysis_modules/halo_catalogs.rst
--- a/doc/source/analyzing/analysis_modules/halo_catalogs.rst
+++ b/doc/source/analyzing/analysis_modules/halo_catalogs.rst
@@ -220,7 +220,7 @@
Recipes allow you to create analysis tasks that consist of a series of
callbacks, quantities, and filters that are run in succession. An example
of this is
-:func:`yt.analysis_modules.halo_analysis.halo_recipes.calculate_virial_quantities`,
+:func:`~yt.analysis_modules.halo_analysis.halo_recipes.calculate_virial_quantities`,
which calculates virial quantities by first creating a sphere container,
performing 1D radial profiles, and then interpolating to get values at a
specified threshold overdensity. All of these operations are separate
http://link.bitbucket.org/wf/click?upn=8USRlNyft-2BCzk2l4Ywl6gDx2lD2xxoS9E7MwXb2SMR-2BXcTD42YocdnOFkyGBVHOUtmqRdJv6-2BukVVr5hGmJmaVzeiOznziiy5NMixq1phf4-3D_ll4ctv0L-2ByeRZFC1LslHcg6aJmnQ70VruLbmeLQr27Aj2-2FK8naRflL58kCj2hbg1VA4Edf0afvjvTnnfHsAVkYlj6ubehhazH6qyIi4urr38OhQdPup-2FMWIHZcCUFfoUqR-2BeCTeftUCbGK7hwoZAwQkbjQduIG7WxcHC2SQFe6c8rBEi0sTIUgVummGfHELxOyUHRE6SnXjzLHH14XIeaaioS1ycCXBQH3Ub1EUTphA-3D
Changeset: 7d98d561e68c
Branch: yt
User: ngoldbaum
Date: 2016-03-23 20:55:41+00:00
Summary: Merged in brittonsmith/yt (pull request #2061)
Adding halo analysis recipes
Affected #: 7 files
diff -r ee78f27e30fbc234af0d10107fc4022f5d42d1d9 -r 7d98d561e68cde5957a324cf1c6d6e3d92b43674 doc/source/analyzing/analysis_modules/halo_catalogs.rst
--- a/doc/source/analyzing/analysis_modules/halo_catalogs.rst
+++ b/doc/source/analyzing/analysis_modules/halo_catalogs.rst
@@ -65,12 +65,13 @@
Analysis is done by adding actions to the
:class:`~yt.analysis_modules.halo_analysis.halo_catalog.HaloCatalog`.
-Each action is represented by a callback function that will be run on each halo.
-There are three types of actions:
+Each action is represented by a callback function that will be run on
+each halo. There are four types of actions:
* Filters
* Quantities
* Callbacks
+* Recipes
A list of all available filters, quantities, and callbacks can be found in
:ref:`halo_analysis_ref`.
@@ -213,6 +214,50 @@
# ... Later on in your script
hc.add_callback("my_callback")
+Recipes
+^^^^^^^
+
+Recipes allow you to create analysis tasks that consist of a series of
+callbacks, quantities, and filters that are run in succession. An example
+of this is
+:func:`~yt.analysis_modules.halo_analysis.halo_recipes.calculate_virial_quantities`,
+which calculates virial quantities by first creating a sphere container,
+performing 1D radial profiles, and then interpolating to get values at a
+specified threshold overdensity. All of these operations are separate
+callbacks, but the recipes allow you to add them to your analysis pipeline
+with one call. For example,
+
+.. code-block:: python
+
+ hc.add_recipe("calculate_virial_quantities", ["radius", "matter_mass"])
+
+The available recipes are located in
+``yt/analysis_modules/halo_analysis/halo_recipes.py``. New recipes can be
+created in the following manner:
+
+.. code-block:: python
+
+ def my_recipe(halo_catalog, fields, weight_field=None):
+ # create a sphere
+ halo_catalog.add_callback("sphere")
+ # make profiles
+ halo_catalog.add_callback("profile", ["radius"], fields,
+ weight_field=weight_field)
+ # save the profile data
+ halo_catalog.add_callback("save_profiles", output_dir="profiles")
+
+ # add recipe to the registry of recipes
+ add_recipe("profile_and_save", my_recipe)
+
+
+ # ... Later on in your script
+ hc.add_recipe("profile_and_save", ["density", "temperature"],
+ weight_field="cell_mass")
+
+Note, that unlike callback, filter, and quantity functions that take a ``Halo``
+object as the first argument, recipe functions should take a ``HaloCatalog``
+object as the first argument.
+
Running Analysis
----------------
diff -r ee78f27e30fbc234af0d10107fc4022f5d42d1d9 -r 7d98d561e68cde5957a324cf1c6d6e3d92b43674 doc/source/cookbook/halo_profiler.py
--- a/doc/source/cookbook/halo_profiler.py
+++ b/doc/source/cookbook/halo_profiler.py
@@ -12,26 +12,16 @@
# Filter out less massive halos
hc.add_filter("quantity_value", "particle_mass", ">", 1e14, "Msun")
-# attach a sphere object to each halo whose radius extends
-# to twice the radius of the halo
-hc.add_callback("sphere", factor=2.0)
+# This recipe creates a spherical data container, computes
+# radial profiles, and calculates r_200 and M_200.
+hc.add_recipe("calculate_virial_quantities", ["radius", "matter_mass"])
-# use the sphere to calculate radial profiles of gas density
-# weighted by cell volume in terms of the virial radius
-hc.add_callback("profile", ["radius"],
- [("gas", "overdensity")],
- weight_field="cell_volume",
- accumulation=True,
- storage="virial_quantities_profiles")
-
-
-hc.add_callback("virial_quantities", ["radius"],
- profile_storage="virial_quantities_profiles")
-hc.add_callback('delete_attribute', 'virial_quantities_profiles')
-
+# Create a sphere container with radius 5x r_200.
field_params = dict(virial_radius=('quantity', 'radius_200'))
hc.add_callback('sphere', radius_field='radius_200', factor=5,
field_parameters=field_params)
+
+# Compute profiles of T vs. r/r_200
hc.add_callback('profile', ['virial_radius_fraction'],
[('gas', 'temperature')],
storage='virial_profiles',
diff -r ee78f27e30fbc234af0d10107fc4022f5d42d1d9 -r 7d98d561e68cde5957a324cf1c6d6e3d92b43674 doc/source/reference/api/api.rst
--- a/doc/source/reference/api/api.rst
+++ b/doc/source/reference/api/api.rst
@@ -472,6 +472,8 @@
~yt.analysis_modules.halo_analysis.halo_quantities.HaloQuantity
~yt.analysis_modules.halo_analysis.halo_quantities.bulk_velocity
~yt.analysis_modules.halo_analysis.halo_quantities.center_of_mass
+ ~yt.analysis_modules.halo_analysis.halo_recipes.HaloRecipe
+ ~yt.analysis_modules.halo_analysis.halo_recipes.calculate_virial_quantities
Halo Finding
^^^^^^^^^^^^
diff -r ee78f27e30fbc234af0d10107fc4022f5d42d1d9 -r 7d98d561e68cde5957a324cf1c6d6e3d92b43674 yt/analysis_modules/halo_analysis/api.py
--- a/yt/analysis_modules/halo_analysis/api.py
+++ b/yt/analysis_modules/halo_analysis/api.py
@@ -15,16 +15,19 @@
from .halo_catalog import \
- HaloCatalog
+ HaloCatalog
from .halo_callbacks import \
- add_callback
+ add_callback
from .halo_finding_methods import \
- add_finding_method
+ add_finding_method
from .halo_filters import \
- add_filter
+ add_filter
from .halo_quantities import \
- add_quantity
+ add_quantity
+
+from .halo_recipes import \
+ add_recipe
diff -r ee78f27e30fbc234af0d10107fc4022f5d42d1d9 -r 7d98d561e68cde5957a324cf1c6d6e3d92b43674 yt/analysis_modules/halo_analysis/halo_callbacks.py
--- a/yt/analysis_modules/halo_analysis/halo_callbacks.py
+++ b/yt/analysis_modules/halo_analysis/halo_callbacks.py
@@ -76,7 +76,7 @@
factor : float
Factor to be multiplied by the base radius for defining
the radius of the sphere.
- Defautl: 1.0.
+ Default: 1.0.
field_parameters : dict
Dictionary of field parameters to be set with the sphere
created.
@@ -166,8 +166,7 @@
bin_fields : list of strings
The binning fields for the profile.
profile_fields : string or list of strings
- The fields to be propython
- filed.
+ The fields to be profiled.
n_bins : int or list of ints
The number of bins in each dimension. If None, 32 bins for
each bin are used for each bin field.
diff -r ee78f27e30fbc234af0d10107fc4022f5d42d1d9 -r 7d98d561e68cde5957a324cf1c6d6e3d92b43674 yt/analysis_modules/halo_analysis/halo_catalog.py
--- a/yt/analysis_modules/halo_analysis/halo_catalog.py
+++ b/yt/analysis_modules/halo_analysis/halo_catalog.py
@@ -35,6 +35,8 @@
finding_method_registry
from .halo_quantities import \
quantity_registry
+from .halo_recipes import \
+ recipe_registry
class HaloCatalog(ParallelAnalysisInterface):
r"""Create a HaloCatalog: an object that allows for the creation and association
@@ -257,6 +259,46 @@
halo_filter = filter_registry.find(halo_filter, *args, **kwargs)
self.actions.append(("filter", halo_filter))
+ def add_recipe(self, recipe, *args, **kwargs):
+ r"""
+ Add a recipe to the halo catalog action list.
+
+ A recipe is an operation consisting of a series of callbacks, quantities,
+ and/or filters called in succession. Recipes can be used to store a more
+ complex series of analysis tasks as a single entity.
+
+ Parameters
+ ----------
+ halo_recipe : string
+ The name of the recipe.
+
+ Examples
+ --------
+
+ >>> import yt
+ >>> from yt.analysis_modules.halo_analysis.api import HaloCatalog
+ >>>
+ >>> data_ds = yt.load('Enzo_64/RD0006/RedshiftOutput0006')
+ >>> halos_ds = yt.load('rockstar_halos/halos_0.0.bin')
+ >>> hc = HaloCatalog(data_ds=data_ds, halos_ds=halos_ds)
+ >>>
+ >>> # Filter out less massive halos
+ >>> hc.add_filter("quantity_value", "particle_mass", ">", 1e14, "Msun")
+ >>>
+ >>> # Calculate virial radii
+ >>> hc.add_recipe("calculate_virial_quantities", ["radius", "matter_mass"])
+ >>>
+ >>> hc.create()
+
+ Available Recipes
+ -----------------
+ calculate_virial_quantities
+
+ """
+
+ halo_recipe = recipe_registry.find(recipe, *args, **kwargs)
+ halo_recipe(self)
+
def create(self, save_halos=False, save_catalog=True, njobs=-1, dynamic=False):
r"""
Create the halo catalog given the callbacks, quantities, and filters that
diff -r ee78f27e30fbc234af0d10107fc4022f5d42d1d9 -r 7d98d561e68cde5957a324cf1c6d6e3d92b43674 yt/analysis_modules/halo_analysis/halo_recipes.py
--- /dev/null
+++ b/yt/analysis_modules/halo_analysis/halo_recipes.py
@@ -0,0 +1,107 @@
+"""
+Halo recipe object
+
+
+
+"""
+
+#-----------------------------------------------------------------------------
+# 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.utilities.operator_registry import \
+ OperatorRegistry
+
+recipe_registry = OperatorRegistry()
+
+def add_recipe(name, function):
+ recipe_registry[name] = HaloRecipe(function)
+
+class HaloRecipe(object):
+ r"""
+ A HaloRecipe is a function that minimally takes in a Halo object
+ and performs some analysis on it. This function may attach attributes
+ to the Halo object, write out data, etc, but does not return anything.
+ """
+ def __init__(self, function, args=None, kwargs=None):
+ self.function = function
+ self.args = args
+ if self.args is None: self.args = []
+ self.kwargs = kwargs
+ if self.kwargs is None: self.kwargs = {}
+
+ def __call__(self, halo_catalog):
+ return self.function(halo_catalog, *self.args, **self.kwargs)
+
+def calculate_virial_quantities(hc, fields,
+ weight_field=None, accumulation=True,
+ radius_field="virial_radius", factor=2.0,
+ overdensity_field=("gas", "overdensity"),
+ critical_overdensity=200):
+ r"""
+ Calculate virial quantities with the following procedure:
+ 1. Create a sphere data container.
+ 2. Create 1D radial profiles of overdensity and any requested fields.
+ 3. Call virial_quantities callback to interpolate profiles for
+ value of critical overdensity.
+ 4. Delete profile and sphere objects from halo.
+
+ Parameters
+ ----------
+ halo : Halo object
+ The Halo object to be provided by the HaloCatalog.
+ fields: string or list of strings
+ The fields for which virial values are to be calculated.
+ weight_field : string
+ Weight field for profiling.
+ Default : "cell_mass"
+ accumulation : bool or list of bools
+ If True, the profile values for a bin n are the cumulative sum of
+ all the values from bin 0 to n. If -True, the sum is reversed so
+ that the value for bin n is the cumulative sum from bin N (total bins)
+ to n. If the profile is 2D or 3D, a list of values can be given to
+ control the summation in each dimension independently.
+ Default: False.
+ radius_field : string
+ Field to be retrieved from the quantities dictionary as
+ the basis of the halo radius.
+ Default: "virial_radius".
+ factor : float
+ Factor to be multiplied by the base radius for defining
+ the radius of the sphere.
+ Default: 2.0.
+ overdensity_field : string or tuple of strings
+ The field used as the overdensity from which interpolation is done to
+ calculate virial quantities.
+ Default: ("gas", "overdensity")
+ critical_overdensity : float
+ The value of the overdensity at which to evaulate the virial quantities.
+ Overdensity is with respect to the critical density.
+ Default: 200
+
+ """
+
+ storage = "virial_quantities_profiles"
+ pfields = [field for field in fields if field != "radius"]
+
+ hc.add_callback("sphere", factor=factor)
+ if pfields:
+ hc.add_callback("profile", ["radius"], pfields,
+ weight_field=weight_field,
+ accumulation=accumulation,
+ storage=storage)
+ hc.add_callback("profile", ["radius"], [overdensity_field],
+ weight_field="cell_volume", accumulation=True,
+ storage=storage)
+ hc.add_callback("virial_quantities", fields,
+ overdensity_field=overdensity_field,
+ critical_overdensity=critical_overdensity,
+ profile_storage=storage)
+ hc.add_callback("delete_attribute", storage)
+ hc.add_callback("delete_attribute", "data_object")
+
+add_recipe("calculate_virial_quantities", calculate_virial_quantities)
Repository URL: http://link.bitbucket.org/wf/click?upn=8USRlNyft-2BCzk2l4Ywl6gDx2lD2xxoS9E7MwXb2SMR-2BI0v8SbQq-2B8-2FZaaHaJT85r_ll4ctv0L-2ByeRZFC1LslHcg6aJmnQ70VruLbmeLQr27Aj2-2FK8naRflL58kCj2hbg1VA4Edf0afvjvTnnfHsAVkWyEvqrxt8dULcE5h4GnW6DvuO7dUqEkQcPCAo6-2FauYY2JKJ2deFbfd20DjSOvQR6euip11b84dficVat6ZvxdYpFLROfC3GGb54QStfdmlffLgIadQ5VktQNmrUHR-2BigsvA2DWavhW7MZd4i4ZP8Ec-3D
--
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/20160323/06694c61/attachment.html>
More information about the yt-svn
mailing list