Skip to content

Allow reductions with dims kwarg work for FieldTimeSeries #4385

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

navidcy
Copy link
Member

@navidcy navidcy commented Apr 11, 2025

At the moment, reductions of FieldTimeSeries work if we don't provide dims kwarg but seem to be broken when we provide dims.

I fixed a few obvious bugs. But I am a bit unsure how to proceed.

using Oceananigans

grid = RectilinearGrid(size=(2, 3, 4), extent=(1, 1, 1))
times = 0:0.1:3

sinf(t) = sin(2π * t / 3)

fts = FieldTimeSeries{Center, Center, Center}(grid, times; backend=OnDisk(), path="test.jld2", name="f")

f = CenterField(grid)
for (i, time) in enumerate(fts.times)
    set!(f, (x, y, z) -> sinf(time))
    set!(fts, f, i)
end

@info "mean(fts)"
@show mean(fts)

@info "mean(fts, dims=4)"
@show mean(fts, dims=4)
julia> include("mwe_fts.jl")
[ Info: mean(fts)
mean(fts) = -1.2676099885359938e-17
[ Info: mean(fts, dims=4)
ERROR: LoadError: MethodError: no method matching (FieldTimeSeries{})(::RectilinearGrid{…}, ::StepRangeLen{…}, ::Type{…}; indices::Tuple{…})

Closest candidates are:
  (FieldTimeSeries{LX, LY, LZ})(::D, ::G, ::K, ::B, ::I, ::Any, ::Any, ::Any, ::Any, ::Any) where {LX, LY, LZ, K, D, G, B, I} got unsupported keyword argument "indices"
   @ Oceananigans ~/Library/CloudStorage/OneDrive-TheUniversityofMelbourne/Documents/Research/Oceananigans.jl-v2/src/OutputReaders/field_time_series.jl:231
  (FieldTimeSeries{LX, LY, LZ})(::Oceananigans.Grids.AbstractGrid, ::Any; kwargs...) where {LX, LY, LZ}
   @ Oceananigans ~/Library/CloudStorage/OneDrive-TheUniversityofMelbourne/Documents/Research/Oceananigans.jl-v2/src/OutputReaders/field_time_series.jl:438
  (FieldTimeSeries{LX, LY, LZ})(::Oceananigans.Grids.AbstractGrid; ...) where {LX, LY, LZ}
   @ Oceananigans ~/Library/CloudStorage/OneDrive-TheUniversityofMelbourne/Documents/Research/Oceananigans.jl-v2/src/OutputReaders/field_time_series.jl:438

Stacktrace:
 [1] sum(f::Function, fts::FieldTimeSeries{…}; dims::Int64, kw::@Kwargs{})
   @ Oceananigans.OutputReaders ~/Library/CloudStorage/OneDrive-TheUniversityofMelbourne/Documents/Research/Oceananigans.jl-v2/src/OutputReaders/field_time_series_reductions.jl:36
 [2] sum(fts::FieldTimeSeries{…}; kw::@Kwargs{})
   @ Oceananigans.OutputReaders ~/Library/CloudStorage/OneDrive-TheUniversityofMelbourne/Documents/Research/Oceananigans.jl-v2/src/OutputReaders/field_time_series_reductions.jl:41
 [3] _mean(f::Function, c::FieldTimeSeries{…}, dims::Int64; condition::Nothing)
   @ Oceananigans.OutputReaders ~/Library/CloudStorage/OneDrive-TheUniversityofMelbourne/Documents/Research/Oceananigans.jl-v2/src/OutputReaders/field_time_series_reductions.jl:66
 [4] mean(c::FieldTimeSeries{…}; condition::Nothing, dims::Int64)
   @ Oceananigans.Fields ~/Library/CloudStorage/OneDrive-TheUniversityofMelbourne/Documents/Research/Oceananigans.jl-v2/src/Fields/field.jl:727
 [5] macro expansion
   @ show.jl:1181 [inlined]
 [6] top-level scope
   @ ~/Library/CloudStorage/OneDrive-TheUniversityofMelbourne/Documents/Research/Oceananigans.jl-v2/mwe_fts.jl:21
 [7] include(fname::String)
   @ Base.MainInclude ./client.jl:494
 [8] top-level scope
   @ REPL[151]:1
in expression starting at /Users/navid/Library/CloudStorage/OneDrive-TheUniversityofMelbourne/Documents/Research/Oceananigans.jl-v2/mwe_fts.jl:21
Some type information was truncated. Use `show(err)` to see complete types.

It's a bit tricky, in the sense if the reduction is over dims=4 then should it return a Field? or a FieldTimeSeries?

@navidcy navidcy requested a review from glwagner April 11, 2025 03:43
@navidcy
Copy link
Member Author

navidcy commented Apr 11, 2025

Of course, I'll add a test after we sort this out.

@navidcy
Copy link
Member Author

navidcy commented Apr 11, 2025

Actually even dims=1 doesn't work really. Probably that's the best place to start

loc = LX, LY, LZ = reduced_location(location(fts); dims)
times = fts.times
rts = FieldTimeSeries{LX, LY, LZ}(grid, times, T; indices=fts.indices)
rts = FieldTimeSeries{LX, LY, LZ}(fts.grid, times; kw...)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
rts = FieldTimeSeries{LX, LY, LZ}(fts.grid, times; kw...)
rts = FieldTimeSeries((LX, LY, LZ), fts.grid, times; indices=fts.indices, kw...)

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.

2 participants