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

Remove t_start #764

Merged
merged 2 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions docs/src/diagnostics/developers_diagnostics.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Internally, this is done by using the [`ClimaDiagnostics.jl`](https://github.com
`add_diagnostic_variable!`, and dispatch off the type of land\_model to define how to compute a diagnostic (for example, surface temperature is computed in `p.bucket.T_sfc` in the bucket model).
- compute methods are defined in a separate file, for example, `bucket_compute_methods.jl`.
- `standard_diagnostic_frequencies.jl` defines standard functions to schedule diagnostics, for example, hourly average or monthly max, these functions are called on a list of diagnostic variables. As developers, we can add more standard functions that users may want to have access to easily in this file.
- `default_diagnostics.jl` defines default diagnostics functions to use on a model simulation. For example, `default_diagnostics(land_model::BucketModel, t_start; output_writer)`.
- `default_diagnostics.jl` defines default diagnostics functions to use on a model simulation. For example, `default_diagnostics(land_model::BucketModel, output_writer)`.
will return a `ScheduledDiagnostics` that computes hourly averages for all Bucket variables, along with their metadata, ready to be written on a NetCDF file when running a Bucket simulation.

The following section give more details on these functions, along with examples. As developers, we want to extand these functionality as ClimaLand progresses.
Expand Down Expand Up @@ -66,7 +66,7 @@ For each model, we define a function `default_diagnostics` which will define wha
on what schedule (for example, hourly average). For example,

```Julia
function default_diagnostics(land_model::BucketModel, t_start; output_writer)
function default_diagnostics(land_model::BucketModel{FT}; output_writer) where {FT}

define_diagnostics!(land_model)

Expand All @@ -87,7 +87,7 @@ function default_diagnostics(land_model::BucketModel, t_start; output_writer)
]

default_outputs =
hourly_averages(bucket_diagnostics...; output_writer, t_start)
hourly_averages(FT, bucket_diagnostics...; output_writer)
return [default_outputs...]
end
```
Expand All @@ -103,11 +103,10 @@ If `average_period = :hourly`, `default_outputs` calls `hourly_averages`, et cet
We defined some functions of diagnostic schedule that may often be used in `standard_diagnostic_frequencies.jl`, for example

```Julia
hourly_averages(short_names...; output_writer, t_start) = common_diagnostics(
60 * 60 * one(t_start),
hourly_averages(FT, short_names...; output_writer) = common_diagnostics(
60 * 60 * one(FT),
(+),
output_writer,
t_start,
short_names...;
pre_output_hook! = average_pre_output_hook!,
)
Expand Down
13 changes: 6 additions & 7 deletions docs/src/diagnostics/users_diagnostics.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ providing the space and output_dir defined in steps 1. and 2.
Now that you defined your model and your writter, you can create a callback function to be called when solving your model. For example:

```Julia
t0 = 0 # the starting time of your simulation
t0 = 0 # the start date of your simulation

reference_date = DateTime(2024) # reference_date is the DateTime of your starting time
start_date = DateTime(2024) # start_date is the DateTime of your start date

diags = ClimaLand.default_diagnostics(model, t0, reference_date; output_writer = nc_writer)
diags = ClimaLand.default_diagnostics(model, start_date; output_writer = nc_writer)

diagnostic_handler =
ClimaDiagnostics.DiagnosticsHandler(diags, Y, p, t0; dt = Δt)
Expand Down Expand Up @@ -118,11 +118,10 @@ add_diagnostic_variable!(
### Define how to schedule your variables. For example, you want the seasonal maximum of your variables, where season is defined as 90 days.

```Julia
seasonal_maxs(short_names...; output_writer, t_start) = common_diagnostics(
90 * 24 * 60 * 60 * one(t_start),
seasonal_maxs(FT, short_names...; output_writer) = common_diagnostics(
90 * 24 * 60 * 60 * one(FT),
max,
output_writer,
t_start,
short_names...,
)
```
Expand All @@ -134,7 +133,7 @@ Now, you can call your schedule with your variables.
```Julia
my_custom_diagnostics = ["lhf", "bor"]

diags = seasonal_maxs(my_custom_diagnostics...; output_writer, t_start)
diags = seasonal_maxs(FT, my_custom_diagnostics...; output_writer)
```

### Analyze your simulation output
Expand Down
18 changes: 9 additions & 9 deletions docs/tutorials/shared_utilities/driver_tutorial.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@
# shortwave and longwave flux (W/m^2). The radiative driver is also where
# a function which computes the zenith angle for the site is stored.

# Both drivers store the reference time for the data/simulation.
# Both drivers store the start date for the data/simulation.
# This is the DateTime object which corresponds to the time at which t=0
# in the simulation. Additionally, for site-level runs, both drivers store the
# forcing data as a spline function fit to the data which takes the time
# `t` as an argument, where `t` is the simulation time measured in seconds since
# the reference time. The reference time should be in UTC.
# the start date. The start date should be in UTC.

# Note: for coupled runs, corresponding types `CoupledAtmosphere`
# and `CoupledRadiativeFluxes` exist. However, these are not defined
Expand All @@ -54,9 +54,9 @@ time_offset = 7;
# Site latitude and longitude
lat = 38.7441; # degree
long = -92.2000; # degree
# Compute the reference time in UTC, and convert local datetime
# vector into a vector of seconds since the reference time
ref_time = local_datetime[1] + Dates.Hour(time_offset);
# Compute the start date in UTC, and convert local datetime
# vector into a vector of seconds since the start date
start_date = local_datetime[1] + Dates.Hour(time_offset);
data_dt = 3600.0;
seconds = 0:data_dt:((length(local_datetime) - 1) * data_dt);

Expand All @@ -81,16 +81,16 @@ earth_param_set = LP.LandParameters(Float64);
insol_params = earth_param_set.insol_params # parameters of Earth's orbit required to compute the insolation
function zenith_angle(
t,
ref_time;
start_date;
latitude = lat,
longitude = long,
insol_params = insol_params,
)
current_datetime = ref_time + Dates.Second(round(t)) # Time in UTC
current_datetime = start_date + Dates.Second(round(t)) # Time in UTC

d, δ, η_UTC = (Insolation.helper_instantaneous_zenith_angle(
current_datetime,
ref_time,
start_date,
insol_params,
))

Expand All @@ -110,7 +110,7 @@ radiation = ClimaLand.PrescribedRadiativeFluxes(
Float64,
SW_d,
LW_d,
ref_time;
start_date;
θs = zenith_angle,
);

Expand Down
10 changes: 5 additions & 5 deletions docs/tutorials/standalone/Bucket/bucket_tutorial.jl
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ using ClimaUtilities.TimeVaryingInputs: TimeVaryingInput
# We also want to plot the solution
using Plots

# And we need to use the DateTime type to store reference times
# And we need to use the DateTime type to store start dates
using Dates

FT = Float32;
Expand Down Expand Up @@ -203,7 +203,7 @@ z_0b = FT(1e-3);
ρc_soil = FT(2e6);
# Snow melt timescale
τc = FT(3600);
# Simulation start time, end time, and timestep
# Simulation start date, end time, and timestep
t0 = 0.0;
tf = 7 * 86400;
Δt = 3600.0;
Expand All @@ -214,7 +214,7 @@ bucket_parameters = BucketModelParameters(FT; albedo, z_0m, z_0b, τc);
# The PrescribedAtmosphere and PrescribedRadiation need to take in a reference
# time, the date of the start of the simulation. In this tutorial we will
# consider this January 1, 2005.
ref_time = DateTime(2005);
start_date = DateTime(2005);

# To drive the system in standalone mode,
# the user must provide
Expand Down Expand Up @@ -247,7 +247,7 @@ bucket_atmos = PrescribedAtmosphere(
TimeVaryingInput(u_atmos),
TimeVaryingInput(q_atmos),
TimeVaryingInput(P_atmos),
ref_time,
start_date,
h_atmos,
earth_param_set,
);
Expand All @@ -262,7 +262,7 @@ bucket_rad = PrescribedRadiativeFluxes(
FT,
TimeVaryingInput(SW_d),
TimeVaryingInput(LW_d),
ref_time,
start_date,
);


Expand Down
6 changes: 3 additions & 3 deletions docs/tutorials/standalone/Soil/evaporation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ thermo_params = LP.thermodynamic_parameters(earth_param_set);
# Our assumption is that in the lab experiment there was no radiative heating
# or cooling of the soil.

ref_time = DateTime(2005) # required argument, but not used in this case
start_date = DateTime(2005) # required argument, but not used in this case
SW_d = (t) -> 0
LW_d = (t) -> 301.15^4 * 5.67e-8
radiation = PrescribedRadiativeFluxes(
FT,
TimeVaryingInput(SW_d),
TimeVaryingInput(LW_d),
ref_time,
start_date,
);
# Set up atmospheric conditions that result in the potential evaporation
# rate obsereved in the experiment.
Expand Down Expand Up @@ -74,7 +74,7 @@ atmos = PrescribedAtmosphere(
TimeVaryingInput(u_atmos),
TimeVaryingInput(q_atmos),
TimeVaryingInput(P_atmos),
ref_time,
start_date,
h_atmos,
earth_param_set;
gustiness = gustiness,
Expand Down
6 changes: 3 additions & 3 deletions docs/tutorials/standalone/Soil/evaporation_gilat_loess.jl
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,14 @@ params = ClimaLand.Soil.EnergyHydrologyParameters(
d_ds,
);

ref_time = DateTime(2005)
start_date = DateTime(2005)
SW_d = (t) -> 0
LW_d = (t) -> 294.15^4 * 5.67e-8
radiation = PrescribedRadiativeFluxes(
FT,
TimeVaryingInput(SW_d),
TimeVaryingInput(LW_d),
ref_time,
start_date,
)
# Atmos
T_air = FT(301.15)
Expand All @@ -104,7 +104,7 @@ atmos = PrescribedAtmosphere(
TimeVaryingInput(u_atmos),
TimeVaryingInput(q_atmos),
TimeVaryingInput(P_atmos),
ref_time,
start_date,
h_atmos,
earth_param_set;
gustiness = gustiness,
Expand Down
6 changes: 3 additions & 3 deletions docs/tutorials/standalone/Soil/sublimation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ FT = Float64;
earth_param_set = LP.LandParameters(FT)
thermo_params = LP.thermodynamic_parameters(earth_param_set);

ref_time = DateTime(2005)
start_date = DateTime(2005)
SW_d = (t) -> 0
LW_d = (t) -> 270.0^4 * 5.67e-8
radiation = PrescribedRadiativeFluxes(
FT,
TimeVaryingInput(SW_d),
TimeVaryingInput(LW_d),
ref_time,
start_date,
);
# Set up atmospheric conditions that result in the potential evaporation
# rate obsereved in the experiment.
Expand Down Expand Up @@ -60,7 +60,7 @@ atmos = PrescribedAtmosphere(
TimeVaryingInput(u_atmos),
TimeVaryingInput(q_atmos),
TimeVaryingInput(P_atmos),
ref_time,
start_date,
h_atmos,
earth_param_set;
gustiness = gustiness,
Expand Down
8 changes: 4 additions & 4 deletions experiments/benchmarks/bucket.jl
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ function setup_prob(t0, tf, Δt; nelements = (100, 10))
npolynomial = 1,
dz_tuple = FT.((1.0, 0.05)),
)
ref_time = DateTime(2005)
start_date = DateTime(2005)

# Initialize parameters
σS_c = FT(0.2)
Expand All @@ -69,7 +69,7 @@ function setup_prob(t0, tf, Δt; nelements = (100, 10))

surface_space = bucket_domain.space.surface
# Construct albedo parameter object using temporal map
albedo = PrescribedSurfaceAlbedo{FT}(ref_time, t0, surface_space)
albedo = PrescribedSurfaceAlbedo{FT}(start_date, surface_space)

bucket_parameters = BucketModelParameters(FT; albedo, z_0m, z_0b, τc)

Expand All @@ -91,7 +91,7 @@ function setup_prob(t0, tf, Δt; nelements = (100, 10))
TimeVaryingInput(u_atmos),
TimeVaryingInput(q_atmos),
TimeVaryingInput(P_atmos),
ref_time,
start_date,
h_atmos,
earth_param_set,
)
Expand All @@ -106,7 +106,7 @@ function setup_prob(t0, tf, Δt; nelements = (100, 10))
FT,
TimeVaryingInput(SW_d),
TimeVaryingInput(LW_d),
ref_time,
start_date,
)

model = BucketModel(
Expand Down
Loading
Loading