API
Parameter dictionaries
ClimaParams.AbstractTOMLDict
— TypeClimaParams.ParamDict
— TypeParamDict(data::Dict, override_dict::Union{Nothing,Dict})
Structure to hold information read-in from TOML file, as well as a parametrization type FT
.
Uses the name to search
Fields
data
: dictionary representing a default/merged parameter TOML fileoverride_dict
: either a nothing, or a dictionary representing an override parameter TOML file
File parsing and parameter logging
User facing functions:
ClimaParams.create_toml_dict
— Functioncreate_toml_dict(FT;
override_file,
default_file,
)
Creates a ParamDict{FT}
struct, by reading and merging upto two TOML files or Julia Dicts with override information taking precedence over default information.
ClimaParams.get_parameter_values
— Functionget_parameter_values(
pd::AbstractTOMLDict,
names::Union{String,Vector{String}},
component::String
)
get_parameter_values(
pd::AbstractTOMLDict,
name_map::Union{Dict, Vector{Pair}, NTuple{N, Pair}, Vararg{Pair}},
component::String
)
Given a toml dict and a list of parameter names, returns a NamedTuple of the parameters and their values. If a component is specified, the parameter is logged as being used in that component.
Instead of a list of parameter names, this can take an iterable mapping from parameter names to variable names in code. Then, this function retrieves all parameters from the long names and returns a NamedTuple where the keys are the variable names.
ClimaParams.get_tagged_parameter_values
— Functionget_tagged_parameter_values(pd::AbstractTOMLDict, tag::AbstractString)
get_tagged_parameter_values(pd::AbstractTOMLDict, tags::Vector{AbstractString})
Returns a list of name-value Pairs of the parameters with the given tag(s).
ClimaParams.get_tagged_parameter_names
— Functionget_tagged_parameter_names(pd::AbstractTOMLDict, tag::AbstractString)
get_tagged_parameter_names(pd::AbstractTOMLDict, tags::Vector{AbstractString})
Returns a list of the parameters with a given tag.
ClimaParams.fuzzy_match
— Functionfuzzy_match(s1::AbstractString, s2::AbstractString)
Takes two strings and checks them for equality. This strips punctuation [' ', '_', '*', '.', ',', '-', '(', ')'] and removes capitalization.
ClimaParams.float_type
— Functionfloat_type(::AbstractTOMLDict)
The float type from the parameter dict.
ClimaParams.log_parameter_information
— Functionlog_parameter_information(
pd::AbstractTOMLDict,
filepath;
strict::Bool = false
)
Writes the parameter log file at filepath
; checks that override parameters are all used.
If strict = true
, errors if override parameters are unused.
ClimaParams.write_log_file
— Functionwrite_log_file(pd::AbstractTOMLDict, filepath)
Writes a log file of all used parameters of pd
at the filepath
. This file can be used to rerun the experiment.
ClimaParams.merge_toml_files
— Functionmerge_toml_files(filepaths; override)
Parses and merges all of the given TOML filepaths and returns them as a Dict. This allows a toml_dict to be constructed from multiple TOML files. By default, non-unique TOML entries are not allowed, but this can be changed by setting override = true
.
ClimaParams.create_parameter_struct
— Functioncreate_parameter_struct(
toml_dict,
param_struct_type,
name_map,
nested_structs = (;),
)
Constructs the parameter struct from the TOML dictionary. If the parameter struct has nested parameter structs, they must be passed. Floating type is inherited from the TOML dictionary.
This is fairly rigid and makes a few assumptions:
- The parameter struct has a constructor that takes keyword arguments
- The parameter struct's first type parameter is the floating point type
- All nested parameter structs are given.