Skip to content

Commit

Permalink
Added zarr v2_3 env
Browse files Browse the repository at this point in the history
  • Loading branch information
folterj committed Jun 28, 2024
1 parent 623b4ab commit d00e41d
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 10 deletions.
6 changes: 3 additions & 3 deletions OmeSliCC/OmeZarrSource.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#import dask.array as da
import numpy as np
from ome_zarr.io import parse_url
from ome_zarr.io import parse_url, ZarrLocation
from ome_zarr.reader import Reader

from OmeSliCC.OmeSource import OmeSource
Expand All @@ -26,7 +25,8 @@ def __init__(self, filename: str,
self.levels = []
nchannels = 1
try:
location = parse_url(filename)
#location = parse_url(filename)
location = ZarrLocation(filename)
if location is None:
raise FileNotFoundError(f'Error parsing ome-zarr file {filename}')
reader = Reader(location)
Expand Down
17 changes: 12 additions & 5 deletions OmeSliCC/Zarr.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import numpy as np
import os.path
import pathlib
import shutil
import zarr
from zarr.store import make_store_path

from OmeSliCC.image_util import *
from OmeSliCC.ome_zarr_util import *
Expand All @@ -22,8 +23,11 @@ def create(self, source, tile_size=None, npyramid_add=0, pyramid_downsample=2, c
self.npyramid_add = npyramid_add
self.pyramid_downsample = pyramid_downsample
if v3:
store_path = make_store_path(self.filename, mode='w')
self.zarr_root = zarr.Group.create(store=store_path, zarr_format=3)
import zarrita
store_path = zarrita.store.make_store_path(self.filename, mode='w')
if os.path.exists(self.filename):
shutil.rmtree(str(store_path.store.root))
self.zarr_root = zarr.Group.create(store=store_path)
else:
file_url = pathlib.Path(self.filename, mode='w').as_uri()
self.zarr_root = zarr.open_group(store=file_url, mode='w', storage_options={'dimension_separator': '/'})
Expand All @@ -43,10 +47,13 @@ def create(self, source, tile_size=None, npyramid_add=0, pyramid_downsample=2, c
for pathi in range(1 + npyramid_add):
shape = calc_shape_scale(shape0, dimension_order, scale)
if v3:
import zarrita
shape = np.array(shape).tolist() # convert to basic int
tile_size = np.array(tile_size).tolist() # convert to basic int
dataset = self.zarr_root.create_array(str(pathi), shape=shape, chunks=tile_size, dtype=dtype,
compressor=compressor, codecs=compression_filters)
#dataset = self.zarr_root.create_array(str(pathi), shape=shape, chunks=tile_size, dtype=dtype,
# compressor=compressor, codecs=compression_filters)
dataset = zarrita.Array.create(store_path / str(pathi), shape=shape, chunks=tile_size, dtype=dtype,
compressor=compressor, codecs=compression_filters)
else:
dataset = self.zarr_root.create_dataset(str(pathi), shape=shape, chunks=tile_size, dtype=dtype,
compressor=compressor, filters=compression_filters)
Expand Down
31 changes: 31 additions & 0 deletions environmentv2_3.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: omesliccv2_3_env
channels:
- ome
- conda-forge
- defaults
dependencies:
- python=3.10
- pip
- numpy
- pandas
- scikit-image
- scikit-learn
- imagecodecs>=2023.3.16
- numcodecs
- dask
- tifffile>=2023.9.26
- zarr==2.18
- ome-zarr==0.9
- aiohttp
- rsa
- tqdm
- psutil
- PyYAML
- Pillow
- imageio
- validators
- toml
- pip:
- opencv-python
- xmltodict
- zarrita
7 changes: 5 additions & 2 deletions tests/ome_zarr_test.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os.path
import numpy as np
from tqdm import tqdm

Expand Down Expand Up @@ -38,10 +39,12 @@ def save_zarr_v3(source, data, filename, output_params):

if __name__ == '__main__':
#filename = 'E:/Personal/Crick/slides/TCGA_KIRC/0f450938-5604-4af6-8783-c385ea647569/TCGA-A3-3358-01Z-00-DX1.1bd1c720-f6db-4837-8f83-e7476dd2b0a3.svs'
filename = 'E:/Personal/Crick/slides/test_images/zarr test.zarr'
#filename = 'E:/Personal/Crick/slides/test_images/zarr test.zarr'
filename = 'https://uk1s3.embassy.ebi.ac.uk/idr/zarr/v0.4/idr0062A/6001240.zarr'
source = create_source(filename, {})
#source = ZarrSource(filename)
w, h = source.get_size()
output_filename = 'D:/slides/test/test.ome.zarr'
output_filename = 'D:/slides/test/' + os.path.basename(filename)
npyramid_add = 4
pyramid_downsample = 2
tile_size = 16
Expand Down

0 comments on commit d00e41d

Please sign in to comment.