{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Variational data assimilation with deep prior (CIRC23)\n", "\n", "## Context\n", "### Purpose\n", "Solve data assimilation problems with implicit regularization with deep prior.\n", "\n", "### Description\n", "Deep image prior, a neural network with proven results in standard inverse problems, is used to determine the state of a physical system. It is a fully unsupervised model which acts as implicit regularization in the variational data assimilation method. The algorithm is demonstrated with a shallow-water toy model and the simulated observations are compared with variational assimilation without regularization, with Tikhonov regularization and with deep prior {cite:p}`filoche_2023`.\n", "\n", "### Highlights\n", "* Fetch the modelling codebase from the GitHub repo provided with the paper.\n", "* Run the main Python script to generate sample observations from a shallow-water model and variational assimilation solutions.\n", "* Recreate visualizations from the paper.\n", "* Compare assimilation scores and smoothness statistics between the different models.\n", "\n", "### Source code\n", "The authors of the notebook acknowledge the original creator for providing public code available at [Deepprior4DVar_CI22](https://github.com/ArFiloche/Deepprior4DVar_CI22)." ] }, { "cell_type": "markdown", "metadata": { "tags": [] }, "source": [ "## Clone the paper's GitHub repository\n", "\n", "The cloned repository is moved to the current directory to easily import the required Python modules." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "tags": [] }, "outputs": [], "source": [ "!git clone -q https://github.com/ArFiloche/Deepprior4DVar_CI22" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Load libraries" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "pycharm": { "is_executing": true }, "tags": [ "hide-input" ] }, "outputs": [], "source": [ "# system\n", "import sys\n", "import os\n", "import shutil\n", "\n", "sys.path.insert(0, os.path.join(os.getcwd(), \"Deepprior4DVar_CI22\"))\n", "\n", "# data\n", "import numpy as np\n", "import pooch\n", "\n", "np.random.seed(42)\n", "\n", "# modelling\n", "import torch\n", "import torch.optim as optim\n", "\n", "torch.manual_seed(42)\n", "\n", "# custom functions from the Deepprior4DVar_CI22 repo\n", "import dynamics\n", "import utils\n", "import _4DVar\n", "import _DeepPrior4DVar\n", "\n", "# plotting and tables\n", "import matplotlib.pyplot as plt\n", "import tabulate\n", "\n", "# utils\n", "import time\n", "import warnings\n", "\n", "warnings.filterwarnings(action=\"ignore\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Set project structure\n", "\n", "The following directory structure is the same as given in the project repository." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "pycharm": { "is_executing": true } }, "outputs": [], "source": [ "root_dir = \"data/generated/\"\n", "save_dir = \"data/estimated/\"\n", "\n", "if os.path.exists(\"data\"):\n", " shutil.rmtree(\"data\")\n", "\n", "os.makedirs(root_dir)\n", "os.makedirs(\"data/results/\")\n", "os.makedirs(save_dir + \"4DVar/\")\n", "os.makedirs(save_dir + \"4DVar_reg/\")\n", "os.makedirs(save_dir + \"4DVar_deep/\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Generate data and run assimilations\n", "\n", "The `Deepprior4DVar_CI22` repo has the following main modules:\n", "* `dynamics`: For simulating the shallow-water model.\n", "* `_4DVar`: For assimilation with and without regularization.\n", "* `_DeepPrior4DVar`: For assimilation with deep prior.\n", "\n", "The repo has a script- `main.py`, to perform all the steps required to reproduce the paper. In this notebook, this script has been run with a smaller sample size to reproduce the results. The repo also contains Jupyter notebooks for demonstration in the `notebooks_demo` directory.\n", "\n", "The first step is to generate observations from a shallow-water model initialized with initial state variables. Keeping in mind the computational limitations, the sample size has been reduced to 20 from 100, as taken in the original script. The output is stored in `data/generated`.\n", "\n", "