From 391a6b58a93e4dd91d8e74167a64845a01b6826f Mon Sep 17 00:00:00 2001 From: Henrik Andersson Date: Tue, 11 Jun 2024 15:47:37 +0200 Subject: [PATCH] Data array math --- docs/user-guide/dataarray.qmd | 37 ++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/docs/user-guide/dataarray.qmd b/docs/user-guide/dataarray.qmd index b3d998753..dcfe693e9 100644 --- a/docs/user-guide/dataarray.qmd +++ b/docs/user-guide/dataarray.qmd @@ -126,7 +126,7 @@ including different ways of *selecting* data: * [`aggregate()`](`mikeio.DataArray.aggregate`) - Aggregate along an axis * [`quantile()`](`mikeio.DataArray.quantile`) - Quantiles along an axis -### {{< fa calculator >}} Mathematical operations +## {{< fa calculator >}} Mathematical operations * ds + value * ds - value * ds * value @@ -136,6 +136,41 @@ and + and - between two DataArrays (if number of items and shapes conform): * ds1 + ds2 * ds1 - ds2 +## Multiply or add scalar + +```{python} +da1 = mikeio.read("../data/oresundHD_run1.dfsu", items="Surface elevation")[0] +da2 = mikeio.read("../data/oresundHD_run2.dfsu", items="Surface elevation")[0] + +da1.values.mean() +``` + +```{python} +da1_A = da1 + 1 +da1_B = da1 - 1 +da1_A.values.mean(), da1_B.values.mean() +``` + +```{python} +da1_C = da1 * 2 +da1_D = da1 / 2 +da1_C.values.mean(), da1_D.values.mean() +``` + +## Difference between two DataArrays + +Assume that we have two calibration runs and we wan't to find the difference... + +```{python} +da_diff = da1-da2 +da_diff.plot(title="Difference"); +``` + +```{python} +da_ratio = da1 / da2 +da_ratio.plot(title="", label="Ratio", vmin=0.8, vmax=1.2, levels=9, cmap="coolwarm") +``` + Other methods that also return a DataArray: * [`interp_like`](`mikeio.DataArray.interp_like`) - Spatio (temporal) interpolation (see example [Dfsu interpolation](../examples/Dfsu-2D-interpolation.qmd))