Hydrologic & Hydraulic Engineering and AI

Paige Brue, P.E., CFM, QSDCivil Engineering, HEC-RAS, Hydrology

Artificial Intelligence (AI) has been all over the news lately. It is obvious that AI is not going anywhere and will continue to impact how people work. Unfortunately, some have chosen to use AI for “spammy” purposes, such as generating unauthentic content and sending scammy emails. However, the applications of AI are practically endless, and there are many opportunities to use AI to improve our work and lives in general. The people who will benefit most from AI in the future will be the subject matter experts who know how to use this technology to increase their productivity effectively. Some may believe that AI will replace professions such as civil engineering. However, I am of the belief that AI will augment humans’ creativity and high-level reasoning/problem-solving.

Learning how AI can be useful for water resources engineers

Recently, I took an online course created by Aaron Nichols, ChatGPT for Water Resources Engineers. I found it to be extremely helpful and cannot recommend it enough. The course costs $149, less than many engineers charge for one hour of their time. The information provided in this course will help automate tasks and save countless hours in the future. I highly recommend this course. It is the “deep dive” into the information provided in this article. The link is provided below for those who want to check it out. Aaron also has some freely available content online that is also helpful for those who want to use AI to upgrade their professional skillset.

https://aaronnichols.gumroad.com/l/chatgptforwre

The following article will provide a high-level overview of the capabilities of a large language model (LLM) such as ChatGPT and specifically discuss how water resources engineers can incorporate AI/LLM tools such as ChatGPT into their HEC-RAS modeling workflows.

What is a Large Language Model (LLM)?

A well-known AI technology is ChatGPT. ChatGPT is a large language model (LLM). An LLM is a sophisticated mathematical model that predicts what word comes next for any piece of text. Instead of predicting one word with certainty, an LLM assigns a probability to the next word. Although the mathematical functions used to build an LLM are deterministic, a chatbot like ChatGPT will often yield results that are not deterministic. This means that an LLM like ChatGPT will not always generate the same answer to a prompt. LLMs learn how to make predictions by processing an enormous amount of information. This process is called training. It is estimated that it would take a human about 2,600 years (non-stop) to read the information used to train GPT-3, and the training datasets are only growing in size. Obviously, this is an enormous amount of information, and learning how to access information from such large datasets effectively is immensely useful. Users engage with an LLM by first providing a prompt, the initial text used to ask the LLM a question or request information. Then the LLM analyzes the prompt using the training data to predict the next word. A process called auto-regression adds the predicted word to the response and repeats the process to predict the subsequent word. The amount of text generated as part of an LLM’s response is referred to as a context window. Although many people are familiar with ChatGPT’s capabilities as a glorified search engine, an LLM can be used for much more than that. ChatGPT can be used to generate images and even code. The future of this technology is exciting, and we are still in the early days.

Automating Excel Tasks

ChatGPT can also generate complex Excel formulas, assist with debugging complex formulas, generate alternatives, and even summarize large datasets provided in an Excel format. One practical application for water resources engineers may be calculating curve numbers using drainage areas, land use, and hydrologic soil group (HSG) shapefiles as input data. ChatGPT can even be prompted to generate a spreadsheet with its calculations. It is worth noting that complex tasks such as this may require a feature called Advanced Data Analysis, which is only available through the paid version of ChatGPT.

Code Interpreter

ChatGPT can also write and execute Python code using the Code Interpreter feature. Although the program can generate code for several programming languages, it will only run Python in the Code Interpreter. This works out well for water resources engineering because many GIS tasks are based on Python. The Code Interpreter feature also allows users to extract data from hydraulic modeling software such as HEC-RAS, FLO-2D, or SWMM and analyze that data. For example, the Code Interpreter may use the Pandas library to generate attractive plots of a hydrograph or other output data.

Using ChatGPT Vision to Troubleshoot a HEC-RAS Model

The ChatGPT Vision capabilities allow users to troubleshoot their models by uploading screenshots of the error to ChatGPT. The ChatGPT Vision feature allows the AI chatbot to read, analyze, and respond based on uploaded images. This means HEC-RAS users do not need to manually type out an error into the search bar of ChatGPT. Instead, they can simply upload a screenshot of the error. Simply use the SnipIt tool, copy the screenshot into the search bar, and write a text prompt telling the chatbot that you would like help with addressing an error.

Using ChatGPT to Analyze Geospatial Information

ChatGPT can be used to analyze and automate GIS workflows using its Code Interpreter (see discussion above). This means ChatGPT can be a useful way to make preprocessing geospatial data and postprocessing HEC-RAS results more efficient. For example, ChatGPT can be used to generate stream centerlines from terrain data or generate upstream and downstream elevations from a DEM. The Python code generated by ChatGPT uses libraries such as GeoPandas, Rasterio, and ArcPy to develop code to automate tasks such as projecting files, clipping data, or extracting data. ChatGPT cannot handle very large raster files. For this reason, it is a good idea to generate code using a small dataset. This code can then be applied to a script for the larger dataset using a Python compiler installed on your local drive. Another limitation worth noting is access to Python libraries. The ChatGPT Code Interpreter includes many commonly used Python libraries but not every library. ChatGPT may write code assuming the presence of a particular library that is not available in the Code Interpreter. However, the code will not be able to be executed by the ChatGPT Code Interpreter. In this case, run the Python script/code locally to ensure it will work properly.

LLM Limitations

While AI can be an incredible tool, it is essential to understand the limitations of Large Language Model (LLM) tools such as ChatGPT. This section will list some of these limitations.

  1. Incorrect Information. Unsurprisingly, ChatGPT can generate incorrect information. Sometimes, this incorrect information can even be presented in a way that convinces you that it is factual information. In the AI world, this phenomenon is called a hallucination. These hallucinations can happen because AI is based on training data. This training data usually comes from the internet, which we know has faulty information. Because training data is generated by humans, we can expect there will always be some degree of bias and incorrect information associated with AI. However, the frequency at which hallucinations are generated is going down as these tools are improved over time.
  2. Knowledge cutoff date. LLM tools such as ChatGPT are trained based on data generated up to a certain point. Thus, ChatGPT may not have the latest and greatest information on a particular topic. This is important to remember when using ChatGPT for rapidly changing tools such as RAS 2025.
  3. Context Window. The context window is the amount of text the model is “allowed” to reference before generating a response. You can think of this as the amount of information ChatGPT can “remember” before generating a response.

In summary, tools such as ChatGPT should be treated as an “assistant” whose work needs to be checked and verified regularly.

Closing

If you are interested in learning even more about how you can incorporate AI into your HEC-RAS modeling workflow, consider joining my one-day HEC-RAS 2D master class entitled “HEC-RAS 2D Zero to Hero Training.” The class will feature a guest speaker who is an expert in AI and HEC-RAS. Don’t miss out on this valuable information! You can check out the course using the link below.