Comments (6)
Thank you for the answer! That was very helpful. Is this syntax documented anywhere?
from mikeio1d.
Hi!
It looks like this happens since the chainage is not included in QueryDataReach. In version 0.3.0, if the chainage wasn't specified, then it automatically used the start chainage. So, the quick fix would be to add the chainage as a third argument to QueryDataReach.
In version 0.4.0, there's a shorter way to write this:
from mikeio1d import Res1D
res = Res1D("model_m1d - Result Files/modelBaseDefault_Network_HD.res1d")
df = res.result_network.reaches.Fictious_outlet_Valldalen_Basin.Discharge.read()
That will return a pandas dataframe with discharge at all of the chainages along the reach.
from mikeio1d.
How would I do if I wanted the discharge from several reaches into one dataframe? Earlier, I would then write res.read([mikeio1d.res1d.QueryDataReach("Discharge", a) for a in tunnels])
since the discharge is the same in all chainages of every reach, it was unimportant to specify chainage. Is there a way I can just get the start or end chainage without knowing it? Or to get a list of the first chainages of every reach in a list?
from mikeio1d.
Thank you for the answer! That was very helpful. Is this syntax documented anywhere?
Good to hear. The syntax is included in some of the example notebooks for now. We need to update the overall documentation, so that'll come in future releases to make it easier :)
from mikeio1d.
How would I do if I wanted the discharge from several reaches into one dataframe? Earlier, I would then write
res.read([mikeio1d.res1d.QueryDataReach("Discharge", a) for a in tunnels])
since the discharge is the same in all chainages of every reach, it was unimportant to specify chainage. Is there a way I can just get the start or end chainage without knowing it? Or to get a list of the first chainages of every reach in a list?
It would be interesting to see how you created 'tunnels' here.
For a temporary fix, you could revert to the old behavior with:
res = Res1D('myfile.res1d', result_reader_type='query')
# continue with the code you had
With 0.4.0 there's a few options, but I think it could probably be improved here.
Option 1 - use autocompletion to find chainage names
from mikeio1d import Res1D
res = Res1D("results.res1d")
# here there's autocompletion that will show reach names, as well as chainages with 'm_' prefix
res.result_network.reaches.Some_Reach_Name.m_1000.Discharge.read()
Option 2 - directly access the first discharge gridpoint
from mikeio1d import Res1D
res = Res1D("model_m1d - Result Files/modelBaseDefault_Network_HD.res1d")
df = res.result_network.reaches.Fictious_outlet_Valldalen_Basin.Discharge.result_quantities[0].read()
For reading multiple reaches into a single dataframe, you can use several add() followed by read()
from mikeio1d import Res1D
res = Res1D("model_m1d - Result Files/modelBaseDefault_Network_HD.res1d")
# here you add quantities to a background 'queue'
res.result_network.reaches.Fictious_outlet_Valldalen_Basin.Discharge.result_quantities[0].add()
res.result_network.reaches.AnotherReach.Discharge.result_quantities[0].add()
# here you read everything in the queue
df = res.read()
Would a syntax like this be useful for your script? This could be an idea for 0.5.0
from mikeio1d import Res1D
res = Res1D('result.res1d')
# select discharges to be read
for reach in res.network.reaches:
if 'tunnel' in reach.name:
reach.Discharge[0].add() # default grabs all chainages, or zero-based index to grab first
# read discharges into pandas dataframe
df = res.read()
from mikeio1d.
Thanks for the tips. I used option 2, with the add()
and read()
methods. My tunnels list looks like this:
tunnels = ['Fictious outlet Valldalen-Basin', 'Inntaksluke-Risbu', 'Fictious outlet Vasstøl', 'Vasstøl-Øyna']
I manually copied the names from the output of res.reaches.keys()
. Here, the list was short enough that I could just translate the names to "snake_case" and skip the for-loop, but this would get clumsy if the list was very long. So yes, your suggested syntax would be welcome in the future.
For me it is not so intuitive to use node or reach names as attributes (is that the correct term?), and I can imagine some problems in translating from one to the other, i.e. a list of strings to a list of attributes, if that is even possible. For me it would be more practical to be able to write res.result_network.reaches['Fictious outlet Valldalen-Basin'].Discharge.result_quantities[0].read()
. Is there a reason why I can't do that instead of your suggestion for v.0.5.0?
from mikeio1d.
Related Issues (20)
- Reading marker of cross sections
- Is there a way to can get the reach type (Weir, Pump, Link)? HOT 1
- How can I use functions from DHI.Mike1D.CrossSectionModule to convert a txt file to xns11 file HOT 1
- Make the UI/UX experience in jupyter notebooks better HOT 5
- Running setup.py install for pythonnet did not run successfully. HOT 7
- PerformanceWarning when reading res1d file
- AttributeError:"IRes1DDataSet" object has no attribute 'GetChainages' HOT 7
- Read .prf-file in MIKE IO 1D v0.3
- Performance of reading result files HOT 1
- Reading large *.res1D files using the MIKEIO1D tool HOT 2
- Extract specific result type from the res1d HOT 10
- DateTime in DataFrame index discards decimals HOT 1
- In make_proper_variable_name( ), Please don't replace all non alpha numeric characters by an underscore HOT 2
- Reading wrong results? HOT 3
- Export xns11 cross sections to GeoPandas, modify, and write back to xns11 file. HOT 1
- mikeio1d conflicts with mikeplus HOT 4
- Conversion from .res11 to .res1d fails
- Filter option in Res1D does not work? HOT 1
- Extraction of total volume from weirs etc. - DischargeIntegrated
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mikeio1d.