{ "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": [], "source": [ "import numpy as np\n", "import mikeio" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "\n", "dims: (time:3, y:5, x:11)\n", "time: 2021-08-14 12:00:00 - 2021-08-16 12:00:00 (3 records)\n", "geometry: Grid2D (ny=5, nx=11)\n", "items:\n", " 0: eastward_sea_water_velocity (meter per sec)\n", " 1: northward_sea_water_velocity (meter per sec)" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ds_surge = mikeio.read(\"../tests/testdata/uv_vertical_daily.dfs2\")\n", "ds_surge" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "\n", "dims: (time:721, x:11)\n", "time: 2021-08-01 00:00:00 - 2021-08-31 00:00:00 (721 records)\n", "geometry: Grid1D (n=11, dx=0.09818)\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": [ "ds_tide = mikeio.read(\"../tests/testdata/vu_tide_hourly.dfs1\")\n", "ds_tide" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### 1. Interpolate in time" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "\n", "dims: (time:721, y:5, x:11)\n", "time: 2021-08-01 00:00:00 - 2021-08-31 00:00:00 (721 records)\n", "geometry: Grid2D (ny=5, nx=11)\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": [], "source": [ "u_surge = ds_surge_h[\"eastward_sea_water_velocity\"]\n", "u_combined = u_surge + u_tide\n", "u_combined.item = mikeio.ItemInfo(\"U\", mikeio.EUMType.u_velocity_component)" ] }, { "cell_type": "code", "execution_count": 7, "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\"]\n", "v_combined = v_surge + v_tide\n", "v_combined.item = mikeio.ItemInfo(\"V\", mikeio.EUMType.u_velocity_component)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### 3. Write to dfs2" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [], "source": [ "ds_combined = mikeio.Dataset([u_combined, v_combined])" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "\n", "dims: (time:49, y:5, x:11)\n", "time: 2021-08-14 12:00:00 - 2021-08-16 12:00:00 (49 records)\n", "geometry: Grid2D (ny=5, nx=11)\n", "items:\n", " 0: U (meter per sec)\n", " 1: V (meter per sec)" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ds_combined = ds_combined.dropna()\n", "ds_combined" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [], "source": [ "ds_combined.to_dfs(\"uv_combined.dfs2\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Clean up\n" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [], "source": [ "import os\n", "os.remove(\"uv_combined.dfs2\")" ] } ], "metadata": { "interpreter": { "hash": "ce8098af3ce22f00283f2dbf9dff06733072d21f076b7f034380a2cf9868eeaa" }, "kernelspec": { "display_name": "Python 3.8.10 ('base')", "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.10" } }, "nbformat": 4, "nbformat_minor": 4 }