Skip to content

Commit f677df5

Browse files
authored
Merge pull request #156 from OceanBioME/jsw/fix-shows
Fixed some `show` methods
2 parents 37530fc + 1658ddf commit f677df5

File tree

8 files changed

+37
-39
lines changed

8 files changed

+37
-39
lines changed

Project.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ StructArrays = "09ab397b-f2b6-538f-b94a-2f83cf4a842a"
1313

1414
[compat]
1515
Adapt = "3"
16-
Documenter = "0.27"
16+
Documenter = "1"
1717
JLD2 = "0.4"
1818
KernelAbstractions = "0.9"
1919
Oceananigans = "0.84.1, 0.85 - 0.89"

docs/make.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ model_parameters = (LOBSTER(; grid = BoxModelGrid()),
5959
GasExchange(; gas = :CO₂).condition.func,
6060
GasExchange(; gas = :O₂).condition.func)
6161

62-
gas_exchange_gas(::Val{G}) where G = G
62+
exchanged_gas(::Val{G}) where G = G
6363

6464
model_name(model) = if Base.typename(typeof(model)).wrapper == GasExchange
65-
"$(gas_exchange_gas(model.gas)) air-sea exchange"
65+
"$(exchanged_gas(model.gas)) air-sea exchange"
6666
else
6767
Base.typename(typeof(model)).wrapper
6868
end

docs/src/model_components/biogeochemical/LOBSTER.md

+2-8
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,11 @@ julia> using OceanBioME, Oceananigans
1212
julia> grid = RectilinearGrid(size=(3, 3, 30), extent=(10, 10, 200));
1313
1414
julia> bgc_model = LOBSTER(; grid, carbonates = true)
15-
Lodyc-DAMTP Ocean Biogeochemical Simulation Tools for Ecosystem and Resources (LOBSTER) model (Float64)
16-
Optional components:
17-
├── Carbonates ✅
18-
├── Oxygen ❌
19-
└── Variable Redfield Ratio ❌
20-
Sinking Velocities:
21-
├── sPOM: 0.0 to -3.47e-5 m/s
22-
└── bPOM: 0.0 to -0.0023148148148148147 m/s
15+
LOBSTER{Float64} with carbonates ✅, oxygen ❌, variable Redfield ratio ❌and (:sPOM, :bPOM) sinking
2316
Light attenuation: Two-band light attenuation model (Float64)
2417
Sediment: Nothing
2518
Particles: Nothing
19+
Modifiers: Nothing
2620
```
2721

2822
## Model equations

src/Light/2band.jl

+1-2
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,7 @@ function TwoBandPhotosyntheticallyActiveRadiation(; grid,
105105

106106
field = CenterField(grid; boundary_conditions =
107107
regularize_field_boundary_conditions(
108-
FieldBoundaryConditions(top = ValueBoundaryCondition(surface_PAR)),
109-
grid, :PAR))
108+
FieldBoundaryConditions(top = ValueBoundaryCondition(surface_PAR)), grid, :PAR))
110109

111110
return TwoBandPhotosyntheticallyActiveRadiation(water_red_attenuation,
112111
water_blue_attenuation,

src/Models/AdvectedPopulations/LOBSTER/LOBSTER.jl

+16-16
Original file line numberDiff line numberDiff line change
@@ -246,17 +246,11 @@ julia> using Oceananigans
246246
julia> grid = RectilinearGrid(size=(3, 3, 30), extent=(10, 10, 200));
247247
248248
julia> model = LOBSTER(; grid)
249-
Lodyc-DAMTP Ocean Biogeochemical Simulation Tools for Ecosystem and Resources (LOBSTER) model (Float64)
250-
Optional components:
251-
├── Carbonates ❌
252-
├── Oxygen ❌
253-
└── Variable Redfield Ratio ❌
254-
Sinking Velocities:
255-
├── sPOM: 0.0 to -3.47e-5 m/s
256-
└── bPOM: 0.0 to -0.0023148148148148147 m/s
249+
LOBSTER{Float64} with carbonates ❌, oxygen ❌, variable Redfield ratio ❌and (:sPOM, :bPOM) sinking
257250
Light attenuation: Two-band light attenuation model (Float64)
258251
Sediment: Nothing
259252
Particles: Nothing
253+
Modifiers: Nothing
260254
```
261255
"""
262256
function LOBSTER(; grid,
@@ -353,7 +347,13 @@ function LOBSTER(; grid,
353347

354348
if scale_negatives
355349
scaler = ScaleNegativeTracers(underlying_biogeochemistry, grid)
356-
modifiers = isnothing(modifiers) ? scaler : (modifiers..., scaler)
350+
if isnothing(modifiers)
351+
modifiers = scaler
352+
elseif modifiers isa Tuple
353+
modifiers = (modifiers..., scaler)
354+
else
355+
modifiers = (modifiers, scaler)
356+
end
357357
end
358358

359359
return Biogeochemistry(underlying_biogeochemistry;
@@ -432,14 +432,14 @@ adapt_structure(to, lobster::LOBSTER) =
432432
adapt(to, lobster.optionals),
433433
adapt(to, lobster.sinking_velocities))
434434

435-
summary(::LOBSTER{FT, B, W}) where {FT, B, W} = string("Lodyc-DAMTP Ocean Biogeochemical Simulation Tools for Ecosystem and Resources (LOBSTER) model ($FT)")
435+
summary(::LOBSTER{FT, Val{B}, NamedTuple{K, V}}) where {FT, B, K, V} = string("LOBSTER{$FT} with carbonates $(B[1] ? :✅ : :❌), oxygen $(B[2] ? :✅ : :❌), variable Redfield ratio $(B[3] ? :✅ : :❌)and $K sinking")
436436

437-
show(io::IO, model::LOBSTER{FT, Val{B}, W}) where {FT, B, W} = string(summary(model), " \n",
438-
" Optional components:", "\n",
439-
" ├── Carbonates $(B[1] ? :✅ : :❌) \n",
440-
" ├── Oxygen $(B[2] ? :✅ : :❌) \n",
441-
" └── Variable Redfield Ratio $(B[3] ? :✅ : :❌)", "\n",
442-
" Sinking Velocities:", "\n", show_sinking_velocities(model.sinking_velocities))
437+
show(io::IO, model::LOBSTER{FT, Val{B}, W}) where {FT, B, W} = print(io, string("Lodyc-DAMTP Ocean Biogeochemical Simulation Tools for Ecosystem and Resources (LOBSTER) model \n",
438+
"├── Optional components:", "\n",
439+
" ├── Carbonates $(B[1] ? :✅ : :❌) \n",
440+
" ├── Oxygen $(B[2] ? :✅ : :❌) \n",
441+
" └── Variable Redfield Ratio $(B[3] ? :✅ : :❌)", "\n",
442+
"└── Sinking Velocities:", "\n", show_sinking_velocities(model.sinking_velocities)))
443443

444444
@inline maximum_sinking_velocity(bgc::LOBSTER) = maximum(abs, bgc.sinking_velocities.bPOM.w)
445445

src/Models/AdvectedPopulations/NPZD.jl

+5-8
Original file line numberDiff line numberDiff line change
@@ -145,14 +145,11 @@ julia> using Oceananigans
145145
julia> grid = RectilinearGrid(size=(20, 30), extent=(200, 200), topology=(Bounded, Flat, Bounded));
146146
147147
julia> model = NutrientPhytoplanktonZooplanktonDetritus(; grid)
148-
Nutrient Phytoplankton Zooplankton Detritus model (Float64)
149-
Sinking Velocities:
150-
├── P: 0.0 to -2.9525462962962963e-6 m/s
151-
└── D: 0.0 to -3.181597222222222e-5 m/s
148+
NutrientPhytoplanktonZooplanktonDetritus{Float64} model, with (:P, :D) sinking
152149
Light attenuation: Two-band light attenuation model (Float64)
153150
Sediment: Nothing
154151
Particles: Nothing
155-
152+
Modifiers: Nothing
156153
```
157154
"""
158155
function NutrientPhytoplanktonZooplanktonDetritus(; grid,
@@ -297,9 +294,9 @@ function update_boxmodel_state!(model::BoxModel{<:Biogeochemistry{<:NPZD}, <:Any
297294
getproperty(model.values, :T) .= model.forcing.T(model.clock.time)
298295
end
299296

300-
summary(::NPZD{FT, W}) where {FT, W} = string("Nutrient Phytoplankton Zooplankton Detritus model ($FT)")
301-
show(io::IO, model::NPZD) = string(summary(model), " \n",
302-
" Sinking Velocities:", "\n", show_sinking_velocities(model.sinking_velocities))
297+
summary(::NPZD{FT, NamedTuple{K, V}}) where {FT, K, V} = string("NutrientPhytoplanktonZooplanktonDetritus{$FT} model, with $K sinking")
298+
show(io::IO, model::NPZD{FT}) where {FT} = print(io, string("NutrientPhytoplanktonZooplanktonDetritus{$FT} model \n",
299+
"└── Sinking Velocities:", "\n", show_sinking_velocities(model.sinking_velocities)))
303300

304301
@inline maximum_sinking_velocity(bgc::NPZD) = maximum(abs, bgc.sinking_velocities.D.w)
305302

src/OceanBioME.jl

+5-2
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,13 @@ conserved_tracers(model::Biogeochemistry) = conserved_tracers(model.underlying_b
163163

164164
summary(bgc::Biogeochemistry) = string("Biogeochemical model based on $(summary(bgc.underlying_biogeochemistry))")
165165
show(io::IO, model::Biogeochemistry) =
166-
print(io, show(model.underlying_biogeochemistry), " \n",
166+
print(io, summary(model.underlying_biogeochemistry), " \n",
167167
" Light attenuation: ", summary(model.light_attenuation), "\n",
168168
" Sediment: ", summary(model.sediment), "\n",
169-
" Particles: ", summary(model.particles))
169+
" Particles: ", summary(model.particles), "\n",
170+
" Modifiers: ", summary(model.modifiers))
171+
172+
summary(modifiers::Tuple) = tuple([summary(modifier) for modifier in modifiers])
170173

171174
include("Utils/Utils.jl")
172175
include("Boundaries/Boundaries.jl")

src/Utils/negative_tracers.jl

+5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ using Oceananigans.Architectures: device, architecture, arch_array
66
using Oceananigans.Biogeochemistry: AbstractBiogeochemistry
77

88
import Adapt: adapt_structure, adapt
9+
import Base: summary, show
910
import Oceananigans.Biogeochemistry: update_tendencies!, update_biogeochemical_state!
1011

1112
"""
@@ -84,6 +85,10 @@ function ScaleNegativeTracers(bgc::AbstractBiogeochemistry, grid; warn = false)
8485
return ScaleNegativeTracers(tracers, scalefactors, warn)
8586
end
8687

88+
summary(scaler::ScaleNegativeTracers) = string("Mass conserving negative scaling of $(scaler.tracers)")
89+
show(io::IO, scaler::ScaleNegativeTracers) = print(io, string(summary(scaler), "\n",
90+
"└── Scalefactors: $(scaler.scalefactors)"))
91+
8792
function update_biogeochemical_state!(model, scale::ScaleNegativeTracers)
8893
workgroup, worksize = work_layout(model.grid, :xyz)
8994

0 commit comments

Comments
 (0)