Skip to content

Commit

Permalink
profiles vized. need to change alt units
Browse files Browse the repository at this point in the history
  • Loading branch information
lewisblake committed Sep 5, 2023
1 parent 7e2da85 commit df098fc
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 24 deletions.
33 changes: 21 additions & 12 deletions pyaerocom/aeroval/coldatatojson_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,6 @@ def process_coldata(self, coldata: ColocatedData):
if not diurnal_only:
logger.info("Processing statistics timeseries for all regions")
input_freq = self.cfg.statistics_opts.stats_tseries_base_freq

for reg in regnames:
try:
stats_ts = _process_statistics_timeseries(
Expand Down Expand Up @@ -301,27 +300,37 @@ def process_coldata(self, coldata: ColocatedData):
"vertical_layer" in coldata.data.attrs
): # LB: Will need some sort of additional flag to deal with the two colocation level types
logger.info("Processing profile data for vizualization")
# Loop through regions
for regid in regnames:
profile_viz = process_profile_data(
data=data,
region_id=regid,
station_name=None,
use_country=use_country,
periods=periods,
seasons=seasons,
)

# for regid in regnames:
fname = get_profile_filename(regnames[regid], obs_name, var_name_web)

outfile_profile = os.path.join(out_dirs["profiles"], fname)
add_profile_entry_json(outfile_profile, data, profile_viz, periods, seasons)
# Loop through stations
for station_name in coldata.data.station_name.values:
profile_viz = process_profile_data(
data,
station_name,
use_country,
periods,
seasons,
data=data,
region_id=None,
station_name=station_name,
use_country=use_country,
periods=periods,
seasons=seasons,
)

fname = get_profile_filename(station_name, obs_name, var_name_web)

outfile_profile = os.path.join(out_dirs["profiles"], fname)
add_profile_entry_json(outfile_profile, data, profile_viz, periods, seasons)

# for reg in regions:
# fname = get_profile_filename(reg, obs_name, var_name_web)

# add_profile_entry(fname, )

logger.info(
f"Finished computing json files for {model_name} ({model_var}) vs. "
f"{obs_name} ({obs_var})"
Expand Down
34 changes: 22 additions & 12 deletions pyaerocom/aeroval/coldatatojson_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1365,13 +1365,13 @@ def _start_stop_from_periods(periods):
return start_stop(start, stop + 1)


def get_profile_filename(station_name, obs_name, var_name_web):
return f"{station_name}_{obs_name}_{var_name_web}.json"
def get_profile_filename(station_or_region_name, obs_name, var_name_web):
return f"{station_or_region_name}_{obs_name}_{var_name_web}.json"


def process_profile_data(
data,
# region_id,
region_id,
station_name,
use_country,
periods,
Expand All @@ -1398,13 +1398,23 @@ def process_profile_data(
output["mod"][freq][perstr] = np.nan
else:
try:
all_stations_subset = _select_period_season_coldata(coldata, per, season)
station_subset = all_stations_subset.data[
:, :, all_stations_subset.data.station_name.values == station_name
] # LB: Assumes ordering of station name matches

output["obs"][freq][perstr] = np.nanmean(station_subset.data[0, :, :])
output["mod"][freq][perstr] = np.nanmean(station_subset.data[1, :, :])
per_season_subset = _select_period_season_coldata(coldata, per, season)
if region_id is not None:
# try: # get the subset for this station or region
subset = per_season_subset.filter_region(
region_id=region_id, check_country_meta=use_country
)
# except UnknownRegion:
if station_name is not None:
subset = per_season_subset.data[
:,
:,
per_season_subset.data.station_name.values
== station_name, # in this case a station
] # LB: Assumes ordering of station name matches

output["obs"][freq][perstr] = np.nanmean(subset.data[0, :, :])
output["mod"][freq][perstr] = np.nanmean(subset.data[1, :, :])

except:
msg = f"Failed to access subset timeseries, and will skip."
Expand All @@ -1429,7 +1439,7 @@ def add_profile_entry_json(profile_file, data, profile_viz, periods, seasons):
if not model_name in current:
current[model_name] = {}
# on = ov[obs_name]

breakpoint()
if not "z" in current[model_name]:
current[model_name]["z"] = [
0
Expand Down Expand Up @@ -1465,7 +1475,7 @@ def add_profile_entry_json(profile_file, data, profile_viz, periods, seasons):

if not "metadata" in current[model_name]:
# should be same for all. hardcoded because no way to pass this all along now
current["metadata"] = {
current[model_name]["metadata"] = {
"z_unit": "m",
"z_description": "Altitude ASL",
"z_long_description": "Altitude Above Sea Level",
Expand Down

0 comments on commit df098fc

Please sign in to comment.