|
12 | 12 | # name: python3 |
13 | 13 | # --- |
14 | 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 | + |
15 | 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 |
16 | 22 | from ome_arrow import OMEArrow |
17 | 23 |
|
| 24 | +from cytodataframe import CytoDataFrame |
| 25 | + |
18 | 26 | # load a tiff using OME Arrow |
19 | | -oa_img = OMEArrow("../../../tests/data/cytotable/JUMP_plate_BR00117006/images/orig/r01c01f01p01-ch2sk1fk1fl1.tiff") |
| 27 | +oa_img = OMEArrow( |
| 28 | + "../../../tests/data/cytotable/JUMP_plate_BR00117006/images/orig/r01c01f01p01-ch2sk1fk1fl1.tiff" |
| 29 | +) |
20 | 30 | oa_img |
21 | 31 |
|
22 | 32 | # + colab={"base_uri": "https://localhost:8080/", "height": 423} id="wkCpuZEBosNV" outputId="4adee883-9707-40a4-92ab-2ee748bbcf76" |
23 | | -# make a slice from the overall image |
24 | | -oa_img_slice = oa_img.slice(x_min=240,x_max=310,y_min=360,y_max=430) |
| 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) |
25 | 35 | oa_img_slice |
26 | 36 |
|
27 | 37 | # + colab={"base_uri": "https://localhost:8080/"} id="ZZ8LWIuQqQqz" outputId="f82de1df-3240-4dba-d0a0-6a4ce973f299" |
28 | 38 | # show the OME Arrow struct |
29 | 39 | oa_img_slice.data |
30 | 40 |
|
31 | 41 | # + colab={"base_uri": "https://localhost:8080/", "height": 1000} id="zcaDHeNorxCt" outputId="e64c061b-c56e-462b-dfe0-c73de76df0d3" |
32 | | -import pyarrow as pa |
33 | | -import pyarrow.parquet as pq |
34 | | -from cytodataframe import CytoDataFrame |
35 | | - |
36 | 42 | # create a pyarrow table for writing the data |
37 | | -table = pa.table({ |
38 | | - "metadata_1": pa.array([0, 2], type=pa.int64()), |
39 | | - "feature_1": pa.array([1, 2], type=pa.int64()), |
40 | | - # add an image column with repeated entries based on the image slice |
41 | | - "image": pa.repeat(oa_img_slice.data, 2), |
42 | | -}) |
| 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 | +) |
43 | 52 |
|
44 | 53 | # write a parquet table |
45 | 54 | pq.write_table(table, "example.ome.parquet") |
46 | 55 |
|
47 | 56 | # read the parquet table with cytodataframe |
| 57 | +# (showing the OME-Arrow image that was written) |
48 | 58 | CytoDataFrame("example.ome.parquet") |
0 commit comments