Skip to content
Snippets Groups Projects
Commit fbc4eaca authored by Franck Pérignon's avatar Franck Pérignon
Browse files

Update hdf reader

parent 004423a7
No related branches found
No related tags found
No related merge requests found
......@@ -21,7 +21,7 @@ class Reader(Monitoring):
"""
def __init__(self, variables, topo, prefix,
formattype=None, task_id=None,
subset=None):
subset=None, names=None):
"""
@param variables : list of variables to read.
@param prefix input file name (without ext)
......@@ -65,39 +65,62 @@ class Reader(Monitoring):
self._slices = self.topo.mesh.iCompute
self.globalResolution.reverse()
self.step = self.readHDF5
@debug
@timed_function
def apply(self, simulation=None):
self.step()
def finalize(self):
Monitoring.finalize(self)
def readHDF5(self):
filename = self.prefix + '.h5'
assert os.path.isfile(filename), 'error, file does not exists'
if self.topo.size == 1:
f = h5py.File(filename, "r")
self._file = h5py.File(filename, "r")
else:
f = h5py.File(filename, 'r', driver='mpio', comm=self.topo.comm)
# It's necessary to compute the set of indices of the current subset
# in global notation
self._file = h5py.File(filename, 'r', driver='mpio',
comm=self.topo.comm)
self._globalSlice = []
if self.subset is None:
# Note : g_start and g_end do not include ghost points.
g_start = self.topo.mesh.global_start
g_end = self.topo.mesh.global_end + 1
sl = [slice(g_start[i], g_end[i])
for i in xrange(self.domain.dimension)]
self._globalSlice = [slice(g_start[i], g_end[i])
for i in xrange(self.domain.dimension)]
else:
g_start = self.subset.gstart
# convert self._slices to global position in topo
sl = self.topo.toIndexGlobal(self._slices)
self._globalSlice = self.topo.toIndexGlobal(self._slices)
# And shift using global position of the surface
sl = [slice(sl[i].start - g_start[i], sl[i].stop - g_start[i])
for i in xrange(self.domain.dimension)]
sl.reverse()
sl = tuple(sl)
self._globalSlice = [slice(self._globalSlice[i].start - g_start[i],
self._globalSlice[i].stop - g_start[i])
for i in xrange(self.domain.dimension)]
self._globalSlice.reverse()
self._globalSlice = tuple(self._globalSlice)
if names is None:
self.names = {}
names = self.dataset_names()
i = 0
for field in self.variables:
self.names[field] = []
for d in xrange(field.nbComponents):
self.names[field].append(names[i])
i += 1
else:
self.names = names
for field in self.variables:
fname = self.names[field]
self.names[field] = [v for v in self.dataset_names()
if fname in v]
assert len(self.names[field]) == field.nbComponents
@debug
@timed_function
def apply(self, simulation=None):
self.step()
def dataset_names(self):
"""
Return the list of available names for datasets in
the required file.
"""
return self._file.keys()
def readHDF5(self):
# It's necessary to compute the set of indices of the current subset
# in global notation
for field in self.variables:
df = field.discreteFields[self.topo]
for d in xrange(df.nbComponents):
......@@ -109,10 +132,12 @@ class Reader(Monitoring):
#Note FP : temp method --> use the first name is dataset
# as data for field. Todo : set a list of names
# to be downloaded.
currentName = f.keys()[0]
ds = f[currentName]
currentName = self.names[field][d]
ds = self._file[currentName]
# In parallel, each proc must write in the proper part
# Of the dataset (of site global resolution)
df.data[d][self._slices] = ds[sl].T
f.close()
df.data[d][self._slices] = ds[self._globalSlice].T
def finalize(self):
Monitoring.finalize(self)
self._file.close()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment