{ "cells": [ { "cell_type": "markdown", "id": "87020fcf-4551-4cc1-b36c-e54ae89df700", "metadata": {}, "source": [ "# Malaria" ] }, { "cell_type": "code", "execution_count": 2, "id": "4f2c2105-520c-4267-b012-fe80250f5fa9", "metadata": {}, "outputs": [], "source": [ "import folium\n", "import geopandas as gpd\n", "import matplotlib.cm as cm\n", "import matplotlib.pyplot as plt\n", "import numpy as np\n", "import pandas as pd\n", "from matplotlib.colors import rgb2hex\n", "\n", "from pyinla.model import *\n", "from pyinla.raster import *\n", "from pyinla.spde import *\n", "from pyinla.utils import *" ] }, { "cell_type": "code", "execution_count": 3, "id": "6d335464-5692-4765-8615-0e35342cf99c", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "R[write to console]: --------------------------------------------------------------\n", " Analysis of Geostatistical Data\n", " For an Introduction to geoR go to http://www.leg.ufpr.br/geoR\n", " geoR version 1.9-2 (built on 2022-08-09) is now loaded\n", "--------------------------------------------------------------\n", "\n", "\n" ] } ], "source": [ "gambia = ro.r('library(\"geoR\"); data(Gambia); gambia')" ] }, { "cell_type": "code", "execution_count": 4, "id": "75c7542e-a5b3-4eb1-a6d7-619d909b1b06", "metadata": {}, "outputs": [], "source": [ "agg = gambia.groupby([\"x\", \"y\"])" ] }, { "cell_type": "code", "execution_count": 5, "id": "a45486cb-413f-45f4-983e-ff086eae5ddf", "metadata": {}, "outputs": [], "source": [ "total = agg[\"pos\"].size()\n", "positive = agg[\"pos\"].sum()\n", "prevalence = positive / total" ] }, { "cell_type": "code", "execution_count": 6, "id": "48f70ece-bb5e-49ee-ba2c-4c606526e9c0", "metadata": {}, "outputs": [], "source": [ "x, y = list(zip(*agg.groups.keys()))" ] }, { "cell_type": "code", "execution_count": 7, "id": "7dd05b4e-f07b-49d1-beaa-009c33bf7b34", "metadata": {}, "outputs": [], "source": [ "d = dict(\n", " x=np.array(x),\n", " y=np.array(y),\n", " total=total.values,\n", " positive=positive.values,\n", " prevalence=prevalence.values,\n", ")" ] }, { "cell_type": "code", "execution_count": 8, "id": "b9dd0dba-3a8f-4979-8d90-2739d3886969", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/var/folders/l1/xkqt8tg56t325lgp9ctmslwm0000gn/T/ipykernel_92607/3175676654.py:5: UserWarning: Geometry is in a geographic CRS. Results from 'centroid' are likely incorrect. Use 'GeoSeries.to_crs()' to re-project geometries to a projected CRS before this operation.\n", "\n", " gdf[\"long\"] = geom.centroid.x\n", "/var/folders/l1/xkqt8tg56t325lgp9ctmslwm0000gn/T/ipykernel_92607/3175676654.py:6: UserWarning: Geometry is in a geographic CRS. Results from 'centroid' are likely incorrect. Use 'GeoSeries.to_crs()' to re-project geometries to a projected CRS before this operation.\n", "\n", " gdf[\"lat\"] = geom.centroid.y\n" ] } ], "source": [ "gdf = gpd.GeoDataFrame.from_dict(\n", " d, geometry=gpd.points_from_xy(x=x, y=y), crs=\"+proj=utm +zone=28\"\n", ").to_crs(\"+proj=longlat +datum=WGS84\")\n", "geom = gdf.geometry.to_crs(\"+proj=longlat +datum=WGS84\")\n", "gdf[\"long\"] = geom.centroid.x\n", "gdf[\"lat\"] = geom.centroid.y" ] }, { "cell_type": "code", "execution_count": 9, "id": "b67e7fbe-03d4-4125-ad93-0a76542f9841", "metadata": {}, "outputs": [ { "data": { "text/html": [ "