Ejemplo n.º 1
0
def get_bfe_in_annual_max(varnames,
                          level_index_dict=None,
                          path_to_era_driven="",
                          path_to_gcm_driven="",
                          start_year=None,
                          end_year=None):
    if level_index_dict is None:
        level_index_dict = collections.defaultdict(lambda: 0)

    finfo_to_season_to_diff = OrderedDict()
    for vname in varnames:
        finf = FieldInfo(vname, start_year, end_year)

        era = analysis.get_annual_maxima(path_to_hdf_file=path_to_era_driven,
                                         start_year=start_year,
                                         end_year=end_year,
                                         var_name=vname,
                                         level=level_index_dict[vname])

        gcm = analysis.get_annual_maxima(path_to_hdf_file=path_to_gcm_driven,
                                         start_year=start_year,
                                         end_year=end_year,
                                         var_name=vname,
                                         level=level_index_dict[vname])

        finfo_to_season_to_diff[finf] = {
            "Annual maximum":
            np.mean(list(gcm.values()), axis=0) -
            np.mean(list(era.values()), axis=0)
        }

    return finfo_to_season_to_diff
Ejemplo n.º 2
0
def get_bfe_in_annual_max(varnames, level_index_dict=None,
                          path_to_era_driven="", path_to_gcm_driven="",
                          start_year=None, end_year=None):
    if level_index_dict is None:
        level_index_dict = collections.defaultdict(lambda: 0)

    finfo_to_season_to_diff = OrderedDict()
    for vname in varnames:
        finf = FieldInfo(vname, start_year, end_year)

        era = analysis.get_annual_maxima(path_to_hdf_file=path_to_era_driven,
                                         start_year=start_year, end_year=end_year,
                                         var_name=vname, level=level_index_dict[vname])

        gcm = analysis.get_annual_maxima(path_to_hdf_file=path_to_gcm_driven,
                                         start_year=start_year, end_year=end_year,
                                         var_name=vname, level=level_index_dict[vname])

        finfo_to_season_to_diff[finf] = {
            "Annual maximum": np.mean(list(gcm.values()), axis=0) - np.mean(list(era.values()), axis=0)
        }

    return finfo_to_season_to_diff
Ejemplo n.º 3
0
def do_calculations(data_path=None, lay_widths=None, start_year=None, end_year=None):

    cache = get_cache_file(**locals())


    if os.path.isfile(cache):
        return pickle.load(open(cache, "rb"))


    alt_data_manager = CRCMDataManager(layer_widths=lay_widths)

    tsoil3d_field = None


    for lev in range(len(lay_widths)):
        field_dict = analysis.get_annual_maxima(path_to_hdf_file=data_path, var_name="I0", level=lev,
                                                start_year=start_year, end_year=end_year)

        field = np.max([fi for fi in field_dict.values()], axis=0)

        if tsoil3d_field is None:
            tsoil3d_field = np.zeros(field.shape + (len(lay_widths), ))

        print("lev, min, max = {}, {}, {}".format(lev, field.min(), field.max()))

        plt.figure()
        img = plt.contourf(field)
        plt.colorbar(img)
        plt.show()

        tsoil3d_field[:, :, lev] = field

    alt_field = alt_data_manager.get_alt(tsoil3d_field)

    with open(cache, "wb") as f:
        pickle.dump(alt_field, f)

    return alt_field