Skip to content

Commit

Permalink
updates to ome_zarr
Browse files Browse the repository at this point in the history
  • Loading branch information
bugraoezdemir authored Jan 15, 2025
1 parent 3a3d685 commit 7305205
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 41 deletions.
2 changes: 1 addition & 1 deletion _includes/ome_zarr/ome_zarr_creation.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Create OME-Zarr data from data stored in monolithic file formats.

- Download the tiff [image series](https://zenodo.org/records/14641498/files/tiff_series.zip?download=1) and extract them to a convenient local directory. \
- Download the [tiff_series](https://zenodo.org/records/14641498/files/tiff_series.zip?download=1) dataset and extract them to a convenient local directory. \
For example: `~/image_data_course/data/tiff/tiff_series`

- Open the files
Expand Down
16 changes: 14 additions & 2 deletions _includes/ome_zarr/ome_zarr_creation_BatchConvert.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
**Perform parallelised conversion of image data collections to OME-Zarr using BatchConvert**
#### Perform parallelised conversion of image data collections to OME-Zarr using BatchConvert

As input, use the `tiff_series` dataset (`~/image_data_course/data/tiff/tiff_series`).
**Important note: BatchConvert is currently only supported on unix-based systems**

As input, use the `tiff_series` dataset.

**Perform parallelised, independent conversion:**
```bash
Expand Down Expand Up @@ -55,3 +57,13 @@ Check the content of the `zarr_series_concatenated_rechunked` folder:
ls /path/to/zarr_series_concatenated_rechunked
```
Optional: Inspect the created OME-Zarr. Compare it to the one created earlier.



```bash
batchconvert omezarr input_path output_path
```

```bash
bfconvert input_path output_path
```
8 changes: 6 additions & 2 deletions _includes/ome_zarr/ome_zarr_inspection_ome-zarr-py.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
**Use the ome_zarr tool for the inspecting and downloading OME-Zarrs from s3:**

Remote OME-Zarr data stored in a public s3 bucket can be inspected and downloaded using
Remote OME-Zarr data stored in a **public** s3 bucket can be inspected and downloaded using
the `ome-zarr-py` tool.

Inspect 3 different remote datasets:
Expand All @@ -20,8 +20,12 @@ ome_zarr info https://s3.embl.de/i2k-2020/platy-raw.ome.zarr
**Optional:** Download the dataset `6001240.zarr` from s3 to a local path:

```bash
# cd ~/ome_zarr_course/data/zarr
# cd ~/image_data_formats/day1/ome_zarr
cd /path/to/local/zarr # where you want to keep the data on your system
ome_zarr download https://uk1s3.embassy.ebi.ac.uk/idr/zarr/v0.4/idr0062A/6001240.zarr
```

**Optional:** Inspect the local dataset in the same way:
```bash
ome_zarr info /path/to/local/zarr/6001240.zarr
```
52 changes: 38 additions & 14 deletions _includes/ome_zarr/ome_zarr_visualisation_napari.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,44 @@
**Visualise the remote data using Napari together with the napari-ome-zarr plugin.**
#### Visualise the remote data using Napari together with the napari-ome-zarr plugin.

```
napari --plugin napari-ome-zarr https://s3.embl.de/ome-zarr-course/data/ZARR/$USER/xyzct_8bit__mitosis.ome.zarr
**Use command line:**
``` bash
napari --plugin napari-ome-zarr https://uk1s3.embassy.ebi.ac.uk/idr/zarr/v0.4/idr0062A/6001240.zarr
```

```
napari --plugin napari-ome-zarr https://s3.embl.de/ome-zarr-course/data/ZARR/$USER/xyz_8bit_calibrated__fib_sem_crop.ome.zarr
```
**Use Python code:**

**Optional: visualise local OME-Zarr data in the same way:**
```
napari --plugin napari-ome-zarr ~/data/ZARR/xyzct_8bit__mitosis.ome.zarr
```
Approach 1: Open the full OME-Zarr from the top level url:
```python
import napari
import zarr, dask.array as da

v = napari.Viewer()
v.open("https://uk1s3.embassy.ebi.ac.uk/idr/zarr/v0.4/idr0062A/6001240.zarr",
plugin = 'napari-ome-zarr'
)
napari.run()
```
Note that this approach automates a lot of tasks for the user,
discovering look-up tables, pixel scalings and units from the OME-Zarr metadata.

**Optional: visualise big remote OME-Zarr data:**
```
napari --plugin napari-ome-zarr https://s3.embl.de/i2k-2020/platy-raw.ome.zarr
Approach 2: Read arrays and open them individually:
```python
import napari
import zarr, dask.array as da

url = "https://uk1s3.embassy.ebi.ac.uk/idr/zarr/v0.4/idr0062A/6001240.zarr"
gr = zarr.open_group(url, mode = 'r')
#array0 = da.from_zarr(gr[0])
array2 = da.from_zarr(gr[2])
#label_array0 = da.from_zarr(gr.labels['0'][0])
label_array2 = da.from_zarr(gr.labels['0'][2])
v = napari.Viewer()
#v.add_image(array0, contrast_limits = (0, 2000), colormap = 'yellow')
v.add_image(array2, contrast_limits = (0, 2000), colormap = 'red')
#v.add_labels(label_array0)
v.add_labels(label_array2)
napari.run()
```
Note that compared to BigDataViewer, there are more delays with Napari.

Note that approach 2 is flexible but does not use any metadata. You have to
specify the metadata to the viewer manually.
25 changes: 22 additions & 3 deletions _includes/ome_zarr/open_ome_zarr_ome-zarr-py.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,39 @@

```python
import ome_zarr, zarr, pprint, os
from ome_zarr import utils
from ome_zarr.reader import Reader
from ome_zarr.io import parse_url
```

**Use the utils module to inspect, download or validate the remote data**

Inspect:
```python
list(utils.info("https://uk1s3.embassy.ebi.ac.uk/EuBI/anna_steyer0/20160112_C.elegans_std_fullhead.zarr"))
```

Download:
```python
utils.download(input_path = "https://uk1s3.embassy.ebi.ac.uk/idr/zarr/v0.4/idr0062A/6001240.zarr",
output_dir = "/path/to/local/zarr") # eg: "/home/oezdemir/image_data_formats/day1/ome_zarr"
```

Validate:
```python
utils.view(input_path = "https://uk1s3.embassy.ebi.ac.uk/idr/zarr/v0.4/idr0062A/6001240.zarr")
```


**Read remote OME-Zarr:**
```python
# local_path = f"{os.path.expanduser('~')}/image_data_course/data/zarr/6001240.zarr"
remote_path = f"https://uk1s3.embassy.ebi.ac.uk/idr/zarr/v0.4/idr0062A/6001240.zarr"
reader = Reader(parse_url(remote_path))
# Note here that 'parse_url' can parse both remote and local urls.
# No need for explicit use of s3fs.
```


Note that ome-zarr-py uses the term 'node' for different zarr groups \
Note that ome-zarr-py uses the term 'node' for different zarr groups
and reads them in a flat list.

**Print the node information per resolution level:**
Expand Down
6 changes: 3 additions & 3 deletions _includes/ome_zarr/save_ome_zarr_ome-zarr-py.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ url as input to the `parse_url` function.

```python
# Specify the path where you want to write
# output_path = f"{os.path.expanduser('~')}/ome_zarr_course/data/zarr/outputs/astronaut.zarr"
# output_path = f"{os.path.expanduser('~')}/image_data_formats/day2/astronaut.zarr"
output_path = "/path/to/astronaut.zarr"
# Parse the url as a zarr store. Note that "mode = 'w'" enables writing to this store.
store = parse_url(output_path, mode = 'w').store
Expand All @@ -35,8 +35,8 @@ In order to create an image pyramid, one has to instantiate a scaler.
This scaler requires the parameters: scale factor, number of resolution
layers and downscaling method.
```python
scaler = scale.Scaler(downscale=2, # Downscaling factor fox x and y axes
max_layer=4, # Number of downscalings
scaler = scale.Scaler(downscale=2, # Downscaling factor for x and y axes
max_layer=4, # Number of downscalings = 5
method = 'nearest' # downscaling method
)
```
Expand Down
14 changes: 8 additions & 6 deletions _includes/ome_zarr/update_rendering_metadata.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@

```python
import zarr, os
from ome_zarr.io import parse_url
from ome_zarr.io import parse_url, utils
import matplotlib.colors as mcolors
```

**At this stage inspect the image using the OME-Zarr validator:**

```bash
ome_zarr view ~/ome_zarr_course/data/zarr/outputs/astronaut.zarr
```python
# path = f"{os.path.expanduser('~')}/image_data_formats/day2/astronaut.zarr"
path = "/path/to/astronaut.zarr"
utils.view(path)
```

**Define a utility function to get the hex color code by simple color names**
Expand All @@ -26,7 +28,6 @@ def get_color_code(color_name):
**Now add rendering metadata**

```python
path = f"{os.path.expanduser('~')}/ome_zarr_course/data/zarr/outputs/astronaut.zarr"
store = parse_url(path, mode = 'w').store # Create a zarr store to save the data. Note that this can also be an s3 object store.
root = zarr.open_group(store=store)
root.attrs["omero"] = {
Expand Down Expand Up @@ -55,7 +56,8 @@ root.attrs["omero"] = {

It is important to know here that not all OME-Zarr readers recognize each of these settings. \
Apply the validator again to the data to see the changes:
```bash
ome_zarr view ~/ome_zarr_course/data/zarr/outputs/astronaut.zarr
```python
path = "/path/to/astronaut.zarr"
utils.view(path)
```
As the data looks valid, now visualize using different viewers to see if the rendering is working.
12 changes: 2 additions & 10 deletions _includes/ome_zarr/validate_ome_zarr_ome-zarr-validator.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,11 @@ of the OME-Zarr dataset.

**Now do the same but with remote data:**

```bash
ome_zarr view https://uk1s3.embassy.ebi.ac.uk/idr/zarr/v0.4/idr0062A/6001240.zarr
```
Note that with the remote url it is possible to copy the link from your browser and share it with
your colleagues.

**Take ome-zarr-py out of the loop and use the web browser directly:**

Enter the following into your browser: `https://ome.github.io/ome-ngff-validator/?source=`

Then paste the dataset url after the 'equal' sign, constructing the following link:

[https://ome.github.io/ome-ngff-validator/?source=https://uk1s3.embassy.ebi.ac.uk/idr/zarr/v0.4/idr0062A/6001240.zarr](https://ome.github.io/ome-ngff-validator/?source=https://uk1s3.embassy.ebi.ac.uk/idr/zarr/v0.4/idr0062A/6001240.zarr)



Note that with the remote url it is possible to copy the link from your browser and share it with
your colleagues.

0 comments on commit 7305205

Please sign in to comment.