A package that uses the DHI dfs libraries to create, write and read dfs and mesh files.
Reason this release was yanked:
alpha release
Project description
MIKE IO: input/output of MIKE files in python
Read, write and manipulate dfs0, dfs1, dfs2, dfs3, dfsu and mesh files.
Facilitates common data processing workflows for MIKE files.
For res1d and xns11 files use the related package MIKE IO 1D
Requirements
- Windows or Linux operating system
- Python x64 3.7 - 3.10
- (Windows) VC++ redistributables (already installed if you have MIKE)
Where can I get help?
- New ideas and feature requests - GitHub Discussions
- Bugs - GitHub Issues
- General help, FAQ - Stackoverflow with the tag
mikeio
Installation
From PyPI:
pip install mikeio
Or development version:
pip install https://github.com/DHI/mikeio/archive/main.zip
Examples
Reading data from dfs0, dfs1, dfs2, dfsu
Generic read
method to read values, if you need additional features such as coordinates, use specialised classes instead e.g. Dfsu
>>> import mikeio
>>> ds = mikeio.read("random.dfs0")
>>> ds
<mikeio.Dataset>
Dimensions: (1000,)
Time: 2017-01-01 00:00:00 - 2017-07-28 03:00:00
Items:
0: VarFun01 <Water Level> (meter)
1: NotFun <Water Level> (meter)
>>> ds = mikeio.read("random.dfs1")
>>> ds
<mikeio.Dataset>
Dimensions: (100, 3)
Time: 2012-01-01 00:00:00 - 2012-01-01 00:19:48
Items:
0: testing water level <Water Level> (meter)
Reading dfs0 file into Pandas DataFrame
>>> from mikeio import Dfs0
>>> dfs = Dfs0('simple.dfs0')
>>> ts = dfs.to_dataframe()
Write simple timeseries
>>> from datetime import datetime
>>> import numpy as np
>>> from mikeio import Dfs0
>>> data = [np.random.random([100])]
>>> dfs = Dfs0()
>>> dfs.write('simple.dfs0', data, start_time=datetime(2017, 1, 1), dt=60)
Write timeseries from dataframe
import pandas as pd
import mikeio
>>> df = pd.read_csv(
... "tests/testdata/co2-mm-mlo.csv",
... parse_dates=True,
... index_col="Date",
... na_values=-99.99,
... )
>>> df.to_dfs0("mauna_loa.dfs0")
For more examples on timeseries data see this notebook
Read dfs2 data
>>> from mikeio import Dfs2
>>> dfs = Dfs2("random.dfs2")
>>> ds = dfs.read()
>>> ds
<mikeio.Dataset>
Dimensions: (3, 100, 2)
Time: 2012-01-01 00:00:00 - 2012-01-01 00:00:24
Items:
0: testing water level <Water Level> (meter)
Create dfs2
For a complete example of conversion from netcdf to dfs2 see this notebook.
Another example of downloading meteorological forecast from the Global Forecasting System and converting it to a dfs2 ready to be used by a MIKE 21 model.
Read dfsu files
>>> import matplotlib.pyplot as plt
>>> from mikeio import Dfsu
>>> dfs = Dfsu("HD.dfsu")
>>> ds = dfs.read()
>>> idx = dfs.find_nearest_element(x=608000, y=6907000)
>>> plt.plot(ds.time, ds.data[0][:,idx])
>>> from mikeio import Mesh
>>> msh = Mesh("FakeLake.dfsu")
>>> msh.plot()
For more examples on working with dfsu and mesh see these notebooks:
- Basic dfsu
- 3d dfsu
- Mesh
- Speed & direction
- Dfsu and mesh plotting
- Export to netcdf
- Export to shapefile
Pfs
Pfs is the format used for MIKE setup files (.m21fm, .m3fm, .sw etc.).
There is experimental support for reading pfs files, but the API is likely to change.
Items, units
Useful when creating a new dfs file
>>> from mikeio.eum import EUMType, EUMUnit
>>> EUMType.Temperature
<EUMType.Temperature: 100006>
>>> EUMType.Temperature.units
[degree Celsius, degree Fahrenheit, degree Kelvin]
>>> EUMUnit.degree_Kelvin
degree Kelvin
Tested
MIKE IO is tested extensively. 95% total test coverage.
See detailed test coverage report below:
File Covered Missed %
-------------------------------------------------
mikeio\__init__.py 40 1 98%
mikeio\aggregator.py 103 9 91%
mikeio\bin\__init__.py 0 0 100%
mikeio\custom_exceptions.py 19 1 95%
mikeio\dataset.py 272 3 99%
mikeio\dfs.py 206 7 97%
mikeio\dfs0.py 239 15 94%
mikeio\dfs1.py 48 2 96%
mikeio\dfs2.py 100 2 98%
mikeio\dfs3.py 201 79 61%
mikeio\dfsu.py 1337 57 96%
mikeio\dfsutil.py 76 4 95%
mikeio\dotnet.py 63 4 94%
mikeio\eum.py 1230 3 99%
mikeio\generic.py 228 2 99%
mikeio\helpers.py 13 0 100%
mikeio\interpolation.py 54 1 98%
mikeio\spatial.py 279 4 99%
mikeio\xyz.py 12 0 100%
-------------------------------------------------
TOTAL 5082 229 95%
=================== 335 passed ==================
Cloud enabled
From MIKE IO v.0.7 it is now possible to run MIKE IO on Linux-based Cloud computing, e.g. Google Colab.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file mikeio-0.11.0.tar.gz
.
File metadata
- Download URL: mikeio-0.11.0.tar.gz
- Upload date:
- Size: 102.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.8.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.7.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7623252fe4273114243cec554e87cd040792a1f93654e79a311a4655ff2f8672 |
|
MD5 | 3334766575c4d1e4ec4be94c8f8d6f4a |
|
BLAKE2b-256 | 23d7aa48b80d5e797c5a8c8b03d02e58a922f5bcfe8869c6a68ffc2e825f3217 |