Skip to content

Commit

Permalink
Merge branch 'main' into feature/chainage_indexing
Browse files Browse the repository at this point in the history
  • Loading branch information
ryan-kipawa committed Sep 12, 2024
2 parents a976b5f + 3800041 commit a6dd09d
Show file tree
Hide file tree
Showing 27 changed files with 5,278 additions and 1,094 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/full_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
python-version: ["3.8", "3.12"]
python-version: ["3.9", "3.12"]

steps:
- uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.8'
python-version: '3.12'
- name: Set up .NET
uses: actions/setup-dotnet@v3
with:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,4 @@ tests/testdata/w_right_discharge_in_structure.extract.txt
tests/testdata/lts_event_statistics.merged.res1d
tests/testdata/lts_monthly_statistics.merged.res1d
tests/testdata/catchment_merge_c.res1d
tests/testdata/network_cali.res1d
13 changes: 10 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,18 @@

### Added


### Fixed


### Changed

## [0.6.1] - 2024-03-23

### Fixed

- Loading MIKE IO 1D together with MIKE+Py
- Fixed override_name parameter that was not working in ResultFrameAggregator
- Fixed converting res11 to res1d
- Fixed calling ResultQuantityCollection.plot with kwargs

## [0.6] - 2024-02-08

Expand Down Expand Up @@ -121,7 +127,8 @@
- Reading of res1d and xns11 files into pandas data frames


[unreleased]: https://github.com/DHI/mikeio1d/compare/v0.6...HEAD
[unreleased]: https://github.com/DHI/mikeio1d/compare/v0.6.1...HEAD
[0.6.1]: https://github.com/DHI/mikeio1d/releases/tag/v0.6.1
[0.6]: https://github.com/DHI/mikeio1d/releases/tag/v0.6
[0.5]: https://github.com/DHI/mikeio1d/releases/tag/v0.5
[0.4.1]: https://github.com/DHI/mikeio1d/releases/tag/v0.4.1
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ For other MIKE files (Dfs0, Dfs1, Dfs2, Dfsu,...) use the related package [MIKE

## Requirements
* Windows operating system (Support for Linux is experimental)
* Python x64 3.6, 3.7 or 3.8
* Python x64 3.9, 3.10, 3.11 or 3.12
* [VC++ redistributables](https://support.microsoft.com/en-us/help/2977003/the-latest-supported-visual-c-downloads) (already installed if you have MIKE)

## Installation
Expand Down
2 changes: 1 addition & 1 deletion mikeio1d/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
# Dev branch marker is: 'X.Y.dev' or 'X.Y.devN' where N is an integer.
# 'X.Y.dev0' is the canonical version of 'X.Y.dev'
#
__version__ = "0.6.0"
__version__ = "0.6.1"

if "64" not in platform.architecture()[0]:
raise Exception("This library has not been tested for a 32 bit system.")
Expand Down
26 changes: 24 additions & 2 deletions mikeio1d/mikepath.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import sys
import platform
import pythonnet

Expand All @@ -25,6 +26,8 @@ class MikePath:

mikeio1d_bin_path = os.path.join(os.path.dirname(__file__), "bin")

mikeio1d_bin_extra_path = os.path.join(os.path.dirname(__file__), "bin/DHI.Mike1D.MikeIO")

mike_install_path = os.environ.get("MIKE_INSTALL_PATH", None)

skip_bin_x64 = os.environ.get("MIKE_SKIP_BIN_X64", None)
Expand All @@ -49,7 +52,10 @@ def setup_mike_installation(syspath):
syspath: list of str
List of strings defining PATH variable.
"""
MikePath.update_mike_bin_to_mikepluspy_bin_if_used()

syspath.append(MikePath.mike_bin_path)
syspath.append(MikePath.mikeio1d_bin_extra_path)

if MikePath.is_linux:
MikePath.setup_mike_installation_linux()
Expand All @@ -58,9 +64,25 @@ def setup_mike_installation(syspath):
MikePath.setup_mike_installation_custom(syspath)

@staticmethod
def setup_mike_installation_custom(syspath):
syspath.append(MikePath.mikeio1d_bin_path)
def update_mike_bin_to_mikepluspy_bin_if_used():
"""
Updates the path for MIKE assemblies to the ones used by MIKE+Py package.
This requires that the MIKE+Py package was already loaded.
"""
mikepluspy = sys.modules.get("mikeplus")
if mikepluspy == None:
return

import mikeplus

mikeplus_bin_path = str(mikeplus.MikeImport.ActiveProduct().InstallRoot)
mikeplus_bin_path = os.path.join(mikeplus_bin_path, MikePath.bin_x64)

MikePath.mikeio1d_bin_path = mikeplus_bin_path
MikePath.mike_bin_path = mikeplus_bin_path

@staticmethod
def setup_mike_installation_custom(syspath):
# Some of the MIKE libraries will need to be resolved by DHI.Mike.Install,
# so set it up here.
import clr
Expand Down
10 changes: 9 additions & 1 deletion mikeio1d/pandas_extension/result_frame_aggregator.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,14 @@ def _finalize_quantity_index(self, quantity_index: pd.Index) -> pd.Index:
continue
quantity_index = quantity_index.droplevel(level)

if self._override_name is not None:
quantity_index = quantity_index.set_levels(
quantity_index.levels[quantity_index.names.index(self._agg_level_name)].map(
lambda _: self._override_name
),
level=self._agg_level_name,
)

quantity_index = quantity_index.map("_".join)

return quantity_index
Expand Down Expand Up @@ -334,7 +342,7 @@ def _finalize_df_post_aggregate(self, df: pd.DataFrame) -> pd.DataFrame:
for level in self._quantity_levels:
if level not in df.columns.names:
continue
df = df.stack(level)
df = df.stack(level, future_stack=True)

df = df.T

Expand Down
5 changes: 4 additions & 1 deletion mikeio1d/res1d.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
from .pandas_extension import Mikeio1dAccessor # noqa: F401

from System import DateTime
from DHI.Mike1D.Generic import Connection


class Res1D:
Expand Down Expand Up @@ -396,8 +397,10 @@ def save(self, file_path):
file_path : str
File path for the new res1d file.
"""
self.data.Connection.FilePath.Path = file_path
connection_original = self.data.Connection
self.data.Connection = Connection.Create(file_path)
self.data.Save()
self.data.Connection = connection_original

def extract(
self,
Expand Down
6 changes: 4 additions & 2 deletions mikeio1d/result_network/result_quantity_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,15 @@ def read(self, column_mode: Optional[str | ColumnMode] = None) -> pd.DataFrame:
timeseries_ids = [q.timeseries_id for q in self.result_quantities]
return self.res1d.read(timeseries_ids, column_mode=column_mode)

def plot(self):
def plot(self, **kwargs):
"""Plot the time series data."""
if len(self.result_quantities) <= 0:
return

# Taking the first data item is enough, because all of them have
# the same quantity and for plotting.
self.data_item = self.result_quantities[0].data_item
ResultQuantity.plot(self)
return ResultQuantity.plot(self, **kwargs)

def get_query(self):
"""Get queries corresponding to ResultQuantityCollection."""
Expand Down
4 changes: 1 addition & 3 deletions mikeio1d/result_network/result_reach.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,7 @@ def try_set_static_attribute_length(self):
try:
self.set_static_attribute("length", self._get_total_length())
except Exception as _:
warnings.warn(
"Length attribute not included. For SWMM and EPANET results this is not implemented."
)
pass

def add_res1d_reach(self, reach):
"""
Expand Down
8 changes: 7 additions & 1 deletion mikeio1d/result_reader_writer/result_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
from typing import List
from typing import Optional

import warnings

from enum import Enum
from abc import ABC
from abc import abstractmethod
Expand Down Expand Up @@ -283,7 +285,11 @@ def update_time_quantities(self, df: pd.DataFrame):
simulation_start + datetime.timedelta(seconds=s)
for s in seconds_since_simulation_started
]
df.iloc[:, i] = datetime_since_simulation_started

# Suppress casting warning for now with hope that it will be fixed by pandas in the future.
with warnings.catch_warnings():
warnings.simplefilter("ignore", category=FutureWarning)
df.iloc[:, i] = datetime_since_simulation_started

def _is_lts_event_time_column(
self,
Expand Down
85 changes: 65 additions & 20 deletions notebooks/epanet_res.ipynb

Large diffs are not rendered by default.

Loading

0 comments on commit a6dd09d

Please sign in to comment.