-
Notifications
You must be signed in to change notification settings - Fork 10
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
Merge NeuralSnow module into main #946
base: main
Are you sure you want to change the base?
Conversation
e6c9746
to
d867a7a
Compare
4f62e77
to
6b9eb71
Compare
4be4bcc
to
adbc045
Compare
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.
thanks for your hard work on this! You can merge once the doc comments are addressed. 🎉
@@ -42,6 +42,23 @@ and is used as a bulk snow model. | |||
""" | |||
abstract type AbstractSnowModel{FT} <: ClimaLand.AbstractExpModel{FT} end | |||
|
|||
""" | |||
AbstractDensityModel{FT} | |||
Defines the model type for density and depth parameterizations |
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.
Defines the model type for density and depth parameterizations | |
Defines the model type for density and depth parameterizations | |
for use within an `AbstractSnowModel` type. Current examples include the | |
`ConstantDensityModel` models. | |
Since depth and bulk density are related via SWE, and SWE is a prognostic variable | |
of the snow model, only depth or density can be independently modeled at one time. | |
This is why they are treated as a single "density model" even if the parameterization is actually | |
a model for snow depth. | |
The snow depth/density model can be diagnostic or introduce additional prognostic variables. |
prognostic_vars(::SnowModel) = (:S, :U) | ||
prognostic_vars(m::SnowModel) = | ||
(:S, :U, density_prog_vars(m.parameters.density)...) | ||
density_prog_vars(::AbstractDensityModel) = () |
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.
density_prog_vars(::AbstractDensityModel) = () | |
""" | |
density_prog_vars(::AbstractDensityModel) | |
A default method for adding prognostic variables to the snow model as required | |
by the density model choice. | |
""" | |
density_prog_vars(::AbstractDensityModel) = () |
@@ -272,8 +299,15 @@ function ClimaLand.make_update_aux(model::SnowModel{FT}) where {FT} | |||
|
|||
@. p.snow.T_sfc = snow_surface_temperature(p.snow.T) | |||
|
|||
@. p.snow.water_runoff = | |||
compute_water_runoff(Y.snow.S, p.snow.q_l, p.snow.T, parameters) | |||
p.snow.water_runoff .= |
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.
p.snow.water_runoff .= | |
# Note that the `snow_depth` call below allocates a field. Return to this in the future. | |
p.snow.water_runoff .= |
@@ -253,7 +253,7 @@ function update_soil_snow_ground_heat_flux!( | |||
κ_soil = ClimaLand.Domains.top_center_to_surface(p.soil.κ) | |||
|
|||
# Depth of snow and soil layers interacting thermally at interface | |||
Δz_snow = p.snow.z # Snow depth | |||
Δz_snow = Snow.snow_depth(snow_params.density, Y, p, snow_params) # Snow depth |
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.
Δz_snow = Snow.snow_depth(snow_params.density, Y, p, snow_params) # Snow depth | |
# Note that the `snow_depth` call below allocates a field. Return to this in the future. | |
Δz_snow = Snow.snow_depth(snow_params.density, Y, p, snow_params) # Snow depth | |
is calculated from a neural network determining the rate of change of snow depth, dzdt. | ||
""" | ||
struct NeuralDepthModel{FT} <: AbstractDensityModel{FT} | ||
z_model::Flux.Chain |
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.
z_model::Flux.Chain | |
" The Flux neural network for compute dz/dt" | |
z_model::Flux.Chain |
""" | ||
struct NeuralDepthModel{FT} <: AbstractDensityModel{FT} | ||
z_model::Flux.Chain | ||
α::FT |
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.
α::FT | |
"The inverse of the averaging window time (1/s)" | |
α::FT |
|
||
""" | ||
get_znetwork() | ||
Return the snow-depth neural network from the paper. |
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.
Return the snow-depth neural network from the paper. | |
Return the snow-depth neural network from Charbonneau et al (2024; https://arxiv.org/abs/2412.06819), and sets the timescale [@a-charbon explain what this timescale is] | |
Note that because we are loading a pre-trained model, the number of features input, the size of the output, etc, are hard coded in the function below. |
|
||
""" | ||
NeuralDepthModel{FT <: AbstractFloat} <: AbstractDensityModel{FT} | ||
Establishes the density parameterization where snow density |
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.
Establishes the density parameterization where snow density | |
Establishes the density parameterization where snow density is calculated from a prognostic snow depth variable, | |
along with the prognostic SWE variable, using a neural network for the rate of change of snow depth, dz/dt. | |
The input to the network are temporally averaged, which we achieve using an exponentially moving average, with a rate of `\alpha`. Therefore, to achieve approximately daily averages, use `\alpha = 1/86400 s^{-1}`. |
|
||
""" | ||
NeuralDepthModel(FT::DataType; Δt::Union{Nothing, FT}=nothing; model::Flux.Chain, α::Union{FT, Nothing}) | ||
An outer constructor for the `NeuralDepthModel` density parameterization for usage in a snow model. |
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.
"An outer constructor for the NeuralDepthModel
density parameterization for usage in a snow model.
By default, the neural network weights trained in Charbonneau et al 2015 are used, but one can also supply their own model by keyword argument. Since the neural network models are trained using temporally averaged input, we also must supply information about how to compute these averaged inputs [using an exponential-weighting scheme]. By default, an averaging window of 43200 seconds is used. "
Is Delta t really optional? I thought the lower constraint was baked into the model.
Can you explain the instability better?
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.
oh, Delta t not used anymore maybe?
p, | ||
) | ||
|
||
dY.snow.Z .= |
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.
Maybe we can comment that dzdt(density,Y) allocates a field here as a reminder
Purpose
To-do
Content