I'm not a huge fan of the lenses used to lookup vectors in the model structure; some downsides I can think of are:
- The lenses have to be updated every time something in the model data structure is changed
- Lookups with these lenses are type unstable
Suggestion
Make a struct that is a new field of the Model struct, like
struct DataLookup{N}
data_float::Dict{String, Vector{Float64}} = Dict()
data_int::Dict{String, Vector{Int}} = Dict()
data_svector::Dict{String, Vector{SVector{N, Float64}}} = Dict()
...
end
where the categorization by type makes it type stable. Then at the construction of the model these dictionaries are populated, with a convenience function:
Base.setindex!(data_lookup::DataLookup, standard_name::String, data::Vector{Float64}) = (data_lookup.data_float[standard_name] = data)
Base.setindex!(data_lookup::DataLookup, standard_name::String, data::Vector{Int}) = (data_lookup.data_int[intstandard_name] = data)
Base.setindex!(data_lookup::DataLookup{N}, standard_name::String, data::Vector{SVector{N, Float64}}) where {N} = (data_lookup.data_svector[standard_name] = data)
...
Another advantage of this is that it is very cheaply checked whether the data corresponding to some standard name is part of the model.
I'm not a huge fan of the lenses used to lookup vectors in the model structure; some downsides I can think of are:
Suggestion
Make a struct that is a new field of the
Modelstruct, likewhere the categorization by type makes it type stable. Then at the construction of the model these dictionaries are populated, with a convenience function:
Another advantage of this is that it is very cheaply checked whether the data corresponding to some standard name is part of the model.