def write_ecoflow_file_drainageareaxml(file_list, dir_name, file_name): """ Write a csv file containing a label (basin id number) and its corresponding area. Parameters ---------- file_list : list List of WATERSimulation.xml files to process dir_name : string String name for output directory file_name : string String name for output file """ area_data = {} for f in file_list: filedir, filename = helpers.get_file_info(f) ecoflow_dir = helpers.make_directory(path=filedir, directory_name=dir_name) helpers.print_input_output_info( input_dict={"input_file": f}, output_dict={"output_directory": ecoflow_dir}) waterapputils_logging.initialize_loggers(output_dir=ecoflow_dir) # read xml file waterxml_tree = waterxml.read_file(f) # get area from each region from the xml file and sum for a total area project, study, simulation = waterxml.get_xml_data( waterxml_tree=waterxml_tree) # get the project name which is the same as the stationid stationid = project["ProjName"] # get the area means for each region areas = waterxml.get_study_unit_areas(simulation_dict=simulation) # calculate total area total_area = waterxml.calc_total_study_unit_areas(areas) # fill area_data with total area area_data[stationid] = total_area # convert from km**2 to mi**2 area_data = helpers.convert_area_values(area_data, in_units="km2", out_units="mi2") # write timeseries of dishcarge + water use for ecoflow program watertxt.write_drainagearea_file(area_data=area_data, save_path=ecoflow_dir, filename=file_name) waterapputils_logging.remove_loggers()
def get_areas_dict(shapefile, id_field, query_field): """ Wrapper for get_shapefile_areas(). If there is no query_field (e.g. area_field), then calculate the area. All WATER application shapefiles are in the Albers NAD83 projection, so areas are in units of meters squared by default. Convert from units of meters squared to units of miles squared. Parameters ---------- shapefile : osgeo.ogr.DataSource A shapefile object. id_field : string A string id id_field to use as keys in return dictionary query_field : string A string field that exists in shapefile Returns ------- areas : dictionary Dictionary containing feature id and areas Notes ----- Area units are in the linear units of the projected coordinate system. All WATER application shapefiles are in the Albers NAD83 projection. """ # get the areas for each region if query_field: areas = get_field_values(shapefile = shapefile, id_field = id_field, query_field = query_field) else: if id_field: areas = get_shapefile_areas(shapefile, id_field = id_field) # convert from m**2 to mi**2; water application uses NAD83 projection with units of meters areas = helpers.convert_area_values(areas, in_units = "m2", out_units = "mi2") else: areas = get_shapefile_areas(shapefile) # convert from m**2 to mi**2; water application uses NAD83 projection with units of meters areas = helpers.convert_area_values(areas, in_units = "m2", out_units = "mi2") return areas
def write_ecoflow_file_drainageareaxml(file_list, dir_name, file_name): """ Write a csv file containing a label (basin id number) and its corresponding area. Parameters ---------- file_list : list List of WATERSimulation.xml files to process dir_name : string String name for output directory file_name : string String name for output file """ area_data = {} for f in file_list: filedir, filename = helpers.get_file_info(f) ecoflow_dir = helpers.make_directory(path = filedir, directory_name = dir_name) helpers.print_input_output_info(input_dict = {"input_file": f}, output_dict = {"output_directory": ecoflow_dir}) waterapputils_logging.initialize_loggers(output_dir = ecoflow_dir) # read xml file waterxml_tree = waterxml.read_file(f) # get area from each region from the xml file and sum for a total area project, study, simulation = waterxml.get_xml_data(waterxml_tree = waterxml_tree) # get the project name which is the same as the stationid stationid = project["ProjName"] # get the area means for each region areas = waterxml.get_study_unit_areas(simulation_dict = simulation) # calculate total area total_area = waterxml.calc_total_study_unit_areas(areas) # fill area_data with total area area_data[stationid] = total_area # convert from km**2 to mi**2 area_data = helpers.convert_area_values(area_data, in_units = "km2", out_units = "mi2") # write timeseries of dishcarge + water use for ecoflow program watertxt.write_drainagearea_file(area_data = area_data, save_path = ecoflow_dir, filename = file_name) waterapputils_logging.remove_loggers()