Skip to content

Commit

Permalink
Merge pull request #1953 from serbinsh/fix_fates_output_dates
Browse files Browse the repository at this point in the history
Updated FATES output time variable to fix issue #1939.
  • Loading branch information
Shawn P. Serbin authored Jun 1, 2018
2 parents 44a238e + 3d1f82b commit 65b3809
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ For more information about this file see also [Keep a Changelog](http://keepacha
## [Unreleased]

### Fixes
- Fixed issue #1939 which corrects output time vector for FATES output
- Update to read.output to look for and read only PEcAn formatted .nc output based on the pecan standard filename format of YYYY.nc. Solves issues with models such as FATES and dvm-dos-tem where the original model output is also in .nc file format and was not ignored by read.output, causing errors with output parsing and plotting with Shiny. Removed deprecated function convert.outputs
- PEcAn.data.atmosphere:
- download.Geostreams is pickier about formatting start/end datess, for fewer surprises in result timestamps
Expand Down
9 changes: 5 additions & 4 deletions models/fates/R/model2netcdf.FATES.R
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ model2netcdf.FATES <- function(outdir) {
files <- dir(outdir, "*clm2.h0.*.nc", full.names = TRUE)
file.dates <- as.Date(sub(".nc", "", sub(".*clm2.h0.", "", files)))
years <- lubridate::year(file.dates)
init_year <- unique(years)[1]

## Loop over years
for (year in unique(years)) {
Expand Down Expand Up @@ -84,11 +85,11 @@ model2netcdf.FATES <- function(outdir) {
sitelat <- ncdf4::ncvar_get(ncin,"lat")
sitelon <- ncdf4::ncvar_get(ncin,"lon")
## time variable based on internal calc, nc$dim$time is the FATES output time
t <- ncdim_def(name = "time", units = paste0("days since ", year, "-01-01 00:00:00"),
vals = as.vector(time), calendar = "standard",
t <- ncdf4::ncdim_def(name = "time", units = paste0("days since ", init_year, "-01-01 00:00:00"),
vals = as.vector(time), calendar = "noleap",
unlim = TRUE) # a direct analog of internal FATES output dim "time"
lat <- ncdim_def("lat", "degrees_north", vals = as.numeric(sitelat), longname = "coordinate_latitude")
lon <- ncdim_def("lon", "degrees_east", vals = as.numeric(sitelon), longname = "coordinate_longitude")
lat <- ncdf4::ncdim_def("lat", "degrees_north", vals = as.numeric(sitelat), longname = "coordinate_latitude")
lon <- ncdf4::ncdim_def("lon", "degrees_east", vals = as.numeric(sitelon), longname = "coordinate_longitude")
xyt <- list(lon, lat, t)

### build netCDF data
Expand Down

0 comments on commit 65b3809

Please sign in to comment.