def write_xml(in_network, out_network): """ Writes relevant data to the project's XML document :param in_network: The input Combined Capacity Network :param out_network: The new Conservation Restoration Network :return: """ proj_path = os.path.dirname( os.path.dirname(os.path.dirname(os.path.dirname(in_network)))) xml_file_path = os.path.join(proj_path, "project.rs.xml") if not os.path.exists(xml_file_path): arcpy.AddWarning("XML file not found. Could not update XML file") return xml_file = XMLBuilder(xml_file_path) in_network_rel_path = find_relative_path(in_network, proj_path) path_element = xml_file.find_by_text(in_network_rel_path) analysis_element = xml_file.find_element_parent( xml_file.find_element_parent(path_element)) write_xml_element_with_path(xml_file, analysis_element, "Vector", "BRAT Conservation and Restoration Output", out_network, proj_path) xml_file.write()
def write_xml(proj_path, in_network, out_network, plot_name): """ Writes relevant data into the XML :param proj_path: The file path to the BRAT project folder :param in_network: The input Conservation Restoration network :param out_network: The newly created Data Validation network :param plot_name: The file path to the created plot :return: """ xml_file_path = os.path.join(proj_path, "project.rs.xml") if not os.path.exists(xml_file_path): arcpy.AddWarning("XML file not found. Could not update XML file") return xml_file = XMLBuilder(xml_file_path) in_network_rel_path = find_relative_path(in_network, proj_path) path_element = xml_file.find_by_text(in_network_rel_path) analysis_element = xml_file.find_element_parent( xml_file.find_element_parent(path_element)) write_xml_element_with_path(xml_file, analysis_element, "Vector", "BRAT Data Validation", out_network, proj_path) # write_xml_element_with_path(xml_file, analysis_element, "Plot", "Obsrved vs Predicted Plot", plot_name, proj_path) xml_file.write()
def xml_add_equations(in_network, region, q_low_eqtn, q2_eqtn): """ Adds the equation strings into the project's XML document :param in_network: The input BRAT table to add hydrologic values to :param region: The optional region code to identify an already existing equation :param q_low_eqtn: The Qlow equation to be calculated :param q2_eqtn: The Q2 equation to be calculated :return: """ # get project folder path from input network proj_path = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(in_network)))) # open xml xml_file_path = os.path.join(proj_path, "project.rs.xml") if not os.path.exists(xml_file_path): raise Exception("XML file for project does not exist. Return to Step 1: BRAT table to create XML.") xml_file = XMLBuilder(xml_file_path) # find input network XML element in_network_rel_path = find_relative_path(in_network, proj_path) path_element = xml_file.find_by_text(in_network_rel_path) # find intermediates element for input network intermediates_element = xml_file.find_element_parent(xml_file.find_element_parent(path_element)) if intermediates_element is None: raise Exception("Equations could not be added because parent element 'Intermediates' not found in XML.") # add regional curves element within intermediates ihyd_element = xml_file.add_sub_element(intermediates_element, name="Regional Curves", text="Equations for estimating streamflow") # add region element to XML if specified if region is not 0: xml_file.add_sub_element(ihyd_element, "Hydrological region", str(region)) # add base flow equation to XML if specified or using generic if q_low_eqtn is None and region is 0: xml_file.add_sub_element(ihyd_element, name="Baseflow equation", text="(DAsqm ** 0.2098) + 1") elif q2_eqtn is None and region is not 0: xml_file.add_sub_element(ihyd_element, name="Baseflow equation", text="Not specified - see iHyd code.") else: xml_file.add_sub_element(ihyd_element, name="Baseflow equation", text=str(q_low_eqtn)) # add high flow equation to XML if specified or using generic if q2_eqtn is None and region is 0: xml_file.add_sub_element(ihyd_element, name="Highflow equation", text="14.7 * (DAsqm ** 0.815)") elif q2_eqtn is None and region is not 0: xml_file.add_sub_element(ihyd_element, name="Highflow equation", text="Not specified - see iHyd code.") else: xml_file.add_sub_element(ihyd_element, name="Highflow equation", text=str(q2_eqtn)) xml_file.write()
def get_brat_element(xml_file, in_network, proj_path): """ Gets the BRAT XML element for this particular in_network :param xml_file: The project's XML file to add to :param in_network: The input BRAT network :param proj_path: The path to the project folder for this BRAT run :return: The BRAT XML element """ relative_path = find_relative_path(in_network, proj_path) path_element = xml_file.find_by_text(relative_path) vec_element = xml_file.find_element_parent(path_element) intermed_element = xml_file.find_element_parent(vec_element) intermeds_element = xml_file.find_element_parent(intermed_element) brat_element = xml_file.find_element_parent(intermeds_element) return brat_element