diff --git a/api/DataArray.html b/api/DataArray.html index 6343ed371..20be8eeec 100644 --- a/api/DataArray.html +++ b/api/DataArray.html @@ -260,7 +260,7 @@

diff --git a/api/Dataset.html b/api/Dataset.html index f31376e95..07159b072 100644 --- a/api/Dataset.html +++ b/api/Dataset.html @@ -260,7 +260,7 @@

diff --git a/api/Dfs0.html b/api/Dfs0.html index f740cd50a..db396ab59 100644 --- a/api/Dfs0.html +++ b/api/Dfs0.html @@ -226,7 +226,7 @@

diff --git a/api/Dfs1.html b/api/Dfs1.html index 8353a93b2..0349d49d2 100644 --- a/api/Dfs1.html +++ b/api/Dfs1.html @@ -226,7 +226,7 @@

diff --git a/api/Dfs2.html b/api/Dfs2.html index 37ff8d657..66447c702 100644 --- a/api/Dfs2.html +++ b/api/Dfs2.html @@ -226,7 +226,7 @@

diff --git a/api/Dfs3.html b/api/Dfs3.html index 353311768..c6297cd70 100644 --- a/api/Dfs3.html +++ b/api/Dfs3.html @@ -226,7 +226,7 @@

diff --git a/api/Dfsu.html b/api/Dfsu.html index be319bc60..2687a53ed 100644 --- a/api/Dfsu.html +++ b/api/Dfsu.html @@ -226,7 +226,7 @@

diff --git a/api/EUMType.html b/api/EUMType.html index 163eb01f9..6fa9e6377 100644 --- a/api/EUMType.html +++ b/api/EUMType.html @@ -260,7 +260,7 @@

diff --git a/api/EUMUnit.html b/api/EUMUnit.html index 3a24f9ac9..cc2bf5b38 100644 --- a/api/EUMUnit.html +++ b/api/EUMUnit.html @@ -260,7 +260,7 @@

diff --git a/api/Grid1D.html b/api/Grid1D.html index 0b87c072c..78a92c349 100644 --- a/api/Grid1D.html +++ b/api/Grid1D.html @@ -260,7 +260,7 @@

diff --git a/api/Grid2D.html b/api/Grid2D.html index 421585416..074b852fd 100644 --- a/api/Grid2D.html +++ b/api/Grid2D.html @@ -226,7 +226,7 @@

diff --git a/api/Grid3D.html b/api/Grid3D.html index 3dc058314..a4f109b04 100644 --- a/api/Grid3D.html +++ b/api/Grid3D.html @@ -226,7 +226,7 @@

diff --git a/api/ItemInfo.html b/api/ItemInfo.html index bdf400f9d..8b9c9b1d4 100644 --- a/api/ItemInfo.html +++ b/api/ItemInfo.html @@ -260,7 +260,7 @@

diff --git a/api/Mesh.html b/api/Mesh.html index a92e6b21a..f35e7c061 100644 --- a/api/Mesh.html +++ b/api/Mesh.html @@ -260,7 +260,7 @@

diff --git a/api/PfsDocument.html b/api/PfsDocument.html index fb4ddc823..b46bf0d91 100644 --- a/api/PfsDocument.html +++ b/api/PfsDocument.html @@ -260,7 +260,7 @@

diff --git a/api/PfsSection.html b/api/PfsSection.html index 057ef7abe..f95b9036e 100644 --- a/api/PfsSection.html +++ b/api/PfsSection.html @@ -260,7 +260,7 @@

diff --git a/api/dataset._data_plot._DataArrayPlotter.html b/api/dataset._data_plot._DataArrayPlotter.html index b683fee4d..7ec9480ef 100644 --- a/api/dataset._data_plot._DataArrayPlotter.html +++ b/api/dataset._data_plot._DataArrayPlotter.html @@ -226,7 +226,7 @@

diff --git a/api/dataset._data_plot._DataArrayPlotterFM.html b/api/dataset._data_plot._DataArrayPlotterFM.html index 7d40a00d9..202bab258 100644 --- a/api/dataset._data_plot._DataArrayPlotterFM.html +++ b/api/dataset._data_plot._DataArrayPlotterFM.html @@ -260,7 +260,7 @@

diff --git a/api/dataset._data_plot._DataArrayPlotterFMVerticalProfile.html b/api/dataset._data_plot._DataArrayPlotterFMVerticalProfile.html index a1626af09..706410ff9 100644 --- a/api/dataset._data_plot._DataArrayPlotterFMVerticalProfile.html +++ b/api/dataset._data_plot._DataArrayPlotterFMVerticalProfile.html @@ -260,7 +260,7 @@

diff --git a/api/dataset._data_plot._DataArrayPlotterGrid1D.html b/api/dataset._data_plot._DataArrayPlotterGrid1D.html index 07e91e233..9f27dcaf5 100644 --- a/api/dataset._data_plot._DataArrayPlotterGrid1D.html +++ b/api/dataset._data_plot._DataArrayPlotterGrid1D.html @@ -260,7 +260,7 @@

diff --git a/api/dataset._data_plot._DataArrayPlotterGrid2D.html b/api/dataset._data_plot._DataArrayPlotterGrid2D.html index e2ec526ea..d5c4cf23f 100644 --- a/api/dataset._data_plot._DataArrayPlotterGrid2D.html +++ b/api/dataset._data_plot._DataArrayPlotterGrid2D.html @@ -260,7 +260,7 @@

diff --git a/api/dfsu.Dfsu2DH.html b/api/dfsu.Dfsu2DH.html index e24e1fb9e..fb098227e 100644 --- a/api/dfsu.Dfsu2DH.html +++ b/api/dfsu.Dfsu2DH.html @@ -260,7 +260,7 @@

diff --git a/api/dfsu.Dfsu2DV.html b/api/dfsu.Dfsu2DV.html index ec73f18da..da2b1dced 100644 --- a/api/dfsu.Dfsu2DV.html +++ b/api/dfsu.Dfsu2DV.html @@ -226,7 +226,7 @@

diff --git a/api/dfsu.Dfsu3D.html b/api/dfsu.Dfsu3D.html index 9b3eff96d..1229e3e5c 100644 --- a/api/dfsu.Dfsu3D.html +++ b/api/dfsu.Dfsu3D.html @@ -226,7 +226,7 @@

diff --git a/api/dfsu.DfsuSpectral.html b/api/dfsu.DfsuSpectral.html index 81c2fe8a1..387fa0f7a 100644 --- a/api/dfsu.DfsuSpectral.html +++ b/api/dfsu.DfsuSpectral.html @@ -260,7 +260,7 @@

diff --git a/api/generic.html b/api/generic.html index cadad996e..66ab49d4d 100644 --- a/api/generic.html +++ b/api/generic.html @@ -260,7 +260,7 @@

diff --git a/api/index.html b/api/index.html index 32ed1a157..36be9064a 100644 --- a/api/index.html +++ b/api/index.html @@ -227,7 +227,7 @@

diff --git a/api/open.html b/api/open.html index 3c83bd83c..0903f9273 100644 --- a/api/open.html +++ b/api/open.html @@ -260,7 +260,7 @@

diff --git a/api/read.html b/api/read.html index 2eba7515e..c3e4ec6bc 100644 --- a/api/read.html +++ b/api/read.html @@ -260,7 +260,7 @@

diff --git a/api/read_pfs.html b/api/read_pfs.html index a40949be0..38d8c229d 100644 --- a/api/read_pfs.html +++ b/api/read_pfs.html @@ -226,7 +226,7 @@

diff --git a/api/spatial.GeometryFM2D.html b/api/spatial.GeometryFM2D.html index 96bfb57ac..b6dfc4bbd 100644 --- a/api/spatial.GeometryFM2D.html +++ b/api/spatial.GeometryFM2D.html @@ -260,7 +260,7 @@

diff --git a/api/spatial.GeometryFM3D.html b/api/spatial.GeometryFM3D.html index e9857490c..c52cc5f82 100644 --- a/api/spatial.GeometryFM3D.html +++ b/api/spatial.GeometryFM3D.html @@ -226,7 +226,7 @@

diff --git a/api/spatial.GeometryFMAreaSpectrum.html b/api/spatial.GeometryFMAreaSpectrum.html index 82e580c88..8451d6d16 100644 --- a/api/spatial.GeometryFMAreaSpectrum.html +++ b/api/spatial.GeometryFMAreaSpectrum.html @@ -260,7 +260,7 @@

diff --git a/api/spatial.GeometryFMLineSpectrum.html b/api/spatial.GeometryFMLineSpectrum.html index a8c52ac40..8483d8ce7 100644 --- a/api/spatial.GeometryFMLineSpectrum.html +++ b/api/spatial.GeometryFMLineSpectrum.html @@ -260,7 +260,7 @@

diff --git a/api/spatial.GeometryFMPointSpectrum.html b/api/spatial.GeometryFMPointSpectrum.html index 96709a35a..94cb62262 100644 --- a/api/spatial.GeometryFMPointSpectrum.html +++ b/api/spatial.GeometryFMPointSpectrum.html @@ -226,7 +226,7 @@

diff --git a/api/spatial.GeometryFMVerticalColumn.html b/api/spatial.GeometryFMVerticalColumn.html index aef580002..de06bb48a 100644 --- a/api/spatial.GeometryFMVerticalColumn.html +++ b/api/spatial.GeometryFMVerticalColumn.html @@ -226,7 +226,7 @@

diff --git a/api/spatial.GeometryFMVerticalProfile.html b/api/spatial.GeometryFMVerticalProfile.html index d193c8a4c..d70605fa3 100644 --- a/api/spatial.GeometryFMVerticalProfile.html +++ b/api/spatial.GeometryFMVerticalProfile.html @@ -226,7 +226,7 @@

diff --git a/api/spatial._FM_geometry._GeometryFMPlotter.html b/api/spatial._FM_geometry._GeometryFMPlotter.html index b41e2a4cc..25a6992d8 100644 --- a/api/spatial._FM_geometry._GeometryFMPlotter.html +++ b/api/spatial._FM_geometry._GeometryFMPlotter.html @@ -260,7 +260,7 @@

diff --git a/design.html b/design.html index 59c3afdec..02fb54b15 100644 --- a/design.html +++ b/design.html @@ -262,7 +262,7 @@

diff --git a/examples/Dfsu-2D-interpolation.html b/examples/Dfsu-2D-interpolation.html index 16bbd48fc..63cce2356 100644 --- a/examples/Dfsu-2D-interpolation.html +++ b/examples/Dfsu-2D-interpolation.html @@ -263,7 +263,7 @@

Dfsu - 2D interpolation

@@ -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.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
    1.8977844597276883

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

    -
    +
    dati = np.zeros((1,dfs.n_elements))
     for j in range(dfs.n_elements):
         dist = dist_in_meters(scatter[:,:2], dfs.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 32a1b96ce..838eb59d0 100644
    --- a/examples/Generic.html
    +++ b/examples/Generic.html
    @@ -265,7 +265,7 @@ 

    Generic dfs processing

    @@ -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, 627.04it/s]
    +
      0%|          | 0/2 [00:00<?, ?it/s]100%|██████████| 2/2 [00:00<00:00, 525.08it/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, 2690.73it/s]
    +
      0%|          | 0/5 [00:00<?, ?it/s]100%|██████████| 5/5 [00:00<00:00, 2250.16it/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()
    -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, 1047.27it/s]
    +
      0%|          | 0/1 [00:00<?, ?it/s]100%|██████████| 1/1 [00:00<00:00, 1284.23it/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()
    -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, 1223.54it/s]
    +
      0%|          | 0/1 [00:00<?, ?it/s]100%|██████████| 1/1 [00:00<00:00, 1265.25it/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, 17965.09it/s]
    +
      0%|          | 0/66 [00:00<?, ?it/s]100%|██████████| 66/66 [00:00<00:00, 15917.66it/s]
    -
    +
    ds = mikeio.read(fn)
     ds.mean(axis=0).describe()   # alternative way of getting the time average
    @@ -713,7 +713,7 @@

    Time average

    -
    +
    ds_avg = mikeio.read(fn_avg)
     ds_avg.describe()
    @@ -781,12 +781,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
    @@ -803,7 +803,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")
    @@ -817,7 +817,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 420005818..d1ffd0a12 100644
    --- a/examples/Time-interpolation.html
    +++ b/examples/Time-interpolation.html
    @@ -263,7 +263,7 @@ 

    Time interpolation

    @@ -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 5960c44c9..a1f61fc0f 100644 --- a/examples/dfs2/bathy.html +++ b/examples/dfs2/bathy.html @@ -266,7 +266,7 @@

    Dfs2 - Bathymetric data

    @@ -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
    @@ -753,7 +753,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();
    @@ -784,7 +784,7 @@

    Dfs2 - Bathymetric data

    -
    +
    ds.elevation.sel(lon=12.74792, lat=55.865, method="nearest")
    @@ -1153,17 +1153,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
    @@ -1171,37 +1171,37 @@

    Dfs2 - Bathymetric data

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

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

    Dfs2 - Bathymetric data

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

    Dfs2 - Bathymetric data

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

    Dfs2 - Bathymetric data

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

    Dfs2 - Bathymetric data

    -
    +
    da.to_dfs("gebco.dfs2")
    -
    +
    ds = mikeio.read("gebco.dfs2")
     ds.Elevation.plot()
    @@ -1262,7 +1262,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 3c0467a6e..461e0bad8 100644 --- a/examples/dfs2/gfs.html +++ b/examples/dfs2/gfs.html @@ -266,7 +266,7 @@

    Dfs2 - Meteo data

    @@ -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
    @@ -760,30 +760,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();
    @@ -797,7 +797,7 @@

    Dfs2 - Meteo data

    Convert to dfs2

    Time

    -
    +
    time = pd.DatetimeIndex(ds.time)
     time
    @@ -809,36 +809,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
    @@ -848,14 +848,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
    @@ -869,11 +869,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/dfs2/index.html b/examples/dfs2/index.html index 580c5acd0..c5ff0ca9d 100644 --- a/examples/dfs2/index.html +++ b/examples/dfs2/index.html @@ -228,7 +228,7 @@

    Dfs2 examples

    diff --git a/examples/index.html b/examples/index.html index b21302007..3cc800c42 100644 --- a/examples/index.html +++ b/examples/index.html @@ -288,7 +288,7 @@

    Examples

    @@ -420,7 +420,7 @@

    Examples

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

    Examples

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

    Examples

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

    Examples

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

    Examples

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

    Examples

    Tools and methods that applies to any type of dfs files. - + Time interpolation @@ -866,8 +866,8 @@

    Examples

    Getting started

    -
    +
    import mikeio
     
     ds = mikeio.read("data/FakeLake.dfsu")
    diff --git a/search.json b/search.json
    index e51d1d1d0..407cc302d 100644
    --- a/search.json
    +++ b/search.json
    @@ -998,7 +998,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, 627.04it/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, 525.08it/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",
    @@ -1010,7 +1010,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, 2690.73it/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, 2250.16it/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",
    @@ -1034,7 +1034,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\n-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, 1047.27it/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\n-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, 1223.54it/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\n-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, 1284.23it/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\n-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, 1265.25it/s]\n\n\n\nds3 = mikeio.read(\"gebco_sound_spatial.dfs2\")\nds3.Elevation[0].plot();",
         "crumbs": [
           "Home",
           "Examples",
    @@ -1046,7 +1046,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, 17965.09it/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\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\n\nds_avg = mikeio.read(fn_avg)\nds_avg.describe()\n\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, 15917.66it/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\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\n\nds_avg = mikeio.read(fn_avg)\nds_avg.describe()\n\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",
    @@ -1224,73 +1224,73 @@
       {
         "objectID": "user-guide/pfs.html",
         "href": "user-guide/pfs.html",
    -    "title": "Pfs",
    +    "title": "PFS",
         "section": "",
         "text": "A PFS file is a text file with a tree structure that contains parameters and settings for MIKE tools and engines. MIKE IO can read, modify and create PFS files.",
         "crumbs": [
           "Home",
           "User Guide",
    -      "Pfs"
    +      "PFS"
         ]
       },
       {
         "objectID": "user-guide/pfs.html#the-pfs-file",
         "href": "user-guide/pfs.html#the-pfs-file",
    -    "title": "Pfs",
    +    "title": "PFS",
         "section": "The PFS file",
    -    "text": "The PFS file\nThe content of the PFS file is similar to a nested dictionary. The root element is often called the target. Some PFS files have multiple root elements. The below sections are called PFS Sections which can be nested and contain key-value pairs called keywords and parameters.\n[TARGET1]\n   keywordA = parameterA\n   [SECTION1]\n      keywordB = parameterB\n      keywordC = parameterC\n      [SECTION2]\n         keywordD = parameterD         \n      EndSect  // SECTION2 \n   EndSect  // SECTION1 \nEndSect  // TARGET1\n\n[TARGET2]\n   keywordE = parameterE \n   [SECTION3]\n      keywordF = parameterF\n   EndSect  // SECTION3 \nEndSect  // TARGET2",
    +    "text": "The PFS file\nThe content of the PFS file is similar to a nested dictionary. The root element is often called the target. Some PFS files have multiple root elements. The below sections are called PFS Sections which can be nested and contain key-value pairs called keywords and parameters.\n1[TARGET1]\n   keywordA = parameterA\n   [SECTION1]\n      keywordB = parameterB\n      keywordC = parameterC\n      [SECTION2]\n         keywordD = parameterD\n      EndSect  // SECTION2\n   EndSect  // SECTION1\nEndSect  // TARGET1\n\n2[TARGET2]\n   keywordE = parameterE\n   [SECTION3]\n      keywordF = parameterF\n   EndSect  // SECTION3\nEndSect  // TARGET2\n\n1\n\nFirst target, access this part with pfs.targets[0]\n\n2\n\nSecond target, access this part with pfs.targets[1]\n\n\n\n\n\n\n\n\nNote\n\n\n\nComments // is used to add comments to the PFS file (e.g. // SECTION2), the comments are ignored by MIKE IO.",
         "crumbs": [
           "Home",
           "User Guide",
    -      "Pfs"
    +      "PFS"
         ]
       },
       {
         "objectID": "user-guide/pfs.html#read",
         "href": "user-guide/pfs.html#read",
    -    "title": "Pfs",
    +    "title": "PFS",
         "section": "Read",
         "text": "Read\nWhen a PFS file is read with MIKE IO, a PfsDocument object is created. It will contain one or more PfsSection objects - one for each target. The PfsSections will typically contain other PfsSections together with a number of key-value pairs.\nA PFS file is read using mikeio.read_pfs:\n\nimport mikeio\n\npfs = mikeio.read_pfs(\"../data/pfs/concat.mzt\")\npfs\n\n[txconc]\n   CLSID = 'TxConc.dll'\n   TypeName = 'txconc'\n   CREATEDTIME = '2020-03-11T15:24:45'\n   MODIFIEDTIME = '2020-03-11T15:24:45'\n   NOTES = ''\n   [Setup]\n      Name = 'Setup Name'\n      NumberFiles = 2\n      NumberDimensions = 1\n      NumberItems = 1\n      InsertDelIfGabs = 0\n      UseTimeRange = 1\n      TimeRange = 0, 145, 1\n      FirstFileTimeDef = 0\n      OverwriteWithLatest = 1\n      [File_1]\n         InputFile = |.\\tide1.dfs1|\n         Items = 1\n      EndSect  // File_1\n      [File_2]\n         InputFile = |.\\tide2.dfs1|\n         Items = 1\n      EndSect  // File_2\n      [File_Out]\n         OutputFile = |.\\txconc.dfs1|\n         OutputFileTitle = ''\n      EndSect  // File_Out\n   EndSect  // Setup\nEndSect  // txconc\n\n\n\nPfsDocument\nThe mikeio.PfsDocument is the MIKE IO equivalent to a PFS file. Its targets can be accessed by their name (as properties), like this:\n\npfs.txconc\n\nCLSID = 'TxConc.dll'\nTypeName = 'txconc'\nCREATEDTIME = '2020-03-11T15:24:45'\nMODIFIEDTIME = '2020-03-11T15:24:45'\nNOTES = ''\n[Setup]\n   Name = 'Setup Name'\n   NumberFiles = 2\n   NumberDimensions = 1\n   NumberItems = 1\n   InsertDelIfGabs = 0\n   UseTimeRange = 1\n   TimeRange = 0, 145, 1\n   FirstFileTimeDef = 0\n   OverwriteWithLatest = 1\n   [File_1]\n      InputFile = |.\\tide1.dfs1|\n      Items = 1\n   EndSect  // File_1\n   [File_2]\n      InputFile = |.\\tide2.dfs1|\n      Items = 1\n   EndSect  // File_2\n   [File_Out]\n      OutputFile = |.\\txconc.dfs1|\n      OutputFileTitle = ''\n   EndSect  // File_Out\nEndSect  // Setup\n\n\nOr by the pfs.targets object (which is a list of PfsSections). Each of the targets is a PfsSection object consisting of key-value pairs (keyword-parameter) and other PfsSections.\nThe mikeio.PfsDocument object is similar to a dictionary. You can loop over its contents with items(), keys() and values() like a dictionary.\n\n\nPfsSection\nThe mikeio.PfsSection object is also similar to a dictionary. You can loop over its contents with items(), keys() and values() like a dictionary.\n\npfs.txconc.keys()\n\ndict_keys(['CLSID', 'TypeName', 'CREATEDTIME', 'MODIFIEDTIME', 'NOTES', 'Setup'])\n\n\nYou can access a specific parameter with the get() method:\n\npfs.txconc.get(\"CLSID\")\n\n'TxConc.dll'\n\n\nOr as a property with dot-notation—which is prefered in most cases as it is more readable:\n\npfs.txconc.CLSID\n\n'TxConc.dll'\n\n\nA PfsSection can be converted to a dictionary with the to_dict() method:\n\npfs.txconc.Setup.File_1.to_dict()\n\n{'InputFile': '|.\\\\tide1.dfs1|', 'Items': 1}\n\n\nIf a PfsSection contains enumerated subsections, they can be converted to a pandas DataFrame with the to_dataframe() method:\n\npfs.txconc.Setup.to_dataframe(prefix=\"File_\")\n\n\n\n\n\n\n\n\n\nInputFile\nItems\n\n\n\n\n1\n|.\\tide1.dfs1|\n1\n\n\n2\n|.\\tide2.dfs1|\n1\n\n\n\n\n\n\n\n\n\n\nUnique or non-unique keywords\nDepending on the engine intended for reading the PFS file it may or may not make sense to have multiple identical keywords in the same PfsSection. MIKE 21/3 and the marine tools does not support non-unique keywords—if non-unique keywords are present, only the first will be read and the presence is most likely a mistake made by hand-editing the file. In other tools, e.g. MIKE Plot Composer, non-unique keywords are used a lot. How MIKE IO shall deal with non-unique keywords can be specified using the unique_keywords argument in the mikeio.read_pfs function:\npfs = mikeio.read_pfs(\"myplot.plt\", unique_keywords=False)\nIf a PfsSection contains non-unique PfsSections or keywords and unique_keywords=False, the repeated key will only appear once and the corresponding value will be a list.",
         "crumbs": [
           "Home",
           "User Guide",
    -      "Pfs"
    +      "PFS"
         ]
       },
       {
         "objectID": "user-guide/pfs.html#update",
         "href": "user-guide/pfs.html#update",
    -    "title": "Pfs",
    +    "title": "PFS",
         "section": "Update",
    -    "text": "Update\nThe PfsSection object can be modified. Existing values can be changed, new key-value pairs can be added, subsections can added or removed.\n\nModify existing keyword\nIt is very simple to modify an existing keyword:\npfs.txconc.Setup.Name = \"new name\"\n\n\nAdd new key-value pair\nA new key-value pair can be added, like in a dictionary, in this way:\npfs.txconc.Setup[\"NewKeyword\"] = 12.0\n\n\nAdd new section as a copy of another section\nOften a PfsSection is added using an existing PfsSection as a template.\ns = pfs.txconc.Setup.File_1.copy()\ns.InputFile = '|.\\tide3.dfs1|'\npfs.txconc.Setup[\"File_3\"] = s\n\n\nAdd new section from a dictionary\nA PfsSection can be created from a dictionary and then added to another PfsSection like any other key-value pair:\nd = {'InputFile': '|.\\\\tide4.dfs1|', 'Items': 1}\ns = mikeio.PfsSection(d)\npfs.txconc.Setup[\"File_4\"] = s",
    +    "text": "Update\nThe PfsSection object can be modified. Existing values can be changed, new key-value pairs can be added, subsections can added or removed.\n\nModify existing keyword\nIt is very simple to modify an existing keyword:\npfs.txconc.Setup.Name = \"new name\"\n\n\nAdd new key-value pair\nA new key-value pair can be added, like in a dictionary, in this way:\npfs.txconc.Setup[\"NewKeyword\"] = 12.0\n\n\nAdd new section as a copy of another section\nOften a PfsSection is added using an existing PfsSection as a template.\ns = pfs.txconc.Setup.File_1.copy()\ns.InputFile = '|.\\tide3.dfs1|'\npfs.txconc.Setup[\"File_3\"] = s\n\n\nAdd new section from a dictionary\nA PfsSection can be created from a dictionary and then added to another PfsSection like any other key-value pair:\n\nd = {'InputFile': '|.\\\\tide4.dfs1|', 'Items': 1}\ns = mikeio.PfsSection(d)\npfs.txconc.Setup[\"File_4\"] = s",
         "crumbs": [
           "Home",
           "User Guide",
    -      "Pfs"
    +      "PFS"
         ]
       },
       {
         "objectID": "user-guide/pfs.html#write-to-file",
         "href": "user-guide/pfs.html#write-to-file",
    -    "title": "Pfs",
    +    "title": "PFS",
         "section": "Write to file",
    -    "text": "Write to file\nA Pfs object can be written to a PFS file using the write method.\npfs.write(\"new.pfs\")",
    +    "text": "Write to file\nA Pfs document can be written to a file using the write method.\npfs.write(\"new.pfs\")",
         "crumbs": [
           "Home",
           "User Guide",
    -      "Pfs"
    +      "PFS"
         ]
       },
       {
         "objectID": "user-guide/pfs.html#create-new-pfs-files",
         "href": "user-guide/pfs.html#create-new-pfs-files",
    -    "title": "Pfs",
    +    "title": "PFS",
         "section": "Create new Pfs files",
    -    "text": "Create new Pfs files\nA new PFS file can be created from dictionary in the following way:\n\nfrom datetime import datetime\n\nd = dict(\n    key1=1,\n    lst=[0.3, 0.7],\n    file_name=r\"|path\\file.dfs0|\",\n    start_time=datetime(2019, 7, 1, 0, 0, 0),\n)\npfs = mikeio.PfsDocument({\"MYTOOL\": d})\npfs\n\n[MYTOOL]\n   key1 = 1\n   lst = 0.3, 0.7\n   file_name = |path\\file.dfs0|\n   start_time = 2019, 7, 1, 0, 0, 0\nEndSect  // MYTOOL\n\n\nMultiple targets can be achieved by providing list of dictionaries.",
    +    "text": "Create new Pfs files\nA new PFS file can be created from dictionary in the following way:\n\nd = dict(\n    key1=1,\n    lst=[0.3, 0.7],\n    file_name=r\"|path\\file.dfs0|\",\n    start_time=[2019, 7, 1, 0, 0, 0],\n)\npfs = mikeio.PfsDocument({\"MYTOOL\": d})\npfs\n\n[MYTOOL]\n   key1 = 1\n   lst = 0.3, 0.7\n   file_name = |path\\file.dfs0|\n   start_time = 2019, 7, 1, 0, 0, 0\nEndSect  // MYTOOL\n\n\nMultiple targets can be achieved by providing list of dictionaries, in this way you can create a PFS file with multiple targets for the same tool.\n\nt1 = {\"file_name\": r\"|path\\file1.dfs0|\"}\nt2 = {\"file_name\": r\"|path\\file2.dfs0|\"}\n\npfs = mikeio.PfsDocument([t1, t2], names=[\"ATOOL\", \"ATOOL\"])\npfs\n\n[ATOOL]\n   file_name = |path\\file1.dfs0|\nEndSect  // ATOOL\n[ATOOL]\n   file_name = |path\\file2.dfs0|\nEndSect  // ATOOL",
         "crumbs": [
           "Home",
           "User Guide",
    -      "Pfs"
    +      "PFS"
         ]
       },
       {
    diff --git a/user-guide/data-structures.html b/user-guide/data-structures.html
    index a3eaa7916..eac771c8c 100644
    --- a/user-guide/data-structures.html
    +++ b/user-guide/data-structures.html
    @@ -228,7 +228,7 @@ 

    diff --git a/user-guide/dataarray.html b/user-guide/dataarray.html index 4182d263e..254ace653 100644 --- a/user-guide/dataarray.html +++ b/user-guide/dataarray.html @@ -264,7 +264,7 @@

    DataArray

    @@ -388,7 +388,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")
    @@ -404,7 +404,7 @@ 

    DataArray

    Temporal selection

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

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

    Spatial selection

    The sel method finds the nearest element.

    -
    +
    da.sel(x=607002, y=6906734)
    <mikeio.DataArray>
    @@ -444,17 +444,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
    @@ -462,7 +462,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()
    @@ -472,7 +472,7 @@

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

    -
    +
    da.plot.mesh()
    diff --git a/user-guide/dataset.html b/user-guide/dataset.html index 8a53f824c..fc5d1a874 100644 --- a/user-guide/dataset.html +++ b/user-guide/dataset.html @@ -264,7 +264,7 @@

    diff --git a/user-guide/dfs0.html b/user-guide/dfs0.html index e745b7f87..ad7c5d570 100644 --- a/user-guide/dfs0.html +++ b/user-guide/dfs0.html @@ -265,7 +265,7 @@

    Dfs0

    @@ -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()
    @@ -478,7 +478,7 @@

    From pandas

    MIKE IO adds a new method to the DataFrame called to_dfs0. This method is used to save the DataFrame to a dfs0 file. (This method becomes available after importing the mikeio module.)

    -
    +
    import pandas as pd
     
     df = pd.read_csv(
    diff --git a/user-guide/dfs1.html b/user-guide/dfs1.html
    index 4a2196608..fed58df3f 100644
    --- a/user-guide/dfs1.html
    +++ b/user-guide/dfs1.html
    @@ -262,7 +262,7 @@ 

    Dfs1

    @@ -368,7 +368,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")
    @@ -385,7 +385,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>
    diff --git a/user-guide/dfs2.html b/user-guide/dfs2.html
    index 3fb54e6ca..d07aef4f1 100644
    --- a/user-guide/dfs2.html
    +++ b/user-guide/dfs2.html
    @@ -262,7 +262,7 @@ 

    Dfs2

    @@ -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 3a426a1d1..80acc6812 100644
    --- a/user-guide/dfsu.html
    +++ b/user-guide/dfsu.html
    @@ -262,7 +262,7 @@ 

    Dfsu and Mesh Overview

    @@ -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 1f9c53927..48202fbe0 100644 --- a/user-guide/eum.html +++ b/user-guide/eum.html @@ -262,7 +262,7 @@

    EUM

    @@ -374,7 +374,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)
    @@ -383,47 +383,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
    @@ -433,7 +433,7 @@

    EUM