Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add Fairmode statistic to aeroval output #613

Merged
merged 22 commits into from
Mar 30, 2022
Merged

add Fairmode statistic to aeroval output #613

merged 22 commits into from
Mar 30, 2022

Conversation

avaldebe
Copy link
Collaborator

close #601

@avaldebe avaldebe added this to the v0.13.0 milestone Mar 30, 2022
@codecov
Copy link

codecov bot commented Mar 30, 2022

Codecov Report

Merging #613 (d60f560) into main-dev (3b1ffbb) will increase coverage by 0.02%.
The diff coverage is 88.37%.

@@             Coverage Diff              @@
##           main-dev     #613      +/-   ##
============================================
+ Coverage     76.96%   76.99%   +0.02%     
============================================
  Files            97       98       +1     
  Lines         17503    17546      +43     
============================================
+ Hits          13471    13509      +38     
- Misses         4032     4037       +5     
Flag Coverage Δ
unittests 76.99% <88.37%> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
pyaerocom/aeroval/coldatatojson_helpers.py 71.73% <50.00%> (-0.15%) ⬇️
pyaerocom/aeroval/fairmode_stats.py 91.89% <91.89%> (ø)
pyaerocom/aeroval/coldatatojson_engine.py 85.71% <100.00%> (+0.13%) ⬆️
pyaerocom/aeroval/setupclasses.py 93.25% <100.00%> (+0.03%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3b1ffbb...d60f560. Read the comment docs.

Copy link
Collaborator Author

@avaldebe avaldebe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some small things to clean up

Comment on lines 7 to 8
from math import sqrt
from typing import Tuple
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unused imports?

Comment on lines 1361 to 1438


def _get_RMSU(mean: float, std: float, species: str) -> Tuple[float, float, float, float]:
species_values = dict(
concno2=dict(
UrRV=0.24,
RV=200,
alpha=0.2,
),
vmro3=dict(
UrRV=0.18,
RV=120,
alpha=0.79,
),
concpm10=dict(
UrRV=0.28,
RV=50,
alpha=0.13,
),
concpm25=dict(
UrRV=0.28,
RV=25,
alpha=0.3,
),
)

if species not in species_values.keys():
raise KeyError(f"Species {species} not in list {species_values.keys()}")

UrRV = species_values[species]["UrRV"]
RV = species_values[species]["RV"]
alpha = species_values[species]["alpha"]

in_sqrt = (1 - alpha ** 2) * (mean ** 2 + std ** 2) + alpha ** 2 * RV ** 2

return UrRV * sqrt(in_sqrt), UrRV, RV, alpha


def _get_fairmode_sign(mod_std: float, obs_std: float, R: float) -> float:
if obs_std * sqrt(2 * (1 - R)) == 0:
return 1
a = abs(mod_std - obs_std) / (obs_std * sqrt(2 * (1 - R)))
return 1 if a >= 1 else -1


def _get_crms(mod_std: float, obs_std: float, R: float) -> float:
return sqrt(mod_std ** 2 + obs_std ** 2 - 2 * mod_std * obs_std * R)


def _process_fairmode(obs_var, stats):
species_list = ["concno2", "vmro3", "concpm10", "concpm25"]

fairmode_stats = dict()

if obs_var not in species_list:
return fairmode_stats

mean = stats["refdata_mean"]
obs_std = stats["refdata_std"]
mod_std = stats["data_std"]
R = stats["R"]
bias = stats["mb"]
rms = stats["rms"]

crms = _get_crms(mod_std, obs_std, R) # sqrt(rms ** 2 - bias ** 2)
sign = _get_fairmode_sign(mod_std, obs_std, R)
rmsu, UrRV, RV, alpha = _get_RMSU(mean, obs_std, obs_var)

fairmode_stats["RMSU"] = rmsu
fairmode_stats["sign"] = sign
fairmode_stats["crms"] = crms
fairmode_stats["bias"] = bias
fairmode_stats["rms"] = rms
fairmode_stats["alpha"] = alpha
fairmode_stats["UrRV"] = UrRV
fairmode_stats["RV"] = RV

return fairmode_stats
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

duplicated code, see fairmode_stats.py

@dulte dulte self-requested a review March 30, 2022 12:11
Copy link
Collaborator

@dulte dulte left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ready to merge

@dulte dulte marked this pull request as ready for review March 30, 2022 12:12
@dulte dulte merged commit 5f20152 into main-dev Mar 30, 2022
@dulte dulte deleted the fairmode branch March 30, 2022 12:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CAMS2_83 FAIRMODE metrics in pyaerocom
3 participants