1
- from pyesgf .search import SearchConnection
2
-
3
1
from climateset .download .abstract_downloader import AbstractDownloader
4
2
from climateset .download .constants .esgf import INPUT4MIPS
5
3
from climateset .download .downloader_config import (
6
4
Input4mipsDownloaderConfig ,
7
5
create_input4mips_downloader_config_from_file ,
8
6
)
9
7
from 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 ,
14
10
)
15
11
from climateset .utils import create_logger
16
12
@@ -67,38 +63,18 @@ def download_raw_input_single_var(
67
63
"""
68
64
self .logger .info ("Using download_raw_input_single_var() function" )
69
65
70
- facets = "project,frequency,variable,nominal_resolution,version,target_mip,grid_label"
71
-
72
66
# Search context is sensitive to order and sequence, which is why
73
67
# 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 (
77
69
variable = variable ,
70
+ project = project ,
78
71
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 ,
80
76
)
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 } " )
102
78
103
79
def download_meta_historic_biomassburning_single_var (
104
80
self ,
@@ -123,38 +99,20 @@ def download_meta_historic_biomassburning_single_var(
123
99
variable_id = variable .replace ("_" , "-" )
124
100
variable_search = f"percentage_{ variable_id .replace ('-' , '_' ).split ('_' )[- 1 ]} "
125
101
self .logger .info (variable , variable_id , institution_id )
126
- facets = "nominal_resolution,version"
127
102
128
103
# Search context is sensitive to order and sequence, which is why
129
104
# 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 (
133
106
variable = variable_search ,
134
107
variable_id = variable_id ,
108
+ project = project ,
135
109
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 ,
156
113
base_path = self .config .data_dir ,
157
114
)
115
+ self .logger .info (f"Download results: { results } " )
158
116
159
117
160
118
def input4mips_download_from_config (config ):
0 commit comments