Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add version fix for MERRA data download #2888

Merged
merged 6 commits into from
Mar 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ We are slowly change the license from NCSA opensource to BSD-3 to help with publ

- Using R4.0 and R4.1 tags to build PEcAn. Default is now 4.1
- Database connections consistently use `DBI::dbConnect` instead of the deprecated `dplyr::src_postgres` (#2881). This change should be invisible to most users, but it involved converting a lot of internal variables from `bety$con` to `con`. If you see errors involving these symbols it means we missed a place, so please report them as bugs.
- Update URL for MERRA downloads (#2888)
- PEcAn.logger is now BSD-3 License
- Skipped ICOS and MERRA download tests when running in github actions

Expand Down
6 changes: 4 additions & 2 deletions modules/data.atmosphere/R/download.MERRA.R
Original file line number Diff line number Diff line change
Expand Up @@ -139,14 +139,14 @@ download.MERRA <- function(outfolder, start_date, end_date,
ncdf4::ncvar_put(loc, merra_flux_vars[r,][["CF_name"]], x,
start = c(1, 1, start), count = c(1, 1, 24))
}
ncdf4::nc_close(nc)
lfofile <- file.path(outfolder, sprintf("merra-lfo-%s.nc", as.character(date)))
nc <- ncdf4::nc_open(lfofile)
for (r in seq_len(nrow(merra_lfo_vars))) {
x <- ncdf4::ncvar_get(nc, merra_lfo_vars[r,][["MERRA_name"]])
ncdf4::ncvar_put(loc, merra_lfo_vars[r,][["CF_name"]], x,
start = c(1, 1, start), count = c(1, 1, 24))
}

ncdf4::nc_close(nc)
}

Expand Down Expand Up @@ -176,7 +176,9 @@ get_merra_date <- function(date, latitude, longitude, outdir, overwrite = FALSE)
month <- as.numeric(gsub(dpat, "\\2", date))
day <- as.numeric(gsub(dpat, "\\3", date))
dir.create(outdir, showWarnings = FALSE, recursive = TRUE)
version <- if (year >= 2011) {
version <- if (year == 2020 & month == 9) {
401
} else if (year >= 2011) {
400
} else if (year >= 2001) {
300
Expand Down