Web application to explore carbon budgets
The web application is written with SveltKit.
Should have the following data files:
{CABE_DATA_DIR} / "ne_110m_admin_0_countries.geojson"- can be downloaded withnpm run download:bordersand move downloaded file to CABE_DATA_DIR directory.{CABE_DATA_DIR} / "xr_policyscen.nc"- Policy scenario data{CABE_DATA_DIR} / {CABE_START_YEAR} / "xr_dataread.nc"- Global data{CABE_DATA_DIR} / {CABE_START_YEAR} / {CABE_ASSUMPTIONSET} / "Allocations" / "xr_alloc_{REGION}.nc"- Region specific data{CABE_DATA_DIR} / {CABE_START_YEAR} / {CABE_ASSUMPTIONSET} / "Aggregated_files" / "xr_alloc_{YEAR}.nc"- Aggregated data
The CABE_DATA_DIR variable is the path to the data directory.
The CABE_START_YEAR variable is the start year of the allocation.
The CABE_ASSUMPTIONSET variable encodes assumptions on which gases are included (GHG or CO2_only) and land use (included/excluded).
The REGION variable is the 3 letter ISO code of the region.
The YEAR variable is the year of the allocation.
The CABE_ variables are defined in the .env file.
See .env.example file for an example.
To run the application the .env file is required.
You should have Node.js (v22 or greater) and Python 3.12 installed.
Dependencies can be installed with
# From the root of the repository
# To install Node.js dependencies
npm install
# To install Python dependencies
pip install -r requirements.txtUse miniforge to setup Python and Node.js.
- From https://conda-forge.org/download download the latest Miniforge3 Windows 64-bit installer and install it.
- Open a PowerShell
- Create environment with
mamba create --name cabe python=3.12 nodejs=22 - Activate environment with
mamba activate cabe - Change the current working directory to the location where you want to clone the repository. For example
cd C:\Users\username\Documents. - Clone repo with
git clone https://github.com/pbl-nl/website-carbon-budget-explorer.gitor use Visual Studio Code to clone repository. - Change the current working directory to the repository with
cd website-carbon-budget-explorer. - Install Python dependencies with
pip install -r requirements.txt - Install Node.js dependencies with
npm install
If git executable is not installed, then install with mamba install git.
If mamba executable is not available, use conda instead.
Do not forget to activate the environment with mamba activate cabe before running the commands below.
The API web service reads the NetCDF files and returns the data as JSON which is used in the web application.
It is written in Python using Flask and xarray.
On Linux and MacOS the web service can be started with
gunicorn --bind 0.0.0.0:5000 --workers 4 'ws:app'(Add --reload argumment to reload on Python file changes)
On Windows, use flask built-in developer server.
flask --app ws:app run -p 5000If an error occurs here, try out different ports (e.g. 5001, 5005 etc). Also adjust the changed port in the .env file.
To see the routes of the web service use
flask --app ws:app routes -s ruleStart a development server:
npm run dev
# or start the server and open the app in a new browser tab
npm run dev -- --openThe code is formatted with Prettier using
npm run formatThe code can be linted, using Prettier and eslint, with
npm run lintThe code can be checked with
npm run checkThe Python web service (ws.py) can be formatted and linted with Ruff
pip install ruff
ruff check
ruff formatThe unit test can be run with
npm run test:unitFor coverage, run
npm run test:unit -- run --coverageThe end-to-end test can be run with
npm run testTo create a production version of your app:
npm run buildYou can run the production build with
node --env-file=.env build/index.jsThe web application server expects the Python web service to be running on http://127.0.0.1:5000.
The web application (aka the backend for the frontend aka SvelteKit server) caches the web service requests aggressively. It will use up to 1GB of memory for caching api requests made directly by browser and another 1Gb of memory for caching api requests made by the backend for the frontend.
If you changed the data then the web service and the web application server must be restarted.