Skip to content

Commit

Permalink
Merge pull request #23 from PALEOtoolkit/link_syntax
Browse files Browse the repository at this point in the history
Simpler syntax for CreateReaction
  • Loading branch information
sjdaines authored May 15, 2022
2 parents 72be3bf + 6ce964c commit 886b858
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 18 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "PALEOboxes"
uuid = "804b410e-d900-4b2a-9ecd-f5a06d4c1fd4"
authors = ["Stuart Daines <[email protected]>"]
version = "0.18.3"
version = "0.18.4"

[deps]
BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
Expand Down
31 changes: 21 additions & 10 deletions src/VariableReaction.jl
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ end
##################################################

"""
CreateVariableReaction(var_type, linklocal_namestr, units, description;
attributes=Tuple(), link_namestr=linklocal_namestr)
-> VariableReaction{T}
CreateVariableReaction(T, localname => link_namestr, units, description; attributes=Tuple()) -> VariableReaction{T}
CreateVariableReaction(T, linklocal_namestr, units, description; attributes=Tuple()) -> VariableReaction{T}
[deprecated] CreateVariableReaction(T, localname, units, description; link_namestr, attributes=Tuple()) -> VariableReaction{T}
Create a [`VariableReaction`](@ref).
Expand All @@ -76,19 +76,30 @@ Not called directly: use short names `VarProp`, `VarDep`, `VarContrib`, `VarTarg
# Arguments
- `var_type::VariableType`: one of `VT_ReactProperty`, `VT_ReactDependency`, `VT_ReactContributor`, `VT_ReactTarget`
- `linklocal_namestr::AbstractString`: either
- `localname`, or
- `<linkreq_domain>.[linkreq_subdomain.]localname` (which is parsed by [`parse_variablereaction_namestr`](@ref)
to define the requested linking to `Domain` Variable).
- `localname::AbstractString`: Reaction-local Variable name
- `link_namestr::AbstractString`: `<linkreq_domain>.[linkreq_subdomain.]linkreq_name`. Parsed by [`parse_variablereaction_namestr`](@ref)
to define the requested linking to `Domain` Variable.
- `linklocal_namestr::AbstractString`: `<linkreq_domain>.[linkreq_subdomain.]localname`. Convenience form to define both `localname`
and requested linking to Domain Variable, for the common case where `linkreq_name == localname`.
- `units::AbstractString`: units ("" if not applicable)
- `description::AbstractString`: text describing the variable
# Keywords
- `attributes::Tuple(:attrb1name=>attrb1value, :attrb2name=>attrb2value, ...)`:
variable attributes, see [`StandardAttributes`](@ref), [`set_attribute!`](@ref), [`get_attribute`](@ref)
- `link_namestr::AbstractString`: parsed by [`parse_variablereaction_namestr`](@ref)
to define requested linking to `Domain` Variable. Only required to specify a requested link name where `linkreq_name`
is different from `localname`. If supplied, `linklocal_namestr` must then be just `localname`.
"""
function CreateVariableReaction end

CreateVariableReaction(
var_type::VariableType,
localname_linkname::Pair{<:AbstractString, <:AbstractString},
units::AbstractString,
description::AbstractString;
attributes::Tuple{Vararg{Pair}}=(), # (:atrb1=>value1, :atrb2=>value2)
) = CreateVariableReaction(
var_type, first(localname_linkname), units, description;
link_namestr=last(localname_linkname), attributes=attributes
)

function CreateVariableReaction(
var_type::VariableType,
linklocal_namestr::AbstractString,
Expand Down
9 changes: 3 additions & 6 deletions src/reactioncatalog/Fluxes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,7 @@ function _FluxVars(
push!(
variables,
varctorfn(
localname, "mol yr-1", "$description $fluxname",
link_namestr=link_namestr,
localname=>link_namestr, "mol yr-1", "$description $fluxname",
attributes=attributes
)
)
Expand Down Expand Up @@ -321,8 +320,7 @@ function PB.register_dynamic_methods!(rj::ReactionFluxTransfer, model::PB.Model)
input_attrb = Tuple(atnm=>PB.get_attribute(input_var, atnm) for atnm in (:field_data, :data_dims, :space))

push!(var_inputs,
PB.VarDep("input_"*fluxname, "mol yr-1", "flux input",
link_namestr=input_namestr,
PB.VarDep("input_"*fluxname => input_namestr, "mol yr-1", "flux input",
attributes=input_attrb,
)
)
Expand All @@ -333,8 +331,7 @@ function PB.register_dynamic_methods!(rj::ReactionFluxTransfer, model::PB.Model)
replace(output_var_patternname, "\$fluxname\$" => fluxname)
)*")"
push!(var_outputs,
PB.VarContrib("output_"*fluxname, "mol yr-1", "flux output",
link_namestr=output_namestr,
PB.VarContrib("output_"*fluxname => output_namestr, "mol yr-1", "flux output",
attributes=input_attrb,
)
)
Expand Down
2 changes: 1 addition & 1 deletion src/reactioncatalog/VariableStats.jl
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ function PB.register_methods!(rj::ReactionSum)
# mark all vars_to_add as optional to help diagnose config errors
# default :field_data=>PB.UndefinedData to allow Variable to link to any data type (this is checked later)
push!(vars_to_add,
PB.VarDep(localname, "", "", link_namestr="("*varname*")")
PB.VarDep(localname => "("*varname*")", "", "")
)
end

Expand Down

2 comments on commit 886b858

@sjdaines
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register()

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/60276

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.18.4 -m "<description of version>" 886b8583b4b3ac24b4091fe42fa3002d474d64ae
git push origin v0.18.4

Please sign in to comment.