Skip to content

Commit

Permalink
Merge pull request #17 from will-moore/alt_store_bfoptions
Browse files Browse the repository at this point in the history
Alt store bfoptions
  • Loading branch information
joshmoore authored Apr 26, 2024
2 parents c1f00b6 + 98dc2f8 commit d3f95c9
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
10 changes: 7 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,21 @@ To create sql containing required functions and run it:

To generate sql and create the symlinks from the ManagedRepository to the NGFF data for a
specified Fileset ID:
The clientpath is used as the basis for the clientpath for each file in the Fileset. If omitted then
the clientpath is 'unknown'. When writing .zarr.bfoptions into the ManagedRepository alongside the
symlink to fileset.zarr, the clientpath will be added to bfoptions as `omezarr.alt_store`, allowing
ZarrReader to read directly from that source.

::

$ omero mkngff sql --symlink_repo /OMERO/ManagedRepository --secret=secret --bfoptions 1234 /path/to/fileset.zarr > myNgff.sql
$ omero mkngff sql --symlink_repo /OMERO/ManagedRepository --secret=secret --bfoptions --clientpath=https://url/to/fileset.zarr 1234 /path/to/fileset.zarr > myNgff.sql
$ psql -U omero -d idr -h $DBHOST -f myNgff.sql

To ONLY perform the symlink creation (and optionally create fileset.zarr.bfoptions)
To ONLY perform the symlink creation (and optionally create fileset.zarr.bfoptions with clientpath as above)

::

$ omero mkngff symlink /OMERO/ManagedRepository 1234 /path/to/fileset.zarr --bfoptions
$ omero mkngff symlink /OMERO/ManagedRepository 1234 /path/to/fileset.zarr --bfoptions --clientpath=https://url/to/fileset.zarr


To ONLY create fileset.zarr.bfoptions
Expand Down
24 changes: 18 additions & 6 deletions src/omero_mkngff/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,10 @@ def _configure(self, parser: Parser) -> None:
"--bfoptions", action="store_true", help="Create data.zarr.bfoptions file"
)
symlink.add_argument("--fs_suffix", default="_mkngff", help=FS_SUFFIX_HELP)
symlink.add_argument(
"--clientpath",
help=("Adds omezarr.alt_store=clientpath/path/to/img.zarr to bfoptions"),
)
symlink.set_defaults(func=self.symlink)

bfoptions = sub.add_parser(
Expand Down Expand Up @@ -290,22 +294,27 @@ def sql(self, args: Namespace) -> None:
if args.symlink_repo:
self.create_symlink(args.symlink_repo, prefix, args.symlink_target)
if args.bfoptions:
self.write_bfoptions(args.symlink_repo, prefix, args.symlink_target)
self.write_bfoptions(
args.symlink_repo, prefix, args.symlink_target, args.clientpath
)

def bfoptions(self, args: Namespace) -> None:
self.suffix = "" if args.fs_suffix == "None" else args.fs_suffix
prefix = self.get_prefix(args)
self.write_bfoptions(args.symlink_repo, prefix, args.symlink_target)
self.write_bfoptions(
args.symlink_repo, prefix, args.symlink_target, args.clientpath
)

def symlink(self, args: Namespace) -> None:
self.suffix = "" if args.fs_suffix == "None" else args.fs_suffix
prefix = self.get_prefix(args)
self.create_symlink(args.symlink_repo, prefix, args.symlink_target)
if args.bfoptions:
self.write_bfoptions(args.symlink_repo, prefix, args.symlink_target)
self.write_bfoptions(
args.symlink_repo, prefix, args.symlink_target, args.clientpath
)

def get_prefix(self, args): # type: ignore

conn = self.ctx.conn(args) # noqa
q = conn.sf.getQueryService()
rv = q.findAllByQuery(
Expand Down Expand Up @@ -334,15 +343,18 @@ def get_symlink_dir(self, symlink_repo, prefix): # type: ignore
symlink_dir = f"{prefix_dir}{self.suffix}"
return symlink_dir

def write_bfoptions(self, managed_repo, fsprefix, symlink_target): # type: ignore # noqa
def write_bfoptions(self, managed_repo, fsprefix, symlink_target, clientpath=None): # type: ignore # noqa
file_path = Path(symlink_target)
mkngff_dir = self.get_symlink_dir(managed_repo, fsprefix)
# os.makedirs(mkngff_dir, exist_ok=True)
zarr_path = os.path.join(mkngff_dir, file_path.name)
bfoptions_path = f"{zarr_path}.bfoptions"
self.ctx.err("write bfoptions to: %s" % bfoptions_path)
lines = ["omezarr.list_pixels=false\n", "omezarr.quick_read=true\n"]
if clientpath is not None:
lines.append("omezarr.alt_store=%s\n" % clientpath)
with open(bfoptions_path, "w") as f:
f.writelines(["omezarr.list_pixels=false", "\nomezarr.quick_read=true"])
f.writelines(lines)

def create_symlink(self, symlink_repo, prefix, symlink_target): # type: ignore # noqa
symlink_path = Path(symlink_target)
Expand Down

0 comments on commit d3f95c9

Please sign in to comment.