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

Bitbucket commits-noreply at bitbucket.org
Wed Jul 25 11:32:29 PDT 2012


3 new commits in yt:


https://bitbucket.org/yt_analysis/yt/changeset/54191f79dd8c/
changeset:   54191f79dd8c
branch:      yt
user:        brittonsmith
date:        2012-07-25 17:23:54
summary:     Fixed some issues with using an output_dir with the halo profiler.
affected #:  1 file

diff -r 01ebfe5512122b5181ec1058a380bd2fa42754b4 -r 54191f79dd8c9fb2aa40b75c1e17bd83816cbaf8 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
@@ -61,68 +61,68 @@
 class HaloProfiler(ParallelAnalysisInterface):
     "Radial profiling, filtering, and projections for halos in cosmological simulations."
     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, 
+                 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),
                  halo_radius=None, 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', 'r_max'], 
+                 velocity_center=['bulk', 'halo'], filter_quantities=['id', 'center', 'r_max'],
                  use_critical_density=False):
         r"""Initialize a Halo Profiler object.
-        
+
         In order to run the halo profiler, the Halo Profiler object must be
         instantiated. At the minimum, the path to a parameter file
         must be provided as the first term.
-        
+
         Parameters
         ----------
-        
+
         dataset : string, required
             The path to the parameter file for the dataset to be analyzed.
         output_dir : string, optional
-            If specified, all output will be put into this path instead of 
+            If specified, all output will be put into this path instead of
             in the dataset directories.  Default: None.
         halos :  {"multiple", "single"}, optional
-            For profiling more than one halo.  In this mode halos are read in 
+            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 
+            the one and only halo
             center is identified automatically as the location of the peak
-            in the density field.  
+            in the density field.
             Default: "multiple".
         halo_list_file : string, optional
             The name of a file containing the list of halos.  The HaloProfiler
             will  look for this file in the data directory.
             Default: "HopAnalysis.out".
         halo_list_format : {string, dict}
-            The format of the halo list file.  "yt_hop" for the format 
+            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. "p-groupfinder"  for P-Groupfinder.  This keyword 
+            by enzo_hop. "p-groupfinder"  for P-Groupfinder.  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".
         halo_finder_function : function
-            If halos is set to multiple and the file given by 
+            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.  
+            specified here will be called.
             Default: HaloFinder (yt_hop).
         halo_finder_args : tuple
             Args given with call to halo finder function.  Default: None.
         halo_finder_kwargs : dict
             kwargs given with call to halo finder function. Default: None.
         recenter : {string, 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 
+            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 
+            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
@@ -145,31 +145,31 @@
         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 
+            profiles will be made.  This keyword is also
             used when halos is set to single.  Default: 0.1.
         radius_units : string
             The units of halo_radius.  Default: "1" (code units).
         n_profile_bins : int
             The number of bins in the radial profiles.  Default: 50.
         profile_output_dir : str
-            The subdirectory, inside the data directory, in which radial profile 
+            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.  
+            The directory will be created if it does not exist.
             Default: "radial_profiles".
         projection_output_dir : str
-            The subdirectory, inside the data directory, in which projection 
+            The subdirectory, inside the data directory, in which projection
             output files will be created.
-            The directory will be created if it does not exist.  
+            The directory will be created if it does not exist.
             Default: "projections".
         projection_width : float
             The width of halo projections.  Default: 8.0.
         projection_width_units : string
             The units of projection_width. Default: "mpc".
         project_at_level : {"max", int}
-            The maximum refinement level to be included in projections.  
+            The maximum refinement level to be included in projections.
             Default: "max" (maximum level within the dataset).
         velocity_center  : array_like
-            The method in which the halo bulk velocity is calculated (used for 
+            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
@@ -178,26 +178,23 @@
     	        * ["max", field]: the velocity of the cell that is the
     	          location of the maximum of the field specified.
         filter_quantities : array_like
-            Quantities from the original halo list file to be written out in the 
+            Quantities from the original halo list file to be written out in the
             filtered list file.  Default: ['id','center'].
         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.
-        
+
         Examples
         --------
         >>> from yt.analysis_modules.halo_profiler.api import *
         >>> hp = HaloProfiler("RedshiftOutput0005/RD0005")
-        
+
         """
         ParallelAnalysisInterface.__init__(self)
 
         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
         self.projection_width = projection_width
         self.projection_width_units = projection_width_units
@@ -213,10 +210,6 @@
         self.all_halos = []
         self.filtered_halos = []
 
-        # 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
@@ -238,7 +231,7 @@
         # 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, 'np': 2, 
+            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]}
@@ -255,8 +248,8 @@
 
         # Flag for whether calculating halo bulk velocity is necessary.
         self._need_bulk_velocity = False
-        
-        # Check validity for VelocityCenter parameter which toggles how the 
+
+        # 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':
@@ -268,7 +261,7 @@
                     self.halo_list_format is 'enzo_hop':
                 mylog.error("Parameter, VelocityCenter, must be 'bulk sphere' for old style hop output files.")
                 return None
-            if not(self.velocity_center[1] == 'halo' or 
+            if not(self.velocity_center[1] == 'halo' or
                    self.velocity_center[1] == 'sphere'):
                 mylog.error("Second value of VelocityCenter must be either 'halo' or 'sphere' if first value is 'bulk'.")
                 return None
@@ -285,6 +278,17 @@
             self.pf = load(self.dataset)
         self.pf.h
 
+        # Create output directories.
+        self.output_dir = output_dir
+        if output_dir is None:
+            output_dir = '.'
+        else:
+            self.__check_directory(output_dir)
+        self.output_dir = os.path.join(output_dir, os.path.basename(self.pf.fullpath))
+        self.__check_directory(self.output_dir)
+        self.profile_output_dir = os.path.join(self.output_dir, profile_output_dir)
+        self.projection_output_dir = os.path.join(self.output_dir, projection_output_dir)
+
         # Figure out what max radius to use for profiling.
         if halo_radius is not None:
             self.halo_radius = halo_radius / self.pf[radius_units]
@@ -315,7 +319,7 @@
         r"""Filters can be added to create a refined list of halos based on
         their profiles or to avoid profiling halos altogether based on
         information given in the halo list file.
-        
+
         It is often the case that one is looking to identify halos with a
         specific set of properties. This can be accomplished through the
         creation of filter functions. A filter function can take as many args
@@ -323,11 +327,11 @@
         object, or at least a dictionary which contains the profile arrays
         for each field. Filter functions must return a list of two things.
         The first is a True or False indicating whether the halo passed the
-        filter. The second is a dictionary containing quantities calculated 
+        filter. The second is a dictionary containing quantities calculated
         for that halo that will be written to a file if the halo passes the
         filter. A sample filter function based on virial quantities can be
         found in yt/analysis_modules/halo_profiler/halo_filters.py.
-        
+
         Parameters
         ----------
         function : function
@@ -336,7 +340,7 @@
             Arguments passed to the halo filter function.
         kwargs : values
             Arguments passed to the halo filter function.
-        
+
         Examples
         -------
         >>> hp.add_halo_filter(HP.VirialFilter, must_be_virialized=True,
@@ -344,18 +348,18 @@
                 virial_overdensity=200,
                 virial_filters=[['TotalMassMsun','>=','1e14']],
                 virial_quantities=['TotalMassMsun','RadiusMpc'])
-        
+
         """
 
         self._halo_filters.append({'function':function, 'args':args, 'kwargs':kwargs})
 
     def add_profile(self, field, weight_field=None, accumulation=False):
         r"""Add a field for profiling.
-        
+
         Once the halo profiler object has been instantiated,
         fields can be added for profiling using this function. This function
         may be called multiple times, once per field to be added.
-        
+
         Parameters
         ----------
         field : string
@@ -366,28 +370,28 @@
         accumulation : bool
             Whether or not the `field` values should be summed up with the
             radius of the profile.
-        
+
         Examples
         >>> hp.add_profile('CellVolume', weight_field=None, accumulation=True)
         >>> hp.add_profile('TotalMassMsun', weight_field=None, accumulation=True)
         >>> hp.add_profile('Density', weight_field=None, accumulation=False)
         >>> hp.add_profile('Temperature', weight_field='CellMassMsun', accumulation=False)
-            
+
         """
 
         # Check for any field that might need to have the bulk velocity set.
         if 'Velocity' in field or 'Mach' in field:
             self._need_bulk_velocity = True
 
-        self.profile_fields.append({'field':field, 'weight_field':weight_field, 
+        self.profile_fields.append({'field':field, 'weight_field':weight_field,
                                     'accumulation':accumulation})
 
     def add_projection(self, field, weight_field=None, cmap='algae'):
         r"""Make a projection of the specified field.
-        
+
         For the given field, a projection will be produced that can be saved
         to HDF5 or image format. See `make_projections`.
-        
+
         Parameters
         ----------
         field : string
@@ -398,7 +402,7 @@
         cmap : string
             The name of the matplotlib color map that will be used if an
             image is made from the projection. Default="algae".
-        
+
         Examples
         --------
         >>> hp.add_projection('Density', weight_field=None)
@@ -411,17 +415,17 @@
         if 'Velocity' in field or 'Mach' in field:
             self._need_bulk_velocity = True
 
-        self.projection_fields.append({'field':field, 'weight_field':weight_field, 
+        self.projection_fields.append({'field':field, 'weight_field':weight_field,
                                        'cmap': cmap})
 
     @parallel_blocking_call
     def make_profiles(self, filename=None, prefilters=None, njobs=-1,
                       dynamic=False, profile_format='ascii'):
         r"""Make radial profiles for all halos in the list.
-        
+
         After all the calls to `add_profile`, this will trigger the actual
         calculations and output the profiles to disk.
-        
+
         Paramters
         ---------
         filename : str
@@ -447,12 +451,12 @@
         profile_format : str
             The file format for the radial profiles, 'ascii' or 'hdf5'.
             Default: 'ascii'.
-        
+
         Examples
         --------
         >>> hp.make_profiles(filename="FilteredQuantities.out",
                  prefilters=["halo['mass'] > 1e13"])
-        
+
         """
 
         extension_map = {'ascii': 'dat',
@@ -496,13 +500,7 @@
         if virial_filter: self._check_for_needed_profile_fields()
 
         # 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)
+        self.__check_directory(self.profile_output_dir)
 
         # Profile all halos.
         updated_halos = []
@@ -519,7 +517,7 @@
             if filter_result and len(self.profile_fields) > 0:
 
                 profile_filename = "%s/Halo_%04d_profile.%s" % \
-                    (my_output_dir, halo['id'], extension_map[profile_format])
+                    (self.profile_output_dir, halo['id'], extension_map[profile_format])
 
                 profiledHalo = self._get_halo_profile(halo, profile_filename,
                                                       virial_filter=virial_filter)
@@ -529,7 +527,7 @@
 
                 # Apply filter and keep track of the quantities that are returned.
                 for hFilter in self._halo_filters:
-                    filter_result, filterQuantities = hFilter['function'](profiledHalo, *hFilter['args'], 
+                    filter_result, filterQuantities = hFilter['function'](profiledHalo, *hFilter['args'],
                                                                           **hFilter['kwargs'])
 
                     if not filter_result: break
@@ -560,7 +558,7 @@
         self.filtered_halos.sort(key=lambda a:a['id'])
 
         if filename is not None:
-            self._write_filtered_halo_list(filename)
+            self._write_filtered_halo_list(os.path.join(self.output_dir, filename))
 
     def _get_halo_profile(self, halo, filename, virial_filter=True,
             force_write=False):
@@ -656,7 +654,7 @@
             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. 
+            # Expand the halo to account for recentering.
             halo['r_max'] += d / 1000. # d is in kpc -> want mpc
             new_sphere = True
 
@@ -675,8 +673,8 @@
                     sphere.set_field_parameter('bulk_velocity', halo['velocity'])
                 elif self.velocity_center[1] == 'sphere':
                     mylog.info('Calculating sphere bulk velocity.')
-                    sphere.set_field_parameter('bulk_velocity', 
-                                               sphere.quantities['BulkVelocity'](lazy_reader=True, 
+                    sphere.set_field_parameter('bulk_velocity',
+                                               sphere.quantities['BulkVelocity'](lazy_reader=True,
                                                                                  preload=False))
                 else:
                     mylog.error("Invalid parameter: velocity_center.")
@@ -699,10 +697,10 @@
                          save_images=False, save_cube=True, njobs=-1,
                          dynamic=False):
         r"""Make projections of all halos using specified fields.
-        
+
         After adding fields using `add_projection`, this starts the actual
         calculations and saves the output to disk.
-        
+
         Parameters
         ---------
         axes = array_like
@@ -725,12 +723,12 @@
             If True, distribute halos using a task queue.  If False,
             distribute halos evenly over all jobs.
             Default: False.
-        
+
         Examples
         --------
         >>> hp.make_projections(axes=[0, 1, 2], save_cube=True,
             save_images=True, halo_list="filtered")
-        
+
         """
 
         # Get list of halos for projecting.
@@ -761,15 +759,9 @@
         projectionResolution = int(self.projection_width / proj_dx)
 
         # 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)
+        self.__check_directory(self.projection_output_dir)
 
-        center = [0.5 * (self.pf.parameters['DomainLeftEdge'][w] + 
+        center = [0.5 * (self.pf.parameters['DomainLeftEdge'][w] +
                          self.pf.parameters['DomainRightEdge'][w])
                   for w in range(self.pf.parameters['TopGridRank'])]
 
@@ -778,15 +770,15 @@
                 continue
             # Check if region will overlap domain edge.
             # Using non-periodic regions is faster than using periodic ones.
-            leftEdge = [(halo['center'][w] - 
+            leftEdge = [(halo['center'][w] -
                          0.5 * self.projection_width/self.pf.units[self.projection_width_units])
                         for w in range(len(halo['center']))]
-            rightEdge = [(halo['center'][w] + 
+            rightEdge = [(halo['center'][w] +
                           0.5 * self.projection_width/self.pf.units[self.projection_width_units])
                          for w in range(len(halo['center']))]
 
             mylog.info("Projecting halo %04d in region: [%f, %f, %f] to [%f, %f, %f]." %
-                       (halo['id'], leftEdge[0], leftEdge[1], leftEdge[2], 
+                       (halo['id'], leftEdge[0], leftEdge[1], leftEdge[2],
                         rightEdge[0], rightEdge[1], rightEdge[2]))
 
             need_per = False
@@ -812,11 +804,11 @@
                 y_axis = coords[1]
 
                 for hp in self.projection_fields:
-                    projections.append(self.pf.h.proj(w, hp['field'], 
-                                                      weight_field=hp['weight_field'], 
+                    projections.append(self.pf.h.proj(w, hp['field'],
+                                                      weight_field=hp['weight_field'],
                                                       source=region, center=halo['center'],
                                                       serialize=False))
-                
+
                 # 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]
@@ -834,13 +826,13 @@
 
                     if save_cube:
                         dataFilename = "%s/Halo_%04d_%s_data.h5" % \
-                            (my_output_dir, halo['id'], axis_labels[w])
+                            (self.projection_output_dir, halo['id'], axis_labels[w])
                         mylog.info("Saving projection data to %s." % dataFilename)
                         output = h5py.File(dataFilename, "a")
 
                     # Create fixed resolution buffer for each projection and write them out.
                     for e, hp in enumerate(self.projection_fields):
-                        frb = FixedResolutionBuffer(projections[e], (proj_left[0], proj_right[0], 
+                        frb = FixedResolutionBuffer(projections[e], (proj_left[0], proj_right[0],
                                                                      proj_left[1], proj_right[1]),
                                                     (projectionResolution, projectionResolution),
                                                     antialias=False)
@@ -849,8 +841,9 @@
                             if dataset_name in output: del output[dataset_name]
                             output.create_dataset(dataset_name, data=frb[hp['field']])
                         if save_images:
-                            filename = "%s/Halo_%04d_%s_%s.png" % (my_output_dir, halo['id'], 
-                                                                   dataset_name, axis_labels[w])
+                            filename = "%s/Halo_%04d_%s_%s.png" % \
+                              (self.projection_output_dir, halo['id'],
+                               dataset_name, axis_labels[w])
                             if (frb[hp['field']] != 0).any():
                                 write_image(na.log10(frb[hp['field']]), filename, cmap_name=hp['cmap'])
                             else:
@@ -864,15 +857,15 @@
     def analyze_halo_spheres(self, analysis_function, halo_list='filtered',
                              analysis_output_dir=None, njobs=-1, dynamic=False):
         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 
+
+        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 
+            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):
@@ -883,7 +876,7 @@
             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 
+            If specified, this directory will be created within the dataset to
             contain any output from the analysis function.  Default: None.
         njobs : int
             The number of jobs over which to split the analysis.  Set
@@ -898,7 +891,7 @@
         --------
         >>> hp.analyze_halo_spheres(my_analysis, halo_list="filtered",
                                     analysis_output_dir='special_analysis')
-        
+
         """
 
         # Get list of halos for projecting.
@@ -920,12 +913,7 @@
 
         # 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)
+            my_output_dir = os.path.join(self.output_dir, analysis_output_dir)
             self.__check_directory(my_output_dir)
 
         for halo in parallel_objects(halo_analysis_list, njobs=njobs, dynamic=dynamic):
@@ -972,11 +960,7 @@
         if filename is None:
             filename = self.halo_list_file
 
-        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)
+        hop_file = os.path.join(self.output_dir, filename)
 
         if not(os.path.exists(hop_file)):
             mylog.info("Halo finder file not found, running halo finder to get halos.")
@@ -1136,7 +1120,7 @@
     def _run_hop(self, hop_file):
         "Run hop to get halos."
 
-        hop_results = self.halo_finder_function(self.pf, *self.halo_finder_args, 
+        hop_results = self.halo_finder_function(self.pf, *self.halo_finder_args,
                                                 **self.halo_finder_kwargs)
         hop_results.write_out(hop_file)
 
@@ -1146,7 +1130,7 @@
     @parallel_root_only
     def _write_filtered_halo_list(self, filename, format="%s"):
         """
-        Write out list of filtered halos along with any quantities 
+        Write out list of filtered halos along with any quantities
         picked up during the filtering process.
         """
 
@@ -1157,7 +1141,7 @@
 
     def _write_filtered_halo_list_ascii(self, filename, format="%s"):
         """
-        Write out list of filtered halos along with any quantities 
+        Write out list of filtered halos along with any quantities
         picked up during the filtering process.
         """
 
@@ -1165,7 +1149,6 @@
             mylog.error("No halos in filtered list.")
             return
 
-        filename = "%s/%s" % (self.pf.fullpath, filename)
         mylog.info("Writing filtered halo list to %s." % filename)
         out_file = open(filename, "w")
         fields = [field for field in sorted(self.filtered_halos[0])]
@@ -1178,7 +1161,7 @@
         header_fields = []
         for halo_field in halo_fields:
             if isinstance(self.filtered_halos[0][halo_field], types.ListType):
-                header_fields.extend(["%s[%d]" % (halo_field, q) 
+                header_fields.extend(["%s[%d]" % (halo_field, q)
                                       for q in range(len(self.filtered_halos[0][halo_field]))])
             else:
                 header_fields.append(halo_field)
@@ -1203,7 +1186,7 @@
 
     def _write_filtered_halo_list_h5(self, filename):
         """
-        Write out list of filtered halos along with any quantities 
+        Write out list of filtered halos along with any quantities
         picked up during the filtering process.
         """
 
@@ -1211,7 +1194,6 @@
             mylog.error("No halos in filtered list.")
             return
 
-        filename = "%s/%s" % (self.pf.fullpath, filename)
         mylog.info("Writing filtered halo list to %s." % filename)
         out_file = h5py.File(filename, "w")
         fields = [field for field in sorted(self.filtered_halos[0])]
@@ -1318,18 +1300,18 @@
         add2_y_weight_field = plot['weight_field'][plot['py'] - 0.5 * plot['pdy'] < 0]
 
         # Add the hanging cells back to the projection data.
-        plot.field_data['px'] = na.concatenate([plot['px'], add_x_px, add_y_px, 
+        plot.field_data['px'] = na.concatenate([plot['px'], add_x_px, add_y_px,
                                                 add2_x_px, add2_y_px])
-        plot.field_data['py'] = na.concatenate([plot['py'], add_x_py, add_y_py, 
+        plot.field_data['py'] = na.concatenate([plot['py'], add_x_py, add_y_py,
                                                 add2_x_py, add2_y_py])
-        plot.field_data['pdx'] = na.concatenate([plot['pdx'], add_x_pdx, add_y_pdx, 
+        plot.field_data['pdx'] = na.concatenate([plot['pdx'], add_x_pdx, add_y_pdx,
                                                  add2_x_pdx, add2_y_pdx])
-        plot.field_data['pdy'] = na.concatenate([plot['pdy'], add_x_pdy, add_y_pdy, 
+        plot.field_data['pdy'] = na.concatenate([plot['pdy'], add_x_pdy, add_y_pdy,
                                                  add2_x_pdy, add2_y_pdy])
-        plot.field_data[field] = na.concatenate([plot[field], add_x_field, add_y_field, 
+        plot.field_data[field] = na.concatenate([plot[field], add_x_field, add_y_field,
                                                  add2_x_field, add2_y_field])
         plot.field_data['weight_field'] = na.concatenate([plot['weight_field'],
-                                                          add_x_weight_field, add_y_weight_field, 
+                                                          add_x_weight_field, add_y_weight_field,
                                                           add2_x_weight_field, add2_y_weight_field])
 
         # Delete original copies of hanging cells.
@@ -1376,7 +1358,7 @@
     ("OverDensity", "CellMassMsun", False),
     #("ParticleMassMsun", None),
     ("StarParticleDensity", "StarParticleMassMsun", False), # How do we weight this?
-    #("StarParticleMassMsun", None), 
+    #("StarParticleMassMsun", None),
     ("StarParticleDensity", "StarParticleMassMsun", False), # How do we weight this?
 ]
 
@@ -1384,4 +1366,3 @@
     for s in ["HI","HII","HeI","HeII","HeIII","H2I","H2II",
     "HM","Electron", "DI","DII","HDI","Metal"]
 ]
-



https://bitbucket.org/yt_analysis/yt/changeset/e985e481d8c1/
changeset:   e985e481d8c1
branch:      yt
user:        brittonsmith
date:        2012-07-25 19:53:06
summary:     Adding option to only output a final image of a light cone projection.
affected #:  1 file

diff -r 54191f79dd8c9fb2aa40b75c1e17bd83816cbaf8 -r e985e481d8c1f90d49f35515e695ffc701989de6 yt/analysis_modules/cosmological_observation/light_cone/light_cone.py
--- a/yt/analysis_modules/cosmological_observation/light_cone/light_cone.py
+++ b/yt/analysis_modules/cosmological_observation/light_cone/light_cone.py
@@ -344,7 +344,8 @@
             del halo_mask_cube
 
     def project_light_cone(self, field, weight_field=None, apply_halo_mask=False,
-                           node=None, save_stack=True, save_slice_images=False,
+                           node=None, save_stack=True, save_final_image=True,
+                           save_slice_images=False,
                            cmap_name='algae', photon_field=False,
                            njobs=1, dynamic=False):
         r"""Create projections for light cone, then add them together.
@@ -369,6 +370,9 @@
             if True, the light cone data including each individual
             slice is written to an hdf5 file.
             Default: True.
+        save_final_image : book
+            if True, save an image of the final light cone projection.
+            Default: True.
         save_slice_images : bool
             save images for each individual projection slice.
             Default: False.
@@ -481,7 +485,7 @@
 
 
         # Write image.
-        if save_slice_images:
+        if save_final_image:
             only_on_root(write_image, na.log10(light_cone_projection),
                          "%s_%s.png" % (filename, field), cmap_name=cmap_name)
 



https://bitbucket.org/yt_analysis/yt/changeset/a9604d4dca3f/
changeset:   a9604d4dca3f
branch:      yt
user:        MatthewTurk
date:        2012-07-25 20:32:27
summary:     Merged in brittonsmith/yt (pull request #217)
affected #:  2 files

diff -r e62a6e4015c51793c8b7b0e6e678d65553b24332 -r a9604d4dca3f054a67ea25479323748a6ff33c7d yt/analysis_modules/cosmological_observation/light_cone/light_cone.py
--- a/yt/analysis_modules/cosmological_observation/light_cone/light_cone.py
+++ b/yt/analysis_modules/cosmological_observation/light_cone/light_cone.py
@@ -344,7 +344,8 @@
             del halo_mask_cube
 
     def project_light_cone(self, field, weight_field=None, apply_halo_mask=False,
-                           node=None, save_stack=True, save_slice_images=False,
+                           node=None, save_stack=True, save_final_image=True,
+                           save_slice_images=False,
                            cmap_name='algae', photon_field=False,
                            njobs=1, dynamic=False):
         r"""Create projections for light cone, then add them together.
@@ -369,6 +370,9 @@
             if True, the light cone data including each individual
             slice is written to an hdf5 file.
             Default: True.
+        save_final_image : book
+            if True, save an image of the final light cone projection.
+            Default: True.
         save_slice_images : bool
             save images for each individual projection slice.
             Default: False.
@@ -481,7 +485,7 @@
 
 
         # Write image.
-        if save_slice_images:
+        if save_final_image:
             only_on_root(write_image, na.log10(light_cone_projection),
                          "%s_%s.png" % (filename, field), cmap_name=cmap_name)
 


diff -r e62a6e4015c51793c8b7b0e6e678d65553b24332 -r a9604d4dca3f054a67ea25479323748a6ff33c7d 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
@@ -61,68 +61,68 @@
 class HaloProfiler(ParallelAnalysisInterface):
     "Radial profiling, filtering, and projections for halos in cosmological simulations."
     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, 
+                 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),
                  halo_radius=None, 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', 'r_max'], 
+                 velocity_center=['bulk', 'halo'], filter_quantities=['id', 'center', 'r_max'],
                  use_critical_density=False):
         r"""Initialize a Halo Profiler object.
-        
+
         In order to run the halo profiler, the Halo Profiler object must be
         instantiated. At the minimum, the path to a parameter file
         must be provided as the first term.
-        
+
         Parameters
         ----------
-        
+
         dataset : string, required
             The path to the parameter file for the dataset to be analyzed.
         output_dir : string, optional
-            If specified, all output will be put into this path instead of 
+            If specified, all output will be put into this path instead of
             in the dataset directories.  Default: None.
         halos :  {"multiple", "single"}, optional
-            For profiling more than one halo.  In this mode halos are read in 
+            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 
+            the one and only halo
             center is identified automatically as the location of the peak
-            in the density field.  
+            in the density field.
             Default: "multiple".
         halo_list_file : string, optional
             The name of a file containing the list of halos.  The HaloProfiler
             will  look for this file in the data directory.
             Default: "HopAnalysis.out".
         halo_list_format : {string, dict}
-            The format of the halo list file.  "yt_hop" for the format 
+            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. "p-groupfinder"  for P-Groupfinder.  This keyword 
+            by enzo_hop. "p-groupfinder"  for P-Groupfinder.  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".
         halo_finder_function : function
-            If halos is set to multiple and the file given by 
+            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.  
+            specified here will be called.
             Default: HaloFinder (yt_hop).
         halo_finder_args : tuple
             Args given with call to halo finder function.  Default: None.
         halo_finder_kwargs : dict
             kwargs given with call to halo finder function. Default: None.
         recenter : {string, 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 
+            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 
+            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
@@ -145,31 +145,31 @@
         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 
+            profiles will be made.  This keyword is also
             used when halos is set to single.  Default: 0.1.
         radius_units : string
             The units of halo_radius.  Default: "1" (code units).
         n_profile_bins : int
             The number of bins in the radial profiles.  Default: 50.
         profile_output_dir : str
-            The subdirectory, inside the data directory, in which radial profile 
+            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.  
+            The directory will be created if it does not exist.
             Default: "radial_profiles".
         projection_output_dir : str
-            The subdirectory, inside the data directory, in which projection 
+            The subdirectory, inside the data directory, in which projection
             output files will be created.
-            The directory will be created if it does not exist.  
+            The directory will be created if it does not exist.
             Default: "projections".
         projection_width : float
             The width of halo projections.  Default: 8.0.
         projection_width_units : string
             The units of projection_width. Default: "mpc".
         project_at_level : {"max", int}
-            The maximum refinement level to be included in projections.  
+            The maximum refinement level to be included in projections.
             Default: "max" (maximum level within the dataset).
         velocity_center  : array_like
-            The method in which the halo bulk velocity is calculated (used for 
+            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
@@ -178,26 +178,23 @@
     	        * ["max", field]: the velocity of the cell that is the
     	          location of the maximum of the field specified.
         filter_quantities : array_like
-            Quantities from the original halo list file to be written out in the 
+            Quantities from the original halo list file to be written out in the
             filtered list file.  Default: ['id','center'].
         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.
-        
+
         Examples
         --------
         >>> from yt.analysis_modules.halo_profiler.api import *
         >>> hp = HaloProfiler("RedshiftOutput0005/RD0005")
-        
+
         """
         ParallelAnalysisInterface.__init__(self)
 
         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
         self.projection_width = projection_width
         self.projection_width_units = projection_width_units
@@ -213,10 +210,6 @@
         self.all_halos = []
         self.filtered_halos = []
 
-        # 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
@@ -238,7 +231,7 @@
         # 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, 'np': 2, 
+            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]}
@@ -255,8 +248,8 @@
 
         # Flag for whether calculating halo bulk velocity is necessary.
         self._need_bulk_velocity = False
-        
-        # Check validity for VelocityCenter parameter which toggles how the 
+
+        # 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':
@@ -268,7 +261,7 @@
                     self.halo_list_format is 'enzo_hop':
                 mylog.error("Parameter, VelocityCenter, must be 'bulk sphere' for old style hop output files.")
                 return None
-            if not(self.velocity_center[1] == 'halo' or 
+            if not(self.velocity_center[1] == 'halo' or
                    self.velocity_center[1] == 'sphere'):
                 mylog.error("Second value of VelocityCenter must be either 'halo' or 'sphere' if first value is 'bulk'.")
                 return None
@@ -285,6 +278,17 @@
             self.pf = load(self.dataset)
         self.pf.h
 
+        # Create output directories.
+        self.output_dir = output_dir
+        if output_dir is None:
+            output_dir = '.'
+        else:
+            self.__check_directory(output_dir)
+        self.output_dir = os.path.join(output_dir, os.path.basename(self.pf.fullpath))
+        self.__check_directory(self.output_dir)
+        self.profile_output_dir = os.path.join(self.output_dir, profile_output_dir)
+        self.projection_output_dir = os.path.join(self.output_dir, projection_output_dir)
+
         # Figure out what max radius to use for profiling.
         if halo_radius is not None:
             self.halo_radius = halo_radius / self.pf[radius_units]
@@ -315,7 +319,7 @@
         r"""Filters can be added to create a refined list of halos based on
         their profiles or to avoid profiling halos altogether based on
         information given in the halo list file.
-        
+
         It is often the case that one is looking to identify halos with a
         specific set of properties. This can be accomplished through the
         creation of filter functions. A filter function can take as many args
@@ -323,11 +327,11 @@
         object, or at least a dictionary which contains the profile arrays
         for each field. Filter functions must return a list of two things.
         The first is a True or False indicating whether the halo passed the
-        filter. The second is a dictionary containing quantities calculated 
+        filter. The second is a dictionary containing quantities calculated
         for that halo that will be written to a file if the halo passes the
         filter. A sample filter function based on virial quantities can be
         found in yt/analysis_modules/halo_profiler/halo_filters.py.
-        
+
         Parameters
         ----------
         function : function
@@ -336,7 +340,7 @@
             Arguments passed to the halo filter function.
         kwargs : values
             Arguments passed to the halo filter function.
-        
+
         Examples
         -------
         >>> hp.add_halo_filter(HP.VirialFilter, must_be_virialized=True,
@@ -344,18 +348,18 @@
                 virial_overdensity=200,
                 virial_filters=[['TotalMassMsun','>=','1e14']],
                 virial_quantities=['TotalMassMsun','RadiusMpc'])
-        
+
         """
 
         self._halo_filters.append({'function':function, 'args':args, 'kwargs':kwargs})
 
     def add_profile(self, field, weight_field=None, accumulation=False):
         r"""Add a field for profiling.
-        
+
         Once the halo profiler object has been instantiated,
         fields can be added for profiling using this function. This function
         may be called multiple times, once per field to be added.
-        
+
         Parameters
         ----------
         field : string
@@ -366,28 +370,28 @@
         accumulation : bool
             Whether or not the `field` values should be summed up with the
             radius of the profile.
-        
+
         Examples
         >>> hp.add_profile('CellVolume', weight_field=None, accumulation=True)
         >>> hp.add_profile('TotalMassMsun', weight_field=None, accumulation=True)
         >>> hp.add_profile('Density', weight_field=None, accumulation=False)
         >>> hp.add_profile('Temperature', weight_field='CellMassMsun', accumulation=False)
-            
+
         """
 
         # Check for any field that might need to have the bulk velocity set.
         if 'Velocity' in field or 'Mach' in field:
             self._need_bulk_velocity = True
 
-        self.profile_fields.append({'field':field, 'weight_field':weight_field, 
+        self.profile_fields.append({'field':field, 'weight_field':weight_field,
                                     'accumulation':accumulation})
 
     def add_projection(self, field, weight_field=None, cmap='algae'):
         r"""Make a projection of the specified field.
-        
+
         For the given field, a projection will be produced that can be saved
         to HDF5 or image format. See `make_projections`.
-        
+
         Parameters
         ----------
         field : string
@@ -398,7 +402,7 @@
         cmap : string
             The name of the matplotlib color map that will be used if an
             image is made from the projection. Default="algae".
-        
+
         Examples
         --------
         >>> hp.add_projection('Density', weight_field=None)
@@ -411,17 +415,17 @@
         if 'Velocity' in field or 'Mach' in field:
             self._need_bulk_velocity = True
 
-        self.projection_fields.append({'field':field, 'weight_field':weight_field, 
+        self.projection_fields.append({'field':field, 'weight_field':weight_field,
                                        'cmap': cmap})
 
     @parallel_blocking_call
     def make_profiles(self, filename=None, prefilters=None, njobs=-1,
                       dynamic=False, profile_format='ascii'):
         r"""Make radial profiles for all halos in the list.
-        
+
         After all the calls to `add_profile`, this will trigger the actual
         calculations and output the profiles to disk.
-        
+
         Paramters
         ---------
         filename : str
@@ -447,12 +451,12 @@
         profile_format : str
             The file format for the radial profiles, 'ascii' or 'hdf5'.
             Default: 'ascii'.
-        
+
         Examples
         --------
         >>> hp.make_profiles(filename="FilteredQuantities.out",
                  prefilters=["halo['mass'] > 1e13"])
-        
+
         """
 
         extension_map = {'ascii': 'dat',
@@ -496,13 +500,7 @@
         if virial_filter: self._check_for_needed_profile_fields()
 
         # 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)
+        self.__check_directory(self.profile_output_dir)
 
         # Profile all halos.
         updated_halos = []
@@ -519,7 +517,7 @@
             if filter_result and len(self.profile_fields) > 0:
 
                 profile_filename = "%s/Halo_%04d_profile.%s" % \
-                    (my_output_dir, halo['id'], extension_map[profile_format])
+                    (self.profile_output_dir, halo['id'], extension_map[profile_format])
 
                 profiledHalo = self._get_halo_profile(halo, profile_filename,
                                                       virial_filter=virial_filter)
@@ -529,7 +527,7 @@
 
                 # Apply filter and keep track of the quantities that are returned.
                 for hFilter in self._halo_filters:
-                    filter_result, filterQuantities = hFilter['function'](profiledHalo, *hFilter['args'], 
+                    filter_result, filterQuantities = hFilter['function'](profiledHalo, *hFilter['args'],
                                                                           **hFilter['kwargs'])
 
                     if not filter_result: break
@@ -560,7 +558,7 @@
         self.filtered_halos.sort(key=lambda a:a['id'])
 
         if filename is not None:
-            self._write_filtered_halo_list(filename)
+            self._write_filtered_halo_list(os.path.join(self.output_dir, filename))
 
     def _get_halo_profile(self, halo, filename, virial_filter=True,
             force_write=False):
@@ -656,7 +654,7 @@
             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. 
+            # Expand the halo to account for recentering.
             halo['r_max'] += d / 1000. # d is in kpc -> want mpc
             new_sphere = True
 
@@ -675,8 +673,8 @@
                     sphere.set_field_parameter('bulk_velocity', halo['velocity'])
                 elif self.velocity_center[1] == 'sphere':
                     mylog.info('Calculating sphere bulk velocity.')
-                    sphere.set_field_parameter('bulk_velocity', 
-                                               sphere.quantities['BulkVelocity'](lazy_reader=True, 
+                    sphere.set_field_parameter('bulk_velocity',
+                                               sphere.quantities['BulkVelocity'](lazy_reader=True,
                                                                                  preload=False))
                 else:
                     mylog.error("Invalid parameter: velocity_center.")
@@ -699,10 +697,10 @@
                          save_images=False, save_cube=True, njobs=-1,
                          dynamic=False):
         r"""Make projections of all halos using specified fields.
-        
+
         After adding fields using `add_projection`, this starts the actual
         calculations and saves the output to disk.
-        
+
         Parameters
         ---------
         axes = array_like
@@ -725,12 +723,12 @@
             If True, distribute halos using a task queue.  If False,
             distribute halos evenly over all jobs.
             Default: False.
-        
+
         Examples
         --------
         >>> hp.make_projections(axes=[0, 1, 2], save_cube=True,
             save_images=True, halo_list="filtered")
-        
+
         """
 
         # Get list of halos for projecting.
@@ -761,15 +759,9 @@
         projectionResolution = int(self.projection_width / proj_dx)
 
         # 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)
+        self.__check_directory(self.projection_output_dir)
 
-        center = [0.5 * (self.pf.parameters['DomainLeftEdge'][w] + 
+        center = [0.5 * (self.pf.parameters['DomainLeftEdge'][w] +
                          self.pf.parameters['DomainRightEdge'][w])
                   for w in range(self.pf.parameters['TopGridRank'])]
 
@@ -778,15 +770,15 @@
                 continue
             # Check if region will overlap domain edge.
             # Using non-periodic regions is faster than using periodic ones.
-            leftEdge = [(halo['center'][w] - 
+            leftEdge = [(halo['center'][w] -
                          0.5 * self.projection_width/self.pf.units[self.projection_width_units])
                         for w in range(len(halo['center']))]
-            rightEdge = [(halo['center'][w] + 
+            rightEdge = [(halo['center'][w] +
                           0.5 * self.projection_width/self.pf.units[self.projection_width_units])
                          for w in range(len(halo['center']))]
 
             mylog.info("Projecting halo %04d in region: [%f, %f, %f] to [%f, %f, %f]." %
-                       (halo['id'], leftEdge[0], leftEdge[1], leftEdge[2], 
+                       (halo['id'], leftEdge[0], leftEdge[1], leftEdge[2],
                         rightEdge[0], rightEdge[1], rightEdge[2]))
 
             need_per = False
@@ -812,11 +804,11 @@
                 y_axis = coords[1]
 
                 for hp in self.projection_fields:
-                    projections.append(self.pf.h.proj(w, hp['field'], 
-                                                      weight_field=hp['weight_field'], 
+                    projections.append(self.pf.h.proj(w, hp['field'],
+                                                      weight_field=hp['weight_field'],
                                                       source=region, center=halo['center'],
                                                       serialize=False))
-                
+
                 # 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]
@@ -834,13 +826,13 @@
 
                     if save_cube:
                         dataFilename = "%s/Halo_%04d_%s_data.h5" % \
-                            (my_output_dir, halo['id'], axis_labels[w])
+                            (self.projection_output_dir, halo['id'], axis_labels[w])
                         mylog.info("Saving projection data to %s." % dataFilename)
                         output = h5py.File(dataFilename, "a")
 
                     # Create fixed resolution buffer for each projection and write them out.
                     for e, hp in enumerate(self.projection_fields):
-                        frb = FixedResolutionBuffer(projections[e], (proj_left[0], proj_right[0], 
+                        frb = FixedResolutionBuffer(projections[e], (proj_left[0], proj_right[0],
                                                                      proj_left[1], proj_right[1]),
                                                     (projectionResolution, projectionResolution),
                                                     antialias=False)
@@ -849,8 +841,9 @@
                             if dataset_name in output: del output[dataset_name]
                             output.create_dataset(dataset_name, data=frb[hp['field']])
                         if save_images:
-                            filename = "%s/Halo_%04d_%s_%s.png" % (my_output_dir, halo['id'], 
-                                                                   dataset_name, axis_labels[w])
+                            filename = "%s/Halo_%04d_%s_%s.png" % \
+                              (self.projection_output_dir, halo['id'],
+                               dataset_name, axis_labels[w])
                             if (frb[hp['field']] != 0).any():
                                 write_image(na.log10(frb[hp['field']]), filename, cmap_name=hp['cmap'])
                             else:
@@ -864,15 +857,15 @@
     def analyze_halo_spheres(self, analysis_function, halo_list='filtered',
                              analysis_output_dir=None, njobs=-1, dynamic=False):
         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 
+
+        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 
+            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):
@@ -883,7 +876,7 @@
             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 
+            If specified, this directory will be created within the dataset to
             contain any output from the analysis function.  Default: None.
         njobs : int
             The number of jobs over which to split the analysis.  Set
@@ -898,7 +891,7 @@
         --------
         >>> hp.analyze_halo_spheres(my_analysis, halo_list="filtered",
                                     analysis_output_dir='special_analysis')
-        
+
         """
 
         # Get list of halos for projecting.
@@ -920,12 +913,7 @@
 
         # 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)
+            my_output_dir = os.path.join(self.output_dir, analysis_output_dir)
             self.__check_directory(my_output_dir)
 
         for halo in parallel_objects(halo_analysis_list, njobs=njobs, dynamic=dynamic):
@@ -972,11 +960,7 @@
         if filename is None:
             filename = self.halo_list_file
 
-        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)
+        hop_file = os.path.join(self.output_dir, filename)
 
         if not(os.path.exists(hop_file)):
             mylog.info("Halo finder file not found, running halo finder to get halos.")
@@ -1136,7 +1120,7 @@
     def _run_hop(self, hop_file):
         "Run hop to get halos."
 
-        hop_results = self.halo_finder_function(self.pf, *self.halo_finder_args, 
+        hop_results = self.halo_finder_function(self.pf, *self.halo_finder_args,
                                                 **self.halo_finder_kwargs)
         hop_results.write_out(hop_file)
 
@@ -1146,7 +1130,7 @@
     @parallel_root_only
     def _write_filtered_halo_list(self, filename, format="%s"):
         """
-        Write out list of filtered halos along with any quantities 
+        Write out list of filtered halos along with any quantities
         picked up during the filtering process.
         """
 
@@ -1157,7 +1141,7 @@
 
     def _write_filtered_halo_list_ascii(self, filename, format="%s"):
         """
-        Write out list of filtered halos along with any quantities 
+        Write out list of filtered halos along with any quantities
         picked up during the filtering process.
         """
 
@@ -1165,7 +1149,6 @@
             mylog.error("No halos in filtered list.")
             return
 
-        filename = "%s/%s" % (self.pf.fullpath, filename)
         mylog.info("Writing filtered halo list to %s." % filename)
         out_file = open(filename, "w")
         fields = [field for field in sorted(self.filtered_halos[0])]
@@ -1178,7 +1161,7 @@
         header_fields = []
         for halo_field in halo_fields:
             if isinstance(self.filtered_halos[0][halo_field], types.ListType):
-                header_fields.extend(["%s[%d]" % (halo_field, q) 
+                header_fields.extend(["%s[%d]" % (halo_field, q)
                                       for q in range(len(self.filtered_halos[0][halo_field]))])
             else:
                 header_fields.append(halo_field)
@@ -1203,7 +1186,7 @@
 
     def _write_filtered_halo_list_h5(self, filename):
         """
-        Write out list of filtered halos along with any quantities 
+        Write out list of filtered halos along with any quantities
         picked up during the filtering process.
         """
 
@@ -1211,7 +1194,6 @@
             mylog.error("No halos in filtered list.")
             return
 
-        filename = "%s/%s" % (self.pf.fullpath, filename)
         mylog.info("Writing filtered halo list to %s." % filename)
         out_file = h5py.File(filename, "w")
         fields = [field for field in sorted(self.filtered_halos[0])]
@@ -1318,18 +1300,18 @@
         add2_y_weight_field = plot['weight_field'][plot['py'] - 0.5 * plot['pdy'] < 0]
 
         # Add the hanging cells back to the projection data.
-        plot.field_data['px'] = na.concatenate([plot['px'], add_x_px, add_y_px, 
+        plot.field_data['px'] = na.concatenate([plot['px'], add_x_px, add_y_px,
                                                 add2_x_px, add2_y_px])
-        plot.field_data['py'] = na.concatenate([plot['py'], add_x_py, add_y_py, 
+        plot.field_data['py'] = na.concatenate([plot['py'], add_x_py, add_y_py,
                                                 add2_x_py, add2_y_py])
-        plot.field_data['pdx'] = na.concatenate([plot['pdx'], add_x_pdx, add_y_pdx, 
+        plot.field_data['pdx'] = na.concatenate([plot['pdx'], add_x_pdx, add_y_pdx,
                                                  add2_x_pdx, add2_y_pdx])
-        plot.field_data['pdy'] = na.concatenate([plot['pdy'], add_x_pdy, add_y_pdy, 
+        plot.field_data['pdy'] = na.concatenate([plot['pdy'], add_x_pdy, add_y_pdy,
                                                  add2_x_pdy, add2_y_pdy])
-        plot.field_data[field] = na.concatenate([plot[field], add_x_field, add_y_field, 
+        plot.field_data[field] = na.concatenate([plot[field], add_x_field, add_y_field,
                                                  add2_x_field, add2_y_field])
         plot.field_data['weight_field'] = na.concatenate([plot['weight_field'],
-                                                          add_x_weight_field, add_y_weight_field, 
+                                                          add_x_weight_field, add_y_weight_field,
                                                           add2_x_weight_field, add2_y_weight_field])
 
         # Delete original copies of hanging cells.
@@ -1376,7 +1358,7 @@
     ("OverDensity", "CellMassMsun", False),
     #("ParticleMassMsun", None),
     ("StarParticleDensity", "StarParticleMassMsun", False), # How do we weight this?
-    #("StarParticleMassMsun", None), 
+    #("StarParticleMassMsun", None),
     ("StarParticleDensity", "StarParticleMassMsun", False), # How do we weight this?
 ]
 
@@ -1384,4 +1366,3 @@
     for s in ["HI","HII","HeI","HeII","HeIII","H2I","H2II",
     "HM","Electron", "DI","DII","HDI","Metal"]
 ]
-

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