{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Test validation function on real dataset\n",
    "\n",
    "Instead of manually repeating the same exceptions for each new processing function, we have written and standardized data validation function `validate_data`. This notebook tests the function on real datasets."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "%load_ext autoreload\n",
    "%autoreload 2\n",
    "\n",
    "import os\n",
    "# avoid thread conflicts between numpy and dask\n",
    "os.environ[\"OMP_NUM_THREADS\"] = \"1\"\n",
    "os.environ[\"OPENBLAS_NUM_THREADS\"] = \"1\"\n",
    "os.environ[\"MKL_NUM_THREADS\"] = \"1\"\n",
    "os.environ[\"VECLIB_MAXIMUM_THREADS\"] = \"1\"\n",
    "os.environ[\"NUMEXPR_NUM_THREADS\"] = \"1\"\n",
    "\n",
    "from polsarpro.dev.devtools import parse_psp_parameter_string\n",
    "import numpy as np\n",
    "from pathlib import Path\n",
    "from polsarpro.io import open_netcdf_beam\n",
    "from polsarpro.auxil import validate_dataset\n",
    "\n",
    "# change to your data paths\n",
    "# original dataset\n",
    "input_alos_data = Path(\"/data/psp/test_files/SAN_FRANCISCO_ALOS1_slc.nc\")\n",
    "# input_alos_data = Path(\"/data/psp/test_files/SAN_FRANCISCO_ALOS1_geocoded_T3_7_look_az.nc\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Load ALOS data and C outputs"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# uncomment to test on S matrix made with SNAP\n",
    "S = open_netcdf_beam(input_alos_data)\n",
    "_ = validate_dataset(S)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from polsarpro.util import S_to_C3, S_to_T4, C3_to_T3\n",
    "C3 = S_to_C3(S).compute()\n",
    "T3 = C3_to_T3(C3)\n",
    "T4 = S_to_T4(S)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "_ = validate_dataset(C3)\n",
    "_ = validate_dataset(T3)\n",
    "_ = validate_dataset(T4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "_ = validate_dataset(np.zeros((3,3)))"
   ]
  }
 ],
 "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": 2
}
