Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Examples #135

Draft
wants to merge 89 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
89 commits
Select commit Hold shift + click to select a range
d480664
Examples README
Jul 1, 2022
cf7e424
steinbock_notebook v1.0.0
ndamond Jul 1, 2022
34c2d67
jupytext
Jul 1, 2022
4bfd87d
extract ome.tiff and metadata
ndamond Jul 1, 2022
75387cc
add script to download examples and panel
ndamond Jul 4, 2022
14dcad6
updated path to proper panel
ndamond Jul 4, 2022
b1fdb2c
updated panel and image conversion
ndamond Jul 5, 2022
44fb55a
add helper functions
ndamond Jul 5, 2022
ff27982
Fix duplicated names in `panel.csv`
ndamond Jul 6, 2022
01852f9
small changes for consistency with steinbock docker
ndamond Jul 6, 2022
fce2d6f
put normalization functions in helpers
ndamond Jul 6, 2022
e31f0b5
make all output file names identical
ndamond Jul 6, 2022
2dd2d7c
make sure deepcell channels are not 0
ndamond Jul 7, 2022
7908af9
run segmentation with deepcell, not steinbock
ndamond Jul 8, 2022
3628efa
new example script for IF data
ndamond Jul 15, 2022
8141c4e
generate stacks from single tiffs
ndamond Jul 18, 2022
ebaa723
read imgs/masks with tifffile for IF measurements
ndamond Aug 18, 2022
0ca7b9a
add jupytext
ndamond Aug 24, 2022
b880f0e
download example data from main notebook
ndamond Aug 24, 2022
3a13169
create panel from mcd
ndamond Aug 24, 2022
fb59129
read panel with
ndamond Aug 24, 2022
0be9030
use steinbock for deepcell segmentation
ndamond Aug 24, 2022
899f30f
cell segmentation check: show image+mask overlay
ndamond Aug 24, 2022
cd184b8
split up the notebooks
ndamond Aug 25, 2022
3a96691
Delete panel.csv
ndamond Aug 25, 2022
a31b6b0
closes #139
Aug 27, 2022
7ba7f45
closes #140
Aug 27, 2022
8690685
closes #141
Aug 27, 2022
0afc134
typing
Aug 27, 2022
1387ae7
rename function
Aug 27, 2022
38639fc
typing
Aug 27, 2022
f560398
use steinbock function for zip extraction
ndamond Aug 29, 2022
c4581a9
update installation instructions
ndamond Aug 29, 2022
4597e16
use imc.create_image_info() to extract image metadata
ndamond Aug 29, 2022
bb818a8
create seg stacks with deepcell.create_segmentation_stack()
ndamond Aug 29, 2022
8802eaf
update .py files jupytext + delete helpers.py
ndamond Aug 29, 2022
e199749
Fix histoCAT mask export (closes #136)
Sep 13, 2022
4c63478
docs (closes #121)
Sep 13, 2022
cf7ad7b
closes #139
Aug 27, 2022
159d491
closes #140
Aug 27, 2022
eef65ef
closes #141
Aug 27, 2022
87e9a28
typing
Aug 27, 2022
aff6b5e
rename function
Aug 27, 2022
020a9fd
typing
Aug 27, 2022
5c639e2
support 2-6 channel TIFFs (closes #109)
Sep 14, 2022
3d81a24
process data from zips individually (closes #117)
Sep 14, 2022
cedb274
docs
Sep 14, 2022
6a270d4
fix relabeling during stitching (closes #146)
Sep 14, 2022
93f7ac1
explain Docker run options (closes #104)
Sep 14, 2022
0992d71
dependency upgrades
Sep 14, 2022
ff658eb
Fix CellProfiler version
Sep 15, 2022
4dc0d08
fix default skimage regionprops
Sep 15, 2022
487ce0b
anndata export panel/image metadata (closes #66)
Sep 15, 2022
0e24bc7
v0.15.0
Sep 15, 2022
65eb900
Merge pull request #147 from BodenmillerGroup/develop
Sep 15, 2022
59a7da2
Examples README
Jul 1, 2022
f989d2a
steinbock_notebook v1.0.0
ndamond Jul 1, 2022
a5d69fc
jupytext
Jul 1, 2022
f35be1f
extract ome.tiff and metadata
ndamond Jul 1, 2022
a47b2ad
add script to download examples and panel
ndamond Jul 4, 2022
f6993bf
updated path to proper panel
ndamond Jul 4, 2022
7b7ccdc
updated panel and image conversion
ndamond Jul 5, 2022
313f75f
add helper functions
ndamond Jul 5, 2022
72b0c1e
Fix duplicated names in `panel.csv`
ndamond Jul 6, 2022
2766ad2
small changes for consistency with steinbock docker
ndamond Jul 6, 2022
9128d20
put normalization functions in helpers
ndamond Jul 6, 2022
b97023a
make all output file names identical
ndamond Jul 6, 2022
e095587
make sure deepcell channels are not 0
ndamond Jul 7, 2022
680a1fd
run segmentation with deepcell, not steinbock
ndamond Jul 8, 2022
ff3e12a
new example script for IF data
ndamond Jul 15, 2022
9eec527
generate stacks from single tiffs
ndamond Jul 18, 2022
cdcf720
read imgs/masks with tifffile for IF measurements
ndamond Aug 18, 2022
2351aa2
add jupytext
ndamond Aug 24, 2022
6b7ee66
download example data from main notebook
ndamond Aug 24, 2022
6970cba
create panel from mcd
ndamond Aug 24, 2022
1e561ac
read panel with
ndamond Aug 24, 2022
110544d
use steinbock for deepcell segmentation
ndamond Aug 24, 2022
02a8cf0
cell segmentation check: show image+mask overlay
ndamond Aug 24, 2022
19f2755
split up the notebooks
ndamond Aug 25, 2022
930de81
Delete panel.csv
ndamond Aug 25, 2022
08456e0
use steinbock function for zip extraction
ndamond Aug 29, 2022
40ef356
update installation instructions
ndamond Aug 29, 2022
072dd28
use imc.create_image_info() to extract image metadata
ndamond Aug 29, 2022
d4148c3
create seg stacks with deepcell.create_segmentation_stack()
ndamond Aug 29, 2022
1bd6479
update .py files jupytext + delete helpers.py
ndamond Aug 29, 2022
e224781
Merge branch 'examples' of github.com:BodenmillerGroup/steinbock into…
Sep 15, 2022
8df67ba
changes for steinbock v0.15
Oct 31, 2022
85345c6
update installation instructions
ndamond Dec 12, 2022
50529d5
update insallation instructions - pyfiles
ndamond Dec 12, 2022
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
2 changes: 1 addition & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
run: |
python -m pip install --upgrade pip setuptools wheel
pip install --upgrade -r requirements_deepcell.txt
pip install --no-deps deepcell==0.12.2
pip install --no-deps deepcell==0.12.3
pip install --upgrade -r requirements.txt
pip install -e .
pip install --upgrade -r requirements_docs.txt
Expand Down
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,19 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.15.0] - 2022-09-15

- [#136](https://github.com/BodenmillerGroup/steinbock/issues/136) Fix histoCAT mask export
- [#146](https://github.com/BodenmillerGroup/steinbock/issues/146) Fix relabeling during stitching
- Upgrade deepcell 0.12.2 to 0.12.3
- Upgrade CellProfiler 4.2.1 to 4.2.4
- Upgrade other dependencies
- [#109](https://github.com/BodenmillerGroup/steinbock/issues/109) Support 2-6 channel TIFF files
- [#66](https://github.com/BodenmillerGroup/steinbock/issues/66) Include panel/image metadata in anndata exports
- [#117](https://github.com/BodenmillerGroup/steinbock/issues/117) Extract and process images from .zip archives file by file
- [#104](https://github.com/BodenmillerGroup/steinbock/issues/104) [#121](https://github.com/BodenmillerGroup/steinbock/issues/121) Documentation improvements
- [#139](https://github.com/BodenmillerGroup/steinbock/issues/139) [#140](https://github.com/BodenmillerGroup/steinbock/issues/140) [#141](https://github.com/BodenmillerGroup/steinbock/issues/141) API improvements

## [0.14.2] - 2022-06-29

- Upgrade DeepCell (to 0.12.2) and other dependencies
Expand Down Expand Up @@ -327,6 +340,7 @@ Added:
Initial release for beta testing


[0.15.0]: https://github.com/BodenmillerGroup/steinbock/compare/v0.14.2...v0.15.0
[0.14.2]: https://github.com/BodenmillerGroup/steinbock/compare/v0.14.1...v0.14.2
[0.14.1]: https://github.com/BodenmillerGroup/steinbock/compare/v0.14.0...v0.14.1
[0.14.0]: https://github.com/BodenmillerGroup/steinbock/compare/v0.13.5...v0.14.0
Expand Down
4 changes: 3 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@ For major changes, please open an issue first to discuss what you would like to

## Development

*steinbock* is developed using [Visual Studio Code](https://code.visualstudio.com).
*steinbock* is developed using [Visual Studio Code](https://code.visualstudio.com). For building the *steinbock* Docker image, BuildKit needs to be enabled for Docker.

For convenience, the following [Docker Compose](https://docs.docker.com/compose) services are available:

- `steinbock` for running *steinbock*
- `steinbock-debug` for debugging *steinbock* using [debugpy](https://github.com/microsoft/debugpy)
- `pytest` for running unit tests with [pytest](https://pytest.org)
- `pytest-debug` for debugging unit tests with [pytest](https://pytest.org) and [debugpy](https://github.com/microsoft/debugpy)

Matching Visual Studio Code launch configurations are provided for debugging:

- `Docker: Python General` for debugging *steinbock* using [Docker](https://www.docker.com) directly
- `Python: Remote Attach (steinbock-debug)` for debugging *steinbock* using [Docker Compose](https://docs.docker.com/compose)
- `Python: Remote Attach (pytest-debug)` for debugging unit tests with [pytest](https://pytest.org) using [Docker Compose](https://docs.docker.com/compose)
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ ARG TENSORFLOW_VERSION
ARG TENSORFLOW_SUFFIX
ARG FIXUID_VERSION=0.5.1
ARG ILASTIK_BINARY=ilastik-1.3.3post3-Linux.tar.bz2
ARG CELLPROFILER_VERSION=4.2.1
ARG CELLPROFILER_VERSION=4.2.4
ARG CELLPROFILER_PLUGINS_VERSION=4.2.1
ARG TZ=Europe/Zurich

Expand Down Expand Up @@ -69,7 +69,7 @@ RUN mkdir /opt/cellprofiler_plugins && \
COPY requirements.txt /app/steinbock/requirements.txt
COPY requirements_deepcell${TENSORFLOW_SUFFIX}.txt /app/steinbock/requirements_deepcell${TENSORFLOW_SUFFIX}.txt
RUN python -m pip install --upgrade -r /app/steinbock/requirements_deepcell${TENSORFLOW_SUFFIX}.txt && \
python -m pip install --no-deps deepcell==0.12.2 && \
python -m pip install --no-deps deepcell==0.12.3 && \
python -m pip install --upgrade -r /app/steinbock/requirements.txt
ENV TF_CPP_MIN_LOG_LEVEL="2" NO_AT_BRIDGE="1"

Expand Down
30 changes: 17 additions & 13 deletions docs/install-docker.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ In principle, the *steinbock* Docker container can be run on any Docker-enabled

For reproducibility, it is recommended to always pull a specific release, e.g.:

docker run ghcr.io/bodenmillergroup/steinbock:0.14.2
docker run ghcr.io/bodenmillergroup/steinbock:0.15.0

To run the *steinbock* Docker container with NVIDIA GPU support (Linux only):

docker run --gpus all ghcr.io/bodenmillergroup/steinbock-gpu:0.14.2
docker run --gpus all ghcr.io/bodenmillergroup/steinbock-gpu:0.15.0

[Bind mounts](https://docs.docker.com/storage/bind-mounts/) can be used to make data from the host system available to the Docker container (see below). Commands that launch a graphical user interface may require further system configuration and additional arguments to `docker run` as outlined in the following.

Expand All @@ -51,11 +51,11 @@ To run the *steinbock* Docker container with NVIDIA GPU support (Linux only):

On the command line, use the following command to run the *steinbock* Docker container:

docker run -v "C:\Data":/data ghcr.io/bodenmillergroup/steinbock:0.14.2
docker run -v "C:\Data":/data ghcr.io/bodenmillergroup/steinbock:0.15.0

In the command above, adapt the bind mount path to your data/working directory (`C:\Data`) and the *steinbock* Docker container version (`0.14.2`) as needed. To simplify the use of the *steinbock* command-line interface, it is recommended to set up a `steinbock` command alias:
In the command above, adapt the bind mount path to your data/working directory (`C:\Data`) and the *steinbock* Docker container version (`0.15.0`) as needed. To simplify the use of the *steinbock* command-line interface, it is recommended to set up a `steinbock` command alias:

doskey steinbock=docker run -v "C:\Data":/data ghcr.io/bodenmillergroup/steinbock:0.14.2 $*
doskey steinbock=docker run -v "C:\Data":/data ghcr.io/bodenmillergroup/steinbock:0.15.0 $*

The created command alias is retained for the current session and enables running `steinbock` from the current command line without typing the full Docker command, for example:

Expand All @@ -68,19 +68,21 @@ The created command alias is retained for the current session and enables runnin

On the terminal, use the following command to run the *steinbock* Docker container:

docker run -v /path/to/data:/data -v /tmp/.X11-unix:/tmp/.X11-unix -v ~/.Xauthority:/home/steinbock/.Xauthority:ro -u $(id -u):$(id -g) -e DISPLAY ghcr.io/bodenmillergroup/steinbock:0.14.2
docker run -v /path/to/data:/data -v /tmp/.X11-unix:/tmp/.X11-unix -v ~/.Xauthority:/home/steinbock/.Xauthority:ro -u $(id -u):$(id -g) -e DISPLAY ghcr.io/bodenmillergroup/steinbock:0.15.0

To run the *steinbock* Docker container with NVIDIA GPU support, use `steinbock-gpu` Docker image instead:

docker run -v /path/to/data:/data -v /tmp/.X11-unix:/tmp/.X11-unix -v ~/.Xauthority:/home/steinbock/.Xauthority:ro -u $(id -u):$(id -g) -e DISPLAY --gpus all ghcr.io/bodenmillergroup/steinbock-gpu:0.14.2
docker run -v /path/to/data:/data -v /tmp/.X11-unix:/tmp/.X11-unix -v ~/.Xauthority:/home/steinbock/.Xauthority:ro -u $(id -u):$(id -g) -e DISPLAY --gpus all ghcr.io/bodenmillergroup/steinbock-gpu:0.15.0

In the commands above, adapt the bind mount path to your data/working directory (`/path/to/data`) and the *steinbock* Docker container version (`0.14.2`) as needed. To simplify the use of the *steinbock* command-line interface, it is recommended to set up a `steinbock` command alias:
In the commands above, adapt the bind mount path to your data/working directory (`/path/to/data`) and the *steinbock* Docker container version (`0.15.0`) as needed. The environment variable `DISPLAY` as well as the bind mounts for `/tmp/.X11-unix` and `~/.Xauthority` are required only when running graphical user interfaces.

alias steinbock="docker run -v /path/to/data:/data -v /tmp/.X11-unix:/tmp/.X11-unix -v ~/.Xauthority:/home/steinbock/.Xauthority:ro -u $(id -u):$(id -g) -e DISPLAY ghcr.io/bodenmillergroup/steinbock:0.14.2"
To simplify the use of the *steinbock* command-line interface, it is recommended to set up a `steinbock` command alias:

alias steinbock="docker run -v /path/to/data:/data -v /tmp/.X11-unix:/tmp/.X11-unix -v ~/.Xauthority:/home/steinbock/.Xauthority:ro -u $(id -u):$(id -g) -e DISPLAY ghcr.io/bodenmillergroup/steinbock:0.15.0"

To run the *steinbock* Docker container with NVIDIA GPU support, use `steinbock-gpu` Docker image instead:

alias steinbock="docker run -v /path/to/data:/data -v /tmp/.X11-unix:/tmp/.X11-unix -v ~/.Xauthority:/home/steinbock/.Xauthority:ro -u $(id -u):$(id -g) -e DISPLAY --gpus all ghcr.io/bodenmillergroup/steinbock-gpu:0.14.2"
alias steinbock="docker run -v /path/to/data:/data -v /tmp/.X11-unix:/tmp/.X11-unix -v ~/.Xauthority:/home/steinbock/.Xauthority:ro -u $(id -u):$(id -g) -e DISPLAY --gpus all ghcr.io/bodenmillergroup/steinbock-gpu:0.15.0"

The created command alias is retained for the current session and enables running `steinbock` from the current terminal without typing the full Docker command, for example:

Expand All @@ -95,11 +97,13 @@ The created command alias is retained for the current session and enables runnin

On the terminal, use the following command to run the *steinbock* Docker container (Docker must be running):

docker run -v /path/to/data:/data -v /tmp/.X11-unix:/tmp/.X11-unix -v ~/.Xauthority:/home/steinbock/.Xauthority:ro -u $(id -u):$(id -g) -e DISPLAY=$(hostname):0 ghcr.io/bodenmillergroup/steinbock:0.14.2
docker run -v /path/to/data:/data -v /tmp/.X11-unix:/tmp/.X11-unix -v ~/.Xauthority:/home/steinbock/.Xauthority:ro -u $(id -u):$(id -g) -e DISPLAY=$(hostname):0 ghcr.io/bodenmillergroup/steinbock:0.15.0

In the command above, adapt the bind mount path to your data/working directory (`/path/to/data`) and the *steinbock* Docker container version (`0.15.0`) as needed. The environment variable `DISPLAY` as well as the bind mounts for `/tmp/.X11-unix` and `~/.Xauthority` are required only when running graphical user interfaces.

In the command above, adapt the bind mount path to your data/working directory (`/path/to/data`) and the *steinbock* Docker container version (`0.14.2`) as needed. To simplify the use of the *steinbock* command-line interface, it is recommended to set up a `steinbock` command alias:
To simplify the use of the *steinbock* command-line interface, it is recommended to set up a `steinbock` command alias:

alias steinbock="docker run -v /path/to/data:/data -v /tmp/.X11-unix:/tmp/.X11-unix -v ~/.Xauthority:/home/steinbock/.Xauthority:ro -u $(id -u):$(id -g) -e DISPLAY=$(hostname):0 ghcr.io/bodenmillergroup/steinbock:0.14.2"
alias steinbock="docker run -v /path/to/data:/data -v /tmp/.X11-unix:/tmp/.X11-unix -v ~/.Xauthority:/home/steinbock/.Xauthority:ro -u $(id -u):$(id -g) -e DISPLAY=$(hostname):0 ghcr.io/bodenmillergroup/steinbock:0.15.0"

The created command alias is retained for the current session and enables running `steinbock` from the current terminal without typing the full Docker command, for example:

Expand Down
2 changes: 1 addition & 1 deletion docs/install-python.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ To install all extras, use the `all` extra:
# choose between one of the following:
# pip install --upgrade -r requirements_deepcell.txt
# pip install --upgrade -r requirements_deepcell-gpu.txt
pip install --no-deps deepcell==0.12.2
pip install --no-deps deepcell==0.12.3
pip install --upgrade -r requirements.txt
pip install --no-deps "steinbock[all]"

Expand Down
239 changes: 239 additions & 0 deletions examples/01_preprocessing_if.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,239 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "4544b34e",
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"import pandas as pd\n",
"import tifffile\n",
"import xtiff\n",
"\n",
"from pathlib import Path\n",
"\n",
"from steinbock import io\n",
"from steinbock.preprocessing import external\n",
"\n",
"import helpers"
]
},
{
"cell_type": "markdown",
"id": "7b752cfb",
"metadata": {},
"source": [
"# Multiplex images preprocessing pipeline\n",
"\n",
"This pipeline will run image segmentation within the steinbock workframe. It can be applied to any multiplex image stacks. The full pipeline consists of three separate notebooks that have to be run successively: `preprocessing` (current notebook), `segmentation`, and `measurement`.\n",
"\n",
"Before running your own script please check the [steinbock documentation](https://bodenmillergroup.github.io/steinbock).\n",
"\n",
"*Installation* \n",
"To install the required python environment, follow the instructions here: https://bodenmillergroup.github.io/steinbock/latest/install-python/"
]
},
{
"cell_type": "markdown",
"id": "83d9d1e0",
"metadata": {},
"source": [
"## Settings\n",
"\n",
"Example data can be downloaded using the `download_examples.ipynb` script.\n",
"\n",
"### Input and output directories\n",
"Edit the working directory if needed (by default, the `examples` folder).\n",
"\n",
"Folder structure:"
]
},
{
"cell_type": "raw",
"id": "4e2d0ccd",
"metadata": {},
"source": [
"steinbock data/working directory \n",
"├── panel.csv (user-provided) \n",
"├── raw (*.tiff stacks, user-provided)\n",
"├── img (*.tiff image stacks, user-provided or generated from stacks in \"raw\")\n",
"├── masks (created by this script) \n",
"├── intensities (created by this script) \n",
"├── regionprops (created by this script) \n",
"└── neighbors (created by this script) "
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "09658e6a",
"metadata": {},
"outputs": [],
"source": [
"working_dir = Path(\".\")\n",
"\n",
"# Paths to zipped acquisition files\n",
"raw_dir = working_dir / \"raw\"\n",
"\n",
"# Output directories\n",
"img_dir = working_dir / \"img\"\n",
"\n",
"# Create directories (if they do not already exist)\n",
"raw_dir.mkdir(exist_ok=True)\n",
"img_dir.mkdir(exist_ok=True)"
]
},
{
"cell_type": "markdown",
"id": "8e98844b",
"metadata": {},
"source": [
"## Antibody panel\n",
"\n",
"### Import the panel\n",
"The antibody panel should meet the steinbock format: https://bodenmillergroup.github.io/steinbock/latest/file-types/#panel \n",
"\n",
"Customized panels should contain the following columns:\n",
"+ `channel`: unique channel id, typically metal and isotope mass (e.g. `Ir191`) or fluorophore.\n",
"+ `name`: unique channel name.\n",
"+ `deepcell`: channels to use for segmentation (1=nuclear, 2=membrane, empty/NaN=ignored).\n",
"+ `keep`: *(optional)* 1 for channels to preprocess, 0 for channels to ignore"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "964e4be4",
"metadata": {},
"outputs": [],
"source": [
"panel_file = working_dir / \"panel.csv\""
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f7fe4ff7",
"metadata": {},
"outputs": [],
"source": [
"panel = io.read_panel(panel_file)\n",
"nb_of_channels = len(panel)\n",
"panel.head()"
]
},
{
"cell_type": "markdown",
"id": "1f625996",
"metadata": {},
"source": [
"## Re-shape `.tiff` stacks\n",
"\n",
"The multichannel image stacks provided by the user in the `raw` folder is reshaped as \"CYX\" (channel, height, width). Other dimensions are ignored: for a time series for instance, please provide one stack per time point.\n",
"\n",
"Alternately, the user can provide single-channel `tiff` files that will be converted to multichannel stacks. For this, the `generate_from_single_tiffs` variable has to be set to `True` and all images belonging to the same stack should start with the same prefix.\n",
"\n",
"If the `raw` folder is empty, it is assumed that properly shaped stacks are directly provided by the user in the `img` folder."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "127cabad",
"metadata": {},
"outputs": [],
"source": [
"generate_from_single_tiffs = True\n",
"\n",
"raw_tiffs = sorted(Path(raw_dir).glob(\"*.tiff\"))"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d0b7852e",
"metadata": {},
"outputs": [],
"source": [
"if raw_tiffs and generate_from_single_tiffs:\n",
" from itertools import cycle\n",
" from os.path import commonprefix\n",
" \n",
" for i, j in zip(range(len(raw_tiffs)),\n",
" cycle(range(nb_of_channels))):\n",
" cur_img = tifffile.imread(raw_tiffs[i])\n",
" cur_img = np.expand_dims(cur_img, axis=0)\n",
" \n",
" if (j == 0):\n",
" img = cur_img\n",
" img_names = []\n",
" else:\n",
" img = np.concatenate((img, cur_img), axis = 0)\n",
" \n",
" img_names.append(raw_tiffs[i].name)\n",
" \n",
" if (j == (nb_of_channels-1)):\n",
" img_file = img_dir / (commonprefix(img_names) + \".tiff\")\n",
" tifffile.imwrite(img_file, img,\n",
" photometric='minisblack',\n",
" metadata={'axes': 'CYX'}) "
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "1ebc673c",
"metadata": {},
"outputs": [],
"source": [
"if raw_tiffs and not generate_from_single_tiffs:\n",
" for raw_tiff in raw_tiffs:\n",
" with tifffile.TiffFile(raw_tiff) as tif:\n",
" volume = tif.asarray()\n",
" axes = tif.series[0].axes\n",
" imagej_metadata = tif.imagej_metadata\n",
" \n",
" img_file = img_dir / raw_tiff.name\n",
" tifffile.imwrite(img_file, volume,\n",
" photometric='minisblack',\n",
" metadata={'axes': 'CYX'}) "
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "7788a1af",
"metadata": {},
"outputs": [],
"source": [
"!conda list"
]
}
],
"metadata": {
"jupytext": {
"formats": "ipynb,py:percent"
},
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.15"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Loading