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

Provide reference dates in download.CRUNCEP output #1357

Merged
merged 9 commits into from
Apr 18, 2017

Conversation

infotroph
Copy link
Member

Description

Ensures output times have CF-compliant units (#1347).

Also some code cleanup while I'm at it:

  • Add missing parameter descriptions
  • Respect overwrite parameter (previously ignored)

For discussion

The test I give here is slow! It downloads a full year of CRUNCEP data to do one check (so far) on the output. Is this a problem? If so, should the download be mocked out, or the test skipped in some environments?

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My change requires a change to the documentation.
  • I have updated the CHANGELOG.md.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

Copy link
Member

@dlebauer dlebauer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me but will defer to authors @jsimkins2 or @mdietze for review / approval

time <- ncdf4::ncdim_def(name = "time", units = "sec", vals = (1:ntime) * 21600,
create_dimvar = TRUE, unlim = TRUE)

timestamps <- (1:ntime) * 6/24 - 3/24 # data are 6-hourly, with timestamp at center of interval
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So are you keeping the timestamp? Shifting time? What are time stamps of input and output data?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're keeping the timestamp. Or more precisely, we're generating a completely new time series here, then on reading each variable in the loop below we check that input times have the same values after converting to our output units.

Input timestamps of CRUNCEP nc files appear to always have units "days since 1700-01-01T00:00:00Z", so a file starting 2004-01-01 looks like 111033.1 111033.4 111033.6 111033.9 111034.1 .... Output timestamps are days since start_date, so the times always look like 0.125 0.375 0.625 0.875 1.125 ....

stopifnot(dap$dim$time$len == ntime)
dap_time <- udunits2::ud.convert(dap$dim$time$vals,
dap$dim$time$units,
paste0("days since ", start_year, "-01-01"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome that is.units can parse this

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right? I should avoid ambiguity and add "00:00:00Z" to the output units, though.

@dlebauer dlebauer requested review from mdietze and jsimkins2 April 18, 2017 04:51
@infotroph infotroph changed the title Retain reference dates in download.CRUNCEP Provide reference dates in download.CRUNCEP output Apr 18, 2017
@@ -79,6 +99,14 @@ download.CRUNCEP <- function(outfolder, start_date, end_date, site_id, lat.in, l
# This throws an error if file not found
dap <- ncdf4::nc_open(dap_file)

# confirm that timestamps match
stopifnot(dap$dim$time$len == ntime)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would prefer if you use PEcAn's logger functions so that we can ensure that this stop is properly caught and written out to the log file.

@mdietze
Copy link
Member

mdietze commented Apr 18, 2017

Note that setting up a test that depends on downloading from CRUNCEP will occasionally cause the build to fail when the code is fine if the connection to CRUNCEP is lost.

@mdietze mdietze merged commit 18503b6 into PecanProject:develop Apr 18, 2017
@infotroph infotroph deleted the cruncep-refdates branch April 18, 2017 16:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants