def process_intersecting_tiles(intersecting_tiles, settings, gcm_delta_dir):
    """    
    Apply water use data to a WATER \*.txt file. The new file created is saved to the same
    directory as the \*.xml file.

    Parameters
    ----------
    intersecting_tiles : dictionary
        Dictionary containing lists of values for a particular field that were intersected by another shapefile.  
    settings : dictionary
        Dictionary of user settings
    gcm_delta_dir : string 
        string path to ecoflow directory

    Notes
    -----
    Uses settings set in user_settings.py 
    """      
    # create a file for the output  
    for featureid, tiles in intersecting_tiles.iteritems():

        # get monthly average gcm delta values
        deltas_data_list, deltas_avg_dict = deltas.get_deltas(delta_files = settings["gcm_delta_files"], tiles = tiles) 

        # print monthly output in nice format to info file
        print("FeatureId: {}\n    Tiles: {}\n    Average GCM Deltas:\n".format(featureid, tiles))  
        for key in deltas_avg_dict.keys():
            print("    {}\n".format(key))
            helpers.print_monthly_dict(monthly_dict = deltas_avg_dict[key])
       
        # get the txt data file that has a parent directory matching the current featureid
        if settings["is_batch_simulation"]:
            path = os.path.join(settings["simulation_directory"], featureid)
        else:
            path = settings["simulation_directory"]

        # find the WATERSimulation.xml and WATER.txt files
        waterxml_file = helpers.find_file(name = settings["water_database_file_name"], path = path)
        watertxt_file = helpers.find_file(name = settings["water_text_file_name"], path = path)

        # get file info
        waterxml_dir, waterxml_filename = helpers.get_file_info(waterxml_file)       
        watertxt_dir, watertxt_filename = helpers.get_file_info(watertxt_file)   

        # create an output directory
        output_dir = helpers.make_directory(path = waterxml_dir, directory_name = settings["gcm_delta_directory_name"])
        
        # initialize error logging
        waterapputils_logging.initialize_loggers(output_dir = output_dir)

        # read the xml file
        waterxml_tree = waterxml.read_file(waterxml_file) 
        watertxt_data = watertxt.read_file(watertxt_file)            

        # apply gcm delta
        for key, value in deltas_avg_dict.iteritems():
            if key == "Ppt":
                waterxml.apply_factors(waterxml_tree = waterxml_tree, element = "ClimaticPrecipitationSeries", factors = deltas_avg_dict[key])

            elif key == "Tmax":
                waterxml.apply_factors(waterxml_tree = waterxml_tree, element = "ClimaticTemperatureSeries", factors = deltas_avg_dict[key])

            elif key == "PET":
                watertxt.apply_factors(watertxt_data, name = "PET", factors = deltas_avg_dict[key], is_additive = False)

        # update the project name in the updated xml
        project = waterxml.create_project_dict() 
        project = waterxml.fill_dict(waterxml_tree = waterxml_tree, data_dict = project, element = "Project", keys = project.keys())
        waterxml.change_element_value(waterxml_tree = waterxml_tree, element = "Project", child = "ProjName" , new_value = settings["gcm_delta_prepend_name"] + project["ProjName"])

        # write updated xml
        waterxml_with_gcm_delta_file = settings["gcm_delta_prepend_name"] + waterxml_filename

        waterxml.write_file(waterxml_tree = waterxml_tree, save_path = output_dir, filename = waterxml_with_gcm_delta_file)              

        # write the pet timeseries file
        watertxt.write_timeseries_file(watertxt_data, name = "PET", save_path = output_dir, filename = settings["pet_timeseries_file_name"])

        # plot 
        updated_waterxml_file = os.path.join(output_dir, waterxml_with_gcm_delta_file)
        water_files_processing.process_water_files(file_list = [updated_waterxml_file ], settings = settings, print_data = False)
        water_files_processing.process_cmp(file_list = [updated_waterxml_file, waterxml_file], settings = settings, print_data = False)

    # plot the gcm deltas 
    for deltas_data in deltas_data_list:
        deltas_viewer.plot_deltas_data(deltas_data = deltas_data, save_path = helpers.make_directory(path = gcm_delta_dir, directory_name = settings["gcm_delta_directory_name"]))
Ejemplo n.º 2
0
def process_intersecting_centroids(intersecting_centroids, settings,
                                   ecoflow_dir, oasis_dir):
    """    
    Apply water use data to a WATER \*.txt file. The new file created is saved to the same
    directory as the \*.xml file.

    Parameters
    ----------
    intersecting_centroids : dictionary
        Dictionary containing lists of values for a particular field that were intersected by another shapefile.  
    settings : dictionary
        Dictionary of user settings
    ecoflow_dir : string
        String path to directory that will contain output specific for ecoflow program
    oasis_dir : string
        String path to directory that will contain output specific for oasis

    Notes
    -----
    Uses settings set in user_settings.py 
    """
    # create a file for the output
    for featureid, centroids in intersecting_centroids.iteritems():

        # get sum of the water use data
        if settings["wateruse_factor_file"]:
            total_wateruse_dict = wateruse.get_all_total_wateruse(
                wateruse_files=settings["wateruse_files"],
                id_list=centroids,
                wateruse_factor_file=settings["wateruse_factor_file"],
                in_cfs=True)

        else:
            total_wateruse_dict = wateruse.get_all_total_wateruse(
                wateruse_files=settings["wateruse_files"],
                id_list=centroids,
                wateruse_factor_file=None,
                in_cfs=True)

        # print monthly output in nice format to info file
        print(
            "FeatureId: {}\n    Centroids: {}\n    Total Water Use:\n".format(
                featureid, centroids))
        helpers.print_monthly_dict(monthly_dict=total_wateruse_dict)

        # get the txt data file that has a parent directory matching the current featureid
        if settings["is_batch_simulation"]:
            path = os.path.join(settings["simulation_directory"], featureid)
        else:
            path = settings["simulation_directory"]

        # find the WATER.txt file
        watertxt_file = helpers.find_file(
            name=settings["water_text_file_name"], path=path)

        # get file info
        watertxt_dir, watertxt_filename = helpers.get_file_info(watertxt_file)

        # create an output directory
        output_dir = helpers.make_directory(
            path=watertxt_dir,
            directory_name=settings["wateruse_directory_name"])

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

        # read the txt
        watertxt_data = watertxt.read_file(watertxt_file)

        # apply water use
        watertxt_data = watertxt.apply_wateruse(
            watertxt_data, wateruse_totals=total_wateruse_dict)

        # write updated txt
        watertxt_with_wateruse_file = settings[
            "wateruse_prepend_name"] + watertxt_filename

        watertxt.write_file(watertxt_data=watertxt_data,
                            save_path=output_dir,
                            filename=watertxt_with_wateruse_file)

        # plot
        updated_watertxt_file = os.path.join(output_dir,
                                             watertxt_with_wateruse_file)
        water_files_processing.process_water_files(
            file_list=[updated_watertxt_file],
            settings=settings,
            print_data=True)

        # write timeseries of discharge + water use for OASIS
        watertxt.write_timeseries_file(watertxt_data=watertxt_data,
                                       name=settings["ecoflow_parameter_name"],
                                       save_path=oasis_dir,
                                       filename="-".join([
                                           watertxt_data["stationid"],
                                           settings["oasis_file_name"]
                                       ]))

        # write timeseries of dishcarge + water use for ecoflow program
        watertxt.write_timeseries_file_stationid(
            watertxt_data,
            name=settings["ecoflow_parameter_name"],
            save_path=ecoflow_dir,
            filename="",
            stationid=watertxt_data["stationid"])
Ejemplo n.º 3
0
def process_intersecting_tiles(intersecting_tiles, settings, gcm_delta_dir):
    """    
    Apply water use data to a WATER \*.txt file. The new file created is saved to the same
    directory as the \*.xml file.

    Parameters
    ----------
    intersecting_tiles : dictionary
        Dictionary containing lists of values for a particular field that were intersected by another shapefile.  
    settings : dictionary
        Dictionary of user settings
    gcm_delta_dir : string 
        string path to ecoflow directory

    Notes
    -----
    Uses settings set in user_settings.py 
    """
    # create a file for the output
    for featureid, tiles in intersecting_tiles.iteritems():

        # get monthly average gcm delta values
        deltas_data_list, deltas_avg_dict = deltas.get_deltas(
            delta_files=settings["gcm_delta_files"], tiles=tiles)

        # print monthly output in nice format to info file
        print("FeatureId: {}\n    Tiles: {}\n    Average GCM Deltas:\n".format(
            featureid, tiles))
        for key in deltas_avg_dict.keys():
            print("    {}\n".format(key))
            helpers.print_monthly_dict(monthly_dict=deltas_avg_dict[key])

        # get the txt data file that has a parent directory matching the current featureid
        if settings["is_batch_simulation"]:
            path = os.path.join(settings["simulation_directory"], featureid)
        else:
            path = settings["simulation_directory"]

        # find the WATERSimulation.xml and WATER.txt files
        waterxml_file = helpers.find_file(
            name=settings["water_database_file_name"], path=path)
        watertxt_file = helpers.find_file(
            name=settings["water_text_file_name"], path=path)

        # get file info
        waterxml_dir, waterxml_filename = helpers.get_file_info(waterxml_file)
        watertxt_dir, watertxt_filename = helpers.get_file_info(watertxt_file)

        # create an output directory
        output_dir = helpers.make_directory(
            path=waterxml_dir,
            directory_name=settings["gcm_delta_directory_name"])

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

        # read the xml file
        waterxml_tree = waterxml.read_file(waterxml_file)
        watertxt_data = watertxt.read_file(watertxt_file)

        # apply gcm delta
        for key, value in deltas_avg_dict.iteritems():
            if key == "Ppt":
                waterxml.apply_factors(waterxml_tree=waterxml_tree,
                                       element="ClimaticPrecipitationSeries",
                                       factors=deltas_avg_dict[key])

            elif key == "Tmax":
                waterxml.apply_factors(waterxml_tree=waterxml_tree,
                                       element="ClimaticTemperatureSeries",
                                       factors=deltas_avg_dict[key])

            elif key == "PET":
                watertxt.apply_factors(watertxt_data,
                                       name="PET",
                                       factors=deltas_avg_dict[key],
                                       is_additive=False)

        # update the project name in the updated xml
        project = waterxml.create_project_dict()
        project = waterxml.fill_dict(waterxml_tree=waterxml_tree,
                                     data_dict=project,
                                     element="Project",
                                     keys=project.keys())
        waterxml.change_element_value(
            waterxml_tree=waterxml_tree,
            element="Project",
            child="ProjName",
            new_value=settings["gcm_delta_prepend_name"] + project["ProjName"])

        # write updated xml
        waterxml_with_gcm_delta_file = settings[
            "gcm_delta_prepend_name"] + waterxml_filename

        waterxml.write_file(waterxml_tree=waterxml_tree,
                            save_path=output_dir,
                            filename=waterxml_with_gcm_delta_file)

        # write the pet timeseries file
        watertxt.write_timeseries_file(
            watertxt_data,
            name="PET",
            save_path=output_dir,
            filename=settings["pet_timeseries_file_name"])

        # plot
        updated_waterxml_file = os.path.join(output_dir,
                                             waterxml_with_gcm_delta_file)
        water_files_processing.process_water_files(
            file_list=[updated_waterxml_file],
            settings=settings,
            print_data=False)
        water_files_processing.process_cmp(
            file_list=[updated_waterxml_file, waterxml_file],
            settings=settings,
            print_data=False)

    # plot the gcm deltas
    for deltas_data in deltas_data_list:
        deltas_viewer.plot_deltas_data(
            deltas_data=deltas_data,
            save_path=helpers.make_directory(
                path=gcm_delta_dir,
                directory_name=settings["gcm_delta_directory_name"]))
def process_intersecting_centroids(intersecting_centroids, settings, ecoflow_dir, oasis_dir):
    """    
    Apply water use data to a WATER \*.txt file. The new file created is saved to the same
    directory as the \*.xml file.

    Parameters
    ----------
    intersecting_centroids : dictionary
        Dictionary containing lists of values for a particular field that were intersected by another shapefile.  
    settings : dictionary
        Dictionary of user settings
    ecoflow_dir : string
        String path to directory that will contain output specific for ecoflow program
    oasis_dir : string
        String path to directory that will contain output specific for oasis

    Notes
    -----
    Uses settings set in user_settings.py 
    """      
    # create a file for the output  
    for featureid, centroids in intersecting_centroids.iteritems():

        # get sum of the water use data
        if settings["wateruse_factor_file"]:
            total_wateruse_dict = wateruse.get_all_total_wateruse(wateruse_files = settings["wateruse_files"], id_list = centroids, wateruse_factor_file = settings["wateruse_factor_file"], in_cfs = True)

        else:
            total_wateruse_dict = wateruse.get_all_total_wateruse(wateruse_files = settings["wateruse_files"], id_list = centroids, wateruse_factor_file = None, in_cfs = True)

        # print monthly output in nice format to info file
        print("FeatureId: {}\n    Centroids: {}\n    Total Water Use:\n".format(featureid, centroids))  
        helpers.print_monthly_dict(monthly_dict = total_wateruse_dict)
       
        # get the txt data file that has a parent directory matching the current featureid
        if settings["is_batch_simulation"]:
            path = os.path.join(settings["simulation_directory"], featureid)
        else:
            path = settings["simulation_directory"]

        # find the WATER.txt file 
        watertxt_file = helpers.find_file(name = settings["water_text_file_name"], path = path)

        # get file info
        watertxt_dir, watertxt_filename = helpers.get_file_info(watertxt_file)       

        # create an output directory
        output_dir = helpers.make_directory(path = watertxt_dir, directory_name = settings["wateruse_directory_name"])
        
        # initialize error logging
        waterapputils_logging.initialize_loggers(output_dir = output_dir)

        # read the txt
        watertxt_data = watertxt.read_file(watertxt_file)            

        # apply water use
        watertxt_data = watertxt.apply_wateruse(watertxt_data, wateruse_totals = total_wateruse_dict) 

        # write updated txt
        watertxt_with_wateruse_file = settings["wateruse_prepend_name"] + watertxt_filename

        watertxt.write_file(watertxt_data = watertxt_data, save_path = output_dir, filename = watertxt_with_wateruse_file)              

        # plot 
        updated_watertxt_file = os.path.join(output_dir, watertxt_with_wateruse_file)
        water_files_processing.process_water_files(file_list = [updated_watertxt_file], settings = settings, print_data = True)

        # write timeseries of discharge + water use for OASIS
        watertxt.write_timeseries_file(watertxt_data = watertxt_data, name = settings["ecoflow_parameter_name"], save_path = oasis_dir, filename = "-".join([watertxt_data["stationid"], settings["oasis_file_name"]]))

        # write timeseries of dishcarge + water use for ecoflow program
        watertxt.write_timeseries_file_stationid(watertxt_data, name = settings["ecoflow_parameter_name"], save_path = ecoflow_dir, filename = "", stationid = watertxt_data["stationid"])