Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pridec_gee-0.1.0.tar.gz (734.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pridec_gee-0.1.0-py3-none-any.whl (745.2 kB view details)

Uploaded Python 3

File details

Details for the file pridec_gee-0.1.0.tar.gz.

File metadata

  • Download URL: pridec_gee-0.1.0.tar.gz
  • Upload date:
  • Size: 734.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","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":true}

File hashes

Hashes for pridec_gee-0.1.0.tar.gz
Algorithm Hash digest
SHA256 fdf12621600bd91f382284b8b073e69753c2ad8e2de313825bee895282ad3695
MD5 ef0aac4ae3453f5a11f9ad9c110a69c4
BLAKE2b-256 ffc2e18e1f2c30e14c306aafb6a2c86978f387195453990160b6e24bef9c9f8f

See more details on using hashes here.

File details

Details for the file pridec_gee-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: pridec_gee-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 745.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","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":true}

File hashes

Hashes for pridec_gee-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 637a7eee80524f9c388cba2fa897d40a53b3e5ff8ad4f3f59b8985af976a0ebc
MD5 ded7a7292346836e6965934accab1e55
BLAKE2b-256 94710b0444f560637cf2722db40acadd74a34ae667b17c958558f0e048c57b2a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page