예제 #1
0
def load_exp_agr(force_new_hdf5_generation, name_hdf5_file, input_folder, haz_real):
    """
    

    Parameters
    ----------
    Load generate Exposure of agriculture if forced or if hdf5 file not present. 
    Otherwise load hdf5 file.

    Parameters
    ----------
    force_new_hdf5_generation : dict of bool
        contains bool wether new Exposure should be forcefully generated.
    name_hdf5_file : str
        name of hdf5 file from wich Exposure is loaded.
    input_folder : str
        Path to input folder containing hdf5 file.
    haz_real : climada.hazard.base.Hazard
        CLIMADA hazard.

    Returns
    -------
    exp_infr : climada.entity.exposures.base.Exposures
        CLIMADA Exposure of Exposure.

    """
    file1 = Path(input_folder + "/" + name_hdf5_file["exp_agr"])
    file2 = Path(input_folder + "/" + "exp_agr_no_centr.hdf5")
    if not file2.exists() and not file1.exists():
        print("Please use import_agrar_exposure to create the hdf5 file!" + 
              " and move it to the input folder")
        sys.exit()
    elif force_new_hdf5_generation["exp_agr"]: #be carefull, this step will take ages when you do both at once
        if not file2.exists():
                    print("Please use import_agrar_exposure to create the hdf5 file!" + 
                          " and move it to the input folder")
                    sys.exit()
        exp_agr = Exposures()
        exp_agr.read_hdf5(input_folder + "/exp_agr_no_centr.hdf5")
    
        exp_agr.check()
        exp_agr.assign_centroids(haz_real, method = "NN", distance = "haversine", threshold = 2)
        exp_agr.check()
        exp_agr.write_hdf5(input_folder + "/exp_agr.hdf5")
    
    else:
        #Agrar Exposure    
        exp_agr = Exposures()
        exp_agr.read_hdf5(input_folder + "/exp_agr.hdf5")
        exp_agr.check()
    return exp_agr
def exp_dem(x_exp=1):
    exp = Exposures()
    exp.read_hdf5(EXP_DEMO_H5)
    exp.gdf.value *= x_exp
    exp.check()
    return exp