Matthew Turk avatar Matthew Turk committed 213e044 Merge

Merged in xarthisius/yt (pull request #395: [chombo] close all hdf5 file handles once they're no longer necessary)

Comments (0)

Files changed (1)

yt/frontends/chombo/data_structures.py

      pluto2enzoDict, \
      yt2plutoFieldsDict, \
      parameterDict \
-     
+
 from yt.funcs import *
 from yt.data_objects.grid_patch import \
      AMRGridPatch
         """
         Return the integer starting index for each dimension at the current
         level.
-        
+
         """
         if self.start_index != None:
             return self.start_index
 class ChomboHierarchy(AMRHierarchy):
 
     grid = ChomboGrid
-    
+
     def __init__(self,pf,data_style='chombo_hdf5'):
         self.domain_left_edge = pf.domain_left_edge
         self.domain_right_edge = pf.domain_right_edge
                 particle_position_z = float(line.split(' ')[3])
                 coord = [particle_position_x, particle_position_y, particle_position_z]
                 # for each particle, determine which grids contain it
-                # copied from object_finding_mixin.py                                                                                                             
+                # copied from object_finding_mixin.py
                 mask=np.ones(self.num_grids)
                 for i in xrange(len(coord)):
                     np.choose(np.greater(self.grid_left_edge[:,i],coord[i]), (mask,0), mask)
     def _detect_fields(self):
         ncomp = int(self._fhandle['/'].attrs['num_components'])
         self.field_list = [c[1] for c in self._fhandle['/'].attrs.items()[-ncomp:]]
-    
+
     def _setup_classes(self):
         dd = self._get_data_reader_dict()
         AMRHierarchy._setup_classes(self, dd)
         self.num_grids = 0
         for lev in self._levels:
             self.num_grids += self._fhandle[lev]['Processors'].len()
-        
+
     def _parse_hierarchy(self):
         f = self._fhandle # shortcut
-        
+
         # this relies on the first Group in the H5 file being
         # 'Chombo_global'
         levels = f.keys()[1:]
     _hierarchy_class = ChomboHierarchy
     _fieldinfo_fallback = ChomboFieldInfo
     _fieldinfo_known = KnownChomboFields
-    
+
     def __init__(self, filename, data_style='chombo_hdf5',
                  storage_filename = None, ini_filename = None):
         fileh = h5py.File(filename,'r')
         self.fullplotdir = os.path.abspath(filename)
         StaticOutput.__init__(self,filename,data_style)
         self.storage_filename = storage_filename
-        
+        fileh.close()
+
     def _set_units(self):
         """
         Generates the conversion to various physical _units based on the parameter file
             self.dimensionality = 3
             fileh = h5py.File(self.parameter_filename,'r')
             self.refine_by = fileh['/level_0'].attrs['ref_ratio']
+            fileh.close()
 
     def _parse_pluto_file(self, ini_filename):
         """
         lines = open(self.ini_filename).readlines()
         # read the file line by line, storing important parameters
         for lineI, line in enumerate(lines):
-            try: 
+            try:
                 param, sep, vals = map(rstrip,line.partition(' '))
             except ValueError:
                 mylog.error("ValueError: '%s'", line)
         RE = dx0*((np.array(list(fileh['/level_0'].attrs['prob_domain'])))[3:] + 1)
         fileh.close()
         return RE
-                  
+
     def __calc_domain_dimensions(self):
         fileh = h5py.File(self.parameter_filename,'r')
         L_index = ((np.array(list(fileh['/level_0'].attrs['prob_domain'])))[0:3])
         R_index = ((np.array(list(fileh['/level_0'].attrs['prob_domain'])))[3:] + 1)
+        fileh.close()
         return R_index - L_index
- 
+
     @classmethod
     def _is_valid(self, *args, **kwargs):
         try:
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.