Debian Codegraph @

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