|
| 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") |
0 commit comments