{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Res1D - Modifying a res1d file" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "execution": { "iopub.execute_input": "2024-11-06T14:19:39.157261Z", "iopub.status.busy": "2024-11-06T14:19:39.156206Z", "iopub.status.idle": "2024-11-06T14:19:40.562071Z", "shell.execute_reply": "2024-11-06T14:19:40.561551Z" } }, "outputs": [], "source": [ "import mikeio1d" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "execution": { "iopub.execute_input": "2024-11-06T14:19:40.564439Z", "iopub.status.busy": "2024-11-06T14:19:40.563925Z", "iopub.status.idle": "2024-11-06T14:19:40.802071Z", "shell.execute_reply": "2024-11-06T14:19:40.801617Z" } }, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "res = mikeio1d.open(\"../tests/testdata/network.res1d\")\n", "res" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Let's load all node water level time series:" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "execution": { "iopub.execute_input": "2024-11-06T14:19:40.803861Z", "iopub.status.busy": "2024-11-06T14:19:40.803583Z", "iopub.status.idle": "2024-11-06T14:19:40.857767Z", "shell.execute_reply": "2024-11-06T14:19:40.856981Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Current maximum water level: 200.06491\n" ] } ], "source": [ "df = res.nodes.WaterLevel.read(column_mode=\"all\")\n", "print(\"Current maximum water level: \", df.max().max())" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Multiply the water level data by a factor of 2, and apply it to the mikeio1d.res1d object." ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "execution": { "iopub.execute_input": "2024-11-06T14:19:40.860341Z", "iopub.status.busy": "2024-11-06T14:19:40.859833Z", "iopub.status.idle": "2024-11-06T14:19:41.143111Z", "shell.execute_reply": "2024-11-06T14:19:41.142586Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Current maximum water level: 400.12982\n" ] } ], "source": [ "df = df * 2\n", "res.modify(df)\n", "df = res.nodes.WaterLevel.read(column_mode=\"all\")\n", "print(\"Current maximum water level: \", df.max().max())" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The modification only exists in memory. Write it to a file." ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "execution": { "iopub.execute_input": "2024-11-06T14:19:41.144918Z", "iopub.status.busy": "2024-11-06T14:19:41.144617Z", "iopub.status.idle": "2024-11-06T14:19:41.180840Z", "shell.execute_reply": "2024-11-06T14:19:41.180311Z" } }, "outputs": [], "source": [ "res.save(\"new.res1d\")" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "execution": { "iopub.execute_input": "2024-11-06T14:19:41.182516Z", "iopub.status.busy": "2024-11-06T14:19:41.182268Z", "iopub.status.idle": "2024-11-06T14:19:41.306046Z", "shell.execute_reply": "2024-11-06T14:19:41.305588Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Current maximum water level: 400.12982\n" ] } ], "source": [ "res = mikeio1d.open(\"new.res1d\")\n", "df = res.nodes.WaterLevel.read(column_mode=\"all\")\n", "print(\"Current maximum water level: \", df.max().max())" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Clean up the file created" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "execution": { "iopub.execute_input": "2024-11-06T14:19:41.307722Z", "iopub.status.busy": "2024-11-06T14:19:41.307292Z", "iopub.status.idle": "2024-11-06T14:19:41.309796Z", "shell.execute_reply": "2024-11-06T14:19:41.309376Z" } }, "outputs": [], "source": [ "import os\n", "\n", "os.remove(\"new.res1d\")" ] } ], "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.12.7" } }, "nbformat": 4, "nbformat_minor": 2 }