| 1 |
{ |
| 2 |
"cells": [ |
| 3 |
{ |
| 4 |
"cell_type": "code", |
| 5 |
"execution_count": null, |
| 6 |
"metadata": {}, |
| 7 |
"outputs": [], |
| 8 |
"source": [ |
| 9 |
"%load_ext autoreload\n", |
| 10 |
"%autoreload 2\n", |
| 11 |
"\n", |
| 12 |
"import os\n", |
| 13 |
"from pathlib import Path\n", |
| 14 |
"\n", |
| 15 |
"import numpy as np\n", |
| 16 |
"import xarray as xr\n", |
| 17 |
"from dask.diagnostics import ProgressBar\n", |
| 18 |
"\n", |
| 19 |
"from polsarpro.io import open_netcdf_beam\n", |
| 20 |
"from polsarpro.util import pauli_rgb\n", |
| 21 |
"\n", |
| 22 |
"# change to your local C-PolSARpro install dir\n", |
| 23 |
"# Kept for consistency with the other dev notebooks, but unused in this\n", |
| 24 |
"# UAVSAR-only variant.\n", |
| 25 |
"c_psp_dir = \"/home/c_psp/Soft/bin/\"\n", |
| 26 |
"os.environ[\"PATH\"] += os.pathsep + f\"{c_psp_dir}/data_process_sngl/\"\n", |
| 27 |
"os.environ[\"PATH\"] += os.pathsep + f\"{c_psp_dir}/data_convert/\"\n", |
| 28 |
"\n", |
| 29 |
"input_uavsar_nc = Path(\"/data/psp/test_files/blackw_20801_22010_006_220507_L090_CX_02_ML5X5.nc\")\n", |
| 30 |
"incidence_angle_file = Path(\n", |
| 31 |
" \"/data/psp/test_files/blackw_20801_22010_006_220507_L090_CX_02.inc\"\n", |
| 32 |
")\n", |
| 33 |
"file_out = Path(\"/data/psp/res/test_dubois_surface_inversion_uavsar.nc\")\n", |
| 34 |
"\n", |
| 35 |
"with xr.open_dataset(input_uavsar_nc) as raw_ds:\n", |
| 36 |
" center_wavelength_cm = raw_ds[\"metadata\"].attrs[\"Annotation:CenterWavelength\"]\n", |
| 37 |
"\n", |
| 38 |
"# Dubois expects GHz; UAVSAR metadata stores the center wavelength in cm.\n", |
| 39 |
"freq_ghz = 29.9792458 / float(center_wavelength_cm)\n", |
| 40 |
"\n", |
| 41 |
"# Leave thresholds as-is for now.\n", |
| 42 |
"thresh1_db = 0.0\n", |
| 43 |
"thresh2_db = -10.0\n", |
| 44 |
"calibration_coeff = 1.0\n", |
| 45 |
"\n", |
| 46 |
"print(f\"Derived radar frequency: {freq_ghz:.6f} GHz\")\n" |
| 47 |
] |
| 48 |
}, |
| 49 |
{ |
| 50 |
"cell_type": "markdown", |
| 51 |
"metadata": {}, |
| 52 |
"source": [ |
| 53 |
"## Load UAVSAR data and incidence angle raster" |
| 54 |
] |
| 55 |
}, |
| 56 |
{ |
| 57 |
"cell_type": "code", |
| 58 |
"execution_count": null, |
| 59 |
"metadata": {}, |
| 60 |
"outputs": [], |
| 61 |
"source": [ |
| 62 |
"C3 = open_netcdf_beam(input_uavsar_nc)\n", |
| 63 |
"row_dim, col_dim = C3.dims\n", |
| 64 |
"# nlines = C3.sizes[row_dim]\n", |
| 65 |
"# ncols = C3.sizes[col_dim]\n", |
| 66 |
"\n", |
| 67 |
"# use lines from .ann file\n", |
| 68 |
"# inc.set_rows (pixels) = 12344 ; INC Lines\n", |
| 69 |
"# inc.set_cols (pixels) = 11248 ; INC Samples\n", |
| 70 |
"\n", |
| 71 |
"nlines = 12344\n", |
| 72 |
"ncols = 11248\n", |
| 73 |
"\n", |
| 74 |
"# The incidence-angle file is a little-endian float32 stream in radians.\n", |
| 75 |
"# Read only the raster-sized prefix and reshape it to the UAVSAR grid.\n", |
| 76 |
"incidence_angle_values = np.fromfile(\n", |
| 77 |
" incidence_angle_file,\n", |
| 78 |
" dtype=\"<f4\",\n", |
| 79 |
" count=nlines * ncols,\n", |
| 80 |
")\n", |
| 81 |
"\n", |
| 82 |
"# reduce to the same dimensions as multilooked 5x5 image\n", |
| 83 |
"incidence_angle_values[incidence_angle_values==-10000] = np.nan\n", |
| 84 |
"incidence_angle = xr.DataArray(\n", |
| 85 |
" incidence_angle_values.reshape(nlines, ncols),\n", |
| 86 |
" dims=(row_dim, col_dim),\n", |
| 87 |
" # coords={row_dim: C3.coords[row_dim], col_dim: C3.coords[col_dim]},\n", |
| 88 |
" name=\"incidence_angle\",\n", |
| 89 |
").coarsen(y=5, x=5, boundary=\"trim\").mean()\n" |
| 90 |
] |
| 91 |
}, |
| 92 |
{ |
| 93 |
"cell_type": "code", |
| 94 |
"execution_count": null, |
| 95 |
"metadata": {}, |
| 96 |
"outputs": [], |
| 97 |
"source": [ |
| 98 |
"# rgb = pauli_rgb(C3)" |
| 99 |
] |
| 100 |
}, |
| 101 |
{ |
| 102 |
"cell_type": "code", |
| 103 |
"execution_count": null, |
| 104 |
"metadata": {}, |
| 105 |
"outputs": [], |
| 106 |
"source": [ |
| 107 |
"# rgb[:,::4,1000:].plot.imshow()\n", |
| 108 |
"import matplotlib.pyplot as plt\n", |
| 109 |
"plt.figure(figsize=(10, 10))\n", |
| 110 |
"plt.imshow(rgb.transpose(\"y\", \"x\", \"band\"), interpolation=\"nearest\")\n", |
| 111 |
"# plt.colorbar(fraction=0.046, pad=0.04)" |
| 112 |
] |
| 113 |
}, |
| 114 |
{ |
| 115 |
"cell_type": "code", |
| 116 |
"execution_count": null, |
| 117 |
"metadata": {}, |
| 118 |
"outputs": [], |
| 119 |
"source": [ |
| 120 |
"# rgb[:,::4,1000:].plot.imshow()\n", |
| 121 |
"import matplotlib.pyplot as plt\n", |
| 122 |
"plt.figure(figsize=(10, 10))\n", |
| 123 |
"# plt.imshow(incidence_angle[::5, ::5], interpolation=\"bilinear\")\n", |
| 124 |
"plt.imshow(incidence_angle, interpolation=\"nearest\")\n", |
| 125 |
"plt.colorbar(fraction=0.046, pad=0.04)" |
| 126 |
] |
| 127 |
} |
| 128 |
], |
| 129 |
"metadata": { |
| 130 |
"kernelspec": { |
| 131 |
"display_name": "Python 3", |
| 132 |
"language": "python", |
| 133 |
"name": "python3" |
| 134 |
}, |
| 135 |
"language_info": { |
| 136 |
"codemirror_mode": { |
| 137 |
"name": "ipython", |
| 138 |
"version": 3 |
| 139 |
}, |
| 140 |
"file_extension": ".py", |
| 141 |
"mimetype": "text/x-python", |
| 142 |
"name": "python", |
| 143 |
"nbconvert_exporter": "python", |
| 144 |
"pygments_lexer": "ipython3", |
| 145 |
"version": "3.12.13" |
| 146 |
} |
| 147 |
}, |
| 148 |
"nbformat": 4, |
| 149 |
"nbformat_minor": 2 |
| 150 |
} |