{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Boundary \n", "\n", "The task is to combine current velocities from an oceanographic model without tides with tidal current.\n", "\n", "* The oceanographic model data is vertically resolved and available in a vertical transect as a Dfs2 with daily timestep\n", "* The tidal model is vertically integrated and available in a line transect as a Dfs1 with hourly timestep\n", "* The spatial grid is identical\n", "\n", "## Steps\n", "1. Read data\n", "2. Interpolate in time\n", "3. Calculate $\\mathbf{U}_{combined} = \\mathbf{U}_{tide} + \\mathbf{U}_{residual}$\n", "4. Write to new dfs2" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "\n", "Dimensions: (3, 5, 11)\n", "Time: 2021-08-14 12:00:00 - 2021-08-16 12:00:00\n", "Items:\n", " 0: eastward_sea_water_velocity (meter per sec)\n", " 1: northward_sea_water_velocity (meter per sec)" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import numpy as np\n", "import matplotlib.pyplot as plt\n", "from mikeio import Dfs2, Dfs1\n", "\n", "dfs2 = Dfs2(\"../tests/testdata/uv_vertical_daily.dfs2\")\n", "ds_surge = dfs2.read()\n", "ds_surge" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "\n", "Dimensions: (721, 11)\n", "Time: 2021-08-01 00:00:00 - 2021-08-31 00:00:00\n", "Items:\n", " 0: Tidal current component (geographic North) (meter per sec)\n", " 1: Tidal current component (geographic East) (meter per sec)" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dfs1 = Dfs1(\"../tests/testdata/vu_tide_hourly.dfs1\")\n", "ds_tide = dfs1.read()\n", "ds_tide" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### 1. Interpolate in time" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "\n", "Dimensions: (721, 5, 11)\n", "Time: 2021-08-01 00:00:00 - 2021-08-31 00:00:00\n", "Items:\n", " 0: eastward_sea_water_velocity (meter per sec)\n", " 1: northward_sea_water_velocity (meter per sec)" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ds_surge_h = ds_surge.interp_time(ds_tide)\n", "ds_surge_h" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### 2. Combine\n", "\n", "**Note that the naming and order is inconsistent between the two data sources!**" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(721, 1, 11)" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "u_tide = ds_tide[\"Tidal current component (geographic East)\"].to_numpy()\n", "u_tide = np.expand_dims(u_tide, 1)\n", "u_tide.shape" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(721, 5, 11)" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "u_surge = ds_surge_h[\"eastward_sea_water_velocity\"].to_numpy()\n", "u_surge.shape" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(721, 5, 11)" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "u_combined = u_tide + u_surge\n", "u_combined.shape" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [], "source": [ "v_tide = ds_tide[\"Tidal current component (geographic North)\"].to_numpy()\n", "v_tide = np.expand_dims(v_tide, 1)\n", "v_surge = ds_surge_h[\"northward_sea_water_velocity\"].to_numpy()\n", "v_combined = v_tide + v_surge" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### 3. Write to dfs2" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "\n", "Dimensions: (721, 5, 11)\n", "Time: 2021-08-01 00:00:00 - 2021-08-31 00:00:00\n", "Items:\n", " 0: eastward_sea_water_velocity (meter per sec)\n", " 1: northward_sea_water_velocity (meter per sec)" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from mikeio import Dataset\n", "ds_combined = Dataset(data=[u_combined, v_combined],\n", " time=ds_tide.time,\n", " items=ds_surge.items)\n", "ds_combined" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "\n", "Dimensions: (49, 5, 11)\n", "Time: 2021-08-14 12:00:00 - 2021-08-16 12:00:00\n", "Items:\n", " 0: eastward_sea_water_velocity (meter per sec)\n", " 1: northward_sea_water_velocity (meter per sec)" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ds_combined = ds_combined.dropna()\n", "ds_combined" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "c:\\users\\jan\\code\\mikeio\\mikeio\\dfs.py:260: UserWarning: No coordinate system provided\n", " warnings.warn(\"No coordinate system provided\")\n" ] } ], "source": [ "dfsnew = Dfs2()\n", "\n", "dfsnew.write(\"uv_combined.dfs2\", ds_combined)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Clean up\n" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [], "source": [ "import os\n", "os.remove(\"uv_combined.dfs2\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "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.9.6" } }, "nbformat": 4, "nbformat_minor": 4 }