Replies: 7 comments
-
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. |
Beta Was this translation helpful? Give feedback.
-
Thank you for the answer! That was very helpful. Is this syntax documented anywhere? |
Beta Was this translation helpful? Give feedback.
-
How would I do if I wanted the discharge from several reaches into one dataframe? Earlier, I would then write |
Beta Was this translation helpful? Give feedback.
-
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 :) |
Beta Was this translation helpful? Give feedback.
-
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() |
Beta Was this translation helpful? Give feedback.
-
Thanks for the tips. I used option 2, with the 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 |
Beta Was this translation helpful? Give feedback.
-
Thanks for the feedback :) I moved this to discussions (I hope that's okay). Did I understand correctly that you had to manually convert reach names to the snake-case version? If you're using a jupyter notebook, then you should be able to use autocompletion for these reach names after running a cell that reads the Res1D object. However, if you're using a plain script, then autocompletion isn't possible. For that use-case it's actually very inconvenient, as you experienced. There's no reason why your suggestion couldn't work (and I agree it's more intuitive!). You could try installing the development branch where this is actually possible already. The only benefit to using attributes instead of string indexing is that you can chain together objects with '.' notations on a single line, where you get autocompletion after every single dot. If you use string indexing, then there's no autocompletion after the closing square bracket. In that case, you have to assign the reach to a variable, and then use that variable to access the autocompletion. On the main branch, referencing either with attributes or string indexing works. |
Beta Was this translation helpful? Give feedback.
-
I have a res1d file which contains the results from a simulation in Mike+. I imported that file with
df = mikeio1d.Res1D("model_m1d - Result Files/modelBaseDefault_Network_HD.res1d")
One of the reaches in the model is a tunnel which I earlier opened with
discharge = df.read(mikeio1d.res1d.QueryDataReach("Discharge", 'Fictious outlet Valldalen-Basin'))
But I get an error:
NoDataForQuery: Invalid query Discharge:Fictious outlet Valldalen-Basin
It works properly in mikeio1d version 0.3.0, but not in 0.4.0. Is it a bug?
Beta Was this translation helpful? Give feedback.
All reactions