def experiment_loop_comparative( base_dat: str, cmip_dat: str, variable: str, spatial_window: int, subsample: Optional[int] = None, trial: int = 1, regrid_filename: Optional[str] = None, ) -> Dict: """Performs one experimental loop for calculating the IT measures for the models""" # 1.1) get base model base_dat = get_base_model(base_dat, variable) # 1.2) get cmip5 model cmip_dat = get_cmip5_model(cmip_dat, variable) # 2) regrid data w. reference grid and reference_ds = get_reference_dataset("noresm1_m") base_dat = regrid_data(reference_ds, base_dat, filename=regrid_filename + ".nc") cmip_dat = regrid_data(reference_ds, cmip_dat, filename=regrid_filename + ".nc") # 3) find overlapping times base_dat, cmip_dat = get_time_overlap(base_dat, cmip_dat) # 4) get density cubes base_df = get_spatial_cubes(base_dat, spatial_window) cmip_df = get_spatial_cubes(cmip_dat, spatial_window) # 5) normalize data base_df = normalize_data(base_df) cmip_df = normalize_data(cmip_df) # 6) Resample/ Subsample data base_df = resample(base_df, n_samples=subsample, random_state=trial) cmip_df = resample(cmip_df, n_samples=subsample, random_state=trial) # 7.1) Mutual Information mutual_info, time_mi = run_rbig_models(base_df, cmip_df, measure="mi", verbose=None) # 7.2 - Pearson, Spearman, KendelTau pearson = stats.pearsonr(base_df.ravel(), cmip_df.ravel())[0] spearman = stats.spearmanr(base_df.ravel(), cmip_df.ravel())[0] kendelltau = stats.kendalltau(base_df.ravel(), cmip_df.ravel())[0] results = { "mi": mutual_info, "time_mi": time_mi, "pearson": pearson, "spearman": spearman, "kendelltau": kendelltau, } return results
def experiment_loop_individual( base: str, cmip: str, variable: str, spatial_window: int, subsample: Optional[int] = None, trial: int = 1, batch_size: Optional[int] = None, regrid_filename: Optional[str] = None, ) -> Dict: """Performs one experimental loop for calculating the IT measures for the models""" # 1.1) get base model base_dat = get_base_model(base, variable) # 1.2) get cmip5 model cmip_dat = get_cmip5_model(cmip, variable) # 2) regrid data w. reference grid and reference_ds = get_reference_dataset("ipsl_cm5a_lr") base_dat = regrid_data(reference_ds, base_dat, filename=regrid_filename + ".nc") cmip_dat = regrid_data(reference_ds, cmip_dat, filename=regrid_filename + ".nc") # 3) find overlapping times base_dat, cmip_dat = get_time_overlap(base_dat, cmip_dat) # 4) get density cubes base_df = get_spatial_cubes(base_dat, spatial_window) cmip_df = get_spatial_cubes(cmip_dat, spatial_window) # 5) normalize data base_df = normalize_data(base_df) cmip_df = normalize_data(cmip_df) # 6) Resample/ Subsample data base_df = resample(base_df, n_samples=subsample, random_state=trial) cmip_df = resample(cmip_df, n_samples=subsample, random_state=trial) # 7.1 - Entropy tc_base, h_base, h_time_base = run_rbig_models(base_df, measure="h", verbose=None) # 7.1 - Total Correlation tc_cmip, h_cmip, h_time_cmip = run_rbig_models(cmip_df, measure="h", verbose=None) results = { "h_base": h_base, "tc_base": tc_base, "h_cmip": h_cmip, "tc_cmip": tc_cmip, "t_base": h_time_base, "t_cmip": h_time_cmip, } return results
def get_features_loop(base: str, cmip: str, variable: str, regrid_name: str) -> Dict: """Performs one experimental loop for calculating the IT measures for the models""" # 1.1) get base model # print(base) base_dat = get_base_model(base, variable) # 1.2) get cmip5 model cmip_dat = get_cmip5_model(cmip, variable, model="rcp") # 2) regrid data # 2) regrid data w. reference grid and reference_ds = get_reference_dataset("noresm1_m") base_dat = regrid_data(reference_ds, base_dat, filename=regrid_name + ".nc") cmip_dat = regrid_data(reference_ds, cmip_dat, filename=regrid_name + ".nc") # 3) find overlapping times base_dat, cmip_dat = get_time_overlap(base_dat, cmip_dat) return base_dat, cmip_dat
def experiment_loop_comparative( base: str, cmip: str, variable: str, spatial_window: int, subsample: Optional[int] = None, batch_size: Optional[int] = None, ) -> Dict: """Performs one experimental loop for calculating the IT measures for the models""" # 1.1) get base model base_dat = get_base_model(base, variable) # 1.2) get cmip5 model cmip_dat = get_cmip5_model(cmip, variable) # 2) regrid data base_dat, cmip_dat = regrid_2_lower_res(base_dat, cmip_dat) # 3) find overlapping times base_dat, cmip_dat = get_time_overlap(base_dat, cmip_dat) # 4) get density cubes base_df = get_spatial_cubes(base_dat, spatial_window) cmip_df = get_spatial_cubes(cmip_dat, spatial_window) # 5) normalize data base_df = normalize_data(base_df) cmip_df = normalize_data(cmip_df) # 7.1) Mutual Information print("Mutual Information") mutual_info, time_mi = run_rbig_models( base_df[:subsample], cmip_df[:subsample], measure="mi", verbose=1, batch_size=batch_size, ) # 7.2 - Pearson, Spearman, KendelTau print("Pearson") pearson = stats.pearsonr(base_df[:subsample].ravel(), cmip_df[:subsample].ravel())[0] print("Spearman") spearman = stats.spearmanr(base_df[:subsample].ravel(), cmip_df[:subsample].ravel())[0] print("KendelTau") kendelltau = stats.kendalltau(base_df[:subsample].ravel(), cmip_df[:subsample].ravel())[0] results = { "mi": mutual_info, "time_mi": time_mi, "pearson": pearson, "spearman": spearman, "kendelltau": kendelltau, } return results
def experiment_loop_individual( base: str, cmip: str, variable: str, spatial_window: int, subsample: Optional[int] = None, batch_size: Optional[int] = None, ) -> Dict: """Performs one experimental loop for calculating the IT measures for the models""" # 1.1) get base model base_dat = get_base_model(base, variable) # 1.2) get cmip5 model cmip_dat = get_cmip5_model(cmip, variable) # 2) regrid data base_dat, cmip_dat = regrid_2_lower_res(base_dat, cmip_dat) # 3) find overlapping times base_dat, cmip_dat = get_time_overlap(base_dat, cmip_dat) # 4) get density cubes base_df = get_spatial_cubes(base_dat, spatial_window) cmip_df = get_spatial_cubes(cmip_dat, spatial_window) # 5) normalize data base_df = normalize_data(base_df) cmip_df = normalize_data(cmip_df) # 7.1) Total Correlation print("TOTAL CORRELATION") print("Base Model") tc_base, time_base = run_rbig_models(base_df[:subsample], measure="t", verbose=1, batch_size=batch_size) print("CMIP Model") tc_cmip, time_cmip = run_rbig_models(cmip_df[:subsample], measure="t", verbose=1, batch_size=batch_size) # 7.2 - ENTROPY print("ENTROPY") print("Base Model") h_base, time_base = run_rbig_models(base_df[:subsample], measure="h", verbose=1, batch_size=batch_size) print("CMIP Model") h_cmip, time_cmip = run_rbig_models(cmip_df[:subsample], measure="h", verbose=1, batch_size=batch_size) results = { "h_base": h_base, "tc_base": tc_base, "h_cmip": h_cmip, "tc_cmip": tc_cmip, "t_base": time_base, "t_cmip": time_cmip, } return results