[yt-svn] commit/yt: 2 new changesets
Bitbucket
commits-noreply at bitbucket.org
Fri Dec 16 18:38:49 PST 2011
2 new commits in yt:
https://bitbucket.org/yt_analysis/yt/changeset/ea2e56baf054/
changeset: ea2e56baf054
branch: yt
user: chummels
date: 2011-12-17 03:35:36
summary: Fixing a bug with the display limits in the write_projection function.
affected #: 1 file
diff -r 0ac521e9ac07be8f66be6f7eb40e7d16a9e20fb8 -r ea2e56baf0542bf593f1d6a984c317b568cdeaa7 yt/visualization/image_writer.py
--- a/yt/visualization/image_writer.py
+++ b/yt/visualization/image_writer.py
@@ -371,10 +371,6 @@
"""
import pylab as pl
- # If there are limits, then clip the data before plotting
- if limits is not None:
- data = na.clip(data, limits[0], limits[1])
-
# If this is rendered as log, then apply now.
if take_log:
data = na.log10(data)
@@ -385,11 +381,12 @@
# Create the figure and paint the data on
fig = pl.figure()
ax = fig.add_subplot(111)
- cax = ax.imshow(data)
- # If there are limits, apply them to the colormap
if limits is not None:
- cax.set_clim=limits
+ cax = ax.imshow(data, vmin=limits[0], vmax=limits[1])
+ else:
+ cax = ax.imshow(data)
+
if title:
ax.set_title(title)
https://bitbucket.org/yt_analysis/yt/changeset/91c3e1596f38/
changeset: 91c3e1596f38
branch: yt
user: chummels
date: 2011-12-17 03:36:31
summary: Merging.
affected #: 5 files
diff -r ea2e56baf0542bf593f1d6a984c317b568cdeaa7 -r 91c3e1596f38fca989299cdd177f9c686001a342 setup.py
--- a/setup.py
+++ b/setup.py
@@ -76,7 +76,7 @@
import setuptools
-VERSION = "2.3dev"
+VERSION = "2.4dev"
if os.path.exists('MANIFEST'): os.remove('MANIFEST')
diff -r ea2e56baf0542bf593f1d6a984c317b568cdeaa7 -r 91c3e1596f38fca989299cdd177f9c686001a342 yt/analysis_modules/halo_profiler/api.py
--- a/yt/analysis_modules/halo_profiler/api.py
+++ b/yt/analysis_modules/halo_profiler/api.py
@@ -34,5 +34,5 @@
from .multi_halo_profiler import \
HaloProfiler, \
FakeProfile, \
- shift_projections, \
+ get_halo_sphere, \
standard_fields
diff -r ea2e56baf0542bf593f1d6a984c317b568cdeaa7 -r 91c3e1596f38fca989299cdd177f9c686001a342 yt/analysis_modules/halo_profiler/multi_halo_profiler.py
--- a/yt/analysis_modules/halo_profiler/multi_halo_profiler.py
+++ b/yt/analysis_modules/halo_profiler/multi_halo_profiler.py
@@ -46,7 +46,8 @@
from yt.utilities.parallel_tools.parallel_analysis_interface import \
ParallelAnalysisInterface, \
parallel_blocking_call, \
- parallel_root_only
+ parallel_root_only, \
+ parallel_objects
from yt.visualization.fixed_resolution import \
FixedResolutionBuffer
from yt.visualization.image_writer import write_image
@@ -66,7 +67,7 @@
recenter = None,
profile_output_dir='radial_profiles', projection_output_dir='projections',
projection_width=8.0, projection_width_units='mpc', project_at_level='max',
- velocity_center=['bulk', 'halo'], filter_quantities=['id','center'],
+ velocity_center=['bulk', 'halo'], filter_quantities=['id', 'center', 'r_max'],
use_critical_density=False):
r"""Initialize a Halo Profiler object.
@@ -184,7 +185,6 @@
self._halo_filters = []
self.all_halos = []
self.filtered_halos = []
- self._projection_halo_list = []
# Create output directory if specified
if self.output_dir is not None:
@@ -454,7 +454,7 @@
# Profile all halos.
updated_halos = []
- for halo in self._get_objs('all_halos', round_robin=True):
+ for halo in parallel_objects(self.all_halos, -1):
# Apply prefilters to avoid profiling unwanted halos.
filter_result = True
haloQuantities = {}
@@ -510,7 +510,7 @@
def _get_halo_profile(self, halo, filename, virial_filter=True,
force_write=False):
- """Profile a single halo and write profile data to a file.
+ r"""Profile a single halo and write profile data to a file.
If file already exists, read profile data from file.
Return a dictionary of id, center, and virial quantities if virial_filter is True.
"""
@@ -528,39 +528,9 @@
mylog.error("Skipping halo with r_max / r_min = %f." % (halo['r_max']/r_min))
return None
- sphere = self.pf.h.sphere(halo['center'], halo['r_max']/self.pf.units['mpc'])
- if len(sphere._grids) == 0: return None
- new_sphere = False
-
- if self.recenter:
- old = halo['center']
- if self.recenter in centering_registry:
- new_x, new_y, new_z = \
- centering_registry[self.recenter](sphere)
- else:
- # user supplied function
- new_x, new_y, new_z = self.recenter(sphere)
- if new_x < self.pf.domain_left_edge[0] or \
- new_y < self.pf.domain_left_edge[1] or \
- new_z < self.pf.domain_left_edge[2]:
- mylog.info("Recentering rejected, skipping halo %d" % \
- halo['id'])
- return None
- halo['center'] = [new_x, new_y, new_z]
- d = self.pf['kpc'] * periodic_dist(old, halo['center'],
- self.pf.domain_right_edge - self.pf.domain_left_edge)
- mylog.info("Recentered halo %d %1.3e kpc away." % (halo['id'], d))
- # Expand the halo to account for recentering.
- halo['r_max'] += d / 1000 # d is in kpc -> want mpc
- new_sphere = True
-
- if new_sphere:
- # Temporary solution to memory leak.
- for g in self.pf.h.grids:
- g.clear_data()
- sphere.clear_data()
- del sphere
- sphere = self.pf.h.sphere(halo['center'], halo['r_max']/self.pf.units['mpc'])
+ # get a sphere object to profile
+ sphere = get_halo_sphere(halo, self.pf, recenter=self.recenter)
+ if sphere is None: return None
if self._need_bulk_velocity:
# Set bulk velocity to zero out radial velocity profiles.
@@ -648,18 +618,18 @@
# Get list of halos for projecting.
if halo_list == 'filtered':
- self._halo_projection_list = self.filtered_halos
+ halo_projection_list = self.filtered_halos
elif halo_list == 'all':
- self._halo_projection_list = self.all_halos
+ halo_projection_list = self.all_halos
elif isinstance(halo_list, types.StringType):
- self._halo_projection_list = self._read_halo_list(halo_list)
+ halo_projection_list = self._read_halo_list(halo_list)
elif isinstance(halo_list, types.ListType):
- self._halo_projection_list = halo_list
+ halo_projection_list = halo_list
else:
mylog.error("Keyword, halo_list', must be 'filtered', 'all', a filename, or an actual list.")
return
- if len(self._halo_projection_list) == 0:
+ if len(halo_projection_list) == 0:
mylog.error("Halo list for projections is empty.")
return
@@ -686,7 +656,7 @@
self.pf.parameters['DomainRightEdge'][w])
for w in range(self.pf.parameters['TopGridRank'])]
- for halo in self._get_objs('_halo_projection_list', round_robin=True):
+ for halo in parallel_objects(halo_projection_list, -1):
if halo is None:
continue
# Check if region will overlap domain edge.
@@ -733,7 +703,7 @@
# Set x and y limits, shift image if it overlaps domain boundary.
if need_per:
pw = self.projection_width/self.pf.units[self.projection_width_units]
- shift_projections(self.pf, projections, halo['center'], center, w)
+ _shift_projections(self.pf, projections, halo['center'], center, w)
# Projection has now been shifted to center of box.
proj_left = [center[x_axis]-0.5*pw, center[y_axis]-0.5*pw]
proj_right = [center[x_axis]+0.5*pw, center[y_axis]+0.5*pw]
@@ -773,6 +743,76 @@
del region
+ @parallel_blocking_call
+ def analyze_halo_spheres(self, analysis_function, halo_list='filtered',
+ analysis_output_dir=None):
+ r"""Perform custom analysis on all halos.
+
+ This will loop through all halo on the HaloProfiler's list,
+ creating a sphere object for each halo and passing that sphere
+ to the provided analysis function.
+
+ Parameters
+ ---------
+ analysis_function : function
+ A function taking two arguments, the halo dictionary, and a
+ sphere object.
+ Example function to calculate total mass of halo:
+ def my_analysis(halo, sphere):
+ total_mass = sphere.quantities['TotalMass']()
+ print total_mass
+ halo_list : {'filtered', 'all'}
+ Which set of halos to make profiles of, either ones passed by the
+ halo filters (if enabled/added), or all halos.
+ Default='filtered'.
+ analysis_output_dir : string, optional
+ If specified, this directory will be created within the dataset to
+ contain any output from the analysis function. Default: None.
+
+ Examples
+ --------
+ >>> hp.analyze_halo_spheres(my_analysis, halo_list="filtered",
+ analysis_output_dir='special_analysis')
+
+ """
+
+ # Get list of halos for projecting.
+ if halo_list == 'filtered':
+ halo_analysis_list = self.filtered_halos
+ elif halo_list == 'all':
+ halo_analysis_list = self.all_halos
+ elif isinstance(halo_list, types.StringType):
+ halo_analysis_list = self._read_halo_list(halo_list)
+ elif isinstance(halo_list, types.ListType):
+ halo_analysis_list = halo_list
+ else:
+ mylog.error("Keyword, halo_list', must be 'filtered', 'all', a filename, or an actual list.")
+ return
+
+ if len(halo_analysis_list) == 0:
+ mylog.error("Halo list for analysis is empty.")
+ return
+
+ # Create output directory.
+ if analysis_output_dir is not None:
+ if self.output_dir is not None:
+ self.__check_directory("%s/%s" % (self.output_dir, self.pf.directory))
+ my_output_dir = "%s/%s/%s" % (self.output_dir, self.pf.directory,
+ analysis_output_dir)
+ else:
+ my_output_dir = "%s/%s" % (self.pf.fullpath, analysis_output_dir)
+ self.__check_directory(my_output_dir)
+
+ for halo in parallel_objects(halo_analysis_list, -1):
+ if halo is None: continue
+
+ # Get a sphere object to analze.
+ sphere = get_halo_sphere(halo, self.pf, recenter=self.recenter)
+ if sphere is None: continue
+
+ # Call the given analysis function.
+ analysis_function(halo, sphere)
+
def _add_actual_overdensity(self, profile):
"Calculate overdensity from TotalMassMsun and CellVolume fields."
@@ -1002,7 +1042,95 @@
else:
os.mkdir(my_output_dir)
-def shift_projections(pf, projections, oldCenter, newCenter, axis):
+def get_halo_sphere(halo, pf, recenter=None):
+ r"""Returns a sphere object for a given halo.
+
+ With a dictionary containing halo properties, such as center
+ and r_max, this creates a sphere object and optionally
+ recenters and recreates the sphere using a recentering function.
+ This is to be used primarily to make spheres for a set of halos
+ loaded by the HaloProfiler.
+
+ Parameters
+ ----------
+ halo : dict, required
+ The dictionary containing halo properties used to make the sphere.
+ Required entries:
+ center : list with center coordinates.
+ r_max : sphere radius in Mpc.
+ pf : parameter file object, required
+ The parameter file from which the sphere will be made.
+ recenter : {None, string or function}
+ The exact location of the sphere center can significantly affect
+ radial profiles. The halo center loaded by the HaloProfiler will
+ typically be the dark matter center of mass calculated by a halo
+ finder. However, this may not be the best location for centering
+ profiles of baryon quantities. For example, one may want to center
+ on the maximum density.
+ If recenter is given as a string, one of the existing recentering
+ functions will be used:
+ Min_Dark_Matter_Density : location of minimum dark matter density
+ Max_Dark_Matter_Density : location of maximum dark matter density
+ CoM_Dark_Matter_Density : dark matter center of mass
+ Min_Gas_Density : location of minimum gas density
+ Max_Gas_Density : location of maximum gas density
+ CoM_Gas_Density : gas center of mass
+ Min_Total_Density : location of minimum total density
+ Max_Total_Density : location of maximum total density
+ CoM_Total_Density : total center of mass
+ Min_Temperature : location of minimum temperature
+ Max_Temperature : location of maximum temperature
+ Alternately, a function can be supplied for custom recentering.
+ The function should take only one argument, a sphere object.
+ Example function:
+ def my_center_of_mass(data):
+ my_x, my_y, my_z = data.quantities['CenterOfMass']()
+ return (my_x, my_y, my_z)
+
+ Examples: this should primarily be used with the halo list of the HaloProfiler.
+ This is an example with an abstract halo asssuming a pre-defined pf.
+ >>> halo = {'center': [0.5, 0.5, 0.5], 'r_max': 1.0}
+ >>> my_sphere = get_halo_sphere(halo, pf, recenter='Max_Gas_Density')
+ >>> # Assuming the above example function has been defined.
+ >>> my_sphere = get_halo_sphere(halo, pf, recenter=my_center_of_mass)
+ """
+
+ sphere = pf.h.sphere(halo['center'], halo['r_max']/pf.units['mpc'])
+ if len(sphere._grids) == 0: return None
+ new_sphere = False
+
+ if recenter:
+ old = halo['center']
+ if recenter in centering_registry:
+ new_x, new_y, new_z = \
+ centering_registry[recenter](sphere)
+ else:
+ # user supplied function
+ new_x, new_y, new_z = recenter(sphere)
+ if new_x < pf.domain_left_edge[0] or \
+ new_y < pf.domain_left_edge[1] or \
+ new_z < pf.domain_left_edge[2]:
+ mylog.info("Recentering rejected, skipping halo %d" % \
+ halo['id'])
+ return None
+ halo['center'] = [new_x, new_y, new_z]
+ d = pf['kpc'] * periodic_dist(old, halo['center'],
+ pf.domain_right_edge - pf.domain_left_edge)
+ mylog.info("Recentered halo %d %1.3e kpc away." % (halo['id'], d))
+ # Expand the halo to account for recentering.
+ halo['r_max'] += d / 1000 # d is in kpc -> want mpc
+ new_sphere = True
+
+ if new_sphere:
+ # Temporary solution to memory leak.
+ for g in pf.h.grids:
+ g.clear_data()
+ sphere.clear_data()
+ del sphere
+ sphere = pf.h.sphere(halo['center'], halo['r_max']/pf.units['mpc'])
+ return sphere
+
+def _shift_projections(pf, projections, oldCenter, newCenter, axis):
"""
Shift projection data around.
This is necessary when projecting a preiodic region.
diff -r ea2e56baf0542bf593f1d6a984c317b568cdeaa7 -r 91c3e1596f38fca989299cdd177f9c686001a342 yt/visualization/plot_collection.py
--- a/yt/visualization/plot_collection.py
+++ b/yt/visualization/plot_collection.py
@@ -211,9 +211,9 @@
Only ONE of the following options can be specified. If all 3 are
specified, they will be used in the following precedence order:
- * `ticks` - a list of floating point numbers at which to put ticks
- * `minmaxtick` - display DEFAULT ticks with min & max also displayed
- * `nticks` - if ticks not specified, can automatically determine a
+ * ``ticks`` - a list of floating point numbers at which to put ticks
+ * ``minmaxtick`` - display DEFAULT ticks with min & max also displayed
+ * ``nticks`` - if ticks not specified, can automatically determine a
number of ticks to be evenly spaced in log space
"""
for plot in self.plots:
@@ -1713,9 +1713,9 @@
r"""Construct a multiple axes plot object, with or without a colorbar, into
which multiple plots may be inserted.
- This will create a set of `matplotlib.axes.Axes`, all lined up into a grid,
- which are then returned to the user and which can be used to plot multiple
- plots on a single figure.
+ This will create a set of :class:`matplotlib.axes.Axes`, all lined up into
+ a grid, which are then returned to the user and which can be used to plot
+ multiple plots on a single figure.
Parameters
----------
@@ -1733,12 +1733,12 @@
Returns
-------
- fig : `matplotlib.figure.Figure
+ fig : :class:`matplotlib.figure.Figure`
The figure created inside which the axes reside
- tr : list of list of `matplotlib.axes.Axes` objects
+ tr : list of list of :class:`matplotlib.axes.Axes` objects
This is a list, where the inner list is along the x-axis and the outer
is along the y-axis
- cbars : list of `matplotlib.axes.Axes` objects
+ cbars : list of :class:`matplotlib.axes.Axes` objects
Each of these is an axes onto which a colorbar can be placed.
Notes
diff -r ea2e56baf0542bf593f1d6a984c317b568cdeaa7 -r 91c3e1596f38fca989299cdd177f9c686001a342 yt/visualization/plot_types.py
--- a/yt/visualization/plot_types.py
+++ b/yt/visualization/plot_types.py
@@ -170,10 +170,11 @@
Only ONE of the following options can be specified. If all 3 are
specified, they will be used in the following precedence order:
- ticks - a list of floating point numbers at which to put ticks
- minmaxtick - display DEFAULT ticks with min & max also displayed
- nticks - if ticks not specified, can automatically determine a
- number of ticks to be evenly spaced in log space
+
+ * ``ticks`` - a list of floating point numbers at which to put ticks
+ * ``minmaxtick`` - display DEFAULT ticks with min & max also displayed
+ * ``nticks`` - if ticks not specified, can automatically determine a
+ number of ticks to be evenly spaced in log space
"""
# This next call fixes some things, but is slower...
self._redraw_image()
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