34 lines
1.0 KiB
Python
34 lines
1.0 KiB
Python
import tables as tb
|
|
|
|
class Frame:
|
|
def __init__(self, id: str, frame_nr: int, garment: str=''):
|
|
self.id = id
|
|
self.frame_nr = frame_nr
|
|
self.garment = garment
|
|
|
|
def __hash__(self):
|
|
return hash((self.id, self.frame_nr, self.garment))
|
|
|
|
def __eq__(self, other):
|
|
return (self.id, self.frame_nr, self.garment) == (other.id, other.frame_nr, self.garment)
|
|
|
|
|
|
def save_to_h5file(h5file, id, frame_nr, garment, data, name, type):
|
|
filters = tb.Filters(complevel=9, complib='blosc2')
|
|
group = h5file.get_node(f'/{id}/{frame_nr}/{garment}')
|
|
|
|
if type == 'float32':
|
|
atom = tb.Float32Atom()
|
|
elif type == 'uint8':
|
|
atom = tb.UInt8Atom()
|
|
elif type == 'bool':
|
|
atom = tb.BoolAtom()
|
|
else:
|
|
raise Exception('Unknown type')
|
|
|
|
if f'{name}' in group:
|
|
array = h5file.get_node(f'/{id}/{frame_nr}/{garment}/{name}')
|
|
array[:] = data
|
|
else:
|
|
carray = h5file.create_carray(group, name, atom=atom, shape=data.shape, filters=filters)
|
|
carray[:] = data |