-
Notifications
You must be signed in to change notification settings - Fork 235
Fix some FieldTimeSeries
indexing bugs
#4505
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
base: main
Are you sure you want to change the base?
Conversation
Improves element-wise comparison, which returned False for values near zero due to relative error default.
Modifies `find_time_index` to take an extra timescale parameter `dt`, so that an absolute error can be computed to avoid `isapprox` returning `false` for values near zero
|
||
|
||
# Compute a timescale for comparisons | ||
dt = mean(file_times[2:end] - file_times[1:end-1]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dt = mean(file_times[2:end] - file_times[1:end-1]) | |
timescale = mean(diff(file_times)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, it's really the time increment between time points, so I think Δt
is more appropriate. Just suggest using the Δ
not dt
for readability
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or mean_Δt
# Compute a timescale for comparisons | ||
dt = mean(file_times[2:end] - file_times[1:end-1]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why don't we compute this within find_time_index
? just a thought...
or something like:
function find_time_index(time::Number, file_times; time_scale = mean(diff(file_times)))
ϵ = 100 * eps(eltype(file_times))
return findfirst(t -> isapprox(t, time, atol=ϵ*time_scale), file_times)
end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, I guess pre-computing it avoids recalculation at every iteration of the for loop it's used in? But if that's not an issue it would be simpler to compute within the function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Precomputing serves two purposes: 1) we don't recompute, which could become important for very long time series, and 2) as a point of design, this allows us to change the estimate of the characteristic time increment later. Right now we use the mean of all time increments, but this is not the only choice one might make.
@loisbaker should we add tests at all? Ok if that's a todo for the future, but tests will ensure these changes are lasting |
Co-authored-by: Gregory L. Wagner <[email protected]>
Sure, I can work on that - a test to check that |
Perhaps just a simple test that resembles the case you presented that illustrated the bug would work (the more fine-grained tests can be nice too, but I don't think necessary in this case and they are more work). We can also do in a future PR, since I think this is otherwise read to merge -- your call! |
Great, I'll put this on the to-do list for a future PR! |
This PR fixes some small indexing bugs for
FieldTimeSeries
described in #4100Oceananigans.jl/src/OutputReaders/field_time_series.jl
Line 252 in d1e9b46
Oceananigans.jl/src/OutputReaders/set_field_time_series.jl
Line 10 in d1e9b46
≈
is replaced with a comparison using a vector norm in the first case, and using an absolute tolerance based on a characteristic timescale in the second case. This avoids returningfalse
due to the default relative error criterion when comparing values close to zero.Oceananigans.jl/src/OutputReaders/set_field_time_series.jl
Line 25 in d1e9b46
fts.times
is aCuArray
.