Skip to content

Commit

Permalink
change NaN replacement
Browse files Browse the repository at this point in the history
  • Loading branch information
juliasloan25 committed Jun 25, 2024
1 parent 4faf23b commit 19a90c5
Showing 1 changed file with 19 additions and 23 deletions.
42 changes: 19 additions & 23 deletions src/FluxCalculator.jl
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ function partitioned_turbulent_fluxes!(
inputs = FluxCalculator.surface_inputs(surface_scheme, input_args)

# calculate the surface fluxes
fluxes = @. FluxCalculator.get_surface_fluxes!(inputs, surface_params)
fluxes = FluxCalculator.get_surface_fluxes!(inputs, surface_params)
(; F_turb_ρτxz, F_turb_ρτyz, F_shf, F_lhf, F_turb_moisture) = fluxes

# perform additional diagnostics if required
Expand Down Expand Up @@ -346,7 +346,7 @@ Uses SurfaceFluxes.jl to calculate turbulent surface fluxes. It should be atmos
"""
function get_surface_fluxes!(inputs, surface_params::SF.Parameters.SurfaceFluxesParameters)
# calculate all fluxes (saturated surface conditions)
outputs = SF.surface_conditions(surface_params, inputs)
outputs = SF.surface_conditions.(surface_params, inputs)

# drag
F_turb_ρτxz = outputs.ρτxz
Expand All @@ -357,27 +357,23 @@ function get_surface_fluxes!(inputs, surface_params::SF.Parameters.SurfaceFluxes
F_lhf = outputs.lhf

# moisture
F_turb_moisture = SF.evaporation(surface_params, inputs, outputs.Ch)

if !isnan(F_turb_ρτxz) && !isnan(F_turb_ρτyz) && !isnan(F_shf) && !isnan(F_lhf) && !isnan(F_turb_moisture)
return (;
F_turb_ρτxz = F_turb_ρτxz,
F_turb_ρτyz = F_turb_ρτyz,
F_shf = F_shf,
F_lhf = F_lhf,
F_turb_moisture = F_turb_moisture,
)
else
return (;
F_turb_ρτxz = zero(F_turb_ρτxz),
F_turb_ρτyz = zero(F_turb_ρτyz),
F_shf = zero(F_shf),
F_lhf = zero(F_lhf),
F_turb_moisture = zero(F_turb_moisture),
)
end


F_turb_moisture = SF.evaporation.(surface_params, inputs, outputs.Ch)

# At locations where this surface model is not evaluated, we get `NaN` for
# surface fluxes. In that case, we replace the values with 0.
@. F_turb_ρτxz = ifelse(isnan(F_turb_ρτxz), zero(F_turb_ρτxz), F_turb_ρτxz)
@. F_turb_ρτyz = ifelse(isnan(F_turb_ρτyz), zero(F_turb_ρτyz), F_turb_ρτyz)
@. F_shf = ifelse(isnan(F_shf), zero(F_shf), F_shf)
@. F_lhf = ifelse(isnan(F_lhf), zero(F_lhf), F_lhf)
@. F_turb_moisture = ifelse(isnan(F_turb_moisture), zero(F_turb_moisture), F_turb_moisture)

return (;
F_turb_ρτxz = F_turb_ρτxz,
F_turb_ρτyz = F_turb_ρτyz,
F_shf = F_shf,
F_lhf = F_lhf,
F_turb_moisture = F_turb_moisture,
)
end

"""
Expand Down

0 comments on commit 19a90c5

Please sign in to comment.