77import pathlib
88import warnings
99from io import StringIO
10- from typing import TYPE_CHECKING , Any , Dict , List , Literal , Optional , Tuple , Union
10+ from typing import TYPE_CHECKING , Any , Collection , Dict , List , Literal , Optional , Tuple , Union
1111
1212import numpy as np
1313import pandas as pd
@@ -349,6 +349,7 @@ def fit_to_model_coords(
349349 name : str ,
350350 data : Optional [Union [TemporalDataUser , NonTemporalDataUser ]],
351351 has_time_dim : bool = True ,
352+ dims : Optional [Collection [FlowSystemDimensions ]] = None ,
352353 ) -> Optional [Union [TemporalData , NonTemporalData ]]:
353354 """
354355 Fit data to model coordinate system (currently time, but extensible).
@@ -357,17 +358,27 @@ def fit_to_model_coords(
357358 name: Name of the data
358359 data: Data to fit to model coordinates
359360 has_time_dim: Wether to use the time dimension or not
361+ dims: Collection of dimension names to use for fitting. If None, all dimensions are used.
360362
361363 Returns:
362364 xr.DataArray aligned to model coordinate system. If data is None, returns None.
363365 """
364366 if data is None :
365367 return None
366368
367- coords = self .coords
369+ if dims is None :
370+ coords = self .coords
368371
369- if not has_time_dim :
370- coords .pop ('time' )
372+ if not has_time_dim :
373+ warnings .warn (
374+ 'has_time_dim is deprecated. Please pass dims to fit_to_model_coords instead.' ,
375+ DeprecationWarning ,
376+ stacklevel = 2 ,
377+ )
378+ coords .pop ('time' )
379+ else :
380+ coords = self .coords
381+ coords = {k : coords [k ] for k in dims if k in coords }
371382
372383 # Rest of your method stays the same, just pass coords
373384 if isinstance (data , TimeSeriesData ):
@@ -390,6 +401,7 @@ def fit_effects_to_model_coords(
390401 effect_values : Optional [Union [TemporalEffectsUser , NonTemporalEffectsUser ]],
391402 label_suffix : Optional [str ] = None ,
392403 has_time_dim : bool = True ,
404+ dims : Optional [Collection [FlowSystemDimensions ]] = None ,
393405 ) -> Optional [Union [TemporalEffects , NonTemporalEffects ]]:
394406 """
395407 Transform EffectValues from the user to Internal Datatypes aligned with model coordinates.
@@ -401,7 +413,10 @@ def fit_effects_to_model_coords(
401413
402414 return {
403415 effect : self .fit_to_model_coords (
404- '|' .join (filter (None , [label_prefix , effect , label_suffix ])), value , has_time_dim = has_time_dim
416+ '|' .join (filter (None , [label_prefix , effect , label_suffix ])),
417+ value ,
418+ has_time_dim = has_time_dim ,
419+ dims = dims ,
405420 )
406421 for effect , value in effect_values_dict .items ()
407422 }
0 commit comments