Skip to content
This repository was archived by the owner on Apr 20, 2020. It is now read-only.

Stub to test remote fs zarr n5 backend #332

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lazyflow/operators/ioOperators/opInputDataReader.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,12 @@ def _attemptOpenAsH5N5(self, filePath):
)
raise OpInputDataReader.DatasetReadError(msg)
try:
compression_setting = h5N5File[internalPath].compression
if internalPath.startswith("/"):
internalPath = internalPath.replace("/", "", 1)

print(h5N5File, internalPath)
compression_setting = None
#compression_setting = h5N5File[internalPath].compression
except Exception as e:
h5N5File.close()
msg = "Error reading H5/N5 File: {}\n{}".format(externalPath, e)
Expand Down
41 changes: 40 additions & 1 deletion lazyflow/operators/ioOperators/opStreamingH5N5Reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,51 @@
import vigra
import h5py
import z5py
import zarr
import json
import os
import numpy as np
import requests

from lazyflow.graph import Operator, InputSlot, OutputSlot
from lazyflow.utility import Timer
from lazyflow.utility.helpers import get_default_axisordering
from urllib.parse import urljoin

logger = logging.getLogger(__name__)

class RemoteFS:
class RemoteFile:
def __init__(self, url):
self._url = url

def read(self):
resp = requests.get(self._url)
resp.raise_for_status()
return resp.content

def __enter__(self):
return self

def __exit__(self, *args, **kwargs):
pass

def isfile(self, path):
return not path.endswith("/")

def isdir(self, path):
return path.endswith(".n5")

def exists(self, path):
return True

def __init__(self, url):
self._url = url

def open(self, path, *args, **kwargs):
url = urljoin(f"{self._url}/", path)
return self.RemoteFile(url)


class OpStreamingH5N5Reader(Operator):
"""
Expand Down Expand Up @@ -155,6 +190,10 @@ def get_h5_n5_file(filepath, mode="a"):
"""
name, ext = os.path.splitext(filepath)
if ext in OpStreamingH5N5Reader.N5EXTS:
return z5py.N5File(filepath, mode)
fs = RemoteFS("https://web.ilastik.org/data/datasources/eec5b03babebc54b64f6b31c3a87d92e/")
store = zarr.n5.N5Store("hbp-00173_262_902_1342__s26.n5", fs=fs)
f = zarr.group(store=store, overwrite=False)
f.close = lambda: None
return f
elif ext in OpStreamingH5N5Reader.H5EXTS:
return h5py.File(filepath, mode)