Skip to content
Snippets Groups Projects
Commit caf68737 authored by v.gramlich1's avatar v.gramlich1
Browse files

Workaround in statistics.py, climatological_skill_scores

parent b15528b9
Branches
Tags
1 merge request!302Draft: Resolve "Class-based Oversampling technique"
Pipeline #75568 passed
...@@ -301,6 +301,47 @@ class SkillScores: ...@@ -301,6 +301,47 @@ class SkillScores:
observation_name=self.observation_name) observation_name=self.observation_name)
for (first, second) in combinations] for (first, second) in combinations]
return skill_score return skill_score
'''
def climatological_skill_scores(self, internal_data: Data, forecast_name: str) -> xr.DataArray:
"""
Calculate climatological skill scores according to Murphy (1988).
Calculate all CASES I - IV and terms [ABC][I-IV]. Internal data has to be set by initialisation, external data
is part of parameters.
:param internal_data: internal data
:param forecast_name: name of the forecast to use for this calculation (must be available in `data`)
:return: all CASES as well as all terms
"""
ahead_names = list(self.external_data[self.ahead_dim].data)
all_terms = ['AI', 'AII', 'AIII', 'AIV', 'BI', 'BII', 'BIV', 'CI', 'CIV', 'CASE I', 'CASE II', 'CASE III',
'CASE IV']
skill_score = xr.DataArray(np.full((len(all_terms), len(ahead_names)), np.nan), coords=[all_terms, ahead_names],
dims=['terms', self.ahead_dim])
for iahead in ahead_names:
data = internal_data.sel({self.ahead_dim: iahead})
skill_score.loc[["CASE I", "AI", "BI", "CI"], iahead] = np.stack(self._climatological_skill_score(
data, mu_type=1, forecast_name=forecast_name, observation_name=self.observation_name).values.flatten())
skill_score.loc[["CASE II", "AII", "BII"], iahead] = np.stack(self._climatological_skill_score(
data, mu_type=2, forecast_name=forecast_name, observation_name=self.observation_name).values.flatten())
if self.external_data is not None and self.observation_name in self.external_data.coords["type"]:
external_data = self.external_data.sel({self.ahead_dim: iahead, "type": [self.observation_name]})
skill_score.loc[["CASE III", "AIII"], iahead] = np.stack(self._climatological_skill_score(
data, mu_type=3, forecast_name=forecast_name, observation_name=self.observation_name,
external_data=external_data).values.flatten())
skill_score.loc[["CASE IV", "AIV", "BIV", "CIV"], iahead] = np.stack(self._climatological_skill_score(
data, mu_type=4, forecast_name=forecast_name, observation_name=self.observation_name,
external_data=external_data).values.flatten())
return skill_score
'''
def climatological_skill_scores(self, internal_data: Data, forecast_name: str) -> xr.DataArray: def climatological_skill_scores(self, internal_data: Data, forecast_name: str) -> xr.DataArray:
""" """
...@@ -314,6 +355,9 @@ class SkillScores: ...@@ -314,6 +355,9 @@ class SkillScores:
:return: all CASES as well as all terms :return: all CASES as well as all terms
""" """
if self.external_data is None:
ahead_names = []
else:
ahead_names = list(self.external_data[self.ahead_dim].data) ahead_names = list(self.external_data[self.ahead_dim].data)
all_terms = ['AI', 'AII', 'AIII', 'AIV', 'BI', 'BII', 'BIV', 'CI', 'CIV', 'CASE I', 'CASE II', 'CASE III', all_terms = ['AI', 'AII', 'AIII', 'AIV', 'BI', 'BII', 'BIV', 'CI', 'CIV', 'CASE I', 'CASE II', 'CASE III',
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment