<html><body>
<p>9 new commits in yt:</p>
<p><a href="http://link.bitbucket.org/wf/click?upn=8USRlNyft-2BCzk2l4Ywl6gDx2lD2xxoS9E7MwXb2SMR-2BXcTD42YocdnOFkyGBVHOUkzHY-2FbmFICjM5L-2BBCzVmMcg1h6BzxZOgVlNF5ciqKXs-3D_ll4ctv0L-2ByeRZFC1LslHcg6aJmnQ70VruLbmeLQr27Aj2-2FK8naRflL58kCj2hbg1VA4Edf0afvjvTnnfHsAVkSv-2FLA-2FwhIGt4PFV-2BFpSxvaL48rkEu-2BS7NwuGLlI6Ru6nMcXUlRiw16aiwo2KE-2F4SHlb4P2aS7tkYCloDAk40wEGVfov7Co-2Bl7eBmXFZPuZfuoMzVpBmqlzOCsS-2BwdI9SXZalhMqfLxev5bbBMj3sro-3D">https://bitbucket.org/yt_analysis/yt/commits/6f895adc2643/</a> Changeset: 6f895adc2643 Branch: yt User: brittonsmith Date: 2016-03-21 20:03:13+00:00 Summary: Adding analysis recipes. Affected #: 3 files</p>
<p>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 @@</p>
<pre>factor : float
Factor to be multiplied by the base radius for defining
the radius of the sphere.</pre>
<ul><li><p>Defautl: 1.0.</p></li></ul>
<p>+ Default: 1.0.</p>
<pre>field_parameters : dict
Dictionary of field parameters to be set with the sphere
created.</pre>
<p>@@ -166,8 +166,7 @@</p>
<pre>bin_fields : list of strings
The binning fields for the profile.
profile_fields : string or list of strings</pre>
<ul><li><p>The fields to be propython</p></li>
<li><p>filed.</p></li></ul>
<p>+ The fields to be profiled.</p>
<pre>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.</pre>
<p>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 @@</p>
<pre> finding_method_registry
from .halo_quantities import \
quantity_registry</pre>
<p>+from .halo_recipes import \ + recipe_registry</p>
<pre>class HaloCatalog(ParallelAnalysisInterface):
r"""Create a HaloCatalog: an object that allows for the creation and association</pre>
<p>@@ -257,6 +259,46 @@</p>
<pre> halo_filter = filter_registry.find(halo_filter, *args, **kwargs)
self.actions.append(("filter", halo_filter))
</pre>
<p>+ 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) +</p>
<pre>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</pre>
<p>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 © 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)</p>
<p><a href="http://link.bitbucket.org/wf/click?upn=8USRlNyft-2BCzk2l4Ywl6gDx2lD2xxoS9E7MwXb2SMR-2BXcTD42YocdnOFkyGBVHOUR8xtei8gmYohCcw0IKuwG15hMYXvW41CJ3v0Ff8dR5c-3D_ll4ctv0L-2ByeRZFC1LslHcg6aJmnQ70VruLbmeLQr27Aj2-2FK8naRflL58kCj2hbg1VA4Edf0afvjvTnnfHsAVkZk-2ByF56uT40kMIXrHmEURIwmiTBZhBirRiDeqwBOS1FMsudtrjEwuEXi-2Fg4PuJTWc-2BLou2s6cAneRqorSGzrfgSUn0T2IpG927twyawSCkbLHn2stD9V9Ldj0yIf04Gg1DJz58X6YdELDkkCtQII58-3D">https://bitbucket.org/yt_analysis/yt/commits/bbb57fb4b250/</a> Changeset: bbb57fb4b250 Branch: yt User: brittonsmith Date: 2016-03-21 20:20:24+00:00 Summary: Adding to docstring. Affected #: 1 file</p>
<p>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 @@</p>
<pre>----------
halo : Halo object
The Halo object to be provided by the HaloCatalog.</pre>
<p>+ fields: string or list of strings + The fields for which virial values are to be calculated.</p>
<pre>weight_field : string
Weight field for profiling.
Default : "cell_mass"</pre>
<p><a href="http://link.bitbucket.org/wf/click?upn=8USRlNyft-2BCzk2l4Ywl6gDx2lD2xxoS9E7MwXb2SMR-2BXcTD42YocdnOFkyGBVHOUYjkhufGrNieTatHevOzFarlacdyEdWsQyrBTgKSAFVs-3D_ll4ctv0L-2ByeRZFC1LslHcg6aJmnQ70VruLbmeLQr27Aj2-2FK8naRflL58kCj2hbg1VA4Edf0afvjvTnnfHsAVkYW8a-2Bryp6jFhxRJ-2BU7yh0SWAXIf4EsxgGpc4LjF7-2BzHVjvVf-2FM-2FCcevciYoxVL5nBjXKGxvCpeem5qVuodogQnYxhiHi-2FKeQcaktA4Fi0DVJUcwzELTlAYqUP9eQovqN8Er0h-2Bc5yY03gsnhuGz3vs-3D">https://bitbucket.org/yt_analysis/yt/commits/c9f355a81716/</a> Changeset: c9f355a81716 Branch: yt User: brittonsmith Date: 2016-03-22 02:18:54+00:00 Summary: Updating cookbook recipe. Affected #: 1 file</p>
<p>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 @@</p>
<pre># Filter out less massive halos
hc.add_filter("quantity_value", "particle_mass", ">", 1e14, "Msun")
</pre>
<p>-# 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"])</p>
<p>-# 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"],</p>
<ul><li><p>[("gas", "overdensity")],</p></li>
<li><p>weight_field="cell_volume",</p></li>
<li><p>accumulation=True,</p></li>
<li><p>storage="virial_quantities_profiles")</p></li></ul>
<p>– – -hc.add_callback("virial_quantities", ["radius"],</p>
<ul><li><p>profile_storage="virial_quantities_profiles")</p></li></ul>
<p>-hc.add_callback('delete_attribute', ‘virial_quantities_profiles’) – +# Create a sphere container with radius 5x r_200.</p>
<pre>field_params = dict(virial_radius=('quantity', 'radius_200'))
hc.add_callback('sphere', radius_field='radius_200', factor=5,
field_parameters=field_params)</pre>
<p>+ +# Compute profiles of T vs. r/r_200</p>
<pre>hc.add_callback('profile', ['virial_radius_fraction'],
[('gas', 'temperature')],
storage='virial_profiles',</pre>
<p><a href="http://link.bitbucket.org/wf/click?upn=8USRlNyft-2BCzk2l4Ywl6gDx2lD2xxoS9E7MwXb2SMR-2BXcTD42YocdnOFkyGBVHOUIKsR1N6sI3agPebc5vJlYjU6KBNIzSKvXryVyTYTFwc-3D_ll4ctv0L-2ByeRZFC1LslHcg6aJmnQ70VruLbmeLQr27Aj2-2FK8naRflL58kCj2hbg1VA4Edf0afvjvTnnfHsAVkfM4zYwxQoZtXcCW90esH8InBrMgm4TqP5e-2FOnYkASOqN5B2bcT-2BFVEZtu3sA9z5jikT-2BQvJEhwpV58667YvcCnQVUCpGwAktYoJShQ8qaxhLYEQY6DsIvPAdOY-2BsL0WCTYrFt6v70lw3Jg9XAP3cGg-3D">https://bitbucket.org/yt_analysis/yt/commits/f0035e2c421b/</a> Changeset: f0035e2c421b Branch: yt User: brittonsmith Date: 2016-03-22 02:22:38+00:00 Summary: Removing import. Affected #: 1 file</p>
<p>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 @@</p>
<pre>import numpy as np
import os
</pre>
<p>-from yt.utilities.logger import ytLogger as \</p>
<ul><li><p>mylog</p></li></ul>
<pre>from yt.utilities.operator_registry import \
OperatorRegistry
</pre>
<p><a href="http://link.bitbucket.org/wf/click?upn=8USRlNyft-2BCzk2l4Ywl6gDx2lD2xxoS9E7MwXb2SMR-2BXcTD42YocdnOFkyGBVHOUeTYwljk8QXNyRShB4vQLWfRbVljGp9dhvDEPV12v2Wo-3D_ll4ctv0L-2ByeRZFC1LslHcg6aJmnQ70VruLbmeLQr27Aj2-2FK8naRflL58kCj2hbg1VA4Edf0afvjvTnnfHsAVkRfu7wvB4SF139LNqLBkiMReSehvwrpw3F4V2SH7N6lALgtkbZdZQaQy-2FGnSruOLH4kW4-2BZIhM6dT6mrlE1SVkvGioaMV1HupISD0cOC346IOQGJKiYKFYYGx07VRZgu-2Fy-2FGkBLmFVZU5Is5BuFeseQ-3D">https://bitbucket.org/yt_analysis/yt/commits/be024db57716/</a> Changeset: be024db57716 Branch: yt User: brittonsmith Date: 2016-03-22 15:36:19+00:00 Summary: Adding to api import. Affected #: 1 file</p>
<p>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 @@</p>
<pre>from .halo_catalog import \</pre>
<ul><li><p>HaloCatalog</p></li></ul>
<p>+ HaloCatalog</p>
<pre>from .halo_callbacks import \</pre>
<ul><li><p>add_callback</p></li></ul>
<p>+ add_callback</p>
<pre>from .halo_finding_methods import \</pre>
<ul><li><p>add_finding_method</p></li></ul>
<p>+ add_finding_method</p>
<pre>from .halo_filters import \</pre>
<ul><li><p>add_filter</p></li></ul>
<p>+ add_filter</p>
<pre>from .halo_quantities import \</pre>
<ul><li><p>add_quantity</p></li></ul>
<p>+ add_quantity + +from .halo_recipes import \ + add_recipe</p>
<p><a href="http://link.bitbucket.org/wf/click?upn=8USRlNyft-2BCzk2l4Ywl6gDx2lD2xxoS9E7MwXb2SMR-2BXcTD42YocdnOFkyGBVHOUX6m4ryOiTQ88NNwBSk4ig-2FpGm3X9BdjyapBT-2Fcj75d4-3D_ll4ctv0L-2ByeRZFC1LslHcg6aJmnQ70VruLbmeLQr27Aj2-2FK8naRflL58kCj2hbg1VA4Edf0afvjvTnnfHsAVkaBcdxlxnh8xyLZXaBK4V3IJ0Gu1tyoRhkvc8tCU9toquDAGyEhLlWunGkKSTFkd-2Bpp03mtkfG6U1aeUcSgSJ3-2FMo8xJHm-2F6QNZv-2FOyfKNqq4m-2F7W1u-2F1NHyMLab9gmpQqg59XN51vUSqmnGONCwosM-3D">https://bitbucket.org/yt_analysis/yt/commits/01579a237ef5/</a> Changeset: 01579a237ef5 Branch: yt User: brittonsmith Date: 2016-03-22 15:36:42+00:00 Summary: Adding docs. Affected #: 2 files</p>
<p>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 @@</p>
<pre>Analysis is done by adding actions to the
:class:`~yt.analysis_modules.halo_analysis.halo_catalog.HaloCatalog`.</pre>
<p>-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:</p>
<pre>* Filters
* Quantities
* Callbacks</pre>
<p>+* Recipes</p>
<pre>A list of all available filters, quantities, and callbacks can be found in
:ref:`halo_analysis_ref`.</pre>
<p>@@ -213,6 +214,50 @@</p>
<pre> # ... Later on in your script
hc.add_callback("my_callback")
</pre>
<p>+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. +</p>
<pre>Running Analysis
----------------
</pre>
<p>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 @@</p>
<pre>~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</pre>
<p>+ ~yt.analysis_modules.halo_analysis.halo_recipes.HaloRecipe + ~yt.analysis_modules.halo_analysis.halo_recipes.calculate_virial_quantities</p>
<pre>Halo Finding
^^^^^^^^^^^^</pre>
<p><a href="http://link.bitbucket.org/wf/click?upn=8USRlNyft-2BCzk2l4Ywl6gDx2lD2xxoS9E7MwXb2SMR-2BXcTD42YocdnOFkyGBVHOUA17u5AqTRMdB1Nn8TfiacjSYFYbINZ88sfpZNctV4Nc-3D_ll4ctv0L-2ByeRZFC1LslHcg6aJmnQ70VruLbmeLQr27Aj2-2FK8naRflL58kCj2hbg1VA4Edf0afvjvTnnfHsAVkY-2FQkM4CDNc1ni6diI-2Bzn-2FRZyj3xEeKvlv8NOYF6X6KwWV0UTSDI8EYZjh79W21u2PDY11Ddz1FjKwFxr2IpZkKE3GMefI-2FKX-2FjgWep0sFXFwshGHxHoPdrXO9fy1gGwnneOIoSyocSbLrIf6-2FteIPo-3D">https://bitbucket.org/yt_analysis/yt/commits/29621968fb99/</a> Changeset: 29621968fb99 Branch: yt User: brittonsmith Date: 2016-03-22 17:18:14+00:00 Summary: Removing imports. Affected #: 1 file</p>
<p>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 @@</p>
<pre># The full license is in the file COPYING.txt, distributed with this software.
#-----------------------------------------------------------------------------
</pre>
<p>-import numpy as np -import os –</p>
<pre>from yt.utilities.operator_registry import \
OperatorRegistry
</pre>
<p><a href="http://link.bitbucket.org/wf/click?upn=8USRlNyft-2BCzk2l4Ywl6gDx2lD2xxoS9E7MwXb2SMR-2BXcTD42YocdnOFkyGBVHOUyN2-2BGU4KHRHgM4xwOs-2B5cHoZUsME-2F7YN5cEmWLk5sb0-3D_ll4ctv0L-2ByeRZFC1LslHcg6aJmnQ70VruLbmeLQr27Aj2-2FK8naRflL58kCj2hbg1VA4Edf0afvjvTnnfHsAVkXwsPWijBRE9udx3gWgxwfo0mPcE5HBDZtRjILn-2FvjMkb6roxUFUV0azwUtBIdENduB86zOAhqysRagkWy7rCAuMnmjZTvMEc128DDybSf-2Frg-2BgfdYJKwCBe5WcXdrWR8u-2BjzdWABBJ5GojeeznkxC8-3D">https://bitbucket.org/yt_analysis/yt/commits/d7067e63cc21/</a> 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</p>
<p>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 @@</p>
<pre>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</pre>
<p>-:func:`yt.analysis_modules.halo_analysis.halo_recipes.calculate_virial_quantities`, +:func:`~yt.analysis_modules.halo_analysis.halo_recipes.calculate_virial_quantities`,</p>
<pre>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</pre>
<p><a href="http://link.bitbucket.org/wf/click?upn=8USRlNyft-2BCzk2l4Ywl6gDx2lD2xxoS9E7MwXb2SMR-2BXcTD42YocdnOFkyGBVHOUtmqRdJv6-2BukVVr5hGmJmaVzeiOznziiy5NMixq1phf4-3D_ll4ctv0L-2ByeRZFC1LslHcg6aJmnQ70VruLbmeLQr27Aj2-2FK8naRflL58kCj2hbg1VA4Edf0afvjvTnnfHsAVkfNJ-2BN6OENHDqWfZGxMrhJvR1k3m-2FHfOPtjXJLm-2Fllj5YRV0AZEbxnYurmDwzpf-2BA44duzqBSUX6B1g8QsOjwvMpUWmGLSWM47ELhhx-2FXHlqxc2z-2FiDDFXfvjb9aQMpffspYKRFOOp-2FyIrxVUwn-2F-2BQo-3D">https://bitbucket.org/yt_analysis/yt/commits/7d98d561e68c/</a> Changeset: 7d98d561e68c Branch: yt User: ngoldbaum Date: 2016-03-23 20:55:41+00:00 Summary: Merged in brittonsmith/yt (pull request #2061)</p>
<p>Adding halo analysis recipes Affected #: 7 files</p>
<p>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 @@</p>
<pre>Analysis is done by adding actions to the
:class:`~yt.analysis_modules.halo_analysis.halo_catalog.HaloCatalog`.</pre>
<p>-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:</p>
<pre>* Filters
* Quantities
* Callbacks</pre>
<p>+* Recipes</p>
<pre>A list of all available filters, quantities, and callbacks can be found in
:ref:`halo_analysis_ref`.</pre>
<p>@@ -213,6 +214,50 @@</p>
<pre> # ... Later on in your script
hc.add_callback("my_callback")
</pre>
<p>+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. +</p>
<pre>Running Analysis
----------------
</pre>
<p>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 @@</p>
<pre># Filter out less massive halos
hc.add_filter("quantity_value", "particle_mass", ">", 1e14, "Msun")
</pre>
<p>-# 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"])</p>
<p>-# 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"],</p>
<ul><li><p>[("gas", "overdensity")],</p></li>
<li><p>weight_field="cell_volume",</p></li>
<li><p>accumulation=True,</p></li>
<li><p>storage="virial_quantities_profiles")</p></li></ul>
<p>– – -hc.add_callback("virial_quantities", ["radius"],</p>
<ul><li><p>profile_storage="virial_quantities_profiles")</p></li></ul>
<p>-hc.add_callback('delete_attribute', ‘virial_quantities_profiles’) – +# Create a sphere container with radius 5x r_200.</p>
<pre>field_params = dict(virial_radius=('quantity', 'radius_200'))
hc.add_callback('sphere', radius_field='radius_200', factor=5,
field_parameters=field_params)</pre>
<p>+ +# Compute profiles of T vs. r/r_200</p>
<pre>hc.add_callback('profile', ['virial_radius_fraction'],
[('gas', 'temperature')],
storage='virial_profiles',</pre>
<p>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 @@</p>
<pre>~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</pre>
<p>+ ~yt.analysis_modules.halo_analysis.halo_recipes.HaloRecipe + ~yt.analysis_modules.halo_analysis.halo_recipes.calculate_virial_quantities</p>
<pre>Halo Finding
^^^^^^^^^^^^</pre>
<p>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 @@</p>
<pre>from .halo_catalog import \</pre>
<ul><li><p>HaloCatalog</p></li></ul>
<p>+ HaloCatalog</p>
<pre>from .halo_callbacks import \</pre>
<ul><li><p>add_callback</p></li></ul>
<p>+ add_callback</p>
<pre>from .halo_finding_methods import \</pre>
<ul><li><p>add_finding_method</p></li></ul>
<p>+ add_finding_method</p>
<pre>from .halo_filters import \</pre>
<ul><li><p>add_filter</p></li></ul>
<p>+ add_filter</p>
<pre>from .halo_quantities import \</pre>
<ul><li><p>add_quantity</p></li></ul>
<p>+ add_quantity + +from .halo_recipes import \ + add_recipe</p>
<p>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 @@</p>
<pre>factor : float
Factor to be multiplied by the base radius for defining
the radius of the sphere.</pre>
<ul><li><p>Defautl: 1.0.</p></li></ul>
<p>+ Default: 1.0.</p>
<pre>field_parameters : dict
Dictionary of field parameters to be set with the sphere
created.</pre>
<p>@@ -166,8 +166,7 @@</p>
<pre>bin_fields : list of strings
The binning fields for the profile.
profile_fields : string or list of strings</pre>
<ul><li><p>The fields to be propython</p></li>
<li><p>filed.</p></li></ul>
<p>+ The fields to be profiled.</p>
<pre>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.</pre>
<p>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 @@</p>
<pre> finding_method_registry
from .halo_quantities import \
quantity_registry</pre>
<p>+from .halo_recipes import \ + recipe_registry</p>
<pre>class HaloCatalog(ParallelAnalysisInterface):
r"""Create a HaloCatalog: an object that allows for the creation and association</pre>
<p>@@ -257,6 +259,46 @@</p>
<pre> halo_filter = filter_registry.find(halo_filter, *args, **kwargs)
self.actions.append(("filter", halo_filter))
</pre>
<p>+ 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) +</p>
<pre>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</pre>
<p>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 © 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)</p>
<p>Repository URL: <a href="http://link.bitbucket.org/wf/click?upn=8USRlNyft-2BCzk2l4Ywl6gDx2lD2xxoS9E7MwXb2SMR-2BI0v8SbQq-2B8-2FZaaHaJT85r_ll4ctv0L-2ByeRZFC1LslHcg6aJmnQ70VruLbmeLQr27Aj2-2FK8naRflL58kCj2hbg1VA4Edf0afvjvTnnfHsAVkTHj4bramoMso1mbd4Qz5-2Faa0QZpWUFXz-2BzjBzDr32dNDWSXDnr3z14Nb8-2FEWbubqL8YQ-2Fvw0uG8ezD7b1t6ej0Out7w-2B3kkztZJDSzSx0MvUp-2Fkw5L0xU4kinYY4XG90NocXM0cSXk3zNotbQi11Y4-3D">https://bitbucket.org/yt_analysis/yt/</a></p>
<p>—</p>
<p>This is a commit notification from bitbucket.org. You are receiving this because you have the service enabled, addressing the recipient of this email.</p>
<img src="http://link.bitbucket.org/wf/open?upn=ll4ctv0L-2ByeRZFC1LslHcg6aJmnQ70VruLbmeLQr27Aj2-2FK8naRflL58kCj2hbg1VA4Edf0afvjvTnnfHsAVkWw39Bt5oRG8AyPdeKyxz72Wip3oQbI1svZr0BeYG6bRueOpV3-2BMCgrtk4oxUTF98aZjHbl4qiWXyrjKhPGoC-2BSi8wwJtsadUTqM5GDDT-2B-2BVhMMJlT4fLknUirl61UIRr8O2Cv5dUe42nZNdH5C8p2g-3D" alt="" width="1" height="1" border="0" style="height:1px !important;width:1px !important;border-width:0 !important;margin-top:0 !important;margin-bottom:0 !important;margin-right:0 !important;margin-left:0 !important;padding-top:0 !important;padding-bottom:0 !important;padding-right:0 !important;padding-left:0 !important;"/>
</body></html>