imarkonis / ithaca

MIT License
0 stars 5 forks source link

created rank_repres function #185

Closed MiRoVaGo closed 3 months ago

MiRoVaGo commented 3 months ago

closes #167

temporarily located at ithaca/source/rank_repres.R inputs: data (data.table) with three variables: dataset, date, value method (character) with seven options: mean, var (variance), slope, kge (Kling–Gupta Efficiency), tss (Taylor Skill Score), kld (Kullback–Leibler Divergence), all (default) ensemble (character) with two options: mean, median (default) output: data.table with representativeness metric based on the selected method with respect to the ensemble mean/median. For any method other than "all" output has two variables: dataset, repres_metric For method "all" output has seven variables: dataset, mean, variance, slope, kge, tss, kld

Note

The representativeness metric is computed as 1 - abs((Xs - Xo)/Xo) Where Xs is the mean/variance/slope of a dataset, and Xo is the corresponding mean/variance/solpe of the ensemble. In other words, a relative difference of 100% or higher is deemed as not representative (repres_metric = 0)

Demo

source("~/ithaca/source/crop_catchment.R")
source("~/ithaca/source/aggregate_ts_catchment.R")
source("~/ithaca/source/rank_repres.R")

dummie_test <- crop_catchment(lon = 0.75, lat = 41.5,
                              dataset_fnames = c("~/shared/data/obs/precip/raw/gpm-imerg-v7_tp_mm_land_200006_202304_025_monthly.nc",
                                                 "~/shared/data/sim/precip/raw/terraclimate_tp_mm_land_195801_202112_025_monthly.nc",
                                                 "~/shared/data/sim/precip/raw/era5-land_tp_mm_land_195001_202112_025_monthly.nc"),
                              catchment_level = 3)

dummie_ts <- aggregate_ts_catchment(dummie_test)

dummie_ts <- dummie_ts[year(date) >= 2001 & year(date) <= 2019,
                       .(dataset, date, value)]

dummie_rank <- rank_repres(dummie_ts)

dummie_rank
dataset mean variance slope kge tss kld
era5-land 0.9519921 0.9952067 0.68001604 0.9343780 0.9948200 1.0000000
gpm-imerg-v7 0.9523014 0.7990231 0.79775781 0.9327233 0.9858977 1.0000000
terraclimate 0.8788934 0.8481994 0.08939963 0.8679664 0.9824497 0.9806118