def example_time_box(file_name: str): tb = TimeBox(file_name) tb._timebox_version = 1 tb._tag_names_are_strings = True tb._date_differentials_stored = False tb._num_points = 4 tb._tags = { 'tag_0': TimeBoxTag('tag_0', 1, 'u'), 'tag_1': TimeBoxTag('tag_1', 2, 'i'), 'tag_2_long_name': TimeBoxTag('tag_2_long_name', 4, 'f') } tb._start_date = np.datetime64('2018-01-01', 's') tb._seconds_between_points = 3600 tb._tags['tag_0'].data = np.array([1, 2, 3, 4], dtype=np.uint8) tb._tags['tag_1'].data = np.array([-4, -2, 0, 2000], dtype=np.int16) tb._tags['tag_2_long_name'].data = np.array([5.2, 0.8, 3.1415, 8], dtype=np.float32) return tb
def test_read_write_file_info_date_deltas(self): tb = TimeBox('') tb._timebox_version = 1 tb._tag_names_are_strings = False tb._date_differentials_stored = True tb._num_points = 10 tb._tags = example_tag_definitions() tb._start_date = np.datetime64('2018-01-01', 's') tb._bytes_per_date_differential = 4 tb._date_differential_units = SECONDS file_name = 'test_delta.npb' with open(file_name, 'wb') as f: self.assertEqual(230, tb._write_file_info(f)) tb_read = TimeBox('') with open(file_name, 'rb') as f: self.assertEqual(230, tb_read._read_file_info(f)) self.assertEqual(tb._timebox_version, tb_read._timebox_version) self.assertEqual(tb._tag_names_are_strings, tb_read._tag_names_are_strings) self.assertEqual(tb._date_differentials_stored, tb_read._date_differentials_stored) self.assertEqual(tb._num_points, tb_read._num_points) self.assertEqual(tb._start_date, tb_read._start_date) self.assertEqual(tb._bytes_per_date_differential, tb_read._bytes_per_date_differential) self.assertEqual(tb._date_differential_units, tb_read._date_differential_units) for t in tb._tags: self.assertTrue(t in tb_read._tags) self.assertEqual(tb._tags[t].identifier, tb_read._tags[t].identifier) self.assertEqual(tb._tags[t].type_char, tb_read._tags[t].type_char) self.assertEqual(tb._tags[t].dtype, tb_read._tags[t].dtype) self.assertEqual(tb._tags[t].bytes_per_value, tb_read._tags[t].bytes_per_value) os.remove(file_name) return
def example_time_box(file_name: str): tb = TimeBox(file_name) tb._timebox_version = 1 tb._tag_names_are_strings = False tb._date_differentials_stored = True tb._num_points = 4 tb._tags = { 0: TimeBoxTag(0, 1, 'u'), 1: TimeBoxTag(1, 2, 'i'), 2: TimeBoxTag(2, 4, 'f') } tb._start_date = np.datetime64('2018-01-01', 's') tb._tags[0].data = np.array([1, 2, 3, 4], dtype=np.uint8) tb._tags[1].data = np.array([-4, -2, 0, 2000], dtype=np.int16) tb._tags[2].data = np.array([5.2, 0.8, 3.1415, 8], dtype=np.float32) tb._date_differentials = np.array([1, 1, 1], dtype=np.uint8) tb._date_differential_units = DAYS tb._bytes_per_date_differential = 1 return tb