Debian Codegraph @

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