mikeio1d conflicts with mikeplus
ZhaoNianZH opened this issue ยท 4 comments
Describe the bug
mikeio1d.res1d.Res1D
module conflicts with mikeplus.Engine1D
module.
Currently the mikeplus
package is in beta and contains limited functionality, when I loaded Engine1D
form mikeplus
, I noticed that mikeio1d could not read the results properly. The following error is returned:
Python.Runtime.PythonException: DHI.Mike1D.ResultDataAccess.ResultData value cannot be converted to DHI.Mike1D.ResultDataAccess.ResultData
The above exception was the direct cause of the following exception:
System.ArgumentException: DHI.Mike1D.ResultDataAccess.ResultData value cannot be converted to DHI.Mike1D.ResultDataAccess.ResultData in method Void .ctor(DHI.Mike1D.ResultDataAccess.ResultData) ---> Python.Runtime.PythonException: DHI.Mike1D.ResultDataAccess.ResultData value cannot be converted to DHI.Mike1D.ResultDataAccess.ResultData
--- End of inner exception stack trace ---
The above exception was the direct cause of the following exception:
System.AggregateException: One or more errors occurred. ---> System.ArgumentException: DHI.Mike1D.ResultDataAccess.ResultData value cannot be converted to DHI.Mike1D.ResultDataAccess.ResultData in method Void .ctor(DHI.Mike1D.ResultDataAccess.ResultData) ---> Python.Runtime.PythonException: DHI.Mike1D.ResultDataAccess.ResultData value cannot be converted to DHI.Mike1D.ResultDataAccess.ResultData
--- End of inner exception stack trace ---
--- End of inner exception stack trace ---
---> (Inner Exception #0) System.ArgumentException: DHI.Mike1D.ResultDataAccess.ResultData value cannot be converted to DHI.Mike1D.ResultDataAccess.ResultData in method Void .ctor(DHI.Mike1D.ResultDataAccess.ResultData) ---> Python.Runtime.PythonException: DHI.Mike1D.ResultDataAccess.ResultData value cannot be converted to DHI.Mike1D.ResultDataAccess.ResultData
--- End of inner exception stack trace ---<---
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "d:/****/****/mikepluspy-main/notebooks/test.py", line 21, in <module>
result_ = mikeio1d.res1d.Res1D(r'D:\****\****\mikepluspy-main\tests\testdata\Db\Sirius\Sirius_m1d - Result Files\Sirius_1_DEMOBaseDefault_Network_HD.res1d')
File "C:\Users\****\.conda\envs\python38\lib\site-packages\mikeio1d\res1d.py", line 113, in __init__
self.result_reader = ResultReaderCreator.create(
File "C:\Users\****\.conda\envs\python38\lib\site-packages\mikeio1d\result_reader_writer\result_reader_creator.py", line 41, in create
return reader(
File "C:\Users\****\.conda\envs\python38\lib\site-packages\mikeio1d\result_reader_writer\result_reader_copier.py", line 59, in __init__
self.result_data_copier = ResultDataCopier(self.data)
TypeError: No method matches given arguments for ResultDataCopier..ctor: (<class 'DHI.Mike1D.ResultDataAccess.ResultData'>)
To Reproduce
Steps to reproduce the behavior:
You can download the attached file which is test data for mikeplus.
Sirius.zip
import mikeplus
import mikeio1d
- read results file using
Res1D
Code
from mikeplus import DataTableAccess
from mikeplus.engines import Engine1D
import mikeio1d
'''
db_path = r'D:\Drainage\MIKEpy\mikepluspy-main\tests\testdata\Db\Sirius\Sirius.sqlite'
data_access = DataTableAccess(db_path)
data_access.open_database()
print(data_access.is_database_open())
data_access.close_database()
'''
# replace the result file path
result = mikeio1d.res1d.Res1D(r'D:\Drainage\MIKEpy\mikepluspy-main\tests\testdata\Db\Sirius\Sirius_m1d - Result Files\Sirius_1_DEMOBaseDefault_Network_HD.res1d')
print(result)
Screenshots
If applicable, add screenshots to help explain your problem.
Sirius.zip
System information:
- Python version: [Python 3.8] / [Python 3.12]
- MIKE IO version [MIKE IO 1D v0.6]
In this scenario there are two versions of the MIKE 1D assemblies in play, on in mikeio1d bin folder and one in the MIKE+ bin folder. Those two are potentially not even the same version, though in most cases they should be close enough.
The question is if mikeio1d can keep track of if the MIKE 1D assemblies are already loaded from somewhere else, and then use those instead of the ones in the mikeio1d bin folder?
Could you try to import the packages in the following way by specifying the MIKE_INSTALL_PATH
:
import os
import mikeplus
from mikeplus.engines import Engine1D
os.environ['MIKE_INSTALL_PATH'] = str(mikeplus.MikeImport.ActiveProduct().InstallRoot)
import mikeio1d
res1d = mikeio1d.Res1D(
r'D:\Drainage\MIKEpy\mikepluspy-main\tests\testdata\Db\Sirius\Sirius_m1d - Result Files\Sirius_1_DEMOBaseDefault_Network_HD.res1d',
result_reader_type="query"
)
and let us know if it works for you.
@ZhaoNianZH This is a temporary workaround and we will fix the behaviour that the user would not need to do special configurations. Good that the above code indicates that we will be able to do that. Also note that "query" reader can be very slow.