Skip to content

Commit 23b0bea

Browse files
committed
Integrate config class for Input4mips
1 parent 6a76fa9 commit 23b0bea

2 files changed

Lines changed: 15 additions & 15 deletions

File tree

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
from abc import ABC, abstractmethod
22

3-
from climateset.download.abstract_downloader_config import AbstractDownloaderConfig
4-
53

64
class AbstractDownloader(ABC):
7-
def __init__(self, config: AbstractDownloaderConfig):
8-
self.config = config
9-
105
@abstractmethod
116
def download(self):
127
pass

climateset/download/input4mips_downloader.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from abstract_downloader import AbstractDownloader
22
from pyesgf.search import SearchConnection
33

4+
from climateset.download.abstract_downloader_config import Input4mipsDownloaderConfig
45
from climateset.download.utils import (
56
_handle_base_search_constraints,
67
download_metadata_variable,
@@ -13,7 +14,8 @@
1314

1415

1516
class Input4MipsDownloader(AbstractDownloader):
16-
def __init__(self):
17+
def __init__(self, config: Input4mipsDownloaderConfig):
18+
self.config: Input4mipsDownloaderConfig = config
1719
self.raw_vars = ""
1820
self.logger = LOGGER
1921

@@ -26,17 +28,17 @@ def download(self):
2628
self.logger.info(f"Downloading data for variable: {variable}")
2729
self.download_raw_input_single_var(variable=variable, institution_id=institution_id)
2830

29-
if self.download_biomass_burning & ("historical" in self.experiments):
30-
for variable in self.biomass_vars:
31+
if self.config.download_biomass_burning & ("historical" in self.config.experiments):
32+
for variable in self.config.biomass_vars:
3133
self.logger.info(f"Downloading biomassburing data for variable: {variable}")
3234
self.download_raw_input_single_var(variable=variable, institution_id="VUA")
3335

34-
if self.download_metafiles:
35-
for variable in self.meta_vars_percentage:
36+
if self.config.download_metafiles:
37+
for variable in self.config.meta_vars_percentage:
3638
# percentage are historic and have no scenarios
3739
self.logger.info(f"Downloading meta percentage data for variable: {variable}")
3840
self.download_meta_historic_biomassburning_single_var(variable=variable, institution_id="VUA")
39-
for variable in self.meta_vars_share:
41+
for variable in self.config.meta_vars_share:
4042
self.logger.info(f"Downloading meta openburning share data for variable: {variable}")
4143
self.download_raw_input_single_var(variable=variable, institution_id="IAMC")
4244

@@ -63,7 +65,7 @@ def download_raw_input_single_var( # noqa: C901
6365
self.logger.info("Using download_raw_input_single_var() function")
6466

6567
facets = "project,frequency,variable,nominal_resolution,version,target_mip,grid_label"
66-
conn = SearchConnection(url=self.model_node_link, distrib=False)
68+
conn = SearchConnection(url=self.config.node_link, distrib=False)
6769

6870
ctx = conn.new_context(
6971
project=project,
@@ -87,7 +89,10 @@ def download_raw_input_single_var( # noqa: C901
8789
self.logger.info(f"Result len {len(results)}")
8890
if len(results) > 0:
8991
download_raw_input_variable(
90-
institution_id=institution_id, search_results=results, variable=variable, base_path=self.data_dir
92+
institution_id=institution_id,
93+
search_results=results,
94+
variable=variable,
95+
base_path=self.config.data_dir,
9196
)
9297

9398
def download_meta_historic_biomassburning_single_var(
@@ -113,7 +118,7 @@ def download_meta_historic_biomassburning_single_var(
113118
variable_id = variable.replace("_", "-")
114119
variable_search = f"percentage_{variable_id.replace('-', '_').split('_')[-1]}"
115120
self.logger.info(variable, variable_id, institution_id)
116-
conn = SearchConnection(url=self.model_node_link, distrib=False)
121+
conn = SearchConnection(url=self.config.node_link, distrib=False)
117122
facets = "nominal_resolution,version"
118123
ctx = conn.new_context(
119124
project=project,
@@ -137,5 +142,5 @@ def download_meta_historic_biomassburning_single_var(
137142
self.logger.info(f"List of results :\n{result_list}")
138143

139144
download_metadata_variable(
140-
institution_id=institution_id, search_results=results, variable=variable, base_path=self.data_dir
145+
institution_id=institution_id, search_results=results, variable=variable, base_path=self.config.data_dir
141146
)

0 commit comments

Comments
 (0)