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

Bitbucket commits-noreply at bitbucket.org
Mon Jun 18 09:45:26 PDT 2012


5 new commits in yt:


https://bitbucket.org/yt_analysis/yt/changeset/b9f47b7c6b34/
changeset:   b9f47b7c6b34
branch:      yt
user:        brittonsmith
date:        2012-06-15 22:20:34
summary:     Added option to write filtered halo list in hdf5.
affected #:  1 file

diff -r 38a09b2207e912525f7b12dbe68adc7c9a74e193 -r b9f47b7c6b3462a0a1cd74d12463484fc395a3da 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
@@ -1078,13 +1078,24 @@
         picked up during the filtering process.
         """
 
+        if filename.endswith('.h5'):
+            self._write_filtered_halo_list_h5(filename)
+        else:
+            self._write_filtered_halo_list_ascii(filename, format=format)
+
+    def _write_filtered_halo_list_ascii(self, filename, format="%s"):
+        """
+        Write out list of filtered halos along with any quantities 
+        picked up during the filtering process.
+        """
+
         if len(self.filtered_halos) == 0:
             mylog.error("No halos in filtered list.")
             return
 
         filename = "%s/%s" % (self.pf.fullpath, filename)
         mylog.info("Writing filtered halo list to %s." % filename)
-        file = open(filename, "w")
+        out_file = open(filename, "w")
         fields = [field for field in sorted(self.filtered_halos[0])]
         halo_fields = []
         for halo_field in self.filter_quantities:
@@ -1099,24 +1110,52 @@
                                       for q in range(len(self.filtered_halos[0][halo_field]))])
             else:
                 header_fields.append(halo_field)
-        file.write("# ")
-        file.write("\t".join(header_fields + fields + ["\n"]))
+        out_file.write("# ")
+        out_file.write("\t".join(header_fields + fields + ["\n"]))
 
         for halo in self.filtered_halos:
             for halo_field in halo_fields:
                 if isinstance(halo[halo_field], types.ListType):
                     field_data = na.array(halo[halo_field])
-                    field_data.tofile(file, sep="\t", format=format)
+                    field_data.tofile(out_file, sep="\t", format=format)
                 else:
                     if halo_field == 'id':
-                        file.write("%04d" % halo[halo_field])
+                        out_file.write("%04d" % halo[halo_field])
                     else:
-                        file.write("%s" % halo[halo_field])
-                file.write("\t")
+                        out_file.write("%s" % halo[halo_field])
+                out_file.write("\t")
             field_data = na.array([halo[field] for field in fields])
-            field_data.tofile(file, sep="\t", format=format)
-            file.write("\n")
-        file.close()
+            field_data.tofile(out_file, sep="\t", format=format)
+            out_file.write("\n")
+        out_file.close()
+
+    def _write_filtered_halo_list_h5(self, filename):
+        """
+        Write out list of filtered halos along with any quantities 
+        picked up during the filtering process.
+        """
+
+        if len(self.filtered_halos) == 0:
+            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])]
+        halo_fields = []
+        for halo_field in self.filter_quantities:
+            if halo_field in fields:
+                fields.remove(halo_field)
+                halo_fields.append(halo_field)
+
+        for halo_field in halo_fields:
+            value_list = []
+            for halo in self.filtered_halos:
+                value_list.append(halo[halo_field])
+            value_list = na.array(value_list)
+            out_file.create_dataset(halo_field, data=value_list)
+        out_file.close()
 
     def _write_profile(self, profile, filename, format="%0.16e"):
         fid = open(filename, "w")



https://bitbucket.org/yt_analysis/yt/changeset/02a3d7bbc3e2/
changeset:   02a3d7bbc3e2
branch:      yt
user:        brittonsmith
date:        2012-06-16 03:01:39
summary:     Fixed bug in writing filtered halo list in hdf5 where not
all fields were being written.
affected #:  1 file

diff -r b9f47b7c6b3462a0a1cd74d12463484fc395a3da -r 02a3d7bbc3e20cbeb34f5417da5e265409261255 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
@@ -1149,7 +1149,7 @@
                 fields.remove(halo_field)
                 halo_fields.append(halo_field)
 
-        for halo_field in halo_fields:
+        for halo_field in halo_fields + fields:
             value_list = []
             for halo in self.filtered_halos:
                 value_list.append(halo[halo_field])



https://bitbucket.org/yt_analysis/yt/changeset/00e639d4377e/
changeset:   00e639d4377e
branch:      yt
user:        brittonsmith
date:        2012-06-16 15:01:59
summary:     Fixing corner case where the index for calculating virial quantities
was the very last one.  Profiles get made with N+1 bins and the values
put in the very last bin are the same as the second to last bin
(in this configuration of 1D profiles).  This was causing the
virial filter to think the slope was zero.
affected #:  1 file

diff -r 02a3d7bbc3e20cbeb34f5417da5e265409261255 -r 00e639d4377e50dc55deec23638a79f995ef01bc 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
@@ -591,6 +591,9 @@
         if newProfile:
             mylog.info("Writing halo %d" % halo['id'])
             profile.write_out(filename, format='%0.6e')
+            # profile will have N+1 bins so remove the last one
+            for field in profile.keys():
+                profile[field] = profile[field][:-1]
         elif force_write:
             mylog.info("Re-writing halo %d" % halo['id'])
             self._write_profile(profile, filename, format='%0.6e')



https://bitbucket.org/yt_analysis/yt/changeset/1010dd5d6090/
changeset:   1010dd5d6090
branch:      yt
user:        brittonsmith
date:        2012-06-16 16:13:16
summary:     Added support for reading/writing halo profiles in hdf5.
affected #:  1 file

diff -r 00e639d4377e50dc55deec23638a79f995ef01bc -r 1010dd5d60906c384aaeb1ed8995b1505c9e840e 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
@@ -45,6 +45,8 @@
 from yt.data_objects.static_output import \
     StaticOutput
 
+from yt.utilities.exceptions import \
+    YTException
 from yt.utilities.parallel_tools.parallel_analysis_interface import \
     ParallelAnalysisInterface, \
     parallel_blocking_call, \
@@ -413,7 +415,8 @@
                                        'cmap': cmap})
 
     @parallel_blocking_call
-    def make_profiles(self, filename=None, prefilters=None, njobs=-1):
+    def make_profiles(self, filename=None, prefilters=None, njobs=-1,
+                      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
@@ -421,7 +424,7 @@
         
         Paramters
         ---------
-        filename : string
+        filename : str
             If set, a file will be written with all of the filtered halos
             and the quantities returned by the filter functions.
             Default: None.
@@ -437,6 +440,9 @@
             The number of jobs over which to split the profiling.  Set
             to -1 so that each halo is done by a single processor.
             Default: -1.
+        profile_format : str
+            The file format for the radial profiles, 'ascii' or 'hdf5'.
+            Default: 'ascii'.
         
         Examples
         --------
@@ -445,6 +451,13 @@
         
         """
 
+        extension_map = {'ascii': 'dat',
+                         'hdf5': 'h5'}
+        if not profile_format in extension_map:
+            mylog.error("Invalid profile_format: %s.  Valid options are %s." %
+                        (profile_format, ", ".join(extension_map.keys())))
+            raise YTException(pf=self.pf)
+
         if len(self.all_halos) == 0:
             mylog.error("Halo list is empty, returning.")
             return None
@@ -501,7 +514,8 @@
 
             if filter_result and len(self.profile_fields) > 0:
 
-                profile_filename = "%s/Halo_%04d_profile.dat" % (my_output_dir, halo['id'])
+                profile_filename = "%s/Halo_%04d_profile.%s" % \
+                    (my_output_dir, halo['id'], extension_map[profile_format])
 
                 profiledHalo = self._get_halo_profile(halo, profile_filename,
                                                       virial_filter=virial_filter)
@@ -590,7 +604,10 @@
 
         if newProfile:
             mylog.info("Writing halo %d" % halo['id'])
-            profile.write_out(filename, format='%0.6e')
+            if filename.endswith('.h5'):
+                profile.write_out_h5(filename)
+            else:
+                profile.write_out(filename, format='%0.6e')
             # profile will have N+1 bins so remove the last one
             for field in profile.keys():
                 profile[field] = profile[field][:-1]
@@ -1015,6 +1032,14 @@
         if not os.path.exists(profileFile):
             return None
 
+        if profileFile.endswith('.h5'):
+            return self._read_profile_hdf5(profileFile)
+        else:
+            return self._read_profile_ascii(profileFile)
+
+    def _read_profile_ascii(self, profileFile):
+        "Read radial profile from file.  Return None if it doesn't have all the fields requested."
+
         f = open(profileFile, 'r')
         lines = f.readlines()
         f.close()
@@ -1063,6 +1088,34 @@
         else:
             return None
 
+    def _read_profile_hdf5(self, profileFile):
+        "Read radial profile from file.  Return None if it doesn't have all the fields requested."
+
+        profile = {}
+        in_file = h5py.File(profileFile, 'r')
+        if not 'RadiusMpc-1d' in in_file:
+            return None
+        my_group = in_file['RadiusMpc-1d']
+        if not 'x-axis-RadiusMpc' in my_group.attrs:
+            return None
+        profile['RadiusMpc'] = my_group.attrs['x-axis-RadiusMpc']
+        fields = my_group.keys()
+
+        # Check if all fields needed are present.
+        all_profile_fields = [hp['field'] for hp in self.profile_fields]
+        for field in all_profile_fields:
+            if not field in fields:
+                in_file.close()
+                return None
+
+        for field in fields:
+            profile[field] = my_group[field][:]
+        in_file.close()
+
+        profile_obj = FakeProfile(self.pf)
+        profile_obj._data = profile
+        return profile_obj
+
     @parallel_blocking_call
     def _run_hop(self, hop_file):
         "Run hop to get halos."



https://bitbucket.org/yt_analysis/yt/changeset/befec010e528/
changeset:   befec010e528
branch:      yt
user:        brittonsmith
date:        2012-06-16 16:24:03
summary:     Merged.
affected #:  111 files
Diff too large to display.

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