def apply_sub_gcm_deltas(settings):
    """    
    Apply substitute gcm delta data to a WATERSimulation \*.xml file(s).  
    User supplies the gcm tiles to a text file that will be 
    contained in the info directory with a name specified in the user_settings.py file 

    Parameters
    ----------
    settings : dictionary
        Dictionary of user settings                 

    Notes
    -----
    Uses settings set in user_settings.py  
    """   

    # create output directories and files   
    info_dir, gcm_delta_dir, info_file = create_output_dirs_files(settings, is_sub_gcm_delta = True)

    # initialize error logging in info_dir
    waterapputils_logging.initialize_loggers(output_dir = info_dir) 

    # write all future print strings to the info_file
    sys.stdout = open(info_file, "w")  

    # get the intersecting points (centroids) based on wateruse non-intersecting_file
    intersecting_tiles = spatialvectors.read_field_values_file(filepath = os.path.join(info_dir, settings["gcm_delta_non_intersecting_file_name"]))

    # apply the wateruse     
    process_intersecting_centroids(intersecting_centroids, settings, gcm_delta_dir)

    waterapputils_logging.remove_loggers()
def apply_gcm_deltas(settings):
    """    
    Apply global climate model delta factor data to a WATERSimulation \*.xml file(s). 

    Parameters
    ----------
    settings : dictionary
        Dictionary of user settings                 

    Notes
    -----
    Uses settings set in user_settings.py  
    """   

	# create output directories and files   
    info_dir, gcm_delta_dir, info_file = create_output_dirs_files(settings)

    # initialize error logging in info_dir
    waterapputils_logging.initialize_loggers(output_dir = info_dir) 

    # write all future print strings to the info_file
    sys.stdout = open(info_file, "w")  
    
    # open shapefiles
    gcm_delta_tile_shapefile = osgeo.ogr.Open(settings["gcm_delta_tile_shapefile"]) 
    basin_shapefile = osgeo.ogr.Open(os.path.join(settings["simulation_directory"], settings["basin_shapefile_name"])) 

    # find intersecting points (centroids) based on water basin supplied
    intersecting_tiles_all = spatialvectors.get_intersected_field_values(intersector = basin_shapefile, intersectee = gcm_delta_tile_shapefile, intersectee_field = settings["gcm_delta_tile_shapefile_id_field"], intersector_field = settings["basin_shapefile_id_field"])

    intersecting_tiles, nonintersecting_tiles = spatialvectors.validate_field_values(field_values_dict = intersecting_tiles_all)     

    # apply gcm deltas
    if intersecting_tiles:    
        process_intersecting_tiles(intersecting_tiles, settings, gcm_delta_dir)

    # if no intersecting centroids, then warn the user and ask user to supply the water use points to a text file that will be contained in the info directory with a name specified in the user_settings.py file
    if nonintersecting_tiles:
        
        spatialvectors.write_field_values_file(filepath = info_dir, filename = settings["gcm_delta_non_intersecting_file_name"], field_values_dict = nonintersecting_tiles, field_id = "Tile")

        warn_str = "The following basin(s) do not intersect with the gcm delta tile shapefile:\n    {}\n\n    gcm delta tile shapefile: {}\n    basin shapefile: {}\n".format(nonintersecting_centroids, 
                                                                                                                                                                              settings["gcm_delta_tile_shapefile"] , 
                                                                                                                                                                              os.path.join(settings["simulation_directory"], settings["basin_shapefile_name"]))
        instruction_str1 = "Using gcm delta tile: 000. This special tile id specifies a delta factor of 0 for Tmax type (additive) and a delta factor of 1 for Ppt type (multiplicative).\n"
        instruction_str2 = "Writing the following gcm delta non intersecting file that specifies the non intersecting basin(s) with the gcm delta tiles:\n    {}\n".format(os.path.join(info_dir, settings["gcm_delta_non_intersecting_file_name"]))
        instruction_str3 = "To apply gcm delta factor(s) to the non intersecting basin(s), add tile ids (separated by commas) that you would like to use for each non intersecting basin to the gcm delta non intersecting non intersecting file."
        logging.warn("\n{}\n{}\n{}\n{}\n".format(warn_str, instruction_str1, instruction_str2, instruction_str3)) 

        # apply a delta factor of 0 for Tmax type (additive) and a delta factor of 1 for Ppt type (multiplicative)
        sub_intersecting_tiles = spatialvectors.read_field_values_file(filepath = os.path.join(info_dir, settings["gcm_delta_non_intersecting_file_name"]))

        # apply gcm deltas    
        process_intersecting_tiles(sub_intersecting_tiles, settings, gcm_delta_dir)        

    # create map of study area
    map_processing.create_simulation_map(settings = settings)

    # remove error logger
    waterapputils_logging.remove_loggers()
def apply_sub_gcm_deltas(settings):
    """    
    Apply substitute gcm delta data to a WATERSimulation \*.xml file(s).  
    User supplies the gcm tiles to a text file that will be 
    contained in the info directory with a name specified in the user_settings.py file 

    Parameters
    ----------
    settings : dictionary
        Dictionary of user settings                 

    Notes
    -----
    Uses settings set in user_settings.py  
    """

    # create output directories and files
    info_dir, gcm_delta_dir, info_file = create_output_dirs_files(
        settings, is_sub_gcm_delta=True)

    # initialize error logging in info_dir
    waterapputils_logging.initialize_loggers(output_dir=info_dir)

    # write all future print strings to the info_file
    sys.stdout = open(info_file, "w")

    # get the intersecting points (centroids) based on wateruse non-intersecting_file
    intersecting_tiles = spatialvectors.read_field_values_file(
        filepath=os.path.join(
            info_dir, settings["gcm_delta_non_intersecting_file_name"]))

    # apply the wateruse
    process_intersecting_centroids(intersecting_centroids, settings,
                                   gcm_delta_dir)

    waterapputils_logging.remove_loggers()
def apply_gcm_deltas(settings):
    """    
    Apply global climate model delta factor data to a WATERSimulation \*.xml file(s). 

    Parameters
    ----------
    settings : dictionary
        Dictionary of user settings                 

    Notes
    -----
    Uses settings set in user_settings.py  
    """

    # create output directories and files
    info_dir, gcm_delta_dir, info_file = create_output_dirs_files(settings)

    # initialize error logging in info_dir
    waterapputils_logging.initialize_loggers(output_dir=info_dir)

    # write all future print strings to the info_file
    sys.stdout = open(info_file, "w")

    # open shapefiles
    gcm_delta_tile_shapefile = osgeo.ogr.Open(
        settings["gcm_delta_tile_shapefile"])
    basin_shapefile = osgeo.ogr.Open(
        os.path.join(settings["simulation_directory"],
                     settings["basin_shapefile_name"]))

    # find intersecting points (centroids) based on water basin supplied
    intersecting_tiles_all = spatialvectors.get_intersected_field_values(
        intersector=basin_shapefile,
        intersectee=gcm_delta_tile_shapefile,
        intersectee_field=settings["gcm_delta_tile_shapefile_id_field"],
        intersector_field=settings["basin_shapefile_id_field"])

    intersecting_tiles, nonintersecting_tiles = spatialvectors.validate_field_values(
        field_values_dict=intersecting_tiles_all)

    # apply gcm deltas
    if intersecting_tiles:
        process_intersecting_tiles(intersecting_tiles, settings, gcm_delta_dir)

    # if no intersecting centroids, then warn the user and ask user to supply the water use points to a text file that will be contained in the info directory with a name specified in the user_settings.py file
    if nonintersecting_tiles:

        spatialvectors.write_field_values_file(
            filepath=info_dir,
            filename=settings["gcm_delta_non_intersecting_file_name"],
            field_values_dict=nonintersecting_tiles,
            field_id="Tile")

        warn_str = "The following basin(s) do not intersect with the gcm delta tile shapefile:\n    {}\n\n    gcm delta tile shapefile: {}\n    basin shapefile: {}\n".format(
            nonintersecting_centroids, settings["gcm_delta_tile_shapefile"],
            os.path.join(settings["simulation_directory"],
                         settings["basin_shapefile_name"]))
        instruction_str1 = "Using gcm delta tile: 000. This special tile id specifies a delta factor of 0 for Tmax type (additive) and a delta factor of 1 for Ppt type (multiplicative).\n"
        instruction_str2 = "Writing the following gcm delta non intersecting file that specifies the non intersecting basin(s) with the gcm delta tiles:\n    {}\n".format(
            os.path.join(info_dir,
                         settings["gcm_delta_non_intersecting_file_name"]))
        instruction_str3 = "To apply gcm delta factor(s) to the non intersecting basin(s), add tile ids (separated by commas) that you would like to use for each non intersecting basin to the gcm delta non intersecting non intersecting file."
        logging.warn("\n{}\n{}\n{}\n{}\n".format(warn_str, instruction_str1,
                                                 instruction_str2,
                                                 instruction_str3))

        # apply a delta factor of 0 for Tmax type (additive) and a delta factor of 1 for Ppt type (multiplicative)
        sub_intersecting_tiles = spatialvectors.read_field_values_file(
            filepath=os.path.join(
                info_dir, settings["gcm_delta_non_intersecting_file_name"]))

        # apply gcm deltas
        process_intersecting_tiles(sub_intersecting_tiles, settings,
                                   gcm_delta_dir)

    # create map of study area
    map_processing.create_simulation_map(settings=settings)

    # remove error logger
    waterapputils_logging.remove_loggers()
예제 #5
0
def apply_wateruse(settings):
    """    
    Apply water use data to WATER.txt file(s). 

    Parameters
    ----------
    settings : dictionary
        Dictionary of user settings                 

    Notes
    -----
    Uses settings set in user_settings.py  
    """

    # create output directories and files
    info_dir, ecoflow_dir, oasis_dir, info_file = create_output_dirs_files(
        settings)

    # initialize error logging in info_dir
    waterapputils_logging.initialize_loggers(output_dir=info_dir)

    # write all future print strings to the info_file
    sys.stdout = open(info_file, "w")

    # open shapefiles
    centroids_shapefile = osgeo.ogr.Open(
        settings["wateruse_centroids_shapefile"])
    basin_shapefile = osgeo.ogr.Open(
        os.path.join(settings["simulation_directory"],
                     settings["basin_shapefile_name"]))

    # find intersecting points (centroids) based on water basin supplied
    intersecting_centroids_all = spatialvectors.get_intersected_field_values(
        intersector=basin_shapefile,
        intersectee=centroids_shapefile,
        intersectee_field=settings["wateruse_centroids_shapefile_id_field"],
        intersector_field=settings["basin_shapefile_id_field"])

    intersecting_centroids, nonintersecting_centroids = spatialvectors.validate_field_values(
        field_values_dict=intersecting_centroids_all)

    # apply water use
    if intersecting_centroids:
        process_intersecting_centroids(intersecting_centroids, settings,
                                       ecoflow_dir, oasis_dir)

    # if no intersecting centroids, then warn the user and ask user to supply the water use points to a text file that will be contained in the info directory with a name specified in the user_settings.py file
    if nonintersecting_centroids:

        spatialvectors.write_field_values_file(
            filepath=info_dir,
            filename=settings["wateruse_non_intersecting_file_name"],
            field_values_dict=nonintersecting_centroids)

        warn_str = "The following basin(s) do not intersect with the water use centroids shapefile:\n    {}\n\n    centroids shapefile: {}\n    basin shapefile: {}\n".format(
            nonintersecting_centroids,
            settings["wateruse_centroids_shapefile"],
            os.path.join(settings["simulation_directory"],
                         settings["basin_shapefile_name"]))
        instruction_str1 = "Using water use centriod id: 000.  This special water use centroid id specifies 0 cubic feet per second water use.\n"
        instruction_str2 = "Writing the following wateruse non intersecting file that specifies the non intersecting basin(s) with the special water use centroid id:\n    {}\n".format(
            os.path.join(info_dir,
                         settings["wateruse_non_intersecting_file_name"]))
        instruction_str3 = "To apply water use to the non intersecting basin(s), add centroid(s) ids (newhydroid) (separated by commas) that you would like to use for each non intersecting basin to the wateruse non intersecting file."
        logging.warn("\n{}\n{}\n{}\n{}\n".format(warn_str, instruction_str1,
                                                 instruction_str2,
                                                 instruction_str3))

        # apply 0 cfs water use using the special centroid id of 000
        sub_intersecting_centroids = spatialvectors.read_field_values_file(
            filepath=os.path.join(
                info_dir, settings["wateruse_non_intersecting_file_name"]))

        # apply the wateruse
        process_intersecting_centroids(sub_intersecting_centroids, settings,
                                       ecoflow_dir, oasis_dir)

    # get the areas (in square miles) for each region
    areas = spatialvectors.get_areas_dict(
        shapefile=basin_shapefile,
        id_field=settings["basin_shapefile_id_field"],
        query_field=settings["basin_shapefile_area_field"])

    # write the drainage area csv file for ecoflow program
    watertxt.write_drainagearea_file(
        area_data=areas,
        save_path=ecoflow_dir,
        filename=settings["ecoflow_drainage_area_file_name"])

    # create map of study area
    map_processing.create_simulation_map(settings=settings)

    # remove error logger
    waterapputils_logging.remove_loggers()
def apply_wateruse(settings):
    """    
    Apply water use data to WATER.txt file(s). 

    Parameters
    ----------
    settings : dictionary
        Dictionary of user settings                 

    Notes
    -----
    Uses settings set in user_settings.py  
    """   

	# create output directories and files   
    info_dir, ecoflow_dir, oasis_dir, info_file = create_output_dirs_files(settings)

    # initialize error logging in info_dir
    waterapputils_logging.initialize_loggers(output_dir = info_dir) 

    # write all future print strings to the info_file
    sys.stdout = open(info_file, "w")  
    
    # open shapefiles
    centroids_shapefile = osgeo.ogr.Open(settings["wateruse_centroids_shapefile"]) 
    basin_shapefile = osgeo.ogr.Open(os.path.join(settings["simulation_directory"], settings["basin_shapefile_name"])) 

    # find intersecting points (centroids) based on water basin supplied
    intersecting_centroids_all = spatialvectors.get_intersected_field_values(intersector = basin_shapefile, intersectee = centroids_shapefile, intersectee_field = settings["wateruse_centroids_shapefile_id_field"], intersector_field = settings["basin_shapefile_id_field"])

    intersecting_centroids, nonintersecting_centroids = spatialvectors.validate_field_values(field_values_dict = intersecting_centroids_all)     

    # apply water use
    if intersecting_centroids:    
        process_intersecting_centroids(intersecting_centroids, settings, ecoflow_dir, oasis_dir)

    # if no intersecting centroids, then warn the user and ask user to supply the water use points to a text file that will be contained in the info directory with a name specified in the user_settings.py file
    if nonintersecting_centroids:
        
        spatialvectors.write_field_values_file(filepath = info_dir, filename = settings["wateruse_non_intersecting_file_name"], field_values_dict = nonintersecting_centroids)

        warn_str = "The following basin(s) do not intersect with the water use centroids shapefile:\n    {}\n\n    centroids shapefile: {}\n    basin shapefile: {}\n".format(nonintersecting_centroids, 
                                                                                                                                                                     settings["wateruse_centroids_shapefile"] , 
                                                                                                                                                                     os.path.join(settings["simulation_directory"], settings["basin_shapefile_name"]))
        instruction_str1 = "Using water use centriod id: 000.  This special water use centroid id specifies 0 cubic feet per second water use.\n"
        instruction_str2 = "Writing the following wateruse non intersecting file that specifies the non intersecting basin(s) with the special water use centroid id:\n    {}\n".format(os.path.join(info_dir, settings["wateruse_non_intersecting_file_name"]))
        instruction_str3 = "To apply water use to the non intersecting basin(s), add centroid(s) ids (newhydroid) (separated by commas) that you would like to use for each non intersecting basin to the wateruse non intersecting file."
        logging.warn("\n{}\n{}\n{}\n{}\n".format(warn_str, instruction_str1, instruction_str2, instruction_str3)) 
        
        # apply 0 cfs water use using the special centroid id of 000 
        sub_intersecting_centroids = spatialvectors.read_field_values_file(filepath = os.path.join(info_dir, settings["wateruse_non_intersecting_file_name"]))

        # apply the wateruse     
        process_intersecting_centroids(sub_intersecting_centroids, settings, ecoflow_dir, oasis_dir)        

    # get the areas (in square miles) for each region 
    areas = spatialvectors.get_areas_dict(shapefile = basin_shapefile, id_field = settings["basin_shapefile_id_field"], query_field = settings["basin_shapefile_area_field"])

    # write the drainage area csv file for ecoflow program
    watertxt.write_drainagearea_file(area_data = areas, save_path = ecoflow_dir, filename = settings["ecoflow_drainage_area_file_name"])

    # create map of study area
    map_processing.create_simulation_map(settings = settings)

    # remove error logger
    waterapputils_logging.remove_loggers()