Ensure that you have a C compiler (gcc), git, virtualenv and its required dependencies installed. The versions from the system reposity on Ubuntu 18.04 are sufficient. Then, this repository can be installed via:
git clone --recurse-submodules https://github.com/LyteFM/tree-cover-server.git
virtualenv --python=python3.7 venv
source venv/bin/activate
pip install -r requirements.txtCompile the sqlite extension file into the tree cover directory. Instructions are given for Linux, for other OS check the extension-functions.c.
cd treecover
gcc -fPIC -lm -shared extension-functions.c -o libsqlitefunctions.so
cd ..For local development in debug mode, run:
export FLASK_APP=server.py
export FLASK_DEBUG=1
flask runFor production use, you can use:
gunicorn wsgi:appIf you get an import error for flask_bootstrap, try deactivate and source venv/bin/activate again. Ensure that you're
authenticated via earthengine authenticate. You can use the UI in two ways:
- Upload a small CSV file with the columns
longitude,latitude,Aridity_Zoneand optionally aplot_id. An example is given intreecover/data/example_fetch_sentinel_input.csv. - Upload a CSV with already populated features by using the command line tool. Example:
treecover/data/example_server_sentinel_input.csvorexample_input_file_landsat.csv
The webapp without GEE retrieval can be viewed at: http://tree-cover.herokuapp.com/ Note that Heroku deployment only works with submodules when pushing from the command line.
The command line tool located in treecover/sentinel.py can be used to fetch raw data for the locations given in a CSV file with columns longitude, latitude, Aridity_Zone and optionally a plot_id.
If the compiled extension is not located in treecover/libsqlitefunctions.so, you need to pass its location as --libsqlite PATH/TO/EXTENSION for modes 1 and 3.
You can use it in the following modes:
- Only write the necessary features to a specified csv file
- Only write the raw fetched data to a sqlite db
- Write the raw fetched data to a sqlite db and export the features to a csv file
source venv/bin/activate
cd treecover
# Mode 1:
python3 sentinel.py data/example_fetch_sentinel_input.csv --output outfile_1.csv
# Mode 2:
python3 sentinel.py data/example_fetch_sentinel_input.csv --db data/my_small_test.db
# Mode 3:
python3 sentinel.py data/example_fetch_sentinel_input.csv --db data/my_small_test.db --output my_small_outfile.csvIn order to save some RAM, you can specify e.g. --chunk 10 in order to commit transactions/ append to the csv after 10 instead of the default of 100 processed rows.
Then, a GCP f1-micro with enough disk space is sufficient.