[Yt-svn] commit/yt: 3 new changesets

Bitbucket commits-noreply at bitbucket.org
Fri Apr 15 11:41:52 PDT 2011


3 new changesets in yt:

http://bitbucket.org/yt_analysis/yt/changeset/92d8bc115b6c/
changeset:   r4133:92d8bc115b6c
branch:      yt
user:        brittonsmith
date:        2011-04-15 17:03:32
summary:     Added use_critical_density keyword arg to HaloProfiler to toggle between
overdensity with respect to critical or to mean matter density.  Virial
filter now returns virial quantities named by value of overdensity threshold
used.
affected #:  2 files (425 bytes)

--- a/yt/analysis_modules/halo_profiler/halo_filters.py	Thu Apr 14 14:05:09 2011 -0400
+++ b/yt/analysis_modules/halo_profiler/halo_filters.py	Fri Apr 15 11:03:32 2011 -0400
@@ -28,10 +28,10 @@
 
 from yt.funcs import *
 
-def VirialFilter(profile,overdensity_field='ActualOverdensity',
-                 virial_overdensity=200.,must_be_virialized=True,
-                 virial_filters=[['TotalMassMsun','>=','1e14']],
-                 virial_quantities=['TotalMassMsun','RadiusMpc'],
+def VirialFilter(profile, overdensity_field='ActualOverdensity',
+                 virial_overdensity=200., must_be_virialized=True,
+                 virial_filters=[['TotalMassMsun', '>=','1e14']],
+                 virial_quantities=['TotalMassMsun', 'RadiusMpc'],
                  virial_index=None):
     """
     Filter halos by virial quantities.
@@ -49,9 +49,7 @@
             fields.append(vfilter[0])
     
     overDensity = []
-    temp_profile = {}
-    for field in fields:
-        temp_profile[field] = []
+    temp_profile = dict((field, []) for field in fields)
 
     for q in range(len(profile[overdensity_field])):
         good = True
@@ -67,9 +65,7 @@
             for field in fields:
                 temp_profile[field].append(profile[field][q])
 
-    virial = {}
-    for field in fields:
-        virial[field] = 0.0
+    virial = dict((field, 0.0) for field in fields)
 
     if (not (na.array(overDensity) >= virial_overdensity).any()) and \
             must_be_virialized:
@@ -106,11 +102,14 @@
 
     for vfilter in virial_filters:
         if eval("%s %s %s" % (virial[vfilter[0]],vfilter[1],vfilter[2])):
-            mylog.debug("(%s %s %s) returned True for %s." % (vfilter[0],vfilter[1],vfilter[2],virial[vfilter[0]]))
+            mylog.debug("(%s %s %s) returned True for %s." % \
+                            (vfilter[0],vfilter[1],vfilter[2],virial[vfilter[0]]))
             continue
         else:
-            mylog.debug("(%s %s %s) returned False for %s." % (vfilter[0],vfilter[1],vfilter[2],virial[vfilter[0]]))
+            mylog.debug("(%s %s %s) returned False for %s." % \
+                            (vfilter[0],vfilter[1],vfilter[2],virial[vfilter[0]]))
             return [False, {}]
 
-    return [True, dict((q,virial[q]) for q in virial_quantities)]
+    return [True, dict((("%s_%s" % (q, virial_overdensity)), virial[q])
+                       for q in virial_quantities)]
 


--- a/yt/analysis_modules/halo_profiler/multi_halo_profiler.py	Thu Apr 14 14:05:09 2011 -0400
+++ b/yt/analysis_modules/halo_profiler/multi_halo_profiler.py	Fri Apr 15 11:03:32 2011 -0400
@@ -62,12 +62,12 @@
                  halo_finder_kwargs=dict(threshold=160.0, safety=1.5, 
                                          dm_only=False, resize=True, 
                                          fancy_padding=True, rearrange=True),
-                 use_density_center=False, density_center_exponent=1.0,
                  halo_radius=0.1, radius_units='1', n_profile_bins=50,
                  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'], 
+                 use_critical_density=False):
         """
         Initialize a HaloProfiler object.
         :param output_dir (str): if specified, all output will be put into this path instead of 
@@ -114,6 +114,7 @@
                                     specified (used only when halos set to single).
         :param filter_quantities (list): quantities from the original halo list file to be written out in the 
                filtered list file.  Default: ['id','center'].
+        :param use_critical_density (bool): if True, the definition of overdensity for virial quantities is calculated with respect to the critical density.  If False, overdensity is with respect to mean matter density, which is lower by a factor of Omega_M.  Default: False.
         """
 
         self.dataset = dataset
@@ -126,6 +127,7 @@
         self.project_at_level = project_at_level
         self.filter_quantities = filter_quantities
         if self.filter_quantities is None: self.filter_quantities = []
+        self.use_critical_density = use_critical_density
 
         self.profile_fields = []
         self.projection_fields = []
@@ -561,10 +563,10 @@
         if 'ActualOverdensity' in profile.keys():
             return
 
-        rho_crit_now = 1.8788e-29 * self.pf.hubble_constant**2.0 * \
-            self.pf.omega_matter # g cm^-3
+        rho_crit_now = 1.8788e-29 * self.pf.hubble_constant**2 # g cm^-3
         Msun2g = 1.989e33
         rho_crit = rho_crit_now * ((1.0 + self.pf.current_redshift)**3.0)
+        if not self.use_critical_density: rho_crit *= self.pf.omega_matter
 
         profile['ActualOverdensity'] = (Msun2g * profile['TotalMassMsun']) / \
             profile['CellVolume'] / rho_crit


http://bitbucket.org/yt_analysis/yt/changeset/864b66223ef4/
changeset:   r4134:864b66223ef4
branch:      yt
user:        brittonsmith
date:        2011-04-15 20:38:50
summary:     Fixed centering methods to center on max and min of fields.
Added a use_cells keyword arg to center of mass calculation to
allow particle-only com.
affected #:  2 files (1.7 KB)

--- a/yt/analysis_modules/halo_profiler/centering_methods.py	Fri Apr 15 11:03:32 2011 -0400
+++ b/yt/analysis_modules/halo_profiler/centering_methods.py	Fri Apr 15 14:38:50 2011 -0400
@@ -40,104 +40,67 @@
 
 #### Dark Matter Density ####
 
-def _MatterDensityXDMMass(field, data):
-    return (data['Dark_Matter_Density'] * data['Dark_Matter_Density'] \
-        * data["CellVolume"])
-def _Convert_MatterDensityXDMMass(data):
-    return 1
-add_field("MatterDensityXDMMass", units=r"",
-          function=_MatterDensityXDMMass,
-          convert_function=_Convert_MatterDensityXDMMass)
-
 @add_function("Min_Dark_Matter_Density")
 def find_minimum_dm_density(data):
-    ma, maxi, mx, my, mz, mg = data.quantities['MinLocation']('MatterDensityXDMMass')
-    return [mx,my,mz]
+    ma, maxi, mx, my, mz, mg = data.quantities['MinLocation']('Dark_Matter_Density')
+    return (mx, my, mz)
 
 @add_function("Max_Dark_Matter_Density")
 def find_maximum_dm_density(data):
-    ma, maxi, mx, my, mz, mg = data.quantities['MaxLocation']('MatterDensityXDMMass')
-    return [mx,my,mz]
+    ma, maxi, mx, my, mz, mg = data.quantities['MaxLocation']('Dark_Matter_Density')
+    return (mx, my, mz)
 
 @add_function("CoM_Dark_Matter_Density")
 def find_CoM_dm_density(data):
-    dc_x = data.quantities['WeightedAverageQuantity']('x', 'MatterDensityXDMMass')
-    dc_y = data.quantities['WeightedAverageQuantity']('y', 'MatterDensityXDMMass')
-    dc_z = data.quantities['WeightedAverageQuantity']('z', 'MatterDensityXDMMass')
-    return [dc_x, dc_y, dc_z]
+   dc_x, dc_y, dc_z = data.quantities['CenterOfMass'](use_cells=False, 
+                                                      use_particles=True)
+   return (dc_x, dc_y, dc_z)
 
 #### Gas Density ####
 
-def _GasDensityXCellMass(field, data):
-    return (data['Density'] * data['CellMassMsun'])
-def _Convert_GasDensityXCellMass(data):
-    return 1
-add_field("GasDensityXCellMass", units=r"",
-          function=_GasDensityXCellMass,
-          convert_function=_Convert_GasDensityXCellMass)
-
 @add_function("Min_Gas_Density")
 def find_minimum_gas_density(data):
-    ma, maxi, mx, my, mz, mg = data.quantities['MinLocation']('GasDensityXCellMass')
-    return [mx,my,mz]
+    ma, maxi, mx, my, mz, mg = data.quantities['MinLocation']('Density')
+    return (mx, my, mz)
 
 @add_function("Max_Gas_Density")
 def find_maximum_gas_density(data):
-    ma, maxi, mx, my, mz, mg = data.quantities['MaxLocation']('GasDensityXCellMass')
-    return [mx,my,mz]
+    ma, maxi, mx, my, mz, mg = data.quantities['MaxLocation']('Density')
+    return (mx, my, mz)
 
 @add_function("CoM_Gas_Density")
 def find_CoM_gas_density(data):
-    dc_x = data.quantities['WeightedAverageQuantity']('x', 'GasDensityXCellMass')
-    dc_y = data.quantities['WeightedAverageQuantity']('y', 'GasDensityXCellMass')
-    dc_z = data.quantities['WeightedAverageQuantity']('z', 'GasDensityXCellMass')
-    return [dc_x, dc_y, dc_z]
+   dc_x, dc_y, dc_z = data.quantities['CenterOfMass'](use_cells=True, 
+                                                      use_particles=False)
+   return (dc_x, dc_y, dc_z)
 
 #### Total Density ####
 
-def _TotalDensityXTotalMass(field, data):
-    return (data['Density'] + data['Dark_Matter_Density']) * \
-        data['TotalMassMsun']
-def _Convert_TotalDensityXTotalMass(data):
-    return 1
-add_field("TotalDensityXTotalMass", units=r"",
-          function=_TotalDensityXTotalMass,
-          convert_function=_Convert_TotalDensityXTotalMass)
-
 @add_function("Min_Total_Density")
 def find_minimum_total_density(data):
-    ma, maxi, mx, my, mz, mg = data.quantities['MinLocation']('TotalDensityXTotalMass')
-    return [mx,my,mz]
+    ma, maxi, mx, my, mz, mg = data.quantities['MinLocation']('Matter_Density')
+    return (mx, my, mz)
 
 @add_function("Max_Total_Density")
 def find_maximum_total_density(data):
-    ma, maxi, mx, my, mz, mg = data.quantities['MaxLocation']('TotalDensityXTotalMass')
-    return [mx,my,mz]
+    ma, maxi, mx, my, mz, mg = data.quantities['MaxLocation']('Matter_Density')
+    return (mx, my, mz)
 
 @add_function("CoM_Total_Density")
 def find_CoM_total_density(data):
-    dc_x = data.quantities['WeightedAverageQuantity']('x', 'TotalDensityXTotalMass')
-    dc_y = data.quantities['WeightedAverageQuantity']('y', 'TotalDensityXTotalMass')
-    dc_z = data.quantities['WeightedAverageQuantity']('z', 'TotalDensityXTotalMass')
-    return [dc_x, dc_y, dc_z]
+   dc_x, dc_y, dc_z = data.quantities['CenterOfMass'](use_cells=True, 
+                                                      use_particles=True)
+   return (dc_x, dc_y, dc_z)
 
 #### Temperature ####
 
-def _TemperatureXCellMass(field, data):
-    return (data['Temperature'] * data['CellMassMsun'])
-def _Convert_TemperatureXCellMass(data):
-    return 1
-add_field("TemperatureXCellMass", units=r"",
-          function=_TemperatureXCellMass,
-          convert_function=_Convert_TemperatureXCellMass)
-
 @add_function("Min_Temperature")
 def find_minimum_temperature(data):
-    ma, mini, mx, my, mz, mg = data.quantities['MinLocation']('TemperatureXCellMass')
-    return [mx,my,mz]
+    ma, mini, mx, my, mz, mg = data.quantities['MinLocation']('Temperature')
+    return (mx, my, mz)
 
 @add_function("Max_Temperature")
 def find_maximum_temperature(data):
-    ma, maxi, mx, my, mz, mg = data.quantities['MaxLocation']('TemperatureXCellMass')
-    return [mx,my,mz]
+    ma, maxi, mx, my, mz, mg = data.quantities['MaxLocation']('Temperature')
+    return (mx, my, mz)
 


--- a/yt/data_objects/derived_quantities.py	Fri Apr 15 11:03:32 2011 -0400
+++ b/yt/data_objects/derived_quantities.py	Fri Apr 15 14:38:50 2011 -0400
@@ -155,18 +155,21 @@
 add_quantity("TotalMass", function=_TotalMass,
              combine_function=_combTotalMass, n_ret = 2)
 
-def _CenterOfMass(data,use_particles=False):
+def _CenterOfMass(data, use_cells=True, use_particles=False):
     """
     This function returns the location of the center
     of mass. By default, it computes of the *non-particle* data in the object. 
 
-    :param use_particles: if True, will compute center of mass for
-    *all data* in the object (default: False)
+    :param use_cells: if True, will include the cell mass (default: True)
+    :param use_particles: if True, will include the particles in the 
+    object (default: False)
     """
-    x = (data["x"] * data["CellMassMsun"]).sum()
-    y = (data["y"] * data["CellMassMsun"]).sum()
-    z = (data["z"] * data["CellMassMsun"]).sum()
-    den = data["CellMassMsun"].sum()
+    x = y = z = den = 0
+    if use_cells: 
+        x += (data["x"] * data["CellMassMsun"]).sum()
+        y += (data["y"] * data["CellMassMsun"]).sum()
+        z += (data["z"] * data["CellMassMsun"]).sum()
+        den += data["CellMassMsun"].sum()
     if use_particles:
         x += (data["particle_position_x"] * data["ParticleMassMsun"]).sum()
         y += (data["particle_position_y"] * data["ParticleMassMsun"]).sum()


http://bitbucket.org/yt_analysis/yt/changeset/503ff7434f2d/
changeset:   r4135:503ff7434f2d
branch:      yt
user:        brittonsmith
date:        2011-04-15 20:41:37
summary:     Merged.
affected #:  2 files (1.3 KB)

--- a/yt/gui/reason/extdirect_repl.py	Fri Apr 15 14:38:50 2011 -0400
+++ b/yt/gui/reason/extdirect_repl.py	Fri Apr 15 14:41:37 2011 -0400
@@ -305,24 +305,31 @@
     def create_proj(self, pfname, axis, field, weight, onmax):
         if weight == "None": weight = None
         else: weight = "'%s'" % (weight)
+        if not onmax:
+            center_string = None
+        else:
+            center_string = "_tpf.h.find_max('Density')[1]"
         funccall = """
         _tpf = %(pfname)s
         _taxis = %(axis)s
         _tfield = "%(field)s"
         _tweight = %(weight)s
-        _tsl = _tpf.h.proj(_taxis,_tfield, weight_field=_tweight)
+        _tcen = %(center_string)s
+        _tsl = _tpf.h.proj(_taxis,_tfield, weight_field=_tweight, periodic = True, center=_tcen)
         _txax, _tyax = x_dict[_taxis], y_dict[_taxis]
         DLE, DRE = _tpf.domain_left_edge, _tpf.domain_right_edge
         from yt.visualization.plot_window import PWViewerExtJS
         _tpw = PWViewerExtJS(_tsl, (DLE[_txax], DRE[_txax], DLE[_tyax], DRE[_tyax]), setup = False)
         _tpw._current_field = _tfield
         _tpw.set_log(_tfield, True)
-        _twidget_data = {'fields': list(set(_tpf.h.field_list +
-                                        _tpf.h.derived_field_list)),
+        _tfield_list = list(set(_tpf.h.field_list + _tpf.h.derived_field_list))
+        _tfield_list.sort()
+        _twidget_data = {'fields': _tfield_list,
                          'initial_field': _tfield}
         """ % dict(pfname = pfname,
                    axis = inv_axis_names[axis],
                    weight = weight,
+                   center_string = center_string,
                    field=field)
         # There is a call to do this, but I have forgotten it ...
         funccall = "\n".join((line.strip() for line in funccall.splitlines()))
@@ -345,14 +352,14 @@
         _tfield = "%(field)s"
         _tcenter = %(center_string)s
         _tcoord = _tcenter[_taxis]
-        _tsl = _tpf.h.slice(_taxis, _tcoord, center = _tcenter)
+        _tsl = _tpf.h.slice(_taxis, _tcoord, center = _tcenter, periodic = True)
         _txax, _tyax = x_dict[_taxis], y_dict[_taxis]
         DLE, DRE = _tpf.domain_left_edge, _tpf.domain_right_edge
         from yt.visualization.plot_window import PWViewerExtJS
         _tpw = PWViewerExtJS(_tsl, (DLE[_txax], DRE[_txax], DLE[_tyax], DRE[_tyax]), setup = False)
         _tpw._current_field = _tfield
         _tpw.set_log(_tfield, True)
-        _tfield_list = _tpf.h.field_list + _tpf.h.derived_field_list
+        _tfield_list = list(set(_tpf.h.field_list + _tpf.h.derived_field_list))
         _tfield_list.sort()
         _twidget_data = {'fields': _tfield_list,
                          'initial_field': _tfield}


--- a/yt/visualization/plot_window.py	Fri Apr 15 14:38:50 2011 -0400
+++ b/yt/visualization/plot_window.py	Fri Apr 15 14:41:37 2011 -0400
@@ -28,6 +28,7 @@
 import color_maps
 from image_writer import \
     write_image, apply_colormap
+from yt.funcs import *
 from yt.utilities.amr_utils import write_png_to_file
 from fixed_resolution import \
     FixedResolutionBuffer
@@ -52,7 +53,7 @@
     return newfunc
 
 class PlotWindow(object):
-    def __init__(self, data_source, bounds, buff_size=(800,800), antialias = True):
+    def __init__(self, data_source, bounds, buff_size=(800,800), antialias = True, periodic = True):
         r"""
         PlotWindow(data_source, bounds, buff_size=(800,800), antialias = True)
         
@@ -83,11 +84,16 @@
 
         """
         self._initfinished = False
+        self.center = None
         self.plots = {}
+        self._periodic = periodic
         self.data_source = data_source
         self.buff_size = buff_size
         self.antialias = True
         self.set_window(bounds) # this automatically updates the data and plot
+        if self.data_source.center is not None:
+            center = [self.data_source.center[i] for i in range(len(self.data_source.center)) if i != self.data_source.axis]
+            self.set_center(center)
         self._initfinished = True
 
     def __getitem__(self, item):
@@ -98,7 +104,7 @@
             bounds = self.bounds
             self._frb = FixedResolutionBuffer(self.data_source, 
                                               bounds, self.buff_size, 
-                                              self.antialias)
+                                              self.antialias, periodic=self._periodic)
         except:
             raise RuntimeError("Failed to repixelize.")
         self._frb._get_data_source_fields()
@@ -171,9 +177,17 @@
 
     @invalidate_data
     def set_window(self, bounds):
-        self.xlim = bounds[0:2]
-        self.ylim = bounds[2:]
-
+        if self.center is not None:
+            dx = bounds[1] - bounds[0]
+            dy = bounds[3] - bounds[2]
+            self.xlim = (self.center[0] - dx/2., self.center[0] + dx/2.)
+            self.ylim = (self.center[1] - dy/2., self.center[1] + dy/2.)
+            mylog.info("xlim = %f %f" %self.xlim)
+            mylog.info("ylim = %f %f" %self.ylim)
+        else:
+            self.xlim = bounds[0:2]
+            self.ylim = bounds[2:]
+        
     @invalidate_data
     def set_width(self, new_width):
         """set the width of the plot window
@@ -192,12 +206,24 @@
         self.ylim[0] = centery - new_width/2.
         self.ylim[1] = centery + new_width/2.
 
+    @invalidate_data
+    def set_center(self, new_center):
+        if new_center is None:
+            self.center = None
+        else:
+            self.center = new_center
+        self.set_window(self.bounds)
+
     @property
     def width(self):
         Wx = self.xlim[1] - self.xlim[0]
         Wy = self.ylim[1] - self.ylim[0]
         return (Wx, Wy)
 
+    # @property
+    # def window(self):
+    #     return self.xlim + self.ylim
+
     @invalidate_data
     def set_antialias(self,aa):
         self.antialias = aa
@@ -218,6 +244,7 @@
 
         if setup: self._setup_plots()
 
+    @invalidate_plot
     def set_log(self,field,log):
         """set a field to log or linear.

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