Tables module#

The tables module gathers functions designed to show scores computed from Evaluator objects in a tabular layout or store them in text files.

Median of station scores#

The function median_station_scores displays a given list of scores for a given list of Evaluator objects.

Scores from exceedances contingency tables#

The function exceedances_scores displays scores from the contingency table of a given list of Evaluator objects.

Example#

In [1]: import evaltools as evt

In [2]: from datetime import date, timedelta

In [3]: stations = evt.utils.read_listing("./sample_data/listing")

In [4]: start_date = date(2017, 6, 1)

In [5]: end_date = date(2017, 6, 4)

In [6]: observations = evt.Observations.from_time_series(
   ...:     generic_file_path="./sample_data/observations/{year}_no2_{station}",
   ...:     correc_unit=1e9,
   ...:     species='no2',
   ...:     start=start_date,
   ...:     end=end_date,
   ...:     stations = stations,
   ...:     forecast_horizon=2)
   ...: 

In [7]: objs = {}

In [8]: daily_objs = {}

In [9]: for model in ['ENS', 'MFM']:
   ...:     generic_file_path = (
   ...:         f"../doc/sample_data/{model}forecast/"
   ...:         "J{forecast_day}/{year}_no2_{station}"
   ...:     )
   ...:     stations_idx = observations.stations.index
   ...:     simulations = evt.Simulations.from_time_series(
   ...:         generic_file_path=generic_file_path,
   ...:         stations_idx=stations_idx,
   ...:         correc_unit=1,
   ...:         species='no2',
   ...:         model=model,
   ...:         start=start_date,
   ...:         end=end_date,
   ...:         forecast_horizon=2,
   ...:     )
   ...:     objs[model] = evt.Evaluator(observations, simulations)
   ...:     daily_objs[model] = objs[model].daily_max()
   ...: 
In [10]: evt.tables.median_station_scores(
   ....:     objs.values(),
   ....:     forecast_day=0,
   ....:     score_list=['RMSE', 'MeanBias', 'PearsonR'],
   ....: )
   ....: 
         RMSE  MeanBias  PearsonR
ENS  9.148952 -3.291864  0.506106
MFM  9.871666 -3.013708  0.336417
In [11]: evt.tables.exceedances_scores(
   ....:     daily_objs.values(),
   ....:     forecast_day=0,
   ....:     thresholds=[20, 30, 40],
   ....: )
   ....: 
threshold = 20
     accuracy  bias_score  success_ratio  hit_rate  false_alarm_ratio  prob_false_detect  threat_score  equitable_ts  peirce_ss  heidke_ss  rousseau_ss  odds_ratio  odds_ratio_ss
ENS  0.596154    0.482759       0.785714  0.379310           0.214286           0.130435      0.343750      0.131955   0.248876   0.233146     0.167366    4.074074       0.605839
MFM  0.653846    0.655172       0.789474  0.517241           0.210526           0.173913      0.454545      0.196567   0.343328   0.328551     0.303571    5.089286       0.671554


threshold = 30
     accuracy  bias_score  success_ratio  hit_rate  false_alarm_ratio  prob_false_detect  threat_score  equitable_ts  peirce_ss  heidke_ss  rousseau_ss  odds_ratio  odds_ratio_ss
ENS  0.653846    0.181818          1.000  0.181818                NaN                NaN      0.181818      0.113636   0.181818   0.204082     0.076923         NaN            NaN
MFM  0.692308    0.363636          0.875  0.318182              0.125           0.033333      0.304348      0.184314   0.284848   0.311258     0.250450   13.533333       0.862385


threshold = 40
     accuracy  bias_score  success_ratio  hit_rate  false_alarm_ratio  prob_false_detect  threat_score  equitable_ts  peirce_ss  heidke_ss  rousseau_ss  odds_ratio  odds_ratio_ss
ENS  0.692308         NaN            NaN       NaN                NaN                NaN           NaN      0.000000   0.000000   0.000000    -0.181818         NaN            NaN
MFM  0.750000      0.3125            0.8      0.25                0.2           0.027778      0.235294      0.159204   0.222222   0.274678     0.224326   11.666667       0.842105


Out[11]: 
[     accuracy  bias_score  ...  odds_ratio  odds_ratio_ss
 ENS  0.596154    0.482759  ...    4.074074       0.605839
 MFM  0.653846    0.655172  ...    5.089286       0.671554
 
 [2 rows x 13 columns],
      accuracy  bias_score  ...  odds_ratio  odds_ratio_ss
 ENS  0.653846    0.181818  ...         NaN            NaN
 MFM  0.692308    0.363636  ...   13.533333       0.862385
 
 [2 rows x 13 columns],
      accuracy  bias_score  ...  odds_ratio  odds_ratio_ss
 ENS  0.692308         NaN  ...         NaN            NaN
 MFM  0.750000      0.3125  ...   11.666667       0.842105
 
 [2 rows x 13 columns]]