Skip to content

Commit 83fca73

Browse files
committed
Reorganizando datos y corrigiendo script dia 2
1 parent e683c3c commit 83fca73

19 files changed

Lines changed: 106 additions & 59 deletions
-3.29 MB
Binary file not shown.
Binary file not shown.

martes/Dia2_Datos_espaciales_R.Rmd renamed to martes/Dia2_Datos_espaciales_R/Dia2_Datos_espaciales_R.Rmd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ temp_fria <- temp_sup_ecu$data %>%
143143
#Escogemos los meses de la epoca fria
144144
filter(lubridate::month(time) <= 4 | lubridate::month(time) == 12) %>%
145145
#Agrupamos por latitud y longitud
146-
group_by(lat, lon) %>%
146+
group_by(latitude, longitude) %>%
147147
#Calculamos el promedio
148148
summarise(temp_prom = mean(sst, na.rm = T))
149149
```
@@ -156,7 +156,7 @@ tierra <- rnaturalearth::ne_countries(returnclass = "sf")
156156
157157
#Grafiquemos
158158
temp_fria %>%
159-
ggplot(aes(x = lon, y = lat))+
159+
ggplot(aes(x = longitude, y = latitude))+
160160
geom_contour_filled(aes(z = temp_prom), binwidth = 2.5)+
161161
scale_fill_brewer(palette = "YlOrRd")+
162162
geom_sf(data = tierra, inherit.aes = F)+

martes/Dia2_Datos_espaciales_R.md renamed to martes/Dia2_Datos_espaciales_R/Dia2_Datos_espaciales_R.md

Lines changed: 104 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,6 @@ Denisse Fierro Arcos
1616

1717
# Analisis de datos espaciales en `R`
1818

19-
Aqui describimos como acceder a datos en formato raster disponibles de
20-
manera libre de la NOAA a traves del servidor
21-
[ERDDAP](https://coastwatch.pfeg.noaa.gov/erddap/index.html) utilizando
22-
el paquete `rerddap`.
23-
2419
Tambien cubriremos como crear mapas utilizando datos tipo raster y
2520
poligonos utilizando las librerias `sf` y `ggplot2`.
2621

@@ -30,24 +25,19 @@ poligonos utilizando las librerias `sf` y `ggplot2`.
3025
library(tidyverse) #Incluye a ggplot2
3126
```
3227

33-
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.2 ──
34-
## ✔ ggplot2 3.4.0 ✔ purrr 1.0.1
35-
## ✔ tibble 3.1.8 ✔ dplyr 1.1.0
36-
## ✔ tidyr 1.3.0 ✔ stringr 1.5.0
37-
## ✔ readr 2.1.2 ✔ forcats 0.5.2
28+
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
29+
## ✔ dplyr 1.1.0 ✔ readr 2.1.4
30+
## ✔ forcats 1.0.0 ✔ stringr 1.5.0
31+
## ✔ ggplot2 3.4.1 ✔ tibble 3.1.8
32+
## ✔ lubridate 1.9.2 ✔ tidyr 1.3.0
33+
## ✔ purrr 1.0.1
3834
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
3935
## ✖ dplyr::filter() masks stats::filter()
4036
## ✖ dplyr::lag() masks stats::lag()
37+
## ℹ Use the ]8;;http://conflicted.r-lib.org/conflicted package]8;; to force all conflicts to become errors
4138

4239
``` r
4340
library(rerddap)
44-
```
45-
46-
## Registered S3 method overwritten by 'hoardr':
47-
## method from
48-
## print.cache_info httr
49-
50-
``` r
5141
library(raster)
5242
```
5343

@@ -201,16 +191,58 @@ Revisemos los datos en mas detalle.
201191
info(temp_sup_res$info$dataset_id[15])
202192
```
203193

204-
## <ERDDAP info> erdMH1sstdmday
194+
## <ERDDAP info> esrlIcoads2ge_LonPM180
205195
## Base URL: https://upwell.pfeg.noaa.gov/erddap
206196
## Dataset Type: griddap
207197
## Dimensions (range):
208-
## time: (2003-01-16T00:00:00Z, 2019-10-16T00:00:00Z)
209-
## latitude: (-89.97918, 89.97916)
210-
## longitude: (-179.9792, 179.9792)
198+
## time: (1800-01-01T00:00:00Z, 2023-01-01T00:00:00Z)
199+
## latitude: (-89.0, 89.0)
200+
## longitude: (-179.0, 179.0)
211201
## Variables:
202+
## air:
203+
## Units: degC
204+
## cldc:
205+
## Units: okta
206+
## lflx:
207+
## Units: grams/kg m/s
208+
## qsminq:
209+
## Units: grams/kg
210+
## rhum:
211+
## Units: %
212+
## sflx:
213+
## Units: degC m/s
214+
## shum:
215+
## Units: grams/kg
216+
## slp:
217+
## Units: millibars
218+
## smina:
219+
## Units: degC
212220
## sst:
213-
## Units: degree_C
221+
## Units: degC
222+
## uairt:
223+
## Units: degC m/s
224+
## ulflx:
225+
## Units: grams/kg m/s
226+
## upstr:
227+
## Units: m^2/s^2
228+
## uspeh:
229+
## Units: grams/kg m/s
230+
## uwnd:
231+
## Units: m/s
232+
## vairt:
233+
## Units: degC m/s
234+
## vlflx:
235+
## Units: grams/kg m/s
236+
## vpstr:
237+
## Units: m^2/s^2
238+
## vspeh:
239+
## Units: grams/kg m/s
240+
## vwnd:
241+
## Units: m/s
242+
## wspd:
243+
## Units: m/s
244+
## wspd3:
245+
## Units: m**3/s**3
214246

215247
Encontramos los datos que necesitamos. Ahora los bajamos a nuestro
216248
disco.
@@ -231,28 +263,31 @@ temp_sup_ecu <- griddap(temp_sup_res$info$dataset_id[15],
231263
temp_sup_ecu
232264
```
233265

234-
## <ERDDAP griddap> erdMH1sstdmday
235-
## Path: [Data//67632e6317d74225c2716f0f14779bb7.nc]
236-
## Last updated: [2023-02-17 16:02:40]
237-
## File size: [3.45 mb]
238-
## Dimensions (dims/vars): [3 X 1]
266+
## <ERDDAP griddap> esrlIcoads2ge_LonPM180
267+
## Path: [Data//718dcfde61b559a0aeb9011a8181c9f0.nc]
268+
## Last updated: [2023-03-01 21:02:43]
269+
## File size: [0.07 mb]
270+
## Dimensions (dims/vars): [3 X 22]
239271
## Dim names: time, latitude, longitude
240-
## Variable names: Masked Daytime Sea Surface Temperature
241-
## data.frame (rows/columns): [860256 X 4]
242-
## # A tibble: 860,256 × 4
243-
## time lat lon sst
244-
## <chr> <dbl> <dbl> <dbl>
245-
## 1 2010-01-16T00:00:00Z 2.02 -92.0 26.5
246-
## 2 2010-01-16T00:00:00Z 2.02 -92.0 26.4
247-
## 3 2010-01-16T00:00:00Z 2.02 -91.9 26.6
248-
## 4 2010-01-16T00:00:00Z 2.02 -91.9 26.6
249-
## 5 2010-01-16T00:00:00Z 2.02 -91.9 26.7
250-
## 6 2010-01-16T00:00:00Z 2.02 -91.8 26.7
251-
## 7 2010-01-16T00:00:00Z 2.02 -91.8 26.8
252-
## 8 2010-01-16T00:00:00Z 2.02 -91.7 26.5
253-
## 9 2010-01-16T00:00:00Z 2.02 -91.7 26.1
254-
## 10 2010-01-16T00:00:00Z 2.02 -91.6 26.4
255-
## # … with 860,246 more rows
272+
## Variable names: Air Temperature Monthly Mean at Surface, Cloudiness Monthly Mean at Surface, Latent Heat Parameter Monthly Mean at Surface, Sat Sp Hum at Sst Minus Sp Hum Monthly Mean at Surface, Relative Humidity Monthly Mean at Surface, Sensible Heat Parameter Monthly Mean at Surface, Specific Humidity Monthly Mean at Surface, Sea Level Pressure Monthly Mean at Surface, Sea-air Temperature Difference Monthly Mean at Surface, Sea Surface Temperature Monthly Mean at Surface, Sensible Heat Trans Eastward Param Monthly Mean at Surface, Zonal Latent Heat Parameter Monthly Mean at Surface, u-wind Stress Monthly Mean at Surface, Latent Heat Trans Eastward Param Monthly Mean at Surface, u-wind Monthly Mean at Surface, Sensible Heat Trans Northward Param Monthly Mean at Surface, Meridional Latent Heat Parameter Monthly Mean at Surface, v-wind Stress Monthly Mean at Surface, Latent Heat Trans Northward Param Monthly Mean at Surface, v-wind Monthly Mean at Surface, Scalar Wind Monthly Mean at Surface, Scalar Wind Cubed Monthly Mean at Surface
273+
## data.frame (rows/columns): [585 X 25]
274+
## # A tibble: 585 × 25
275+
## longi…¹ latit…² time air cldc lflx qsminq rhum sflx shum slp smina
276+
## <dbl[1> <dbl[1> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
277+
## 1 -91 3 2010… 26.9 5.70 33.5 4.91 89 3 18.7 1011. 1.22
278+
## 2 -89 3 2010… 26.6 5.30 40 5.79 89.4 1.30 18.6 1010. 2.25
279+
## 3 -87 3 2010… 24.7 5.70 9.60 3.69 94.2 5.20 18.3 1012 2
280+
## 4 -85 3 2010… 26.6 NA NA NA NA NA NA 1012. NA
281+
## 5 -83 3 2010… 26.9 8 13.7 5.05 80 3.60 18.4 1010. 0.820
282+
## 6 -81 3 2010… 27.0 6.10 17.9 2.20 84.9 1.40 19.2 1010. -0.200
283+
## 7 -79 3 2010… 23.9 8 23.5 5.67 83.8 10.1 16.8 1010. 2.40
284+
## 8 -77 3 2010… 26.0 7.5 11 4.22 77.3 2.20 19.0 1010. 0.450
285+
## 9 -75 3 2010… NA NA NA NA NA NA NA NA NA
286+
## 10 -91 1 2010… NA NA NA NA NA NA NA NA NA
287+
## # … with 575 more rows, 13 more variables: sst <dbl>, uairt <dbl>, ulflx <dbl>,
288+
## # upstr <dbl>, uspeh <dbl>, uwnd <dbl>, vairt <dbl>, vlflx <dbl>,
289+
## # vpstr <dbl>, vspeh <dbl>, vwnd <dbl>, wspd <dbl>, wspd3 <dbl>, and
290+
## # abbreviated variable names ¹​longitude, ²​latitude
256291

257292
Revisemos los archivos que acabamos de guardar en el disco.
258293

@@ -261,27 +296,33 @@ archivo <- list.files("Data/", pattern = ".nc", full.names = T)
261296
archivo
262297
```
263298

264-
## [1] "Data/67632e6317d74225c2716f0f14779bb7.nc"
299+
## [1] "Data//718dcfde61b559a0aeb9011a8181c9f0.nc"
265300

266301
## Graficando datos
267302

268303
Tenemos primero que subir los datos a nuestra sesion.
269304

270305
``` r
271306
temp_sup_ec <- raster(archivo)
307+
```
308+
309+
## Warning in .varName(nc, varname, warn = warn): varname used is: air
310+
## If that is not correct, you can set it to one of: air, cldc, lflx, qsminq, rhum, sflx, shum, slp, smina, sst, uairt, ulflx, upstr, uspeh, uwnd, vairt, vlflx, vpstr, vspeh, vwnd, wspd, wspd3
311+
312+
``` r
272313
temp_sup_ec
273314
```
274315

275316
## class : RasterLayer
276-
## band : 1 (of 12 bands)
277-
## dimensions : 174, 412, 71688 (nrow, ncol, ncell)
278-
## resolution : 0.04166667, 0.04166668 (x, y)
279-
## extent : -92.04166, -74.875, -5.208338, 2.041664 (xmin, xmax, ymin, ymax)
317+
## band : 1 (of 13 bands)
318+
## dimensions : 5, 9, 45 (nrow, ncol, ncell)
319+
## resolution : 2, 2 (x, y)
320+
## extent : -92, -74, -6, 4 (xmin, xmax, ymin, ymax)
280321
## crs : +proj=longlat +datum=WGS84 +no_defs
281-
## source : 67632e6317d74225c2716f0f14779bb7.nc
282-
## names : Masked.Daytime.Sea.Surface.Temperature
283-
## z-value : 2010-01-16
284-
## zvar : sst
322+
## source : 718dcfde61b559a0aeb9011a8181c9f0.nc
323+
## names : Air.Temperature.Monthly.Mean.at.Surface
324+
## z-value : 2010-01-01
325+
## zvar : air
285326

286327
Este archivo tiene 12 bandas, una por cada mes en el anio. Revisemos el
287328
primer mes.
@@ -311,31 +352,37 @@ temp_fria <- temp_sup_ecu$data %>%
311352
#Escogemos los meses de la epoca fria
312353
filter(lubridate::month(time) <= 4 | lubridate::month(time) == 12) %>%
313354
#Agrupamos por latitud y longitud
314-
group_by(lat, lon) %>%
355+
group_by(latitude, longitude) %>%
315356
#Calculamos el promedio
316357
summarise(temp_prom = mean(sst, na.rm = T))
317358
```
318359

319-
## `summarise()` has grouped output by 'lat'. You can override using the `.groups`
320-
## argument.
360+
## `summarise()` has grouped output by 'latitude'. You can override using the
361+
## `.groups` argument.
321362

322363
Ahora podemos graficar este promedio.
323364

324365
``` r
325366
#Capa de continentes
326367
tierra <- rnaturalearth::ne_countries(returnclass = "sf")
368+
```
369+
370+
## Registered S3 method overwritten by 'httr':
371+
## method from
372+
## print.cache_info hoardr
327373

374+
``` r
328375
#Grafiquemos
329376
temp_fria %>%
330-
ggplot(aes(x = lon, y = lat))+
377+
ggplot(aes(x = longitude, y = latitude))+
331378
geom_contour_filled(aes(z = temp_prom), binwidth = 2.5)+
332379
scale_fill_brewer(palette = "YlOrRd")+
333380
geom_sf(data = tierra, inherit.aes = F)+
334381
lims(x = c(-92, -74.9), y = c(-5.2, 2))+
335382
theme_bw()
336383
```
337384

338-
## Warning: Removed 23522 rows containing non-finite values
385+
## Warning: Removed 19 rows containing non-finite values
339386
## (`stat_contour_filled()`).
340387

341388
![](Dia2_Datos_espaciales_R_files/figure-gfm/unnamed-chunk-13-1.png)<!-- -->
8.69 KB
Loading
8.55 KB
Loading
19.8 KB
Loading
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)