fix(align.met): use length(stamps.hr) instead of stamps.hr as the rep() each argument#4012
Open
anshul23102 wants to merge 1 commit into
Open
Conversation
…ach argument
In the ensemble-source code path of align.met(), when the source data is
at a coarser time step than the training data (align == "repeat"), the
call was:
rep(dat.tem, each = stamps.hr)
`stamps.hr` is a numeric vector of hour-of-day time stamps, not a scalar
count. R's rep() silently uses only the first element of a vector passed
to `each`, so the replication count was stamps.hr[1] = hr.train / 2,
a floating-point number that gets truncated to an integer, yielding
completely wrong output dimensions and corrupted met data.
The equivalent code in the single-time-series branch (same function,
earlier) correctly writes:
rep(dat.tem, each = length(stamps.hr))
This one-character fix aligns the ensemble path with the single-series
path and produces the correct number of output rows per source time step.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
In the ensemble-source branch of
align.met(), when the source dataset is at a coarser time step than the training data (align == "repeat"), source values must be repeated to match the finer training resolution. The original code was:stamps.hris a numeric vector of hour-of-day time stamps (e.g.c(1, 3, 5, ...)for 2-hourly data). Passing a vector torep()'seachargument is silent in R -- the function uses only the first element and ignores the rest. The first element ishr.train / 2, a floating-point number that gets truncated to an integer, so the replication count is wrong.The correct scalar to pass is
length(stamps.hr)-- the number of output sub-steps that each coarser source value should fill. The equivalent code in the single-time-series branch of the same function (a few hundred lines earlier) already does this correctly:The ensemble-source path was missing the
length()call, producing silently corrupted met data with the wrong number of rows any time ensemble source data at a coarser temporal resolution was aligned with higher-resolution training data.Change
modules/data.atmosphere/R/align_met.Rline 431:each = stamps.hr->each = length(stamps.hr).modules/data.atmosphere/NEWS.md: added entry for the development version.Test plan
align.met()with ensemble source data at daily resolution and training data at sub-daily resolution (e.g. 3-hourly); confirm the number of rows inmet.out$dat.sourcematches the training data time dimension.R CMD checkonPEcAn.data.atmospherepasses without new warnings or errors.