From 1fb79bf17cdaee6a9df30323457a5fde9e28278a Mon Sep 17 00:00:00 2001 From: slwatkins Date: Wed, 10 Apr 2024 10:57:31 -0600 Subject: [PATCH] copy metadata value before getting size of it --- src/splendaq/io/_io.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/splendaq/io/_io.py b/src/splendaq/io/_io.py index f0ff731..811c406 100644 --- a/src/splendaq/io/_io.py +++ b/src/splendaq/io/_io.py @@ -1,6 +1,7 @@ import subprocess import os import sys +import copy from pathlib import Path from datetime import datetime import numpy as np @@ -157,15 +158,24 @@ def write_data(self, data, filename=None, **metadata): """ + current_metadata_size = 0 + if filename is not None: self.filename = filename elif self.filename is None: raise ValueError("No filename specified.") with h5py.File(self.filename, mode='w') as hf: - hf.create_dataset('data', data=data, compression='gzip') + hf.create_dataset( + 'data', + data=data, + compression='gzip', + track_order=True, + ) for key in metadata: - if sys.getsizeof(metadata[key]) < 64000: + size_of_key = sys.getsizeof(copy.deepcopy(metadata[key])) + if current_metadata_size + size_of_key < 64000: + current_metadata_size += size_of_key hf.attrs[key] = metadata[key] else: hf.create_dataset(