|
1 | 1 | import marimo |
2 | 2 |
|
3 | | -__generated_with = "0.15.5" |
| 3 | +__generated_with = "0.19.8" |
4 | 4 | app = marimo.App(width="medium") |
5 | 5 |
|
6 | 6 |
|
@@ -153,7 +153,9 @@ def select_for_data_cubes( |
153 | 153 |
|
154 | 154 | @app.cell |
155 | 155 | def _(mo): |
156 | | - mo.md(r"""# OMEGA C Channel Data""") |
| 156 | + mo.md(r""" |
| 157 | + # OMEGA C Channel Data |
| 158 | + """) |
157 | 159 | return |
158 | 160 |
|
159 | 161 |
|
@@ -242,7 +244,9 @@ def _(omega_c_chan_ds, plt, select_rgb_img): |
242 | 244 |
|
243 | 245 | @app.cell |
244 | 246 | def _(mo): |
245 | | - mo.md(r"""# OMEGA Data cubes""") |
| 247 | + mo.md(r""" |
| 248 | + # OMEGA Data cubes |
| 249 | + """) |
246 | 250 | return |
247 | 251 |
|
248 | 252 |
|
@@ -381,7 +385,9 @@ def _(np, omega_dc_ds): |
381 | 385 |
|
382 | 386 | @app.cell |
383 | 387 | def _(mo): |
384 | | - mo.md(r"""# Comparison between L2 and L3 products""") |
| 388 | + mo.md(r""" |
| 389 | + # Comparison between L2 and L3 products |
| 390 | + """) |
385 | 391 | return |
386 | 392 |
|
387 | 393 |
|
@@ -599,6 +605,79 @@ def _( |
599 | 605 | return |
600 | 606 |
|
601 | 607 |
|
| 608 | +@app.cell |
| 609 | +def _( |
| 610 | + common_omega_idx, |
| 611 | + common_omega_idx_slider, |
| 612 | + img_omega, |
| 613 | + omega_c_channel_builder, |
| 614 | +): |
| 615 | + omega_c_channel_builder.make_thumbnail( |
| 616 | + common_omega_idx[common_omega_idx_slider.value], |
| 617 | + data=img_omega[1].Reflectance.values, |
| 618 | + dims=(258, 258), |
| 619 | + ) |
| 620 | + return |
| 621 | + |
| 622 | + |
| 623 | +@app.cell |
| 624 | +def _(np, plt): |
| 625 | + from typing import Literal |
| 626 | + from PIL import Image |
| 627 | + |
| 628 | + def convert_arr_to_thumbnail( |
| 629 | + data: np.ndarray, |
| 630 | + resize_dims: tuple[int, int], |
| 631 | + mode: Literal["L", "RGB", "RGBA"] = "L", |
| 632 | + cmap: str | None = None, |
| 633 | + ) -> Image.Image: |
| 634 | + """ |
| 635 | + Converts a 2D or 3D NumPy array into a resized PNG-style image. |
| 636 | + Applies a matplotlib colormap if provided. |
| 637 | + """ |
| 638 | + |
| 639 | + # Normalizes data between 0 and 1 |
| 640 | + result = np.asarray(data, dtype=float) |
| 641 | + |
| 642 | + result_min = np.nanmin(result[~np.isneginf(result)]) |
| 643 | + result_max = np.nanmax(result[~np.isposinf(result)]) |
| 644 | + if np.isnan(result_max) or np.isnan(result_min): |
| 645 | + raise ValueError( |
| 646 | + f"Seems like the array's size is NaN (min={result_min}, max={result_max})" |
| 647 | + ) |
| 648 | + |
| 649 | + result = (result - result_min) / (result_max - result_min + 1e-8) |
| 650 | + |
| 651 | + if cmap is not None: |
| 652 | + cm = plt.get_cmap(cmap) |
| 653 | + result = cm(result)[..., :4] # includes alpha |
| 654 | + result = (result * 255).astype(np.uint8) |
| 655 | + if mode == "RGB": |
| 656 | + result = result[..., :3] |
| 657 | + else: |
| 658 | + result = (result * 255).astype(np.uint8) |
| 659 | + if mode in ["RGB", "RGBA"]: |
| 660 | + result = np.stack([result] * (3 if mode == "RGB" else 4), axis=-1) |
| 661 | + |
| 662 | + img = Image.fromarray(result[0], mode=mode) |
| 663 | + img = img.resize(resize_dims, Image.Resampling.LANCZOS) |
| 664 | + |
| 665 | + return img |
| 666 | + |
| 667 | + return (convert_arr_to_thumbnail,) |
| 668 | + |
| 669 | + |
| 670 | +@app.cell |
| 671 | +def _(convert_arr_to_thumbnail, img_omega): |
| 672 | + convert_arr_to_thumbnail( |
| 673 | + img_omega[1].Reflectance.values, |
| 674 | + resize_dims=(258, 258), |
| 675 | + mode="RGB", |
| 676 | + cmap="viridis", |
| 677 | + ) |
| 678 | + return |
| 679 | + |
| 680 | + |
602 | 681 | @app.cell |
603 | 682 | def _(): |
604 | 683 | return |
|
0 commit comments