#!/usr/bin/env python # coding: utf-8 # # Res1D - Strategies for handling large files # In[1]: import mikeio1d # All static network data is loaded into memory by default. Dynamic result data is only loaded when required. # In[2]: res = mikeio1d.open("../tests/testdata/network.res1d") loaded_time_steps = res.data.NumberOfTimeSteps loaded_time_steps # Calling read() loads dynamic data for the entire network. # In[3]: res.read() loaded_time_steps = res.data.NumberOfTimeSteps loaded_time_steps # All network dynamic data is loaded into memory regardless of how read() is called. In the future, it would nice to make this work lazily. # In[4]: res = mikeio1d.open("../tests/testdata/network.res1d") # this still reads all network data, but only creates a DataFrame with the requested data res.nodes["1"].WaterLevel.read().head() # To avoid loading the entire network's dynamic data into memory, you can specify which IDs to load when opening the file. # In[5]: res = mikeio1d.open("../tests/testdata/network.res1d", nodes=["1"], reaches=["100l1"]) res.nodes # In[6]: res.reaches # In[7]: res.read() # Similarly, you can also specify the time range to read. # In[8]: start, end = "1994-08-07 18:30:07.967", "1994-08-07 18:33:07.967" res = mikeio1d.open( "../tests/testdata/network.res1d", nodes=["1"], reaches=["100l1"], time=(start, end) ) loaded_time_steps = res.data.NumberOfTimeSteps loaded_time_steps # In[9]: res.read() loaded_time_steps = res.data.NumberOfTimeSteps loaded_time_steps # In[10]: res.read().head() # It's also possible to load every 'nth' time step with the 'step_every' parameter. # In[42]: # First plot the full time series for a comparison res = mikeio1d.open( "../tests/testdata/network.res1d", reaches=["100l1"] ) ax = res.reaches['100l1'][0].WaterLevel.plot(linestyle='-', marker='x') # Then plot with every 5th time step res = mikeio1d.open( "../tests/testdata/network.res1d", reaches=["100l1"], step_every=5, ) ax = res.reaches['100l1'][0].WaterLevel.plot(ax=ax, linestyle='--', marker='o', color='g') ax.legend(["all steps", "step_every=5"]) ax.set_xlim("1994-08-07 17:15", "1994-08-07 17:50") # In[43]: res.data.NumberOfTimeSteps # Lastly you can also specify which quantities to include. # In[45]: res = mikeio1d.open( "../tests/testdata/network.res1d", nodes=["1"], reaches=["100l1"], step_every=10, quantities=["Discharge"] ) res.read()