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

Add Basin / subgrid_time table #1975

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

Add Basin / subgrid_time table #1975

wants to merge 10 commits into from

Conversation

visr
Copy link
Member

@visr visr commented Dec 13, 2024

Fixes #1010

This adds Basin / subgrid_time. So far the only relation we could update over time was Q(h) (TabulatedRatingCurve / time), and that is implemented differently. I wrote #1976 to get those more in line. It's good to read that since it explains the implementation here.

Things I dislike:

  • Need a special case to allow an underscore in Basin / subgrid_time, just like Basin / concentration_.
  • Other dynamic tables are just named time and have a static counterpart like Basin / static, Basin / time. Since we already have Basin / subgrid we cannot do that.

@visr visr marked this pull request as ready for review December 16, 2024 15:25
Copy link
Member

@evetion evetion left a comment

Choose a reason for hiding this comment

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

Can you document the construction of the new interpolation objects? That inner loop is opaque to me (with complexted indexlookups etc).

subgrid_id::Vector{Int32}
basin_index::Vector{Int32}
interpolations::Vector{ScalarInterpolation}
# level of each subgrid (static and dynamic) ordered by subgrid_id
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
# level of each subgrid (static and dynamic) ordered by subgrid_id
# current level of each subgrid (static and dynamic) ordered by subgrid_id

level::Vector{Float64}
# static
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
# static
# Static part
# Static subgrid ids

level_index_static::Vector{Int}
# per subgrid one relation
interpolations_static::Vector{ScalarInterpolation}
# dynamic
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
# dynamic
# Dynamic part
# Dynamic subgrid ids

core/src/read.jl Show resolved Hide resolved
subgrid_id = repeat(subgrid.subgrid_id; outer = ntsteps)
subgrid_id = repeat(
sort(vcat(subgrid.subgrid_id_static, subgrid.subgrid_id_time));
outer = ntsteps,
Copy link
Member

Choose a reason for hiding this comment

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

Does time already account for the multiple possible timestates (i.e. duplicates already exist)?

function static_and_time_node_ids(
db::DB,
static::StructVector,
time::StructVector,
node_type::String,
node_type::String;
is_complete::Bool = true,
Copy link
Member

Choose a reason for hiding this comment

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

This is undocumented (and unclear to me). I get that there's a state before/after, but not what the difference(s) are.

Copy link
Member Author

Choose a reason for hiding this comment

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

I mentioned it at the callsite, but also added docs here.

subgrid_id = first(getproperty.(group, :subgrid_id))
node_id = NodeID(NodeType.Basin, first(getproperty.(group, :node_id)), db)
node_id = first(getproperty.(group, :node_id))
Copy link
Member

Choose a reason for hiding this comment

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

Why do we away with NodeID here?

Copy link
Member Author

Choose a reason for hiding this comment

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

It simplified the code, otherwise we needed to strip out the integers later on.

has_error && error("Invalid Basin / subgrid_time table.")
level = fill(NaN, length(subgrid_id_static) + length(subgrid_id_time))

# Find the level indices
Copy link
Member

Choose a reason for hiding this comment

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

This static part can be moved up?

core/src/read.jl Outdated Show resolved Hide resolved
core/src/read.jl Outdated
cache_parameters = true,
)
# # These should only be pushed when the subgrid_id has changed
if subgrid_id_time[end] != subgrid_id
Copy link
Member

Choose a reason for hiding this comment

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

Hmmm, not sure if I get it, but if we group by subgrid_id, this will always be true?

@@ -114,6 +115,10 @@ const ScalarInterpolation = LinearInterpolation{
(1,),
}

"ConstantInterpolation from a Float64 to an Int, used to look up indices"
Copy link
Member Author

Choose a reason for hiding this comment

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

Suggested change
"ConstantInterpolation from a Float64 to an Int, used to look up indices"
"ConstantInterpolation from a Float64 to an Int, used to look up indices over time"

@@ -187,11 +187,18 @@ function parse_static_and_time(
return out, !errors
end

"""
Validate the split of node IDs between static and time tables.
Copy link
Member Author

Choose a reason for hiding this comment

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

Suggested change
Validate the split of node IDs between static and time tables.
Retrieve and validate the split of node IDs between static and time tables.

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.

Time dependent subgrid
2 participants