[Yt-svn] commit/yt: MatthewTurk: Attempt to consolidate the h5py opening and closing for FLASH datasets into the
Bitbucket
commits-noreply at bitbucket.org
Thu Nov 10 17:45:36 PST 2011
1 new commit in yt:
https://bitbucket.org/yt_analysis/yt/changeset/4de2d4020909/
changeset: 4de2d4020909
branch: yt
user: MatthewTurk
date: 2011-11-11 02:45:06
summary: Attempt to consolidate the h5py opening and closing for FLASH datasets into the
StaticOutput, which then get passed around and only closed in the __del__
method of the parameter file.
affected #: 2 files
diff -r 384f497a891ff5577bec164d99852fa60512a667 -r 4de2d40209098bb7f4f657f9b2412a0103ea0e5e yt/frontends/flash/data_structures.py
--- a/yt/frontends/flash/data_structures.py
+++ b/yt/frontends/flash/data_structures.py
@@ -60,9 +60,8 @@
class FLASHHierarchy(AMRHierarchy):
grid = FLASHGrid
- _handle = None
- def __init__(self,pf,data_style='chombo_hdf5'):
+ def __init__(self,pf,data_style='flash_hdf5'):
self.data_style = data_style
self.field_info = FLASHFieldContainer()
self.field_indexes = {}
@@ -70,14 +69,11 @@
# for now, the hierarchy file is the parameter file!
self.hierarchy_filename = self.parameter_file.parameter_filename
self.directory = os.path.dirname(self.hierarchy_filename)
- self._handle = h5py.File(self.hierarchy_filename)
+ self._handle = pf._handle
self.float_type = na.float64
AMRHierarchy.__init__(self,pf,data_style)
- self._handle.close()
- self._handle = None
-
def _initialize_data_storage(self):
pass
@@ -102,7 +98,7 @@
def _count_grids(self):
try:
self.num_grids = self.parameter_file._find_parameter(
- "integer", "globalnumblocks", True, self._handle)
+ "integer", "globalnumblocks", True)
except KeyError:
self.num_grids = self._handle["/simulation parameters"][0][0]
@@ -114,9 +110,9 @@
self.grid_right_edge[:] = f["/bounding box"][:,:,1]
# Move this to the parameter file
try:
- nxb = pf._find_parameter("integer", "nxb", True, f)
- nyb = pf._find_parameter("integer", "nyb", True, f)
- nzb = pf._find_parameter("integer", "nzb", True, f)
+ nxb = pf._find_parameter("integer", "nxb", True)
+ nyb = pf._find_parameter("integer", "nyb", True)
+ nzb = pf._find_parameter("integer", "nzb", True)
except KeyError:
nxb, nyb, nzb = [int(f["/simulation parameters"]['n%sb' % ax])
for ax in 'xyz']
@@ -194,6 +190,7 @@
storage_filename = None,
conversion_override = None):
+ self._handle = h5py.File(filename, "r")
if conversion_override is None: conversion_override = {}
self._conversion_override = conversion_override
@@ -273,26 +270,17 @@
for unit in mpc_conversion.keys():
self.units[unit] = mpc_conversion[unit] / mpc_conversion["cm"]
- def _find_parameter(self, ptype, pname, scalar = False, handle = None):
- # We're going to implement handle caching eventually
- if handle is None:
- close = False
- handle = self._handle
- if handle is None:
- close = True
- handle = h5py.File(self.parameter_filename, "r")
+ def _find_parameter(self, ptype, pname, scalar = False):
nn = "/%s %s" % (ptype,
{False: "runtime parameters", True: "scalars"}[scalar])
- for tpname, pval in handle[nn][:]:
+ for tpname, pval in self._handle[nn][:]:
if tpname.strip() == pname:
return pval
- if close: handle.close()
raise KeyError(pname)
def _parse_parameter_file(self):
self.unique_identifier = \
int(os.stat(self.parameter_filename)[stat.ST_CTIME])
- self._handle = h5py.File(self.parameter_filename, "r")
if "file format version" in self._handle:
self._flash_version = int(
self._handle["file format version"][:])
@@ -308,15 +296,15 @@
# Determine domain dimensions
try:
- nxb = self._find_parameter("integer", "nxb", scalar = True, handle = self._handle)
- nyb = self._find_parameter("integer", "nyb", scalar = True, handle = self._handle)
- nzb = self._find_parameter("integer", "nzb", scalar = True, handle = self._handle)
+ nxb = self._find_parameter("integer", "nxb", scalar = True)
+ nyb = self._find_parameter("integer", "nyb", scalar = True)
+ nzb = self._find_parameter("integer", "nzb", scalar = True)
except KeyError:
nxb, nyb, nzb = [int(self._handle["/simulation parameters"]['n%sb' % ax])
for ax in 'xyz']
- nblockx = self._find_parameter("integer", "nblockx", handle = self._handle)
- nblocky = self._find_parameter("integer", "nblockx", handle = self._handle)
- nblockz = self._find_parameter("integer", "nblockx", handle = self._handle)
+ nblockx = self._find_parameter("integer", "nblockx")
+ nblocky = self._find_parameter("integer", "nblockx")
+ nblockz = self._find_parameter("integer", "nblockx")
self.domain_dimensions = \
na.array([nblockx*nxb,nblocky*nyb,nblockz*nzb])
@@ -342,8 +330,9 @@
else:
self.current_redshift = self.omega_lambda = self.omega_matter = \
self.hubble_constant = self.cosmological_simulation = 0.0
+
+ def __del__(self):
self._handle.close()
- self._handle = None
@classmethod
def _is_valid(self, *args, **kwargs):
diff -r 384f497a891ff5577bec164d99852fa60512a667 -r 4de2d40209098bb7f4f657f9b2412a0103ea0e5e yt/frontends/flash/io.py
--- a/yt/frontends/flash/io.py
+++ b/yt/frontends/flash/io.py
@@ -38,7 +38,7 @@
BaseIOHandler.__init__(self, *args, **kwargs)
# Now we cache the particle fields
self.pf = pf
- self._handle = h5py.File(self.pf.parameter_filename, "r")
+ self._handle = pf._handle
try :
particle_fields = [s[0].strip() for s in
self._handle["/particle names"][:]]
@@ -47,9 +47,6 @@
except KeyError:
self._particle_fields = {}
- def __del__(self):
- self._handle.close()
-
def _read_particles(self, fields_to_read, type, args, grid_list,
count_list, conv_factors):
pass
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