Modified Instructions for RAPID_py: Kalman Filtering for River Network Modeling
As in the original instructions, ensure you have Conda installed on your system to manage the environment and dependencies.
Before beginning, navigate to the repository's requirements.txt file. The package versions listed here weren't all compatible for me, so I had to alter them slightly; what worked for me was to modify the matplotlib-base version to 3.6.2.
Then, as in the original instructions:
-
Create a Conda environment:
conda create --name <env_name> conda activate <env_name>
-
Install the required libraries:
Navigate to the repository's root directory.
For me, using
pip install -r requirements.txtto install the required packages as per the original instructions didn't work; instead I used:conda install --file requirements.txt --channel conda-forge
Alternatively, you can perform both steps 1 and 2 above at the same time using:
From the root directory:
conda create --name <env_name> --file requirements.txt --channel conda-forge conda activate <env_name>
As mentioned in the original instructions, before executing any scripts, we must first prepare/obtain the data.
As the original instructions explain, the official dataset is available from Zenodo, but it is highly recommended to use the quick access data provided by the original author(s) of this repository, as it allows for (almost; more on this later) all of the files required by the scripts to be quickly downloaded all at once for immediate use:
Download this entire Google Drive folder provided by this repository's author(s), unzip the contents into a folder/directory named rapid_data, and place this folder/directory in the root directory of the repository. It's important that this folder/directory is exactly named rapid_data.
There are a few more things we must do before we can successfuly run the scripts.
-
First, there are references in the code to a file in the dataset named
m3_d_riv.csv. However, no such file exists, neither in the quick access data provided by the repository's author(s) nor in the official dataset on Zenodo. Thus, to be able to execute the code, we remove / comment out all references to this file (and references to objects that reference this file) in the code:- In the file
rapid_python.py, comment out line 111. - In the file
utility.py, comment out lines 32, 50, 67, and 73.
- In the file
-
Ensure that in line 285 of
rapid_python.py,load_modeis set to0, so that the data load mode is set to file (=0), rather than pickle (=1) or both (=2). -
Finally, in line 286 of
rapid_python.py, set sim_mode to either0or1, to set the simulation mode to open loop (=0) or Kalman Filter estimation (=1).
Now, we can finally execute the scripts.
As per the original instructions, there is currently only one Kalman Filter implementation / modeling approach (more are being developed):
-
Original Kalman Filter Implementation:
- Description: Directly follows the methodology outlined in the referenced paper, with the state variable representing lateral inflows.
- Execution: Run
python rapid_python.pyto perform the simulation.
The output generated by the execution of this rapid_python.py script will be located in a new directory in the root directory, named model_saved_3hour. Note: one of the files generated is load_coef.pkl, which, if we like, we can use to run rapid_python.py with load_mode set to 1 (pickle) or 2 (both file and pickle)!
After completing the execution of rapid_python.py above, to be able to plot the geographical river network, create a directory named model_saved in the root directory, and place the file discharge_est.csv (located in the model_saved_3hour directory generated by the execution of rapid_python.py) into this model_saved directory.
Now, as per the original instructions, to plot the geographical river network, use the following command:
python visualize_with_shp.pyThe output of the execution of this visualize_with_shp.py script will be in the model_saved directory.
Finally, if you'd like to (graphically) plot the changes in river flow, as per the original instructions, use this command to visualize the estimation discharge_est.csv:
python evaluate_open_loop.pyThe output of the execution of this evaluate_open_loop.py script will be in a new directory in the root directory, named figure.