def setUp(self): self.f = h5py.File(self.filename, driver='core', backing_store=False) self.x = np.array([0, 1, 2]) self.y = np.array([0, 2, 4]) self.x_attrs = {'name': 't', 'unit': 's', 'label': 't [s]', 'label_latex': '$t \\: [\\mathrm{s}]$', 'help': 'time axis', 'initial': 0, 'step': 1} self.y_attrs = {'name': 'x', 'unit': 'nm', 'label': 'x [nm]', 'label_latex': '$x \: [\mathrm{nm}]$', 'help': 'cantilever amplitude', 'abscissa': 'x', 'n_avg': 1} self.f['x'] = self.x self.f['y'] = self.y update_attrs(self.f['x'].attrs, self.x_attrs) update_attrs(self.f['y'].attrs, self.y_attrs) self.s = Signal()
def setUp(self): self.f = h5py.File(self.filename, driver='core', backing_store=False) self.x = np.array([0, 1, 2]) self.y = np.array([0, 2, 4]) self.x_attrs = { 'name': 't', 'unit': 's', 'label': 't [s]', 'label_latex': '$t \\: [\\mathrm{s}]$', 'help': 'time axis', 'initial': 0, 'step': 1 } self.y_attrs = { 'name': 'x', 'unit': 'nm', 'label': 'x [nm]', 'label_latex': '$x \: [\mathrm{nm}]$', 'help': 'cantilever amplitude', 'abscissa': 'x', 'n_avg': 1 } self.f['x'] = self.x self.f['y'] = self.y update_attrs(self.f['x'].attrs, self.x_attrs) update_attrs(self.f['y'].attrs, self.y_attrs) self.s = Signal()
def write_h5file(self): """Write the representative dataset to a file.""" f = h5py.File(self.filename, 'w') update_attrs(f.attrs, self.f_attrs) f['x'] = self.t update_attrs(f['x'].attrs, self.x_attrs) f0 = 0.013/(2*self.dt) self.y = np.sin(2*np.pi*f0*self.t) f['y'] = self.y update_attrs(f['y'].attrs, self.y_attrs) f.close()
def write_h5file(self): """Write the representative dataset to a file.""" f = h5py.File(self.filename, 'w') update_attrs(f.attrs, self.f_attrs) f['x'] = self.t update_attrs(f['x'].attrs, self.x_attrs) f0 = 0.013 / (2 * self.dt) self.y = np.sin(2 * np.pi * f0 * self.t) f['y'] = self.y update_attrs(f['y'].attrs, self.y_attrs) f.close()
def test_empty_write(self): """Writing an empty dictionary should do nothing.""" empty_attrs = {} update_attrs(self.f.attrs, empty_attrs) assert self.f.attrs['to-be-overwritten'] == 'initial'
def test_normal_write(self): """Writing a non-empty dictionary should do something""" attrs = {'one': 1} update_attrs(self.f.attrs, attrs) assert self.f.attrs['one'] == 1
def test_overwrite(self): """The function *should* overwrite existing attributes""" attrs = {'to-be-overwritten': 0} update_attrs(self.f.attrs, attrs) assert self.f.attrs['to-be-overwritten'] == 0