Debian Codegraph @

notebooks/dev/test-wishart-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.\n",
12 "- For integer classification results, areas corresponding to NaNs are labeled as 0."
13 ]
14 },
15 {
16 "cell_type": "code",
17 "execution_count": null,
18 "id": "99920dfb",
19 "metadata": {},
20 "outputs": [],
21 "source": [
22 "%load_ext autoreload\n",
23 "%autoreload 2\n",
24 "\n",
25 "import os\n",
26 "\n",
27 "import numpy as np\n",
28 "from pathlib import Path\n",
29 "import xarray as xr\n",
30 "from polsarpro.io import open_netcdf_beam\n",
31 "from polsarpro.classification import wishart_h_a_alpha\n",
32 "from polsarpro.util import S_to_T3, boxcar\n",
33 "import matplotlib.pyplot as plt\n",
34 "# optional import for progress bar\n",
35 "from dask.diagnostics import ProgressBar\n",
36 "\n",
37 "# change to your data paths\n",
38 "# original dataset\n",
39 "input_alos_slc = Path(\"/data/psp/test_files/SAN_FRANCISCO_ALOS1_slc.nc\")\n",
40 "input_alos_geo = Path(\"/data/psp/test_files/SAN_FRANCISCO_ALOS1_geocoded_T3_7_look_az.nc\")"
41 ]
42 },
43 {
44 "cell_type": "code",
45 "execution_count": null,
46 "id": "14bc0335",
47 "metadata": {},
48 "outputs": [],
49 "source": [
50 "slc = open_netcdf_beam(input_alos_slc)\n",
51 "geo = open_netcdf_beam(input_alos_geo)\n",
52 "\n",
53 "# uncomment if you want to test for cropped data\n",
54 "# geo_crop = geo.isel(lat=slice(0,1000))"
55 ]
56 },
57 {
58 "cell_type": "code",
59 "execution_count": null,
60 "id": "cb995ca2",
61 "metadata": {},
62 "outputs": [],
63 "source": [
64 "# let's use persist (retains dask arrays) instead of compute (produces numpy arrays)\n",
65 "with ProgressBar():\n",
66 " res_slc = wishart_h_a_alpha(slc, boxcar_size=[7 ,7]).persist()\n",
67 "with ProgressBar():\n",
68 " # data has been multilooked in azimuth so we need less filtering\n",
69 " res_geo = wishart_h_a_alpha(geo, boxcar_size=[3 ,3]).persist()\n",
70 "\n",
71 " # uncomment if you want to test for cropped data\n",
72 " # res_geo = h_a_alpha(geo_crop, boxcar_size=[7 ,7]).compute()"
73 ]
74 },
75 {
76 "cell_type": "code",
77 "execution_count": null,
78 "id": "9691637e",
79 "metadata": {},
80 "outputs": [],
81 "source": [
82 "for var in res_geo.data_vars:\n",
83 " if res_slc[var].ndim < 2:\n",
84 " continue\n",
85 " plt.figure(figsize=(10, 10))\n",
86 " plt.suptitle(var)\n",
87 " plt.subplot(121)\n",
88 " plt.imshow(res_slc[var][::8], interpolation=\"none\", vmin=0, vmax=16)\n",
89 " plt.colorbar(fraction=0.046, pad=0.04)\n",
90 " plt.subplot(122)\n",
91 " plt.imshow(res_geo[var], interpolation=\"none\", vmin=0, vmax=16)\n",
92 " plt.colorbar(fraction=0.046, pad=0.04)"
93 ]
94 }
95 ],
96 "metadata": {
97 "kernelspec": {
98 "display_name": "psp",
99 "language": "python",
100 "name": "python3"
101 },
102 "language_info": {
103 "codemirror_mode": {
104 "name": "ipython",
105 "version": 3
106 },
107 "file_extension": ".py",
108 "mimetype": "text/x-python",
109 "name": "python",
110 "nbconvert_exporter": "python",
111 "pygments_lexer": "ipython3",
112 "version": "3.12.13"
113 }
114 },
115 "nbformat": 4,
116 "nbformat_minor": 5
117 }