Skip to content

Commit

Permalink
Merge pull request #1317 from metno/fix-profiles-issue
Browse files Browse the repository at this point in the history
Fix aerovaldb profiles arguments issue
  • Loading branch information
lewisblake authored Aug 19, 2024
2 parents 26414f5 + 5e1b98f commit f73e411
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 7 deletions.
26 changes: 23 additions & 3 deletions pyaerocom/aeroval/coldatatojson_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,8 @@ def process_coldata(self, coldata: ColocatedData):
station_names=coldata.data.station_name.values,
periods=periods,
seasons=seasons,
obs_name=obs_name,
var_name_web=var_name_web,
)

logger.info(
Expand Down Expand Up @@ -276,6 +278,8 @@ def _process_profile_data_for_visualization(
station_names: ArrayLike = None,
periods: tuple[str, ...] = None,
seasons: tuple[str, ...] = None,
obs_name: str = None,
var_name_web: str = None,
):
if region_names is None and station_names is None:
raise ValueError("Both region_id and station_name can not both be None")
Expand All @@ -289,8 +293,16 @@ def _process_profile_data_for_visualization(
periods=periods,
seasons=seasons,
)

self.exp_output.add_profile_entry(data, profile_viz, periods, seasons)
location = region_names[regid]
self.exp_output.add_profile_entry(
data,
profile_viz,
periods,
seasons,
location=location,
network=obs_name,
obsvar=var_name_web,
)

# Loop through stations
for station_name in station_names:
Expand All @@ -302,7 +314,15 @@ def _process_profile_data_for_visualization(
seasons=seasons,
)

self.exp_output.add_profile_entry(data, profile_viz, periods, seasons)
self.exp_output.add_profile_entry(
data,
profile_viz,
periods,
seasons,
location=station_name,
network=obs_name,
obsvar=var_name_web,
)

def _process_stats_timeseries_for_all_regions(
self,
Expand Down
15 changes: 12 additions & 3 deletions pyaerocom/aeroval/experiment_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -1030,7 +1030,14 @@ def write_timeseries(self, data):
)

def add_profile_entry(
self, data: ColocatedData, profile_viz: dict, periods: list[str], seasons: list[str]
self,
data: ColocatedData,
profile_viz: dict,
periods: list[str],
seasons: list[str],
location,
network,
obsvar,
):
"""Adds an entry for the colocated data to profiles.json.
Expand All @@ -1041,7 +1048,9 @@ def add_profile_entry(
seasons (list[str]): seasons to compute over (e.g., All, DJF, etc.)
"""
with self.avdb.lock():
current = self.avdb.get_profiles(self.proj_id, self.exp_id, default={})
current = self.avdb.get_profiles(
self.proj_id, self.exp_id, location, network, obsvar, default={}
)
current = recursive_defaultdict(current)

for freq, coldata in data.items():
Expand Down Expand Up @@ -1084,4 +1093,4 @@ def add_profile_entry(
}
current[model_name] = round_floats(current[model_name])

self.avdb.put_profiles(current, self.proj_id, self.exp_id)
self.avdb.put_profiles(current, self.proj_id, self.exp_id, location, network, obsvar)
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ classifiers = [
]
requires-python = ">=3.10"
dependencies = [
"aerovaldb == 0.0.15",
"aerovaldb==0.0.17",
"scitools-iris>=3.8.1",
"xarray>=2022.12.0",
"cartopy>=0.21.1",
Expand Down

0 comments on commit f73e411

Please sign in to comment.