Skip to content

Commit

Permalink
obs_config -> pyaro_config, data_id -> reader_id
Browse files Browse the repository at this point in the history
  • Loading branch information
magnusuMET authored and thorbjoernl committed Dec 2, 2024
1 parent e5f5c8a commit 9479865
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 36 deletions.
34 changes: 17 additions & 17 deletions pyaerocom/colocation/colocation_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class ColocationSetup(BaseModel):
model_id : str
ID of model to be used.
obs_config: PyaroConfig
pyaro_config: PyaroConfig
In the case Pyaro is used, a config must be provided. In that case obs_id(see below)
is ignored and only the config is used.
obs_id : str
Expand Down Expand Up @@ -335,7 +335,7 @@ def validate_start_stop(cls, v):
if isinstance(v, str):
return pd.Timestamp(v)

obs_config: PyaroConfig | None = None
pyaro_config: PyaroConfig | None = None

###############################
# Attributes with defaults
Expand Down Expand Up @@ -450,7 +450,7 @@ def validate_kwargs(cls, v):
def __init__(
self,
model_id: str | None = None,
obs_config: PyaroConfig | None = None,
pyaro_config: PyaroConfig | None = None,
obs_id: str | None = None,
obs_vars: tuple[str, ...] | None = (),
ts_type: str = "monthly",
Expand All @@ -462,7 +462,7 @@ def __init__(
) -> None:
super().__init__(
model_id=model_id,
obs_config=obs_config,
pyaro_config=pyaro_config,
obs_id=obs_id,
obs_vars=obs_vars,
ts_type=ts_type,
Expand All @@ -489,25 +489,25 @@ def basedir_logfiles(self):
return str(p)

@model_validator(mode="after")
def validate_obs_config(self):
if self.obs_config is None:
def validate_pyaro_config(self):
if self.pyaro_config is None:
return self
if self.obs_config.name != self.obs_id:
if self.pyaro_config.name != self.obs_id:
logger.info(
f"Data ID in Pyaro config {self.obs_config.name} does not match obs_id {self.obs_id}. Setting Pyaro config to None!"
f"Data ID in Pyaro config {self.pyaro_config.name} does not match obs_id {self.obs_id}. Setting Pyaro config to None!"
)
self.obs_config = None
if self.obs_config is not None:
if isinstance(self.obs_config, dict):
logger.info("Obs config was given as dict. Will try to convert to PyaroConfig")
self.obs_config = PyaroConfig(**self.obs_config)
if self.obs_config.name != self.obs_id:
self.pyaro_config = None
if self.pyaro_config is not None:
if isinstance(self.pyaro_config, dict):
logger.info("pyaro config was given as dict. Will try to convert to PyaroConfig")
self.pyaro_config = PyaroConfig(**self.pyaro_config)
if self.pyaro_config.name != self.obs_id:
logger.info(
f"Data ID in Pyaro config {self.obs_config.name} does not match obs_id {self.obs_id}. Setting Obs ID to match Pyaro Config!"
f"Data ID in Pyaro config {self.pyaro_config.name} does not match obs_id {self.obs_id}. Setting Obs ID to match Pyaro Config!"
)
self.obs_id = self.obs_config.name
self.obs_id = self.pyaro_config.name
if self.obs_id is None:
self.obs_id = self.obs_config.name
self.obs_id = self.pyaro_config.name
return self

def add_glob_meta(self, **kwargs):
Expand Down
4 changes: 2 additions & 2 deletions pyaerocom/colocation/colocator.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def obs_is_ungridded(self):
"""
bool: True if obs_id refers to an ungridded observation, else False
"""
if self.colocation_setup.obs_config is not None:
if self.colocation_setup.pyaro_config is not None:
return True

return True if self.colocation_setup.obs_id in get_all_supported_ids_ungridded() else False
Expand Down Expand Up @@ -196,7 +196,7 @@ def obs_reader(self):
data_ids=[self.colocation_setup.obs_id],
data_dirs=self.colocation_setup.obs_data_dir,
configs=[
self.colocation_setup.obs_config,
self.colocation_setup.pyaro_config,
],
)
else:
Expand Down
2 changes: 1 addition & 1 deletion pyaerocom/io/pyaro/pyaro_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class PyaroConfig(BaseModel):
##########################

name: str
data_id: str
reader_id: str
filename_or_obj_or_url: str | list[str] | Path | list[Path]
filters: dict[str, FilterArgs]
name_map: dict[str, str] | None = None # no Unit conversion option
Expand Down
12 changes: 6 additions & 6 deletions pyaerocom/io/pyaro/read_pyaro.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ def read_file(self, filename, vars_to_retrieve=None):

def _check_id(self):
avail_readers = list_timeseries_engines()
if self.config.data_id not in avail_readers:
if self.config.reader_id not in avail_readers:
logger.warning(
f"Could not find {self.config.data_id} in list of available Pyaro readers: {avail_readers}"
f"Could not find {self.config.reader_id} in list of available Pyaro readers: {avail_readers}"
)


Expand All @@ -105,23 +105,23 @@ def __init__(self, config: PyaroConfig) -> None:
self.reader: Reader = self._open_reader()

def _open_reader(self) -> Reader:
data_id = self.config.data_id
reader_id = self.config.reader_id
if self.config.model_extra is not None:
kwargs = self.config.model_extra
else:
kwargs = {}

if self.config.name_map is None:
return open_timeseries(
data_id,
reader_id,
self.config.filename_or_obj_or_url,
filters=self.config.filters,
**kwargs,
)
else:
return VariableNameChangingReader(
open_timeseries(
data_id,
reader_id,
self.config.filename_or_obj_or_url,
filters=self.config.filters,
**kwargs,
Expand Down Expand Up @@ -244,7 +244,7 @@ def read(self, vars_to_retrieve=None) -> UngriddedData:
for var in vars_to_retrieve:
if var not in allowed_vars:
logger.warning(
f"Variable {var} not in list over allowed variabes for {self.config.data_id}: {allowed_vars}"
f"Variable {var} not in list over allowed variabes for {self.config.reader_id}: {allowed_vars}"
)
continue

Expand Down
2 changes: 1 addition & 1 deletion pyaerocom/io/readungridded.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ class :class:`ReadUngriddedBase`)
reader = ReadPyaro(config=config)
self._readers[name] = reader
self._data_ids.append(name)
self.config_ids[name] = config.data_id
self.config_ids[name] = config.reader_id
self.config_map[name] = config
return reader

Expand Down
2 changes: 1 addition & 1 deletion tests/colocation/test_colocator.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ def test_colocator_with_obs_data_dir_gridded(setup):

def test_colocation_pyaro(pyaro_testconfig, fake_aod_MSCWCtm_data_monthly_2010, setup) -> None:
config = pyaro_testconfig[0]
setup["obs_config"] = config
setup["pyaro_config"] = config
setup["model_id"] = "EMEP"
setup["gridded_reader_id"] = {"model": "ReadMscwCtm"}
setup["model_data_dir"] = fake_aod_MSCWCtm_data_monthly_2010
Expand Down
10 changes: 5 additions & 5 deletions tests/fixtures/pyaro.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,19 @@ def make_csv_test_file(tmp_path: Path) -> Path:


def testconfig(tmp_path: Path) -> PyaroConfig:
data_id = "csv_timeseries"
reader_id = "csv_timeseries"

config1 = PyaroConfig(
name="test",
data_id=data_id,
reader_id=reader_id,
filename_or_obj_or_url=str(make_csv_test_file(tmp_path)),
filters={},
name_map={"SOx": "concso4", "AOD": "od550aer"},
)

config2 = PyaroConfig(
name="test2",
data_id=data_id,
reader_id=reader_id,
filename_or_obj_or_url=str(make_csv_test_file(tmp_path)),
filters={},
name_map={"SOx": "concso4", "AOD": "od550aer"},
Expand All @@ -63,7 +63,7 @@ def testconfig(tmp_path: Path) -> PyaroConfig:


def testconfig_kwargs(tmp_path: Path) -> PyaroConfig:
data_id = "csv_timeseries"
reader_id = "csv_timeseries"
columns = {
"variable": 0,
"station": 1,
Expand All @@ -82,7 +82,7 @@ def testconfig_kwargs(tmp_path: Path) -> PyaroConfig:

config = PyaroConfig(
name="test",
data_id=data_id,
reader_id=reader_id,
filename_or_obj_or_url=str(make_csv_test_file(tmp_path)),
filters={},
name_map={"SOx": "concso4"},
Expand Down
4 changes: 2 additions & 2 deletions tests/io/pyaro/test_pyaro_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
def get_test_config() -> PyaroConfig:
config = PyaroConfig(
name="test",
data_id="test",
reader_id="test",
filename_or_obj_or_url="test",
filters={},
name_map={},
Expand All @@ -21,7 +21,7 @@ def get_test_config() -> PyaroConfig:
def get_existing_config() -> PyaroConfig:
config = PyaroConfig(
name="aeronetsun_test",
data_id="test",
reader_id="test",
filename_or_obj_or_url="test",
filters={},
name_map={},
Expand Down
2 changes: 1 addition & 1 deletion tests/io/test_readungridded.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def test_supported_pyaro(pyaro_testconfig):
reader = ReadUngridded(configs=pyaro_testconfig)

assert ReadPyaro in reader.SUPPORTED_READERS
assert pyaro_testconfig[0].data_id in reader.supported_datasets
assert pyaro_testconfig[0].reader_id in reader.supported_datasets


def test_read_pyaro_and_other(pyaro_testconfig):
Expand Down

0 comments on commit 9479865

Please sign in to comment.