5. Python initialise scripts¶
Python initialise scripts provide the following features:
- Building mapping coordinates files for the application
- Creating custom geojson and topojson files
- Management commands
Note: these scripts are not directly used by the application at runtime. If you wish to extent or develop features such as using another EEIO dataset it is recommendend to investigate how these script work. Deployment management commands are used for populating the database, see section 4.3.
5.1. Building mapping coordinates files for the application¶
EXIOBASE v3.3 has specific classifications that needs to map to user input. For example if Europe is selected by the user as one of the parameters for analyses, the calculation procedure uses indices corresponding to all countries belonging to Europe. In turn these calculation results need to be aggregated back into a single value for Europe. For coordinating user input to calculation procedures the RaMa-Scene application developed the following mapping CSV’s :
- final_countryTree_exiovisuals.csv
- final_productTree_exiovisuals.csv
These files are read in by the script prepare_csv.py
that in turn makes a slight modification to easily denote aggregated or disaggregated countries or product categories.
Note : see project folder python_ini/data & python_ini/devScripts.
5.2. Creating custom geojson and topojson files¶
For visualizations of continental data custom polygons need to be created that reflect the country mapping of EXIOBASE. A script is developed to dissolve countries that belong to a certain continent or “rest of ” classification with the library GeoPandas.
Relevant scripts: geo_dissolve_by_level.py
, prepare_geomapping_ISO3166_3.py
, prepare_geomapping_ISO3166_2.py
Note : see project folder python_ini/geomapBuilds
5.3. Management commands¶
This application uses a sql-lite database to store mapping coordinates, user queries (Jobs) and user results (Celery results). For mapping coordinates the database needs to be populated before running the application.
The management commands uses CSV files generated by prepare_csv.py
:
- mod_final_countryTree_exiovisuals.csv
- mod_final_productTree_exiovisuals.csv
The following command is used to populate the database python manage.py populateHierarchies
populates the database with the mapping files needed.
Aside from database population, it is necessary to clean the database of results when needed. This can be done
with the following command python manage.py clear_models
Note : see project folder ramascene/management/commands