Skip to content

Commit 91cad90

Browse files
authored
Add OME-Arrow demonstration notebook (#210)
* show simple demo of ome-arrow with cytodataframe * remove colab widgets for rendering * Update omearrow_and_cytodataframe.ipynb * linting and include with docs
1 parent 00c5943 commit 91cad90

5 files changed

Lines changed: 326 additions & 7 deletions

File tree

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ repos:
1515
- id: check-yaml
1616
- id: detect-private-key
1717
- repo: https://github.com/tox-dev/pyproject-fmt
18-
rev: "v2.21.0"
18+
rev: "v2.21.1"
1919
hooks:
2020
- id: pyproject-fmt
2121
- repo: https://github.com/codespell-project/codespell
@@ -50,7 +50,7 @@ repos:
5050
hooks:
5151
- id: actionlint
5252
- repo: https://github.com/astral-sh/ruff-pre-commit
53-
rev: "v0.15.8"
53+
rev: "v0.15.10"
5454
hooks:
5555
- id: ruff-format
5656
- id: ruff-check

docs/src/examples.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Examples
22

3+
Featured example:
4+
[OME Arrow and CytoDataFrame](examples/omearrow_and_cytodataframe)
5+
36
```{toctree}
47
---
58
caption: "List of examples"

docs/src/examples/omearrow_and_cytodataframe.ipynb

Lines changed: 258 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# ---
2+
# jupyter:
3+
# jupytext:
4+
# text_representation:
5+
# extension: .py
6+
# format_name: light
7+
# format_version: '1.5'
8+
# jupytext_version: 1.17.3
9+
# kernelspec:
10+
# display_name: cytodataframe-shAZamSV-py3.12
11+
# language: python
12+
# name: python3
13+
# ---
14+
15+
# # OME-Arrow and CytoDataFrame
16+
#
17+
# This notebook demonstrates how [OME-Arrow](https://github.com/WayScience/ome-arrow) works in context with CytoDataFrame.
18+
19+
# + colab={"base_uri": "https://localhost:8080/", "height": 423} id="Y5e85t05nSLt" outputId="a0807c7c-4705-41a2-83b2-9fb7287c40f9"
20+
import pyarrow as pa
21+
import pyarrow.parquet as pq
22+
from ome_arrow import OMEArrow
23+
24+
from cytodataframe import CytoDataFrame
25+
26+
# load a tiff using OME Arrow
27+
oa_img = OMEArrow(
28+
"../../../tests/data/cytotable/JUMP_plate_BR00117006/images/orig/r01c01f01p01-ch2sk1fk1fl1.tiff"
29+
)
30+
oa_img
31+
32+
# + colab={"base_uri": "https://localhost:8080/", "height": 423} id="wkCpuZEBosNV" outputId="4adee883-9707-40a4-92ab-2ee748bbcf76"
33+
# make a "slice" (crop) from the overall image
34+
oa_img_slice = oa_img.slice(x_min=240, x_max=310, y_min=360, y_max=430)
35+
oa_img_slice
36+
37+
# + colab={"base_uri": "https://localhost:8080/"} id="ZZ8LWIuQqQqz" outputId="f82de1df-3240-4dba-d0a0-6a4ce973f299"
38+
# show the OME Arrow struct
39+
oa_img_slice.data
40+
41+
# + colab={"base_uri": "https://localhost:8080/", "height": 1000} id="zcaDHeNorxCt" outputId="e64c061b-c56e-462b-dfe0-c73de76df0d3"
42+
# create a pyarrow table for writing the data
43+
table = pa.table(
44+
{
45+
# two columns, two values each, both int64 type
46+
"metadata_1": pa.array([0, 2], type=pa.int64()),
47+
"feature_1": pa.array([1, 2], type=pa.int64()),
48+
# add an image column with repeated entries based on the image slice
49+
"image": pa.repeat(oa_img_slice.data, 2),
50+
}
51+
)
52+
53+
# write a parquet table
54+
pq.write_table(table, "example.ome.parquet")
55+
56+
# read the parquet table with cytodataframe
57+
# (showing the OME-Arrow image that was written)
58+
CytoDataFrame("example.ome.parquet")

pyproject.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,16 @@ lint.select = [
110110
]
111111
# Ignore `E402` and `F401` (unused imports) in all `__init__.py` files
112112
lint.per-file-ignores."__init__.py" = [ "E402", "F401" ]
113-
lint.per-file-ignores."docs/src/examples/cytodataframe_at_a_glance.py" = [ "E402" ]
113+
lint.per-file-ignores."docs/src/examples/*.py" = [ "E402", "E501" ]
114114
lint.per-file-ignores."src/cytodataframe/*.py" = [ "ANN401", "PLC0415" ]
115115
lint.per-file-ignores."src/cytodataframe/image.py" = [ "PLR2004" ]
116116
# ignore typing rules for tests
117117
lint.per-file-ignores."tests/*" = [ "ANN201", "PLR0913", "PLR2004", "SIM105" ]
118118

119+
# specify where version replacement is performed
120+
[tool.bandit]
121+
exclude_dirs = [ "tests" ]
122+
119123
[tool.pytest]
120124
ini_options.addopts = "--cov=src/cytodataframe --cov-report=term-missing:skip-covered --no-cov-on-fail"
121125

@@ -130,10 +134,6 @@ run.omit = [
130134
[tool.jupytext]
131135
formats = "ipynb,py:light"
132136

133-
# specify where version replacement is performed
134-
[tool.bandit]
135-
exclude_dirs = [ "tests" ]
136-
137137
[tool.poe]
138138
# note: quarto commands below expect quarto installed on the local system.
139139
# see here for more information: https://quarto.org/docs/download/

0 commit comments

Comments
 (0)