[Yt-svn] yt: [svn r1743] Changed naming conventions of modules with class...
hg at spacepope.org
hg at spacepope.org
Mon Jun 7 11:45:16 PDT 2010
hg Repository: yt
details: yt/rev/ea258e3dfc95
changeset: 1752:ea258e3dfc95
user: britton
date:
Mon Jun 07 14:38:23 2010 -0400
description:
[svn r1743] Changed naming conventions of modules with classes from ThisModule.py to
this_module.
diffstat:
yt/extensions/HaloFilters.py | 115 -----
yt/extensions/HaloProfiler.py | 826 -----------------------------------
yt/extensions/halo_filters.py | 115 +++++
yt/extensions/halo_profiler.py | 826 +++++++++++++++++++++++++++++++++++
yt/extensions/lightcone/HaloMask.py | 2 +-
yt/extensions/lightcone/LightCone.py | 556 ------------------------
yt/extensions/lightcone/UniqueSolution.py | 2 +-
yt/extensions/lightcone/light_cone.py | 556 ++++++++++++++++++++++++
yt/extensions/mods.py | 4 +-
yt/lagos/__init__.py | 2 +-
yt/lagos/clump.py | 290 ++++++++++++
11 files changed, 1792 insertions(+), 1502 deletions(-)
diffs (truncated from 3369 to 300 lines):
diff -r e9e1e992e77e -r ea258e3dfc95 yt/extensions/HaloFilters.py
--- a/yt/extensions/HaloFilters.py Sun Jun 06 18:51:30 2010 -0400
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,115 +0,0 @@
-"""
-Halo filters to be used with the HaloProfiler.
-
-Author: Britton Smith <brittons at origins.colorado.edu>
-Affiliation: CASA/University of CO, Boulder
-Homepage: http://yt.enzotools.org/
-License:
- Copyright (C) 2008-2009 Britton Smith. All Rights Reserved.
-
- This file is part of yt.
-
- yt is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-"""
-
-from yt.logger import lagosLogger as mylog
-from copy import deepcopy
-import numpy as na
-
-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.
- Return values are a True or False whether the halo passed the filter,
- along with a dictionary of virial quantities for the fields specified in
- the virial_quantities keyword. Thresholds for virial quantities are
- given with the virial_filters keyword in the following way:
- [field, condition, value].
- """
-
- fields = deepcopy(virial_quantities)
- if virial_filters is None: virial_filters = []
- for vfilter in virial_filters:
- if not vfilter[0] in fields:
- fields.append(vfilter[0])
-
- overDensity = []
- temp_profile = {}
- for field in fields:
- temp_profile[field] = []
-
- for q in range(len(profile[overdensity_field])):
- good = True
- if (profile[overdensity_field][q] != profile[overdensity_field][q]):
- good = False
- continue
- for field in fields:
- if (profile[field][q] != profile[field][q]):
- good = False
- break
- if good:
- overDensity.append(profile[overdensity_field][q])
- for field in fields:
- temp_profile[field].append(profile[field][q])
-
- virial = {}
- for field in fields:
- virial[field] = 0.0
-
- if (not (na.array(overDensity) >= virial_overdensity).any()) and \
- must_be_virialized:
- mylog.error("This halo is not virialized!")
- return [False, {}]
-
- if (len(overDensity) < 2):
- mylog.error("Skipping halo with no valid points in profile.")
- return [False, {}]
-
- if (overDensity[1] <= virial_overdensity):
- index = 0
- elif (overDensity[-1] >= virial_overdensity):
- index = -2
- else:
- for q in (na.arange(len(overDensity)-2))+2:
- if (overDensity[q] < virial_overdensity):
- index = q - 1
- break
-
- if type(virial_index) is list:
- virial_index.append(index)
-
- for field in fields:
- if (overDensity[index+1] - overDensity[index]) == 0:
- mylog.error("Overdensity profile has slope of zero.")
- return [False, {}]
- else:
- slope = (temp_profile[field][index+1] - temp_profile[field][index]) / \
- (overDensity[index+1] - overDensity[index])
- value = slope * (virial_overdensity - overDensity[index]) + \
- temp_profile[field][index]
- virial[field] = value
-
- 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]]))
- continue
- else:
- 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)]
-
diff -r e9e1e992e77e -r ea258e3dfc95 yt/extensions/HaloProfiler.py
--- a/yt/extensions/HaloProfiler.py Sun Jun 06 18:51:30 2010 -0400
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,826 +0,0 @@
-"""
-HaloProfiler class and member functions.
-
-Author: Britton Smith <brittons at origins.colorado.edu>
-Affiliation: CASA/University of CO, Boulder
-Homepage: http://yt.enzotools.org/
-License:
- Copyright (C) 2008-2009 Britton Smith. All Rights Reserved.
-
- This file is part of yt.
-
- yt is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-"""
-
-import yt.lagos as lagos
-from yt.lagos.HaloFinding import HaloFinder
-from yt.logger import lagosLogger as mylog
-import yt.raven as raven
-from HaloFilters import *
-import numpy as na
-import os
-import h5py
-import types
-
-PROFILE_RADIUS_THRESHOLD = 2
-
-class HaloProfiler(lagos.ParallelAnalysisInterface):
- "Radial profiling, filtering, and projections for halos in cosmological simulations."
- def __init__(self, dataset, halos='multiple', halo_list_file='HopAnalysis.out', halo_list_format='yt_hop',
- halo_finder_function=HaloFinder, halo_finder_args=None, halo_finder_kwargs=None,
- use_density_center=False, density_center_exponent=1.0, use_field_max_center=None,
- halo_radius=0.1, radius_units='1', n_profile_bins=50,
- 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']):
- """
- Initialize a HaloProfiler object.
- :param halos (str): "multiple" for profiling more than one halo. In this mode halos are read in
- from a list or identified with a halo finder. In "single" mode, the one and only halo
- center is identified automatically as the location of the peak in the density field.
- Default: "multiple".
- :param halo_list_file (str): name of file containing the list of halos. The HaloProfiler will
- look for this file in the data directory. Default: "HopAnalysis.out".
- :param halo_list_format (str or dict): the format of the halo list file. "yt_hop" for the format
- given by yt's halo finders. "enzo_hop" for the format written by enzo_hop. This keyword
- can also be given in the form of a dictionary specifying the column in which various
- properties can be found. For example, {"id": 0, "center": [1, 2, 3], "mass": 4, "radius": 5}.
- Default: "yt_hop".
- :param halo_finder_function (function): If halos is set to multiple and the file given by
- halo_list_file does not exit, the halo finding function specified here will be called.
- Default: HaloFinder (yt_hop).
- :param halo_finder_args (tuple): args given with call to halo finder function. Default: None.
- :param halo_finder_kwargs (dict): kwargs given with call to halo finder function. Default: None.
- :param use_density_center (bool): re-center halos before performing profiles with an center of mass
- weighted by overdensity. This is generally not needed. Default: False.
- :param density_center_exponent (float): when use_density_center set to True, this specifies the
- exponent, alpha, such that the halo center calculation is weighted by overdensity^alpha.
- Default: 1.0.
- :param use_field_max_center (str): another alternative for halo re-centering by selecting the
- location of the maximum of the field given by this keyword. This is generally not needed.
- Default: None.
- :param halo_radius (float): if no halo radii are provided in the halo list file, this parameter is
- used to specify the radius out to which radial profiles will be made. This keyword is also
- used when halos is set to single. Default: 0.1.
- :param radius_units (str): the units of halo_radius. Default: "1" (code units).
- :param n_profile_bins (int): the number of bins in the radial profiles. Default: 50.
- :param profile_output_dir (str): the subdirectory, inside the data directory, in which radial profile
- output files will be created. The directory will be created if it does not exist.
- Default: "radial_profiles".
- :param projection_output_dir (str): the subdirectory, inside the data directory, in which projection
- output files will be created. The directory will be created if it does not exist.
- Default: "projections".
- :param projection_width (float): the width of halo projections. Default: 8.0.
- :param projection_width_units (str): the units of projection_width. Default: "mpc".
- :param project_at_level (int or "max"): the maximum refinement level to be included in projections.
- Default: "max" (maximum level within the dataset).
- :param velocity_center (list): the method in which the halo bulk velocity is calculated (used for
- calculation of radial and tangential velocities. Valid options are:
- - ["bulk", "halo"] (Default): the velocity provided in the halo list
- - ["bulk", "sphere"]: the bulk velocity of the sphere centered on the halo center.
- - ["max", field]: the velocity of the cell that is the location of the maximum of the field
- 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'].
- """
-
- self.dataset = dataset
-
- self.profile_output_dir = profile_output_dir
- self.projection_output_dir = projection_output_dir
- self.n_profile_bins = n_profile_bins
- self.projection_width = projection_width
- self.projection_width_units = projection_width_units
- self.project_at_level = project_at_level
- self.filter_quantities = filter_quantities
- if self.filter_quantities is None: self.filter_quantities = []
-
- self.profile_fields = []
- self.projection_fields = []
-
- self._halo_filters = []
- self.all_halos = []
- self.filtered_halos = []
- self._projection_halo_list = []
-
- # Set halo finder function and parameters, if needed.
- self.halo_finder_function = halo_finder_function
- self.halo_finder_args = halo_finder_args
- if self.halo_finder_args is None: self.halo_finder_args = ()
- self.halo_finder_kwargs = halo_finder_kwargs
- if self.halo_finder_kwargs is None: self.halo_finder_kwargs = {}
-
- # Set option to get halos from hop or single halo at density maximum.
- # multiple: get halos from hop
- # single: get single halo from density maximum
- self.halos = halos
- if not(self.halos is 'multiple' or self.halos is 'single'):
- mylog.error("Keyword, halos, must be either 'single' or 'multiple'.")
- return None
-
- # Set halo list format.
- # 'yt_hop': yt hop output.
- # 'enzo_hop': enzo_hop output.
- # dictionary: a dictionary containing fields and their corresponding columns.
- self.halo_list_file = halo_list_file
- if halo_list_format == 'yt_hop':
- self.halo_list_format = {'id':0, 'mass':1, 'center':[7, 8, 9], 'velocity':[10, 11, 12], 'r_max':13}
- elif halo_list_format == 'enzo_hop':
- self.halo_list_format = {'id':0, 'center':[4, 5, 6]}
- elif isinstance(halo_list_format, types.DictType):
- self.halo_list_format = halo_list_format
- else:
- mylog.error("Keyword, halo_list_format, must be 'yt_hop', 'enzo_hop', or a dictionary of custom settings.")
- return None
-
- # Option to recenter sphere on density center.
- self.use_density_center = use_density_center
- self.density_center_exponent = density_center_exponent
- if self.use_density_center:
- def _MatterDensityXTotalMass(field, data):
- return na.power((data['Matter_Density'] * data['TotalMassMsun']), self.density_center_exponent)
- def _Convert_MatterDensityXTotalMass(data):
- return 1
- lagos.add_field("MatterDensityXTotalMass", units=r"",
- function=_MatterDensityXTotalMass,
- convert_function=_Convert_MatterDensityXTotalMass)
-
- # Option to recenter sphere on the location of a field max.
- self.use_field_max_center = use_field_max_center
- if self.use_field_max_center is not None:
- self.use_density_center = False
-
- # Look for any field that might need to have the bulk velocity set.
- self._need_bulk_velocity = False
- for field in [hp['field'] for hp in self.profile_fields]:
- if 'Velocity' in field or 'Mach' in field:
- self._need_bulk_velocity = True
- break
-
- # Check validity for VelocityCenter parameter which toggles how the
- # velocity is zeroed out for radial velocity profiles.
- self.velocity_center = velocity_center[:]
- if self.velocity_center[0] == 'bulk':
- if self.velocity_center[1] == 'halo' and \
- self.halos is 'single':
- mylog.error("Parameter, VelocityCenter, must be set to 'bulk sphere' or 'max <field>' with halos flag set to 'single'.")
More information about the yt-svn
mailing list