Skip to content

Commit 84510ec

Browse files
authored
Merge pull request #25 from chris-allan/zarr-only
Switch to Zarr only
2 parents d76fbcc + 8beb7ca commit 84510ec

File tree

5 files changed

+46
-31
lines changed

5 files changed

+46
-31
lines changed

README.md

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,37 @@ Python tool that uses Philips' SDK to write slides in an intermediary raw format
66

77
## Requirements
88

9+
* Python 3.6+
910
* Philips iSyntax SDK (https://openpathology.philips.com)
1011

1112
The iSyntax SDK __must__ be downloaded separately from Philips and the
1213
relevant license agreement agreed to before any conversion can take place.
1314

15+
As of version 0.4.0, which has a Python 3.6+ requirement, the supported
16+
iSyntax SDK versions and environments are as follows:
17+
18+
* iSyntax SDK 1.2.1 (CentOS 7, Ubuntu 18.04, Windows 10 64-bit)
19+
* iSyntax SDK 2.0 (CentOS 8, Ubuntu 18.04, Windows 10 64-bit)
20+
1421
## Usage
1522

1623
Basic usage is:
1724

18-
isyntax2raw write_tiles /path/to/input.isyntax /path/to/tile/directory
25+
isyntax2raw write_tiles /path/to/input.isyntax /path/to/directory.zarr
1926

2027
Please see `isyntax2raw write_tiles --help` for detailed information.
2128

2229
Output tile width and height can optionally be specified; default values are
2330
detailed in `--help`.
2431

2532
A directory structure containing the pyramid tiles at all resolutions and
26-
macro/label images will be created. The default format is N5. Additional
33+
macro/label images will be created. The default format is Zarr. Additional
2734
metadata is written to a JSON file. Be mindful of available disk space, as
2835
larger .isyntax files can result in >20 GB of tiles.
2936

30-
Use of a n5 (the default) or zarr `--file_type` will result in losslessly
31-
compressed output. These are the only formats that are currently
32-
supported by the downstream `raw2ometiff`.
37+
Use of the Zarr file type will result in losslessly compressed output. This
38+
is the only format currently supported by the downstream `raw2ometiff` (as of
39+
version 0.3.0).
3340

3441
## Background color
3542

appveyor.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
image: ubuntu1804
22

33
install:
4-
- sudo apt-get update
54
- sudo apt-get install -y python3-setuptools python3-wheel twine
65

76
build: off

isyntax2raw/__init__.py

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,13 @@
2525

2626
from PIL import Image
2727
from kajiki import PackageLoader
28+
from zarr.storage import FSStore
2829

2930

3031
log = logging.getLogger(__name__)
3132

32-
# version of the N5/Zarr layout
33-
LAYOUT_VERSION = 1
33+
# version of the Zarr layout
34+
LAYOUT_VERSION = 3
3435

3536

3637
class MaxQueuePool(object):
@@ -79,20 +80,20 @@ def __exit__(self, exception_type, exception_value, traceback):
7980
class WriteTiles(object):
8081

8182
def __init__(
82-
self, tile_width, tile_height, resolutions, file_type, max_workers,
83-
batch_size, input_path, output_path, fill_color
83+
self, tile_width, tile_height, resolutions, max_workers,
84+
batch_size, fill_color, nested, input_path, output_path
8485
):
8586
self.tile_width = tile_width
8687
self.tile_height = tile_height
8788
self.resolutions = resolutions
88-
self.file_type = file_type
8989
self.max_workers = max_workers
9090
self.batch_size = batch_size
91+
self.fill_color = fill_color
92+
self.nested = nested
9193
self.input_path = input_path
9294
self.slide_directory = output_path
93-
self.fill_color = fill_color
9495

95-
os.makedirs(self.slide_directory, exist_ok=True)
96+
os.makedirs(os.path.join(self.slide_directory, "OME"), exist_ok=True)
9697

9798
render_context = softwarerendercontext.SoftwareRenderContext()
9899
render_backend = softwarerenderbackend.SoftwareRenderBackend()
@@ -378,7 +379,9 @@ def wait_any(self, regions):
378379

379380
def write_metadata(self):
380381
'''write metadata to a JSON file'''
381-
metadata_file = os.path.join(self.slide_directory, "METADATA.json")
382+
metadata_file = os.path.join(
383+
self.slide_directory, "OME", "METADATA.json"
384+
)
382385

383386
with open(metadata_file, "w", encoding="utf-8") as f:
384387
metadata = self.get_metadata()
@@ -419,7 +422,9 @@ def write_metadata(self):
419422
loader = PackageLoader()
420423
template = loader.import_("isyntax2raw.resources.ome_template")
421424
xml = template(xml_values).render()
422-
ome_xml_file = os.path.join(self.slide_directory, "METADATA.ome.xml")
425+
ome_xml_file = os.path.join(
426+
self.slide_directory, "OME", "METADATA.ome.xml"
427+
)
423428
with open(ome_xml_file, "w", encoding="utf-8") as omexml:
424429
omexml.write(xml)
425430

@@ -474,12 +479,15 @@ def write_image_type(self, image_type, series):
474479
log.info("wrote %s image" % image_type)
475480

476481
def create_tile_directory(self, series, resolution, width, height):
477-
tile_directory = os.path.join(
478-
self.slide_directory, "data.%s" % self.file_type
482+
dimension_separator = '/'
483+
if not self.nested:
484+
dimension_separator = '.'
485+
self.zarr_store = FSStore(
486+
self.slide_directory,
487+
dimension_separator=dimension_separator,
488+
normalize_keys=True,
489+
auto_mkdir=True
479490
)
480-
self.zarr_store = zarr.DirectoryStore(tile_directory)
481-
if self.file_type == "n5":
482-
self.zarr_store = zarr.N5Store(tile_directory)
483491
self.zarr_group = zarr.group(store=self.zarr_store)
484492
self.zarr_group.attrs['bioformats2raw.layout'] = LAYOUT_VERSION
485493

@@ -520,7 +528,7 @@ def write_tile(
520528
x_end = x_start + tile_width
521529
y_end = y_start + tile_height
522530
try:
523-
# N5/Zarr has a single n-dimensional array representation on
531+
# Zarr has a single n-dimensional array representation on
524532
# disk (not interleaved RGB)
525533
pixels = self.make_planar(pixels, tile_width, tile_height)
526534
z = self.zarr_group["0/%d" % resolution]

isyntax2raw/cli/isyntax2raw.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,6 @@ def cli():
3131
"--resolutions", type=int,
3232
help="number of pyramid resolutions to generate [default: all]"
3333
)
34-
@click.option(
35-
"--file_type", type=click.Choice(['n5', 'zarr']), default="n5",
36-
show_default=True,
37-
help="tile file extension"
38-
)
3934
@click.option(
4035
"--max_workers", default=4, type=int,
4136
show_default=True,
@@ -50,15 +45,19 @@ def cli():
5045
show_default=True,
5146
help="background color for missing tiles (0-255)"
5247
)
48+
@click.option(
49+
"--nested/--no-nested", default=True, show_default=True,
50+
help="Whether to use '/' as the chunk path separator"
51+
)
5352
@click.option(
5453
"--debug", is_flag=True,
5554
help="enable debugging",
5655
)
5756
@click.argument("input_path")
5857
@click.argument("output_path")
5958
def write_tiles(
60-
tile_width, tile_height, resolutions, file_type, max_workers, batch_size,
61-
input_path, output_path, fill_color, debug
59+
tile_width, tile_height, resolutions, max_workers, batch_size,
60+
fill_color, nested, debug, input_path, output_path
6261
):
6362
level = logging.INFO
6463
if debug:
@@ -69,8 +68,8 @@ def write_tiles(
6968
"(%(thread)10s) %(message)s"
7069
)
7170
with WriteTiles(
72-
tile_width, tile_height, resolutions, file_type, max_workers,
73-
batch_size, input_path, output_path, fill_color
71+
tile_width, tile_height, resolutions, max_workers,
72+
batch_size, fill_color, nested, input_path, output_path
7473
) as wt:
7574
wt.write_metadata()
7675
wt.write_label_image()

setup.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ def read(fname):
6262

6363
setup(name='isyntax2raw',
6464
version=version.getVersion(),
65+
python_requires='>=3.6',
6566
description='iSyntax to raw format converter',
6667
long_description=read('README.md'),
6768
long_description_content_type='text/markdown',
@@ -82,8 +83,9 @@ def read(fname):
8283
'click==7.0',
8384
'pillow>=7.1.0',
8485
'numpy==1.17.3',
85-
'zarr==2.4.0',
86+
'zarr==2.8.1',
8687
'kajiki==0.8.2',
88+
'fsspec>=0.9.0',
8789
],
8890
tests_require=[
8991
'flake8',

0 commit comments

Comments
 (0)