[yt-svn] commit/yt: xarthisius: Merged in chummels/yt (pull request #1184)
commits-noreply at bitbucket.org
commits-noreply at bitbucket.org
Fri Sep 5 15:13:27 PDT 2014
1 new commit in yt:
https://bitbucket.org/yt_analysis/yt/commits/0abeb6afd3bc/
Changeset: 0abeb6afd3bc
Branch: yt
User: xarthisius
Date: 2014-09-06 00:13:19
Summary: Merged in chummels/yt (pull request #1184)
A couple of bug fixes and a new cookbook recipe for running rockstar on nested cosmo runs
Affected #: 7 files
diff -r 1ae07010694a53b29095fa7300a5c4f457cb4b90 -r 0abeb6afd3bc2b563c023b4a72be222447d843af 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
@@ -129,7 +129,14 @@
are center_of_mass and bulk_velocity. Their definitions are available in
``yt/analysis_modules/halo_analysis/halo_quantities.py``. If you think that
your quantity may be of use to the general community, add it to
-``halo_quantities.py`` and issue a pull request.
+``halo_quantities.py`` and issue a pull request. Default halo quantities are:
+
+* ``particle_identifier`` -- Halo ID (e.g. 0 to N)
+* ``particle_mass`` -- Mass of halo
+* ``particle_position_x`` -- Location of halo
+* ``particle_position_y`` -- Location of halo
+* ``particle_position_z`` -- Location of halo
+* ``virial_radius`` -- Virial radius of halo
An example of adding a quantity:
diff -r 1ae07010694a53b29095fa7300a5c4f457cb4b90 -r 0abeb6afd3bc2b563c023b4a72be222447d843af doc/source/analyzing/analysis_modules/halo_finders.rst
--- a/doc/source/analyzing/analysis_modules/halo_finders.rst
+++ b/doc/source/analyzing/analysis_modules/halo_finders.rst
@@ -75,7 +75,8 @@
mass. In simulations where the highest-resolution particles all have the
same mass (ie: zoom-in grid based simulations), one can set up a particle
filter to select the lowest mass particles and perform the halo finding
- only on those.
+ only on those. See the this cookbook recipe for an example:
+ :ref:`cookbook-rockstar-nested-grid`.
To run the Rockstar Halo finding, you must launch python with MPI and
parallelization enabled. While Rockstar itself does not require MPI to run,
diff -r 1ae07010694a53b29095fa7300a5c4f457cb4b90 -r 0abeb6afd3bc2b563c023b4a72be222447d843af doc/source/cookbook/cosmological_analysis.rst
--- a/doc/source/cookbook/cosmological_analysis.rst
+++ b/doc/source/cookbook/cosmological_analysis.rst
@@ -14,6 +14,22 @@
.. yt_cookbook:: halo_plotting.py
+.. _cookbook-rockstar-nested-grid:
+
+Running Rockstar to Find Halos on Multi-Resolution-Particle Datasets
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+The version of Rockstar installed with yt does not have the capability
+to work on datasets with particles of different masses. Unfortunately,
+many simulations possess particles of different masses, notably cosmological
+zoom datasets. This recipe uses Rockstar in two different ways to generate a
+HaloCatalog from the highest resolution dark matter particles (the ones
+inside the zoom region). It then overlays some of those halos on a projection
+as a demonstration. See :ref:`halo-analysis` and :ref:`annotate-halos` for
+more information.
+
+.. yt_cookbook:: rockstar_nest.py
+
.. _cookbook-halo_finding:
Halo Profiling and Custom Analysis
diff -r 1ae07010694a53b29095fa7300a5c4f457cb4b90 -r 0abeb6afd3bc2b563c023b4a72be222447d843af doc/source/cookbook/rockstar_nest.py
--- /dev/null
+++ b/doc/source/cookbook/rockstar_nest.py
@@ -0,0 +1,74 @@
+# You must run this job in parallel.
+# There are several mpi flags which can be useful in order for it to work OK.
+# It requires at least 3 processors in order to run because of the way in which
+# rockstar divides up the work. Make sure you have mpi4py installed as per
+# http://yt-project.org/docs/dev/analyzing/parallel_computation.html#setting-up-parallel-yt
+
+# Usage: mpirun -np <num_procs> --mca btl ^openib python this_script.py
+
+import yt
+from yt.analysis_modules.halo_analysis.halo_catalog import HaloCatalog
+from yt.data_objects.particle_filters import add_particle_filter
+from yt.analysis_modules.halo_finding.rockstar.api import RockstarHaloFinder
+yt.enable_parallelism() # rockstar halofinding requires parallelism
+
+# Create a dark matter particle filter
+# This will be code dependent, but this function here is true for enzo
+
+def DarkMatter(pfilter, data):
+ filter = data[("all", "particle_type")] == 1 # DM = 1, Stars = 2
+ return filter
+
+add_particle_filter("dark_matter", function=DarkMatter, filtered_type='all', \
+ requires=["particle_type"])
+
+# First, we make sure that this script is being run using mpirun with
+# at least 3 processors as indicated in the comments above.
+assert(yt.communication_system.communicators[-1].size >= 3)
+
+# Load the dataset and apply dark matter filter
+fn = "Enzo_64/DD0043/data0043"
+ds = yt.load(fn)
+ds.add_particle_filter('dark_matter')
+
+# Determine highest resolution DM particle mass in sim by looking
+# at the extrema of the dark_matter particle_mass field.
+ad = ds.all_data()
+min_dm_mass = ad.quantities.extrema(('dark_matter','particle_mass'))[0]
+
+# Define a new particle filter to isolate all highest resolution DM particles
+# and apply it to dataset
+def MaxResDarkMatter(pfilter, data):
+ return data["particle_mass"] <= 1.01 * min_dm_mass
+
+add_particle_filter("max_res_dark_matter", function=MaxResDarkMatter, \
+ filtered_type='dark_matter', requires=["particle_mass"])
+ds.add_particle_filter('max_res_dark_matter')
+
+# If desired, we can see the total number of DM and High-res DM particles
+#if yt.is_root():
+# print "Simulation has %d DM particles." % ad['dark_matter','particle_type'].shape
+# print "Simulation has %d Highest Res DM particles." % ad['max_res_dark_matter', 'particle_type'].shape
+
+# Run the halo catalog on the dataset only on the highest resolution dark matter
+# particles
+hc = HaloCatalog(data_ds=ds, finder_method='rockstar', \
+ finder_kwargs={'dm_only':True, 'particle_type':'max_res_dark_matter'})
+hc.create()
+
+# Or alternatively, just run the RockstarHaloFinder and later import the
+# output file as necessary. You can skip this step if you've already run it
+# once, but be careful since subsequent halo finds will overwrite this data.
+#rhf = RockstarHaloFinder(ds, particle_type="max_res_dark_matter")
+#rhf.run()
+# Load the halo list from a rockstar output for this dataset
+# Create a projection with the halos overplot on top
+#halos = yt.load('rockstar_halos/halos_0.0.bin')
+#hc = HaloCatalog(halos_ds=halos)
+#hc.load()
+
+# Regardless of your method of creating the halo catalog, use it to overplot the
+# halos on a projection.
+p = yt.ProjectionPlot(ds, "x", "density")
+p.annotate_halos(hc, annotate_field = 'particle_identifier', width=(10,'Mpc'), factor=2)
+p.save()
diff -r 1ae07010694a53b29095fa7300a5c4f457cb4b90 -r 0abeb6afd3bc2b563c023b4a72be222447d843af doc/source/cookbook/thin_slice_projection.py
--- a/doc/source/cookbook/thin_slice_projection.py
+++ b/doc/source/cookbook/thin_slice_projection.py
@@ -4,7 +4,7 @@
ds = yt.load("Enzo_64/DD0030/data0030")
# Make a projection that is the full width of the domain,
-# but only 10 Mpc in depth. This is done by creating a
+# but only 5 Mpc in depth. This is done by creating a
# region object with this exact geometry and providing it
# as a data_source for the projection.
@@ -17,12 +17,12 @@
right_corner = ds.domain_right_edge
# Now adjust the size of the region along the line of sight (x axis).
-depth = ds.quan(10.0,'Mpc')
+depth = ds.quan(5.0,'Mpc')
left_corner[0] = center[0] - 0.5 * depth
-left_corner[0] = center[0] + 0.5 * depth
+right_corner[0] = center[0] + 0.5 * depth
# Create the region
-region = ds.region(center, left_corner, right_corner)
+region = ds.box(left_corner, right_corner)
# Create a density projection and supply the region we have just created.
# Only cells within the region will be included in the projection.
diff -r 1ae07010694a53b29095fa7300a5c4f457cb4b90 -r 0abeb6afd3bc2b563c023b4a72be222447d843af doc/source/visualizing/_cb_docstrings.inc
--- a/doc/source/visualizing/_cb_docstrings.inc
+++ b/doc/source/visualizing/_cb_docstrings.inc
@@ -151,19 +151,28 @@
Overplot Halo Annotations
~~~~~~~~~~~~~~~~~~~~~~~~~
-.. function:: annotate_halos(self, halo_catalog, col='white', alpha=1, \
- width=None):
+.. function:: annotate_halos(self, halo_catalog, circle_kwargs=None, width=None, \
+ annotate_field=False, font_kwargs=None, factor=1.0):
(This is a proxy for
:class:`~yt.visualization.plot_modifications.HaloCatalogCallback`.)
Accepts a :class:`~yt.analysis_modules.halo_analysis.halo_catalog.HaloCatalog`
- and plots a circle at the location of each
- halo with the radius of the circle corresponding to the virial radius of the
- halo. If ``width`` is set to None (default) all halos are plotted.
- Otherwise, only halos that fall within a slab with width ``width`` centered
- on the center of the plot data. The color and transparency of the circles can
- be controlled with ``col`` and ``alpha`` respectively.
+ and plots a circle at the location of each halo with the radius of the
+ circle corresponding to the virial radius of the halo. If ``width`` is set
+ to None (default) all halos are plotted, otherwise it accepts a tuple in
+ the form (1.0, ‘Mpc’) to only display halos that fall within a slab with
+ width ``width`` centered on the center of the plot data. The appearance of
+ the circles can be changed with the circle_kwargs dictionary, which is
+ supplied to the Matplotlib patch Circle. One can label each of the halos
+ with the annotate_field, which accepts a field contained in the halo catalog
+ to add text to the plot near the halo (example: annotate_field =
+ ``particle_mass`` will write the halo mass next to each halo, whereas
+ ``particle_identifier`` shows the halo number). font_kwargs contains the
+ arguments controlling the text appearance of the annotated field.
+ Factor is the number the virial radius is multiplied by for plotting the
+ circles. Ex: factor = 2.0 will plot circles with twice the radius of each
+ halo virial radius.
.. python-script::
@@ -177,7 +186,7 @@
hc.create()
prj = yt.ProjectionPlot(data_ds, 'z', 'density')
- prj.annotate_halos(hc)
+ prj.annotate_halos(hc, annotate_field=particle_identifier)
prj.save()
Overplot a Straight Line
diff -r 1ae07010694a53b29095fa7300a5c4f457cb4b90 -r 0abeb6afd3bc2b563c023b4a72be222447d843af yt/visualization/plot_modifications.py
--- a/yt/visualization/plot_modifications.py
+++ b/yt/visualization/plot_modifications.py
@@ -907,8 +907,8 @@
class HaloCatalogCallback(PlotCallback):
"""
annotate_halos(halo_catalog, circle_kwargs=None,
- width = None, annotate_field=False,
- font_kwargs = None, factor = 1.0)
+ width = None, annotate_field = False,
+ font_kwargs=None, factor = 1.0)
Plots circles at the locations of all the halos
in a halo catalog with radii corresponding to the
@@ -935,14 +935,16 @@
region = None
_descriptor = None
- def __init__(self, halo_catalog, circle_kwargs = None,
+ def __init__(self, halo_catalog, circle_kwargs=None,
width = None, annotate_field = False,
- font_kwargs = None, factor = 1.0):
+ font_kwargs=None, factor = 1.0):
PlotCallback.__init__(self)
self.halo_catalog = halo_catalog
self.width = width
self.annotate_field = annotate_field
+ if font_kwargs is None:
+ font_kwargs = {'color':'white'}
self.font_kwargs = font_kwargs
self.factor = factor
if circle_kwargs is None:
@@ -1005,7 +1007,7 @@
if self.annotate_field:
annotate_dat = halo_data[self.annotate_field]
- texts = ['{0}'.format(dat) for dat in annotate_dat]
+ texts = ['{:g}'.format(float(dat))for dat in annotate_dat]
for pos_x, pos_y, t in zip(px, py, texts):
plot._axes.text(pos_x, pos_y, t, **self.font_kwargs)
Repository URL: https://bitbucket.org/yt_analysis/yt/
--
This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.
More information about the yt-svn
mailing list