Skip to content

Commit

Permalink
Merge pull request #92 from LSSTDESC/90-fix-hdf5-chunk-write
Browse files Browse the repository at this point in the history
90 fix hdf5 chunk write
  • Loading branch information
joselotl authored May 16, 2022
2 parents 8f6c2c4 + 15839cb commit 79d8d2f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
20 changes: 15 additions & 5 deletions qp/ensemble.py
Original file line number Diff line number Diff line change
Expand Up @@ -599,16 +599,24 @@ def plot_native(self, key=0, **kwargs):
return self._gen_class.plot_native(self[key], **kwargs)

def _get_allocation_kwds(self, npdf):
return self._gen_class.get_allocation_kwds(npdf,
**{**self.metadata(),
**self.objdata()})
tables = self.build_tables()
groups = tables.items()
keywords = {}
for group, tab in tables.items():
if group != 'meta':
keywords[group]={}
for key, array in tab.items():
shape = list(array.shape)
shape[0] = npdf
keywords[group][key] = (shape, array.dtype)
return keywords

def initializeHdf5Write(self, filename, npdf):
"""set up the output write for an ensemble, but set size to npdf rather than
the size of the ensemble, as the "initial chunk" will not contain the full data
"""
kwds = self._get_allocation_kwds(npdf)
group, fout = io.initializeHdf5Write(filename, 'data', **kwds)
group, fout = io.initializeHdf5Write(filename, **kwds)
return group, fout

def writeHdf5Chunk(self, fname, start, end):
Expand All @@ -619,7 +627,9 @@ def writeHdf5Chunk(self, fname, start, end):
start : `int` starting index of h5py file
end : `int` ending index in h5py file
"""
io.writeDictToHdf5Chunk(fname, self.objdata(), start, end)
odict = self.build_tables().copy()
odict.pop('meta')
io.writeDictToHdf5Chunk(fname, odict, start, end)

def finalizeHdf5Write(self, filename):
"""write ensemble metadata to the output file
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@
"numpy",
"scipy>=1.7.0",
"scikit-learn",
"tables_io"],
"tables_io>=0.7.4"],
)

0 comments on commit 79d8d2f

Please sign in to comment.