6060 from collections .abc import Iterable , Sequence
6161
6262 from esmvalcore .config import Session
63+ from esmvalcore .io .protocol import DataElement
6364 from esmvalcore .typing import Facets
6465
6566logger = logging .getLogger (__name__ )
@@ -328,20 +329,12 @@ def _update_weighting_settings(
328329 _exclude_dataset (settings , facets , "weighting_landsea_fraction" )
329330
330331
331- def _add_to_download_list (dataset : Dataset ) -> None :
332- """Add the files of `dataset` to `DOWNLOAD_FILES`."""
333- for i , file in enumerate (dataset .files ):
334- if isinstance (file , esgf .ESGFFile ):
335- DOWNLOAD_FILES .add (file )
336- dataset .files [i ] = file .local_file (dataset .session ["download_dir" ])
337-
338-
339332def _schedule_for_download (datasets : Iterable [Dataset ]) -> None :
340333 """Schedule files for download."""
341334 for dataset in datasets :
342- _add_to_download_list (dataset )
335+ DOWNLOAD_FILES . update (dataset . files )
343336 for supplementary_ds in dataset .supplementaries :
344- _add_to_download_list (supplementary_ds )
337+ DOWNLOAD_FILES . update (supplementary_ds . files )
345338
346339
347340def _log_input_files (datasets : Iterable [Dataset ]) -> None :
@@ -367,12 +360,7 @@ def _log_input_files(datasets: Iterable[Dataset]) -> None:
367360
368361def _get_files_str (dataset : Dataset ) -> str :
369362 """Get nice string representation of all files of a dataset."""
370- return "\n " .join (
371- f" { f } "
372- if f .exists () # type: ignore
373- else f" { f } (will be downloaded)"
374- for f in dataset .files
375- )
363+ return "\n " .join (f" { f } " for f in dataset .files )
376364
377365
378366def _check_input_files (input_datasets : Iterable [Dataset ]) -> set [str ]:
@@ -455,10 +443,7 @@ def _get_common_attributes(
455443
456444 # Ensure that attributes start_year and end_year are always available if at
457445 # least one of the input datasets defines it
458- if "timerange" in attributes :
459- start_year , end_year = _parse_period (attributes ["timerange" ])
460- attributes ["start_year" ] = int (str (start_year [0 :4 ]))
461- attributes ["end_year" ] = int (str (end_year [0 :4 ]))
446+ _set_start_end_year (attributes )
462447
463448 return attributes
464449
@@ -722,7 +707,7 @@ def _get_preprocessor_products(
722707 )
723708
724709 for product in products :
725- _set_start_end_year (product )
710+ _set_start_end_year (product . attributes )
726711 product .check ()
727712
728713 return products
@@ -782,18 +767,18 @@ def _configure_multi_product_preprocessor(
782767
783768 for product in multimodel_products | ensemble_products :
784769 product .check ()
785- _set_start_end_year (product )
770+ _set_start_end_year (product . attributes )
786771
787772
788- def _set_start_end_year (product : PreprocessorFile ) -> None :
773+ def _set_start_end_year (attributes : dict [ str , Any ] ) -> None :
789774 """Set the attributes `start_year` and `end_year`.
790775
791776 These attributes are used by many diagnostic scripts in ESMValTool.
792777 """
793- if "timerange" in product . attributes :
794- start_year , end_year = _parse_period (product . attributes ["timerange" ])
795- product . attributes ["start_year" ] = int (str (start_year [0 :4 ]))
796- product . attributes ["end_year" ] = int (str (end_year [0 :4 ]))
778+ if "timerange" in attributes :
779+ start_year , end_year = _parse_period (attributes ["timerange" ])
780+ attributes ["start_year" ] = int (str (start_year [0 :4 ]))
781+ attributes ["end_year" ] = int (str (end_year [0 :4 ]))
797782
798783
799784def _update_preproc_functions (
@@ -916,7 +901,7 @@ def __init__(
916901 # Clear the global variable containing the set of files to download
917902 DOWNLOAD_FILES .clear ()
918903 USED_DATASETS .clear ()
919- self ._download_files : set [esgf . ESGFFile ] = set ()
904+ self ._download_files : set [DataElement ] = set ()
920905 self .session = session
921906 self .session ["write_ncl_interface" ] = self ._need_ncl (
922907 raw_recipe ["diagnostics" ],
@@ -1342,8 +1327,8 @@ def run(self) -> None:
13421327 filled_recipe = self .write_filled_recipe ()
13431328
13441329 # Download required data
1345- if self . session [ "search_esgf" ] != "never" :
1346- esgf . download ( self . _download_files , self . session [ "download_dir" ] )
1330+ for file in self . _download_files :
1331+ file . prepare ( )
13471332
13481333 self .tasks .run (max_parallel_tasks = self .session ["max_parallel_tasks" ])
13491334 logger .info (
0 commit comments