[Yt-svn] commit/yt: brittonsmith: Added output_dir keyword arg to halo profiler to allow all output to be
Bitbucket
commits-noreply at bitbucket.org
Sat Mar 5 10:28:29 PST 2011
1 new changeset in yt:
http://bitbucket.org/yt_analysis/yt/changeset/4473e60cd73e/
changeset: r3793:4473e60cd73e
branch: yt
user: brittonsmith
date: 2011-03-05 19:28:08
summary: Added output_dir keyword arg to halo profiler to allow all output to be
put into a separate path. Also, changed default halo profiler to
parallel hop.
affected #: 1 file (1.6 KB)
--- a/yt/analysis_modules/halo_profiler/multi_halo_profiler.py Fri Mar 04 11:58:40 2011 -0700
+++ b/yt/analysis_modules/halo_profiler/multi_halo_profiler.py Sat Mar 05 13:28:08 2011 -0500
@@ -34,8 +34,7 @@
load
from yt.data_objects.profiles import \
BinnedProfile1D, EmptyProfileData
-from yt.analysis_modules.halo_finding.api import \
- HaloFinder
+from yt.analysis_modules.halo_finding.api import *
from .halo_filters import \
VirialFilter
from yt.data_objects.field_info_container import \
@@ -54,15 +53,23 @@
class HaloProfiler(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,
+ def __init__(self, dataset, output_dir=None,
+ halos='multiple', halo_list_file='HopAnalysis.out',
+ halo_list_format='yt_hop', halo_finder_function=parallelHF,
+ halo_finder_args=None,
+ 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,
+ 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 output_dir (str): if specified, all output will be put into this path instead of
+ in the dataset directories. Default: None.
: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.
@@ -114,7 +121,7 @@
"""
self.dataset = dataset
-
+ self.output_dir = output_dir
self.profile_output_dir = profile_output_dir
self.projection_output_dir = projection_output_dir
self.n_profile_bins = n_profile_bins
@@ -132,6 +139,10 @@
self.filtered_halos = []
self._projection_halo_list = []
+ # Create output directory if specified
+ if self.output_dir is not None:
+ self.__check_directory(self.output_dir)
+
# Set halo finder function and parameters, if needed.
self.halo_finder_function = halo_finder_function
self.halo_finder_args = halo_finder_args
@@ -153,7 +164,8 @@
# 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}
+ self.halo_list_format = {'id':0, 'mass':1, 'np': 2,
+ '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 halo_list_format == 'p-groupfinder':
@@ -169,7 +181,8 @@
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)
+ return na.power((data['Matter_Density'] * data['TotalMassMsun']),
+ self.density_center_exponent)
def _Convert_MatterDensityXTotalMass(data):
return 1
add_field("MatterDensityXTotalMass", units=r"",
@@ -288,8 +301,14 @@
# Add profile fields necessary for calculating virial quantities.
if virial_filter: self._check_for_needed_profile_fields()
- outputDir = "%s/%s" % (self.pf.fullpath, self.profile_output_dir)
- self.__check_directory(outputDir)
+ # Create output directory.
+ 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,
+ self.profile_output_dir)
+ else:
+ my_output_dir = "%s/%s" % (self.pf.fullpath, self.profile_output_dir)
+ self.__check_directory(my_output_dir)
# Profile all halos.
for halo in self._get_objs('all_halos', round_robin=True):
@@ -305,7 +324,7 @@
if filter_result and len(self.profile_fields) > 0:
- profile_filename = "%s/Halo_%04d_profile.dat" % (outputDir, halo['id'])
+ profile_filename = "%s/Halo_%04d_profile.dat" % (my_output_dir, halo['id'])
profiledHalo = self._get_halo_profile(halo, profile_filename, virial_filter=virial_filter)
@@ -456,8 +475,14 @@
(self.pf.parameters['RefineBy']**proj_level)
projectionResolution = int(self.projection_width / proj_dx)
- outputDir = "%s/%s" % (self.pf.fullpath, self.projection_output_dir)
- self.__check_directory(outputDir)
+ # Create output directory.
+ 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,
+ self.projection_output_dir)
+ else:
+ my_output_dir = "%s/%s" % (self.pf.fullpath, self.projection_output_dir)
+ self.__check_directory(my_output_dir)
center = [0.5 * (self.pf.parameters['DomainLeftEdge'][w] + self.pf.parameters['DomainRightEdge'][w])
for w in range(self.pf.parameters['TopGridRank'])]
@@ -519,7 +544,7 @@
if save_cube:
axis_labels = ['x', 'y', 'z']
dataFilename = "%s/Halo_%04d_%s_data.h5" % \
- (outputDir, halo['id'], axis_labels[w])
+ (my_output_dir, halo['id'], axis_labels[w])
mylog.info("Saving projection data to %s." % dataFilename)
output = h5py.File(dataFilename, "a")
@@ -535,7 +560,7 @@
output.close()
if save_images:
- pc.save("%s/Halo_%04d" % (outputDir, halo['id']), force_save=True)
+ pc.save("%s/Halo_%04d" % (my_output_dir, halo['id']), force_save=True)
del region
@@ -573,13 +598,17 @@
if filename is None:
filename = self.halo_list_file
- hopFile = "%s/%s" % (self.pf.fullpath, filename)
+ if self.output_dir is not None:
+ self.__check_directory("%s/%s" % (self.output_dir, self.pf.directory))
+ hop_file = "%s/%s/%s" % (self.output_dir, self.pf.directory, filename)
+ else:
+ hop_file = "%s/%s" % (self.pf.fullpath, filename)
- if not(os.path.exists(hopFile)):
- mylog.info("Hop file not found, running hop to get halos.")
- self._run_hop(hopFile)
+ if not(os.path.exists(hop_file)):
+ mylog.info("Halo finder file not found, running halo finder to get halos.")
+ self._run_hop(hop_file)
- self.all_halos = self._read_halo_list(hopFile)
+ self.all_halos = self._read_halo_list(hop_file)
def _read_halo_list(self, listFile):
"""
@@ -685,11 +714,11 @@
return None
@parallel_blocking_call
- def _run_hop(self, hopFile):
+ def _run_hop(self, hop_file):
"Run hop to get halos."
hop_results = self.halo_finder_function(self.pf, *self.halo_finder_args, **self.halo_finder_kwargs)
- hop_results.write_out(hopFile)
+ hop_results.write_out(hop_file)
del hop_results
self.pf.h.clear_all_data()
@@ -752,13 +781,13 @@
fid.close()
@parallel_root_only
- def __check_directory(self, outputDir):
- if (os.path.exists(outputDir)):
- if not(os.path.isdir(outputDir)):
- mylog.error("Output directory exists, but is not a directory: %s." % outputDir)
- raise IOError(outputDir)
+ def __check_directory(self, my_output_dir):
+ if (os.path.exists(my_output_dir)):
+ if not(os.path.isdir(my_output_dir)):
+ mylog.error("Output directory exists, but is not a directory: %s." % my_output_dir)
+ raise IOError(my_output_dir)
else:
- os.mkdir(outputDir)
+ os.mkdir(my_output_dir)
def shift_projections(pf, pc, oldCenter, newCenter, axis):
"""
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