Skip to content
Snippets Groups Projects
convert.ipynb 2.99 KiB
Newer Older
Zvolenský Juraj's avatar
Zvolenský Juraj committed
{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Converting NetCDF into COGs\n",
    "Copying the data from the network drive using a wildcard to get SWE maps. \\\n",
    "Then using a function defined in utils.py to convert the NetCDF files into COGs. "
Zvolenský Juraj's avatar
Zvolenský Juraj committed
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
Zvolenský Juraj's avatar
Zvolenský Juraj committed
   "metadata": {},
   "outputs": [],
   "source": [
    "from utils import copy_netcdf_data\n",
    "from conversion import netcdf_to_cog, process_multiple_datasets\n",
Zvolenský Juraj's avatar
Zvolenský Juraj committed
    "from transformation import transform_cogs_in_dirs"
Zvolenský Juraj's avatar
Zvolenský Juraj committed
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Find and copy the SWE data to the data folder\n",
Zvolenský Juraj's avatar
Zvolenský Juraj committed
    "netcdf_path = \"/mnt/CEPH_PROJECTS/PROSNOW/SENTINEL-2/Daily_SCA/Venosta/*_swe.nc\"\n",
    "output = \"./data\"\n",
Zvolenský Juraj's avatar
Zvolenský Juraj committed
    "\n",
    "copy_netcdf_data(netcdf_path, output)"
Zvolenský Juraj's avatar
Zvolenský Juraj committed
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
Zvolenský Juraj's avatar
Zvolenský Juraj committed
   "metadata": {},
   "outputs": [],
Zvolenský Juraj's avatar
Zvolenský Juraj committed
   "source": [
Zvolenský Juraj's avatar
Zvolenský Juraj committed
    "# Convert single NetCDF into a folder of COGs\n",
    "cogs = netcdf_to_cog(\n",
    "    netcdf_path=\"./data/venosta_hy2021_swe.nc\",\n",
    "    cog_dir=\"./output_cog/venosta_2021_cog/\",\n",
    ")"
Zvolenský Juraj's avatar
Zvolenský Juraj committed
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
Zvolenský Juraj's avatar
Zvolenský Juraj committed
    "# Convert a list of NetCDF files into their respective output COG folders\n",
    "net_cdf_paths = [\n",
Zvolenský Juraj's avatar
Zvolenský Juraj committed
    "    \"./data/venosta_hy1718_swe.nc\",\n",
    "    \"./data/venosta_hy1819_swe.nc\",\n",
    "    \"./data/venosta_hy1920_swe.nc\",\n",
    "    \"./data/venosta_hy2021_swe.nc\",\n",
    "    \"./data/venosta_hy2122_swe.nc\",\n",
    "]\n",
    "\n",
    "cog_dirs = [\n",
Zvolenský Juraj's avatar
Zvolenský Juraj committed
    "    \"./output_cog/venosta_1819_cog/\",\n",
    "    \"./output_cog/venosta_1819_cog/\",\n",
    "    \"./output_cog/venosta_1920_cog/\",\n",
    "    \"./output_cog/venosta_2021_cog/\",\n",
    "    \"./output_cog/venosta_2122_cog/\",\n",
    "]\n",
    "\n",
    "process_multiple_datasets(net_cdf_paths, cog_dirs)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
Zvolenský Juraj's avatar
Zvolenský Juraj committed
    "# Transform the coordinates of the COGs to any EPSG\n",
    "# In this case EPSG:3035\n",
    "dirs = [\n",
    "    \"./output_cog/venosta_1718_cog\",\n",
    "    \"./output_cog/venosta_1819_cog\",\n",
    "    \"./output_cog/venosta_1920_cog\",\n",
    "    \"./output_cog/venosta_2021_cog\",\n",
    "    \"./output_cog/venosta_2122_cog\",\n",
    "]\n",
    "transform_cogs_in_dirs(dirs, \"EPSG:3035\")"
Zvolenský Juraj's avatar
Zvolenský Juraj committed
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": ".venv",
   "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.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}