From f1d3e5dd180b325b125443205a4bfaca38f32210 Mon Sep 17 00:00:00 2001 From: Elio Campitelli Date: Fri, 3 Nov 2023 18:05:23 -0300 Subject: [PATCH] Kriging --- .../post/2023-11-03-metR-new-features.en.Rmd | 115 +++ .../post/2023-11-03-metR-new-features.en.html | 59 ++ .../how-to-make-shaded-relief-in-r/index.html | 37 +- .../index.html | 37 +- .../index.html | 37 +- .../index.html | 37 +- .../2019/01/statistical-metamerism/index.html | 37 +- .../2019/04/ecmwfr-global-warming/index.html | 37 +- .../2019/07/why-i-love-data-table/index.html | 37 +- .../2019/11/rammstein-vs-lacrimosa/index.html | 37 +- docs/en/2021/03/star-trek-rakings/index.html | 37 +- docs/en/2021/05/r-pipa-nativa/index.html | 37 +- docs/en/2021/07/wrapper-stop/index.html | 37 +- docs/en/2021/08/docker-renv/index.html | 37 +- docs/en/2021/09/contour-labels/index.html | 37 +- docs/en/2022/12/chatpgt-midi-music/index.html | 37 +- docs/en/2023/02/dataset-functions/index.html | 37 +- .../2023/04/knitr-rmarkdown-tricks/index.html | 37 +- docs/en/2023/10/dependencies-in-r/index.html | 41 +- docs/en/2023/11/kriging-metr-r/index.html | 816 +++++++++++++++++ docs/en/2023/11/metr-new-features/index.html | 817 ++++++++++++++++++ docs/en/404.html | 37 +- docs/en/archives/index.html | 46 +- docs/en/categories/gpt/index.html | 37 +- docs/en/categories/index.html | 31 +- docs/en/categories/index.xml | 4 +- docs/en/categories/r/index.html | 138 +-- docs/en/categories/r/index.xml | 60 +- docs/en/categories/r/page/2/index.html | 139 +-- docs/en/categories/r/page/3/index.html | 97 ++- docs/en/categories/statistics/index.html | 37 +- docs/en/index.html | 140 +-- docs/en/index.xml | 60 +- docs/en/page/2/index.html | 140 +-- docs/en/page/3/index.html | 100 ++- docs/en/post/index.html | 140 +-- docs/en/post/index.xml | 60 +- docs/en/post/page/2/index.html | 140 +-- docs/en/post/page/3/index.html | 100 ++- docs/en/sitemap.xml | 13 +- docs/en/tags/data.table/index.html | 37 +- docs/en/tags/ejemplos/index.html | 37 +- docs/en/tags/ggplot2/index.html | 37 +- docs/en/tags/packages/index.html | 37 +- docs/en/tags/paquetes/index.html | 37 +- docs/en/tags/text/index.html | 37 +- docs/en/tags/webscraping/index.html | 37 +- .../figure-html/unnamed-chunk-1-1.png | Bin 0 -> 105922 bytes .../figure-html/unnamed-chunk-2-1.png | Bin 0 -> 116120 bytes .../figure-html/unnamed-chunk-3-1.png | Bin 0 -> 116922 bytes .../figure-html/unnamed-chunk-4-1.png | Bin 0 -> 116842 bytes docs/sitemap.xml | 2 +- .../figure-html/unnamed-chunk-1-1.png | Bin 0 -> 105922 bytes .../figure-html/unnamed-chunk-2-1.png | Bin 0 -> 116120 bytes .../figure-html/unnamed-chunk-3-1.png | Bin 0 -> 116922 bytes .../figure-html/unnamed-chunk-4-1.png | Bin 0 -> 116842 bytes 56 files changed, 3232 insertions(+), 988 deletions(-) create mode 100644 content/post/2023-11-03-metR-new-features.en.Rmd create mode 100644 content/post/2023-11-03-metR-new-features.en.html create mode 100644 docs/en/2023/11/kriging-metr-r/index.html create mode 100644 docs/en/2023/11/metr-new-features/index.html create mode 100644 docs/post/2023-11-03-metR-new-features.en_files/figure-html/unnamed-chunk-1-1.png create mode 100644 docs/post/2023-11-03-metR-new-features.en_files/figure-html/unnamed-chunk-2-1.png create mode 100644 docs/post/2023-11-03-metR-new-features.en_files/figure-html/unnamed-chunk-3-1.png create mode 100644 docs/post/2023-11-03-metR-new-features.en_files/figure-html/unnamed-chunk-4-1.png create mode 100644 static/post/2023-11-03-metR-new-features.en_files/figure-html/unnamed-chunk-1-1.png create mode 100644 static/post/2023-11-03-metR-new-features.en_files/figure-html/unnamed-chunk-2-1.png create mode 100644 static/post/2023-11-03-metR-new-features.en_files/figure-html/unnamed-chunk-3-1.png create mode 100644 static/post/2023-11-03-metR-new-features.en_files/figure-html/unnamed-chunk-4-1.png diff --git a/content/post/2023-11-03-metR-new-features.en.Rmd b/content/post/2023-11-03-metR-new-features.en.Rmd new file mode 100644 index 0000000..fa5b8ec --- /dev/null +++ b/content/post/2023-11-03-metR-new-features.en.Rmd @@ -0,0 +1,115 @@ +--- +title: "Kriging with metR" +author: Elio Campitelli +date: '2023-11-02' +slug: kriging-metR-R +categories: + - R +keywords: + - package development +--- + +```{r setup, include = FALSE} +knitr::opts_chunk$set(warning = FALSE, message = FALSE) +library(data.table) +library(ggplot2) +library(metR) +``` + +```{r data, include = FALSE} +data <- metR::GetSMNData("2023-01-01", "hourly") |> + _[, .(t = mean(t, na.rm = TRUE)), by = station] + +estaciones_url <- "https://ssl.smn.gob.ar/dpd/zipopendata.php?dato=estaciones" +estaciones_zip <- tempfile() +estaciones_dir <- file.path(tempdir(), "estaciones") +download.file(estaciones_url, estaciones_zip) +unzip(estaciones_zip, exdir = estaciones_dir) +estaciones_file <- list.files(estaciones_dir, full.names = TRUE) + +gm2dd <- function(grados, minutos) { + grados <- as.numeric(grados) + minutos <- as.numeric(minutos) + + (abs(grados) + minutos/60)*sign(grados) +} + +estaciones <- read.fwf(estaciones_file, skip = 2, fileEncoding = "ISO-8859-1", + widths = c(31, 37, 9, 9, 9, 9, 6, 6, 4), + col.names = c("nombre", "provincia", "lat_grad", "lat_min", "lon_grad", "lon_min", "altura", "nro", "oaci")) |> + + lapply(trimws) |> + as.data.table() |> + _[, `:=`(lat = gm2dd(lat_grad, lat_min), + lon = gm2dd(lon_grad, lon_min))] |> + _[lat > -60] + +argentina_provincias <- rnaturalearth::ne_states(country = c("argentina", "falkland islands"), returnclass = "sf") +argentina_provincias_sin_malvinas <- rnaturalearth::ne_states(country = c("argentina"), returnclass = "sf") +``` + +Say yo have data measured at different weather stations, which in Argentina might look something like this + +```{r} +estaciones[data, on = c("nombre" = "station")] |> + ggplot(aes(lon, lat)) + + geom_point(aes(color = t)) + + geom_sf(data = argentina_provincias, inherit.aes = FALSE, fill = NA) + + scale_color_viridis_c() +``` + +Because this is not a regular grid, it's not possible to visualise this data with contours as is. +Instead, it's necessary to interpolate it into a regular grid. + +There are many ways to go from irregular measurement locations to a regular grid and it comes with a bunch of assumptions. +But for quick an dirty visualisations, `metR::geom_contour_fill()` can use kriging by setting `kriging = TRUE` + +```{r} +estaciones[data, on = c("nombre" = "station")] |> + ggplot(aes(lon, lat)) + + metR::geom_contour_fill(aes(z = t), + kriging = TRUE) + + geom_point(aes(fill = t), shape = 21) + + geom_sf(data = argentina_provincias, inherit.aes = FALSE, fill = NA) + + scale_color_viridis_c(aesthetics = c("fill", "colour")) +``` + +One big problem with this is that by default it estimates values in the bounding box of the data, which in this case includes a bunch of the Atlantic Ocean. +So it would be nice to be able to only show the contours over land. + +In a desperate attempt to procrastinate from writing my thesis I implemented this functionality. +Now, the `clip` argument takes a polygon which clips the contours. + +```{r} +estaciones[data, on = c("nombre" = "station")] |> + ggplot(aes(lon, lat)) + + metR::geom_contour_fill(aes(z = t), + kriging = TRUE, + clip = argentina_provincias_sin_malvinas) + + geom_point(aes(fill = t), shape = 21) + + geom_sf(data = argentina_provincias, inherit.aes = FALSE, fill = NA) + + scale_color_viridis_c(aesthetics = c("fill", "colour")) + +``` + +Another small issue is that the default interpolates to a 40-pixel wide grid, which is a bit too coarse and doesn't reach the top corners of the map. +The `kriging` argument now can take a numeric, which defines number of gridpoints each direction. + +```{r} +estaciones[data, on = c("nombre" = "station")] |> + ggplot(aes(lon, lat)) + + metR::geom_contour_fill(aes(z = t), + kriging = 100, + clip = argentina_provincias_sin_malvinas) + + geom_point(aes(fill = t), shape = 21) + + geom_sf(data = argentina_provincias, inherit.aes = FALSE, fill = NA) + + scale_color_viridis_c(aesthetics = c("fill", "colour")) +``` + +Much better! + +You can install the development version of [metR](https://eliocamp.github.io/metR/) with + +```{r, eval = FALSE} +install.packages("metR", repos = c("https://eliocamp.github.io/metR", getOption("repos"))) +``` diff --git a/content/post/2023-11-03-metR-new-features.en.html b/content/post/2023-11-03-metR-new-features.en.html new file mode 100644 index 0000000..2f4b8d0 --- /dev/null +++ b/content/post/2023-11-03-metR-new-features.en.html @@ -0,0 +1,59 @@ +--- +title: "Kriging with metR" +author: Elio Campitelli +date: '2023-11-02' +slug: kriging-metR-R +categories: + - R +keywords: + - package development +--- + + + +

Say yo have data measured at different weather stations, which in Argentina might look something like this

+
estaciones[data, on = c("nombre" = "station")] |> 
+   ggplot(aes(lon, lat)) +
+   geom_point(aes(color = t)) +
+   geom_sf(data = argentina_provincias, inherit.aes = FALSE, fill = NA) + 
+   scale_color_viridis_c()
+

+

Because this is not a regular grid, it’s not possible to visualise this data with contours as is. +Instead, it’s necessary to interpolate it into a regular grid.

+

There are many ways to go from irregular measurement locations to a regular grid and it comes with a bunch of assumptions. +But for quick an dirty visualisations, metR::geom_contour_fill() can use kriging by setting kriging = TRUE

+
estaciones[data, on = c("nombre" = "station")] |> 
+   ggplot(aes(lon, lat)) +
+   metR::geom_contour_fill(aes(z = t), 
+                           kriging = TRUE) +
+   geom_point(aes(fill = t), shape = 21) +
+   geom_sf(data = argentina_provincias, inherit.aes = FALSE, fill = NA) + 
+   scale_color_viridis_c(aesthetics = c("fill", "colour")) 
+

+

One big problem with this is that by default it estimates values in the bounding box of the data, which in this case includes a bunch of the Atlantic Ocean. +So it would be nice to be able to only show the contours over land.

+

In a desperate attempt to procrastinate from writing my thesis I implemented this functionality. +Now, the clip argument takes a polygon which clips the contours.

+
estaciones[data, on = c("nombre" = "station")] |> 
+   ggplot(aes(lon, lat)) +
+   metR::geom_contour_fill(aes(z = t), 
+                           kriging = TRUE, 
+                           clip = argentina_provincias_sin_malvinas) +
+   geom_point(aes(fill = t), shape = 21) +
+   geom_sf(data = argentina_provincias, inherit.aes = FALSE, fill = NA) + 
+   scale_color_viridis_c(aesthetics = c("fill", "colour")) 
+

+

Another small issue is that the default interpolates to a 40-pixel wide grid, which is a bit too coarse and doesn’t reach the top corners of the map. +The kriging argument now can take a numeric, which defines number of gridpoints each direction.

+
estaciones[data, on = c("nombre" = "station")] |> 
+   ggplot(aes(lon, lat)) +
+   metR::geom_contour_fill(aes(z = t), 
+                           kriging = 100, 
+                           clip = argentina_provincias_sin_malvinas) +
+   geom_point(aes(fill = t), shape = 21) +
+   geom_sf(data = argentina_provincias, inherit.aes = FALSE, fill = NA) + 
+   scale_color_viridis_c(aesthetics = c("fill", "colour")) 
+

+

Much better!

+

You can install the development version of metR with

+
install.packages("metR", repos = c("https://eliocamp.github.io/metR", getOption("repos")))
diff --git a/docs/en/2018/02/how-to-make-shaded-relief-in-r/index.html b/docs/en/2018/02/how-to-make-shaded-relief-in-r/index.html index 50a7ced..012157b 100644 --- a/docs/en/2018/02/how-to-make-shaded-relief-in-r/index.html +++ b/docs/en/2018/02/how-to-make-shaded-relief-in-r/index.html @@ -716,6 +716,24 @@

Elio Campitelli

+
+ +
+ +

Kriging with metR

+
+ + + Nov 11, 2023 + + +
Say yo have data measured at different weather stations, which in Argentina might look something like this +estaciones[data, on = c("nombre" = "station")] |> ggplot(aes(lon, lat)) + geom_point(aes(color = t)) + geom_sf(data = argentina_provincias, inherit.aes = FALSE, fill = NA) + scale_color_viridis_c() Because this is not a regular grid, it’s not possible to visualise this data with contours as is. Instead, it’s necessary to interpolate it into a regular grid.
+
+
+
+
+
@@ -879,23 +897,6 @@

Star Trek ratings on IMDB


-
- -
- -

Rammstein vs. Lacrimosa

-
- - - Nov 11, 2019 - - -
Some time ago, someone I follow on twitter posted about having to buy a whole book with rules to tease out grammatical gender in German. Further down the replies, someone reminisced about trying (and failing) to learn German just by listening to Rammstein’s lyrics. I studied about drei Jahre of German at the same time I started listening to Rammstein and other German-speaking bands and I’ve always found Rammstein’s lyrics to be surprisingly simple.
-
-
-
-
-
diff --git a/docs/en/2018/05/how-to-make-a-generic-stat-in-ggplot2/index.html b/docs/en/2018/05/how-to-make-a-generic-stat-in-ggplot2/index.html index 81bb035..5454d8a 100644 --- a/docs/en/2018/05/how-to-make-a-generic-stat-in-ggplot2/index.html +++ b/docs/en/2018/05/how-to-make-a-generic-stat-in-ggplot2/index.html @@ -660,6 +660,24 @@

Elio Campitelli

+
+ +
+ +

Kriging with metR

+
+ + + Nov 11, 2023 + + +
Say yo have data measured at different weather stations, which in Argentina might look something like this +estaciones[data, on = c("nombre" = "station")] |> ggplot(aes(lon, lat)) + geom_point(aes(color = t)) + geom_sf(data = argentina_provincias, inherit.aes = FALSE, fill = NA) + scale_color_viridis_c() Because this is not a regular grid, it’s not possible to visualise this data with contours as is. Instead, it’s necessary to interpolate it into a regular grid.
+
+
+
+
+
@@ -823,23 +841,6 @@

Star Trek ratings on IMDB


-
- -
- -

Rammstein vs. Lacrimosa

-
- - - Nov 11, 2019 - - -
Some time ago, someone I follow on twitter posted about having to buy a whole book with rules to tease out grammatical gender in German. Further down the replies, someone reminisced about trying (and failing) to learn German just by listening to Rammstein’s lyrics. I studied about drei Jahre of German at the same time I started listening to Rammstein and other German-speaking bands and I’ve always found Rammstein’s lyrics to be surprisingly simple.
-
-
-
-
-
diff --git a/docs/en/2018/08/periodic-data-ggplot2-ggperiodic/index.html b/docs/en/2018/08/periodic-data-ggplot2-ggperiodic/index.html index c5eeb56..d971d64 100644 --- a/docs/en/2018/08/periodic-data-ggplot2-ggperiodic/index.html +++ b/docs/en/2018/08/periodic-data-ggplot2-ggperiodic/index.html @@ -629,6 +629,24 @@

Elio Campitelli

+
+ +
+ +

Kriging with metR

+
+ + + Nov 11, 2023 + + +
Say yo have data measured at different weather stations, which in Argentina might look something like this +estaciones[data, on = c("nombre" = "station")] |> ggplot(aes(lon, lat)) + geom_point(aes(color = t)) + geom_sf(data = argentina_provincias, inherit.aes = FALSE, fill = NA) + scale_color_viridis_c() Because this is not a regular grid, it’s not possible to visualise this data with contours as is. Instead, it’s necessary to interpolate it into a regular grid.
+
+
+
+
+
@@ -792,23 +810,6 @@

Star Trek ratings on IMDB


-
- -
- -

Rammstein vs. Lacrimosa

-
- - - Nov 11, 2019 - - -
Some time ago, someone I follow on twitter posted about having to buy a whole book with rules to tease out grammatical gender in German. Further down the replies, someone reminisced about trying (and failing) to learn German just by listening to Rammstein’s lyrics. I studied about drei Jahre of German at the same time I started listening to Rammstein and other German-speaking bands and I’ve always found Rammstein’s lyrics to be surprisingly simple.
-
-
-
-
-
diff --git a/docs/en/2018/09/multiple-color-fill-scales-ggplot2/index.html b/docs/en/2018/09/multiple-color-fill-scales-ggplot2/index.html index 8aaa561..ef2c116 100644 --- a/docs/en/2018/09/multiple-color-fill-scales-ggplot2/index.html +++ b/docs/en/2018/09/multiple-color-fill-scales-ggplot2/index.html @@ -623,6 +623,24 @@

Elio Campitelli

+
+ +
+ +

Kriging with metR

+
+ + + Nov 11, 2023 + + +
Say yo have data measured at different weather stations, which in Argentina might look something like this +estaciones[data, on = c("nombre" = "station")] |> ggplot(aes(lon, lat)) + geom_point(aes(color = t)) + geom_sf(data = argentina_provincias, inherit.aes = FALSE, fill = NA) + scale_color_viridis_c() Because this is not a regular grid, it’s not possible to visualise this data with contours as is. Instead, it’s necessary to interpolate it into a regular grid.
+
+
+
+
+
@@ -786,23 +804,6 @@

Star Trek ratings on IMDB


-
- -
- -

Rammstein vs. Lacrimosa

-
- - - Nov 11, 2019 - - -
Some time ago, someone I follow on twitter posted about having to buy a whole book with rules to tease out grammatical gender in German. Further down the replies, someone reminisced about trying (and failing) to learn German just by listening to Rammstein’s lyrics. I studied about drei Jahre of German at the same time I started listening to Rammstein and other German-speaking bands and I’ve always found Rammstein’s lyrics to be surprisingly simple.
-
-
-
-
-
diff --git a/docs/en/2019/01/statistical-metamerism/index.html b/docs/en/2019/01/statistical-metamerism/index.html index 3dd6bf0..60c1f8f 100644 --- a/docs/en/2019/01/statistical-metamerism/index.html +++ b/docs/en/2019/01/statistical-metamerism/index.html @@ -892,6 +892,24 @@

Elio Campitelli

+
+ +
+ +

Kriging with metR

+
+ + + Nov 11, 2023 + + +
Say yo have data measured at different weather stations, which in Argentina might look something like this +estaciones[data, on = c("nombre" = "station")] |> ggplot(aes(lon, lat)) + geom_point(aes(color = t)) + geom_sf(data = argentina_provincias, inherit.aes = FALSE, fill = NA) + scale_color_viridis_c() Because this is not a regular grid, it’s not possible to visualise this data with contours as is. Instead, it’s necessary to interpolate it into a regular grid.
+
+
+
+
+
@@ -1055,23 +1073,6 @@

Star Trek ratings on IMDB


-
- -
- -

Rammstein vs. Lacrimosa

-
- - - Nov 11, 2019 - - -
Some time ago, someone I follow on twitter posted about having to buy a whole book with rules to tease out grammatical gender in German. Further down the replies, someone reminisced about trying (and failing) to learn German just by listening to Rammstein’s lyrics. I studied about drei Jahre of German at the same time I started listening to Rammstein and other German-speaking bands and I’ve always found Rammstein’s lyrics to be surprisingly simple.
-
-
-
-
-
diff --git a/docs/en/2019/04/ecmwfr-global-warming/index.html b/docs/en/2019/04/ecmwfr-global-warming/index.html index 3c178ef..a978a44 100644 --- a/docs/en/2019/04/ecmwfr-global-warming/index.html +++ b/docs/en/2019/04/ecmwfr-global-warming/index.html @@ -669,6 +669,24 @@

Elio Campitelli

+
+ +
+ +

Kriging with metR

+
+ + + Nov 11, 2023 + + +
Say yo have data measured at different weather stations, which in Argentina might look something like this +estaciones[data, on = c("nombre" = "station")] |> ggplot(aes(lon, lat)) + geom_point(aes(color = t)) + geom_sf(data = argentina_provincias, inherit.aes = FALSE, fill = NA) + scale_color_viridis_c() Because this is not a regular grid, it’s not possible to visualise this data with contours as is. Instead, it’s necessary to interpolate it into a regular grid.
+
+
+
+
+
@@ -832,23 +850,6 @@

Star Trek ratings on IMDB


-
- -
- -

Rammstein vs. Lacrimosa

-
- - - Nov 11, 2019 - - -
Some time ago, someone I follow on twitter posted about having to buy a whole book with rules to tease out grammatical gender in German. Further down the replies, someone reminisced about trying (and failing) to learn German just by listening to Rammstein’s lyrics. I studied about drei Jahre of German at the same time I started listening to Rammstein and other German-speaking bands and I’ve always found Rammstein’s lyrics to be surprisingly simple.
-
-
-
-
-
diff --git a/docs/en/2019/07/why-i-love-data-table/index.html b/docs/en/2019/07/why-i-love-data-table/index.html index 88b9b0f..9d3284f 100644 --- a/docs/en/2019/07/why-i-love-data-table/index.html +++ b/docs/en/2019/07/why-i-love-data-table/index.html @@ -625,6 +625,24 @@

Elio Campitelli

+
+ +
+ +

Kriging with metR

+
+ + + Nov 11, 2023 + + +
Say yo have data measured at different weather stations, which in Argentina might look something like this +estaciones[data, on = c("nombre" = "station")] |> ggplot(aes(lon, lat)) + geom_point(aes(color = t)) + geom_sf(data = argentina_provincias, inherit.aes = FALSE, fill = NA) + scale_color_viridis_c() Because this is not a regular grid, it’s not possible to visualise this data with contours as is. Instead, it’s necessary to interpolate it into a regular grid.
+
+
+
+
+
@@ -788,23 +806,6 @@

Star Trek ratings on IMDB


-
- -
- -

Rammstein vs. Lacrimosa

-
- - - Nov 11, 2019 - - -
Some time ago, someone I follow on twitter posted about having to buy a whole book with rules to tease out grammatical gender in German. Further down the replies, someone reminisced about trying (and failing) to learn German just by listening to Rammstein’s lyrics. I studied about drei Jahre of German at the same time I started listening to Rammstein and other German-speaking bands and I’ve always found Rammstein’s lyrics to be surprisingly simple.
-
-
-
-
-
diff --git a/docs/en/2019/11/rammstein-vs-lacrimosa/index.html b/docs/en/2019/11/rammstein-vs-lacrimosa/index.html index e24893c..ff2b234 100644 --- a/docs/en/2019/11/rammstein-vs-lacrimosa/index.html +++ b/docs/en/2019/11/rammstein-vs-lacrimosa/index.html @@ -780,6 +780,24 @@

Elio Campitelli

+
+ +
+ +

Kriging with metR

+
+ + + Nov 11, 2023 + + +
Say yo have data measured at different weather stations, which in Argentina might look something like this +estaciones[data, on = c("nombre" = "station")] |> ggplot(aes(lon, lat)) + geom_point(aes(color = t)) + geom_sf(data = argentina_provincias, inherit.aes = FALSE, fill = NA) + scale_color_viridis_c() Because this is not a regular grid, it’s not possible to visualise this data with contours as is. Instead, it’s necessary to interpolate it into a regular grid.
+
+
+
+
+
@@ -943,23 +961,6 @@

Star Trek ratings on IMDB


-
- -
- -

Rammstein vs. Lacrimosa

-
- - - Nov 11, 2019 - - -
Some time ago, someone I follow on twitter posted about having to buy a whole book with rules to tease out grammatical gender in German. Further down the replies, someone reminisced about trying (and failing) to learn German just by listening to Rammstein’s lyrics. I studied about drei Jahre of German at the same time I started listening to Rammstein and other German-speaking bands and I’ve always found Rammstein’s lyrics to be surprisingly simple.
-
-
-
-
-
diff --git a/docs/en/2021/03/star-trek-rakings/index.html b/docs/en/2021/03/star-trek-rakings/index.html index 795d966..13a3113 100644 --- a/docs/en/2021/03/star-trek-rakings/index.html +++ b/docs/en/2021/03/star-trek-rakings/index.html @@ -908,6 +908,24 @@

Elio Campitelli

+
+ +
+ +

Kriging with metR

+
+ + + Nov 11, 2023 + + +
Say yo have data measured at different weather stations, which in Argentina might look something like this +estaciones[data, on = c("nombre" = "station")] |> ggplot(aes(lon, lat)) + geom_point(aes(color = t)) + geom_sf(data = argentina_provincias, inherit.aes = FALSE, fill = NA) + scale_color_viridis_c() Because this is not a regular grid, it’s not possible to visualise this data with contours as is. Instead, it’s necessary to interpolate it into a regular grid.
+
+
+
+
+
@@ -1071,23 +1089,6 @@

Star Trek ratings on IMDB


-
- -
- -

Rammstein vs. Lacrimosa

-
- - - Nov 11, 2019 - - -
Some time ago, someone I follow on twitter posted about having to buy a whole book with rules to tease out grammatical gender in German. Further down the replies, someone reminisced about trying (and failing) to learn German just by listening to Rammstein’s lyrics. I studied about drei Jahre of German at the same time I started listening to Rammstein and other German-speaking bands and I’ve always found Rammstein’s lyrics to be surprisingly simple.
-
-
-
-
-
diff --git a/docs/en/2021/05/r-pipa-nativa/index.html b/docs/en/2021/05/r-pipa-nativa/index.html index b06d9c3..bb35fed 100644 --- a/docs/en/2021/05/r-pipa-nativa/index.html +++ b/docs/en/2021/05/r-pipa-nativa/index.html @@ -665,6 +665,24 @@

Elio Campitelli

+
+ +
+ +

Kriging with metR

+
+ + + Nov 11, 2023 + + +
Say yo have data measured at different weather stations, which in Argentina might look something like this +estaciones[data, on = c("nombre" = "station")] |> ggplot(aes(lon, lat)) + geom_point(aes(color = t)) + geom_sf(data = argentina_provincias, inherit.aes = FALSE, fill = NA) + scale_color_viridis_c() Because this is not a regular grid, it’s not possible to visualise this data with contours as is. Instead, it’s necessary to interpolate it into a regular grid.
+
+
+
+
+
@@ -828,23 +846,6 @@

Star Trek ratings on IMDB


-
- -
- -

Rammstein vs. Lacrimosa

-
- - - Nov 11, 2019 - - -
Some time ago, someone I follow on twitter posted about having to buy a whole book with rules to tease out grammatical gender in German. Further down the replies, someone reminisced about trying (and failing) to learn German just by listening to Rammstein’s lyrics. I studied about drei Jahre of German at the same time I started listening to Rammstein and other German-speaking bands and I’ve always found Rammstein’s lyrics to be surprisingly simple.
-
-
-
-
-
diff --git a/docs/en/2021/07/wrapper-stop/index.html b/docs/en/2021/07/wrapper-stop/index.html index dc13717..0903855 100644 --- a/docs/en/2021/07/wrapper-stop/index.html +++ b/docs/en/2021/07/wrapper-stop/index.html @@ -590,6 +590,24 @@

Elio Campitelli

+
+ +
+ +

Kriging with metR

+
+ + + Nov 11, 2023 + + +
Say yo have data measured at different weather stations, which in Argentina might look something like this +estaciones[data, on = c("nombre" = "station")] |> ggplot(aes(lon, lat)) + geom_point(aes(color = t)) + geom_sf(data = argentina_provincias, inherit.aes = FALSE, fill = NA) + scale_color_viridis_c() Because this is not a regular grid, it’s not possible to visualise this data with contours as is. Instead, it’s necessary to interpolate it into a regular grid.
+
+
+
+
+
@@ -753,23 +771,6 @@

Star Trek ratings on IMDB


-
- -
- -

Rammstein vs. Lacrimosa

-
- - - Nov 11, 2019 - - -
Some time ago, someone I follow on twitter posted about having to buy a whole book with rules to tease out grammatical gender in German. Further down the replies, someone reminisced about trying (and failing) to learn German just by listening to Rammstein’s lyrics. I studied about drei Jahre of German at the same time I started listening to Rammstein and other German-speaking bands and I’ve always found Rammstein’s lyrics to be surprisingly simple.
-
-
-
-
-
diff --git a/docs/en/2021/08/docker-renv/index.html b/docs/en/2021/08/docker-renv/index.html index 8192f42..e65e744 100644 --- a/docs/en/2021/08/docker-renv/index.html +++ b/docs/en/2021/08/docker-renv/index.html @@ -614,6 +614,24 @@

Elio Campitelli

+
+ +
+ +

Kriging with metR

+
+ + + Nov 11, 2023 + + +
Say yo have data measured at different weather stations, which in Argentina might look something like this +estaciones[data, on = c("nombre" = "station")] |> ggplot(aes(lon, lat)) + geom_point(aes(color = t)) + geom_sf(data = argentina_provincias, inherit.aes = FALSE, fill = NA) + scale_color_viridis_c() Because this is not a regular grid, it’s not possible to visualise this data with contours as is. Instead, it’s necessary to interpolate it into a regular grid.
+
+
+
+
+
@@ -777,23 +795,6 @@

Star Trek ratings on IMDB


-
- -
- -

Rammstein vs. Lacrimosa

-
- - - Nov 11, 2019 - - -
Some time ago, someone I follow on twitter posted about having to buy a whole book with rules to tease out grammatical gender in German. Further down the replies, someone reminisced about trying (and failing) to learn German just by listening to Rammstein’s lyrics. I studied about drei Jahre of German at the same time I started listening to Rammstein and other German-speaking bands and I’ve always found Rammstein’s lyrics to be surprisingly simple.
-
-
-
-
-
diff --git a/docs/en/2021/09/contour-labels/index.html b/docs/en/2021/09/contour-labels/index.html index 0fd62e3..dcb71a2 100644 --- a/docs/en/2021/09/contour-labels/index.html +++ b/docs/en/2021/09/contour-labels/index.html @@ -570,6 +570,24 @@

Elio Campitelli

+
+ +
+ +

Kriging with metR

+
+ + + Nov 11, 2023 + + +
Say yo have data measured at different weather stations, which in Argentina might look something like this +estaciones[data, on = c("nombre" = "station")] |> ggplot(aes(lon, lat)) + geom_point(aes(color = t)) + geom_sf(data = argentina_provincias, inherit.aes = FALSE, fill = NA) + scale_color_viridis_c() Because this is not a regular grid, it’s not possible to visualise this data with contours as is. Instead, it’s necessary to interpolate it into a regular grid.
+
+
+
+
+
@@ -733,23 +751,6 @@

Star Trek ratings on IMDB


-
- -
- -

Rammstein vs. Lacrimosa

-
- - - Nov 11, 2019 - - -
Some time ago, someone I follow on twitter posted about having to buy a whole book with rules to tease out grammatical gender in German. Further down the replies, someone reminisced about trying (and failing) to learn German just by listening to Rammstein’s lyrics. I studied about drei Jahre of German at the same time I started listening to Rammstein and other German-speaking bands and I’ve always found Rammstein’s lyrics to be surprisingly simple.
-
-
-
-
-
diff --git a/docs/en/2022/12/chatpgt-midi-music/index.html b/docs/en/2022/12/chatpgt-midi-music/index.html index a9a8e02..b96ef91 100644 --- a/docs/en/2022/12/chatpgt-midi-music/index.html +++ b/docs/en/2022/12/chatpgt-midi-music/index.html @@ -1350,6 +1350,24 @@

Elio Campitelli

+
+ +
+ +

Kriging with metR

+
+ + + Nov 11, 2023 + + +
Say yo have data measured at different weather stations, which in Argentina might look something like this +estaciones[data, on = c("nombre" = "station")] |> ggplot(aes(lon, lat)) + geom_point(aes(color = t)) + geom_sf(data = argentina_provincias, inherit.aes = FALSE, fill = NA) + scale_color_viridis_c() Because this is not a regular grid, it’s not possible to visualise this data with contours as is. Instead, it’s necessary to interpolate it into a regular grid.
+
+
+
+
+
@@ -1513,23 +1531,6 @@

Star Trek ratings on IMDB


-
- -
- -

Rammstein vs. Lacrimosa

-
- - - Nov 11, 2019 - - -
Some time ago, someone I follow on twitter posted about having to buy a whole book with rules to tease out grammatical gender in German. Further down the replies, someone reminisced about trying (and failing) to learn German just by listening to Rammstein’s lyrics. I studied about drei Jahre of German at the same time I started listening to Rammstein and other German-speaking bands and I’ve always found Rammstein’s lyrics to be surprisingly simple.
-
-
-
-
-
diff --git a/docs/en/2023/02/dataset-functions/index.html b/docs/en/2023/02/dataset-functions/index.html index 44cbb01..6d95328 100644 --- a/docs/en/2023/02/dataset-functions/index.html +++ b/docs/en/2023/02/dataset-functions/index.html @@ -601,6 +601,24 @@

Elio Campitelli

+
+ +
+ +

Kriging with metR

+
+ + + Nov 11, 2023 + + +
Say yo have data measured at different weather stations, which in Argentina might look something like this +estaciones[data, on = c("nombre" = "station")] |> ggplot(aes(lon, lat)) + geom_point(aes(color = t)) + geom_sf(data = argentina_provincias, inherit.aes = FALSE, fill = NA) + scale_color_viridis_c() Because this is not a regular grid, it’s not possible to visualise this data with contours as is. Instead, it’s necessary to interpolate it into a regular grid.
+
+
+
+
+
@@ -764,23 +782,6 @@

Star Trek ratings on IMDB


-
- -
- -

Rammstein vs. Lacrimosa

-
- - - Nov 11, 2019 - - -
Some time ago, someone I follow on twitter posted about having to buy a whole book with rules to tease out grammatical gender in German. Further down the replies, someone reminisced about trying (and failing) to learn German just by listening to Rammstein’s lyrics. I studied about drei Jahre of German at the same time I started listening to Rammstein and other German-speaking bands and I’ve always found Rammstein’s lyrics to be surprisingly simple.
-
-
-
-
-
diff --git a/docs/en/2023/04/knitr-rmarkdown-tricks/index.html b/docs/en/2023/04/knitr-rmarkdown-tricks/index.html index 3b2cc65..51daed4 100644 --- a/docs/en/2023/04/knitr-rmarkdown-tricks/index.html +++ b/docs/en/2023/04/knitr-rmarkdown-tricks/index.html @@ -679,6 +679,24 @@

Elio Campitelli

+
+ +
+ +

Kriging with metR

+
+ + + Nov 11, 2023 + + +
Say yo have data measured at different weather stations, which in Argentina might look something like this +estaciones[data, on = c("nombre" = "station")] |> ggplot(aes(lon, lat)) + geom_point(aes(color = t)) + geom_sf(data = argentina_provincias, inherit.aes = FALSE, fill = NA) + scale_color_viridis_c() Because this is not a regular grid, it’s not possible to visualise this data with contours as is. Instead, it’s necessary to interpolate it into a regular grid.
+
+
+
+
+
@@ -842,23 +860,6 @@

Star Trek ratings on IMDB


-
- -
- -

Rammstein vs. Lacrimosa

-
- - - Nov 11, 2019 - - -
Some time ago, someone I follow on twitter posted about having to buy a whole book with rules to tease out grammatical gender in German. Further down the replies, someone reminisced about trying (and failing) to learn German just by listening to Rammstein’s lyrics. I studied about drei Jahre of German at the same time I started listening to Rammstein and other German-speaking bands and I’ve always found Rammstein’s lyrics to be surprisingly simple.
-
-
-
-
-
diff --git a/docs/en/2023/10/dependencies-in-r/index.html b/docs/en/2023/10/dependencies-in-r/index.html index 681e9f4..a388f86 100644 --- a/docs/en/2023/10/dependencies-in-r/index.html +++ b/docs/en/2023/10/dependencies-in-r/index.html @@ -380,7 +380,7 @@

Conclusions

  • - + NEXT @@ -466,7 +466,7 @@

    Conclusions

  • - + NEXT @@ -602,6 +602,24 @@

    Elio Campitelli

    +
    + +
    + +

    Kriging with metR

    +
    + + + Nov 11, 2023 + + +
    Say yo have data measured at different weather stations, which in Argentina might look something like this +estaciones[data, on = c("nombre" = "station")] |> ggplot(aes(lon, lat)) + geom_point(aes(color = t)) + geom_sf(data = argentina_provincias, inherit.aes = FALSE, fill = NA) + scale_color_viridis_c() Because this is not a regular grid, it’s not possible to visualise this data with contours as is. Instead, it’s necessary to interpolate it into a regular grid.
    +
    +
    +
    +
    +
    @@ -765,23 +783,6 @@

    Star Trek ratings on IMDB


    -
    - -
    - -

    Rammstein vs. Lacrimosa

    -
    - - - Nov 11, 2019 - - -
    Some time ago, someone I follow on twitter posted about having to buy a whole book with rules to tease out grammatical gender in German. Further down the replies, someone reminisced about trying (and failing) to learn German just by listening to Rammstein’s lyrics. I studied about drei Jahre of German at the same time I started listening to Rammstein and other German-speaking bands and I’ve always found Rammstein’s lyrics to be surprisingly simple.
    -
    -
    -
    -
    -
    diff --git a/docs/en/2023/11/kriging-metr-r/index.html b/docs/en/2023/11/kriging-metr-r/index.html new file mode 100644 index 0000000..bddf78d --- /dev/null +++ b/docs/en/2023/11/kriging-metr-r/index.html @@ -0,0 +1,816 @@ + + + + + + + + + + + + + + + + + + + + + + + + + Kriging with metR + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    + + + + + + +
    +
    + + +
    + +

    + Kriging with metR +

    + + + + + + + +
    + + + + + + +
    +
    + + + +

    Say yo have data measured at different weather stations, which in Argentina might look something like this

    +
    estaciones[data, on = c("nombre" = "station")] |> 
    +   ggplot(aes(lon, lat)) +
    +   geom_point(aes(color = t)) +
    +   geom_sf(data = argentina_provincias, inherit.aes = FALSE, fill = NA) + 
    +   scale_color_viridis_c()
    +

    +

    Because this is not a regular grid, it’s not possible to visualise this data with contours as is. +Instead, it’s necessary to interpolate it into a regular grid.

    +

    There are many ways to go from irregular measurement locations to a regular grid and it comes with a bunch of assumptions. +But for quick an dirty visualisations, metR::geom_contour_fill() can use kriging by setting kriging = TRUE

    +
    estaciones[data, on = c("nombre" = "station")] |> 
    +   ggplot(aes(lon, lat)) +
    +   metR::geom_contour_fill(aes(z = t), 
    +                           kriging = TRUE) +
    +   geom_point(aes(fill = t), shape = 21) +
    +   geom_sf(data = argentina_provincias, inherit.aes = FALSE, fill = NA) + 
    +   scale_color_viridis_c(aesthetics = c("fill", "colour")) 
    +

    +

    One big problem with this is that by default it estimates values in the bounding box of the data, which in this case includes a bunch of the Atlantic Ocean. +So it would be nice to be able to only show the contours over land.

    +

    In a desperate attempt to procrastinate from writing my thesis I implemented this functionality. +Now, the clip argument takes a polygon which clips the contours.

    +
    estaciones[data, on = c("nombre" = "station")] |> 
    +   ggplot(aes(lon, lat)) +
    +   metR::geom_contour_fill(aes(z = t), 
    +                           kriging = TRUE, 
    +                           clip = argentina_provincias_sin_malvinas) +
    +   geom_point(aes(fill = t), shape = 21) +
    +   geom_sf(data = argentina_provincias, inherit.aes = FALSE, fill = NA) + 
    +   scale_color_viridis_c(aesthetics = c("fill", "colour")) 
    +

    +

    Another small issue is that the default interpolates to a 40-pixel wide grid, which is a bit too coarse and doesn’t reach the top corners of the map. +The kriging argument now can take a numeric, which defines number of gridpoints each direction.

    +
    estaciones[data, on = c("nombre" = "station")] |> 
    +   ggplot(aes(lon, lat)) +
    +   metR::geom_contour_fill(aes(z = t), 
    +                           kriging = 100, 
    +                           clip = argentina_provincias_sin_malvinas) +
    +   geom_point(aes(fill = t), shape = 21) +
    +   geom_sf(data = argentina_provincias, inherit.aes = FALSE, fill = NA) + 
    +   scale_color_viridis_c(aesthetics = c("fill", "colour")) 
    +

    +

    Much better!

    +

    You can install the development version of metR with

    +
    install.packages("metR", repos = c("https://eliocamp.github.io/metR", getOption("repos")))
    + + +
    +
    + +
    +
    + + © 2023 Elio Campitelli. All Rights Reserved + +
    + +
    +
    + +
    + + +
    + + +
    + + +
    + +
    +
    +
    + +
    + + Author's picture + +

    Elio Campitelli

    + + +
    + +
    + Atmospheric sciences graduate researcher at CONICET +
    + + +
    + +
    + Argentina +
    + +
    +
    + + + + + +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/en/2023/11/metr-new-features/index.html b/docs/en/2023/11/metr-new-features/index.html new file mode 100644 index 0000000..9e299db --- /dev/null +++ b/docs/en/2023/11/metr-new-features/index.html @@ -0,0 +1,817 @@ + + + + + + + + + + + + + + + + + + + + + + + + + Kriging with metR + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    + + + + + + +
    +
    + + +
    + +

    + Kriging with metR +

    + + + + + + + +
    + + + + + + +
    +
    + + + +

    The other day I was on a meeting with a colleague and she mentioned having problems trying to plot station-based data. +She had data measured at different weather stations, which in Argentina might look something like this

    +
    estaciones[data, on = c("nombre" = "station")] |> 
    +   ggplot(aes(lon, lat)) +
    +   geom_point(aes(color = t)) +
    +   geom_sf(data = argentina_provincias, inherit.aes = FALSE, fill = NA) + 
    +   scale_color_viridis_c()
    +

    +

    Because this is not a regular grid, it’s not possible to visualise this data with contours as is. +Instead, it’s necessary to interpolate it into a regular grid.

    +

    There are many ways to go from irregular measurement locations to a regular grid and it comes with a bunch of assumptions. +But for quick an dirty visualisations, metR::geom_contour_fill() can use kriging by setting kriging = TRUE

    +
    estaciones[data, on = c("nombre" = "station")] |> 
    +   ggplot(aes(lon, lat)) +
    +   metR::geom_contour_fill(aes(z = t), 
    +                           kriging = TRUE) +
    +   geom_point(aes(fill = t), shape = 21) +
    +   geom_sf(data = argentina_provincias, inherit.aes = FALSE, fill = NA) + 
    +   scale_color_viridis_c(aesthetics = c("fill", "colour")) 
    +

    +

    One big problem with this is that by default it estimates values in the bounding box of the data, which in this case includes a bunch of the Atlantic Ocean. +So it would be nice to be able to only show the contours over land.

    +

    In a desperate attempt to procrastinate from writing my thesis I implemented this functionality. +Now, the clip argument takes a polygon removes contours outside the polygon.

    +
    estaciones[data, on = c("nombre" = "station")] |> 
    +   ggplot(aes(lon, lat)) +
    +   metR::geom_contour_fill(aes(z = t), 
    +                           kriging = TRUE, 
    +                           clip = argentina_provincias_sin_malvinas) +
    +   geom_point(aes(fill = t), shape = 21) +
    +   geom_sf(data = argentina_provincias, inherit.aes = FALSE, fill = NA) + 
    +   scale_color_viridis_c(aesthetics = c("fill", "colour")) 
    +

    +

    Another small issue is that the default interpolates to a 40-pixel wide grid, which is a bit too coarse and doesn’t reach the top corners of the map. +The kriging argument now can take a numeric, which defines number of gridpoints each direction.

    +
    estaciones[data, on = c("nombre" = "station")] |> 
    +   ggplot(aes(lon, lat)) +
    +   metR::geom_contour_fill(aes(z = t), 
    +                           kriging = 100, 
    +                           clip = argentina_provincias_sin_malvinas) +
    +   geom_point(aes(fill = t), shape = 21) +
    +   geom_sf(data = argentina_provincias, inherit.aes = FALSE, fill = NA) + 
    +   scale_color_viridis_c(aesthetics = c("fill", "colour")) 
    +

    +

    Much better!

    +

    You can install the development version of metR with

    +
    install.packages("metR", repos = c("https://eliocamp.github.io/metR", getOption("repos")))
    + + +
    +
    + +
    +
    + + © 2023 Elio Campitelli. All Rights Reserved + +
    + +
    +
    + +
    + + +
    + + +
    + + +
    + +
    +
    +
    + +
    + + Author's picture + +

    Elio Campitelli

    + + +
    + +
    + Atmospheric sciences graduate researcher at CONICET +
    + + +
    + +
    + Argentina +
    + +
    +
    + + + + + +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/en/404.html b/docs/en/404.html index 0674c0e..8d0a129 100644 --- a/docs/en/404.html +++ b/docs/en/404.html @@ -127,6 +127,24 @@

    Elio Campitelli

    +
    + +
    + +

    Kriging with metR

    +
    + + + Nov 11, 2023 + + +
    Say yo have data measured at different weather stations, which in Argentina might look something like this +estaciones[data, on = c("nombre" = "station")] |> ggplot(aes(lon, lat)) + geom_point(aes(color = t)) + geom_sf(data = argentina_provincias, inherit.aes = FALSE, fill = NA) + scale_color_viridis_c() Because this is not a regular grid, it’s not possible to visualise this data with contours as is. Instead, it’s necessary to interpolate it into a regular grid.
    +
    +
    +
    +
    +
    @@ -290,23 +308,6 @@

    Star Trek ratings on IMDB


    -
    - -
    - -

    Rammstein vs. Lacrimosa

    -
    - - - Nov 11, 2019 - - -
    Some time ago, someone I follow on twitter posted about having to buy a whole book with rules to tease out grammatical gender in German. Further down the replies, someone reminisced about trying (and failing) to learn German just by listening to Rammstein’s lyrics. I studied about drei Jahre of German at the same time I started listening to Rammstein and other German-speaking bands and I’ve always found Rammstein’s lyrics to be surprisingly simple.
    -
    -
    -
    -
    -
    diff --git a/docs/en/archives/index.html b/docs/en/archives/index.html index dd9bd14..1eec049 100644 --- a/docs/en/archives/index.html +++ b/docs/en/archives/index.html @@ -218,6 +218,15 @@

    2023

    + +