-
Notifications
You must be signed in to change notification settings - Fork 0
Snt25 518 #96
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
EstebanMontandon
wants to merge
5
commits into
main
Choose a base branch
from
SNT25-518
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Snt25 518 #96
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
efd6e98
first commit
EstebanMontandon 7d8fae2
feat(map): try build pop table
EstebanMontandon 34ac46f
feat(map): indicators computation per year
EstebanMontandon 2519d25
fix(map): report (standard)
EstebanMontandon 01687bc
fix(): reviews from copilot.
EstebanMontandon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ SNT Process/ | |
| .vscode/ | ||
| venv/ | ||
| uv.lock | ||
| __pycache__/ | ||
|
|
||
| # Jupyter stuff ------------------------- | ||
|
|
||
|
|
||
367 changes: 156 additions & 211 deletions
367
pipelines/snt_map_extracts/reporting/snt_map_extracts_report.ipynb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,216 +1,161 @@ | ||
| { | ||
| "cells": [ | ||
| { | ||
| "cell_type": "markdown", | ||
| "id": "5777b72c-d87e-47c5-87b1-2698a6510b2f", | ||
| "metadata": {}, | ||
| "source": [ | ||
| "# **Cartes extraites du Malaria Atlas Project (MAP)**" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "id": "6397ab91-1ae4-4db7-b6c3-061c453a7b03", | ||
| "metadata": { | ||
| "vscode": { | ||
| "languageId": "r" | ||
| } | ||
| }, | ||
| "outputs": [], | ||
| "source": [ | ||
| "# Set SNT Paths\n", | ||
| "SNT_ROOT_PATH <- \"~/workspace\"\n", | ||
| "CODE_PATH <- file.path(SNT_ROOT_PATH, \"code\")\n", | ||
| "CONFIG_PATH <- file.path(SNT_ROOT_PATH, \"configuration\")\n", | ||
| "PIPELINE_PATH <- file.path(SNT_ROOT_PATH, \"pipelines\", \"snt_map_extracts\")\n", | ||
| "\n", | ||
| "# load util functions\n", | ||
| "source(file.path(CODE_PATH, \"snt_utils.r\"))\n", | ||
| "source(file.path(PIPELINE_PATH, \"utils\", \"snt_map_extracts_report.r\"))\n", | ||
| "\n", | ||
| "# List required packages\n", | ||
| "required_packages <- c(\"dplyr\", \"tidyr\", \"terra\", \"ggplot2\", \"stringr\", \"lubridate\", \"viridis\", \"patchwork\", \"zoo\", \"purrr\", \"arrow\", \"sf\", \"reticulate\")\n", | ||
| "\n", | ||
| "# Execute function\n", | ||
| "install_and_load(required_packages)\n", | ||
| "\n", | ||
| "# Set environment to load openhexa.sdk from the right environment\n", | ||
| "Sys.setenv(RETICULATE_PYTHON = \"/opt/conda/bin/python\")\n", | ||
| "reticulate::py_config()$python\n", | ||
| "openhexa <- import(\"openhexa.sdk\")\n", | ||
| "\n", | ||
| "# Load SNT config\n", | ||
| "config_json <- tryCatch({ jsonlite::fromJSON(file.path(CONFIG_PATH, \"SNT_config.json\"))},\n", | ||
| " error = function(e) {\n", | ||
| " msg <- paste0(\"Error while loading configuration\", conditionMessage(e))\n", | ||
| " cat(msg)\n", | ||
| " stop(msg)\n", | ||
| " })\n", | ||
| "\n", | ||
| "# Required environment for the sf packages\n", | ||
| "Sys.setenv(PROJ_LIB = \"/opt/conda/share/proj\")\n", | ||
| "Sys.setenv(GDAL_DATA = \"/opt/conda/share/gdal\")" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "id": "93e04996-13ba-4855-a1d1-46e70ba4640e", | ||
| "metadata": { | ||
| "vscode": { | ||
| "languageId": "r" | ||
| } | ||
| }, | ||
| "outputs": [], | ||
| "source": [ | ||
| "# Configuration variables\n", | ||
| "DATASET_NAME <- config_json$SNT_DATASET_IDENTIFIERS$SNT_MAP_EXTRACT\n", | ||
| "COUNTRY_CODE <- config_json$SNT_CONFIG$COUNTRY_CODE\n", | ||
| "ADM_2 <- toupper(config_json$SNT_CONFIG$DHIS2_ADMINISTRATION_2)" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "id": "a1ee21d1-c7d1-4893-ac56-91abb92926ea", | ||
| "metadata": { | ||
| "vscode": { | ||
| "languageId": "r" | ||
| } | ||
| }, | ||
| "outputs": [], | ||
| "source": [ | ||
| "# printdim() loaded from utils/snt_map_extracts_report.r" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "id": "f7de799e-896c-4237-a9f6-9dafc0f30bde", | ||
| "metadata": { | ||
| "vscode": { | ||
| "languageId": "r" | ||
| } | ||
| }, | ||
| "outputs": [], | ||
| "source": [ | ||
| "# import seasonality data\n", | ||
| "map_data <- load_map_report_input(\n", | ||
| " dataset_name = DATASET_NAME,\n", | ||
| " filename = paste0(COUNTRY_CODE, \"_map_data.parquet\"),\n", | ||
| " label = \"MAP extracted data\"\n", | ||
| ")\n", | ||
| "\n", | ||
| "# import DHIS2 shapes data\n", | ||
| "DATASET_DHIS2 <- config_json$SNT_DATASET_IDENTIFIERS$DHIS2_DATASET_FORMATTED\n", | ||
| "shapes_data <- load_map_report_input(\n", | ||
| " dataset_name = DATASET_DHIS2,\n", | ||
| " filename = paste0(COUNTRY_CODE, \"_shapes.geojson\"),\n", | ||
| " label = \"DHIS2 shapes data\"\n", | ||
| ")\n", | ||
| "\n", | ||
| "printdim(map_data)" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "id": "84031c7e-e9c6-4496-896f-7f7f3403d951", | ||
| "metadata": { | ||
| "vscode": { | ||
| "languageId": "r" | ||
| } | ||
| }, | ||
| "outputs": [], | ||
| "source": [ | ||
| "names(map_data)" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "id": "66b05b53-3f65-424a-af22-0686238a06c9", | ||
| "metadata": { | ||
| "vscode": { | ||
| "languageId": "r" | ||
| } | ||
| }, | ||
| "outputs": [], | ||
| "source": [ | ||
| "unique(map_data$METRIC_NAME)" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "id": "9d0515ab-4dc2-4671-8c3c-236578a840d8", | ||
| "metadata": { | ||
| "vscode": { | ||
| "languageId": "r" | ||
| } | ||
| }, | ||
| "outputs": [], | ||
| "source": [ | ||
| "# Merge geometry with map data\n", | ||
| "map_data_joined <- dplyr::left_join(shapes_data, map_data, by = c(\"ADM2_ID\" = \"ADM2_ID\"))\n", | ||
| "\n", | ||
| "# Get list of metrics\n", | ||
| "metrics <- unique(map_data$METRIC_NAME)\n", | ||
| "\n", | ||
| "# Create one map per metric\n", | ||
| "plots <- build_metric_plots(map_data_joined = map_data_joined, metrics = metrics)" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "id": "0f1dc1df-211d-4174-83ae-e8ae974fa790", | ||
| "metadata": { | ||
| "vscode": { | ||
| "languageId": "r" | ||
| } | ||
| }, | ||
| "outputs": [], | ||
| "source": [ | ||
| "# Set plot size for individual display\n", | ||
| "options(repr.plot.width = 10, repr.plot.height = 8)\n", | ||
| "\n", | ||
| "# Loop through plots and print one by one\n", | ||
| "for (p in plots) {\n", | ||
| " print(p)\n", | ||
| " Sys.sleep(1) # Optional: short pause between plots\n", | ||
| "}" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "id": "50c843e4-9157-480d-acde-80887410d156", | ||
| "metadata": { | ||
| "vscode": { | ||
| "languageId": "r" | ||
| } | ||
| }, | ||
| "outputs": [], | ||
| "source": [] | ||
| "cells": [ | ||
| { | ||
| "cell_type": "markdown", | ||
| "id": "5777b72c-d87e-47c5-87b1-2698a6510b2f", | ||
| "metadata": {}, | ||
| "source": [ | ||
| "# **Cartes extraites du Malaria Atlas Project (MAP)**" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "markdown", | ||
| "id": "f0860675-9819-4a0a-b0ce-23f1b16d40c3", | ||
| "metadata": {}, | ||
| "source": [ | ||
| "## Setup" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "id": "dfb0dee9-0da8-4afd-9f3a-7e8f0a830f85", | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "source(file.path(\"~/workspace/pipelines/snt_map_extracts/utils/snt_map_extracts_report.r\"))\n", | ||
| "setup_var <- get_setup_variables(packages= c(\"arrow\", \"dplyr\", \"tidyr\", \"stringr\", \"stringi\", \"jsonlite\", \"httr\", \"reticulate\", \"glue\"))\n", | ||
| "config_json <- load_snt_config(file.path(setup_var$CONFIG_PATH, \"SNT_config.json\"))\n", | ||
| "\n", | ||
| "# Save config variables\n", | ||
| "DATASET_MAP <- config_json$SNT_DATASET_IDENTIFIERS$SNT_MAP_EXTRACT\n", | ||
| "DATASET_FORMATTED <- config_json$SNT_DATASET_IDENTIFIERS$DHIS2_DATASET_FORMATTED\n", | ||
| "COUNTRY_CODE <- config_json$SNT_CONFIG$COUNTRY_CODE" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "markdown", | ||
| "id": "6b3456da-ddfd-4b9b-9c9b-506f583aab3e", | ||
| "metadata": {}, | ||
| "source": [ | ||
| "## Load Data" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "id": "f7de799e-896c-4237-a9f6-9dafc0f30bde", | ||
| "metadata": { | ||
| "vscode": { | ||
| "languageId": "r" | ||
| } | ||
| ], | ||
| "metadata": { | ||
| "kernelspec": { | ||
| "display_name": "R", | ||
| "language": "R", | ||
| "name": "ir" | ||
| }, | ||
| "language_info": { | ||
| "codemirror_mode": "r", | ||
| "file_extension": ".r", | ||
| "mimetype": "text/x-r-source", | ||
| "name": "R", | ||
| "pygments_lexer": "r", | ||
| "version": "4.4.3" | ||
| }, | ||
| "outputs": [], | ||
| "source": [ | ||
| "# Load parameters\n", | ||
| "map_parameters <- load_dataset_file(dataset_id = DATASET_MAP, filename = paste0(COUNTRY_CODE, \"_parameters.json\"))\n", | ||
| "cat(jsonlite::toJSON(map_parameters, pretty = TRUE, auto_unbox = TRUE), \"\\n\")\n", | ||
| "\n", | ||
| "# Load latest year file available\n", | ||
| "map_data <- load_dataset_file(dataset_id = DATASET_MAP, filename = glue(\"{COUNTRY_CODE}_map_data_{map_parameters$YEAR_END}.parquet\"))\n", | ||
| "\n", | ||
| "# import DHIS2 shapes data\n", | ||
| "shapes_data <- load_dataset_file(dataset_id = DATASET_FORMATTED, filename = paste0(COUNTRY_CODE, \"_shapes.geojson\"))\n", | ||
| "\n", | ||
| "printdim(map_data)" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "id": "66b05b53-3f65-424a-af22-0686238a06c9", | ||
| "metadata": { | ||
| "vscode": { | ||
| "languageId": "r" | ||
| } | ||
| }, | ||
| "outputs": [], | ||
| "source": [ | ||
| "print(glue(\"Year file selection: {map_parameters$YEAR_END}\"))\n", | ||
| "print(glue(\"Indicators: {unique(map_data$METRIC_NAME)}\"))" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "markdown", | ||
| "id": "0ea5587e-b7d3-47c1-a4b3-c69061d24bca", | ||
| "metadata": {}, | ||
| "source": [ | ||
| "## Create plots \n", | ||
| "\n", | ||
| "We select the latest year of the selected years based on the parameters run." | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "id": "9d0515ab-4dc2-4671-8c3c-236578a840d8", | ||
| "metadata": { | ||
| "vscode": { | ||
| "languageId": "r" | ||
| } | ||
| }, | ||
| "outputs": [], | ||
| "source": [ | ||
| "# Merge geometry with map data\n", | ||
| "map_data_joined <- dplyr::left_join(shapes_data, map_data, by = c(\"ADM2_ID\" = \"ADM2_ID\"))\n", | ||
| "\n", | ||
| "# Get list of metrics\n", | ||
| "metrics <- unique(map_data$METRIC_NAME)\n", | ||
| "\n", | ||
| "# Create one map per metric\n", | ||
| "plots <- build_metric_plots(map_data_joined = map_data_joined, metrics = metrics, year=map_parameters$YEAR_END)" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "id": "0f1dc1df-211d-4174-83ae-e8ae974fa790", | ||
| "metadata": { | ||
| "vscode": { | ||
| "languageId": "r" | ||
| } | ||
| }, | ||
| "outputs": [], | ||
| "source": [ | ||
| "# Set plot size for individual display\n", | ||
| "options(repr.plot.width = 10, repr.plot.height = 8)\n", | ||
| "\n", | ||
| "# Loop through plots and print one by one\n", | ||
| "for (p in plots) {\n", | ||
| " print(p)\n", | ||
| " Sys.sleep(1) # Optional: short pause between plots\n", | ||
| "}" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "id": "8eb9cc86-f3ed-45f2-84f3-9e395ef85106", | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [] | ||
| } | ||
| ], | ||
| "metadata": { | ||
| "kernelspec": { | ||
| "display_name": "R", | ||
| "language": "R", | ||
| "name": "ir" | ||
| }, | ||
| "nbformat": 4, | ||
| "nbformat_minor": 5 | ||
| "language_info": { | ||
| "codemirror_mode": "r", | ||
| "file_extension": ".r", | ||
| "mimetype": "text/x-r-source", | ||
| "name": "R", | ||
| "pygments_lexer": "r", | ||
| "version": "4.5.3" | ||
| } | ||
| }, | ||
| "nbformat": 4, | ||
| "nbformat_minor": 5 | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.