{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "1d0a5ad8",
   "metadata": {},
   "outputs": [],
   "source": [
    "%config Completer.use_jedi = False #for auto complete code"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "8a2d66a0",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3.8.13 (default, Mar 28 2022, 06:59:08) [MSC v.1916 64 bit (AMD64)]\n",
      "flopy version: 3.3.5\n"
     ]
    }
   ],
   "source": [
    "import os\n",
    "import sys\n",
    "import matplotlib as mpl\n",
    "import matplotlib.pyplot as plt\n",
    "import numpy as np\n",
    "\n",
    "try:\n",
    "    import flopy\n",
    "except:\n",
    "    fpth = os.path.abspath(os.path.join(\"..\", \"..\"))\n",
    "    sys.path.append(fpth)\n",
    "    import flopy\n",
    "\n",
    "from flopy.export import vtk\n",
    "\n",
    "print(sys.version)\n",
    "print(\"flopy version: {}\".format(flopy.__version__))\n",
    "\n",
    "np.set_printoptions(precision=4, suppress=True)\n",
    "\n",
    "sys.path.insert(0, '../src/')\n",
    "\n",
    "import warnings\n",
    "warnings.filterwarnings('ignore')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "ec0c6cab",
   "metadata": {},
   "outputs": [],
   "source": [
    "model_name = 'regional_model'\n",
    "model_path = '../examples/out/angascancha/model/'\n",
    "exe_name = '../exe/mf6.exe'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "927138f7",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "loading simulation...\n",
      "  loading simulation name file...\n",
      "  loading tdis package...\n",
      "  loading model gwf6...\n",
      "    loading package disv...\n",
      "WARNING: Unable to resolve dimension of ('gwf6', 'disv', 'cell2d', 'cell2d', 'icvert') based on shape \"ncvert\".\n",
      "    loading package ic...\n",
      "    loading package npf...\n",
      "    loading package rch...\n",
      "    loading package evt...\n",
      "    loading package drn...\n",
      "    loading package oc...\n",
      "  loading ims package regional_model...\n"
     ]
    }
   ],
   "source": [
    "#load the regional model\n",
    "sim = flopy.mf6.MFSimulation.load(model_name+'.nam',sim_ws=model_path,exe_name=exe_name)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "966c2d66",
   "metadata": {},
   "outputs": [],
   "source": [
    "workspace = '../examples/out/angascancha/vtk_files/'\n",
    "if not os.path.isdir(workspace):\n",
    "    os.makedirs(workspace, exist_ok=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "d5382615",
   "metadata": {},
   "outputs": [],
   "source": [
    "gwf = sim.get_model()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "355bd381",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['DISV', 'IC', 'NPF', 'RCHA_0', 'EVTA_0', 'DRN_0', 'OC']"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "gwf.get_package_list()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "3de35f2b",
   "metadata": {},
   "outputs": [],
   "source": [
    "disv = gwf.get_package('DISV')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "7ac2dbe8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 73388 characters]\n",
      "text/plain": [
       "<Figure size 1008x432 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "#plot aerial plot\n",
    "fig, ax = plt.subplots(figsize=(14,6))\n",
    "mapview = flopy.plot.PlotMapView(model=gwf)\n",
    "linecollection = mapview.plot_grid()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "0c6b5713",
   "metadata": {},
   "outputs": [],
   "source": [
    "model_output_dir = os.path.join(workspace, \"model_output_test\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "801576b8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'../examples/out/angascancha/vtk_files/model_output_test'"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "gwf.export(model_output_dir, fmt=\"vtk\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "7fb9b88f",
   "metadata": {},
   "outputs": [],
   "source": [
    "# import the HeadFile reader and read in the head file\n",
    "from flopy.utils import HeadFile\n",
    "\n",
    "head_file = os.path.join(model_path, model_name+\".hds\")\n",
    "hds = HeadFile(head_file)\n",
    "\n",
    "\n",
    "# create the vtk object and export heads\n",
    "vtkobj = vtk.Vtk(gwf, xml=True, pvd=True, vertical_exageration=2)\n",
    "vtkobj.add_heads(hds)\n",
    "vtkobj.write(os.path.join(workspace, \"heads_output_test\", \"regional_model_head.vtu\"))"
   ]
  }
 ],
 "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.8.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
