def test_save(cleanup=True): tables = import_tables() fname = 'foo.hdf5' h = d.histogram.hist1d(numpy.linspace(0, 1, 11)) # save to opened file with tables.open_file(fname, 'w') as hdf: d.histsave(h, hdf, '/', 'foo') # let histsave open the file for you d.histsave(h, fname, '/', 'foo', overwrite=True) if cleanup: os.unlink(fname) else: return fname
def Finish(self): for i in range(len(self.zenbins_fine)): for j in range(len(self.depthbins)): self.multiplicity_slices[i][j].flush() self.multiplicity._h_bincontent[ i + 1, j + 1, :] += self.multiplicity_slices[i][j]._h_bincontent self.multiplicity._h_squaredweights[ i + 1, j + 1, :] += self.multiplicity_slices[i][j]._h_squaredweights for i in range(len(self.zenbins)): for j in range(len(self.depthbins)): self.radius_slices[i][j].flush() self.energy_slices[i][j].flush() self.radius._h_bincontent[ i + 1, j + 1, :, :] += self.radius_slices[i][j]._h_bincontent self.radius._h_squaredweights[ i + 1, j + 1, :, :] += self.radius_slices[i][j]._h_squaredweights self.energy._h_bincontent[ i + 1, j + 1, :, :, :] += self.energy_slices[i][j]._h_bincontent self.energy._h_squaredweights[ i + 1, j + 1, :, :, :] += self.energy_slices[i][j]._h_squaredweights self.primary.flush() with tables.openFile(outfile, 'w') as hdf: dashi.histsave(self.primary, hdf, '/', 'primary') dashi.histsave(self.multiplicity, hdf, '/', 'multiplicity') dashi.histsave(self.radius, hdf, '/', 'radius') dashi.histsave(self.energy, hdf, '/', 'energy')
def Finish(self): # return with tables.openFile(self.outfile, 'a') as hdf: if self.where != '/': hdf.createGroup('/', self.where[1:]) dashi.histsave(self.binner.primary.to_dashi(), hdf, self.where, 'primary') dashi.histsave(self.binner.multiplicity.to_dashi(), hdf, self.where, 'multiplicity') dashi.histsave(self.binner.radius.to_dashi(), hdf, self.where, 'radius') dashi.histsave(self.binner.energy.to_dashi(), hdf, self.where, 'energy')
def save(self, hdf, hist, where): # save in single precision hist._h_bincontent = hist._h_bincontent.astype(numpy.float32) hist._h_squaredweights = hist._h_squaredweights.astype(numpy.float32) dashi.histsave(hist, hdf, self.where, where)