Using open-source tech and ChatGPT to create virtual analysers of chemical dosage

Article by Eigen

A new online dashboard of chemical concentrations for an offshore oil production facility used open-source technology stack and ChatGPT to achieve the holy grail in digital: better, faster, and cheaper – built for less than a tenth of the cost of installing new instrumentation offshore

IN THE same way that chlorine keeps a swimming pool safe, and detergent cleans dishes, advanced chemicals are used in oil production to improve oil-water separation, delay rust, absorb harmful gases, make fluids easier to pump, clean discharged water, and prevent bacterial growth.

All these chemicals work at a certain concentration, measured in Parts Per Million (ppm). If the concentration is too low, then the chemical won’t perform. If too high, OPEX is wasted, and undesirable side-effects can occur.

Like sailing using the stars to navigate

Offshore instrumentation is expensive and the more complex it is, the more unreliable it can be in harsh operating conditions. Consequently, there is typically no available measurement of chemical concentrations or usage.

Many facilities do not have [working] flowrate sensors on chemical injection points either. Instead, operators rely on periodic lab samples and monthly reconciliation of chemical usage versus product volumes.

Much like the sailors of old who used the stars to navigate, there are only periodic status checks, and the chemical dosage can be off target for days before engineers realise.

The aim is to keep the concentration (light blue line) within the green band. The operators are shown the calculated flowrate vs the recommended rate so that they know how to adapt to keep with the target

Calculating a virtual flow rate for tank levels

On this particular facility, tank level measurements were available online, creating an opportunity to use the change in tank level (and known tank volumes) to calculate a virtual chemical flowrate for each chemical.

These virtual chemical flowrates, combined with process flow measurements, were used to calculate concentrations in real-time. A standard deviation function was employed to the level measurement of the tank to detect different states: flowing, filling, or not-in-use.

Owing to vibrations from pumps and fouling in pipework, signals from the level measurements were unstable over short time periods (up to eight hours). To resolve the instability, an algorithm was developed using a combination of standard deviation, logic functions, and concepts similar to Proportional, Integral and Derivative (PID) control. This delivered robust estimates of the flowrate from the tank.

The tech stack

Data for the tank levels was read directly from the AspenTech IP.21 data historian managed by the control system vendor. Node-RED, a low code, online, scripting platform, ran the algorithm every five minutes and wrote the results back to an InfluxDB timeseries historian where they could be accessed by anyone.

Applying a standard deviation transform to the tank level gives a signal that can be used to differentiate between the tank states

Low-code scripting – a great alternative to Excel VBA

The algorithm was developed using Node-RED which allows a user to drag, drop, and edit functions together. Node-RED takes care of all the behind-the-scenes code for security, authentication, and scheduling; the user only has to focus on the business logic. Updates can easily be made and run (and re-run) in Node-RED to backfill historic data – and be deployed instantly. No developers were involved in the project; everything was built by the engineers themselves.

Using ChatGPT

Many engineers understand VBA, Python, and JavaScript but are better at modifying existing code rather than starting from scratch. Time was saved – and the client’s budget – by using ChatGPT with a prompt like:

“I have a chemical tank with level measurement X in %. Write me a NodeRed function in JavaScript to output the tank flowing status based on the Standard Deviation of X. The tank is:

not flowing when StdDev(X) < 0.07,
flowing when StdDev(X) > 0.07
transferring when StdDev(X) > 0.5
filling when StdDev(X) > 1”

This could then be dropped easily into Node-RED.

Better, faster, and cheaper digitalisation

The final dashboard was built in Eigen Ingenuity, which is a digital platform for combining information and includes securely packaged versions of Node-RED and InfluxDB. Users can drag and drop elements on to a canvas and configure the display.

Eigen Ingenuity Chemical Dosing example dashboard

Empowering engineers to make better decisions, faster, cheaper

This example demonstrates the power of digital transformation – without the huge investment, multi-year timelines, and disruption to business-as-usual.

Harnessing the power of open-source software, like Node-RED, Neo4j, and ChatGPT, along with a dynamic visualisation platform like Eigen Ingenuity, negates the need for costly and time-consuming installation of offshore instrumentation.

Within weeks, the client was able to use its new chemicals dashboard to build a comprehensive picture of chemical stock levels and dosing, with data that was already available – but under-utilised.

What’s more, equipped with these intuitive tools, engineers can now complete much of the development work themselves, inside their own private cloud. With a clear migration path if the operator wants to productise the tool in the future, there is little to no dependency on Eigen or other consultants to maintain and adapt.

And this is just the start. By seeing first-hand what is possible by integrating smart software tools with existing data, the client can see all manner of potential applications, eg well production testing, blowdown verification analysis, valve travel-time verification, and loss reporting.

And what’s more, they now have the tools and the capabilities to build these applications themselves.


InfluxDB is a registered trademark of InfluxData, which is not affiliated with, and does not endorse, this project.

Article by Eigen

Recent Editions

Catch up on the latest news, views and jobs from The Chemical Engineer. Below are the four latest issues. View a wider selection of the archive from within the Magazine section of this site.