1- from pyesgf .search import SearchConnection
2-
31from climateset .download .abstract_downloader import AbstractDownloader
42from climateset .download .constants .esgf import INPUT4MIPS
53from climateset .download .downloader_config import (
64 Input4mipsDownloaderConfig ,
75 create_input4mips_downloader_config_from_file ,
86)
97from climateset .download .utils import (
10- download_metadata_variable ,
11- download_raw_input_variable ,
12- get_upload_version ,
13- handle_base_search_constraints ,
8+ search_and_download_esgf_biomass_single_var ,
9+ search_and_download_esgf_raw_single_var ,
1410)
1511from climateset .utils import create_logger
1612
@@ -67,38 +63,18 @@ def download_raw_input_single_var(
6763 """
6864 self .logger .info ("Using download_raw_input_single_var() function" )
6965
70- facets = "project,frequency,variable,nominal_resolution,version,target_mip,grid_label"
71-
7266 # Search context is sensitive to order and sequence, which is why
7367 # it's done in different steps instead of putting everything in `new_context`
74- conn = SearchConnection (url = self .config .node_link , distrib = False )
75- ctx = conn .new_context (
76- project = project ,
68+ results_list = search_and_download_esgf_raw_single_var (
7769 variable = variable ,
70+ project = project ,
7871 institution_id = institution_id ,
79- facets = facets ,
72+ default_grid_label = default_grid_label ,
73+ default_frequency = default_frequency ,
74+ preferred_version = preferred_version ,
75+ data_dir = self .config .data_dir ,
8076 )
81- ctx = handle_base_search_constraints (ctx , default_frequency , default_grid_label )
82-
83- mips_targets = list (ctx .facet_counts ["target_mip" ])
84- self .logger .info (f"Available target mips: { mips_targets } " )
85-
86- for target in mips_targets :
87- ctx_target = ctx .constrain (target_mip = target )
88- version = get_upload_version (context = ctx_target , preferred_version = preferred_version )
89- if version :
90- ctx_target = ctx_target .constrain (version = version )
91-
92- results = ctx_target .search ()
93- self .logger .info (f"Result len { len (results )} " )
94- if len (results ) > 0 :
95- download_raw_input_variable (
96- project = INPUT4MIPS ,
97- institution_id = institution_id ,
98- search_results = results ,
99- variable = variable ,
100- base_path = self .config .data_dir ,
101- )
77+ self .logger .info (f"Download results: { results_list } " )
10278
10379 def download_meta_historic_biomassburning_single_var (
10480 self ,
@@ -123,38 +99,20 @@ def download_meta_historic_biomassburning_single_var(
12399 variable_id = variable .replace ("_" , "-" )
124100 variable_search = f"percentage_{ variable_id .replace ('-' , '_' ).split ('_' )[- 1 ]} "
125101 self .logger .info (variable , variable_id , institution_id )
126- facets = "nominal_resolution,version"
127102
128103 # Search context is sensitive to order and sequence, which is why
129104 # it's done in different steps instead of putting everything in `new_context`
130- conn = SearchConnection (url = self .config .node_link , distrib = False )
131- ctx = conn .new_context (
132- project = project ,
105+ results = search_and_download_esgf_biomass_single_var (
133106 variable = variable_search ,
134107 variable_id = variable_id ,
108+ project = project ,
135109 institution_id = institution_id ,
136- target_mip = "CMIP" ,
137- facets = facets ,
138- )
139- ctx = handle_base_search_constraints (ctx , default_frequency , default_grid_label )
140-
141- version = get_upload_version (context = ctx , preferred_version = preferred_version )
142- if version :
143- ctx = ctx .constrain (version = version )
144-
145- results = ctx .search ()
146- self .logger .info (f"Result len { len (results )} " )
147-
148- result_list = [r .file_context ().search () for r in results ]
149- self .logger .info (f"List of results :\n { result_list } " )
150-
151- download_metadata_variable (
152- project = INPUT4MIPS ,
153- institution_id = institution_id ,
154- search_results = results ,
155- variable = variable ,
110+ default_grid_label = default_grid_label ,
111+ default_frequency = default_frequency ,
112+ preferred_version = preferred_version ,
156113 base_path = self .config .data_dir ,
157114 )
115+ self .logger .info (f"Download results: { results } " )
158116
159117
160118def input4mips_download_from_config (config ):
0 commit comments