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

updated modules/data.atmosphere #2775

Merged
merged 30 commits into from May 24, 2021
Merged

updated modules/data.atmosphere #2775

merged 30 commits into from May 24, 2021

Conversation

moki1202
Copy link
Collaborator

fixed tidyverse notes for the remaining variables.

fixed tidyverse notes for the remaining variables in check_met_input.R for variables " is_required, cf_standard_name, test_passed, test_raw ".
fixed tidyverse notes for the remaining variables in download.NARR_site.R for variables " CF_name, year, data, month , startdate, hours ".
fixed tidyverse notes for the remaining variables "doy, rpot, avg.rpot, days" .
fixed tidyverse notes for the remaining variables " .attrs, canonical_units, description ".
deleted (relevant) lines starting <function name>: no visible binding for global variable <variable>.
Copy link
Member

@infotroph infotroph left a comment

Choose a reason for hiding this comment

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

Most the suggested changes here are places I saw names in the data that reuse names defined elsewhere, and are therefore not showing up in the check warnings -- adding .data to these shouldn't change the code behavior, but disambiguating them should make it a lot easier to read the code!

Since most of these changes are additional edits rather than corrections, tagging @ashiklom to review them as the person most likely to know if I mangled a global that should stay global.

@@ -43,14 +43,14 @@ download.NARR_site <- function(outfolder,
date_limits_chr <- strftime(range(narr_data$datetime), "%Y-%m-%d %H:%M:%S", tz = "UTC")

narr_byyear <- narr_data %>%
dplyr::mutate(year = lubridate::year(datetime)) %>%
dplyr::group_by(year) %>%
dplyr::mutate(year = lubridate::.data$year(datetime)) %>%
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
dplyr::mutate(year = lubridate::.data$year(datetime)) %>%
dplyr::mutate(year = lubridate::year(datetime)) %>%

@@ -73,10 +73,10 @@ download.NARR_site <- function(outfolder,

narr_proc <- result_full %>%
dplyr::mutate(
data_nc = purrr::map2(data, file, prepare_narr_year, lat = lat, lon = lon)
data_nc = purrr::map2(.data$data, file, prepare_narr_year, lat = lat, lon = lon)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
data_nc = purrr::map2(.data$data, file, prepare_narr_year, lat = lat, lon = lon)
data_nc = purrr::map2(.data$data, .data$file, prepare_narr_year, lat = lat, lon = lon)

Copy link
Member

Choose a reason for hiding this comment

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

Hmm. @ashiklom is narr_proc needed at all? I don't see it used anywhere between here and the end of the function.

@@ -225,7 +225,7 @@ get_NARR_thredds <- function(start_date, end_date, lat.in, lon.in,
PEcAn.logger::logger.info("Downloading in parallel")
flx_df$flx <- TRUE
sfc_df$flx <- FALSE
get_dfs <- dplyr::bind_rows(flx_df, sfc_df)
get_dfs <- dplyr::bind_rows(.data$flx_df, sfc_df)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
get_dfs <- dplyr::bind_rows(.data$flx_df, sfc_df)
get_dfs <- dplyr::bind_rows(flx_df, sfc_df)

Needed because (1) we want the flx_df defined on line 207, and (2) the arguments to bind_rows need to be whole dataframes rather than single columns.

@@ -296,19 +296,19 @@ post_process <- function(dat) {
dat %>%
tidyr::unnest(data) %>%
dplyr::ungroup() %>%
dplyr::mutate(datetime = startdate + lubridate::dhours(dhours)) %>%
dplyr::select(-startdate, -dhours) %>%
dplyr::mutate(datetime = .data$startdate + lubridate::.data$dhours(.data$dhours)) %>%
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
dplyr::mutate(datetime = .data$startdate + lubridate::.data$dhours(.data$dhours)) %>%
dplyr::mutate(datetime = .data$startdate + lubridate::dhours(.data$dhours)) %>%

Comment on lines 325 to 327
year = lubridate::.data$year(date),
month = lubridate::.data$month(date),
daygroup = daygroup(date, .data$flx)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
year = lubridate::.data$year(date),
month = lubridate::.data$month(date),
daygroup = daygroup(date, .data$flx)
year = lubridate::.year(.data$date),
month = lubridate::month(.data$date),
daygroup = daygroup(.data$date, .data$flx)

unique(year),
unique(month),
unique(.data$year),
unique(.data$month),
unique(daygroup)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
unique(daygroup)
unique(.data$daygroup)

unique(daygroup)
)
) %>%
dplyr::ungroup() %>%
dplyr::select(startdate, url)
dplyr::select(.data$startdate, url)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
dplyr::select(.data$startdate, url)
dplyr::select(.data$startdate, .data$url)

@@ -382,12 +382,12 @@ get_narr_url <- function(url, xy, flx, pb = NULL) {
if (dhours[1] == 3) dhours <- dhours - 3
narr_vars <- if (flx) narr_flx_vars else narr_sfc_vars
result <- purrr::pmap(
narr_vars %>% dplyr::select(variable = NARR_name, unit = units),
narr_vars %>% dplyr::select(variable = .data$NARR_name, unit = units),
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
narr_vars %>% dplyr::select(variable = .data$NARR_name, unit = units),
narr_vars %>% dplyr::select(variable = .data$NARR_name, unit = .data$units),

read_narr_var,
nc = nc, xy = xy, flx = flx, pb = pb
)
names(result) <- narr_vars$CF_name
dplyr::bind_cols(dhours = dhours, result)
dplyr::bind_cols(dhours = .data$dhours, result)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
dplyr::bind_cols(dhours = .data$dhours, result)
dplyr::bind_cols(dhours = dhours, result)

dplyr::mutate(hour = lubridate::hour(.data$time)) %>%
dplyr::mutate(doy = lubridate::yday(.data$time) + hour/(24/hr))%>%
dplyr::mutate(rpot = downscale_solar_geom(doy, as.vector(lon), as.vector(lat))) %>% # hourly sw flux calculated using solar geometry
dplyr::mutate(hour = lubridate::.data$hour(.data$time)) %>%
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
dplyr::mutate(hour = lubridate::.data$hour(.data$time)) %>%
dplyr::mutate(hour = lubridate::hour(.data$time)) %>%

fixed the mistakes that were mentioned.
removed ' .data' pronoun from hour() function in line 83 .
@infotroph
Copy link
Member

/document

mostly to trigger a CI run
Copy link
Member

@infotroph infotroph left a comment

Choose a reason for hiding this comment

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

A few more reported by the CI checks.

@@ -86,8 +86,8 @@ download.NARR_site <- function(outfolder,
#' @param file Full path to target file
#' @param lat_nc `ncdim` object for latitude
#' @param lon_nc `ncdim` object for longitude
#' @param verbose
#' @return List of NetCDF variables in data. Creates NetCDF file containing
#' @param verbose
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
#' @param verbose
#' @param verbose logical: ask`ncdf4` functions to be very chatty while they work?

Documenting arguments is always good, but the reason we need this now is kind of 🙄: With the trailing space included, Roxygen was previousy complaining about "argument items with no description" and we ignored it in Rcheck_reference.log. Without the trailing space, Roxygen complains instead about "undocumented arguments" and causes a CI failure because the ignore-preexisting-errors script only knows how to skip exact test matches.

After fixing this we should delete the "with no description" from Rcheck_reference.log (currently lines 420-421).

Comment on lines 95 to 96
test_passed = !purrr::map_lgl(test_raw, inherits, "try-error"),
test_error_message = purrr::map_chr(test_raw, purrr::possibly(as.character, NA_character_))
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
test_passed = !purrr::map_lgl(test_raw, inherits, "try-error"),
test_error_message = purrr::map_chr(test_raw, purrr::possibly(as.character, NA_character_))
test_passed = !purrr::map_lgl(.data$test_raw, inherits, "try-error"),
test_error_message = purrr::map_chr(.data$test_raw, purrr::possibly(as.character, NA_character_))

TIL you can reuse previously defined columns inside a tibble definition! I had assumed this kind of transformation would need to be written df <- tibble::tibble(col_a = ...) %>% mutate(col_b = f(col_a, ...),...)

Copy link
Member

Choose a reason for hiding this comment

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

Yup! IIRC, this is one of the key differences between tibble::tibble and data.frame -- it will not work in the latter.

@@ -296,19 +296,19 @@ post_process <- function(dat) {
dat %>%
tidyr::unnest(data) %>%
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
tidyr::unnest(data) %>%
tidyr::unnest(.data$data) %>%

Copy link
Member

@ashiklom ashiklom left a comment

Choose a reason for hiding this comment

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

I think this looks good (after @infotroph 's suggestions)!

@infotroph
Copy link
Member

/document

@moki1202
Copy link
Collaborator Author

@ashiklom @infotroph can you guys suggest to me the next issue I should start working on?

@moki1202
Copy link
Collaborator Author

moki1202 commented Mar 9, 2021

@infotroph is there any other changes required here?

@infotroph
Copy link
Member

@moki1202 Sorry for the delay here. The test failure in https://github.com/PecanProject/pecan/runs/2056814058#step:9:1353 ("column flx not found in .data") probably means I was wrong about at least one of the .data additions I suggested, but at a glance it sure looks like flx ought to be a column.

The next step is probably to run the tests locally and step through to verify what columns are actually present in the data at that step.

@infotroph
Copy link
Member

@moki1202 Clarification: If you see how to fix the issue without stepping through the tests, go for it! That's just the next thing I'd do.

@moki1202
Copy link
Collaborator Author

moki1202 commented Mar 9, 2021

@infotroph gave it a thorough check in the file download.NARR_site.R and didn't find any line where ' fix ' variable was not properly called using the ' .data$ ' pronoun....although, I did find out that I actually missed deleting the respective line regarding global variable error for ' flx ' variable in the Rcheck_reference.R . could this be a problem?

@moki1202
Copy link
Collaborator Author

@infotroph @ashiklom does this PR need any further work?

@infotroph
Copy link
Member

@moki1202 Nope, we're just waiting for the build to turn green. The current failures are "unable to verify current time", which is apparently caused by R itself trying to consult a flaky third-party API. So definitely not your problem!

@mdietze mdietze merged commit 52bb318 into PecanProject:develop May 24, 2021
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.

None yet

4 participants