Closed mikejohnson51 closed 3 years ago
library(sf)
#> Warning: package 'sf' was built under R version 4.0.2
#> Linking to GEOS 3.8.1, GDAL 3.1.1, PROJ 6.3.1
library(climateR)
AOI = st_sfc(st_point(c(-70.06456, 41.93111)), crs = 4326)
prism = getPRISM(AOI, "prcp",
startDate = "2018-01-01",
endDate = "2018-01-31")
gridMet = getGridMET(AOI,
param = "prcp",
startDate = "2018-01-01",
endDate = "2018-01-31")
plot(prism$date, prism$prcp, type = "l")
lines(c(gridMet$date), c(gridMet$prcp), type = "l", col = "red")
Created on 2021-01-19 by the reprex package (v0.3.0)
Turns out this was not a bug in climateR but an actual lag between the gridmet and prism dataset! This is being reverted:
Thank you to @sgoslee for identifying this was not a correct fix. The data we expect now is demonstrated below with a comparison to a CSV downloaded from the gridmet producers.
library(sf)
#> Warning: package 'sf' was built under R version 4.0.2
#> Linking to GEOS 3.8.1, GDAL 3.1.4, PROJ 6.3.1
library(climateR)
AOI = st_sfc(st_point(c(-70.06456, 41.93111)), crs = 4326)
prism = getPRISM(AOI, "prcp",
startDate = "2018-01-01",
endDate = "2018-01-31")
gridMet = getGridMET(AOI,
param = "prcp",
startDate = "2018-01-01",
endDate = "2018-01-31")
plot(prism$date, prism$prcp, type = "l")
lines(c(gridMet$date), c(gridMet$prcp), type = "l", col = "red")
# As evidence, we download the following file from:
# https://climatetoolbox.org/tool/Data-Download
from_gridmet = readr::read_csv('/Users/mikejohnson/Downloads/metdata_41.93111N_70.06456W.csv', skip = 8) %>%
dplyr::mutate(date = as.Date(paste(Year,
sprintf("%02d", Month),
sprintf("%02d", Day), sep = "-")))
#>
#> ── Column specification ────────────────────────────────────────────────────────
#> cols(
#> Year = col_double(),
#> Month = col_double(),
#> Day = col_double(),
#> `pr(mm)` = col_double()
#> )
head(from_gridmet)
#> # A tibble: 6 x 5
#> Year Month Day `pr(mm)` date
#> <dbl> <dbl> <dbl> <dbl> <date>
#> 1 2018 1 1 0 2018-01-01
#> 2 2018 1 2 0 2018-01-02
#> 3 2018 1 3 0 2018-01-03
#> 4 2018 1 4 25.4 2018-01-04
#> 5 2018 1 5 0 2018-01-05
#> 6 2018 1 6 0 2018-01-06
plot(from_gridmet$`pr(mm)`, gridMet$prcp)
plot(from_gridmet$date, from_gridmet$`pr(mm)`, type = "l")
lines(c(gridMet$date), c(gridMet$prcp), type = "l", col = "red")
Created on 2021-03-09 by the reprex package (v0.3.0)
A reasonable question is "well GridMet is right, PRISM must be off..." however I am confident the PRISM URLs are correct as they only contain a single time point per file and are specified by date. For example:
With a DDS of (note time = 1):
Dataset {
Float64 t[t = 1];
Grid {
ARRAY:
Float64 ppt[t = 1][latitude = 621][longitude = 1405];
MAPS:
Float64 t[t = 1];
Float64 latitude[latitude = 621];
Float64 longitude[longitude = 1405];
} ppt;
Grid {
ARRAY:
Float64 tmean[t = 1][latitude = 621][longitude = 1405];
MAPS:
Float64 t[t = 1];
Float64 latitude[latitude = 621];
Float64 longitude[longitude = 1405];
} tmean;
Grid {
ARRAY:
Float64 tmin[t = 1][latitude = 621][longitude = 1405];
MAPS:
Float64 t[t = 1];
Float64 latitude[latitude = 621];
Float64 longitude[longitude = 1405];
} tmin;
Grid {
ARRAY:
Float64 tmax[t = 1][latitude = 621][longitude = 1405];
MAPS:
Float64 t[t = 1];
Float64 latitude[latitude = 621];
Float64 longitude[longitude = 1405];
} tmax;
Float64 longitude[longitude = 1405];
Float64 latitude[latitude = 621];
} prism/daily/combo/2018/PRISM_combo_20180101.nc;
So, if there is an error/lag, it is in the raw data and not in the climateR extraction/formatting...
The date interval is off by one for some resources.