{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# XSAR simple example\n",
    "\n",
    "just open a dataset with [xsar.open_dataset](../basic_api.rst#xsar.open_dataset), and display denoised `sigma0` in 'VH' polarisation"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import xarray as xr\n",
    "import xsar \n",
    "import os"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import holoviews as hv\n",
    "hv.extension('bokeh')\n",
    "from holoviews.operation.datashader import datashade,rasterize\n",
    "import datashader as dh"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "tags": []
   },
   "source": [
    "## Sentinel 1 Example"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# get test file. You can replace with an path to other SAFE\n",
    "filename = xsar.get_test_file('S1A_IW_GRDH_1SDV_20170907T103020_20170907T103045_018268_01EB76_Z010.SAFE')\n",
    "filename"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# open the datatree with xarray\n",
    "dt_xsar = xsar.open_datatree(filename,resolution='100m')\n",
    "dt_xsar"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# open the dataset with xarray\n",
    "ds_xsar = xsar.open_dataset(filename, resolution='100m')\n",
    "ds_xsar"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# we use here 'rasterize' to display the image, because the full image is really big\n",
    "rasterize(hv.Image(ds_xsar.sigma0.sel(pol='VH')).opts(cmap='gray',colorbar=True,tools=['hover'],title=\"xsar\",width=800,height=800,clim=(0,0.02)))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "tags": []
   },
   "source": [
    "## RadarSat2 example"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# get test file. You can replace with an path to other SAFE\n",
    "filename = xsar.get_test_file('RS2_OK135107_PK1187782_DK1151894_SCWA_20220407_182127_VV_VH_SGF')\n",
    "filename"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# open the datatree with xarray\n",
    "dt_xsar = xsar.open_datatree(filename,resolution='100m')\n",
    "dt_xsar"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# open the dataset with xarray\n",
    "ds_xsar = xsar.open_dataset(filename, resolution='100m')\n",
    "ds_xsar"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# we use here 'rasterize' to display the image, because the full image is really big\n",
    "rasterize(hv.Image(ds_xsar.sigma0.sel(pol='VH')).opts(cmap='gray',colorbar=True,tools=['hover'],title=\"xsar\",width=800,height=800,clim=(0,0.02)))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "tags": []
   },
   "source": [
    "## RCM example"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import warnings\n",
    "warnings.filterwarnings('ignore')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# get test file. You can replace with an path to other SAFE\n",
    "filename = xsar.get_test_file('RCM1_OK1050603_PK1050605_1_SC50MB_20200214_115905_HH_HV_Z010')\n",
    "filename"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# open the datatree with xarray\n",
    "dt_xsar = xsar.open_datatree(filename,resolution='100m')\n",
    "dt_xsar"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# open the dataset with xarray\n",
    "ds_xsar = xsar.open_dataset(filename, resolution='100m')\n",
    "ds_xsar"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# we use here 'rasterize' to display the image, because the full image is really big\n",
    "rasterize(hv.Image(ds_xsar.sigma0.sel(pol='HV')).opts(cmap='gray',colorbar=True,tools=['hover'],title=\"xsar\",width=800,height=800,clim=(0,0.02)))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "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.10.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
