Skip to content

Commit

Permalink
Simplify 2-stream increment function (#407)
Browse files Browse the repository at this point in the history
  • Loading branch information
sriharshakandala authored Dec 2, 2023
1 parent 2cf9a2e commit 40486d9
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 23 deletions.
2 changes: 1 addition & 1 deletion docs/src/optics/Optics.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,6 @@ compute_gray_optical_thickness_sw
interp1d
interp2d
interp3d
increment!
increment_2stream
delta_scale
```
6 changes: 4 additions & 2 deletions src/optics/CloudOptics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ function add_cloud_optics_2stream(op::TwoStream, as::AtmosphericState, lkp::Look
cld_mask = as.cld_mask_lw[glay, gcol]
if cld_mask
τ_cl, τ_cl_ssa, τ_cl_ssag = compute_cld_props(lkp_cld, as, cld_mask, glay, gcol, ibnd, igpt)
increment!(op, τ_cl, τ_cl_ssa, τ_cl_ssag, glay, gcol, igpt)
op.τ[glay, gcol], op.ssa[glay, gcol], op.g[glay, gcol] =
increment_2stream(op.τ[glay, gcol], op.ssa[glay, gcol], op.g[glay, gcol], τ_cl, τ_cl_ssa, τ_cl_ssag)
end
end
return nothing
Expand All @@ -44,7 +45,8 @@ function add_cloud_optics_2stream(op::TwoStream, as::AtmosphericState, lkp::Look
if cld_mask
τ_cl, τ_cl_ssa, τ_cl_ssag = compute_cld_props(lkp_cld, as, cld_mask, glay, gcol, ibnd, igpt)
τ_cl, τ_cl_ssa, τ_cl_ssag = delta_scale(τ_cl, τ_cl_ssa, τ_cl_ssag)
increment!(op, τ_cl, τ_cl_ssa, τ_cl_ssag, glay, gcol, igpt)
op.τ[glay, gcol], op.ssa[glay, gcol], op.g[glay, gcol] =
increment_2stream(op.τ[glay, gcol], op.ssa[glay, gcol], op.g[glay, gcol], τ_cl, τ_cl_ssa, τ_cl_ssag)
end
end
return nothing
Expand Down
27 changes: 7 additions & 20 deletions src/optics/OpticsUtils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -122,31 +122,18 @@ where,
)
end
"""
increment!(
op::TwoStream{FT},
τ2,
ssa2,
g2,
glay,
gcol,
igpt,
) where {FT<:AbstractFloat}
Increment TwoStream optical properties `op` for layer `glay`
and column `gcol` with optical thickness `τ2`, single scattering
albedo `ssa2` and symmetry parameter `g2`.
increment_2stream!(τ1::FT, ssa1::FT, g1::FT, τ2::FT, ssa2::FT, g2::FT) where {FT}
Increment TwoStream optical properties `τ1`, `ssa1` and `g1`
with `τ2`, `ssa2` and `g2`. Here `τ` is the optical thickness,
`ssa` is the single-scattering albedo, and `g` is the symmetry parameter.
"""
function increment!(op::TwoStream{FT}, τ2, ssa2, g2, glay, gcol, igpt) where {FT <: AbstractFloat}
τ1, ssa1, g1 = op.τ[glay, gcol], op.ssa[glay, gcol], op.g[glay, gcol]
function increment_2stream(τ1::FT, ssa1::FT, g1::FT, τ2::FT, ssa2::FT, g2::FT) where {FT}
τ = τ1 + τ2
ssa = τ1 * ssa1 + τ2 * ssa2
ssag = (τ1 * ssa1 * g1 + τ2 * ssa2 * g2) / max(eps(FT), ssa)
ssa /= max(eps(FT), τ)

op.τ[glay, gcol] = τ
op.ssa[glay, gcol] = ssa
op.g[glay, gcol] = ssag
return nothing
return τ, ssa, ssag
end
"""
delta_scale(τ, ssa, g)
Expand Down

0 comments on commit 40486d9

Please sign in to comment.