{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "c165ac4d",
   "metadata": {},
   "source": [
    "# Visual comparison of parameters for images in SAR and geographic coordinates\n",
    "\n",
    "- This is only to check the outputs for geocoded images\n",
    "- Numerical comparison is done in a script with C outputs using reference data."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "99920dfb",
   "metadata": {},
   "outputs": [],
   "source": [
    "%load_ext autoreload\n",
    "%autoreload 2\n",
    "\n",
    "import os\n",
    "\n",
    "from pathlib import Path\n",
    "from polsarpro.io import open_netcdf_beam\n",
    "from polsarpro.decompositions import h_a_alpha\n",
    "import matplotlib.pyplot as plt\n",
    "# optional import for progress bar\n",
    "from dask.diagnostics import ProgressBar\n",
    "\n",
    "# change to your data paths\n",
    "# original dataset\n",
    "input_alos_slc = Path(\"/data/psp/test_files/SAN_FRANCISCO_ALOS1_slc.nc\")\n",
    "input_alos_geo = Path(\"/data/psp/test_files/SAN_FRANCISCO_ALOS1_geocoded_T3_7_look_az.nc\")\n",
    "\n",
    "# input files from C\n",
    "input_test_dir = Path(\"/data/psp/test_files/input/h_a_alpha_decomposition/\")\n",
    "\n",
    "# output files from C\n",
    "output_test_dir = Path(\"/data/psp/res/h_a_alpha_c\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "14bc0335",
   "metadata": {},
   "outputs": [],
   "source": [
    "slc = open_netcdf_beam(input_alos_slc)\n",
    "geo = open_netcdf_beam(input_alos_geo)\n",
    "\n",
    "# uncomment if you want to test for cropped data\n",
    "# geo_crop = geo.isel(lat=slice(0,1000))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "cb995ca2",
   "metadata": {},
   "outputs": [],
   "source": [
    "# let's use persist (retains dask arrays) instead of compute (produces numpy arrays)\n",
    "with ProgressBar():\n",
    "    res_slc = h_a_alpha(slc, boxcar_size=[7 ,7]).persist()\n",
    "with ProgressBar():\n",
    "    # data has been multilooked in azimuth so we need less filtering\n",
    "    res_geo = h_a_alpha(geo, boxcar_size=[3 ,3]).persist()\n",
    "\n",
    "    # uncomment if you want to test for cropped data\n",
    "    # res_geo = h_a_alpha(geo_crop, boxcar_size=[7 ,7]).compute()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9691637e",
   "metadata": {},
   "outputs": [],
   "source": [
    "plt.figure(figsize=(10, 10))\n",
    "plt.imshow(res_slc.anisotropy[::8], interpolation=\"none\")\n",
    "plt.colorbar(fraction=0.046, pad=0.04)\n",
    "plt.figure(figsize=(10, 10))\n",
    "plt.imshow(res_geo.anisotropy, interpolation=\"none\", vmin=0, vmax=1)\n",
    "plt.colorbar(fraction=0.046, pad=0.04)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "af56f4c9",
   "metadata": {},
   "outputs": [],
   "source": [
    "plt.figure(figsize=(10, 10))\n",
    "plt.imshow(res_slc.alpha[::8], interpolation=\"none\")\n",
    "plt.colorbar(fraction=0.046, pad=0.04)\n",
    "plt.figure(figsize=(10, 10))\n",
    "plt.imshow(res_geo.alpha, interpolation=\"none\", vmin=0, vmax=90)\n",
    "plt.colorbar(fraction=0.046, pad=0.04)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "945ff755",
   "metadata": {},
   "outputs": [],
   "source": [
    "plt.figure(figsize=(10, 10))\n",
    "plt.imshow(res_slc.entropy[::8], interpolation=\"none\")\n",
    "plt.colorbar(fraction=0.046, pad=0.04)\n",
    "plt.figure(figsize=(10, 10))\n",
    "plt.imshow(res_geo.entropy, 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.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
