| 1 |
{ |
| 2 |
"cells": [ |
| 3 |
{ |
| 4 |
"cell_type": "code", |
| 5 |
"execution_count": null, |
| 6 |
"id": "3ca2e56f", |
| 7 |
"metadata": {}, |
| 8 |
"outputs": [], |
| 9 |
"source": [ |
| 10 |
"%load_ext autoreload\n", |
| 11 |
"%autoreload 2\n", |
| 12 |
"from pathlib import Path\n", |
| 13 |
"\n", |
| 14 |
"import numpy as np\n", |
| 15 |
"import xarray as xr\n", |
| 16 |
"import dask.array as da\n", |
| 17 |
"\n", |
| 18 |
"from polsarpro.speckle_filters import refined_lee\n", |
| 19 |
"from dask.diagnostics import ProgressBar" |
| 20 |
] |
| 21 |
}, |
| 22 |
{ |
| 23 |
"cell_type": "code", |
| 24 |
"execution_count": null, |
| 25 |
"id": "0c5bc905", |
| 26 |
"metadata": {}, |
| 27 |
"outputs": [], |
| 28 |
"source": [ |
| 29 |
"# Load data and make dataset\n", |
| 30 |
"input_data = Path(\"/data/psp/test_files/Simul_PolSAR.npy\")\n", |
| 31 |
"img = np.load(input_data)\n", |
| 32 |
"\n", |
| 33 |
"dims = (\"y\", \"x\")\n", |
| 34 |
"T3_dict = dict(\n", |
| 35 |
" m11=xr.DataArray(img[..., 0, 0].real, dims=dims),\n", |
| 36 |
" m22=xr.DataArray(img[..., 1, 1].real, dims=dims),\n", |
| 37 |
" m33=xr.DataArray(img[..., 2, 2].real, dims=dims),\n", |
| 38 |
" m12=xr.DataArray(img[..., 0, 1], dims=dims),\n", |
| 39 |
" m13=xr.DataArray(img[..., 0, 2], dims=dims),\n", |
| 40 |
" m23=xr.DataArray(img[..., 1, 2], dims=dims), \n", |
| 41 |
")\n", |
| 42 |
"# T3 = xr.Dataset(T3_dict, attrs=dict(poltype=\"T3\", description=\"...\")).chunk(x=512, y=512)\n", |
| 43 |
"T3 = xr.Dataset(T3_dict, attrs=dict(poltype=\"T3\", description=\"...\")).chunk(x=128, y=128)" |
| 44 |
] |
| 45 |
}, |
| 46 |
{ |
| 47 |
"cell_type": "code", |
| 48 |
"execution_count": null, |
| 49 |
"id": "58b15309", |
| 50 |
"metadata": {}, |
| 51 |
"outputs": [], |
| 52 |
"source": [ |
| 53 |
"with ProgressBar():\n", |
| 54 |
" res = refined_lee(T3, window_size=7, num_looks=4).compute()" |
| 55 |
] |
| 56 |
}, |
| 57 |
{ |
| 58 |
"cell_type": "code", |
| 59 |
"execution_count": null, |
| 60 |
"id": "9dc68aa2", |
| 61 |
"metadata": {}, |
| 62 |
"outputs": [], |
| 63 |
"source": [ |
| 64 |
"import matplotlib.pyplot as plt\n", |
| 65 |
"plt.figure(figsize=(10, 10))\n", |
| 66 |
"plt.imshow(res.m11, interpolation=\"none\")\n", |
| 67 |
"plt.colorbar(fraction=0.046, pad=0.04)" |
| 68 |
] |
| 69 |
} |
| 70 |
], |
| 71 |
"metadata": { |
| 72 |
"kernelspec": { |
| 73 |
"display_name": "psp", |
| 74 |
"language": "python", |
| 75 |
"name": "python3" |
| 76 |
}, |
| 77 |
"language_info": { |
| 78 |
"codemirror_mode": { |
| 79 |
"name": "ipython", |
| 80 |
"version": 3 |
| 81 |
}, |
| 82 |
"file_extension": ".py", |
| 83 |
"mimetype": "text/x-python", |
| 84 |
"name": "python", |
| 85 |
"nbconvert_exporter": "python", |
| 86 |
"pygments_lexer": "ipython3", |
| 87 |
"version": "3.12.11" |
| 88 |
} |
| 89 |
}, |
| 90 |
"nbformat": 4, |
| 91 |
"nbformat_minor": 5 |
| 92 |
} |