[yt-svn] commit/yt: xarthisius: Update gdf_writer, conform to pep8

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Wed Mar 19 07:09:10 PDT 2014


1 new commit in yt:

https://bitbucket.org/yt_analysis/yt/commits/f31a4502dad8/
Changeset:   f31a4502dad8
Branch:      yt-3.0
User:        xarthisius
Date:        2014-03-19 14:49:46
Summary:     Update gdf_writer, conform to pep8
Affected #:  1 file

diff -r f099b2d7fe9448b0e0579c28d0c941dcb2ba04f9 -r f31a4502dad8691791600432252743771a7d5b62 yt/utilities/grid_data_format/writer.py
--- a/yt/utilities/grid_data_format/writer.py
+++ b/yt/utilities/grid_data_format/writer.py
@@ -35,7 +35,7 @@
     """
 
     f = _create_new_gdf(pf, gdf_path, data_author, data_comment,
-                       particle_type_name)
+                        particle_type_name)
 
     # now add the fields one-by-one
     for field_name in pf.field_list:
@@ -44,6 +44,7 @@
     # don't forget to close the file.
     f.close()
 
+
 def save_field(pf, field_name, field_parameters=None):
     """
     Write a single field associated with the parameter file pf to the
@@ -63,25 +64,29 @@
         field_name = field_name[1]
     field_obj = pf._get_field_info(field_name)
     if field_obj.particle_type:
-        print( "Saving particle fields currently not supported." )
+        print("Saving particle fields currently not supported.")
         return
-    
+
     backup_filename = pf.backup_filename
     if os.path.exists(backup_filename):
         # backup file already exists, open it
         f = h5py.File(backup_filename, "r+")
     else:
         # backup file does not exist, create it
-        f = _create_new_gdf(pf, backup_filename, data_author=None, data_comment=None,
-                       particle_type_name="dark_matter")
+        f = _create_new_gdf(pf, backup_filename, data_author=None,
+                            data_comment=None,
+                            particle_type_name="dark_matter")
 
     # now save the field
-    _write_field_to_gdf(pf, f, field_name, particle_type_name="dark_matter", field_parameters=field_parameters)
+    _write_field_to_gdf(pf, f, field_name, particle_type_name="dark_matter",
+                        field_parameters=field_parameters)
 
     # don't forget to close the file.
     f.close()
-        
-def _write_field_to_gdf(pf, fhandle, field_name, particle_type_name, field_parameters=None):
+
+
+def _write_field_to_gdf(pf, fhandle, field_name, particle_type_name,
+                        field_parameters=None):
 
     # add field info to field_types group
     g = fhandle["field_types"]
@@ -94,7 +99,7 @@
     except ValueError:
         print "Error - File already contains field called " + field_name
         sys.exit(1)
-        
+
     # grab the display name and units from the field info container.
     display_name = fi.display_name
     units = fi.get_units()
@@ -114,13 +119,13 @@
     sg.attrs["staggering"] = 0
 
     # now add actual data, grid by grid
-    g = fhandle["data"]     
+    g = fhandle["data"]
     for grid in pf.index.grids:
 
         # set field parameters, if specified
         if field_parameters is not None:
-            for k,v in field_parameters.iteritems():
-                grid.set_field_parameter(k,v)
+            for k, v in field_parameters.iteritems():
+                grid.set_field_parameter(k, v)
 
         grid_group = g["grid_%010i" % (grid.id - grid._id_offset)]
         particles_group = grid_group["particles"]
@@ -133,15 +138,17 @@
         else:  # a field
             grid_group[field_name] = grid[field_name]
 
+
 def _create_new_gdf(pf, gdf_path, data_author=None, data_comment=None,
-                   particle_type_name="dark_matter"):
+                    particle_type_name="dark_matter"):
     # Make sure we have the absolute path to the file first
     gdf_path = os.path.abspath(gdf_path)
 
     # Stupid check -- is the file already there?
     # @todo: make this a specific exception/error.
     if os.path.exists(gdf_path):
-        raise IOError("A file already exists in the location: %s. Please provide a new one or remove that file." % gdf_path)
+        raise IOError("A file already exists in the location: %s. Please \
+                      provide a new one or remove that file." % gdf_path)
 
     ###
     # Create and open the file with h5py
@@ -201,19 +208,19 @@
     ###
     # root datasets -- info about the grids
     ###
-    f["grid_dimensions"] = pf.grid_dimensions
+    f["grid_dimensions"] = pf.index.grid_dimensions
     f["grid_left_index"] = np.array(
-            [g.get_global_startindex() for g in pf.index.grids]
-    ).reshape(pf.grid_dimensions.shape[0], 3)
-    f["grid_level"] = pf.grid_levels
+        [grid.get_global_startindex() for grid in pf.index.grids]
+    ).reshape(pf.index.grid_dimensions.shape[0], 3)
+    f["grid_level"] = pf.index.grid_levels
     # @todo: Fill with proper values
-    f["grid_parent_id"] = -np.ones(pf.grid_dimensions.shape[0])
-    f["grid_particle_count"] = pf.grid_particle_count
+    f["grid_parent_id"] = -np.ones(pf.index.grid_dimensions.shape[0])
+    f["grid_particle_count"] = pf.index.grid_particle_count
 
     ###
     # "data" group -- where we should spend the most time
     ###
-    
+
     g = f.create_group("data")
     for grid in pf.index.grids:
         # add group for this grid
@@ -223,4 +230,3 @@
         pt_group = particles_group.create_group(particle_type_name)
 
     return f
-

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