Debian Codegraph @

notebooks/dev/test-h-a-alpha-geocoded.ipynb

raw
1 {
2 "cells": [
3 {
4 "cell_type": "markdown",
5 "id": "c165ac4d",
6 "metadata": {},
7 "source": [
8 "# Visual comparison of parameters for images in SAR and geographic coordinates\n",
9 "\n",
10 "- This is only to check the outputs for geocoded images\n",
11 "- Numerical comparison is done in a script with C outputs using reference data."
12 ]
13 },
14 {
15 "cell_type": "code",
16 "execution_count": null,
17 "id": "99920dfb",
18 "metadata": {},
19 "outputs": [],
20 "source": [
21 "%load_ext autoreload\n",
22 "%autoreload 2\n",
23 "\n",
24 "import os\n",
25 "\n",
26 "from pathlib import Path\n",
27 "from polsarpro.io import open_netcdf_beam\n",
28 "from polsarpro.decompositions import h_a_alpha\n",
29 "import matplotlib.pyplot as plt\n",
30 "# optional import for progress bar\n",
31 "from dask.diagnostics import ProgressBar\n",
32 "\n",
33 "# change to your data paths\n",
34 "# original dataset\n",
35 "input_alos_slc = Path(\"/data/psp/test_files/SAN_FRANCISCO_ALOS1_slc.nc\")\n",
36 "input_alos_geo = Path(\"/data/psp/test_files/SAN_FRANCISCO_ALOS1_geocoded_T3_7_look_az.nc\")\n",
37 "\n",
38 "# input files from C\n",
39 "input_test_dir = Path(\"/data/psp/test_files/input/h_a_alpha_decomposition/\")\n",
40 "\n",
41 "# output files from C\n",
42 "output_test_dir = Path(\"/data/psp/res/h_a_alpha_c\")"
43 ]
44 },
45 {
46 "cell_type": "code",
47 "execution_count": 2,
48 "id": "14bc0335",
49 "metadata": {},
50 "outputs": [],
51 "source": [
52 "slc = open_netcdf_beam(input_alos_slc)\n",
53 "geo = open_netcdf_beam(input_alos_geo)\n",
54 "\n",
55 "# uncomment if you want to test for cropped data\n",
56 "# geo_crop = geo.isel(lat=slice(0,1000))"
57 ]
58 },
59 {
60 "cell_type": "code",
61 "execution_count": null,
62 "id": "cb995ca2",
63 "metadata": {},
64 "outputs": [],
65 "source": [
66 "# let's use persist (retains dask arrays) instead of compute (produces numpy arrays)\n",
67 "with ProgressBar():\n",
68 " res_slc = h_a_alpha(slc, boxcar_size=[7 ,7]).persist()\n",
69 "with ProgressBar():\n",
70 " # data has been multilooked in azimuth so we need less filtering\n",
71 " res_geo = h_a_alpha(geo, boxcar_size=[3 ,3]).persist()\n",
72 "\n",
73 " # uncomment if you want to test for cropped data\n",
74 " # res_geo = h_a_alpha(geo_crop, boxcar_size=[7 ,7]).compute()"
75 ]
76 },
77 {
78 "cell_type": "code",
79 "execution_count": null,
80 "id": "9691637e",
81 "metadata": {},
82 "outputs": [],
83 "source": [
84 "plt.figure(figsize=(10, 10))\n",
85 "plt.imshow(res_slc.anisotropy[::8], interpolation=\"none\")\n",
86 "plt.colorbar(fraction=0.046, pad=0.04)\n",
87 "plt.figure(figsize=(10, 10))\n",
88 "plt.imshow(res_geo.anisotropy, interpolation=\"none\", vmin=0, vmax=1)\n",
89 "plt.colorbar(fraction=0.046, pad=0.04)"
90 ]
91 },
92 {
93 "cell_type": "code",
94 "execution_count": null,
95 "id": "af56f4c9",
96 "metadata": {},
97 "outputs": [],
98 "source": [
99 "plt.figure(figsize=(10, 10))\n",
100 "plt.imshow(res_slc.alpha[::8], interpolation=\"none\")\n",
101 "plt.colorbar(fraction=0.046, pad=0.04)\n",
102 "plt.figure(figsize=(10, 10))\n",
103 "plt.imshow(res_geo.alpha, interpolation=\"none\", vmin=0, vmax=90)\n",
104 "plt.colorbar(fraction=0.046, pad=0.04)"
105 ]
106 },
107 {
108 "cell_type": "code",
109 "execution_count": null,
110 "id": "945ff755",
111 "metadata": {},
112 "outputs": [],
113 "source": [
114 "plt.figure(figsize=(10, 10))\n",
115 "plt.imshow(res_slc.entropy[::8], interpolation=\"none\")\n",
116 "plt.colorbar(fraction=0.046, pad=0.04)\n",
117 "plt.figure(figsize=(10, 10))\n",
118 "plt.imshow(res_geo.entropy, interpolation=\"none\")\n",
119 "plt.colorbar(fraction=0.046, pad=0.04)"
120 ]
121 }
122 ],
123 "metadata": {
124 "kernelspec": {
125 "display_name": "psp",
126 "language": "python",
127 "name": "python3"
128 },
129 "language_info": {
130 "codemirror_mode": {
131 "name": "ipython",
132 "version": 3
133 },
134 "file_extension": ".py",
135 "mimetype": "text/x-python",
136 "name": "python",
137 "nbconvert_exporter": "python",
138 "pygments_lexer": "ipython3",
139 "version": "3.12.12"
140 }
141 },
142 "nbformat": 4,
143 "nbformat_minor": 5
144 }