1818from anemoi .utils .config import load_any_dict_format
1919from earthkit .data .core .order import normalize_order_by
2020
21+ from anemoi .datasets .dates .groups import Groups
22+
2123LOG = logging .getLogger (__name__ )
2224
2325
@@ -338,20 +340,72 @@ def _prepare_serialisation(o: Any) -> Any:
338340 return str (o )
339341
340342
341- def loader_config (config : dict ) -> LoadersConfig :
343+ def set_to_test_mode (cfg : dict ) -> None :
344+ """Modifies the configuration to run in test mode.
345+
346+ Parameters
347+ ----------
348+ cfg : dict
349+ The configuration dictionary.
350+ """
351+ NUMBER_OF_DATES = 4
352+
353+ LOG .warning (f"Running in test mode. Changing the list of dates to use only { NUMBER_OF_DATES } ." )
354+ groups = Groups (** LoadersConfig (cfg ).dates )
355+
356+ dates = groups .provider .values
357+ cfg ["dates" ] = dict (
358+ start = dates [0 ],
359+ end = dates [NUMBER_OF_DATES - 1 ],
360+ frequency = groups .provider .frequency ,
361+ group_by = NUMBER_OF_DATES ,
362+ )
363+
364+ num_ensembles = count_ensembles (cfg )
365+
366+ def set_element_to_test (obj ):
367+ if isinstance (obj , (list , tuple )):
368+ for v in obj :
369+ set_element_to_test (v )
370+ return
371+ if isinstance (obj , (dict , DotDict )):
372+ if "grid" in obj and num_ensembles > 1 :
373+ previous = obj ["grid" ]
374+ obj ["grid" ] = "20./20."
375+ LOG .warning (f"Running in test mode. Setting grid to { obj ['grid' ]} instead of { previous } " )
376+ if "number" in obj and num_ensembles > 1 :
377+ if isinstance (obj ["number" ], (list , tuple )):
378+ previous = obj ["number" ]
379+ obj ["number" ] = previous [0 :3 ]
380+ LOG .warning (f"Running in test mode. Setting number to { obj ['number' ]} instead of { previous } " )
381+ for k , v in obj .items ():
382+ set_element_to_test (v )
383+ if "constants" in obj :
384+ constants = obj ["constants" ]
385+ if "param" in constants and isinstance (constants ["param" ], list ):
386+ constants ["param" ] = ["cos_latitude" ]
387+
388+ set_element_to_test (cfg )
389+
390+
391+ def loader_config (config : dict , is_test : bool = False ) -> LoadersConfig :
342392 """Loads and validates the configuration for dataset loaders.
343393
344394 Parameters
345395 ----------
346396 config : dict
347397 The configuration dictionary.
398+ is_test : bool, optional
399+ Whether to run in test mode. Defaults to False.
348400
349401 Returns
350402 -------
351403 LoadersConfig
352404 The validated configuration object.
353405 """
354406 config = Config (config )
407+ if is_test :
408+ set_to_test_mode (config )
355409 obj = LoadersConfig (config )
356410
357411 # yaml round trip to check that serialisation works as expected
@@ -372,9 +426,6 @@ def loader_config(config: dict) -> LoadersConfig:
372426 LOG .info (f"Setting env variable { k } ={ v } " )
373427 os .environ [k ] = str (v )
374428
375- # Used by pytest only
376- # copy.pop('checks', None)
377-
378429 return copy
379430
380431
0 commit comments