Skip to content

Commit

Permalink
Merge pull request #18 from splendor-collab/bug/fix_metadata_size
Browse files Browse the repository at this point in the history
Copy metadata value before getting size of it
  • Loading branch information
slwatkins authored Apr 10, 2024
2 parents edd8980 + 1fb79bf commit 5b4d5fe
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/splendaq/io/_io.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import subprocess
import os
import sys
import copy
from pathlib import Path
from datetime import datetime
import numpy as np
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 5b4d5fe

Please sign in to comment.