Skip to content

Commit 2a33a5f

Browse files
authored
Merge pull request #55 from rOpenSpain/dechelp2
Package update
2 parents 415d3c5 + 17c6e34 commit 2a33a5f

25 files changed

+553
-93
lines changed

NAMESPACE

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export(climatestripes_station)
2222
export(climatogram_normal)
2323
export(climatogram_period)
2424
export(dms2decdegrees)
25+
export(dms2decdegrees_2)
2526
export(first_day_of_year)
2627
export(get_data_aemet)
2728
export(get_metadata_aemet)

NEWS.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
- Migrate from **httr** to **httr2** (#50).
44
- It is possible to use several API keys to avoid API throttling, see
5-
`?climaemet::aemet_api_key` (#53).
5+
`?climaemet::aemet_api_key` (#53). `?climaemet::aemet_api_key`.
6+
- New helper function `dms2decdegrees_2()`.
7+
- Update `aemet_munic` with January 2024 data.
68

79
# climaemet 1.2.1
810

R/data.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,11 @@ NULL
8989
#'
9090
#' @description
9191
#' A [`tibble`][tibble::tibble()] with all the municipalities of Spain as
92-
#' defined by the INE (Instituto Nacional de Estadistica) as of January 2020.
92+
#' defined by the INE (Instituto Nacional de Estadistica) as of January 2024.
9393
#'
9494
#' @source
9595
#' INE, [Municipality codes by
96-
#' province](https://www.ine.es/en/daco/daco42/codmun/codmunmapa_en.htm)
96+
#' province](https://www.ine.es/dyngs/INEbase/es/operacion.htm?c=Estadistica_C&cid=1254736177031&menu=ultiDatos&idp=1254734710990)
9797
#'
9898
#' @encoding UTF-8
9999
#'

R/helpers.R

+29-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@
44
#'
55
#' @family helpers
66
#'
7-
#' @note Code modified from project <https://github.com/SevillaR/aemet>
7+
#' @rdname dms2decdegrees
8+
#'
9+
#' @note
10+
#'
11+
#' Code for `dms2decdegrees()` modified from project
12+
#' <https://github.com/SevillaR/aemet>.
813
#'
914
#' @param input Character string as DMS coordinates.
1015
#'
@@ -13,7 +18,6 @@
1318
#' @examples
1419
#' dms2decdegrees("055245W")
1520
#' @export
16-
1721
dms2decdegrees <- function(input = NULL) {
1822
if (is.null(input)) {
1923
stop("Input can't be missing")
@@ -33,6 +37,29 @@ dms2decdegrees <- function(input = NULL) {
3337
return(x)
3438
}
3539

40+
#' @rdname dms2decdegrees
41+
#' @export
42+
#' @examples
43+
#' dms2decdegrees_2("-3º 40' 37\"")
44+
dms2decdegrees_2 <- function(input = NULL) {
45+
input_2 <- iconv(input, "latin1", "ASCII", sub = " ")
46+
minus <- ifelse(grepl("^-", input_2), -1, 1)
47+
# Remove now signs
48+
input_3 <- gsub("[^0-9]", " ", input_2)
49+
50+
pieces <- unlist(strsplit(input_3, split = " "))
51+
pieces <- as.double(pieces[pieces != ""])
52+
53+
# Check here
54+
if (length(pieces) != 3) stop("Something went wrong")
55+
56+
57+
# Convert pieces and sign
58+
dec <- minus * sum(pieces / c(1, 60, 60^2))
59+
60+
dec
61+
}
62+
3663
#' First and last day of year
3764
#'
3865
#' Get first and last day of year.

README.Rmd

+1-1
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ data_observation <- aemet_last_obs(station)
150150
knitr::kable(head(data_observation))
151151
152152
## Get daily/annual climatology values for a station
153-
data_daily <- aemet_daily_clim(station, start = "2022-01-01", end = "2022-12-31")
153+
data_daily <- aemet_daily_clim(station, start = "2022-01-01", end = "2022-06-30")
154154
155155
knitr::kable(head(data_daily))
156156

README.md

+21-19
Original file line numberDiff line numberDiff line change
@@ -117,20 +117,22 @@ library(climaemet)
117117
# See a tibble in action
118118

119119
aemet_last_obs("9434")
120-
#> # A tibble: 24 × 25
120+
#> # A tibble: 13 × 25
121121
#> idema lon fint prec alt vmax vv dv lat dmax
122122
#> <chr> <dbl> <dttm> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
123-
#> 1 9434 -1.00 2024-04-22 10:00:00 0 249 16.1 9.8 325 41.7 310
124-
#> 2 9434 -1.00 2024-04-22 11:00:00 0 249 15.1 8.3 322 41.7 323
125-
#> 3 9434 -1.00 2024-04-22 12:00:00 0 249 13.5 7.8 335 41.7 318
126-
#> 4 9434 -1.00 2024-04-22 13:00:00 0 249 14.5 9.4 317 41.7 330
127-
#> 5 9434 -1.00 2024-04-22 14:00:00 0 249 16.6 9.9 325 41.7 315
128-
#> 6 9434 -1.00 2024-04-22 15:00:00 0 249 15.9 8.7 332 41.7 318
129-
#> 7 9434 -1.00 2024-04-22 16:00:00 0 249 16.4 8.8 328 41.7 328
130-
#> 8 9434 -1.00 2024-04-22 17:00:00 0 249 16.8 10.5 327 41.7 325
131-
#> 9 9434 -1.00 2024-04-22 18:00:00 0 249 18.5 12.1 321 41.7 318
132-
#> 10 9434 -1.00 2024-04-22 19:00:00 0 249 19.5 10.2 318 41.7 315
133-
#> # ℹ 14 more rows
123+
#> 1 9434 -1.00 2024-06-19 21:00:00 0 249 14.6 7.5 317 41.7 318
124+
#> 2 9434 -1.00 2024-06-19 22:00:00 0 249 14.1 8.8 307 41.7 318
125+
#> 3 9434 -1.00 2024-06-19 23:00:00 0 249 14.5 7.3 300 41.7 293
126+
#> 4 9434 -1.00 2024-06-20 00:00:00 0 249 9.4 3.9 316 41.7 293
127+
#> 5 9434 -1.00 2024-06-20 01:00:00 0 249 8.4 5.9 310 41.7 295
128+
#> 6 9434 -1.00 2024-06-20 02:00:00 0 249 8.4 6.1 309 41.7 323
129+
#> 7 9434 -1.00 2024-06-20 03:00:00 0 249 10 7.7 298 41.7 298
130+
#> 8 9434 -1.00 2024-06-20 04:00:00 0 249 10.4 7.2 304 41.7 325
131+
#> 9 9434 -1.00 2024-06-20 05:00:00 0 249 9.7 6.5 301 41.7 313
132+
#> 10 9434 -1.00 2024-06-20 06:00:00 4 249 9.2 4.5 304 41.7 305
133+
#> 11 9434 -1.00 2024-06-20 07:00:00 0 249 9.8 6.9 291 41.7 280
134+
#> 12 9434 -1.00 2024-06-20 08:00:00 0 249 11 5.1 313 41.7 308
135+
#> 13 9434 -1.00 2024-06-20 09:00:00 0 249 7.9 4.9 320 41.7 308
134136
#> # ℹ 15 more variables: ubi <chr>, pres <dbl>, hr <dbl>, stdvv <dbl>, ts <dbl>,
135137
#> # pres_nmar <dbl>, tamin <dbl>, ta <dbl>, tamax <dbl>, tpr <dbl>,
136138
#> # stddv <dbl>, inso <dbl>, tss5cm <dbl>, pacutp <dbl>, tss20cm <dbl>
@@ -169,17 +171,17 @@ knitr::kable(head(data_observation))
169171

170172
| idema | lon | fint | prec | alt | vmax | vv | dv | lat | dmax | ubi | pres | hr | stdvv | ts | pres_nmar | tamin | ta | tamax | tpr | stddv | inso | tss5cm | pacutp | tss20cm |
171173
|:------|----------:|:--------------------|-----:|----:|-----:|----:|----:|---------:|-----:|:--------------------|------:|----:|------:|-----:|----------:|------:|-----:|------:|-----:|------:|-----:|-------:|-------:|--------:|
172-
| 9434 | -1.004167 | 2024-04-22 10:00:00 | 0 | 249 | 16.1 | 9.8 | 325 | 41.66056 | 310 | ZARAGOZA AEROPUERTO | 988.0 | 29 | 1.9 | 17.0 | 1018.1 | 11.4 | 13.1 | 13.4 | -4.5 | 11 | 60 | 17.5 | 0 | 18.0 |
173-
| 9434 | -1.004167 | 2024-04-22 11:00:00 | 0 | 249 | 15.1 | 8.3 | 322 | 41.66056 | 323 | ZARAGOZA AEROPUERTO | 987.5 | 26 | 1.8 | 19.2 | 1017.5 | 13.1 | 14.6 | 14.7 | -4.8 | 11 | 60 | 19.1 | 0 | 17.9 |
174-
| 9434 | -1.004167 | 2024-04-22 12:00:00 | 0 | 249 | 13.5 | 7.8 | 335 | 41.66056 | 318 | ZARAGOZA AEROPUERTO | 987.1 | 22 | 1.9 | 20.6 | 1017.0 | 14.4 | 15.4 | 15.5 | -6.4 | 14 | 60 | 21.0 | 0 | 18.0 |
175-
| 9434 | -1.004167 | 2024-04-22 13:00:00 | 0 | 249 | 14.5 | 9.4 | 317 | 41.66056 | 330 | ZARAGOZA AEROPUERTO | 986.6 | 22 | 1.4 | 20.6 | 1016.4 | 15.4 | 16.0 | 16.2 | -5.7 | 10 | 60 | 22.6 | 0 | 18.2 |
176-
| 9434 | -1.004167 | 2024-04-22 14:00:00 | 0 | 249 | 16.6 | 9.9 | 325 | 41.66056 | 315 | ZARAGOZA AEROPUERTO | 986.2 | 22 | 2.0 | 21.3 | 1015.9 | 15.8 | 16.2 | 16.5 | -5.7 | 11 | 60 | 23.5 | 0 | 18.5 |
177-
| 9434 | -1.004167 | 2024-04-22 15:00:00 | 0 | 249 | 15.9 | 8.7 | 332 | 41.66056 | 318 | ZARAGOZA AEROPUERTO | 985.8 | 22 | 1.8 | 20.4 | 1015.6 | 15.9 | 15.9 | 16.5 | -5.7 | 13 | 60 | 23.8 | 0 | 18.9 |
174+
| 9434 | -1.004167 | 2024-06-19 21:00:00 | 0 | 249 | 14.6 | 7.5 | 317 | 41.66056 | 318 | ZARAGOZA AEROPUERTO | 984.2 | 48 | 2.3 | 24.8 | 1013.0 | 23.9 | 23.9 | 26.4 | 12.2 | 14 | 0 | 34.0 | 0 | 33.9 |
175+
| 9434 | -1.004167 | 2024-06-19 22:00:00 | 0 | 249 | 14.1 | 8.8 | 307 | 41.66056 | 318 | ZARAGOZA AEROPUERTO | 984.3 | 61 | 1.1 | 21.6 | 1013.4 | 20.6 | 20.7 | 23.9 | 13.0 | 9 | 0 | 32.9 | 0 | 33.7 |
176+
| 9434 | -1.004167 | 2024-06-19 23:00:00 | 0 | 249 | 14.5 | 7.3 | 300 | 41.66056 | 293 | ZARAGOZA AEROPUERTO | 985.3 | 58 | 1.4 | 21.0 | 1014.5 | 20.2 | 20.3 | 20.7 | 11.8 | 9 | 0 | 31.9 | 0 | 33.4 |
177+
| 9434 | -1.004167 | 2024-06-20 00:00:00 | 0 | 249 | 9.4 | 3.9 | 316 | 41.66056 | 293 | ZARAGOZA AEROPUERTO | 984.9 | 60 | 0.8 | 19.6 | 1014.2 | 19.4 | 19.4 | 20.4 | 11.4 | 10 | 0 | 31.1 | 0 | 33.0 |
178+
| 9434 | -1.004167 | 2024-06-20 01:00:00 | 0 | 249 | 8.4 | 5.9 | 310 | 41.66056 | 295 | ZARAGOZA AEROPUERTO | 984.8 | 60 | 0.8 | 19.5 | 1014.1 | 19.0 | 19.0 | 19.4 | 11.1 | 7 | 0 | 30.3 | 0 | 32.6 |
179+
| 9434 | -1.004167 | 2024-06-20 02:00:00 | 0 | 249 | 8.4 | 6.1 | 309 | 41.66056 | 323 | ZARAGOZA AEROPUERTO | 984.3 | 61 | 0.9 | 19.9 | 1013.6 | 18.6 | 18.7 | 19.1 | 11.0 | 7 | 0 | 29.7 | 0 | 32.2 |
178180

179181
``` r
180182

181183
## Get daily/annual climatology values for a station
182-
data_daily <- aemet_daily_clim(station, start = "2022-01-01", end = "2022-12-31")
184+
data_daily <- aemet_daily_clim(station, start = "2022-01-01", end = "2022-06-30")
183185

184186
knitr::kable(head(data_daily))
185187
```

codemeta.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"name": "R",
1515
"url": "https://r-project.org"
1616
},
17-
"runtimePlatform": "R version 4.3.3 (2024-02-29 ucrt)",
17+
"runtimePlatform": "R version 4.4.0 (2024-04-24)",
1818
"provider": {
1919
"@id": "https://cran.r-project.org",
2020
"@type": "Organization",
@@ -301,7 +301,7 @@
301301
},
302302
"applicationCategory": "Meteorology",
303303
"isPartOf": "https://ropenspain.es/",
304-
"fileSize": "772.362KB",
304+
"fileSize": "776.122KB",
305305
"citation": [
306306
{
307307
"@type": "SoftwareSourceCode",

data-raw/aemet_munic.R

+12-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@
33

44
library(readxl)
55
library(dplyr)
6-
munis <- read_excel("data-raw/20codmun.xlsx",
6+
7+
download.file(
8+
"https://www.ine.es/daco/daco42/codmun/diccionario24.xlsx",
9+
"data-raw/diccionario24.xlsx"
10+
)
11+
12+
munis <- read_excel("data-raw/diccionario24.xlsx",
713
skip = 1
814
)
915

@@ -21,6 +27,8 @@ selected <- master_mapspain %>%
2127
) %>%
2228
distinct_all()
2329

30+
prev <- climaemet::aemet_munic
31+
2432
# Build final name
2533
aemet_munic <- munis %>%
2634
left_join(selected) %>%
@@ -33,4 +41,7 @@ aemet_munic <- munis %>%
3341
arrange(municipio)
3442

3543

44+
identical(names(prev), names(aemet_munic))
45+
46+
3647
usethis::use_data(aemet_munic, overwrite = TRUE)

data-raw/diccionario24.xlsx

299 KB
Binary file not shown.

data/aemet_munic.rda

-224 Bytes
Binary file not shown.

data/climaemet_9434_climatogram.rda

15 Bytes
Binary file not shown.

data/climaemet_9434_temp.rda

-4 Bytes
Binary file not shown.

data/climaemet_9434_wind.rda

28 Bytes
Binary file not shown.

inst/schemaorg.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
"name": "Comprehensive R Archive Network (CRAN)",
4343
"url": "https://cran.r-project.org"
4444
},
45-
"runtimePlatform": "R version 4.3.3 (2024-02-29 ucrt)",
45+
"runtimePlatform": "R version 4.4.0 (2024-04-24)",
4646
"version": "1.2.1.9000"
4747
},
4848
{

man/aemet_munic.Rd

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/dms2decdegrees.Rd

+6-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
-824 Bytes
Loading

man/figures/README-climatogram-1.png

-38 Bytes
Loading

man/figures/README-spatial-1.png

-1.51 KB
Loading

man/figures/README-windrose-1.png

-907 Bytes
Loading

vignettes/climaemet.Rmd

+21-21
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Once that you have your API Key, you can use any of the following methods:
3535
This is the recommended option. Just type:
3636

3737

38-
```r
38+
``` r
3939
aemet_api_key("YOUR_API_KEY", install = TRUE)
4040
```
4141

@@ -49,7 +49,7 @@ This is a temporary alternative. You can set your API key as an environment
4949
variable
5050

5151

52-
```r
52+
``` r
5353
Sys.setenv(AEMET_API_KEY = "YOUR_API_KEY")
5454
```
5555

@@ -83,27 +83,27 @@ numbers are parsed as double, etc.).
8383
See how a `tibble` is displayed:
8484

8585

86-
```r
86+
``` r
8787
# See a tibble in action
8888

8989
aemet_last_obs("9434")
90-
#> # A tibble: 24 × 25
91-
#> idema lon fint prec alt vmax vv dv lat dmax
92-
#> <chr> <dbl> <dttm> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
93-
#> 1 9434 -1.00 2024-04-22 10:00:00 0 249 16.1 9.8 325 41.7 310
94-
#> 2 9434 -1.00 2024-04-22 11:00:00 0 249 15.1 8.3 322 41.7 323
95-
#> 3 9434 -1.00 2024-04-22 12:00:00 0 249 13.5 7.8 335 41.7 318
96-
#> 4 9434 -1.00 2024-04-22 13:00:00 0 249 14.5 9.4 317 41.7 330
97-
#> 5 9434 -1.00 2024-04-22 14:00:00 0 249 16.6 9.9 325 41.7 315
98-
#> 6 9434 -1.00 2024-04-22 15:00:00 0 249 15.9 8.7 332 41.7 318
99-
#> 7 9434 -1.00 2024-04-22 16:00:00 0 249 16.4 8.8 328 41.7 328
100-
#> 8 9434 -1.00 2024-04-22 17:00:00 0 249 16.8 10.5 327 41.7 325
101-
#> 9 9434 -1.00 2024-04-22 18:00:00 0 249 18.5 12.1 321 41.7 318
102-
#> 10 9434 -1.00 2024-04-22 19:00:00 0 249 19.5 10.2 318 41.7 315
103-
#> # ℹ 14 more rows
104-
#> # ℹ 15 more variables: ubi <chr>, pres <dbl>, hr <dbl>, stdvv <dbl>, ts <dbl>,
105-
#> # pres_nmar <dbl>, tamin <dbl>, ta <dbl>, tamax <dbl>, tpr <dbl>,
106-
#> # stddv <dbl>, inso <dbl>, tss5cm <dbl>, pacutp <dbl>, tss20cm <dbl>
90+
#> # A tibble: 13 × 25
91+
#> idema lon fint prec alt vmax vv dv lat dmax ubi pres hr stdvv ts pres_nmar tamin ta
92+
#> <chr> <dbl> <dttm> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
93+
#> 1 9434 -1.00 2024-06-19 21:00:00 0 249 14.6 7.5 317 41.7 318 ZARA… 984. 48 2.3 24.8 1013 23.9 23.9
94+
#> 2 9434 -1.00 2024-06-19 22:00:00 0 249 14.1 8.8 307 41.7 318 ZARA… 984. 61 1.1 21.6 1013. 20.6 20.7
95+
#> 3 9434 -1.00 2024-06-19 23:00:00 0 249 14.5 7.3 300 41.7 293 ZARA… 985. 58 1.4 21 1014. 20.2 20.3
96+
#> 4 9434 -1.00 2024-06-20 00:00:00 0 249 9.4 3.9 316 41.7 293 ZARA… 985. 60 0.8 19.6 1014. 19.4 19.4
97+
#> 5 9434 -1.00 2024-06-20 01:00:00 0 249 8.4 5.9 310 41.7 295 ZARA… 985. 60 0.8 19.5 1014. 19 19
98+
#> 6 9434 -1.00 2024-06-20 02:00:00 0 249 8.4 6.1 309 41.7 323 ZARA… 984. 61 0.9 19.9 1014. 18.6 18.7
99+
#> 7 9434 -1.00 2024-06-20 03:00:00 0 249 10 7.7 298 41.7 298 ZARA… 984. 63 0.8 19.9 1014. 18.4 18.8
100+
#> 8 9434 -1.00 2024-06-20 04:00:00 0 249 10.4 7.2 304 41.7 325 ZARA… 984 70 1.3 18.8 1013. 17.8 17.9
101+
#> 9 9434 -1.00 2024-06-20 05:00:00 0 249 9.7 6.5 301 41.7 313 ZARA… 985. 70 1.2 18.6 1014. 17.8 17.8
102+
#> 10 9434 -1.00 2024-06-20 06:00:00 4 249 9.2 4.5 304 41.7 305 ZARA… 985. 81 0.8 17.8 1015. 16.7 17.3
103+
#> 11 9434 -1.00 2024-06-20 07:00:00 0 249 9.8 6.9 291 41.7 280 ZARA… 985. 76 1.2 20.8 1015. 17.3 18.2
104+
#> 12 9434 -1.00 2024-06-20 08:00:00 0 249 11 5.1 313 41.7 308 ZARA… 986. 68 0.9 23.8 1015 18.1 19.2
105+
#> 13 9434 -1.00 2024-06-20 09:00:00 0 249 7.9 4.9 320 41.7 308 ZARA… 986. 65 0.8 25.9 1016. 19.2 20.1
106+
#> # ℹ 7 more variables: tamax <dbl>, tpr <dbl>, stddv <dbl>, inso <dbl>, tss5cm <dbl>, pacutp <dbl>, tss20cm <dbl>
107107
```
108108

109109
Note that when possible, data representing dates and numbers are converted to
@@ -117,7 +117,7 @@ spatial **sf** format, using `return_sf = TRUE`. The coordinate reference system
117117
(WGS)** and return coordinates in latitude/longitude (unprojected coordinates):
118118

119119

120-
```r
120+
``` r
121121
# You would need to install `sf` if not installed yet
122122
# run install.packages("sf") for installation
123123

vignettes/example-gif.gif

206 Bytes
Loading

0 commit comments

Comments
 (0)