Skip to content

Commit

Permalink
merge #31
Browse files Browse the repository at this point in the history
  • Loading branch information
domeniconappo committed Sep 5, 2019
2 parents d8ce51f + ded0cb7 commit c70f5e1
Show file tree
Hide file tree
Showing 36 changed files with 410 additions and 1,300 deletions.
31 changes: 16 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,17 @@ Other useful resources
## Quick start

You can download code and datasets for testing the model.
Follow this instruction for a basic test (Drina catchment, included in this repository under [tests/data/Drina](https://github.com/ec-jrc/lisflood-code/tree/master/tests/data/Drina))
Follow this instruction for a basic test (included in this repository under [tests/data/TestCatchment1](https://github.com/ec-jrc/lisflood-code/tree/master/tests/data/TestCatchment1))

1. Clone the master branch of this repository (you need to have git installed on your machine).

```bash
git clone --single-branch --branch master https://github.com/ec-jrc/lisflood-code.git
```

2. Install requirements into a python virtualenv.
We recommend to follow the instructions on [virtualenv docs](https://virtualenv.pypa.io/en/latest/). Assuming you activated your virtual environment:
2. Install requirements into a Python 3 virtualenv.
We recommend to follow the instructions on [virtualenv docs](https://virtualenv.pypa.io/en/latest/).
Assuming you've activated your virtual environment, you can now install requirements with pip:

```bash
cd lisflood-code # move into lisflood-code project directory
Expand All @@ -48,7 +49,7 @@ To compile this Cython module to enable OpenMP multithreading (parallel kinemati

* Delete the files *.so (if any) in directory hydrological-modules

* Inside the hydrological_modules folder, execute "python2 compile_kinematic_wave_parallel_tools.py build_ext --inplace"
* Inside the hydrological_modules folder, execute "python compile_kinematic_wave_parallel_tools.py build_ext --inplace"

Important: the module has to be compiled on the machine where the model is run - the resulting binary is not portable.

Expand All @@ -60,15 +61,15 @@ Then in the settings file the option "numberParallelThreadsKinematicWave" may ta
```xml
<textvar name="numCPUs_parallelKinematicWave" value="3"/>
```
4. Run a cold run for the Drina test catchment
4. Run a cold run for the test catchment

Now your environment should be set up to run lisflood. Try with a prepared settings file for Drina catchment:
Now your environment should be set up to run lisflood. Try with a prepared settings file for one of the two test catchments:

```bash
python src/lisf1.py tests/data/Drina/settings/lisfloodSettings_cold_day_base.xml
python src/lisf1.py tests/data/TestCatchment1/settings/lisfloodSettings_cold_day_base.xml
```

If the command above successed without errors, producing dis.nc into tests/data/Drina/outputs folder, your lisflood installation was correct.
If the command above successed without errors, producing dis.nc into tests/data/TestCatchment1/outputs folder, your lisflood installation was correct.

### Docker image

Expand All @@ -80,26 +81,26 @@ First, you pull image from repository.
docker pull efas/lisflood:latest
```

Copy Drina catchment files from container to your host, using mapped directories.
Copy catchment files from container to your host, using mapped directories.

```bash
docker run -v /absolute_path/to/my/local/folder:/usecases efas/lisflood:latest usecases
```

After this command, you can find all files to run a test against Drina catchment under the directory you mapped: `/absolute_path/to/my/local/folder/Drina`
After this command, you can find all files to run a test against a catchment under the directory you mapped: `/absolute_path/to/my/local/folder/TestCatchment1`


Now, you can run LISFLOOD as a docker container to test the Drina catchment. Only thing you need to do is to map the Drina folder to the container folder `input`, by using -v option.
Now, you can run LISFLOOD as a docker container to test included catchments. Only thing you need to do is to map the TestCatchment1 folder to the container folder `input`, by using -v option.
In the XML settings file, all paths are adjusted to be relative to the very same settings file, so you don't need to edit paths, as long as you keep same folders structure.


Execute the following to run the simulation:

```bash
docker run -v /absolute_path/to/my/local/folder/Drina:/input efas/lisflood /input/settings/lisfloodSettings_cold_day_base.xml
docker run -v /absolute_path/to/my/local/folder/TestCatchment1:/input efas/lisflood /input/settings/cold_day_base.xml
```

Once LISFLOOD finished, you can find reported maps in `/absolute_path/to/my/local/folder/Drina/outputs/` folder.
Once LISFLOOD finished, you can find reported maps in `/absolute_path/to/my/local/folder/TestCatchment1/outputs/` folder.

### Pypi packaged LISFLOOD

Expand All @@ -112,13 +113,13 @@ pip install lisflood-model
Command above will also install the executable `lisflood` in the virtualenv, so that you can run LISFLOOD with the following:

```bash
lisflood /absolute_path/to/my/local/folder/Drina/settings/lisfloodSettings_cold_day_base.xml
lisflood /absolute_path/to/my/local/folder/TestCatchment1/settings/lisfloodSettings_cold_day_base.xml
```

## Collaborate

If you find an issue in our code, plese follow the [GitHub flow](https://guides.github.com/introduction/flow/) to propose your changes (Fork, commit your changes and ask for a Pull Request).
When you develop, you need to run our "acceptance" tests. We have a couple of tests (domains are Drina and Madeira catchments) that can run with tox on py27, py36, py37 environments.
When you develop, you need to run our "acceptance" tests. We have two test catchments, that can run with tox on py27, py36, py37 environments.
Simply execute `tox` on comman line from project folder.

Tox tests can last minutes. You can also just use pytest and run tests in a single environment (e.g. Python 3.7).
Expand Down
4 changes: 2 additions & 2 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ set -e
if [[ "$1" = 'usecases' ]]; then
mkdir -p /usecases
echo "Copying maps to /input/Drina..."
cp -R /tests/data/Drina /usecases/
chmod a+w /usecases/Drina/settings/*.xml
cp -R /tests/data/TestCatchment1 /usecases/
chmod a+w /usecases/TestCatchment1/settings/*.xml
else
exec python /lisf1.py "$@"
fi
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ xarray
pyproj
nine
future
lisflood-utilities
1 change: 0 additions & 1 deletion src/lisf1.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
######################################################################
"""

# to work with the new grid engine JRC - workaround with error on pyexpat
import sys

from lisflood.main import main
Expand Down
6 changes: 4 additions & 2 deletions src/lisflood/Lisflood_dynamic.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,8 @@ def dynamic(self):
if i == 1:
# flag for netcdf output for all, steps and end
_ = CDFFlags(uuid.uuid4()) # init CDF flags
# globals.cdfFlag = [0, 0, 0, 0 ,0 ,0,0]

self.TimeSinceStart = self.currentTimeStep() - self.firstTimeStep() + 1

if flags['loud']:
print("%-6i %10s" % (self.currentTimeStep(), self.CalendarDate.strftime("%d/%m/%Y %H:%M")))
else:
Expand All @@ -64,6 +62,10 @@ def dynamic(self):
# Print step number and date to console
sys.stdout.write("\r%d" % i), sys.stdout.write("%s" % " - "+self.CalendarDate.strftime("%d/%m/%Y %H:%M"))
sys.stdout.flush()
if i == self.nrTimeSteps():
# last timestep. Send a new line to the terminal for polishness
sys.stdout.write('\n')
sys.stdout.flush()

# ************************************************************
""" up to here it was fun, now the real stuff starts
Expand Down
Loading

0 comments on commit c70f5e1

Please sign in to comment.