Import environmental data from Google Earth Engine into DHIS2 instances
Project description
pridec-gee
A python library to extract environmental and climate variables from DHIS2 polygons and optionally import the data into a DHIS2 instance
Pre-requisites
DHIS2 Instance
Any DHIS2 instance can be used for the extraction of climate variables if it has associated polygons for the orgUnits of interest.
If you would like to import the climate variables into the DHIS2 instance, the PRIDE-C metadata must already be in place. Please see docs/pridec-climate-metadata.json for a list of dataElements to create. More info can be found at this configuration repo.
For testing, it is recommended that you use a local instance via the DHIS2 CLI.
You will need to either create a personal access token to access this account or have access to a username/password that can acces the geojson data and POST dataElements.
Google Earth Engine Service Account
This workflow requires an activated GEE service account, project, and service token. The information for this is stored in .gee-private-key.json. You can create your account following instructions here.
The GEE account can then either be authenticated via script or interactively:
#via script
credentials = ee.ServiceAccountCredentials(GEE_SERVICE_ACCOUNT, ".gee-private-key.json")
ee.Initialize(credentials)
#interactively
ee.Authenticate()
ee.Initialize(project=os.environ.get("GEE_PROJECT"))
Python
This requires Python>=3.12.
Installation
via github
pip install git+https://github.com/Pivot-Madagascar/pridec-gee.git
via pyPI
pip install pridec_gee
Usage
Create .env file
The library uses several sensitive variables that can be provided via script or .env file. An example .env file is below:
DHIS_URL='http://your-dhis-url.com'
DHIS_TOKEN='YOUR_DHIS_TOKEN' #or userame and password
DHIS_USER='your-dhis-username'
DHIS_PWD='your-dhis-password'
PARENT_OU='parent-orgunit-uid' #usually an 11 character string from DHIS2, corresponding to parent unit containing orgUnits of interest
OU_LEVEL='5' # corresponds to orgUnit hierarchy level for which you want to extract variables
GEE_PROJECT='YOUR_GEE_PROJECT_NAME'
GEE_SERVICE_ACCOUNT='YOUR_SERVICE_ACCOUNT@YOUR_CLOUD_PROJECT.iam.gserviceaccount.com'
(Opt) Back up sql database on server
If you are not using a test server, it is recommended to back up the SQL database before importing climate variables.
sudo -u postgres pg_dump dhis2 | gzip > NAME_OF_FILE.sql.gz
Extract climate vairables
Individual climate variables can be extracted using the fetch_* functions by providing a FeatureCollection of the orgUnits and a dateRange to extract. An example python script using the DHIS2 play instance is in docs/example.py.
The import_pridec_climate function runs the full PRIDE-C climate variable extraction and importation process if your DHIS2 instance contains the appropriate metadata structure.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pridec_gee-1.0.0.tar.gz.
File metadata
- Download URL: pridec_gee-1.0.0.tar.gz
- Upload date:
- Size: 734.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.4 {"installer":{"name":"uv","version":"0.10.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
296c5ca9c98f11824b71c341524b4dbcd5985597a0448b8ea9377ca3bf1de5ed
|
|
| MD5 |
3185e2e231ab0925acca1ef821a63eca
|
|
| BLAKE2b-256 |
dde6e6efd9e6af6fd01a28c0567a4c17cf1c8dc4e49065cee1a3a7f43ff78d29
|
File details
Details for the file pridec_gee-1.0.0-py3-none-any.whl.
File metadata
- Download URL: pridec_gee-1.0.0-py3-none-any.whl
- Upload date:
- Size: 745.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.4 {"installer":{"name":"uv","version":"0.10.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b50a74f5034c73f7f74a5dbf4e210dcb3933e3506a0277356087a4e0e163bdc6
|
|
| MD5 |
c7a216265a36613a6d39dedf2999d3a6
|
|
| BLAKE2b-256 |
0de3b4bd46fa478663a1274161c3e7474a976d7c740773d22b6ed4f67cc1f0a0
|