twhy 0.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (83) hide show
  1. twhy-0.2.0/LICENSE +201 -0
  2. twhy-0.2.0/MANIFEST.in +4 -0
  3. twhy-0.2.0/PKG-INFO +228 -0
  4. twhy-0.2.0/README.md +197 -0
  5. twhy-0.2.0/docs/architecture.md +507 -0
  6. twhy-0.2.0/docs/reference.md +1123 -0
  7. twhy-0.2.0/docs/validation.md +1008 -0
  8. twhy-0.2.0/environment.yml +6 -0
  9. twhy-0.2.0/examples/make_demo.py +96 -0
  10. twhy-0.2.0/pyproject.toml +61 -0
  11. twhy-0.2.0/setup.cfg +4 -0
  12. twhy-0.2.0/src/twhy/__init__.py +20 -0
  13. twhy-0.2.0/src/twhy/__main__.py +4 -0
  14. twhy-0.2.0/src/twhy/_validation.py +23 -0
  15. twhy-0.2.0/src/twhy/_version.py +18 -0
  16. twhy-0.2.0/src/twhy/annotation_identity.py +48 -0
  17. twhy-0.2.0/src/twhy/channel_colors.py +71 -0
  18. twhy-0.2.0/src/twhy/cli.py +325 -0
  19. twhy-0.2.0/src/twhy/compositing.py +65 -0
  20. twhy-0.2.0/src/twhy/geojson_clip.py +127 -0
  21. twhy-0.2.0/src/twhy/glyph_atlas.py +148 -0
  22. twhy-0.2.0/src/twhy/image_clip.py +124 -0
  23. twhy-0.2.0/src/twhy/image_document.py +145 -0
  24. twhy-0.2.0/src/twhy/image_input.py +310 -0
  25. twhy-0.2.0/src/twhy/image_pyramid.py +58 -0
  26. twhy-0.2.0/src/twhy/intensity_window.py +81 -0
  27. twhy-0.2.0/src/twhy/pdf_text.py +63 -0
  28. twhy-0.2.0/src/twhy/pdf_workers.py +152 -0
  29. twhy-0.2.0/src/twhy/png_clip.py +135 -0
  30. twhy-0.2.0/src/twhy/py.typed +0 -0
  31. twhy-0.2.0/src/twhy/resampling.py +75 -0
  32. twhy-0.2.0/src/twhy/runtime_overview.py +256 -0
  33. twhy-0.2.0/src/twhy/sampled_overview.py +122 -0
  34. twhy-0.2.0/src/twhy/selection_geometry.py +127 -0
  35. twhy-0.2.0/src/twhy/source_input.py +206 -0
  36. twhy-0.2.0/src/twhy/startup_overview.py +49 -0
  37. twhy-0.2.0/src/twhy/structured_rendering.py +141 -0
  38. twhy-0.2.0/src/twhy/terminal_capabilities.py +58 -0
  39. twhy-0.2.0/src/twhy/text_clip.py +124 -0
  40. twhy-0.2.0/src/twhy/text_image.py +141 -0
  41. twhy-0.2.0/src/twhy/text_renderer.py +124 -0
  42. twhy-0.2.0/src/twhy/view_info.py +68 -0
  43. twhy-0.2.0/src/twhy/view_session.py +462 -0
  44. twhy-0.2.0/src/twhy/viewer/__init__.py +6 -0
  45. twhy-0.2.0/src/twhy/viewer/bindings.py +296 -0
  46. twhy-0.2.0/src/twhy/viewer/clipping.py +488 -0
  47. twhy-0.2.0/src/twhy/viewer/controls.py +272 -0
  48. twhy-0.2.0/src/twhy/viewer/file_viewer.py +117 -0
  49. twhy-0.2.0/src/twhy/viewer/mode_navigation.py +109 -0
  50. twhy-0.2.0/src/twhy/viewer/navigation.py +404 -0
  51. twhy-0.2.0/src/twhy/viewer/rendering.py +69 -0
  52. twhy-0.2.0/src/twhy/viewer/selection.py +266 -0
  53. twhy-0.2.0/src/twhy/viewer/selection_set.py +189 -0
  54. twhy-0.2.0/src/twhy/viewer/viewer.py +800 -0
  55. twhy-0.2.0/src/twhy/viewport.py +79 -0
  56. twhy-0.2.0/src/twhy.egg-info/PKG-INFO +228 -0
  57. twhy-0.2.0/src/twhy.egg-info/SOURCES.txt +81 -0
  58. twhy-0.2.0/src/twhy.egg-info/dependency_links.txt +1 -0
  59. twhy-0.2.0/src/twhy.egg-info/entry_points.txt +2 -0
  60. twhy-0.2.0/src/twhy.egg-info/requires.txt +22 -0
  61. twhy-0.2.0/src/twhy.egg-info/top_level.txt +1 -0
  62. twhy-0.2.0/tests/conftest.py +76 -0
  63. twhy-0.2.0/tests/test_channel_colors.py +466 -0
  64. twhy-0.2.0/tests/test_cli.py +144 -0
  65. twhy-0.2.0/tests/test_clipping.py +837 -0
  66. twhy-0.2.0/tests/test_document_navigation.py +598 -0
  67. twhy-0.2.0/tests/test_geojson_clip.py +135 -0
  68. twhy-0.2.0/tests/test_image_input.py +446 -0
  69. twhy-0.2.0/tests/test_legacy_rendering.py +33 -0
  70. twhy-0.2.0/tests/test_mode_navigation.py +531 -0
  71. twhy-0.2.0/tests/test_multiselection.py +510 -0
  72. twhy-0.2.0/tests/test_packaging.py +60 -0
  73. twhy-0.2.0/tests/test_pty.py +312 -0
  74. twhy-0.2.0/tests/test_remote_input.py +233 -0
  75. twhy-0.2.0/tests/test_rendering.py +218 -0
  76. twhy-0.2.0/tests/test_runtime_overview.py +573 -0
  77. twhy-0.2.0/tests/test_sampled_overview.py +267 -0
  78. twhy-0.2.0/tests/test_source_session.py +230 -0
  79. twhy-0.2.0/tests/test_startup_overview.py +410 -0
  80. twhy-0.2.0/tests/test_structured_rendering.py +235 -0
  81. twhy-0.2.0/tests/test_svs.py +195 -0
  82. twhy-0.2.0/tests/test_terminal_capabilities.py +103 -0
  83. twhy-0.2.0/tests/test_viewer.py +422 -0
twhy-0.2.0/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
twhy-0.2.0/MANIFEST.in ADDED
@@ -0,0 +1,4 @@
1
+ include environment.yml
2
+ recursive-include docs *.md
3
+ recursive-include examples *.py
4
+ recursive-include tests *.py
twhy-0.2.0/PKG-INFO ADDED
@@ -0,0 +1,228 @@
1
+ Metadata-Version: 2.4
2
+ Name: twhy
3
+ Version: 0.2.0
4
+ Summary: Zoomable microscopy, image and PDF previews in a text terminal
5
+ Author: Jason L Weirather
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Repository, https://github.com/jason-weirather/twhy
8
+ Project-URL: Issues, https://github.com/jason-weirather/twhy/issues
9
+ Requires-Python: >=3.11
10
+ Description-Content-Type: text/markdown
11
+ License-File: LICENSE
12
+ Requires-Dist: click<9,>=8.1
13
+ Requires-Dist: coolname<6,>=2.2
14
+ Requires-Dist: numpy<3,>=1.26.4
15
+ Requires-Dist: scipy<2,>=1.14
16
+ Requires-Dist: omeify>=0.22.1
17
+ Requires-Dist: pillow<13,>=11.3
18
+ Requires-Dist: pypdfium2<6,>=4.30
19
+ Requires-Dist: prompt-toolkit<4,>=3.0.52
20
+ Requires-Dist: wcwidth>=0.2.13
21
+ Provides-Extra: s3
22
+ Requires-Dist: omeify[s3]>=0.22.1; extra == "s3"
23
+ Provides-Extra: dev
24
+ Requires-Dist: pytest<10,>=8; extra == "dev"
25
+ Requires-Dist: pytest-asyncio>=0.24; extra == "dev"
26
+ Requires-Dist: pytest-cov>=5; extra == "dev"
27
+ Requires-Dist: pexpect>=4.9; sys_platform != "win32" and extra == "dev"
28
+ Requires-Dist: ruff>=0.12; extra == "dev"
29
+ Requires-Dist: build>=1.2; extra == "dev"
30
+ Dynamic: license-file
31
+
32
+ # twhy
33
+
34
+ **Whole-slide microscopy, ordinary images, and scientific PDFs, right in your terminal.**
35
+
36
+ `twhy` is a zoomable, full-screen image viewer made of *actual terminal characters*. Open an OME-TIFF, SVS, or OME-Zarr slide, explore multichannel fluorescence, inspect a PNG, or page through a PDF. No browser, image server, X11, graphics protocol, or GPU required.
37
+
38
+ I had a use case for this on a remote cluster with thousands of images. Sometimes
39
+ I just needed the tissue's shape, a rough count of regions of interest, or to tell
40
+ a big chunk of tissue from a few tiny core needle biopsies. An ASCII-art
41
+ representation of a preview from the image pyramid seemed like it would do the job.
42
+
43
+ Then working in tmux, switching the active area of the terminal with either the
44
+ mouse or keyboard, got me wondering... just how far can we push a text-based image
45
+ viewer? And thus began `twhy`. I've been having a little fun with AI slop along
46
+ the way, and now it opens PDFs and lets me draw polygons on pathology images.
47
+ It's ridiculous, but I'm actually going to use it.
48
+
49
+ <p align="center">
50
+ <a href="https://github.com/jason-weirather/twhy/blob/main/docs/media/pathology.gif"><img src="https://raw.githubusercontent.com/jason-weirather/twhy/main/docs/media/pathology.gif" width="900" alt="Real recording of twhy zooming through multiplex immunofluorescence and revealing CD8 signal in cyan on blue DAPI nuclei"></a>
51
+ </p>
52
+ <p align="center"><em>Real terminal footage: 59-channel multiplex microscopy, DAPI and CD8. Channel selection and zoom, no mock interface.</em></p>
53
+
54
+ ## See it in action
55
+
56
+ These are short, automatically looping recordings of `twhy` itself. Click any clip to view it at full GIF size.
57
+
58
+ <table>
59
+ <tr>
60
+ <td width="50%" valign="top">
61
+ <strong>Whole-slide H&amp;E SVS</strong><br>
62
+ <a href="https://github.com/jason-weirather/twhy/blob/main/docs/media/he.gif"><img src="https://raw.githubusercontent.com/jason-weirather/twhy/main/docs/media/he.gif" width="440" alt="twhy zooming from an SVS whole-slide tissue overview to individual nuclei in a real H&E image"></a><br>
63
+ <small>Zoom from whole-slide tissue context into individual nuclei.</small>
64
+ </td>
65
+ <td width="50%" valign="top">
66
+ <strong>An ordinary PNG. Featuring a cat.</strong><br>
67
+ <a href="https://github.com/jason-weirather/twhy/blob/main/docs/media/cat.gif"><img src="https://raw.githubusercontent.com/jason-weirather/twhy/main/docs/media/cat.gif" width="440" alt="twhy zooming into an orange-and-white cat in a sunlit windowsill illustration"></a><br>
68
+ <small>PNG, JPEG, WebP: zoom and pan familiar images, too.</small>
69
+ </td>
70
+ </tr>
71
+ <tr>
72
+ <td width="50%" valign="top">
73
+ <strong>A scientific PDF</strong><br>
74
+ <a href="https://github.com/jason-weirather/twhy/blob/main/docs/media/pdf.gif"><img src="https://raw.githubusercontent.com/jason-weirather/twhy/main/docs/media/pdf.gif" width="440" alt="twhy switching pages in a scientific PDF and zooming into a transformer architecture diagram"></a><br>
75
+ <small>Turn pages, then zoom into figures. PDF support is standard.</small>
76
+ </td>
77
+ <td width="50%" valign="top">
78
+ <strong>Polygon selections</strong><br>
79
+ <a href="https://github.com/jason-weirather/twhy/blob/main/docs/media/selection.gif"><img src="https://raw.githubusercontent.com/jason-weirather/twhy/main/docs/media/selection.gif" width="440" alt="twhy drawing a yellow polygon selection around a tissue core and preparing it for GeoJSON export"></a><br>
80
+ <small>Select rectangles or polygons; export GeoJSON, text, ANSI art, or PNG.</small>
81
+ </td>
82
+ </tr>
83
+ </table>
84
+
85
+ ## Install
86
+
87
+ Python **3.11+**. The **PyPI distribution**, terminal command, and Python import all share the name `twhy`.
88
+
89
+ Install the standalone command without changing packages in a scientific Python environment:
90
+
91
+ ```bash
92
+ uv tool install twhy
93
+ # or: pipx install twhy
94
+ # or: python -m pip install twhy
95
+ ```
96
+
97
+ From a cloned checkout, for development:
98
+
99
+ ```bash
100
+ python -m pip install -e '.[dev]'
101
+ ```
102
+
103
+ PDF support is **included** in the standard install. No special extra or system PDF converter is needed.
104
+
105
+ ## Quickstart
106
+
107
+ ```bash
108
+ twhy photo.png # PNG, JPEG, WebP, and more
109
+ twhy paper.pdf # page navigation and progressive detail
110
+ twhy slide.svs # Aperio whole-slide RGB
111
+ twhy slide.ome.tif # OME-TIFF, grayscale or multichannel
112
+ twhy /data/sample.ome.zarr # local OME-Zarr
113
+
114
+ # Compose two fluorescence channels with chosen colors:
115
+ twhy slide.ome.tif --channel 0 --channel 2 \
116
+ --channel-color 0 blue --channel-color 2 cyan
117
+ ```
118
+
119
+ The initial view fits the image. Wheel zoom is anchored to the pointer; pan with the mouse or arrow keys. The terminal sidebar keeps channels, colors, and contrast controls at hand.
120
+
121
+ ## Why a terminal viewer?
122
+
123
+ - **Whole-slide without whole-slide RAM use:** regional TIFF/SVS reads and pyramids, with bounded previews and useful zoomed-out overviews.
124
+ - **Multichannel, not just RGB:** select channels, change pseudocolors, and adjust each marker's display window and gamma without modifying source pixels.
125
+ - **PDFs and everyday images:** ordinary images use in-memory pyramids; PDFs refine progressively from a quick preview to higher-detail pages.
126
+ - **Real characters:** colored `▀` half-blocks, Braille detail, shape-oriented Unicode art, and portable ASCII modes.
127
+ - **Selection and export:** copy/save terminal text, colored ANSI, shareable PNGs, and GeoJSON polygons/rectangles.
128
+ - **Reusable Python library:** sampling, intensity normalization, composition, and rendering are available without opening the interactive terminal UI.
129
+
130
+ `twhy` works over ordinary terminal sessions, including environments where a desktop image viewer is inconvenient. It is an exploratory display, **not a color-managed diagnostic viewer** and not a substitute for measuring the original pixels.
131
+
132
+ ## The keys you'll actually use
133
+
134
+ | Action | Key or gesture |
135
+ |---|---|
136
+ | Zoom; pan; fit image | Wheel or `+`/`-`; arrows or drag; `r`/Home |
137
+ | Next/previous PDF page or OME series | `]` / `[` or PageDown / PageUp; `p` to jump |
138
+ | Toggle a channel; focus another | Click channel/Space; `,` and `.` |
139
+ | Adjust channel color or contrast | `h` (hue); `l`/`u` (limits); `g` (gamma); `a` (auto window) |
140
+ | Switch artwork / strict ASCII | `m` / `M`; `t` toggles artwork color; `f` toggles fullscreen |
141
+ | Select region | `s` rectangle; `v` polygon |
142
+ | Export a selection | `y/Y` text, `i/I` PNG, `t/T` ANSI, `j/J` GeoJSON (copy/save) |
143
+ | Help or quit | `?` / `q` |
144
+
145
+ ## From terminal annotations to full-resolution ROIs
146
+
147
+ The useful part of the joke: draw regions in `twhy`, save their coordinates as
148
+ GeoJSON, and let [Omeify](https://github.com/jason-weirather/omeify) extract them
149
+ from the original image. This example uses a calibrated OME-TIFF, series 0.
150
+ You also need the `omeify` command on your PATH; with isolated tool installs,
151
+ install it separately using `uv tool install omeify`.
152
+
153
+ ```bash
154
+ # Open the source and choose where to save the annotations.
155
+ twhy slide.ome.tif --series 0 --output-geojson-clip regions.geojson
156
+ ```
157
+
158
+ Zoom to the view you need, then press **`s`** for a rectangle or **`v`** for a
159
+ polygon and draw. Close a polygon with **Enter**; **`a`** adds another region in
160
+ the same view. Press **Shift+J** to save all the regions before quitting.
161
+
162
+ ```bash
163
+ # Export one full-resolution image per region, with lossless compression.
164
+ omeify crop slide.ome.tif --series 0 \
165
+ --geojson regions.geojson -o regions.ome.tif \
166
+ --shatter by_index --compression Deflate --no-overwrite
167
+ ```
168
+
169
+ This writes `regions-01.ome.tif`, `regions-02.ome.tif`, and so on, retaining all
170
+ channels from the selected series. Omit `--shatter by_index` to put the regions
171
+ into separate image series in one OME-TIFF instead.
172
+
173
+ **Full-resolution pixels, not a screenshot:** Omeify reads the original image,
174
+ not the terminal preview. Polygon crops use their **bounding rectangles**, not
175
+ polygon masks; keep the GeoJSON for the outlines. Use the same source image,
176
+ series, and orientation in both steps. Annotation placement follows the terminal
177
+ grid, so zoom in before drawing for finer boundaries.
178
+ [More crop options](https://github.com/jason-weirather/omeify/blob/main/docs/regions.md).
179
+
180
+ ## Supported files
181
+
182
+ | Format | What twhy does |
183
+ |---|---|
184
+ | OME-TIFF | Regional, pyramidal microscopy viewing and channel composition |
185
+ | Aperio SVS | RGB whole-slide viewing using available stored levels |
186
+ | OME-Zarr | Local and HTTP(S) stores, regional chunk reads, supported NGFF multiscales |
187
+ | PNG, JPEG, WebP, BMP, TGA, PPM | Ordinary raster viewing with zoom and pan |
188
+ | GIF, APNG, animated WebP | View a selected frame (not animation playback) |
189
+ | PDF | Navigate pages; progressively improve raster detail; copy embedded text from a rectangular selection |
190
+
191
+ For advanced flags, channel/series semantics, color modes, cache limits, clipboard behavior, and format caveats, use the **[full reference](https://github.com/jason-weirather/twhy/blob/main/docs/reference.md)**. Architecture notes are in [docs/architecture.md](https://github.com/jason-weirather/twhy/blob/main/docs/architecture.md).
192
+
193
+ ## Try a synthetic microscopy example
194
+
195
+ The repo includes a deterministic fixture generator that creates public-safe, synthetic tissue-like RGB and multichannel OME-TIFFs. It is a renderer demonstration, not a biological simulation.
196
+
197
+ ```bash
198
+ python examples/make_demo.py --output-directory /tmp/twhy-demo
199
+ twhy /tmp/twhy-demo/synthetic-mif.ome.tif --channel 0 --channel 2
200
+ ```
201
+
202
+ ## Python API
203
+
204
+ ```python
205
+ import numpy as np
206
+ from twhy import TextRenderer
207
+
208
+ pixels = np.linspace(0, 1, 256**2).reshape(256, 256)
209
+ frame = TextRenderer(mode="detail", color=False).render(pixels, columns=80)
210
+ print(frame.to_text())
211
+ ```
212
+
213
+ ## Optional remote sources
214
+
215
+ Local files are the main workflow. `twhy` also supports HTTP(S) images/PDFs (bounded download) and HTTP(S) OME-Zarr (regional chunk reads). For native S3 or S3-compatible stores, install `twhy[s3]` and use your normal AWS credentials or an endpoint override. No S3 setup is needed for local images, slides, or PDFs. [Remote input reference](https://github.com/jason-weirather/twhy/blob/main/docs/reference.md#local-and-remote-inputs).
216
+
217
+ ## Release media and provenance
218
+
219
+ These GIFs are edited recordings of the real `twhy` terminal viewer. Showcase sources:
220
+
221
+ - **mIF:** Tan, Y. & Kempchen, T. (2024), [*SPACEc demo dataset*](https://doi.org/10.5061/dryad.brv15dvj1), Dryad.
222
+ - **H&E whole-slide demo:** `CMU-1.svs`, [OpenSlide test data](https://openslide.cs.cmu.edu/download/openslide-testdata/Aperio/), Carnegie Mellon University, CC0 1.0.
223
+ - **PDF:** Vaswani, A. et al. (2017), [*Attention Is All You Need*](https://arxiv.org/abs/1706.03762), NeurIPS.
224
+ - **Cat:** Illustration generated with ChatGPT (OpenAI).
225
+
226
+ ## License
227
+
228
+ Apache-2.0. See [LICENSE](https://github.com/jason-weirather/twhy/blob/main/LICENSE).
twhy-0.2.0/README.md ADDED
@@ -0,0 +1,197 @@
1
+ # twhy
2
+
3
+ **Whole-slide microscopy, ordinary images, and scientific PDFs, right in your terminal.**
4
+
5
+ `twhy` is a zoomable, full-screen image viewer made of *actual terminal characters*. Open an OME-TIFF, SVS, or OME-Zarr slide, explore multichannel fluorescence, inspect a PNG, or page through a PDF. No browser, image server, X11, graphics protocol, or GPU required.
6
+
7
+ I had a use case for this on a remote cluster with thousands of images. Sometimes
8
+ I just needed the tissue's shape, a rough count of regions of interest, or to tell
9
+ a big chunk of tissue from a few tiny core needle biopsies. An ASCII-art
10
+ representation of a preview from the image pyramid seemed like it would do the job.
11
+
12
+ Then working in tmux, switching the active area of the terminal with either the
13
+ mouse or keyboard, got me wondering... just how far can we push a text-based image
14
+ viewer? And thus began `twhy`. I've been having a little fun with AI slop along
15
+ the way, and now it opens PDFs and lets me draw polygons on pathology images.
16
+ It's ridiculous, but I'm actually going to use it.
17
+
18
+ <p align="center">
19
+ <a href="https://github.com/jason-weirather/twhy/blob/main/docs/media/pathology.gif"><img src="https://raw.githubusercontent.com/jason-weirather/twhy/main/docs/media/pathology.gif" width="900" alt="Real recording of twhy zooming through multiplex immunofluorescence and revealing CD8 signal in cyan on blue DAPI nuclei"></a>
20
+ </p>
21
+ <p align="center"><em>Real terminal footage: 59-channel multiplex microscopy, DAPI and CD8. Channel selection and zoom, no mock interface.</em></p>
22
+
23
+ ## See it in action
24
+
25
+ These are short, automatically looping recordings of `twhy` itself. Click any clip to view it at full GIF size.
26
+
27
+ <table>
28
+ <tr>
29
+ <td width="50%" valign="top">
30
+ <strong>Whole-slide H&amp;E SVS</strong><br>
31
+ <a href="https://github.com/jason-weirather/twhy/blob/main/docs/media/he.gif"><img src="https://raw.githubusercontent.com/jason-weirather/twhy/main/docs/media/he.gif" width="440" alt="twhy zooming from an SVS whole-slide tissue overview to individual nuclei in a real H&E image"></a><br>
32
+ <small>Zoom from whole-slide tissue context into individual nuclei.</small>
33
+ </td>
34
+ <td width="50%" valign="top">
35
+ <strong>An ordinary PNG. Featuring a cat.</strong><br>
36
+ <a href="https://github.com/jason-weirather/twhy/blob/main/docs/media/cat.gif"><img src="https://raw.githubusercontent.com/jason-weirather/twhy/main/docs/media/cat.gif" width="440" alt="twhy zooming into an orange-and-white cat in a sunlit windowsill illustration"></a><br>
37
+ <small>PNG, JPEG, WebP: zoom and pan familiar images, too.</small>
38
+ </td>
39
+ </tr>
40
+ <tr>
41
+ <td width="50%" valign="top">
42
+ <strong>A scientific PDF</strong><br>
43
+ <a href="https://github.com/jason-weirather/twhy/blob/main/docs/media/pdf.gif"><img src="https://raw.githubusercontent.com/jason-weirather/twhy/main/docs/media/pdf.gif" width="440" alt="twhy switching pages in a scientific PDF and zooming into a transformer architecture diagram"></a><br>
44
+ <small>Turn pages, then zoom into figures. PDF support is standard.</small>
45
+ </td>
46
+ <td width="50%" valign="top">
47
+ <strong>Polygon selections</strong><br>
48
+ <a href="https://github.com/jason-weirather/twhy/blob/main/docs/media/selection.gif"><img src="https://raw.githubusercontent.com/jason-weirather/twhy/main/docs/media/selection.gif" width="440" alt="twhy drawing a yellow polygon selection around a tissue core and preparing it for GeoJSON export"></a><br>
49
+ <small>Select rectangles or polygons; export GeoJSON, text, ANSI art, or PNG.</small>
50
+ </td>
51
+ </tr>
52
+ </table>
53
+
54
+ ## Install
55
+
56
+ Python **3.11+**. The **PyPI distribution**, terminal command, and Python import all share the name `twhy`.
57
+
58
+ Install the standalone command without changing packages in a scientific Python environment:
59
+
60
+ ```bash
61
+ uv tool install twhy
62
+ # or: pipx install twhy
63
+ # or: python -m pip install twhy
64
+ ```
65
+
66
+ From a cloned checkout, for development:
67
+
68
+ ```bash
69
+ python -m pip install -e '.[dev]'
70
+ ```
71
+
72
+ PDF support is **included** in the standard install. No special extra or system PDF converter is needed.
73
+
74
+ ## Quickstart
75
+
76
+ ```bash
77
+ twhy photo.png # PNG, JPEG, WebP, and more
78
+ twhy paper.pdf # page navigation and progressive detail
79
+ twhy slide.svs # Aperio whole-slide RGB
80
+ twhy slide.ome.tif # OME-TIFF, grayscale or multichannel
81
+ twhy /data/sample.ome.zarr # local OME-Zarr
82
+
83
+ # Compose two fluorescence channels with chosen colors:
84
+ twhy slide.ome.tif --channel 0 --channel 2 \
85
+ --channel-color 0 blue --channel-color 2 cyan
86
+ ```
87
+
88
+ The initial view fits the image. Wheel zoom is anchored to the pointer; pan with the mouse or arrow keys. The terminal sidebar keeps channels, colors, and contrast controls at hand.
89
+
90
+ ## Why a terminal viewer?
91
+
92
+ - **Whole-slide without whole-slide RAM use:** regional TIFF/SVS reads and pyramids, with bounded previews and useful zoomed-out overviews.
93
+ - **Multichannel, not just RGB:** select channels, change pseudocolors, and adjust each marker's display window and gamma without modifying source pixels.
94
+ - **PDFs and everyday images:** ordinary images use in-memory pyramids; PDFs refine progressively from a quick preview to higher-detail pages.
95
+ - **Real characters:** colored `▀` half-blocks, Braille detail, shape-oriented Unicode art, and portable ASCII modes.
96
+ - **Selection and export:** copy/save terminal text, colored ANSI, shareable PNGs, and GeoJSON polygons/rectangles.
97
+ - **Reusable Python library:** sampling, intensity normalization, composition, and rendering are available without opening the interactive terminal UI.
98
+
99
+ `twhy` works over ordinary terminal sessions, including environments where a desktop image viewer is inconvenient. It is an exploratory display, **not a color-managed diagnostic viewer** and not a substitute for measuring the original pixels.
100
+
101
+ ## The keys you'll actually use
102
+
103
+ | Action | Key or gesture |
104
+ |---|---|
105
+ | Zoom; pan; fit image | Wheel or `+`/`-`; arrows or drag; `r`/Home |
106
+ | Next/previous PDF page or OME series | `]` / `[` or PageDown / PageUp; `p` to jump |
107
+ | Toggle a channel; focus another | Click channel/Space; `,` and `.` |
108
+ | Adjust channel color or contrast | `h` (hue); `l`/`u` (limits); `g` (gamma); `a` (auto window) |
109
+ | Switch artwork / strict ASCII | `m` / `M`; `t` toggles artwork color; `f` toggles fullscreen |
110
+ | Select region | `s` rectangle; `v` polygon |
111
+ | Export a selection | `y/Y` text, `i/I` PNG, `t/T` ANSI, `j/J` GeoJSON (copy/save) |
112
+ | Help or quit | `?` / `q` |
113
+
114
+ ## From terminal annotations to full-resolution ROIs
115
+
116
+ The useful part of the joke: draw regions in `twhy`, save their coordinates as
117
+ GeoJSON, and let [Omeify](https://github.com/jason-weirather/omeify) extract them
118
+ from the original image. This example uses a calibrated OME-TIFF, series 0.
119
+ You also need the `omeify` command on your PATH; with isolated tool installs,
120
+ install it separately using `uv tool install omeify`.
121
+
122
+ ```bash
123
+ # Open the source and choose where to save the annotations.
124
+ twhy slide.ome.tif --series 0 --output-geojson-clip regions.geojson
125
+ ```
126
+
127
+ Zoom to the view you need, then press **`s`** for a rectangle or **`v`** for a
128
+ polygon and draw. Close a polygon with **Enter**; **`a`** adds another region in
129
+ the same view. Press **Shift+J** to save all the regions before quitting.
130
+
131
+ ```bash
132
+ # Export one full-resolution image per region, with lossless compression.
133
+ omeify crop slide.ome.tif --series 0 \
134
+ --geojson regions.geojson -o regions.ome.tif \
135
+ --shatter by_index --compression Deflate --no-overwrite
136
+ ```
137
+
138
+ This writes `regions-01.ome.tif`, `regions-02.ome.tif`, and so on, retaining all
139
+ channels from the selected series. Omit `--shatter by_index` to put the regions
140
+ into separate image series in one OME-TIFF instead.
141
+
142
+ **Full-resolution pixels, not a screenshot:** Omeify reads the original image,
143
+ not the terminal preview. Polygon crops use their **bounding rectangles**, not
144
+ polygon masks; keep the GeoJSON for the outlines. Use the same source image,
145
+ series, and orientation in both steps. Annotation placement follows the terminal
146
+ grid, so zoom in before drawing for finer boundaries.
147
+ [More crop options](https://github.com/jason-weirather/omeify/blob/main/docs/regions.md).
148
+
149
+ ## Supported files
150
+
151
+ | Format | What twhy does |
152
+ |---|---|
153
+ | OME-TIFF | Regional, pyramidal microscopy viewing and channel composition |
154
+ | Aperio SVS | RGB whole-slide viewing using available stored levels |
155
+ | OME-Zarr | Local and HTTP(S) stores, regional chunk reads, supported NGFF multiscales |
156
+ | PNG, JPEG, WebP, BMP, TGA, PPM | Ordinary raster viewing with zoom and pan |
157
+ | GIF, APNG, animated WebP | View a selected frame (not animation playback) |
158
+ | PDF | Navigate pages; progressively improve raster detail; copy embedded text from a rectangular selection |
159
+
160
+ For advanced flags, channel/series semantics, color modes, cache limits, clipboard behavior, and format caveats, use the **[full reference](https://github.com/jason-weirather/twhy/blob/main/docs/reference.md)**. Architecture notes are in [docs/architecture.md](https://github.com/jason-weirather/twhy/blob/main/docs/architecture.md).
161
+
162
+ ## Try a synthetic microscopy example
163
+
164
+ The repo includes a deterministic fixture generator that creates public-safe, synthetic tissue-like RGB and multichannel OME-TIFFs. It is a renderer demonstration, not a biological simulation.
165
+
166
+ ```bash
167
+ python examples/make_demo.py --output-directory /tmp/twhy-demo
168
+ twhy /tmp/twhy-demo/synthetic-mif.ome.tif --channel 0 --channel 2
169
+ ```
170
+
171
+ ## Python API
172
+
173
+ ```python
174
+ import numpy as np
175
+ from twhy import TextRenderer
176
+
177
+ pixels = np.linspace(0, 1, 256**2).reshape(256, 256)
178
+ frame = TextRenderer(mode="detail", color=False).render(pixels, columns=80)
179
+ print(frame.to_text())
180
+ ```
181
+
182
+ ## Optional remote sources
183
+
184
+ Local files are the main workflow. `twhy` also supports HTTP(S) images/PDFs (bounded download) and HTTP(S) OME-Zarr (regional chunk reads). For native S3 or S3-compatible stores, install `twhy[s3]` and use your normal AWS credentials or an endpoint override. No S3 setup is needed for local images, slides, or PDFs. [Remote input reference](https://github.com/jason-weirather/twhy/blob/main/docs/reference.md#local-and-remote-inputs).
185
+
186
+ ## Release media and provenance
187
+
188
+ These GIFs are edited recordings of the real `twhy` terminal viewer. Showcase sources:
189
+
190
+ - **mIF:** Tan, Y. & Kempchen, T. (2024), [*SPACEc demo dataset*](https://doi.org/10.5061/dryad.brv15dvj1), Dryad.
191
+ - **H&E whole-slide demo:** `CMU-1.svs`, [OpenSlide test data](https://openslide.cs.cmu.edu/download/openslide-testdata/Aperio/), Carnegie Mellon University, CC0 1.0.
192
+ - **PDF:** Vaswani, A. et al. (2017), [*Attention Is All You Need*](https://arxiv.org/abs/1706.03762), NeurIPS.
193
+ - **Cat:** Illustration generated with ChatGPT (OpenAI).
194
+
195
+ ## License
196
+
197
+ Apache-2.0. See [LICENSE](https://github.com/jason-weirather/twhy/blob/main/LICENSE).