diff --git a/api/DataArray.html b/api/DataArray.html index 0f83c13c5..97822d62e 100644 --- a/api/DataArray.html +++ b/api/DataArray.html @@ -421,7 +421,7 @@

DataArray

Examples

-
+
import pandas as pd
 import mikeio
 
@@ -818,7 +818,7 @@ 

Examples

-
+
da1 = mikeio.read("../data/HD2D.dfsu", time=[0,1])[0]
 da2 = mikeio.read("../data/HD2D.dfsu", time=[2,3])[0]
 da1.time
@@ -826,7 +826,7 @@

+
da3 = mikeio.DataArray.concat([da1,da2])
 da3
@@ -1135,7 +1135,7 @@

interp_na

Wrapper of xarray.DataArray.interpolate_na

Examples

-
+
import numpy as np
 import pandas as pd
 time = pd.date_range("2000", periods=3, freq="D")
@@ -1150,7 +1150,7 @@ 

+
da.interp_na()
<mikeio.DataArray>
@@ -1339,7 +1339,7 @@ 

Examples

-
+
da = mikeio.read("../data/europe_wind_long_lat.dfs2")[0]
 da
@@ -1350,7 +1350,7 @@

+
da.isel(time=-1)
<mikeio.DataArray>
@@ -1360,7 +1360,7 @@ 

+
da.isel(x=slice(10,20), y=slice(40,60))
<mikeio.DataArray>
@@ -1370,7 +1370,7 @@ 

+
da = mikeio.read("../data/oresund_sigma_z.dfsu").Temperature
 da.isel(element=range(200))
@@ -2061,7 +2061,7 @@

Examples

-
+
da = mikeio.read("../data/random.dfs1")[0]
 da
@@ -2072,7 +2072,7 @@

+
da.sel(time=slice(None, "2012-1-1 00:02"))
<mikeio.DataArray>
@@ -2082,7 +2082,7 @@ 

+
da.sel(x=100)
<mikeio.DataArray>
@@ -2093,7 +2093,7 @@ 

+
da = mikeio.read("../data/oresund_sigma_z.dfsu").Temperature
 da
@@ -2109,7 +2109,7 @@

+
da.sel(time="1997-09-15")
<mikeio.DataArray>
@@ -2125,7 +2125,7 @@ 

+
da.sel(x=340000, y=6160000, z=-3)
<mikeio.DataArray>
@@ -2136,7 +2136,7 @@ 

+
da.sel(layers="bottom")
<mikeio.DataArray>
diff --git a/api/Dataset.html b/api/Dataset.html
index c1700d466..f21b050fe 100644
--- a/api/Dataset.html
+++ b/api/Dataset.html
@@ -438,7 +438,7 @@ 

Examples

-
+
import mikeio
 mikeio.read("../data/europe_wind_long_lat.dfs2")
diff --git a/api/EUMType.html b/api/EUMType.html index ba3881d66..94e2c2349 100644 --- a/api/EUMType.html +++ b/api/EUMType.html @@ -370,14 +370,14 @@

EUMType

EUM type

Examples

-
+
import mikeio
 mikeio.EUMType.Temperature
Temperature
-
+
mikeio.EUMType.Temperature.units
[degree Celsius, degree Fahrenheit, degree Kelvin]
diff --git a/api/EUMUnit.html b/api/EUMUnit.html index ae7d700c6..24b5de04d 100644 --- a/api/EUMUnit.html +++ b/api/EUMUnit.html @@ -370,7 +370,7 @@

EUMUnit

EUM unit

Examples

-
+
import mikeio
 mikeio.EUMUnit.degree_Kelvin
diff --git a/api/Grid1D.html b/api/Grid1D.html index b531020be..c8db5bc8b 100644 --- a/api/Grid1D.html +++ b/api/Grid1D.html @@ -463,7 +463,7 @@

Examples

-
+
import mikeio
 mikeio.Grid1D(nx=3,dx=0.1)
@@ -471,7 +471,7 @@

x: [0, 0.1, 0.2] (nx=3, dx=0.1)

-
+
mikeio.Grid1D(x=[0.1, 0.5, 0.9])
<mikeio.Grid1D>
@@ -657,7 +657,7 @@ 

Examples

-
+
import mikeio
 g = mikeio.Grid1D(nx=3,dx=0.1)
 g
@@ -666,14 +666,14 @@

+
g.isel([1,2])
<mikeio.Grid1D>
 x: [0.1, 0.2] (nx=2, dx=0.1)
-
+
g.isel(1)
GeometryUndefined()
diff --git a/api/ItemInfo.html b/api/ItemInfo.html index 490c8444c..bbdea9888 100644 --- a/api/ItemInfo.html +++ b/api/ItemInfo.html @@ -425,14 +425,14 @@

Examples

-
+
import mikeio
 mikeio.ItemInfo("Viken", mikeio.EUMType.Water_Level)
Viken <Water Level> (meter)
-
+
mikeio.ItemInfo(mikeio.EUMType.Wind_speed)
Wind speed <Wind speed> (meter per sec)
diff --git a/api/Mesh.html b/api/Mesh.html index 4266439da..3b1e01ed6 100644 --- a/api/Mesh.html +++ b/api/Mesh.html @@ -416,7 +416,7 @@

Examples

-
+
import mikeio
 mikeio.Mesh("../data/odense_rough.mesh")
@@ -472,7 +472,7 @@

Re

Examples

-
+
import mikeio
 msh = mikeio.open("../data/odense_rough.mesh")
 msh.to_shapely()
diff --git a/api/PfsDocument.html b/api/PfsDocument.html index 18776f901..4e39ce964 100644 --- a/api/PfsDocument.html +++ b/api/PfsDocument.html @@ -577,7 +577,7 @@

Examples

-
+
import pandas as pd
 import mikeio
 df = pd.DataFrame(dict(station=["Foo", "Bar"],include=[0,1]), index=[1,2])
@@ -611,7 +611,7 @@ 

-
+
mikeio.PfsSection.from_dataframe(df,"STATION_")
[STATION_1]
@@ -779,7 +779,7 @@ 

Examples

-
+
pfs = mikeio.read_pfs("../data/pfs/lake.sw")
 pfs.SW.OUTPUTS.to_dataframe(prefix="OUTPUT_")
diff --git a/api/PfsSection.html b/api/PfsSection.html index bdbf1f917..5e5b0edd2 100644 --- a/api/PfsSection.html +++ b/api/PfsSection.html @@ -496,7 +496,7 @@

Examples

-
+
import pandas as pd
 import mikeio
 df = pd.DataFrame(dict(station=["Foo", "Bar"],include=[0,1]), index=[1,2])
@@ -530,7 +530,7 @@ 

-
+
mikeio.PfsSection.from_dataframe(df,"STATION_")
[STATION_1]
@@ -693,7 +693,7 @@ 

Examples

-
+
pfs = mikeio.read_pfs("../data/pfs/lake.sw")
 pfs.SW.OUTPUTS.to_dataframe(prefix="OUTPUT_")
diff --git a/api/dataset._data_plot._DataArrayPlotterFM.html b/api/dataset._data_plot._DataArrayPlotterFM.html index 12c4f2464..505e3fcab 100644 --- a/api/dataset._data_plot._DataArrayPlotterFM.html +++ b/api/dataset._data_plot._DataArrayPlotterFM.html @@ -381,7 +381,7 @@

dataset._data_plot._DataArrayPlotterFM

If DataArray is 3D the surface layer will be plotted.

Examples

-
+
import mikeio
 da = mikeio.read("../data/HD2D.dfsu")["Surface elevation"]
 da.plot()
@@ -440,7 +440,7 @@

Examples

-
+
da = mikeio.read("../data/HD2D.dfsu")["Surface elevation"]
 da.plot.contour()
@@ -459,7 +459,7 @@

Examples

-
+
da = mikeio.read("../data/HD2D.dfsu")["Surface elevation"]
 da.plot.contourf()
@@ -561,7 +561,7 @@

Examples

-
+
da = mikeio.read("../data/HD2D.dfsu")["Surface elevation"]
 da.plot.mesh()
@@ -580,7 +580,7 @@

Examples

-
+
da = mikeio.read("../data/HD2D.dfsu")["Surface elevation"]
 da.plot.outline()
@@ -599,7 +599,7 @@

Examples

-
+
da = mikeio.read("../data/HD2D.dfsu")["Surface elevation"]
 da.plot.patch()
diff --git a/api/dataset._data_plot._DataArrayPlotterFMVerticalColumn.html b/api/dataset._data_plot._DataArrayPlotterFMVerticalColumn.html index 03779bc23..dcb4ff7a2 100644 --- a/api/dataset._data_plot._DataArrayPlotterFMVerticalColumn.html +++ b/api/dataset._data_plot._DataArrayPlotterFMVerticalColumn.html @@ -376,7 +376,7 @@

dataset._data_plot._DataArrayPlotterFMVertic

If DataArray has multiple time steps, the first step will be plotted.

Examples

-
+
import mikeio
 ds = mikeio.read("../data/oresund_sigma_z.dfsu")
 dsp = ds.sel(x=333934.1, y=6158101.5)
@@ -390,7 +390,7 @@ 

-
+
da.plot(extrapolate=False, marker='o')
@@ -400,7 +400,7 @@

-
+
da.plot.pcolormesh()
@@ -410,7 +410,7 @@

-
+
da.plot.hist()
(array([1., 0., 0., 1., 1., 0., 1., 4., 1., 3.]),
diff --git a/api/dataset._data_plot._DataArrayPlotterFMVerticalProfile.html b/api/dataset._data_plot._DataArrayPlotterFMVerticalProfile.html
index 3b800e574..4a757b023 100644
--- a/api/dataset._data_plot._DataArrayPlotterFMVerticalProfile.html
+++ b/api/dataset._data_plot._DataArrayPlotterFMVerticalProfile.html
@@ -375,7 +375,7 @@ 

dataset._data_plot._DataArrayPlotterFMVertic

If DataArray has multiple time steps, the first step will be plotted.

Examples

-
+
import mikeio
 da = mikeio.read("../data/oresund_vertical_slice.dfsu")["Temperature"]
 da.plot()
@@ -387,7 +387,7 @@

-
+
da.plot.hist()
(array([  1.,   2.,  19.,  70., 202., 384., 336., 167., 127.,  15.]),
diff --git a/api/dataset._data_plot._DataArrayPlotterGrid2D.html b/api/dataset._data_plot._DataArrayPlotterGrid2D.html
index ed6662eee..a087b31b1 100644
--- a/api/dataset._data_plot._DataArrayPlotterGrid2D.html
+++ b/api/dataset._data_plot._DataArrayPlotterGrid2D.html
@@ -378,7 +378,7 @@ 

dataset._data_plot._DataArrayPlotterGrid2DIf DataArray has multiple time steps, the first step will be plotted.

Examples

-
+
import mikeio
 da = mikeio.read("../data/gebco_sound.dfs2")["Elevation"]
 da.plot()
@@ -434,7 +434,7 @@

Examples

-
+
da = mikeio.read("../data/gebco_sound.dfs2")["Elevation"]
 da.plot.contour()
@@ -459,7 +459,7 @@

Examples

-
+
da = mikeio.read("../data/gebco_sound.dfs2")["Elevation"]
 da.plot.contourf()
@@ -567,7 +567,7 @@

Examples

-
+
da = mikeio.read("../data/gebco_sound.dfs2")["Elevation"]
 da.plot.pcolormesh()
diff --git a/api/from_pandas.html b/api/from_pandas.html index 61032da13..493f6db98 100644 --- a/api/from_pandas.html +++ b/api/from_pandas.html @@ -423,7 +423,7 @@

Re

Examples

-
+
import pandas as pd
 import mikeio
 
diff --git a/api/from_polars.html b/api/from_polars.html
index 76edcb49d..8889e26c0 100644
--- a/api/from_polars.html
+++ b/api/from_polars.html
@@ -429,7 +429,7 @@ 

Re

Examples

-
+
import polars as pl
 import mikeio
 from datetime import datetime
diff --git a/examples/Dfsu-2D-interpolation.html b/examples/Dfsu-2D-interpolation.html
index 0b4f1da62..80df16e84 100644
--- a/examples/Dfsu-2D-interpolation.html
+++ b/examples/Dfsu-2D-interpolation.html
@@ -383,10 +383,10 @@ 

Dfsu - 2D interpolation

-
+
import mikeio
-
+
ds = mikeio.read("../data/wind_north_sea.dfsu", items="Wind speed")
 ds
@@ -398,7 +398,7 @@

Dfsu - 2D interpolation

0: Wind speed <Wind speed> (meter per sec)
-
+
da = ds.Wind_speed
 da.plot();
@@ -416,7 +416,7 @@

Interpolate to gridThen interpolate all data to the new grid and plot.
  • The interpolated data is then saved to a dfs2 file.
  • -
    +
    g = da.geometry.get_overset_grid(dx=0.1)
     g
    @@ -426,7 +426,7 @@

    Interpolate to grid

    -
    +
    da_grid = da.interp_like(g)
     da_grid
    @@ -437,7 +437,7 @@

    Interpolate to grid

    -
    +
    da_grid.plot();
    @@ -450,14 +450,14 @@

    Interpolate to grid

    Save to dfs2 file

    -
    +
    da_grid.to_dfs("wind_north_sea_interpolated.dfs2")

    Save to NetCDF

    -
    +
    xr_da = da_grid.to_xarray()
     xr_da.to_netcdf("wind_north_sea_interpolated.nc")
    @@ -478,7 +478,7 @@

    Save to GeoTiff

    This section requires the rasterio package.

    -
    +
    import numpy as np
     import rasterio
     from rasterio.transform import from_origin
    @@ -502,7 +502,7 @@ 

    Save to GeoTiff

    Interpolate to other mesh

    Interpolate the data from this coarse mesh onto a finer resolution mesh

    -
    +
    msh = mikeio.Mesh('../data/north_sea_2.mesh')
     msh
    @@ -512,7 +512,7 @@

    Interpolate to other mesh

    projection: LONG/LAT
    -
    +
    dsi = da.interp_like(msh)
     dsi
    @@ -523,7 +523,7 @@

    Interpolate to other mesh

    geometry: Dfsu2D (2259 elements, 1296 nodes)
    -
    +
    da[0].plot(figsize=(9,7), show_mesh=True);
    @@ -533,7 +533,7 @@

    Interpolate to other mesh

    -
    +
    dsi[0].plot(figsize=(9,7), show_mesh=True);
    @@ -545,14 +545,14 @@

    Interpolate to other mesh

    Note: 3 of the new elements are outside the original mesh and data are therefore NaN by default

    -
    +
    nan_elements = np.where(np.isnan(dsi[0].to_numpy()))[0]
     nan_elements
    array([ 249,  451, 1546])
    -
    +
    da.geometry.contains(msh.element_coordinates[nan_elements,:2])
    array([False, False, False])
    @@ -561,10 +561,10 @@

    We can force extrapolation to avoid the NaN values

    -
    +
    dat_interp = da.interp_like(msh, extrapolate=True)
    -
    +
    n_nan_elements = np.sum(np.isnan(dat_interp.values))
     n_nan_elements
    @@ -577,14 +577,14 @@

    Interpola

    We want to interpolate scatter data onto an existing mesh and create a new dfsu with the interpolated data.

    This uses lower level private utility methods not part of the public API.

    Interpolating from scatter data will soon be possible in a simpler way.

    -
    +
    from mikeio.spatial._utils import dist_in_meters
     from mikeio._interpolation import get_idw_interpolant
    -
    +
    dfs = mikeio.open("../data/wind_north_sea.dfsu")
    -
    +
    dfs.geometry.plot.mesh();
    @@ -594,7 +594,7 @@

    Interpola

    -
    +
    # scatter data: x,y,value for 4 points
     scatter= np.array([[1,50,1], [4, 52, 3], [8, 55, 2], [-1, 55, 1.5]])
     scatter
    @@ -611,35 +611,35 @@

    Interpola
  • calc IDW interpolatant weights
  • Interpolate
  • -
    +
    dist = dist_in_meters(scatter[:,:2], dfs.geometry.element_coordinates[0,:2])
     dist
    array([4.00139539, 3.18881018, 6.58769411, 2.69722991])
    -
    +
    w = get_idw_interpolant(dist, p=2)
     w
    array([0.19438779, 0.30607974, 0.07171749, 0.42781498])
    -
    +
    np.dot(scatter[:,2], w) # interpolated value in element 0
    np.float64(1.8977844597276883)

    Let’s do the same for all points in the mesh and plot in the end

    -
    +
    dati = np.zeros((1, dfs.geometry.n_elements))
     for j in range(dfs.geometry.n_elements):
         dist = dist_in_meters(scatter[:, :2], dfs.geometry.element_coordinates[j, :2])
         w = get_idw_interpolant(dist, p=2)
         dati[0, j] = np.dot(scatter[:, 2], w)
    -
    +
    da = mikeio.DataArray(data=dati, geometry=dfs.geometry, time=dfs.start_time)
     da
    @@ -650,7 +650,7 @@

    Interpola geometry: Dfsu2D (958 elements, 570 nodes)

    -
    +
    da.plot(title="Interpolated scatter data");
    @@ -660,13 +660,13 @@

    Interpola

    -
    +
    da.to_dfs("interpolated_scatter.dfsu")

    Clean up

    -
    +
    import os
     
     os.remove("wind_north_sea_interpolated.dfs2")
    diff --git a/examples/Generic.html b/examples/Generic.html
    index 3b075f881..dac9fa20e 100644
    --- a/examples/Generic.html
    +++ b/examples/Generic.html
    @@ -394,7 +394,7 @@ 

    Generic dfs processing

  • quantile: Create temporal quantiles of dfs file
  • -
    +
    import matplotlib.pyplot as plt
     import mikeio
     import mikeio.generic
    @@ -402,7 +402,7 @@

    Generic dfs processing

    Concatenation

    Take a look at these two files with overlapping timesteps.

    -
    +
    t1 = mikeio.read("../data/tide1.dfs1")
     t1
    @@ -414,7 +414,7 @@

    Concatenation

    0: Level <Water Level> (meter)
    -
    +
    t2 = mikeio.read("../data/tide2.dfs1")
     t2
    @@ -427,7 +427,7 @@

    Concatenation

    Plot one of the points along the line.

    -
    +
    plt.plot(t1.time,t1[0].isel(x=1).values, label="File 1")
     plt.plot(t2.time,t2[0].isel(x=1).values,'k+', label="File 2")
     plt.legend()
    @@ -439,15 +439,15 @@

    Concatenation

    -
    +
    mikeio.generic.concat(infilenames=["../data/tide1.dfs1",
                                        "../data/tide2.dfs1"],
                          outfilename="concat.dfs1")
    -
      0%|          | 0/2 [00:00<?, ?it/s]100%|██████████| 2/2 [00:00<00:00, 650.89it/s]
    +
      0%|          | 0/2 [00:00<?, ?it/s]100%|██████████| 2/2 [00:00<00:00, 661.25it/s]
    -
    +
    c = mikeio.read("concat.dfs1")
     c[0].isel(x=1).plot()
     c
    @@ -471,16 +471,16 @@

    Concatenation

    Difference between two files

    Take difference between two dfs files with same structure - e.g. to see the difference in result between two calibration runs

    -
    +
    fn1 = "../data/oresundHD_run1.dfsu"
     fn2 = "../data/oresundHD_run2.dfsu"
     fn_diff = "oresundHD_difference.dfsu"
     mikeio.generic.diff(fn1, fn2, fn_diff)
    -
      0%|          | 0/5 [00:00<?, ?it/s]100%|██████████| 5/5 [00:00<00:00, 2973.00it/s]
    +
      0%|          | 0/5 [00:00<?, ?it/s]100%|██████████| 5/5 [00:00<00:00, 3034.07it/s]
    -
    +
    _, ax = plt.subplots(1,3, sharey=True, figsize=(12,5))
     da = mikeio.read(fn1, time=-1)[0]
     da.plot(vmin=0.06, vmax=0.27, ax=ax[0], title='run 1')
    @@ -504,11 +504,11 @@ 

    Extract time s
  • time slice by specifying start and/or end
  • specific items
  • -
    +
    infile = "../data/tide1.dfs1"
     mikeio.generic.extract(infile, "extracted.dfs1", start='2019-01-02')
    -
    +
    e = mikeio.read("extracted.dfs1")
     e
    @@ -520,11 +520,11 @@

    Extract time s 0: Level <Water Level> (meter)

    -
    +
    infile = "../data/oresund_vertical_slice.dfsu"
     mikeio.generic.extract(infile, "extracted.dfsu", items='Salinity', end=-2)
    -
    +
    e = mikeio.read("extracted.dfsu")
     e
    @@ -545,7 +545,7 @@

    Extract time s

    Scaling

    Adding a constant e.g to adjust datum

    -
    +
    ds = mikeio.read("../data/gebco_sound.dfs2")
     ds.Elevation[0].plot();
    @@ -556,23 +556,23 @@

    Scaling

    -
    +
    ds['Elevation'][0,104,131].to_numpy()
    np.float32(-1.0)

    This is the processing step.

    -
    +
    mikeio.generic.scale("../data/gebco_sound.dfs2", 
                          "gebco_sound_local_datum.dfs2",
                          offset=-2.1
                          )
    -
      0%|          | 0/1 [00:00<?, ?it/s]100%|██████████| 1/1 [00:00<00:00, 1870.79it/s]
    +
      0%|          | 0/1 [00:00<?, ?it/s]100%|██████████| 1/1 [00:00<00:00, 1261.82it/s]
    -
    +
    ds2 = mikeio.read("gebco_sound_local_datum.dfs2")
     ds2['Elevation'][0].plot()
    @@ -583,7 +583,7 @@

    Scaling

    -
    +
    ds2['Elevation'][0,104,131].to_numpy()
    np.float32(-3.1)
    @@ -591,7 +591,7 @@

    Scaling

    Spatially varying correction

    -
    +
    import numpy as np
     factor = np.ones_like(ds['Elevation'][0].to_numpy())
     factor.shape
    @@ -600,7 +600,7 @@

    Spatially var

    Add some spatially varying factors, exaggerated values for educational purpose.

    -
    +
    factor[:,0:100] = 5.3
     factor[0:40,] = 0.1
     factor[150:,150:] = 10.7
    @@ -615,7 +615,7 @@ 

    Spatially var

    The 2d array must first be flipped upside down and then converted to a 1d vector using numpy.ndarray.flatten to match how data is stored in dfs files.

    -
    +
    factor_ud = np.flipud(factor)
     factor_vec  = factor_ud.flatten()
     mikeio.generic.scale("../data/gebco_sound.dfs2", 
    @@ -623,10 +623,10 @@ 

    Spatially var factor=factor_vec )

    -
      0%|          | 0/1 [00:00<?, ?it/s]100%|██████████| 1/1 [00:00<00:00, 1079.34it/s]
    +
      0%|          | 0/1 [00:00<?, ?it/s]100%|██████████| 1/1 [00:00<00:00, 1783.29it/s]
    -
    +
    ds3 = mikeio.read("gebco_sound_spatial.dfs2")
     ds3.Elevation[0].plot();
    @@ -641,15 +641,15 @@

    Spatially var

    Time average

    -
    +
    fn = "../data/NorthSea_HD_and_windspeed.dfsu"
     fn_avg = "Avg_NorthSea_HD_and_windspeed.dfsu"
     mikeio.generic.avg_time(fn, fn_avg)
    -
      0%|          | 0/66 [00:00<?, ?it/s]100%|██████████| 66/66 [00:00<00:00, 18895.84it/s]
    +
      0%|          | 0/66 [00:00<?, ?it/s]100%|██████████| 66/66 [00:00<00:00, 22422.17it/s]
    -
    +
    ds = mikeio.read(fn)
     ds.mean(axis=0).describe()   # alternative way of getting the time average
    @@ -711,7 +711,7 @@

    Time average

    -
    +
    ds_avg = mikeio.read(fn_avg)
     ds_avg.describe()
    @@ -777,12 +777,12 @@

    Time average

    Quantile

    Example that calculates the 25%, 50% and 75% percentile for all items in a dfsu file.

    -
    +
    fn = "../data/NorthSea_HD_and_windspeed.dfsu"
     fn_q = "Q_NorthSea_HD_and_windspeed.dfsu"
     mikeio.generic.quantile(fn, fn_q, q=[0.25,0.5,0.75])
    -
    +
    ds = mikeio.read(fn_q)
     ds
    @@ -799,7 +799,7 @@

    Quantile

    5: Quantile 0.75, Wind speed <Wind speed> (meter per sec)
    -
    +
    da_q75 = ds["Quantile 0.75, Wind speed"]
     da_q75.plot(title="75th percentile, wind speed", label="m/s")
    @@ -813,7 +813,7 @@

    Quantile

    Clean up

    -
    +
    import os
     os.remove("concat.dfs1")
     os.remove("oresundHD_difference.dfsu")
    diff --git a/examples/Time-interpolation.html b/examples/Time-interpolation.html
    index 76bfd8786..1a2c1f180 100644
    --- a/examples/Time-interpolation.html
    +++ b/examples/Time-interpolation.html
    @@ -376,11 +376,11 @@ 

    Time interpolation

    -
    +
    import numpy as np
     import mikeio
    -
    +
    ds = mikeio.read("../data/waves.dfs2")
     ds
    @@ -397,7 +397,7 @@

    Time interpolation

    Interpolate to specific timestep

    A common use case is to interpolate to a shorter timestep, in this case 1h.

    -
    +
    ds_h = ds.interp_time(3600)
     ds_h
    @@ -412,14 +412,14 @@

    Interpola

    And to store the interpolated data in a new file.

    -
    +
    ds_h.to_dfs("waves_3h.dfs2")

    Interpolate to time axis of another dataset

    Read some non-equidistant data typically found in observed data.

    -
    +
    ts = mikeio.read("../data/waves.dfs0")
     ts
    @@ -434,10 +434,10 @@

    +
    dsi = ds.interp_time(ts)
    -
    +
    dsi.time
    DatetimeIndex(['2004-01-01 01:00:00', '2004-01-01 02:00:00',
    @@ -455,13 +455,13 @@ 

    +
    dsi["Sign. Wave Height"].shape
    (24, 31, 31)
    -
    +
    ax = dsi["Sign. Wave Height"].sel(x=250, y=1200).plot(marker='+')
     ts["Sign. Wave Height"].plot(ax=ax,marker='+')
    @@ -479,7 +479,7 @@

    Model validation

    In the example below we calculate this metric using the model data interpolated to the observed times.

    For a more elaborate model validation library which takes care of these things for you as well as calculating a number of relevant metrics, take a look at `ModelSkill.

    Use np.nanmean to skip NaN.

    -
    +
    ts["Sign. Wave Height"]
    <mikeio.DataArray>
    @@ -490,7 +490,7 @@ 

    Model validation

    values: [0.06521, 0.06771, ..., 0.0576]
    -
    +
    dsi["Sign. Wave Height"].sel(x=250, y=1200)
    <mikeio.DataArray>
    @@ -501,7 +501,7 @@ 

    Model validation

    values: [0.0387, 0.03939, ..., nan]
    -
    +
    diff = (ts["Sign. Wave Height"]  - dsi["Sign. Wave Height"].sel(x=250, y=1200))
     diff.plot()
    @@ -512,7 +512,7 @@

    Model validation

    -
    +
    mae = np.abs(diff).nanmean().to_numpy()
     mae
    @@ -522,7 +522,7 @@

    Model validation

    Clean up

    -
    +
    import os
     os.remove("waves_3h.dfs2")
    diff --git a/examples/dfs2/bathy.html b/examples/dfs2/bathy.html index 8589c5213..842b83e94 100644 --- a/examples/dfs2/bathy.html +++ b/examples/dfs2/bathy.html @@ -377,11 +377,11 @@

    Dfs2 - Bathymetric data

    GEBCO Compilation Group (2020) GEBCO 2020 Grid (doi:10.5285/a29c5465-b138-234d-e053-6c86abc040b9)

    -
    +
    import xarray
     import mikeio
    -
    +
    ds = xarray.open_dataset("../../data/gebco_2020_n56.3_s55.2_w12.2_e13.1.nc")
     ds
    @@ -759,7 +759,7 @@

    Dfs2 - Bathymetric data

    Coordinates: (2) Data variables: elevation (lat, lon) int16 114kB ... -Attributes: (8)
  • Conventions :
    CF-1.6
    title :
    The GEBCO_2020 Grid - a continuous terrain model for oceans and land at 15 arc-second intervals
    institution :
    On behalf of the General Bathymetric Chart of the Oceans (GEBCO), the data are held at the British Oceanographic Data Centre (BODC).
    source :
    The GEBCO_2020 Grid is the latest global bathymetric product released by the General Bathymetric Chart of the Oceans (GEBCO) and has been developed through the Nippon Foundation-GEBCO Seabed 2030 Project. This is a collaborative project between the Nippon Foundation of Japan and GEBCO. The Seabed 2030 Project aims to bring together all available bathymetric data to produce the definitive map of the world ocean floor and make it available to all.
    history :
    Information on the development of the data set and the source data sets included in the grid can be found in the data set documentation available from https://www.gebco.net
    references :
    DOI: 10.5285/a29c5465-b138-234d-e053-6c86abc040b9
    comment :
    The data in the GEBCO_2020 Grid should not be used for navigation or any purpose relating to safety at sea.
    node_offset :
    1.0
  • -
    +
    ds.elevation.plot();
    @@ -790,7 +790,7 @@

    Dfs2 - Bathymetric data

    -
    +
    ds.elevation.sel(lon=12.74792, lat=55.865, method="nearest")
    @@ -1165,17 +1165,17 @@

    Dfs2 - Bathymetric data

    <xarray.DataArray 'elevation' ()> Size: 2B
     [1 values with dtype=int16]
     Coordinates: (2)
    -Attributes: (7)
    +Attributes: (7)

    Check ordering of dimensions, should be (y,x)

    -
    +
    ds.elevation.dims
    ('lat', 'lon')
    -
    +
    el = ds.elevation.values
     el.shape
    @@ -1183,37 +1183,37 @@

    Dfs2 - Bathymetric data

    Check that axes are increasing, S->N W->E

    -
    +
    ds.lat.values[0],ds.lat.values[-1] 
    (np.float64(55.20208333333332), np.float64(56.29791666666665))
    -
    +
    ds.lat.values[0] < ds.lat.values[-1] 
    np.True_
    -
    +
    ds.lon.values[0],ds.lon.values[-1] 
    (np.float64(12.20208333333332), np.float64(13.097916666666663))
    -
    +
    el[0,0] # Bottom left
    np.int16(-8)
    -
    +
    el[-1,0] # Top Left
    np.int16(-31)
    -
    +
    geometry = mikeio.Grid2D(x=ds.lon.values, y=ds.lat.values, projection="LONG/LAT")
     geometry
    @@ -1223,7 +1223,7 @@

    Dfs2 - Bathymetric data

    projection: LONG/LAT
    -
    +
    da = mikeio.DataArray(data=el,
                    item=mikeio.ItemInfo("Elevation", mikeio.EUMType.Total_Water_Depth),
                    geometry=geometry,
    @@ -1238,7 +1238,7 @@ 

    Dfs2 - Bathymetric data

    geometry: Grid2D (ny=264, nx=216)
    -
    +
    da.plot();
    @@ -1248,7 +1248,7 @@

    Dfs2 - Bathymetric data

    -
    +
    da.plot(cmap='coolwarm', vmin=-100, vmax=100);
    @@ -1258,10 +1258,10 @@

    Dfs2 - Bathymetric data

    -
    +
    da.to_dfs("gebco.dfs2")
    -
    +
    ds = mikeio.read("gebco.dfs2")
     ds.Elevation.plot()
    @@ -1274,7 +1274,7 @@

    Dfs2 - Bathymetric data

    Clean up

    -
    +
    import os
     
     os.remove("gebco.dfs2")
    diff --git a/examples/dfs2/gfs.html b/examples/dfs2/gfs.html index 06e2880f3..6ab59c552 100644 --- a/examples/dfs2/gfs.html +++ b/examples/dfs2/gfs.html @@ -380,13 +380,13 @@

    Dfs2 - Meteo data

    -
    +
    import xarray
     import pandas as pd
     import mikeio

    The file gfs_wind.nc contains a small sample of the GFS forecast data downloaded via their OpenDAP service

    -
    +
    ds = xarray.open_dataset('../../data/gfs_wind.nc')
     ds
    @@ -766,30 +766,30 @@

    Dfs2 - Meteo data

    msletmsl (time, lat, lon) float32 10kB ... ugrd10m (time, lat, lon) float32 10kB ... vgrd10m (time, lat, lon) float32 10kB ... -Attributes: (4)

    Running a Mike 21 HD model, needs at least three variables of meteorological forcing * Mean Sea Level Pressure * U 10m * V 10m

    Let’s take a look the U 10m

    -
    +
    ds.ugrd10m.isel(time=0).plot();
    @@ -803,7 +803,7 @@

    Dfs2 - Meteo data

    Convert to dfs2

    Time

    -
    +
    time = pd.DatetimeIndex(ds.time)
     time
    @@ -815,36 +815,36 @@

    Time

    Variable types

    -
    +
    mikeio.EUMType.Air_Pressure
    Air Pressure
    -
    +
    mikeio.EUMType.Air_Pressure.units
    [hectopascal, millibar]
    -
    +
    mikeio.EUMType.Wind_Velocity
    Wind Velocity
    -
    +
    mikeio.EUMType.Wind_Velocity.units
    [meter per sec, feet per sec, miles per hour, km per hour, knot]
    -
    +
    mslp = ds.msletmsl.values / 100 # conversion from Pa to hPa
     u = ds.ugrd10m.values
     v = ds.vgrd10m.values
    -
    +
    geometry = mikeio.Grid2D(x=ds.lon.values, y=ds.lat.values, projection="LONG/LAT")
     geometry
    @@ -854,14 +854,14 @@

    Variable types

    projection: LONG/LAT
    -
    +
    from mikeio import ItemInfo, EUMType, EUMUnit
     
     mslp_da = mikeio.DataArray(data=mslp,time=time, geometry=geometry, item=ItemInfo("Mean Sea Level Pressure", EUMType.Air_Pressure, EUMUnit.hectopascal))
     u_da = mikeio.DataArray(data=u,time=time, geometry=geometry, item=ItemInfo("Wind U", EUMType.Wind_Velocity, EUMUnit.meter_per_sec))
     v_da = mikeio.DataArray(data=v,time=time, geometry=geometry, item=ItemInfo("Wind V", EUMType.Wind_Velocity, EUMUnit.meter_per_sec))
    -
    +
    mds = mikeio.Dataset([mslp_da, u_da, v_da])
     mds
    @@ -875,11 +875,11 @@

    Variable types

    2: Wind V <Wind Velocity> (meter per sec)
    -
    +
    mds.to_dfs("gfs.dfs2")

    Clean up

    -
    +
    import os
     
     os.remove("gfs.dfs2")
    diff --git a/examples/index.html b/examples/index.html index 813fe85e1..7e7b1d4fd 100644 --- a/examples/index.html +++ b/examples/index.html @@ -456,7 +456,7 @@

    Examples

    - + Dfs2 - Bathymetric data @@ -464,7 +464,7 @@

    Examples

    Convert GEBCO 2020 NetCDF to dfs2 - + Dfs2 - Meteo data @@ -472,7 +472,7 @@

    Examples

    Conversion of NetCDF from Global Forecasting System to Dfs2 - + Dfs2 examples @@ -483,7 +483,7 @@

    Examples

    - + Dfsu - 2D interpolation @@ -491,7 +491,7 @@

    Examples

    Interpolate dfsu data to a grid, save as dfs2 and geotiff. Interpolate dfsu data to another mesh. - + Generic dfs processing @@ -499,7 +499,7 @@

    Examples

    Tools and methods that applies to any type of dfs files. - + Time interpolation diff --git a/index.html b/index.html index 68f002c5a..2900b303e 100644 --- a/index.html +++ b/index.html @@ -388,7 +388,7 @@

    Installation

    Getting started

    -
    +
    import mikeio
     
     ds = mikeio.read("data/FakeLake.dfsu")
    diff --git a/search.json b/search.json
    index 68e707335..70f4995fa 100644
    --- a/search.json
    +++ b/search.json
    @@ -593,7 +593,7 @@
         "href": "examples/Generic.html#concatenation",
         "title": "Generic dfs processing",
         "section": "Concatenation",
    -    "text": "Concatenation\nTake a look at these two files with overlapping timesteps.\n\nt1 = mikeio.read(\"../data/tide1.dfs1\")\nt1\n\n<mikeio.Dataset>\ndims: (time:97, x:10)\ntime: 2019-01-01 00:00:00 - 2019-01-03 00:00:00 (97 records)\ngeometry: Grid1D (n=10, dx=0.06667)\nitems:\n  0:  Level <Water Level> (meter)\n\n\n\nt2 = mikeio.read(\"../data/tide2.dfs1\")\nt2\n\n<mikeio.Dataset>\ndims: (time:97, x:10)\ntime: 2019-01-02 00:00:00 - 2019-01-04 00:00:00 (97 records)\ngeometry: Grid1D (n=10, dx=0.06667)\nitems:\n  0:  Level <Water Level> (meter)\n\n\nPlot one of the points along the line.\n\nplt.plot(t1.time,t1[0].isel(x=1).values, label=\"File 1\")\nplt.plot(t2.time,t2[0].isel(x=1).values,'k+', label=\"File 2\")\nplt.legend()\n\n\n\n\n\n\n\n\n\nmikeio.generic.concat(infilenames=[\"../data/tide1.dfs1\",\n                                   \"../data/tide2.dfs1\"],\n                     outfilename=\"concat.dfs1\")\n\n  0%|          | 0/2 [00:00<?, ?it/s]100%|██████████| 2/2 [00:00<00:00, 650.89it/s]\n\n\n\nc = mikeio.read(\"concat.dfs1\")\nc[0].isel(x=1).plot()\nc\n\n<mikeio.Dataset>\ndims: (time:145, x:10)\ntime: 2019-01-01 00:00:00 - 2019-01-04 00:00:00 (145 records)\ngeometry: Grid1D (n=10, dx=0.06667)\nitems:\n  0:  Level <Water Level> (meter)",
    +    "text": "Concatenation\nTake a look at these two files with overlapping timesteps.\n\nt1 = mikeio.read(\"../data/tide1.dfs1\")\nt1\n\n<mikeio.Dataset>\ndims: (time:97, x:10)\ntime: 2019-01-01 00:00:00 - 2019-01-03 00:00:00 (97 records)\ngeometry: Grid1D (n=10, dx=0.06667)\nitems:\n  0:  Level <Water Level> (meter)\n\n\n\nt2 = mikeio.read(\"../data/tide2.dfs1\")\nt2\n\n<mikeio.Dataset>\ndims: (time:97, x:10)\ntime: 2019-01-02 00:00:00 - 2019-01-04 00:00:00 (97 records)\ngeometry: Grid1D (n=10, dx=0.06667)\nitems:\n  0:  Level <Water Level> (meter)\n\n\nPlot one of the points along the line.\n\nplt.plot(t1.time,t1[0].isel(x=1).values, label=\"File 1\")\nplt.plot(t2.time,t2[0].isel(x=1).values,'k+', label=\"File 2\")\nplt.legend()\n\n\n\n\n\n\n\n\n\nmikeio.generic.concat(infilenames=[\"../data/tide1.dfs1\",\n                                   \"../data/tide2.dfs1\"],\n                     outfilename=\"concat.dfs1\")\n\n  0%|          | 0/2 [00:00<?, ?it/s]100%|██████████| 2/2 [00:00<00:00, 661.25it/s]\n\n\n\nc = mikeio.read(\"concat.dfs1\")\nc[0].isel(x=1).plot()\nc\n\n<mikeio.Dataset>\ndims: (time:145, x:10)\ntime: 2019-01-01 00:00:00 - 2019-01-04 00:00:00 (145 records)\ngeometry: Grid1D (n=10, dx=0.06667)\nitems:\n  0:  Level <Water Level> (meter)",
         "crumbs": [
           "Home",
           "Examples",
    @@ -605,7 +605,7 @@
         "href": "examples/Generic.html#difference-between-two-files",
         "title": "Generic dfs processing",
         "section": "Difference between two files",
    -    "text": "Difference between two files\nTake difference between two dfs files with same structure - e.g. to see the difference in result between two calibration runs\n\nfn1 = \"../data/oresundHD_run1.dfsu\"\nfn2 = \"../data/oresundHD_run2.dfsu\"\nfn_diff = \"oresundHD_difference.dfsu\"\nmikeio.generic.diff(fn1, fn2, fn_diff)\n\n  0%|          | 0/5 [00:00<?, ?it/s]100%|██████████| 5/5 [00:00<00:00, 2973.00it/s]\n\n\n\n_, ax = plt.subplots(1,3, sharey=True, figsize=(12,5))\nda = mikeio.read(fn1, time=-1)[0]\nda.plot(vmin=0.06, vmax=0.27, ax=ax[0], title='run 1')\nda = mikeio.read(fn2, time=-1)[0]\nda.plot(vmin=0.06, vmax=0.27, ax=ax[1], title='run 2')\nda = mikeio.read(fn_diff, time=-1)[0]\nda.plot(vmin=-0.1, vmax=0.1, cmap='coolwarm', ax=ax[2], title='difference');",
    +    "text": "Difference between two files\nTake difference between two dfs files with same structure - e.g. to see the difference in result between two calibration runs\n\nfn1 = \"../data/oresundHD_run1.dfsu\"\nfn2 = \"../data/oresundHD_run2.dfsu\"\nfn_diff = \"oresundHD_difference.dfsu\"\nmikeio.generic.diff(fn1, fn2, fn_diff)\n\n  0%|          | 0/5 [00:00<?, ?it/s]100%|██████████| 5/5 [00:00<00:00, 3034.07it/s]\n\n\n\n_, ax = plt.subplots(1,3, sharey=True, figsize=(12,5))\nda = mikeio.read(fn1, time=-1)[0]\nda.plot(vmin=0.06, vmax=0.27, ax=ax[0], title='run 1')\nda = mikeio.read(fn2, time=-1)[0]\nda.plot(vmin=0.06, vmax=0.27, ax=ax[1], title='run 2')\nda = mikeio.read(fn_diff, time=-1)[0]\nda.plot(vmin=-0.1, vmax=0.1, cmap='coolwarm', ax=ax[2], title='difference');",
         "crumbs": [
           "Home",
           "Examples",
    @@ -629,7 +629,7 @@
         "href": "examples/Generic.html#scaling",
         "title": "Generic dfs processing",
         "section": "Scaling",
    -    "text": "Scaling\nAdding a constant e.g to adjust datum\n\nds = mikeio.read(\"../data/gebco_sound.dfs2\")\nds.Elevation[0].plot();\n\n\n\n\n\n\n\n\n\nds['Elevation'][0,104,131].to_numpy()\n\nnp.float32(-1.0)\n\n\nThis is the processing step.\n\nmikeio.generic.scale(\"../data/gebco_sound.dfs2\", \n                     \"gebco_sound_local_datum.dfs2\",\n                     offset=-2.1\n                     )\n\n  0%|          | 0/1 [00:00<?, ?it/s]100%|██████████| 1/1 [00:00<00:00, 1870.79it/s]\n\n\n\nds2 = mikeio.read(\"gebco_sound_local_datum.dfs2\")\nds2['Elevation'][0].plot()\n\n\n\n\n\n\n\n\n\nds2['Elevation'][0,104,131].to_numpy()\n\nnp.float32(-3.1)\n\n\n\nSpatially varying correction\n\nimport numpy as np\nfactor = np.ones_like(ds['Elevation'][0].to_numpy())\nfactor.shape\n\n(264, 216)\n\n\nAdd some spatially varying factors, exaggerated values for educational purpose.\n\nfactor[:,0:100] = 5.3\nfactor[0:40,] = 0.1\nfactor[150:,150:] = 10.7\nplt.imshow(factor)\nplt.colorbar();\n\n\n\n\n\n\n\n\nThe 2d array must first be flipped upside down and then converted to a 1d vector using numpy.ndarray.flatten to match how data is stored in dfs files.\n\nfactor_ud = np.flipud(factor)\nfactor_vec  = factor_ud.flatten()\nmikeio.generic.scale(\"../data/gebco_sound.dfs2\", \n                     \"gebco_sound_spatial.dfs2\",\n                     factor=factor_vec\n                     )\n\n  0%|          | 0/1 [00:00<?, ?it/s]100%|██████████| 1/1 [00:00<00:00, 1079.34it/s]\n\n\n\nds3 = mikeio.read(\"gebco_sound_spatial.dfs2\")\nds3.Elevation[0].plot();",
    +    "text": "Scaling\nAdding a constant e.g to adjust datum\n\nds = mikeio.read(\"../data/gebco_sound.dfs2\")\nds.Elevation[0].plot();\n\n\n\n\n\n\n\n\n\nds['Elevation'][0,104,131].to_numpy()\n\nnp.float32(-1.0)\n\n\nThis is the processing step.\n\nmikeio.generic.scale(\"../data/gebco_sound.dfs2\", \n                     \"gebco_sound_local_datum.dfs2\",\n                     offset=-2.1\n                     )\n\n  0%|          | 0/1 [00:00<?, ?it/s]100%|██████████| 1/1 [00:00<00:00, 1261.82it/s]\n\n\n\nds2 = mikeio.read(\"gebco_sound_local_datum.dfs2\")\nds2['Elevation'][0].plot()\n\n\n\n\n\n\n\n\n\nds2['Elevation'][0,104,131].to_numpy()\n\nnp.float32(-3.1)\n\n\n\nSpatially varying correction\n\nimport numpy as np\nfactor = np.ones_like(ds['Elevation'][0].to_numpy())\nfactor.shape\n\n(264, 216)\n\n\nAdd some spatially varying factors, exaggerated values for educational purpose.\n\nfactor[:,0:100] = 5.3\nfactor[0:40,] = 0.1\nfactor[150:,150:] = 10.7\nplt.imshow(factor)\nplt.colorbar();\n\n\n\n\n\n\n\n\nThe 2d array must first be flipped upside down and then converted to a 1d vector using numpy.ndarray.flatten to match how data is stored in dfs files.\n\nfactor_ud = np.flipud(factor)\nfactor_vec  = factor_ud.flatten()\nmikeio.generic.scale(\"../data/gebco_sound.dfs2\", \n                     \"gebco_sound_spatial.dfs2\",\n                     factor=factor_vec\n                     )\n\n  0%|          | 0/1 [00:00<?, ?it/s]100%|██████████| 1/1 [00:00<00:00, 1783.29it/s]\n\n\n\nds3 = mikeio.read(\"gebco_sound_spatial.dfs2\")\nds3.Elevation[0].plot();",
         "crumbs": [
           "Home",
           "Examples",
    @@ -641,7 +641,7 @@
         "href": "examples/Generic.html#time-average",
         "title": "Generic dfs processing",
         "section": "Time average",
    -    "text": "Time average\n\nfn = \"../data/NorthSea_HD_and_windspeed.dfsu\"\nfn_avg = \"Avg_NorthSea_HD_and_windspeed.dfsu\"\nmikeio.generic.avg_time(fn, fn_avg)\n\n  0%|          | 0/66 [00:00<?, ?it/s]100%|██████████| 66/66 [00:00<00:00, 18895.84it/s]\n\n\n\nds = mikeio.read(fn)\nds.mean(axis=0).describe()   # alternative way of getting the time average\n\n\n\n\n\n\n\n\nSurface elevation\nWind speed\n\n\n\n\ncount\n958.000000\n958.000000\n\n\nmean\n0.449857\n12.772706\n\n\nstd\n0.178127\n2.367667\n\n\nmin\n0.114355\n6.498364\n\n\n25%\n0.373691\n11.199439\n\n\n50%\n0.431747\n12.984060\n\n\n75%\n0.479224\n14.658077\n\n\nmax\n1.202888\n16.677952\n\n\n\n\n\n\n\n\nds_avg = mikeio.read(fn_avg)\nds_avg.describe()\n\n\n\n\n\n\n\n\nSurface elevation\nWind speed\n\n\n\n\ncount\n958.000000\n958.000000\n\n\nmean\n0.449857\n12.772706\n\n\nstd\n0.178127\n2.367667\n\n\nmin\n0.114355\n6.498364\n\n\n25%\n0.373691\n11.199439\n\n\n50%\n0.431747\n12.984060\n\n\n75%\n0.479224\n14.658077\n\n\nmax\n1.202888\n16.677952",
    +    "text": "Time average\n\nfn = \"../data/NorthSea_HD_and_windspeed.dfsu\"\nfn_avg = \"Avg_NorthSea_HD_and_windspeed.dfsu\"\nmikeio.generic.avg_time(fn, fn_avg)\n\n  0%|          | 0/66 [00:00<?, ?it/s]100%|██████████| 66/66 [00:00<00:00, 22422.17it/s]\n\n\n\nds = mikeio.read(fn)\nds.mean(axis=0).describe()   # alternative way of getting the time average\n\n\n\n\n\n\n\n\nSurface elevation\nWind speed\n\n\n\n\ncount\n958.000000\n958.000000\n\n\nmean\n0.449857\n12.772706\n\n\nstd\n0.178127\n2.367667\n\n\nmin\n0.114355\n6.498364\n\n\n25%\n0.373691\n11.199439\n\n\n50%\n0.431747\n12.984060\n\n\n75%\n0.479224\n14.658077\n\n\nmax\n1.202888\n16.677952\n\n\n\n\n\n\n\n\nds_avg = mikeio.read(fn_avg)\nds_avg.describe()\n\n\n\n\n\n\n\n\nSurface elevation\nWind speed\n\n\n\n\ncount\n958.000000\n958.000000\n\n\nmean\n0.449857\n12.772706\n\n\nstd\n0.178127\n2.367667\n\n\nmin\n0.114355\n6.498364\n\n\n25%\n0.373691\n11.199439\n\n\n50%\n0.431747\n12.984060\n\n\n75%\n0.479224\n14.658077\n\n\nmax\n1.202888\n16.677952",
         "crumbs": [
           "Home",
           "Examples",
    diff --git a/user-guide/dataarray.html b/user-guide/dataarray.html
    index 40d7e4adc..51f4b767d 100644
    --- a/user-guide/dataarray.html
    +++ b/user-guide/dataarray.html
    @@ -392,7 +392,7 @@ 

    DataArray

  • values - a numpy.ndarray
  • Use DataArray’s string representation to get an overview of the DataArray

    -
    +
    import mikeio
     
     ds = mikeio.read("../data/HD2D.dfsu")
    @@ -408,7 +408,7 @@ 

    DataArray

    Temporal selection

    -
    +
    da.sel(time="1985-08-06 12:00")
    <mikeio.DataArray>
    @@ -419,7 +419,7 @@ 

    +
    da["1985-8-7":]
    <mikeio.DataArray>
    @@ -433,7 +433,7 @@ 

    Spatial selection

    The sel method finds the nearest element.

    -
    +
    da.sel(x=607002, y=6906734)
    <mikeio.DataArray>
    @@ -448,17 +448,17 @@ 

    Modifying values

    You can modify the values of a DataArray by changing its values:

    -
    +
    da.values[0, 3] = 5.0

    If you wish to change values of a subset of the DataArray you should be aware of the difference between a view and a copy of the data. Similar to NumPy, MIKE IO selection method will return a view of the data when using single index and slices, but a copy of the data using fancy indexing (a list of indicies or boolean indexing). Note that prior to release 1.3, MIKE IO would always return a copy.

    It is recommended to change the values using values property directly on the original DataArray (like above), but it is also possible to change the values of the original DataArray by working on a subset DataArray if it is selected with single index or slice as explained above.

    -
    +
    da_sub = da.isel(time=0)
     da_sub.values[:] = 5.0    # will change da

    Fancy indexing will return a copy and therefore not change the original:

    -
    +
    da_sub = da.isel(time=[0,1,2])
     da_sub.values[:] = 5.0    # will NOT change da
    @@ -466,7 +466,7 @@

    Modifying values

    Plotting

    The plotting of a DataArray is context-aware meaning that plotting behaviour depends on the geometry of the DataArray being plotted.

    -
    +
    da.plot()
    @@ -476,7 +476,7 @@

    -
    +
    da.plot.contourf()
    @@ -486,7 +486,7 @@

    -
    +
    da.plot.mesh()
    @@ -507,7 +507,7 @@

    Properties

  • shape - Shape of the data
  • deletevalue - File delete value (NaN value)
  • -
    +
    da.geometry
    Flexible Mesh Geometry: Dfsu2D
    @@ -553,7 +553,7 @@ 

    Multiply or add scalar

    -
    +
    da1 = mikeio.read("../data/oresundHD_run1.dfsu", items="Surface elevation")[0]
     da2 = mikeio.read("../data/oresundHD_run2.dfsu", items="Surface elevation")[0]
     
    @@ -562,7 +562,7 @@ 

    Multiply or add sca
    np.float32(0.18681714)

    -
    +
    da1_A = da1 + 1
     da1_B = da1 - 1
     da1_A.values.mean(), da1_B.values.mean()
    @@ -570,7 +570,7 @@

    Multiply or add sca
    (np.float32(1.1868172), np.float32(-0.81318283))

    -
    +
    da1_C = da1 * 2
     da1_D = da1 / 2
     da1_C.values.mean(), da1_D.values.mean()
    @@ -582,7 +582,7 @@

    Multiply or add sca

    Difference between two DataArrays

    Assume that we have two calibration runs and we wan’t to find the difference…

    -
    +
    da_diff = da1-da2
     da_diff.plot(title="Difference");
    @@ -593,7 +593,7 @@

    Differen

    -
    +
    da_ratio = da1 / da2
     da_ratio.plot(title="", label="Ratio", vmin=0.8, vmax=1.2, levels=9, cmap="coolwarm")
    diff --git a/user-guide/dataset.html b/user-guide/dataset.html index e80912897..945a5e26b 100644 --- a/user-guide/dataset.html +++ b/user-guide/dataset.html @@ -387,7 +387,7 @@

    Dataset

  • geometry - a Geometry object with the spatial description of the data
  • Use Dataset’s string representation to get an overview of the Dataset

    -
    +
    import mikeio
     ds = mikeio.read("../data/HD2D.dfsu")
     ds
    @@ -414,7 +414,7 @@

    +
    ds.Surface_elevation
    <mikeio.DataArray>
    @@ -434,7 +434,7 @@ 

    Temporal selection

    A time slice of a Dataset can be selected in several different ways.

    -
    +
    ds.sel(time="1985-08-06 12:00")
    <mikeio.Dataset>
    @@ -448,7 +448,7 @@ 

    +
    ds["1985-8-7":]
    <mikeio.Dataset>
    @@ -466,7 +466,7 @@ 

    Spatial selection

    The sel method finds a single element.

    -
    +
    ds.sel(x=607002, y=6906734)
    <mikeio.Dataset>
    @@ -494,7 +494,7 @@ 

    Add a new item

    A common workflow is to create a new item based on existing items in a dataset.

    This can be in done in several ways. Let’s try one of the options.

    -
    +
    ds = mikeio.read("../data/NorthSea_HD_and_windspeed.dfsu")
     ds
    @@ -510,7 +510,7 @@

    Add a new item

    1. Create a copy of the DataArray
    -
    +
    ws2 = ds.Wind_speed.copy()
     ws2.plot.hist();
    @@ -524,7 +524,7 @@

    Add a new item

    1. Make the modifications, in this case we will clip the values to the interval 1-18 m/s.
    -
    +
    import numpy as np
     ws2.values = np.clip(ws2.to_numpy(), 1,18)
     ws2.plot.hist();
    @@ -539,7 +539,7 @@

    Add a new item

    1. Assign it to a new name in the dataset
    -
    +
    ds["Wind_speed_clipped"] = ws2
     ds
    @@ -556,7 +556,7 @@

    Add a new item

    1. Reorder items if necessary (See selecting items above)
    -
    +
    ds2 = ds[["Wind_speed_clipped", "Surface elevation", "Wind speed"]]
     ds2
    @@ -573,7 +573,7 @@

    Add a new item

    1. Write the new dataset to a new file
    -
    +
    ds2.to_dfs("modified.dfsu")

    diff --git a/user-guide/dfs0.html b/user-guide/dfs0.html index bbb50f89e..d105fe3eb 100644 --- a/user-guide/dfs0.html +++ b/user-guide/dfs0.html @@ -381,7 +381,7 @@

    Dfs0

    Read Dfs0 to Dataset

    -
    +
    import mikeio
     
     ds = mikeio.read("../data/da_diagnostic.dfs0")
    @@ -401,7 +401,7 @@ 

    Read Dfs0 to Dataset<

    From Dfs0 to pandas DataFrame

    -
    +
    df = ds.to_dataframe()
     df.head()
    @@ -463,7 +463,7 @@

    From Dfs0 to

    From pandas DataFrame to Dfs0

    -
    +
    import pandas as pd
     
     df = pd.read_csv(
    diff --git a/user-guide/dfs1.html b/user-guide/dfs1.html
    index fdf9382ee..47fd40bfd 100644
    --- a/user-guide/dfs1.html
    +++ b/user-guide/dfs1.html
    @@ -369,7 +369,7 @@ 

    Dfs1

    A dfs1 file contains node-based line series data. Dfs1 files do not contain enough metadata to determine their geographical position, but have a relative distance from the origo.

    -
    +
    import mikeio
     
     ds = mikeio.read("../data/tide1.dfs1")
    @@ -386,7 +386,7 @@ 

    Dfs1

    Grid 1D

    The spatial information is available in the geometry attribute (accessible from Dfs1, Dataset, and DataArray), which in the case of a dfs1 file is a Grid1D geometry.

    -
    +
    ds.geometry
    <mikeio.Grid1D>
    @@ -410,7 +410,7 @@ 

    Creating a dfs1 file<
  • Create a data array with dimensions (time, x)
  • In this example the grid consist of two points (west and east), but the same approach can be used for any number of points.

    -
    +
    import numpy as np
     import pandas as pd
     import matplotlib.pyplot as plt
    @@ -431,7 +431,7 @@ 

    Creating a dfs1 file<
    1. Create a Grid1D geometry with the number of points in the x-direction and the spacing.
    -
    +
    geometry = mikeio.Grid1D(nx=2, dx=1)
     geometry
    @@ -442,7 +442,7 @@

    Creating a dfs1 file<
    1. Create a DataArray object with the data, time, geometry, and item information.
    -
    +
    da = mikeio.DataArray(
         data,
         time=t,
    @@ -458,7 +458,7 @@ 

    Creating a dfs1 file< geometry: Grid1D (n=2, dx=1)

    -
    +
    da.plot.timeseries()
    @@ -472,7 +472,7 @@

    Creating a dfs1 file<
    1. Write to a dfs1 file.
    -
    +
    da.to_dfs("boundary.dfs1")
    diff --git a/user-guide/dfs2.html b/user-guide/dfs2.html index 879f413e3..e693dd67c 100644 --- a/user-guide/dfs2.html +++ b/user-guide/dfs2.html @@ -370,7 +370,7 @@

    Dfs2

    A dfs2 file is also called a grid series file. Values in a dfs2 file are ‘element based’, i.e. values are defined in the centre of each grid cell.

    -
    +
    import mikeio
     ds = mikeio.read("../data/gebco_sound.dfs2")
     ds
    @@ -386,7 +386,7 @@

    Dfs2

    Subset in space

    The most convenient way to subset in space is to use the sel method, which returns a new (smaller) dataset, which can be further processed or written to disk using the to_dfs method.

    -
    +
    ds.geometry
    <mikeio.Grid2D>
    @@ -395,7 +395,7 @@ 

    Subset in space

    projection: LONG/LAT
    -
    +
    ds_aoi = ds.sel(x=slice(12.5, 13.0), y=slice(55.5, 56.0))
     ds_aoi.geometry
    @@ -406,7 +406,7 @@

    Subset in space

    In order to specify an open-ended subset (i.e. where the end of the subset is the end of the domain), use None as the end of the slice.

    -
    +
    ds.sel(x=slice(None, 13.0))
    <mikeio.Dataset>
    @@ -421,7 +421,7 @@ 

    Subset in space

    Grid2D

    The spatial information is available in the geometry attribute (accessible from Dfs2, Dataset, and DataArray), which in the case of a dfs2 file is a Grid2D geometry.

    -
    +
    ds.geometry
    <mikeio.Grid2D>
    diff --git a/user-guide/dfsu.html b/user-guide/dfsu.html
    index 151232715..d07c79a33 100644
    --- a/user-guide/dfsu.html
    +++ b/user-guide/dfsu.html
    @@ -517,7 +517,7 @@ 

    MIKE IO Fle

    These properties and methods are accessible from the geometry, but also from the Mesh/Dfsu object.

    If a .dfsu file is read with mikeio.read, the returned Dataset ds will contain a Flexible Mesh Geometry geometry. If a .dfsu or a .mesh file is opened with mikeio.open, the returned object will also contain a Flexible Mesh Geometry geometry.

    -
    +
    import mikeio
     
     ds = mikeio.read("../data/oresundHD_run1.dfsu")
    @@ -529,7 +529,7 @@ 

    MIKE IO Fle projection: UTM-33

    -
    +
    dfs = mikeio.open("../data/oresundHD_run1.dfsu")
     dfs.geometry
    diff --git a/user-guide/eum.html b/user-guide/eum.html index 01e70e208..c93cf9f95 100644 --- a/user-guide/eum.html +++ b/user-guide/eum.html @@ -363,7 +363,7 @@

    EUM

  • unit - an EUMUnit
  • The ItemInfo class has some sensible defaults, thus you can specify only a name or a type. If you don’t specify a unit, the default unit for that type will be used.

    -
    +
    from mikeio import ItemInfo, EUMType, EUMUnit
     
     item = ItemInfo("Viken", EUMType.Water_Level)
    @@ -372,47 +372,47 @@ 

    EUM

    Viken <Water Level> (meter)
    -
    +
    ItemInfo(EUMType.Wind_speed)
    Wind speed <Wind speed> (meter per sec)
    -
    +
    ItemInfo("Viken", EUMType.Water_Level, EUMUnit.feet)
    Viken <Water Level> (feet)

    Matching units for specific type:

    -
    +
    EUMType.Wind_speed.units
    [meter per sec, feet per sec, knot, km per hour, miles per hour]

    Default unit:

    -
    +
    EUMType.Precipitation_Rate.units[0]
    mm per day
    -
    +
    unit = EUMType.Precipitation_Rate.units[0]
     unit
    mm per day
    -
    +
    type(unit)
    <enum 'EUMUnit'>

    a [](mikeio.EUMUnit)` is encoded as integers, which you can utilize in some MIKE applications.

    -
    +
    int(unit)
     2004
    @@ -422,7 +422,7 @@

    EUM