Skip to content

Commit

Permalink
Incluye .quarto/
Browse files Browse the repository at this point in the history
  • Loading branch information
flor14 committed Dec 12, 2023
1 parent ceacf63 commit c7cfd6b
Show file tree
Hide file tree
Showing 48 changed files with 14,859 additions and 0 deletions.
20 changes: 20 additions & 0 deletions .quarto/_freeze/analisis_datos_covid/execute-results/html.json

Large diffs are not rendered by default.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions .quarto/_freeze/creacion_de_rasters/execute-results/html.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"hash": "346afe36ab1c5ceae40d2503921f2afd",
"result": {
"markdown": "---\ntitle: \"Creación de imagenes raster\"\nlang: es\n---\n\n\n---\n\n**Datos iniciales:**\nLos archivos empleados para este procesamiento son los `.csv` diarios provistos por Meta que son reportados para tres momentos del día: 0am, 8am, 4pm en el periodo de analisis. Cada dato de movilidad se reporta por QuadKey.\n\n**Se busca obtener:**\nImagenes raster que representen el cambio porcentual semanal y prepandemia en \nla movilidad ciudadana.\n\n---\n\n## Procesamiento de datos iniciales\nPuedes encontrar un ejemplo detallado en [esta viñeta del paquete `quadkeyr`](https://fernandez-lab-wsu.github.io/quadkeyr/articles/create_rasters_from_grid.html).\nSe transcribe a continuación un ejemplo\n\n\n\n::: {.cell}\n::: {.cell-output .cell-output-stderr}\n```\n\nAttaching package: 'quadkeyr'\n```\n:::\n\n::: {.cell-output .cell-output-stderr}\n```\nThe following object is masked from 'package:graphics':\n\n clip\n```\n:::\n:::\n\n\n\n### 1. Carga y procesamiento de los csv \n\n\n::: {.cell}\n\n```{.r .cell-code}\nfiles <- read_all_files(path_to_csvs = \"../Desktop/Facebook data/AMBA_facebookpop/\",\n colnames = c(\"lat\", \"lon\", \n \"quadkey\", \"date_time\", \n \"n_crisis\", \"percent_change\"),\n coltypes = list(\n lat = 'd',\n lon = 'd',\n quadkey = 'd',\n date_time = 'T',\n n_crisis = 'c',\n percent_change = 'c')) \n\nfiles\n```\n:::\n\n\nDatos faltantes en la corrida para los archivos de AMBA: \n\n```\nday time\n1 2020-07-03 0\n2 2020-07-04 0\n3 2020-07-05 0\n4 2020-07-06 0\n5 2020-07-07 0\n6 2020-07-08 0\n7 2020-07-09 0\n8 2020-07-10 0\n9 2020-07-11 0\n10 2020-07-12 0\n11 2020-09-12 0\n12 2020-09-13 0\n13 2020-07-03 8\n14 2020-07-04 8\n15 2020-07-05 8\n16 2020-07-06 8\n17 2020-07-07 8\n18 2020-07-08 8\n19 2020-07-09 8\n20 2020-07-10 8\n21 2020-07-11 8\n22 2020-07-12 8\n23 2020-09-12 8\n24 2020-09-13 8\n25 2020-07-03 16\n26 2020-07-04 16\n27 2020-07-05 16\n28 2020-07-06 16\n29 2020-07-07 16\n30 2020-07-08 16\n31 2020-07-09 16\n32 2020-07-10 16\n33 2020-07-11 16\n34 2020-09-12 16\n```\n\n\n### 2. Obtención de las coordenadas \n\n\n::: {.cell}\n\n```{.r .cell-code}\nquadkeys <- unique(files$quadkey)\n\nqtll <- quadkey_to_latlong(quadkeys = quadkeys)\n\nqtll\n```\n:::\n\n\n### 3. Completo la grilla\n\n\n::: {.cell}\n\n```{.r .cell-code}\nregular_grid <- regular_qk_grid(qtll)\n\nregular_grid\n```\n:::\n\n\n### 4. Convierto a polígonos\n\n\n::: {.cell}\n\n```{.r .cell-code}\npolygrid <- grid_to_polygon(regular_grid$data)\n\npolygrid\n```\n:::\n\n\n\n### 5. Genero las variable `percent_change_7` \nEsta variable me permite obtener los valores de cambio porcentual semanal.\n\n\n::: {.cell}\n\n```{.r .cell-code}\npolyvar <- files |>\n select(day, time, quadkey, n_crisis, percent_change) |>\n inner_join(polygrid, by = 'quadkey' ) |>\n apply_weekly_lag() \n\npolyvar7 <- polyvar |>\n drop_na(percent_change_7)\n```\n:::\n\n\n\n### 6. Creación de las imagenes raster \n\n\n::: {.cell}\n\n```{.r .cell-code}\n# Cambio porcentual prepandemia\npolygon_to_raster(data = polyvar,\n nx = grid$num_cols +1 ,\n ny = grid$num_rows +1 ,\n template = polyvar,\n variable = 'percent_change',\n filename = 'Baires',\n path = \"data/\"\n)\n\n# Cambio porcentual semanal\npolygon_to_raster(data = polyvar7,\n nx = grid$num_cols +1 ,\n ny = grid$num_rows +1 ,\n template = polyvar7,\n variable = 'percent_change_7',\n filename = 'Baires',\n path = \"data/\"\n)\n```\n:::\n",
"supporting": [],
"filters": [
"rmarkdown/pagebreak.lua"
],
"includes": {},
"engineDependencies": {},
"preserve": {},
"postProcess": true
}
}
16 changes: 16 additions & 0 deletions .quarto/_freeze/creacion_mapa_bsas/execute-results/html.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"hash": "dc5cefdde1c619e748877763bfacfc06",
"result": {
"markdown": "---\ntitle: \"Creación Mapas Buenos Aires\"\nlang: es\n---\n\n\n---\n\n**Datos iniciales:**\n- Mapas vectoriales de Buenos Aires y AMBA.\n\n**Se busca obtener:**\n- Mapas vectoriales de Buenos Aires y AMBA de menor tamaño.\n- Una opción de mapa de Buenos Aires sin las comunas de CABA.\n- Centroides de los departamentos de provincia de Buenos Aires.\n\n---\n\n\n::: {.cell}\n::: {.cell-output .cell-output-stderr}\n```\n── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──\n✔ dplyr 1.1.2 ✔ readr 2.1.4\n✔ forcats 1.0.0 ✔ stringr 1.5.0\n✔ ggplot2 3.4.3 ✔ tibble 3.2.1\n✔ lubridate 1.9.2 ✔ tidyr 1.3.0\n✔ purrr 1.0.1 \n── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──\n✖ dplyr::filter() masks stats::filter()\n✖ dplyr::lag() masks stats::lag()\nℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors\nLinking to GEOS 3.11.0, GDAL 3.5.3, PROJ 9.1.0; sf_use_s2() is TRUE\n```\n:::\n:::\n\n\n\n## Area Metropolitana de Buenos Aires (AMBA) y Ciudad Autonoma de Buenos Aires (CABA)\n\nEl AMBA consta de 40 municipios mas ciudad de buenos aires. Vamos a hacer una seleccion de amba con menos partidos.\nfuente: https://www.argentina.gob.ar/dami/centro/amba\n\n\n\n::: {.cell}\n\n```{.r .cell-code}\n# Lista de los partidos que vamos a considerar AMBA incluyendo comunas CABA\namba_reducido_names <- c('Almirante Brown',\n 'Avellaneda',\n 'Berazategui',\n paste('Comuna', 1:15), # CABA\n 'Esteban Echeverría', 'Escobar', 'Ezeiza',\n 'Florencio Varela',\n 'General San Martín',\n 'Hurlingham',\n 'Ituzaingó',\n 'José C. Paz',\n 'La Matanza', 'Lanús', 'Lomas de Zamora',\n 'Malvinas Argentinas', 'Merlo', 'Moreno', 'Morón',\n 'Quilmes', 'Pilar', 'Presidente Perón',\n 'San Fernando', 'San Isidro', 'San Miguel',\n 'Tigre', 'Tres de Febrero',\n 'Vicente López')\n\n# Estos shapefiles fueron extraidos del Instituto Geografico Nacional (IGN)\n\namba <- st_read(\"data/inicial/departamentos.shp\") |>\n st_zm() |>\n filter(str_detect(NAM, paste(amba_reducido_names, collapse = \"|\")),\n SAG %in% c('ARBA - Gerencia de Servicios Catastrales',\n 'Direc. de Catastro'))\n```\n\n::: {.cell-output .cell-output-stdout}\n```\nReading layer `departamentos' from data source \n `/Users/florenciadandrea/geocovid_bsas/data/inicial/departamentos.shp' \n using driver `ESRI Shapefile'\nSimple feature collection with 529 features and 10 fields\nGeometry type: MULTIPOLYGON\nDimension: XY, XYZ\nBounding box: xmin: -74 ymin: -90 xmax: -25 ymax: -21.78113\nz_range: zmin: 0 zmax: 0\nGeodetic CRS: WGS 84\n```\n:::\n\n```{.r .cell-code}\n# Chequeo el resultado visualmente\namba_reducido <- amba |>\n dplyr::select('partido' = NAM , geometry) |>\n dplyr::filter(partido %in% amba_reducido_names)\n\nggplot() +\n geom_sf(data = amba_reducido)+\n theme_minimal()\n```\n\n::: {.cell-output-display}\n![](creacion_mapa_bsas_files/figure-html/unnamed-chunk-1-1.png){width=672}\n:::\n:::\n\n\n\n### Elimino polígono fuera del área de análisis\n\nEl partido de San Fernando esta compuesto por dos polígonos, pero solo\nusaremos el que no es parte del Delta.\n\n\n::: {.cell}\n\n```{.r .cell-code}\n# Visualizo el partido\nggplot() +\n geom_sf(data = subset(amba_reducido,\n partido == 'San Fernando'))+\n theme_minimal()\n```\n\n::: {.cell-output-display}\n![](creacion_mapa_bsas_files/figure-html/unnamed-chunk-2-1.png){width=672}\n:::\n\n```{.r .cell-code}\n# Fuerzo el pasaje a POLYGON, esto lo va a partir en dos filas\namba_reducido = st_cast(amba_reducido,\"POLYGON\")\n\n# Chequeo que se cual quiero eliminar\nggplot() +\n geom_sf(data = amba_reducido$geom[30])+\n theme_minimal()\n```\n\n::: {.cell-output-display}\n![](creacion_mapa_bsas_files/figure-html/unnamed-chunk-2-2.png){width=672}\n:::\n\n```{.r .cell-code}\n# Elimino el poligono extra\namba_reducido <- amba_reducido[-30,]\n\n# Archivo vectorial final de AMBA\nggplot() +\n geom_sf(data = amba_reducido)+\n theme_minimal()\n```\n\n::: {.cell-output-display}\n![](creacion_mapa_bsas_files/figure-html/unnamed-chunk-2-3.png){width=672}\n:::\n:::\n\n\n\nEste es el archivo con los poligonos finales seleccionados para AMBA\n\n\n::: {.cell}\n\n```{.r .cell-code}\n## guardo el archivo\n\nst_write(amba, \"data/procesada/amba_ampliado.gpkg\", append = FALSE)\n```\n\n::: {.cell-output .cell-output-stdout}\n```\nDeleting layer `amba_ampliado' using driver `GPKG'\nWriting layer `amba_ampliado' to data source \n `data/procesada/amba_ampliado.gpkg' using driver `GPKG'\nWriting 42 features with 10 fields and geometry type Multi Polygon.\n```\n:::\n:::\n\n\n## Provincia de Buenos Aires\n\n\n::: {.cell}\n\n```{.r .cell-code}\n# Obtengo los poligonos desde el IGN\nbsas <- sf::st_read('data/inicial/departamentos.shp') |>\n dplyr::filter(SAG %in% c('Direc. de Catastro', # comunas\n 'ARBA - Gerencia de Servicios Catastrales'), # partidos de baires\n GNA %in% c('Partido', 'Comuna')) |> # elimino prov de san juan\n dplyr::select('partido' = NAM, geometry) |>\n sf::st_zm()\n```\n\n::: {.cell-output .cell-output-stdout}\n```\nReading layer `departamentos' from data source \n `/Users/florenciadandrea/geocovid_bsas/data/inicial/departamentos.shp' \n using driver `ESRI Shapefile'\nSimple feature collection with 529 features and 10 fields\nGeometry type: MULTIPOLYGON\nDimension: XY, XYZ\nBounding box: xmin: -74 ymin: -90 xmax: -25 ymax: -21.78113\nz_range: zmin: 0 zmax: 0\nGeodetic CRS: WGS 84\n```\n:::\n\n```{.r .cell-code}\n# Lo paso a poligono para eliminar el extra en San Fernando\nbsas = st_cast(bsas,\"POLYGON\")\n\n# Chequeo el numero de poligono que quiero eliminar\nggplot() +\n geom_sf(data = bsas$geometry[126])+\n theme_minimal()\n```\n\n::: {.cell-output-display}\n![](creacion_mapa_bsas_files/figure-html/unnamed-chunk-4-1.png){width=672}\n:::\n\n```{.r .cell-code}\n# Elimino el poligono extra\nbsas <- bsas[-126,]\n\n# Mapa final\nggplot() +\n geom_sf(data = bsas)+\n theme_minimal()\n```\n\n::: {.cell-output-display}\n![](creacion_mapa_bsas_files/figure-html/unnamed-chunk-4-2.png){width=672}\n:::\n\n```{.r .cell-code}\nwrite_sf(bsas, 'data/procesada/bsas.gpkg')\n```\n:::\n\n\n### Unifico las comunas de Capital Federal\n\nNo en todos los casos usaremos las comunas, asique creo archivos que no las \nposean.\n\n\n::: {.cell}\n\n```{.r .cell-code}\n # uno las comunas\n caba <- bsas[grep(\"Comuna\", bsas$partido), ] |>\n st_union()\n\n # aca podria agregar algun tipo de control de calidad para asegurarme que\n # tengo la cantidad de comunas que son\n # chequear que tenga proyeccion\n\n\n # las reemplazo en el dataset por caba\n bsas_caba <- bsas |>\n slice(-grep(\"Comuna\", bsas$partido)) |>\n rbind(st_sf(\n geometry = caba,\n partido = 'Capital Federal'\n ))\n\n\n\n ggplot() +\n geom_sf(data = subset(bsas_caba,\n partido == 'Capital Federal')) + \n theme_minimal()\n```\n\n::: {.cell-output-display}\n![](creacion_mapa_bsas_files/figure-html/unnamed-chunk-5-1.png){width=672}\n:::\n\n```{.r .cell-code}\nwrite_sf(bsas_caba, 'data/procesada/bsas_caba.gpkg')\n```\n:::\n\n\n### Simplifico los poligonos para agilizar la app\n\nEs posible emplear la funcion `sf::st_simplify` con este mismo fin, \npero no conserva tan bien la topografia entre los poligonos, \nes por ello que uso este paquete donde se aplica el algoritmo de Visvalingam.\n\n\n::: {.cell}\n\n```{.r .cell-code}\nbsas_caba <- st_read('data/procesada/bsas_caba.gpkg')\n```\n\n::: {.cell-output .cell-output-stdout}\n```\nReading layer `bsas_caba' from data source \n `/Users/florenciadandrea/geocovid_bsas/data/procesada/bsas_caba.gpkg' \n using driver `GPKG'\nSimple feature collection with 136 features and 1 field\nGeometry type: POLYGON\nDimension: XY\nBounding box: xmin: -63.38597 ymin: -41.03791 xmax: -56.66499 ymax: -33.26185\nGeodetic CRS: WGS 84\n```\n:::\n\n```{.r .cell-code}\nlibrary(rmapshaper)\nbsas_caba_simple <- rmapshaper::ms_simplify(bsas_caba)\n\nst_write(bsas_caba_simple, \"data/procesada/bsas_caba_simple.gpkg\", append=FALSE)\n```\n\n::: {.cell-output .cell-output-stdout}\n```\nDeleting layer `bsas_caba_simple' using driver `GPKG'\nWriting layer `bsas_caba_simple' to data source \n `data/procesada/bsas_caba_simple.gpkg' using driver `GPKG'\nWriting 136 features with 1 fields and geometry type Polygon.\n```\n:::\n:::\n\n\n\n### Calculo de centroides\n\nUso la función `sf::st_point_on_surface()` que evita que el centroide caiga\nfuera del polígono si este tiene forma irregular.\n\n\n::: {.cell}\n\n```{.r .cell-code}\ncent <- bsas_caba_simple |> \n st_point_on_surface()\n\n# guardo el archivo con los vectores de partidos de provincia de Buenos Aires\n\nggplot() +\n geom_sf(data = bsas_caba)+\n geom_sf(data = cent) +\n theme_minimal()\n```\n\n::: {.cell-output-display}\n![](creacion_mapa_bsas_files/figure-html/unnamed-chunk-7-1.png){width=672}\n:::\n\n```{.r .cell-code}\n# guardo los centroides\nst_write(cent, \"data/procesada/centroides_mapa.gpkg\", append=FALSE)\n```\n\n::: {.cell-output .cell-output-stdout}\n```\nDeleting layer `centroides_mapa' using driver `GPKG'\nWriting layer `centroides_mapa' to data source \n `data/procesada/centroides_mapa.gpkg' using driver `GPKG'\nWriting 136 features with 1 fields and geometry type Point.\n```\n:::\n:::\n",
"supporting": [
"creacion_mapa_bsas_files"
],
"filters": [
"rmarkdown/pagebreak.lua"
],
"includes": {},
"engineDependencies": {},
"preserve": {},
"postProcess": true
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit c7cfd6b

Please sign in to comment.