Interaction method for converting SWMM model data into data directly recognized by graph neural network

SWMM model data is extracted and normalized through MATLAB and visualized in Python, which solves the problem of converting SWMM model data into a recognizable format of graph neural networks, and realizes efficient and accurate urban hydrological management analysis support.

CN119720756AActive Publication Date: 2025-03-28CHONGQING JIAOTONG UNIV
View PDF 6 Cites 0 Cited by

Patent Information

Application Number
CN202411773151.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-04
Publication Date
2025-03-28
Estimated Expiration
2044-12-04

AI Technical Summary

Technical Problem

The prior art is difficult to directly convert the complex unstructured data output by the SWMM model into a format recognizable by the graph neural network, limiting the data analysis efficiency and accuracy.

Method used

The node coordinates, pipeline connection relationships and node feature data in the SWMM model are extracted and normalized by MATLAB software and saved as npy files, which can be visualized and prepared for graph neural network data in Python.

Benefits of technology

It realizes the rapid structure of SWMM model data into a format recognizable by graph neural networks, improves the data analysis efficiency and accuracy, and supports more accurate and real-time urban hydrological management decisions.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119720756A_ABST
    Figure CN119720756A_ABST
Patent Text Reader

Abstract

The invention discloses an interaction method for converting SWMM model data into data directly identified by a graph neural network, which comprises the following steps of: 1, reading an. Inp file of an SWMM model based on MATLAB software, extracting information, storing pipeline connection relation information as a first npy file, storing pipeline length information as a second npy file, and storing pipeline length information as a second npy file; extracting and normalizing data of catchment area, maximum impervious rate, total width, maximum gradient, whether the node is a discharge port, node elevation and node depth associated with each node to obtain a node feature matrix, and storing the node feature matrix as a third npy file; and 2, carrying out visualization processing on the npy file by using python software. According to the method, the data processing flow is simplified, rapid structuring of SWMM model data is realized, and accurate and real-time analysis support is provided for urban hydrological management.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the technical field of urban rain and flood simulation data processing, and in particular relates to an interactive method for converting SWMM model data into data directly recognized by a graph neural network. Background Art

[0002] In the process of urbanization, urban drainage systems and stormwater management are important components of urban infrastructure planning and environmental protection. With the expansion of urban areas and the increase of surface impermeable layers, the risk of urban flood disasters has increased significantly. Effective urban stormwater management requires not only accurate data collection and monitoring, but also efficient data processing and analysis methods to predict and regulate flood events.

[0003] The Urban Stormwater Management Model (SWMM) is a comprehensive computer model used to simulate single rain events or continuously simulate runoff and water quality in urban areas. SWMM can simulate the rainfall runoff process in natural and artificial areas, calculate the conversion from rainfall to the amount discharged into the receiving water body, and is one of the standard tools for urban drainage system design and analysis. However, the data output by SWMM is usually complex and in an unstructured format, such as node flow, water level, pipe network connection, etc. These data can usually only reflect the rainfall process and the performance of the urban drainage system itself and drainage-related performance, and cannot reflect the performance and problems of the design, construction, operation and management of drainage system facilities and analyze them at these levels. Therefore, further conversion and processing are required to be applicable to more advanced data analysis methods.

[0004] Although SWMM excels in simulation accuracy, its data processing and analysis capabilities are limited, especially when dealing with large-scale data sets, making it difficult to directly apply advanced machine learning and artificial intelligence techniques, such as graph neural networks. Graph neural networks (GNNs) have been shown to excel in analyzing data with complex network structures, especially when the relationships between nodes and edges are critical to the overall analysis. However, there are certain technical challenges in converting SWMM's output data into a format that can be directly used by graph neural networks. For example, how to effectively integrate the physical and hydrological properties of nodes and edges into the graph structure, and how to process and represent this data to optimize the performance of the neural network.

[0005] Given the limitations of existing technologies, it is necessary to develop a method that can efficiently convert SWMM output data and apply it to graph neural networks. This method can not only improve data availability and analysis efficiency, but also utilize the powerful data processing capabilities of graph neural networks to provide more accurate and real-time decision support for urban hydrological management. Summary of the invention

[0006] In view of the above-mentioned deficiencies of the prior art, the technical problem to be solved by the present invention is: how to provide an interactive method for converting SWMM model data into data directly recognized by graph neural networks, which can improve data availability and analysis efficiency, so that it can directly utilize the powerful data processing capabilities of graph neural networks for overall analysis, facilitate various types of research related to urban precipitation, and be more conducive to providing more accurate and real-time decision support for urban hydrological management.

[0007] In order to solve the above technical problems, the present invention adopts the following technical solutions:

[0008] An interactive method for converting SWMM model data into data directly recognized by a graph neural network, firstly establishing a SWMM model of a research urban area, dividing the catchment area in the model, and exporting an inp (a text file with a suffix of inp) file; characterized in that it also includes the following steps:

[0009] Step 1: First, based on MATLAB (a commercial mathematical software used for data analysis), the .inp file of the SWMM model is read. The X-axis coordinate position and Y-axis coordinate position of each node are first extracted and normalized. Then, the pipeline connection relationship (i.e., the pipeline and its two-end node information) and pipeline length information are extracted. After extraction, the pipeline connection relationship information is saved as the first npy file (a binary file used to save array data), and the pipeline length information is saved as the second npy file. Then, the drainage area, maximum imperviousness, total width, maximum slope, whether it is a drainage outlet, node elevation and node depth data associated with each node are extracted and normalized. Finally, the node X and Y position, drainage area, maximum imperviousness, total width, maximum slope, whether it is a drainage outlet, node elevation and node depth data are integrated and saved as a node feature matrix, and the node feature matrix is ​​saved as the third npy file.

[0010] Step 2: Use Python (a computer language) software to perform visualization based on the three npy files.

[0011] Thus, in the present invention, the node-related data, pipeline connection relationship and pipeline length data are first normalized and saved as three different npy files. In this step, all the data of the inp file of the SWMM model are converted into a form that can be directly recognized and used by the graph neural network. The graph neural network can help identify potential drainage problems in the area (such as waterlogging, sewage overflow, etc.), and can also help understand the flow process of water in the drainage system, predict future water level changes, the susceptibility of urban flood disasters, etc., and better help researchers to assess the flood risk of the city. Then, based on these three npy files, python software is used to realize visualization processing. In the step, isolated nodes (nodes with no pipes connected to other nodes) are visualized. ) are removed to transform complex data into simpler and more intuitive graphics, which helps users to more quickly identify key nodes and pipelines in the model, as well as the relationships and interactions between them. This processing also makes it easier for users to find nodes that lack drainage areas and information such as outlets, helping users to optimize their decisions. For example, in the risk assessment of urban flood disasters, the relative positions of various nodes in the urban drainage system and the flow direction of water can be quickly understood, so that designers can more intuitively add pipelines to areas prone to floods and adjust nodes that lack drainage areas, allowing urban planners to better plan and adjust corresponding urban functional areas or emergency measures in urban flood-prone areas, etc.

[0012] Therefore, the present invention realizes the direct interaction between the SWMM model and the Python graph neural network using Matlab software, which facilitates the use of graph neural network algorithms to directly analyze various types of urban waterlogging data and conduct related research. By combining SWMM and GNN, more advanced automation and intelligence can be achieved in the design, optimization and operation management of urban drainage systems, effectively reducing human errors and improving the system's response speed and disaster management capabilities.

[0013] In the scheme, a node refers to the connection point of the pipeline in the urban drainage network system, which can be a diverter, storage unit or discharge port. These nodes play a key role in the network structure of the drainage system. They connect different links (such as pipes, channels, etc.) and allow water to flow or store between these links.

[0014] In the scheme, the X-axis coordinate position and Y-axis coordinate position of each node (Node X and Y Coordinates) refer to the geometric coordinates of the node in two-dimensional space, which are used to describe its specific position in the drainage network in the model. The X and Y positions of the node are stored in node_positionX (variable matrix name) and node_positionY respectively, and node_positionX_norm and node_positionY_norm are generated by normalization.

[0015] In the scheme, the catchment area associated with each node refers to the sum of the catchment areas of all areas converging to a node, which is used to represent the range of rainwater sources received by the node. In the model, the catchment area directly affects the input water volume of the node and is one of the key determinants of the node flow. A larger catchment area means that the node needs to handle more rainwater and may also put higher pressure on the downstream pipeline. The catchment area is represented by the variable mjjz in the step, and it is normalized to the minimum-maximum in subsequent processing to generate the normalized result mjjz_norm.

[0016] In the scheme, the maximum imperviousness associated with each node refers to the proportion of impervious surfaces (such as buildings, roads, etc.) in the catchment area associated with a node to the total area. It reflects the part of the rainwater runoff processed by the node that cannot penetrate into the ground. The higher the maximum imperviousness of the node, the greater the surface runoff it collects, increasing the burden on the downstream pipe network. In the step, this physical quantity is stored in the variable imperviousness_doub and normalized to generate imperviousness_norm.

[0017] In the scheme, the total width (Subcatchment Width) associated with each node refers to the total width of the water flow path in the catchment area associated with a node, which describes the degree of dispersion of the water flow converging to the node. The larger the total width, the shorter the water flow path and the faster the water flow speed, so the water flow impact received by the node may be greater. This physical quantity is represented by the variable subWidth_doub in the step, and the normalized result is stored as subWidth_norm.

[0018] In the scheme, the maximum slope associated with each node refers to the maximum terrain slope of the catchment area associated with a node, which is used to indicate the acceleration ability of water flow in the area. The larger the slope, the faster the water flows to the node, which may cause greater flow pressure on the node. A smaller slope results in a slower water flow and a longer confluence time. This physical quantity is represented by slope_doub and is normalized to generate slope_norm.

[0019] In the scheme, the outlet (Is Outlet) associated with each node indicates whether a node is the terminal discharge point of the drainage system. It is stored as a Boolean value, 0 for a normal node and 1 for an outlet node. The outlet node is the key point of the entire drainage system and directly affects the drainage efficiency. For the outlet node, water is discharged from the system to the external environment; while the non-outlet node is only a transfer node for water flow in the pipe network. In the step, this attribute is stored in the fifth column of the matrix X_combine to identify the function of the node.

[0020] In the scheme, the node elevation associated with each node refers to the ground height of a node, which is used to reflect the terrain characteristics of the node. Elevation affects the gravity flow direction of water flow and is a key parameter that determines whether the water flow can be discharged smoothly. Elevation data is stored as Node_bottomElevation and generated as Node_bottomElevation_norm after normalization for subsequent model calculations.

[0021] In the scheme, the node depth associated with each node refers to the maximum depth from the ground of the node to the bottom of the drainage pipe. It represents the maximum water holding capacity of the node. The greater the depth, the more water the node can hold. The node depth is stored as Node_MaxDepth and is normalized to generate Node_MaxDepth_norm.

[0022] The first step of this method specifically comprises the following steps:

[0023] Step 1: Use MATLAB software to open the SWMM model and extract the information data in the inp file; convert all data content into the variable matrix newline (variable matrix name) for subsequent processing.

[0024] The specific implementation process of step 1 is as follows:

[0025] 1) Set the simulation step size: define a variable time_step with a value of 5, which means that the simulation is performed every 5 minutes.

[0026] 2) Clean up the environment: Use the clear and clc commands to clear the variables and command windows in the MATLAB environment to prepare for new file operations.

[0027] 3) File path and mode: Use the fopen (open file and set read-write mode command) function to open a .inp file containing SWMM model data. Here the file is opened in read-write mode (r+), allowing the file content to be modified.

[0028] 4) Initialize variables: Initialize variable i and array newline. newline is used to store each line of data read from the file.

[0029] 5) Loop reading: Use the while loop and the feof function to check if the file has reached the end. This loop remains active until the file is completely read.

[0030] 6) Read line by line: Use the fgetl (read file content line by line command) function to read the file content line by line. Each time a line is read, the variable i increases by 1 and the read line is stored in the newline array.

[0031] 7) Close file operation: Use fclose(fileID) (close opened file command) command to close the previously opened file. This is an important operation used to release system resources and ensure that all changes are saved.

[0032] Step 2: Extract the node X and Y axis coordinate information, that is, extract the node name and coordinate information from the variable matrix newline in step 1, and convert it into the node number name matrix node_name, the node position X coordinate node_positionX, and the node position Y coordinate node_positionY, so as to be used for establishing the graph structure.

[0033] The specific implementation of step 2 includes the following operation steps:

[0034] 1) Initialize and find the node position: Use the contains (command to determine whether a string array contains a specific substring) function and the find (command to find the index of the element that meets the condition) function to find and locate the row containing 'COORDINATES' (the row where the coordinates are located) and 'VERTICES' in the newline array and save them in the variables node_id and node_idend respectively. By finding the position of these keywords, the start (3 rows below the row where 'COORDINATES' is located) and end (1 row above the row where 'VERTICES' is located) of the node data can be located.

[0035] 2) Calculate the number of nodes: Based on the starting and ending positions of the node data, calculate the total number of nodes, which is obtained by subtracting the starting position from the ending position plus one and saved in the variable num_node.

[0036] 3) Loop to extract node data: Use a for loop, starting from the starting position, and loop to extract the data of each node according to the number of nodes.

[0037] 4) Split data by expression: Use the regexp (split string by regular expression) function and the expression \s+ to split each line of data, so that the node name and coordinate information can be extracted. This expression splits the string based on spaces to obtain detailed information about the node.

[0038] 5) Storing node information: storing the node number name, the X-axis coordinate of the node position, and the Y-axis coordinate of the node position obtained by segmentation into pre-defined variables node_name, node_positionX, and node_positionY respectively.

[0039] Step 3: Normalize the X and Y axis coordinate data of the node, that is, convert the node X and Y coordinate information extracted in step 2 into normalized values ​​and save them in the matrices node_positionX_norm and node_positionY_norm respectively to ensure that the data is in the range of 0 to 1.

[0040] The specific implementation of step 3 includes the following operation steps:

[0041] 1) String to number conversion: Use the str2double (convert a string to a double-precision numerical command) function to convert the node coordinates node_positionX and node_positionY from a string format to a double-precision floating point number (double).

[0042] 2) Process the coordinate data using min-max normalization: Calculate the minimum and maximum values ​​of node_positionX and node_positionY respectively. These values ​​are used in the subsequent normalization process to ensure that all coordinates are scaled to the range between 0 and 1.

[0043] 3) Perform normalization: Normalize node_positionX and node_positionY, and use the normalization formula to convert each coordinate value into a value in the range of 0 to 1, where the minimum coordinate becomes 0 and the maximum coordinate becomes 1. After calculation, the data is stored in variables node_positionX_norm and node_positionY_norm respectively.

[0044] The normalization process is explained here:

[0045] The normalization step is usually to scale the data values ​​of different features to a relatively consistent range to facilitate model processing or further data analysis.

[0046] The first step of normalization is to determine the minimum and maximum values. For the data that needs to be normalized (such as the X coordinate, Y coordinate of a node, or the length of a pipeline), the minimum and maximum values ​​of these data need to be calculated first.

[0047] Minimum: Use the min() function to find the minimum value in the data.

[0048] Maximum: Use the max() function to find the maximum value in the data.

[0049] The second step is to use the normalization formula, which is:

[0050]

[0051] In this formula:

[0052] original_value: is the original data value, such as the original coordinates of a node or the original length of a pipe.

[0053] min_value: is the minimum value calculated in the first step.

[0054] max_value: is the maximum value calculated in the first step.

[0055] normalized_value: The normalized value usually falls in the range of [0,1].

[0056] Normalizing data can ensure that each feature is within the same magnitude range, which is very important for subsequent data modeling and analysis. Especially in graph neural network models, normalization can prevent some feature values ​​from having an unbalanced impact on model training due to excessive scale.

[0057] Through this normalization process, all data are scaled to the same interval [0,1], which is convenient for subsequent model training or data visualization.

[0058] Step 4: Extract the pipeline information from the variable matrix newline in step 1, including the pipeline and its two end connection nodes and their lengths, and save them in the matrices link_name, graph_connection1 (starting end), graph_connection2 (ending end) and link_length.

[0059] This step 4 specifically includes the following operation steps:

[0060] 1) Find the key identifier: Use the contains function and the find function to search for the row in the newline array that contains 'CONDUITS' (the row where the pipeline data information connecting the two nodes is located), which marks the beginning of the pipeline data and is saved in the variable link_id. Use the find function to determine the position of this row, and adjust the offset to determine the actual data starting row (that is, 3 rows below the row where 'CONDUITS' is located), and save it in the variable link_id_position.

[0061] 2) Determine the end position of the data: Use the contains function and the find function to locate the line containing 'XSECTIONS' and save it in the variable link_idend, which marks the end of the pipeline data. And adjust the offset to determine the actual data end line (that is, 2 lines above the line where 'XSECTIONS' is located) and save it in the variable link_idend_position.

[0062] 3) Calculate the number of pipelines: Use the start and end position calculation (i.e. link_idend_position minus link_id_position plus one) to get the total number of pipelines.

[0063] 4) Loop through the pipeline data: Use a for loop, starting from the first pipeline data row and iterating to the last pipeline data row.

[0064] 5) Regular expression data segmentation: Use the regexp function and the \s+ regular expression to segment each line. This regular expression uses one or more spaces as delimiters to extract the pipe name and related connection nodes and lengths.

[0065] 6) Store the extracted pipeline data: The name of the extracted pipeline, the names of the connecting nodes at both ends, and the length of the pipeline are stored in link_name, graph_connection1 (starting end), graph_connection2 (end end), and link_length respectively.

[0066] Step 5: Establish the pipeline connection relationship matrix edges to save the start and end node index positions corresponding to each pipeline for connection relationship modeling in graph neural networks.

[0067] This step 5 specifically includes the following operation process steps:

[0068] 1) Edge matrix definition: Use the zeros (create an array of all zeros) function to initialize a matrix of size num_link x 2, named edges. This matrix is ​​used to store the index of the start and end nodes of each pipeline in the graph. Each row represents a pipeline, the first column stores the index of the start node, and the second column stores the index of the end node.

[0069] 2) Loop through the pipeline data: Use a for loop, with variable i as the counter (i.e. the number of the pipeline), and traverse from the first pipeline to the last pipeline.

[0070] 3) Extract node names: Inside the loop, get the names of the start node (startNode) and end node (endNode) of the current (i.e., i-th) pipeline from the graph_connection1 and graph_connection2 arrays created previously.

[0071] 4) Find the node index: Use the strcmp function to compare each element of node_name with the startNode string to see if they are exactly the same. When the first identical element is found, use the find function to get the index position of the element and assign this index position to the startIndex variable (i.e. the index position of the starting node). The endIndex (i.e. the index position of the ending node) is the same as above. startIndex and endIndex represent the indexes of the starting node and the ending node in the node_name array respectively.

[0072] 5) Update the pipeline connection relationship matrix: store the found node index startIndex and endIndex in the corresponding rows of the edges matrix. In this way, the start and end node index positions of each edge are recorded in the edges matrix.

[0073] Step 6: Normalize the pipeline length, save the pipeline connection relationship as the first npy file, and save the normalized pipeline length as the second npy file.

[0074] The purpose of this step is to normalize the pipeline length matrix link_length extracted in step 4 and convert it into a link_length_norm matrix, and save it as a pipeline connection relationship matrix and pipeline length for subsequent python reading.

[0075] Step 6 specifically includes the following execution process steps:

[0076] 1) Data type conversion: Use the str2double function to convert the string in the link_length array to a numeric type for mathematical operations.

[0077] 2) Normalization calculation: Use the built-in min and max functions in MATLAB to calculate the minimum and maximum values ​​of link_length, and then use the minimum-maximum normalization formula to convert the pipe length to a value between 0 and 1. This step converts all pipe lengths to values ​​between 0 and 1, so that the length data has a consistent weight in subsequent processing and is saved in the variable link_length_norm, which is conducive to distance-based analysis and calculation.

[0078] 3) Output of pipeline connection relationship matrix file: Use write.NPY (save array as npy file command) function to save the normalized pipeline connection relationship matrix edges in the form of edges.npy file to the specified file path. This function is used to store data in NumPy format so that the data can be easily read and subsequently processed by graph neural network in Python.

[0079] 4) Pipeline length file output: Similar to saving the edge matrix, use the write.NPY function to save the normalized pipeline length link_length_norm in the form of a pipeline length matrix edges_weight.npy file to the specified path. In this way, the pipeline length can also be used in subsequent research.

[0080] Step 7: Extract the catchment area mjjz, maximum imperviousness_doub, total width subWidth_doub and maximum slope slope_doub of each node's associated catchment area from the variable matrix newline in step 1 for subsequent processing.

[0081] This step 7 specifically includes the following execution steps:

[0082] 1) Query data range: Use the contains function and the find function to search for the positions of the rows containing the keywords 'SUBCATCHMENTS' (i.e. the row where the catchment area information is located) and 'SUBAREAS' in the newline array and save them in the variables lia33 and lia44 respectively.

[0083] Define the data range: Use the found row numbers to calculate the row range where the catchment area data is located, this is done by adding 3 to the starting row lia33 (i.e. starting 3 rows below 'SUBCATCHMENTS') and subtracting 2 from the ending row lia44 (i.e. ending 2 rows above 'SUBAREAS'), making sure to skip non-data descriptive content.

[0084] 2) Calculate the number of data rows: Calculate the number of rows occupied by the catchment area. The calculation formula is lia44-lia33-5+1, which includes itself, so add one.

[0085] 3) Initialize the area storage variable: Use cell(0) to initialize an empty cell array mj to temporarily store the area string of each row.

[0086] 4) Initialize the area numerical matrix: Use zeros(0) to initialize an empty numerical array mjjz to store the area data converted into numerical values.

[0087] 5) Initialize temporary storage structure: Before the loop starts, each iteration will reinitialize an mj_all cell array to temporarily store the string split by the expression.

[0088] 6) Regular expression string segmentation: Use the regexp function with the \s+ regular expression to extract and segment the data rows for each catchment area from the newline array. This regular expression segments the string based on one or more spaces.

[0089] 7) Extract specific attributes: For each catchment area, extract the catchment area, maximum imperviousness (variable imperviousness), total width (variable subWidth), and maximum slope (variable slope) from the segmented result mj_all, and store them in the corresponding arrays respectively.

[0090] 8) Digital conversion: Use the str2double function to convert the catchment area data from a string to a number and store it in the mjjz array. Convert the string data of the maximum imperviousness, total width, and maximum slope to numerical values ​​and store them in the imperviousness_doub, subWidth_doub, and slope_doub arrays, respectively.

[0091] Step 8: Normalize the catchment area mjjz, total width subWidth_doub, maximum imperviousness_doub and maximum slope slope_doub of the catchment area extracted in step 7.

[0092] This step 8 specifically includes the following execution process steps:

[0093] 1) Normalized area data: The area data in the mjjz array is converted into values ​​between 0 and 1 using the minimum-maximum normalization formula, where min(mjjz) and max(mjjz) represent the minimum and maximum values ​​in the array, respectively.

[0094] 2) Normalize the total width: Use the minimum-maximum normalization formula applied to the subWidth_doub array to ensure that the data is at the same order of magnitude for easy comparison and further processing.

[0095] 3) Adjust the maximum imperviousness and maximum slope ratio: Since the maximum imperviousness and maximum slope may be provided as a percentage (such as 100 represents 100%), divide them by 100 to convert them to a 0 to 1 ratio.

[0096] Step 9: Construct the X_combine data matrix containing the catchment area, total width, maximum imperviousness, and maximum slope information.

[0097] This step 9 specifically includes the following execution steps:

[0098] 1) Matrix initialization: Use zeros(988,4) to initialize the X_combine matrix to store the four parameters corresponding to 988 nodes: area sum, maximum imperviousness, total width sum, and maximum slope. This matrix dimension is based on the assumption that there are 988 nodes.

[0099] 2) Node traversal: Use a for loop to traverse from 1 to 988 through the counter i, representing each node.

[0100] 3) Get the name of the current node: Use the index to get the name of the current node (i.e. get the i-th node) from the node_name array.

[0101] 4) Find matching catchment areas: Use strcmp and find functions to find the indexes of all entries in the LidToNode array that match the current node name (i.e., the name of the i-th node obtained in the previous step).

[0102] 5) Condition judgment: Check whether the found index array indices is empty, that is, whether there is a catchment area associated with the current node.

[0103] 6) Set default values: If indices is empty, it means that there is no catchment area associated with this node, so all values ​​in the current row of the X_combine matrix are set to 0.

[0104] 7) Accumulate area and total width: If indices is not empty, then for all matched catchment areas, calculate the sum of their area (mjjz) and total width (subWidth_doub), that is, the variables mjjz_sum and subWidth_sum.

[0105] 8) Calculate the maximum value: Calculate the maximum value of the maximum imperviousness (imperviousness_doub) and the maximum slope (slope_doub) of all matched catchment areas, that is, the variables imperviousness_max and slope_max.

[0106] 9) Fill the result matrix: Fill these calculation result variables mjjz_sum, imperviousness_max, subWidth_sum and slope_max (sum of area, maximum imperviousness, sum of total width, maximum slope) into the corresponding columns of the X_combine matrix.

[0107] Step 10: Establish a catchment area name matrix and extract the corresponding outlets of the area; that is, extract the catchment area name and its corresponding outlet information LidToNode1 array from the variable matrix newline in step 1 and save it.

[0108] This step 10 specifically includes the following execution steps:

[0109] 1) Initialize the name storage structure: Use zeros (0) to initialize an empty numeric array mcjz to store the watershed area names converted into numeric values.

[0110] 2) Loop through the catchment area data rows: Use a for loop, starting from the data row of the first catchment area (that is, starting from the data row below the 'SUBCATCHMENTS' row) and iterating to the data row of the last catchment area.

[0111] 3) Regular expression string segmentation: Use the regexp function with \s+ regular expression to extract and segment the data rows for each catchment area from the newline array.

[0112] 4) Extract name data: For each catchment area, extract the first element (i.e. the area number name) from the segmented result mc_all and store it in the mc array.

[0113] 5) Name storage: Assign the contents of the mc array directly to the mcjz array. Here mcjz is used to store the name of the catchment area, which is suitable for situations involving text.

[0114] 6) Initialize the outlet storage structure: Use cell(0) to initialize an empty cell array LidToNode to store the outlet information corresponding to each catchment area.

[0115] 7) Loop through the catchment area data rows: Use a for loop, starting from the first catchment area data row and iterating to the last catchment area data row.

[0116] 8) Regular expression string segmentation: Use the regexp function with the \s+ regular expression to extract and segment the data rows for each catchment area from the newline array.

[0117] 9) Extract outlet data: For each catchment area, extract the third element (i.e. the corresponding number of the outlet) from the segmented result corresponding and store it in the LidToNode array.

[0118] 10) String to number conversion: Use the str2double function to convert the outlet data in the LidToNode array from a string to a number and store it in the LidToNode1 array.

[0119] 11) Save data: Use the write.NPY function to save the LidToNode1 array as a NumPy format file.

[0120] Step 11: extract the outlet data, that is, extract the outlet data from the variable matrix newline in step 1 and identify whether the node is an outlet in the data matrix X_combine established in step 11.

[0121] This step 11 specifically includes the following execution steps:

[0122] 1) Query the range of outlet data: Use the contains function and the find function to retrieve the row containing the label '[OUTFALLS]' (that is, the starting row of the outlet data information corresponding to the node), and shift it down four rows (that is, the four rows below the '[OUTFALLS]' label is the beginning of the actual data), which marks the beginning of the outlet data, and save the position information in the variable outfall_node. Also use the contains and find functions to locate the [CONDUITS] label, which marks the end of the outlet data, and shift it up two rows (that is, the two rows above the '[CONDUITS]' label is the end of the actual data) to accurately define the end of the data interval, and save the position information in the variable outfall_node_end.

[0123] 2) Calculate the number of data rows: Use the difference between the start row and the end row plus one to calculate the total number of outlets (ie, num_outfall = outfall_node_end - outfall_node + 1), and store it in the variable num_outfall.

[0124] 3) Traverse the outlet data rows: Use a for loop to iterate from the first outlet data row to the last outlet data row.

[0125] 4) Initialize the outlet storage array: Use cell(0) to initialize an empty cell array outfall_nodeX for temporarily storing the area string of each row.

[0126] 5) Regular expression string splitting: Use the regexp function with \s+ regular expression to extract and split the data line of each outlet from the newline array.

[0127] 6) Extract the outlet name and bottom elevation: For each outlet, extract the first element (outlet name) and the second element (inner bottom elevation) from the segmented result outfall_nodeX, and store them in the outfall_node_name and outfall_bottomElevation arrays respectively.

[0128] 7) Set the fifth column to zero: Initialize the value of each node in the fifth column of the X_combine matrix to 0, in preparation for recording the existence of the outlet. This step sets the basic state, assuming that no node is an outlet at the beginning.

[0129] 8) Node traversal: Use a for loop to traverse each outlet. The number of loops is determined by num_outfall (the total number of outlets).

[0130] 9) Extract the current outlet name: Use the array index to get the name of the current outlet from the outfall_node_name array and store it in the outfall_node_now variable.

[0131] 10) Find the node index: Use the strcmp function to compare node_name (an array of all node names) with the outfall_node_now array to find the node index with a matching name. The find function returns the position of this matching node in the node_name array.

[0132] 11) Set the outlet mark: Set the value of the node index position found in the fifth column of the X_combine matrix to 1, marking the node as the outlet.

[0133] Step 12: Extract the node elevation and node depth information from the variable matrix newline in step 1 and normalize them to obtain the Node_bottomElevation and Node_MaxDepth_norm arrays.

[0134] This step 12 specifically includes the following execution process steps:

[0135] 1) Query data range: Use the contains function and find function to retrieve the row containing the label '[JUNCTIONS]' (that is, the starting row of the data information of the node elevation and node depth corresponding to the node), and shift it down three rows (that is, the three rows below the '[JUNCTIONS]' label are the beginning of the actual data), which marks the beginning of the outlet data, and save the position information in the variable Junctions. Also use the contains and find functions to locate the [OUTFALLS] label, which marks the end of the outlet data, and shift it up two rows (that is, the two rows above the '[OUTFALLS]' label are the end of the actual data) to accurately define the end of the data interval, and save the position information in the variable outfall_node_new.

[0136] 2) Calculate the total number of nodes involved: Use the difference between the start and end rows plus one to calculate the total number of nodes involved, stored in num_Junctions.

[0137] 3) Traverse the node data rows: Use a for loop to iterate from the first node data row to the last node data row.

[0138] 4) Regular expression string splitting: Use the regexp function with the \s+ regular expression to extract and split the data line of each node from the newline array and save it in the variable Junctions_nodeX.

[0139] 5) Extract node elevation and node depth: For each node, extract the second element (node ​​elevation) and the third element (node ​​depth) from the segmented result Junctions_nodeX, and store them in the Junctions_bottomElevation and Junctions_MaxDepth arrays respectively.

[0140] 6) Merge node elevation data: Use array concatenation operation to merge the Junctions_bottomElevation and outfall_bottomElevation arrays.

[0141] 7) Fill in missing node depth values: For the outlet node, there is no maximum depth data, so a constant of '10' is used instead. Use the repmat function to generate an array with an element of '10' and a length equal to the number of outlet nodes (num_node-length(Junctions_MaxDepth)), and merge it with the Junctions_MaxDepth array.

[0142] 8) Convert node elevation and node depth data to numeric types: Convert the strings in the Node_bottomElevation and Node_MaxDepth arrays to double-precision floating point numbers.

[0143] 9) Normalize node elevation: Calculate the normalized values ​​of the Node_bottomElevation and Node_MaxDepth_norm arrays, and scale all node elevation data to between 0 and 1.

[0144] Step 13: Construct the final X_combine_final matrix, that is, integrate the node X, Y coordinate data normalized in step 3 and the node elevation and node depth data Node_bottomElevation and Node_MaxDepth_norm arrays normalized in step 12 into the X_combine matrix filled in step 9 and save it as an NPY file for subsequent data extraction of the python graph neural network.

[0145] This step 13 specifically includes the following process steps:

[0146] 1) Combine data: Combine the X_combine matrix with the normalized node positions node_positionX_norm' and node_positionY_norm', and the normalized node elevation Node_bottomElevation_norm' and node depth Node_MaxDepth_norm' arrays. Use array transpose' for each matrix here to ensure that all data columns are correctly aligned.

[0147] 2) Data merging: Through array concatenation operations, different data sources are integrated into a larger data matrix X_combine_final for unified processing and analysis.

[0148] 3) Save data: Use the write.NPY function to save the X_combine_final matrix as a NumPy file. The columns in the X_combine_final matrix include the node X and Y position, catchment area, maximum imperviousness, total width, maximum slope, whether it is an outlet, node elevation, and node depth data related to each node.

[0149] As an optimization, the second step of this method specifically includes the following steps:

[0150] Step a: Loading the initialization environment; including the following execution steps;

[0151] 1) Set up the environment;

[0152] Import the following libraries:

[0153] Numpy library: used for numerical calculations;

[0154] Torch library and torch_geometric.data library: used for graph neural network data structure processing;

[0155] Networkx library and matplotlib library: for graph visualization.

[0156] 2) Set the environment variable os.environ['KMP_DUPLICATE_LIB_OK'] = 'TRUE' to resolve potential parallel processing library conflicts.

[0157] Step b: Load the node, edge and weight data converted from MATLAB software; that is, load the pipeline connection relationship, pipeline length data and node characteristics required for the graph structure in the edges.npy, edges_weight.npy and X_combine_final.npy files created by MATLAB software from external files.

[0158] This step b specifically includes the following execution steps:

[0159] 1) Create a variable edges to determine the pipeline connection relationship = np.load(r'C:\...\edges.npy'): Load the pipeline network connection relationship between the catchment areas. This is a two-dimensional array, where each row contains two integers, indicating the start and end node number names of the pipeline connection.

[0160] 2) Create variables to read data and determine the length of the pipeline edges_weight = np.load(r'C:\...\edges_weight.npy'): load the length of the pipeline after normalization. This is a one-dimensional array with a length of num_edges.

[0161] 3) x_combine_final = np.load(r'C:\...\X_combine_final.npy'): Load the node feature matrix, including the relevant information of each catchment area. The columns in the X_combine_final matrix include the node's catchment area, maximum imperviousness, total width, maximum slope, whether it is an outlet, node X and Y position, node elevation, and node depth data. Through these loading steps, the code successfully obtains all the node features, pipe connection relationships, and pipe length data required to build the graph structure from the external file, ready for the next step of processing.

[0162] Step c: Construct the input data based on the graph neural network and convert the loaded node features and edge information into a format that can be used by the graph neural network (GNN).

[0163] This step c specifically includes the following execution steps:

[0164] 1) Execute device = torch.device("cuda" if torch.cuda.is_available() else "cpu"): Move data to the GPU (computer graphics processing unit) or CPU (computer central processing unit) depending on the availability of CUDA.

[0165] 2) Execute x_combine = torch.tensor(x_combine_final, dtype = torch.float).to(device): Create the x_combine variable to save the PyTorch tensor after converting the node feature matrix and move it to the device (GPU / CPU). torch.tensor is the command to convert data into a PyTorch tensor.

[0166] 3) Execute edge_index = torch.tensor(edges.T-1, dtype = torch.long).to(device): Create the edge_index variable to convert the edge index matrix into a PyTorch tensor and move it to the corresponding device. Note that edges.T is transposed here, and the dimension is (2, num_edges). (The edge index is reduced by 1 to adjust the node number from 1-based to 0-based, which conforms to the Python indexing standard)

[0167] 4) Execute edge_attr = torch.tensor(edges_weight, dtype = torch.float).to(device): Create the edge_attr variable to convert the pipeline length (pipeline length) into a PyTorch tensor. At this point, all the matrix data required for the graph neural network has been loaded.

[0168] 5) Use the Data(x=x_combine, edge_index=edge_index, edge_attr=edge_attr) function to package the node features, edge information, and pipeline length into a graph data object and store it in the variable data.

[0169] Step d: Extract the node positions of the graph and process isolated nodes in the graph to ensure the integrity of the graph structure.

[0170] This step d specifically includes the following execution steps:

[0171] 1) Create a variable node_positions = x_combine[:,[5,6]].cpu().numpy(): Extract the X and Y coordinate information of the node. The 6th and 7th columns of x_combine store the plane coordinates of each node, which are used to locate the position of the node on the graph.

[0172] 2) Handle isolated nodes. The specific process is as follows:

[0173] a) Use NetworkX to build a directed graph DiGraph and filter out isolated nodes without edges;

[0174] b) Use edge_index.cpu().numpy().T to convert edge information into NumPy format and store it in edges_numpy;

[0175] c) Get the set of nodes connected to the edge through edges_numpy.flatten() and store it in the connected_nodes variable;

[0176] 3) Execute G.add_edges_from((u,v)for u,v in edges_numpy if u in connected_nodes and v in connected_nodes): add pipeline connection relationships (i.e. edges) to the network graph G, including only connected nodes.

[0177] 4) Create variable area_column = x_combine[:len(G.nodes),0].cpu().numpy(): extract the area information of the node.

[0178] 5) Create variable outlet_column = x_combine[:len(G.nodes),4].cpu().numpy(): Extract the Boolean value of whether the node is an outlet. Based on this information, set the outlet node to blue, set the default color to orange, and set the point with an area of ​​0 to light red. The color of other nodes changes according to the area.

[0179] 6) Set color: Set color rules according to the area of ​​the node and the outlet attributes. The specific process is as follows;

[0180] If the node is an outlet (is_outlet == 1), set it to blue (0.33, 0.66, 0.89, 0.8); if the area is 0 (area == 0), set it to light red (0.83, 0.37, 0.33, 0.8); for other nodes, use the default orange (0.96, 0.73, 0.48, 0.8); and store the color of each node in the list node_colors;

[0181] 7) Determine the node position: Use the extracted node coordinates to generate the node position dictionary pos, where the key of the dictionary is the node index and the value is the x, y coordinates of the node.

[0182] Step e: Visualize the graph and make detailed adjustments to the visualized part of the image so that the information of nodes and edges is intuitively visible.

[0183] This step e specifically includes the following execution steps:

[0184] 1) Draw nodes:

[0185] Use nx.draw_networkx_nodes (the command for drawing nodes in the graph) function to draw the nodes.

[0186] Use the pos instruction to map each node to its position (usually a 2D coordinate).

[0187] The color of each node is specified using the node_color directive.

[0188] The size of the nodes (in points) is set with the node_size directive.

[0189] The alpha command sets the transparency of the color.

[0190] The edgecolors directive sets the color of the node borders.

[0191] 2) Draw edges and arrows:

[0192] Use nx.draw_networkx_edges function to draw edges.

[0193] The arrowstyle and arrowsize parameters control the style and size of the arrows.

[0194] The color and total width of the edge are set with the edge_color and width parameters.

[0195] The connectionstyle parameter controls the curvature style of the edges.

[0196] 3) Add a legend:

[0197] Use the mpatches.Patch command to create labels that match the node colors.

[0198] Use the plt.legend function to add a legend to a figure.

[0199] The position of the legend is set with the loc parameter.

[0200] The fontsize and prop parameters are used to control the font size and font of the text in the legend.

[0201] Step f: Save the generated graphics as a high-quality image file.

[0202] This step f specifically includes the following execution process steps:

[0203] 1) Define the path to save the image: Create the output_path variable to determine the save location.

[0204] 2) Save the image: Use the savefig command to save the image, and use the format command to specify the image saving format as JPG and the resolution DPI as 600.

[0205] Compared with the existing technology, the advantages of this method are as follows: Compared with other methods that directly use the SWMM model to study urban waterlogging and analyze sponge city LID construction plans, this method can efficiently and accurately complete the direct identification of SWMM model information data and convert it into data that can be directly recognized and used by the graph neural network, saving a lot of time in importing the original model data one by one into the graph neural network, converting the SWMM model data into data that can be directly recognized by the graph neural network, solving the problem that traditional urban hydrological and hydraulic model data are difficult to directly use modern intelligent algorithms for efficient analysis and prediction. By combining SWMM's simulation capabilities for urban precipitation with the advantages of graph neural networks in complex network data analysis, it provides more accurate technical support for urban water resources management, flood control, and infrastructure planning and research and analysis.

[0206] In summary, the present invention simplifies the data processing flow, realizes the rapid structuring of SWMM model data, provides accurate and real-time analysis support for urban hydrological management, and is an important technological innovation for smart city construction and modern management. BRIEF DESCRIPTION OF THE DRAWINGS

[0207] Figure 1 This is a model picture derived from the .inp file data under the SWMM software for the SWMM model established for Wanzhou District, Chongqing in a specific implementation manner of the present invention.

[0208] Figure 2 for Figure 1The SWMM model is generated after the data conversion in MATLAB and the visualization in Python’s graph neural network. DETAILED DESCRIPTION

[0209] The present invention is further described in detail below in conjunction with specific implementation modes. Specific implementation method:

[0211] An interactive method for converting SWMM model data into data directly recognized by a graph neural network, firstly establishing a SWMM model of a research urban area, dividing the catchment area in the model, and exporting an inp (a text file with a suffix of inp) file; characterized in that it also includes the following steps:

[0212] Step 1: First, based on MATLAB (a commercial mathematical software used for data analysis), the .inp file of the SWMM model is read. The X-axis coordinate position and Y-axis coordinate position of each node are first extracted and normalized. Then, the pipeline connection relationship (i.e., the pipeline and its two-end node information) and pipeline length information are extracted. After extraction, the pipeline connection relationship information is saved as the first npy file (a binary file used to save array data), and the pipeline length information is saved as the second npy file. Then, the drainage area, maximum imperviousness, total width, maximum slope, whether it is a drainage outlet, node elevation and node depth data associated with each node are extracted and normalized. Finally, the node X and Y position, drainage area, maximum imperviousness, total width, maximum slope, whether it is a drainage outlet, node elevation and node depth data are integrated and saved as a node feature matrix, and the node feature matrix is ​​saved as the third npy file.

[0213] Step 2: Use Python (a computer language) software to visualize the npy file.

[0214] Thus, in the present invention, the node-related data, pipeline connection relationship and pipeline length data are first normalized and saved as three different npy files. In this step, all the data of the inp file of the SWMM model are converted into a form that can be directly recognized and used by the graph neural network. The graph neural network can help identify potential drainage problems in the area (such as waterlogging, sewage overflow, etc.), and can also help understand the flow process of water in the drainage system, predict future water level changes, the susceptibility of urban flood disasters, etc., and better help researchers to assess the flood risk of the city. Then, based on these three npy files, python software is used to realize visualization processing. In the step, isolated nodes (nodes with no pipes connected to other nodes) are visualized. ) are removed to transform complex data into simpler and more intuitive graphics, which helps users to more quickly identify key nodes and pipelines in the model, as well as the relationships and interactions between them. This processing also makes it easier for users to find nodes that lack drainage areas and information such as outlets, helping users to optimize their decisions. For example, in the risk assessment of urban flood disasters, the relative positions of various nodes in the urban drainage system and the flow direction of water can be quickly understood, so that designers can more intuitively add pipelines to areas prone to floods and adjust nodes that lack drainage areas, allowing urban planners to better plan and adjust corresponding urban functional areas or emergency measures in urban flood-prone areas, etc.

[0215] Therefore, the present invention realizes the direct interaction between the SWMM model and the Python graph neural network using Matlab software, which facilitates the use of graph neural network algorithms to directly analyze various types of urban waterlogging data and conduct related research. By combining SWMM and GNN, more advanced automation and intelligence can be achieved in the design, optimization and operation management of urban drainage systems, effectively reducing human errors and improving the system's response speed and disaster management capabilities.

[0216] In the scheme, a node refers to the connection point of the pipeline in the urban drainage network system, which can be a diverter, storage unit or discharge port. These nodes play a key role in the network structure of the drainage system. They connect different links (such as pipes, channels, etc.) and allow water to flow or store between these links.

[0217] In the scheme, the X-axis coordinate position and Y-axis coordinate position of each node (Node X and Y Coordinates) refer to the geometric coordinates of the node in two-dimensional space, which are used to describe its specific position in the drainage network in the model. The X and Y positions of the node are stored in node_positionX (variable matrix name) and node_positionY respectively, and node_positionX_norm and node_positionY_norm are generated by normalization.

[0218] In the scheme, the catchment area associated with each node refers to the sum of the catchment areas of all areas converging to a node, which is used to represent the range of rainwater sources received by the node. In the model, the catchment area directly affects the input water volume of the node and is one of the key determinants of the node flow. A larger catchment area means that the node needs to handle more rainwater and may also put higher pressure on the downstream pipeline. The catchment area is represented by the variable mjjz in the step, and it is normalized to the minimum-maximum in subsequent processing to generate the normalized result mjjz_norm.

[0219] In the scheme, the maximum imperviousness associated with each node refers to the proportion of impervious surfaces (such as buildings, roads, etc.) in the catchment area associated with a node to the total area. It reflects the part of the rainwater runoff processed by the node that cannot penetrate into the ground. The higher the maximum imperviousness of the node, the greater the surface runoff it collects, increasing the burden on the downstream pipe network. In the step, this physical quantity is stored in the variable imperviousness_doub and normalized to generate imperviousness_norm.

[0220] In the scheme, the total width (Subcatchment Width) associated with each node refers to the total width of the water flow path in the catchment area associated with a node, which describes the degree of dispersion of the water flow converging to the node. The larger the total width, the shorter the water flow path and the faster the water flow speed, so the water flow impact received by the node may be greater. This physical quantity is represented by the variable subWidth_doub in the step, and the normalized result is stored as subWidth_norm.

[0221] In the scheme, the maximum slope associated with each node refers to the maximum terrain slope of the catchment area associated with a node, which is used to indicate the acceleration ability of water flow in the area. The larger the slope, the faster the water flows to the node, which may cause greater flow pressure on the node. A smaller slope results in a slower water flow and a longer confluence time. This physical quantity is represented by slope_doub and is normalized to generate slope_norm.

[0222] In the scheme, the outlet (Is Outlet) associated with each node indicates whether a node is the terminal discharge point of the drainage system. It is stored as a Boolean value, 0 for a normal node and 1 for an outlet node. The outlet node is the key point of the entire drainage system and directly affects the drainage efficiency. For the outlet node, water is discharged from the system to the external environment; while the non-outlet node is only a transfer node for water flow in the pipe network. In the step, this attribute is stored in the fifth column of the matrix X_combine to identify the function of the node.

[0223] In the scheme, the node elevation associated with each node refers to the ground height of a node, which is used to reflect the terrain characteristics of the node. Elevation affects the gravity flow direction of water flow and is a key parameter that determines whether the water flow can be discharged smoothly. Elevation data is stored as Node_bottomElevation and generated as Node_bottomElevation_norm after normalization for subsequent model calculations.

[0224] In the scheme, the node depth associated with each node refers to the maximum depth from the ground of the node to the bottom of the drainage pipe. It represents the maximum water holding capacity of the node. The greater the depth, the more water the node can hold. The node depth is stored as Node_MaxDepth and is normalized to generate Node_MaxDepth_norm.

[0225] The first step of this method specifically comprises the following steps:

[0226] Step 1: Use MATLAB software to open the SWMM model and extract the information data in the inp file; convert all data content into the variable matrix newline (variable matrix name) for subsequent processing.

[0227] The specific implementation process of step 1 is as follows:

[0228] 1) Set the simulation step size: define a variable time_step with a value of 5, which means that the simulation is performed every 5 minutes.

[0229] 2) Clean up the environment: Use the clear and clc commands to clear the variables and command windows in the MATLAB environment to prepare for new file operations.

[0230] 3) File path and mode: Use the fopen (open file and set read-write mode command) function to open a .inp file containing SWMM model data. Here the file is opened in read-write mode (r+), allowing the file content to be modified.

[0231] 4) Initialize variables: Initialize variable i and array newline. newline is used to store each line of data read from the file.

[0232] 5) Loop reading: Use the while loop and the feof function to check if the file has reached the end. This loop remains active until the file is completely read.

[0233] 6) Read line by line: Use the fgetl (read file content line by line command) function to read the file content line by line. Each time a line is read, the variable i increases by 1 and the read line is stored in the newline array.

[0234] 7) Close file operation: Use fclose(fileID) (close opened file command) command to close the previously opened file. This is an important operation used to release system resources and ensure that all changes are saved.

[0235] Step 2: Extract the node X and Y axis coordinate information, that is, extract the node name and coordinate information from the variable matrix newline in step 1, and convert it into the node number name matrix node_name, the node position X coordinate node_positionX, and the node position Y coordinate node_positionY, so as to be used for establishing the graph structure.

[0236] The specific implementation of step 2 includes the following operation steps:

[0237] 1) Initialize and find the node position: Use the contains (command to determine whether a string array contains a specific substring) function and the find (command to find the index of the element that meets the condition) function to find and locate the row containing 'COORDINATES' (the row where the coordinates are located) and 'VERTICES' in the newline array and save them in the variables node_id and node_idend respectively. By finding the position of these keywords, the start (3 rows below the row where 'COORDINATES' is located) and end (1 row above the row where 'VERTICES' is located) of the node data can be located.

[0238] 2) Calculate the number of nodes: Based on the starting and ending positions of the node data, calculate the total number of nodes, which is obtained by subtracting the starting position from the ending position plus one and saved in the variable num_node.

[0239] 3) Loop to extract node data: Use a for loop, starting from the starting position, and loop to extract the data of each node according to the number of nodes.

[0240] 4) Split data by expression: Use the regexp (split string by regular expression) function and the expression \s+ to split each line of data, so that the node name and coordinate information can be extracted. This expression splits the string based on spaces to obtain detailed information about the node.

[0241] 5) Storing node information: storing the node number name, the X-axis coordinate of the node position, and the Y-axis coordinate of the node position obtained by segmentation into pre-defined variables node_name, node_positionX, and node_positionY respectively.

[0242] Step 3: Normalize the X and Y axis coordinate data of the node, that is, convert the node X and Y coordinate information extracted in step 2 into normalized values ​​and save them in the matrices node_positionX_norm and node_positionY_norm respectively to ensure that the data is in the range of 0 to 1.

[0243] The specific implementation of step 3 includes the following operation steps:

[0244] 1) String to number conversion: Use the str2double (convert a string to a double-precision numerical command) function to convert the node coordinates node_positionX and node_positionY from a string format to a double-precision floating point number (double).

[0245] 2) Process the coordinate data using min-max normalization: Calculate the minimum and maximum values ​​of node_positionX and node_positionY respectively. These values ​​are used in the subsequent normalization process to ensure that all coordinates are scaled to the range between 0 and 1.

[0246] 3) Perform normalization: Normalize node_positionX and node_positionY, and use the normalization formula to convert each coordinate value into a value in the range of 0 to 1, where the minimum coordinate becomes 0 and the maximum coordinate becomes 1. After calculation, the data is stored in variables node_positionX_norm and node_positionY_norm respectively.

[0247] The normalization process is explained here:

[0248] The normalization step is usually to scale the data values ​​of different features to a relatively consistent range to facilitate model processing or further data analysis.

[0249] The first step of normalization is to determine the minimum and maximum values. For the data that needs to be normalized (such as the X coordinate, Y coordinate of a node, or the length of a pipeline), the minimum and maximum values ​​of these data need to be calculated first.

[0250] Minimum: Use the min() function to find the minimum value in the data.

[0251] Maximum: Use the max() function to find the maximum value in the data.

[0252] The second step is to use the normalization formula, which is:

[0253]

[0254] In this formula:

[0255] original_value: is the original data value, such as the original coordinates of a node or the original length of a pipe.

[0256] min_value: is the minimum value calculated in the first step.

[0257] max_value: is the maximum value calculated in the first step.

[0258] normalized_value: The normalized value usually falls in the range of [0,1].

[0259] Normalizing data can ensure that each feature is within the same magnitude range, which is very important for subsequent data modeling and analysis. Especially in graph neural network models, normalization can prevent some feature values ​​from having an unbalanced impact on model training due to excessive scale.

[0260] Through this normalization process, all data are scaled to the same interval [0,1], which is convenient for subsequent model training or data visualization.

[0261] Step 4: Extract the pipeline information from the variable matrix newline in step 1, including the pipeline and its two end connection nodes and their lengths, and save them in the matrices link_name, graph_connection1 (starting end), graph_connection2 (ending end) and link_length.

[0262] This step specifically includes the following operation steps:

[0263] 1) Find the key identifier: Use the contains function and the find function to search for the row in the newline array that contains 'CONDUITS' (the row where the pipeline data information connecting the two nodes is located), which marks the beginning of the pipeline data and is saved in the variable link_id. Use the find function to determine the position of this row, and adjust the offset to determine the actual data starting row (that is, 3 rows below the row where 'CONDUITS' is located), and save it in the variable link_id_position.

[0264] 2) Determine the end position of the data: Use the contains function and the find function to locate the line containing 'XSECTIONS' and save it in the variable link_idend, which marks the end of the pipeline data. And adjust the offset to determine the actual data end line (that is, 2 lines above the line where 'XSECTIONS' is located) and save it in the variable link_idend_position.

[0265] 3) Calculate the number of pipelines: Use the start and end position calculation (i.e. link_idend_position minus link_id_position plus one) to get the total number of pipelines.

[0266] 4) Loop through the pipeline data: Use a for loop, starting from the first pipeline data row and iterating to the last pipeline data row.

[0267] 5) Regular expression data segmentation: Use the regexp function and the \s+ regular expression to segment each line. This regular expression uses one or more spaces as delimiters to extract the pipe name and related connection nodes and lengths.

[0268] 6) Store the extracted pipeline data: The name of the extracted pipeline, the names of the connecting nodes at both ends, and the length of the pipeline are stored in link_name, graph_connection1 (starting end), graph_connection2 (end end), and link_length respectively.

[0269] Step 5: Establish the pipeline connection relationship matrix edges to save the start and end node index positions corresponding to each pipeline for connection relationship modeling in graph neural networks.

[0270] This step 5 specifically includes the following operation process steps:

[0271] 1) Edge matrix definition: Use the zeros (create an array of all zeros) function to initialize a matrix of size num_link x 2, named edges. This matrix is ​​used to store the index of the start and end nodes of each pipeline in the graph. Each row represents a pipeline, the first column stores the index of the start node, and the second column stores the index of the end node.

[0272] 2) Loop through the pipeline data: Use a for loop, with variable i as the counter (i.e. the number of the pipeline), and traverse from the first pipeline to the last pipeline.

[0273] 3) Extract node names: Inside the loop, get the names of the start node (startNode) and end node (endNode) of the current (i.e., i-th) pipeline from the graph_connection1 and graph_connection2 arrays created previously.

[0274] 4) Find the node index: Use the strcmp function to compare each element of node_name with the startNode string to see if they are exactly the same. When the first identical element is found, use the find function to get the index position of the element and assign this index position to the startIndex variable (i.e. the index position of the starting node). The endIndex (i.e. the index position of the ending node) is the same as above. startIndex and endIndex represent the indexes of the starting node and the ending node in the node_name array respectively.

[0275] 5) Update the pipeline connection relationship matrix: store the found node index startIndex and endIndex in the corresponding rows of the edges matrix. In this way, the start and end node index positions of each edge are recorded in the edges matrix.

[0276] Step 6: Normalize the pipeline length, save the pipeline connection relationship as the first npy file, and save the normalized pipeline length as the second npy file.

[0277] The purpose of this step is to normalize the pipeline length matrix link_length extracted in step 4 and convert it into a link_length_norm matrix, and save it as a pipeline connection relationship matrix and pipeline length for subsequent python reading.

[0278] Step 6 specifically includes the following execution process steps:

[0279] 1) Data type conversion: Use the str2double function to convert the string in the link_length array to a numeric type for mathematical operations.

[0280] 2) Normalization calculation: Use the built-in min and max functions in MATLAB to calculate the minimum and maximum values ​​of link_length, and then use the minimum-maximum normalization formula to convert the pipe length to a value between 0 and 1. This step converts all pipe lengths to values ​​between 0 and 1, so that the length data has a consistent weight in subsequent processing and is saved in the variable link_length_norm, which is conducive to distance-based analysis and calculation.

[0281] 3) Output of pipeline connection relationship matrix file: Use write.NPY (save array as npy file command) function to save the normalized pipeline connection relationship matrix edges in the form of edges.npy file to the specified file path. This function is used to store data in NumPy format so that the data can be easily read and subsequently processed by graph neural network in Python.

[0282] 4) Pipeline length file output: Similar to saving the edge matrix, use the write.NPY function to save the normalized pipeline length link_length_norm in the form of a pipeline length matrix edges_weight.npy file to the specified path. In this way, the pipeline length can also be used in subsequent research.

[0283] Step 7: Extract the catchment area mjjz, maximum imperviousness_doub, total width subWidth_doub and maximum slope slope_doub of each node's associated catchment area from the variable matrix newline in step 1 for subsequent processing.

[0284] This step 7 specifically includes the following execution steps:

[0285] 1) Query data range: Use the contains function and the find function to search for the positions of the rows containing the keywords 'SUBCATCHMENTS' (i.e. the row where the catchment area information is located) and 'SUBAREAS' in the newline array and save them in the variables lia33 and lia44 respectively.

[0286] Define the data range: Use the found row numbers to calculate the row range where the catchment area data is located, this is done by adding 3 to the starting row lia33 (i.e. starting 3 rows below 'SUBCATCHMENTS') and subtracting 2 from the ending row lia44 (i.e. ending 2 rows above 'SUBAREAS'), making sure to skip non-data descriptive content.

[0287] 2) Calculate the number of data rows: Calculate the number of rows occupied by the catchment area. The calculation formula is lia44-lia33-5+1, which includes itself, so add one.

[0288] 3) Initialize the area storage variable: Use cell(0) to initialize an empty cell array mj to temporarily store the area string of each row.

[0289] 4) Initialize the area numerical matrix: Use zeros(0) to initialize an empty numerical array mjjz to store the area data converted into numerical values.

[0290] 5) Initialize temporary storage structure: Before the loop starts, each iteration will reinitialize an mj_all cell array to temporarily store the string split by the expression.

[0291] 6) Regular expression string segmentation: Use the regexp function with the \s+ regular expression to extract and segment the data rows for each catchment area from the newline array. This regular expression segments the string based on one or more spaces.

[0292] 7) Extract specific attributes: For each catchment area, extract the catchment area, maximum imperviousness (variable imperviousness), total width (variable subWidth), and maximum slope (variable slope) from the segmented result mj_all, and store them in the corresponding arrays respectively.

[0293] 8) Digital conversion: Use the str2double function to convert the catchment area data from a string to a number and store it in the mjjz array. Convert the string data of the maximum imperviousness, total width, and maximum slope to numerical values ​​and store them in the imperviousness_doub, subWidth_doub, and slope_doub arrays, respectively.

[0294] Step 8: Normalize the catchment area mjjz, total width subWidth_doub, maximum imperviousness_doub and maximum slope slope_doub of the catchment area extracted in step 7.

[0295] This step 8 specifically includes the following execution process steps:

[0296] 1) Normalize area data: Normalize the area data in the mjjz array using the minimum-maximum normalization formula:

[0297]

[0298] Convert the value to a value between 0 and 1, where min(mjjz) and max(mjjz) represent the minimum and maximum values ​​in the array respectively.

[0299] 2) Normalize the total width: Use the minimum-maximum normalization formula applied to the subWidth_doub array, the formula is as follows:

[0300]

[0301] To ensure that the data are at the same level, it is easy to compare and further process.

[0302] 3) Adjust the maximum imperviousness and maximum slope ratio: Since the maximum imperviousness and maximum slope may be provided as a percentage (such as 100 represents 100%), divide them by 100 to convert them to a 0 to 1 ratio.

[0303] Step 9: Construct the X_combine data matrix containing the catchment area, total width, maximum imperviousness, and maximum slope information.

[0304] This step 9 specifically includes the following execution steps:

[0305] 1) Matrix initialization: Use zeros(988,4) to initialize the X_combine matrix to store the four parameters corresponding to 988 nodes: area sum, maximum imperviousness, total width sum, and maximum slope. This matrix dimension is based on the assumption that there are 988 nodes.

[0306] 2) Node traversal: Use a for loop to traverse from 1 to 988 through the counter i, representing each node.

[0307] 3) Get the name of the current node: Use the index to get the name of the current node (i.e. get the i-th node) from the node_name array.

[0308] 4) Find matching catchment areas: Use strcmp and find functions to find the indexes of all entries in the LidToNode array that match the current node name (i.e., the name of the i-th node obtained in the previous step).

[0309] 5) Condition judgment: Check whether the found index array indices is empty, that is, whether there is a catchment area associated with the current node.

[0310] 6) Set default values: If indices is empty, it means that there is no catchment area associated with this node, so all values ​​in the current row of the X_combine matrix are set to 0.

[0311] 7) Accumulate area and total width: If indices is not empty, then for all matched catchment areas, calculate the sum of their area (mjjz) and total width (subWidth_doub), that is, the variables mjjz_sum and subWidth_sum.

[0312] 8) Calculate the maximum value: Calculate the maximum value of the maximum imperviousness (imperviousness_doub) and the maximum slope (slope_doub) of all matched catchment areas, that is, the variables imperviousness_max and slope_max.

[0313] 9) Fill the result matrix: Fill these calculation result variables mjjz_sum, imperviousness_max, subWidth_sum and slope_max (sum of area, maximum imperviousness, sum of total width, maximum slope) into the corresponding columns of the X_combine matrix.

[0314] Step 10: Establish a catchment area name matrix and extract the corresponding outlets of the area; that is, extract the catchment area name and its corresponding outlet information LidToNode1 array from the variable matrix newline in step 1 and save it.

[0315] This step 10 specifically includes the following execution steps:

[0316] 1) Initialize the name storage structure: Use zeros (0) to initialize an empty numeric array mcjz to store the watershed area names converted into numeric values.

[0317] 2) Loop through the catchment area data rows: Use a for loop, starting from the data row of the first catchment area (that is, starting from the data row below the 'SUBCATCHMENTS' row) and iterating to the data row of the last catchment area.

[0318] 3) Regular expression string segmentation: Use the regexp function with \s+ regular expression to extract and segment the data rows for each catchment area from the newline array.

[0319] 4) Extract name data: For each catchment area, extract the first element (i.e. the area number name) from the segmented result mc_all and store it in the mc array.

[0320] 5) Name storage: Assign the contents of the mc array directly to the mcjz array. Here mcjz is used to store the name of the catchment area, which is suitable for situations involving text.

[0321] 6) Initialize the outlet storage structure: Use cell(0) to initialize an empty cell array LidToNode to store the outlet information corresponding to each catchment area.

[0322] 7) Loop through the catchment area data rows: Use a for loop, starting from the first catchment area data row and iterating to the last catchment area data row.

[0323] 8) Regular expression string segmentation: Use the regexp function with the \s+ regular expression to extract and segment the data rows for each catchment area from the newline array.

[0324] 9) Extract outlet data: For each catchment area, extract the third element (i.e. the corresponding number of the outlet) from the segmented result corresponding and store it in the LidToNode array.

[0325] 10) String to number conversion: Use the str2double function to convert the outlet data in the LidToNode array from a string to a number and store it in the LidToNode1 array.

[0326] 11) Save data: Use the write.NPY function to save the LidToNode1 array as a NumPy format file.

[0327] Step 11: extract the outlet data, that is, extract the outlet data from the variable matrix newline in step 1 and identify whether the node is an outlet in the data matrix X_combine established in step 11.

[0328] This step 11 specifically includes the following execution steps:

[0329] 1) Query the range of outlet data: Use the contains function and the find function to retrieve the row containing the label '[OUTFALLS]' (that is, the starting row of the outlet data information corresponding to the node), and shift it down four rows (that is, the four rows below the '[OUTFALLS]' label is the beginning of the actual data), which marks the beginning of the outlet data, and save the position information in the variable outfall_node. Also use the contains and find functions to locate the [CONDUITS] label, which marks the end of the outlet data, and shift it up two rows (that is, the two rows above the '[CONDUITS]' label is the end of the actual data) to accurately define the end of the data interval, and save the position information in the variable outfall_node_end.

[0330] 2) Calculate the number of data rows: Use the difference between the start row and the end row plus one to calculate the total number of outlets (ie, num_outfall = outfall_node_end - outfall_node + 1), and store it in the variable num_outfall.

[0331] 3) Traverse the outlet data rows: Use a for loop to iterate from the first outlet data row to the last outlet data row.

[0332] 4) Initialize the outlet storage array: Use cell(0) to initialize an empty cell array outfall_nodeX for temporarily storing the area string of each row.

[0333] 5) Regular expression string splitting: Use the regexp function with \s+ regular expression to extract and split the data line of each outlet from the newline array.

[0334] 6) Extract the outlet name and bottom elevation: For each outlet, extract the first element (outlet name) and the second element (inner bottom elevation) from the segmented result outfall_nodeX, and store them in the outfall_node_name and outfall_bottomElevation arrays respectively.

[0335] 7) Set the fifth column to zero: Initialize the value of each node in the fifth column of the X_combine matrix to 0, in preparation for recording the existence of the outlet. This step sets the basic state, assuming that no node is an outlet at the beginning.

[0336] 8) Node traversal: Use a for loop to traverse each outlet. The number of loops is determined by num_outfall (the total number of outlets).

[0337] 9) Extract the current outlet name: Use the array index to get the name of the current outlet from the outfall_node_name array and store it in the outfall_node_now variable.

[0338] 10) Find the node index: Use the strcmp function to compare node_name (an array of all node names) with the outfall_node_now array to find the node index with a matching name. The find function returns the position of this matching node in the node_name array.

[0339] 11) Set the outlet mark: Set the value of the node index position found in the fifth column of the X_combine matrix to 1, marking the node as the outlet.

[0340] Step 12: Extract the node elevation and node depth information from the variable matrix newline in step 1 and normalize them to obtain the Node_bottomElevation and Node_MaxDepth_norm arrays.

[0341] This step 12 specifically includes the following execution process steps:

[0342] 1) Query data range: Use the contains function and find function to retrieve the row containing the label '[JUNCTIONS]' (that is, the starting row of the data information of the node elevation and node depth corresponding to the node), and shift it down three rows (that is, the three rows below the '[JUNCTIONS]' label are the beginning of the actual data), which marks the beginning of the outlet data, and save the position information in the variable Junctions. Also use the contains and find functions to locate the [OUTFALLS] label, which marks the end of the outlet data, and shift it up two rows (that is, the two rows above the '[OUTFALLS]' label are the end of the actual data) to accurately define the end of the data interval, and save the position information in the variable outfall_node_new.

[0343] 2) Calculate the total number of nodes involved: Use the difference between the start and end rows plus one to calculate the total number of nodes involved, stored in num_Junctions.

[0344] 3) Traverse the node data rows: Use a for loop to iterate from the first node data row to the last node data row.

[0345] 4) Regular expression string splitting: Use the regexp function with the \s+ regular expression to extract and split the data line of each node from the newline array and save it in the variable Junctions_nodeX.

[0346] 5) Extract node elevation and node depth: For each node, extract the second element (node ​​elevation) and the third element (node ​​depth) from the segmented result Junctions_nodeX, and store them in the Junctions_bottomElevation and Junctions_MaxDepth arrays respectively.

[0347] 6) Merge node elevation data: Use array concatenation operation to merge the Junctions_bottomElevation and outfall_bottomElevation arrays.

[0348] 7) Fill in missing node depth values: For the outlet node, there is no maximum depth data, so a constant of '10' is used instead. Use the repmat function to generate an array with an element of '10' and a length equal to the number of outlet nodes (num_node-length(Junctions_MaxDepth)), and merge it with the Junctions_MaxDepth array.

[0349] 8) Convert node elevation and node depth data to numeric types: Convert the strings in the Node_bottomElevation and Node_MaxDepth arrays to double-precision floating point numbers.

[0350] 9) Normalized node elevation: Calculate the normalized values ​​of the Node_bottomElevation and Node_MaxDepth_norm arrays using the formula:

[0351]

[0352]

[0353] This process scales all node elevation data to between 0 and 1.

[0354] Step 13: Construct the final X_combine_final matrix, that is, integrate the node X, Y coordinate data normalized in step 3 and the node elevation and node depth data Node_bottomElevation and Node_MaxDepth_norm arrays normalized in step 12 into the X_combine matrix filled in step 9 and save it as an NPY file for subsequent data extraction of the python graph neural network.

[0355] This step 13 specifically includes the following process steps:

[0356] 1) Combine data: Combine the X_combine matrix with the normalized node positions node_positionX_norm' and node_positionY_norm', and the normalized node elevation Node_bottomElevation_norm' and node depth Node_MaxDepth_norm' arrays. Use array transpose' for each matrix here to ensure that all data columns are correctly aligned.

[0357] 2) Data merging: Through array concatenation operations, different data sources are integrated into a larger data matrix X_combine_final for unified processing and analysis.

[0358] 3) Save data: Use the write.NPY function to save the X_combine_final matrix as a NumPy file. The columns in the X_combine_final matrix include the node X and Y position, catchment area, maximum imperviousness, total width, maximum slope, whether it is an outlet, node elevation, and node depth data related to each node.

[0359] During implementation, the second step of this method specifically includes the following steps:

[0360] Step a: Loading the initialization environment; including the following execution steps;

[0361] 1) Set up the environment;

[0362] Import the following libraries:

[0363] Numpy library: used for numerical calculations;

[0364] Torch library and torch_geometric.data library: used for graph neural network data structure processing;

[0365] Networkx library and matplotlib library: for graph visualization.

[0366] 2) Set the environment variable os.environ['KMP_DUPLICATE_LIB_OK'] = 'TRUE' to resolve potential parallel processing library conflicts.

[0367] Step b: Load the node, edge and weight data converted from MATLAB software; that is, load the pipeline connection relationship, pipeline length data and node characteristics required for the graph structure in the edges.npy, edges_weight.npy and X_combine_final.npy files created by MATLAB software from external files.

[0368] This step b specifically includes the following execution steps:

[0369] 1) Create a variable edges to determine the pipeline connection relationship = np.load(r'C:\...\edges.npy'): Load the pipeline network connection relationship between the catchment areas. This is a two-dimensional array, where each row contains two integers, indicating the start and end node number names of the pipeline connection.

[0370] 2) Create variables to read data and determine the length of the pipeline edges_weight = np.load(r'C:\...\edges_weight.npy'): load the length of the pipeline after normalization. This is a one-dimensional array with a length of num_edges.

[0371] 3) x_combine_final = np.load(r'C:\...\X_combine_final.npy'): Load the node feature matrix, including the relevant information of each catchment area. The columns in the X_combine_final matrix include the node's catchment area, maximum imperviousness, total width, maximum slope, whether it is an outlet, node X and Y position, node elevation, and node depth data. Through these loading steps, the code successfully obtains all the node features, pipe connection relationships, and pipe length data required to build the graph structure from the external file, ready for the next step of processing.

[0372] Step c: Construct the input data based on the graph neural network and convert the loaded node features and edge information into a format that can be used by the graph neural network (GNN).

[0373] This step c specifically includes the following execution steps:

[0374] 1) Execute device = torch.device("cuda" if torch.cuda.is_available() else "cpu"): Move data to the GPU (computer graphics processing unit) or CPU (computer central processing unit) depending on the availability of CUDA.

[0375] 2) Execute x_combine = torch.tensor(x_combine_final, dtype = torch.float).to(device): Create the x_combine variable to save the PyTorch tensor after converting the node feature matrix and move it to the device (GPU / CPU). torch.tensor is the command to convert data into a PyTorch tensor.

[0376] 3) Execute edge_index = torch.tensor(edges.T-1, dtype = torch.long).to(device): Create the edge_index variable to convert the edge index matrix into a PyTorch tensor and move it to the corresponding device. Note that edges.T is transposed here, and the dimension is (2, num_edges). (The edge index is reduced by 1 to adjust the node number from 1-based to 0-based, which conforms to the Python indexing standard)

[0377] 4) Execute edge_attr = torch.tensor(edges_weight, dtype = torch.float).to(device): Create the edge_attr variable to convert the pipeline length (pipeline length) into a PyTorch tensor. At this point, all the matrix data required for the graph neural network has been loaded.

[0378] 5) Use the Data(x=x_combine, edge_index=edge_index, edge_attr=edge_attr) function to package the node features, edge information, and pipeline length into a graph data object and store it in the variable data.

[0379] Step d: Extract the node positions of the graph and process isolated nodes in the graph to ensure the integrity of the graph structure.

[0380] This step d specifically includes the following execution steps:

[0381] 1) Create a variable node_positions = x_combine[:,[5,6]].cpu().numpy(): Extract the X and Y coordinate information of the node. The 6th and 7th columns of x_combine store the plane coordinates of each node, which are used to locate the position of the node on the graph.

[0382] 2) Handle isolated nodes. The specific process is as follows:

[0383] a) Use NetworkX to build a directed graph DiGraph and filter out isolated nodes without edges;

[0384] b) Use edge_index.cpu().numpy().T to convert edge information into NumPy format and store it in edges_numpy;

[0385] c) Get the set of nodes connected to the edge through edges_numpy.flatten() and store it in the connected_nodes variable;

[0386] 3) Execute G.add_edges_from((u,v)for u,v in edges_numpy if u in connected_nodes and v in connected_nodes): add pipeline connection relationships (i.e. edges) to the network graph G, including only connected nodes.

[0387] 4) Create variable area_column = x_combine[:len(G.nodes),0].cpu().numpy(): extract the area information of the node.

[0388] 5) Create variable outlet_column = x_combine[:len(G.nodes),4].cpu().numpy(): Extract the Boolean value of whether the node is an outlet. Based on this information, set the outlet node to blue, set the default color to orange, and set the point with an area of ​​0 to light red. The color of other nodes changes according to the area.

[0389] 6) Set color: Set color rules according to the area of ​​the node and the outlet attributes. The specific process is as follows;

[0390] If the node is an outlet (is_outlet == 1), set it to blue (0.33, 0.66, 0.89, 0.8); if the area is 0 (area == 0), set it to light red (0.83, 0.37, 0.33, 0.8); for other nodes, use the default orange (0.96, 0.73, 0.48, 0.8); and store the color of each node in the list node_colors;

[0391] 7) Determine the node position: Use the extracted node coordinates to generate the node position dictionary pos, where the key of the dictionary is the node index and the value is the x, y coordinates of the node.

[0392] Step e: Visualize the graph and make detailed adjustments to the visualized part of the image so that the information of nodes and edges is intuitively visible.

[0393] This step e specifically includes the following execution steps:

[0394] 1) Draw nodes:

[0395] Use nx.draw_networkx_nodes (the command for drawing nodes in the graph) function to draw the nodes.

[0396] Use the pos instruction to map each node to its position (usually a 2D coordinate).

[0397] The color of each node is specified using the node_color directive.

[0398] The size of the nodes (in points) is set with the node_size directive.

[0399] The alpha command sets the transparency of the color.

[0400] The edgecolors directive sets the color of the node borders.

[0401] 2) Draw edges and arrows:

[0402] Use nx.draw_networkx_edges function to draw edges.

[0403] The arrowstyle and arrowsize parameters control the style and size of the arrows.

[0404] The color and total width of the edge are set with the edge_color and width parameters.

[0405] The connectionstyle parameter controls the curvature style of the edges.

[0406] 3) Add a legend:

[0407] Use the mpatches.Patch command to create labels that match the node colors.

[0408] Use the plt.legend function to add a legend to the figure.

[0409] The position of the legend is set with the loc parameter.

[0410] The fontsize and prop parameters are used to control the font size and font of the text in the legend.

[0411] Step f: Save the generated graphics as a high-quality image file.

[0412] This step f specifically includes the following execution process steps:

[0413] 1) Define the path to save the image: Create the output_path variable to determine the save location.

[0414] 2) Save the image: Use the savefig command to save the image, and use the format command to specify the image saving format as JPG and the resolution DPI as 600.

[0415] The applicant further specifically took Wanzhou District, Chongqing as an example and established a SWMM model of the city under the SWMM software. The model image derived from the .inp file data is shown in Figure 1 From the picture, we can see the nodes of the area and their corresponding catchment areas, connected pipes and outlets, but we cannot quickly and intuitively judge the corresponding outlets of each node, the connection relationship of the pipes and the flow direction of the water flow. Then, the applicant used the above conversion method steps to convert the SWMM model through MATLAB data conversion and python graph neural network visualization to generate a picture. Figure 2 As can be seen from the figure, it displays the nodes and edges of the network diagram, as well as the characteristic information of each node, so that complex data can be converted into more concise and intuitive graphics, which helps users to more quickly identify the key nodes and pipes in the model, as well as the relationship and interaction between them. This processing can also make it easier for users to find nodes that lack drainage area, the connection relationship of pipes, and information such as drainage outlets, helping users to optimize their decisions. For example, in the risk assessment of urban flood disasters, the relative position of each node in the urban drainage system and the flow direction of water can be quickly understood, so that designers can more intuitively add pipes to areas prone to floods and adjust nodes that lack drainage area, so that urban planners can better plan and adjust corresponding urban functional areas or emergency measures in urban flood-prone areas, etc., so that subsequent researchers can analyze the network structure and the relationship between nodes.

[0416] Therefore, compared with the existing technology, the advantages of this method are as follows: Compared with other methods that directly use the SWMM model to study urban waterlogging and analyze sponge city LID construction plans, this method can efficiently and accurately complete the direct identification of SWMM model information data and convert it into data that can be directly recognized and used by the graph neural network, saving a lot of time in importing the original model data one by one into the graph neural network, converting the SWMM model data into data that can be directly recognized by the graph neural network, solving the problem that traditional urban hydrological and hydraulic model data are difficult to directly use modern intelligent algorithms for efficient analysis and prediction. By combining SWMM's simulation capabilities for urban precipitation with the advantages of graph neural networks in complex network data analysis, it provides more accurate technical support for urban water resources management, flood control, and infrastructure planning and research and analysis.

Claims

1. An interactive method for converting SWMM model data into data directly recognized by a graph neural network, firstly establishing a SWMM model of the urban area, dividing the catchment area in the model, and exporting an inp file; characterized in that, The following steps are also included: Step 1: First, read the .inp file of the SWMM model based on MATLAB software, extract and normalize the X-axis coordinate position and Y-axis coordinate position of each node, then extract the pipeline connection relationship and pipeline length information, save the pipeline connection relationship information as the first npy file after extraction, and save the pipeline length information as the second npy file, then extract and normalize the catchment area, maximum impermeability, total width, maximum slope, whether it is a discharge outlet, node elevation and node depth data associated with each node, and finally integrate the node X and Y position, catchment area, maximum impermeability, total width, maximum slope, whether it is a discharge outlet, node elevation and node depth data into a node feature matrix, and save the node feature matrix as the third npy file; Step 2: Use Python software to perform visualization based on three npy files.

2. The interactive method for converting SWMM model data into data directly recognized by a graph neural network as claimed in claim 1, characterized in that , the first step of this method specifically includes the following steps: Step 1: Use MATLAB software to open the SWMM model and extract the information data in the inp file; convert all data content into variable matrix newline for subsequent processing; Step 2: Extract the node X and Y axis coordinate information, that is, extract the node name and coordinate information from the variable matrix newline in step 1, and convert them into the node number name matrix node_name, the node position X coordinate node_positionX, and the node position Y coordinate node_positionY, so as to be used for the establishment of the graph structure; Step 3: Normalize the X and Y axis coordinate data of the node, that is, convert the node X and Y coordinate information extracted in step 2 into normalized values ​​and save them in the matrices node_positionX_norm and node_positionY_norm respectively to ensure that the data is within the range of 0 to 1; Step 4: Extract the pipeline information from the variable matrix newline in step 1, including the pipeline and its two end connection nodes and their lengths, and save them in the matrices link_name, graph_connection1 (starting end), graph_connection2 (ending end) and link_length; Step 5: Create a pipeline connection relationship matrix edges to store the start and end node index positions corresponding to each pipeline for connection relationship modeling in the graph neural network; Step 6: Normalize the pipeline length, save the pipeline connection relationship as the first npy file, and save the normalized pipeline length as the second npy file; Step 7: Extract the catchment area mjjz, maximum imperviousness_doub, total width subWidth_doub and maximum slope slope_doub of the catchment area associated with each node from the variable matrix newline in step 1 for subsequent processing; Step 8: normalize the catchment area mjjz, total width subWidth_doub, maximum imperviousness_doub and maximum slope slope_doub of the catchment area extracted in step 7; Step 9: Construct the X_combine data matrix containing the catchment area, total width, maximum imperviousness and maximum slope information; Step 10: Establish a catchment area name matrix and extract the corresponding outlets of the area; that is, extract the catchment area name and its corresponding outlet information LidToNode1 array from the variable matrix newline in step 1 and save it; Step 11: extract the outlet data, that is, extract the outlet data from the variable matrix newline in step 1 and identify whether the node is an outlet in the data matrix X_combine established in step 11; Step 12: Extract node elevation and node depth information from the variable matrix newline in step 1 and perform normalization to obtain Node_bottomElevation and Node_MaxDepth_norm arrays; Step 13: Construct the final X_combine_final matrix, integrate the normalized node X, Y coordinate data in step 3 and the normalized node elevation and node depth data Node_bottomElevation and Node_MaxDepth_norm arrays in step 12 into the X_combine matrix filled in step 9 and save it as an NPY file for subsequent data extraction of the python graph neural network.

3. The interactive method for converting SWMM model data into data directly recognized by a graph neural network as claimed in claim 1, characterized in that , the second step of this method specifically includes the following steps: Step a: Load the initialization environment; Step b: Load the node, edge and weight data converted from MATLAB software; that is, load the pipeline connection relationship, pipeline length data and node features required for the graph structure in the edges.npy, edges_weight.npy and X_combine_final.npy files created by MATLAB software from external files; Step c: Construct input data based on graph neural network and convert the loaded node features and edge information into a format that can be used by graph neural network GNN; Step d: Extract the node positions of the graph and process the isolated nodes in the graph to ensure the integrity of the graph structure; Step e: visualize the graph and adjust the details of the visualized part of the image so that the information of nodes and edges can be intuitively seen; Step f: Save the generated graphics as a high-quality image file.

4. The interactive method for converting SWMM model data into data directly recognized by a graph neural network as claimed in claim 3, characterized in that , step b specifically includes the following execution steps: 1) Create the variable edges to determine the pipeline connection relationship = np.load(r'C:\...\edges.npy'): load the pipeline network connection relationship between the catchment areas; this is a two-dimensional array, in which each row contains two integers, indicating the start and end node number names of the pipeline connection; 2) Create variables to read data and determine the length of the pipeline edges_weight = np.load(r'C:\...\edges_weight.npy'): load the length of the pipeline after normalization; this is a one-dimensional array with a length of num_edges; 3) x_combine_final = np.load(r'C:\...\X_combine_final.npy'): Loads the node feature matrix, including the relevant information of each catchment area; the columns in the X_combine_final matrix include the node's catchment area, maximum imperviousness, total width, maximum slope, whether it is an outlet, node X and Y positions, node elevation and node depth data.

5. The interactive method for converting SWMM model data into data directly recognized by a graph neural network as claimed in claim 3, characterized in that , step c specifically includes the following execution steps: 1) Execute device = torch.device("cuda" if torch.cuda.is_available() else "cpu"): Move data to the GPU (computer graphics processing unit) or CPU (computer central processing unit) depending on the availability of CUDA; 2) Execute x_combine = torch.tensor(x_combine_final, dtype=torch.float).to(device): Create the x_combine variable to save the PyTorch tensor converted from the node feature matrix and move it to the device GPU or CPU; 3) Execute edge_index = torch.tensor(edges.T - 1, dtype=torch.long).to(device): Create the edge_index variable to convert the edge index matrix into a PyTorch tensor and move it to the corresponding device; 4) Execute edge_attr = torch.tensor(edges_weight, dtype=torch.float).to(device): Create the edge_attr variable to convert the pipeline length (pipeline length) into a PyTorch tensor; 5) Use the Data(x=x_combine, edge_index=edge_index, edge_attr=edge_attr) function to package the node features, edge information, and pipeline length into a graph data object and store it in the variable data.

6. The interactive method for converting SWMM model data into data directly recognized by a graph neural network as claimed in claim 3, characterized in that , step d specifically includes the following execution steps: 1) Create variable node_positions = x_combine[:, [5, 6]].cpu().numpy(): Extract the X and Y coordinate information of the node; 2) Handle isolated nodes. The specific process is as follows: a) Use NetworkX to construct a directed graph DiGraph and filter out isolated nodes without edges; b) Use edge_index.cpu().numpy().T to convert edge information into NumPy format and store it in edges_numpy; c) Get the set of nodes connected to the edge through edges_numpy.flatten() and store it in the connected_nodes variable; 3) Execute G.add_edges_from((u, v) for u, v in edges_numpy if u in connected_nodes and v in connected_nodes): add pipeline connections to the network graph G, including only connected nodes; 4) Create variable area_column = x_combine[:len(G.nodes), 0].cpu().numpy(): extract the area information of the node; 5) Create variable outlet_column = x_combine[:len(G.nodes), 4].cpu().numpy(): Extract the Boolean value of whether the node is an outlet; based on this information, set the outlet node to blue, set the default color to orange, and set the point with an area of ​​0 to light red. The colors of other nodes change according to the area; 6) Set color: Set color rules according to the area of ​​the node and the outlet properties. The specific process is as follows; If the node is a drain outlet, set it to blue; if the area is 0, set it to light red; for other nodes, use the default orange; and store the color of each node in the list node_colors; 7) Determine the node position: Use the extracted node coordinates to generate the node position dictionary pos, where the key of the dictionary is the node index and the value is the x, y coordinates of the node.

7. The interactive method for converting SWMM model data into data directly recognized by a graph neural network as claimed in claim 3, characterized in that , step e specifically includes the following execution steps: 1) Draw nodes: Draw nodes using the nx.draw_networkx_nodes function; Use the pos instruction to map each node to its position; The color of each node is specified using the node_color directive; The node size is set using the node_size directive; The transparency of the color is set using the alpha command; Use the edgecolors directive to set the color of the node border; 2) Draw edges and arrows: Use nx.draw_networkx_edges function to draw edges; The arrowstyle and arrowsize parameters are used to control the style and size of the arrows; The edge color and total width are set using the edge_color and width parameters; The connectionstyle parameter is used to control the bending style of the edge; 3) Add a legend: Use the mpatches.Patch command to create labels that match the node colors; Use the plt.legend function to add a legend to the graph; The position of the legend is set with the loc parameter; The fontsize and prop parameters are used to control the font size and font of the text in the legend.

Citation Information

Patent Citations

  • Defense method for radio signal identification countermeasure attacks

    CN111428817A

  • Urban rainwater drainage system automatic optimization method based on SWMM and MATLAB

    CN113190944A

  • Urban rainstorm waterlogging rapid simulation method based on deep convolutional neural network

    CN116702627A

  • Water quality simulation method for plant-network-river integrated water supply

    CN118504467A

  • Method and device for optimizing old urban drainage system based on SWMM model

    CN119026284A