carbon-budget-explorer / cabe

Web application to explore carbon budgets
Apache License 2.0
1 stars 0 forks source link

Carbon Budget Explorer (CABE)

DOI

Web application to explore carbon budgets

The web application is written with SveltKit.

[!WARNING]

This repo has been transferred to https://github.com/pbl-nl/ (private repo) where it was further tailored for production. A hosted instance is available at https://carbonbudgetexplorer.nl/.

Data requirements

Should have the following data files:

  1. data/xr_dataread.nc - NetCDF file
  2. data/xr_policyscen.nc - NetCDF file
  3. data/xr_allow_<3 letter ISO countr code>.nc - NetCDF file for each country
  4. data/xr_allow_<2030|2040|FC>.nc - NetCDF file
  5. data/ne_110m_admin_0_countries.geojson - can be downloaded with npm run download:borders

API service

The API web service reads the NetCDF file and returns the data as JSON which is used in the web application.

It is written in Python using Flask and xarray.

Python dependencies can be installed with

python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt

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)

In Windows gunicorn might not work. Then use waitress.

pip install waitress
waitress-serve --listen=127.0.0.1:5000 ws:app

Developing

You'll need node.js to run a local development server. Once you've created a project and installed dependencies with npm install (or pnpm install or yarn), start a development server:

npm run dev

# or start the server and open the app in a new browser tab
npm run dev -- --open

Formatting & linting

The code is formatted with Prettier using

npm run format

The code can be linted, using Prettier and eslint, with

npm run lint

The code can be checked with

npm run check

Testing

The unit test can be run with

npm run test:unit

For coverage, run

npm run test:unit -- run --coverage

Building

To create a production version of your app:

npm run build

You can the production build with

node build/index.js

To deploy your app, you may need to install an adapter for your target environment.

If the Python webservice is not running on http://127.0.0.1:5000 then set CABE_API_URL environment variable to right URL.