Skip to content

Commit

Permalink
use _write_rfs_to_file()
Browse files Browse the repository at this point in the history
  • Loading branch information
magland committed Apr 19, 2024
1 parent 0b35dae commit 5b4b6f4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
8 changes: 4 additions & 4 deletions lindi/LindiH5ZarrStore/LindiH5ZarrStore.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
_get_chunk_byte_range,
_get_byte_range_for_contiguous_dataset,
_join,
_get_chunk_names_for_dataset
_get_chunk_names_for_dataset,
_write_rfs_to_file,
)
from ..conversion.attr_conversion import h5_to_zarr_attr
from ..conversion.reformat_json import reformat_json
Expand Down Expand Up @@ -469,9 +470,8 @@ def write_reference_file_system(self, output_file_name: str):
if not output_file_name.endswith(".lindi.json"):
raise Exception("The output file name must end with .lindi.json")

ret = self.to_reference_file_system()
with open(output_file_name, "w") as f:
json.dump(ret, f, indent=2)
rfs = self.to_reference_file_system()
_write_rfs_to_file(rfs=rfs, output_file_name=output_file_name)

def to_reference_file_system(self) -> dict:
"""Create a reference file system corresponding to this store.
Expand Down
8 changes: 8 additions & 0 deletions lindi/LindiH5ZarrStore/_util.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import IO, List
import json
import numpy as np
import h5py

Expand Down Expand Up @@ -83,3 +84,10 @@ def _get_chunk_names_for_dataset(chunk_coords_shape: List[int]) -> List[str]:
for name0 in names0:
names.append(f"{i}.{name0}")
return names


def _write_rfs_to_file(*, rfs: dict, output_file_name: str):
"""Write a reference file system to a file.
"""
with open(output_file_name, "w") as f:
json.dump(rfs, f, indent=2, sort_keys=True)
6 changes: 3 additions & 3 deletions lindi/LindiStagingStore/LindiStagingStore.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from zarr.storage import Store as ZarrStore
from ..LindiH5pyFile.LindiReferenceFileSystemStore import LindiReferenceFileSystemStore
from .StagingArea import StagingArea, _random_str
from ..LindiH5ZarrStore._util import _write_rfs_to_file


# Accepts a string path to a file, uploads (or copies) it somewhere, and returns a string URL
Expand Down Expand Up @@ -138,9 +139,8 @@ def upload(
raise ValueError(f"Could not find url in blob mapping: {url1}")
rfs['refs'][k][0] = url2
with tempfile.TemporaryDirectory() as tmpdir:
rfs_fname = f"{tmpdir}/rfs.json"
with open(rfs_fname, 'w') as f:
json.dump(rfs, f, indent=2, sort_keys=True)
rfs_fname = f"{tmpdir}/rfs.lindi.json"
_write_rfs_to_file(rfs=rfs, output_file_name=rfs_fname)
return on_upload_main(rfs_fname)

def consolidate_chunks(self):
Expand Down

0 comments on commit 5b4b6f4

Please sign in to comment.