{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3ca2e56f",
   "metadata": {},
   "outputs": [],
   "source": [
    "%load_ext autoreload\n",
    "%autoreload 2\n",
    "from pathlib import Path\n",
    "\n",
    "import numpy as np\n",
    "import xarray as xr\n",
    "import dask.array as da\n",
    "\n",
    "from polsarpro.speckle_filters import refined_lee\n",
    "from dask.diagnostics import ProgressBar"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0c5bc905",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Load data and make dataset\n",
    "input_data = Path(\"/data/psp/test_files/Simul_PolSAR.npy\")\n",
    "img = np.load(input_data)\n",
    "\n",
    "dims = (\"y\", \"x\")\n",
    "T3_dict = dict(\n",
    "    m11=xr.DataArray(img[..., 0, 0].real, dims=dims),\n",
    "    m22=xr.DataArray(img[..., 1, 1].real, dims=dims),\n",
    "    m33=xr.DataArray(img[..., 2, 2].real, dims=dims),\n",
    "    m12=xr.DataArray(img[..., 0, 1], dims=dims),\n",
    "    m13=xr.DataArray(img[..., 0, 2], dims=dims),\n",
    "    m23=xr.DataArray(img[..., 1, 2], dims=dims),    \n",
    ")\n",
    "# T3 = xr.Dataset(T3_dict, attrs=dict(poltype=\"T3\", description=\"...\")).chunk(x=512, y=512)\n",
    "T3 = xr.Dataset(T3_dict, attrs=dict(poltype=\"T3\", description=\"...\")).chunk(x=128, y=128)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "58b15309",
   "metadata": {},
   "outputs": [],
   "source": [
    "with ProgressBar():\n",
    "    res = refined_lee(T3, window_size=7, num_looks=4).compute()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9dc68aa2",
   "metadata": {},
   "outputs": [],
   "source": [
    "import matplotlib.pyplot as plt\n",
    "plt.figure(figsize=(10, 10))\n",
    "plt.imshow(res.m11, interpolation=\"none\")\n",
    "plt.colorbar(fraction=0.046, pad=0.04)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "psp",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
