{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f4244124",
   "metadata": {},
   "outputs": [],
   "source": [
    "from polsarpro.io import open_netcdf_beam\n",
    "from polsarpro.speckle_filters import refined_lee\n",
    "from polsarpro.decompositions import freeman\n",
    "from polsarpro.util import S_to_C3, multilook"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "49af1167",
   "metadata": {},
   "outputs": [],
   "source": [
    "S = open_netcdf_beam(\"/data/psp/biomass_test.nc\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "82eed5ef",
   "metadata": {},
   "outputs": [],
   "source": [
    "S"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5eeff7f1",
   "metadata": {},
   "outputs": [],
   "source": [
    "C3 = S_to_C3(S)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "17693036",
   "metadata": {},
   "outputs": [],
   "source": [
    "C3 = multilook(C3, dim_az=6, dim_rg=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1d883781",
   "metadata": {},
   "outputs": [],
   "source": [
    "out = freeman(C3, boxcar_size=[5, 5])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "126c5a13",
   "metadata": {},
   "outputs": [],
   "source": [
    "from dask.diagnostics import ProgressBar\n",
    "# execution happens now!\n",
    "with ProgressBar():\n",
    "    out.to_netcdf(\"/data/psp/test.nc\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9676cead",
   "metadata": {},
   "outputs": [],
   "source": [
    "import xarray as xr\n",
    "out = xr.open_dataset(\"/data/psp/test.nc\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b7076743",
   "metadata": {},
   "outputs": [],
   "source": [
    "import matplotlib.pyplot as plt\n",
    "plt.figure(figsize=(10, 10))\n",
    "plt.imshow(out.odd, interpolation=\"none\", vmax=1)\n",
    "plt.colorbar(fraction=0.046, pad=0.04)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4d07fb42",
   "metadata": {},
   "outputs": [],
   "source": [
    "from polsarpro.util import pauli_rgb\n",
    "\n",
    "rgb = pauli_rgb(C3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "438d95b2",
   "metadata": {},
   "outputs": [],
   "source": [
    "rgb.plot.imshow()"
   ]
  }
 ],
 "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.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
