11"""
2- ModelSpec(model; multiscale=nothing, timestep=nothing, input_bindings=NamedTuple(), meteo_bindings=NamedTuple(), output_routing=NamedTuple(), scope=:global)
2+ ModelSpec(model; multiscale=nothing, timestep=nothing, input_bindings=NamedTuple(), meteo_bindings=NamedTuple(), meteo_window=nothing, output_routing=NamedTuple(), scope=:global)
33
44User-side model configuration wrapper for mapping/model list composition.
55
66`ModelSpec` keeps model implementation and scenario-specific usage metadata in one place.
77This allows modelers to publish reusable models while users decide how models are coupled in
88their simulation setup.
99"""
10- struct ModelSpec{M,MS,TS,IB,MB,OR,SC}
10+ struct ModelSpec{M,MS,TS,IB,MB,MW, OR,SC}
1111 model:: M
1212 multiscale:: MS
1313 timestep:: TS
1414 input_bindings:: IB
1515 meteo_bindings:: MB
16+ meteo_window:: MW
1617 output_routing:: OR
1718 scope:: SC
1819end
@@ -29,6 +30,7 @@ function ModelSpec(
2930 timestep= nothing ,
3031 input_bindings= NamedTuple (),
3132 meteo_bindings= NamedTuple (),
33+ meteo_window= nothing ,
3234 output_routing= NamedTuple (),
3335 scope= :global
3436)
@@ -43,14 +45,16 @@ function ModelSpec(
4345 normalized_multiscale = _normalize_multiscale_mapping (base_model, base_multiscale)
4446 normalized_input_bindings = _normalize_input_bindings (input_bindings)
4547 normalized_meteo_bindings = _normalize_meteo_bindings (meteo_bindings)
48+ normalized_meteo_window = _normalize_meteo_window (meteo_window)
4649 normalized_output_routing = _normalize_output_routing (output_routing)
4750 normalized_scope = _normalize_scope_selector (scope)
48- return ModelSpec {typeof(base_model),typeof(normalized_multiscale),typeof(timestep),typeof(normalized_input_bindings),typeof(normalized_meteo_bindings),typeof(normalized_output_routing),typeof(normalized_scope)} (
51+ return ModelSpec {typeof(base_model),typeof(normalized_multiscale),typeof(timestep),typeof(normalized_input_bindings),typeof(normalized_meteo_bindings),typeof(normalized_meteo_window),typeof( normalized_output_routing),typeof(normalized_scope)} (
4952 base_model,
5053 normalized_multiscale,
5154 timestep,
5255 normalized_input_bindings,
5356 normalized_meteo_bindings,
57+ normalized_meteo_window,
5458 normalized_output_routing,
5559 normalized_scope
5660 )
@@ -63,10 +67,11 @@ function ModelSpec(
6367 timestep= spec. timestep,
6468 input_bindings= spec. input_bindings,
6569 meteo_bindings= spec. meteo_bindings,
70+ meteo_window= spec. meteo_window,
6671 output_routing= spec. output_routing,
6772 scope= spec. scope
6873)
69- ModelSpec (model; multiscale= multiscale, timestep= timestep, input_bindings= input_bindings, meteo_bindings= meteo_bindings, output_routing= output_routing, scope= scope)
74+ ModelSpec (model; multiscale= multiscale, timestep= timestep, input_bindings= input_bindings, meteo_bindings= meteo_bindings, meteo_window = meteo_window, output_routing= output_routing, scope= scope)
7075end
7176
7277as_model_spec (spec:: ModelSpec ) = spec
@@ -113,6 +118,16 @@ function with_meteo_bindings(model_or_spec, bindings)
113118 return ModelSpec (spec; meteo_bindings= _normalize_meteo_bindings (bindings))
114119end
115120
121+ """
122+ with_meteo_window(model_or_spec, window)
123+
124+ Return a `ModelSpec` with explicit weather-window selection strategy.
125+ """
126+ function with_meteo_window (model_or_spec, window)
127+ spec = as_model_spec (model_or_spec)
128+ return ModelSpec (spec; meteo_window= _normalize_meteo_window (window))
129+ end
130+
116131"""
117132 with_output_routing(model_or_spec, routing)
118133
184199
185200_normalize_meteo_bindings (bindings) = bindings
186201
202+ function _normalize_meteo_window (window)
203+ if isnothing (window)
204+ return nothing
205+ elseif window isa DataType
206+ window <: PlantMeteo.AbstractSamplingWindow || error (
207+ " Unsupported MeteoWindow type `$(window) `. " ,
208+ " Use a PlantMeteo sampling-window type/instance."
209+ )
210+ return window ()
211+ elseif window isa PlantMeteo. AbstractSamplingWindow
212+ return window
213+ end
214+
215+ error (
216+ " Unsupported MeteoWindow value `$(window) ` of type `$(typeof (window)) `. " ,
217+ " Use a PlantMeteo sampling-window type/instance."
218+ )
219+ end
220+
187221function _normalize_output_routing (routing:: NamedTuple )
188222 normalized = Pair{Symbol,Symbol}[]
189223 for (k, v) in pairs (routing)
@@ -243,6 +277,14 @@ Each value can be:
243277MeteoBindings (bindings) = x -> with_meteo_bindings (x, bindings)
244278MeteoBindings (; kwargs... ) = MeteoBindings ((; kwargs... ))
245279
280+ """
281+ MeteoWindow(window)
282+
283+ Pipe-style transform that sets the weather window-selection strategy on a model/spec.
284+ Use `PlantMeteo.RollingWindow()` (default) or `PlantMeteo.CalendarWindow(...)`.
285+ """
286+ MeteoWindow (window) = x -> with_meteo_window (x, window)
287+
246288"""
247289 OutputRouting(routing)
248290 OutputRouting(; kwargs...)
0 commit comments