© Mohammad Khorasani, Mohamed Abdou, Javier Hernández Fernández 2022
M. Khorasani et al.Web Application Development with Streamlithttps://doi.org/10.1007/978-1-4842-8111-6_12

12. Streamlit at Work

Mohammad Khorasani1  , Mohamed Abdou2 and Javier Hernández Fernández1
(1)
Doha, Qatar
(2)
Cambridge, United Kingdom
 

This final chapter introduces two real-world cases that have taken advantage of Streamlit to develop web applications in some capacity. The first case covers the technical development of a data manager application for wind farms for Iberdrola – a renewable energy firm. We can observe how this application is being used to estimate electrical losses during production and to obtain valuable insights from Iberdrola’s SCADA data. The second case divulges the utility of Streamlit for industrial applications with maxon Group – a manufacturer of high-precision electronic motors. Specifically, we can see that Streamlit can be used to create a command and control dashboard application to control the maxon motors of a surgical scope adapter system both locally and remotely.

12.1 Streamlit in Clean Energy: Iberdrola

Iberdrola is a multinational electric utility with operations in more than 30 countries in the world. Since its inception, Iberdrola has been dedicated to developing a clean and reliable business model based on investments in renewable energy and is now one of the world’s largest renewable energy operators in terms of installed capacity. Iberdrola’s renewable energy activities are one of its three strategic business units, alongside networks and wholesale/retail solutions.

The renewable business of Iberdrola generates electrical energy from clean resources such as wind (onshore and offshore), hydro, photovoltaic, biomass, and others. In the coming five years, Iberdrola will invest €75 billion in renewable energy and other projects. By the end of the period, renewables will account for 51% of this organic investment (over €34 billion), with a capacity of 60 GW. Similarly, the company forecasts indicate an increase in installed renewable capacity to 95 GW by 2030. The group’s commitment will allow it to assist offshore wind technology (reach 4 GW installed by 2025), develop solar photovoltaic (reach 16 GW installed by 2025), and increase its renewable generation capacity to more than 100 GW. This renewable growth is backed by the Paris Agreement which aims to cut greenhouse gas emissions and limit global warming below two degrees Celsius. The agreement was ratified in 2016, at COP21 held in France with 147 countries joining it. It came into force in November 2018 after enough countries joined it for meeting their respective targets of emission cuts. The firm’s renewable unit, in addition to generating clean electricity, finances research and development to help advance new technologies that will ensure that green energies continue to play an increasingly crucial role in Iberdrola’s portfolio over the next few years.
Figure 12-1

Wikinger offshore wind farm. Source: Iberdrola.​com [14]

12.1.1 Visualizing Operational Performance of Wind Farms

Daniel Paredes and Jerome Dumont, both members of the Energy Resource department, have spent years developing algorithms and tailor-made software to analyze Iberdrola’s wind farms. In particular, the use case being discussed here focuses on a program that analyzes wind farm operational data to obtain energy yield assessment and identify variations. Operational performance studies and energy yield assessments are integral and essential components within the life cycle management of a wind farm. At Iberdrola, the utmost attention is paid to the running and optimization of wind farms, which are constantly inspected for deviations.

To this end, a novel and in-house software solution was rendered to address the needs of operational performance analysis – the Operational Wind Farm data manager hereinafter referred to as OWFdm. The presence of such software adds value by automating and streamlining computations that would be otherwise done manually, accommodating the requirements of operational technicians and engineers alike. Initially developed with Python and the QT GUI framework, OWFdm was able to address the needs of operational analysis; however, a complete deployment to the cloud would provide greater potential and pave the way to accommodate additional utilities for the end users. The justification for migrating the OWFdm to the cloud as a web application included technical reasons (scalability, accessibility, access to network resources and databases) as well as the need for a more powerful visualization library that would largely replace the role of Matplotlib and QT. As all the algorithms were already implemented in Python, a web framework was required to interface with the web browser. For this purpose, Streamlit was introduced to take on the role of creating the frontend interface. As a pure Python package, Streamlit required a very shallow learning curve and reduced the burden of the developers of having to code in HTML or CSS. In addition, Streamlit provided an integrated development environment (IDE) that allowed for rapid development.

In collaboration with Iberdrola Innovation Middle East, a research center devoted to developing innovative solutions in smart grids and distributed renewable energy integration, a redesign and enhancement of the functionality of the OWFdm tool was developed. In the following sections, we will look at some of the Streamlit-based graphical representations utilized by the Iberdrola wind engineers.

12.1.2 Wind Turbine Power Curves

Wind turbines are mechanical devices that convert kinetic energy (energy due to movement) in wind into electrical power. They do this by using three main components: a rotor, a generator, and a tower. The blades of a turbine are connected to the rotor. When the blades move, they cause the shaft of the generator to spin. The type of wire used in wind turbines is known as a multistrand wire and is composed of many individual strands of copper wire twisted together and covered with an outer protective covering.

The power output for a wind turbine depends on the density of the air, which is affected by both altitude and climate. The power output for wind turbines ranges from a few kW to the 14MW of the GE Haliade-X offshore, which is the most powerful turbine available in the market at the time of the writing of this book [17, 18]. A large industrial-type onshore wind turbine such as those populating our countryside usually ranges between 2 and 4MW, with a rotor diameter ranging around 130 meters. The power output for small wind turbines is typically measured in watts (W), while large industrial types are often measured in megawatts (MW). A wind turbine with a 100W power output will meet the needs of an average household, while one that has 3000W can power anything from a small business to an entire neighborhood. A turbine’s energy production is proportional to the third power of its blade length, so doubling the blade length would produce eight times as much power. Doubling the blade span (the length of the arc that the blades sweep through when making a full rotation) would produce 16 times as much power.

The power curve of a wind turbine is a graph that shows how much electrical energy the turbine will generate at different wind speeds. Power curves for wind turbines are usually created by testing an actual turbine at specific sites under similar wind conditions and measuring its electrical output at each point either with a wattmeter or a power analyzer. Wind turbines are tested at different wind speeds, and the turbine’s power output is measured and recorded as a function of wind speed to generate a wind speed vs. power curve for that particular site. A power curve is typically represented as a graph with wind speed on the x axis and turbine power output on the y axis. The wind speed axis can be given in either actual or average (rated) values. A rated value is the speed at which the turbine’s power output matches its maximum capability during normal weather conditions at that site. The typical power curve for a modern industrial three-blade horizontal axis wind turbine is shown in Figure 12-2.

Since the initial wind speed is zero, the turbine’s power output begins at zero and gradually increases as wind speeds increase. Wind turbines have to be able to produce electricity even when the wind is blowing below their rated speed – this is called a cut-in speed. The cut-in speed of a turbine will depend on its overall size and design, but there is a minimum speed below which the turbine will not produce any power. As wind speed continues to increase, so does power output until it reaches its rated value. At this point, the power curve flattens and remains constant until wind speeds go beyond the rated value. In the cut-out speed point, where there is a sudden drop in rotational speed and power output, most turbines will enter an automatic braking mode. Wind turbines are designed with an optimum efficiency point (limit point) where all the power in the wind goes into turning the rotor; beyond this limit, no more torque can be converted, and the power output drops dramatically.
Figure 12-2

Typical wind turbine power output

It is a normal procedure to compare the power curve provided by the turbine manufacturer to the one produced with the observed power during production. This information is useful to wind engineers to perform energy assessment reports, maintenance, or performance evaluations. Figure 12-3 shows three representations in the same graph:
  • The power curve as provided by the manufacturer, operational power curve in the legend

  • The real or measured power curve, operational power curve (meas) in the legend

  • The three-sigma variance of the real power curve, operational power curve 3Sigmas in the legend

  • All the data points obtained during the period, P-v recorded in the legend

Graphs displayed with Plotly and wrapped with Streamlit can provide an interactive lasso tool that can be used to manually filter outliers. Thanks to the Streamlit framework, a two-way communication between this chart and other components is executed seamlessly.

12.1.3 Wind Roses

A wind rose is a graphical depiction of the frequency with which the wind speed and direction are dispersed at a certain location. Meteorologists use wind roses to give a concise view of how wind speed and direction are typically distributed at a particular location. Modern wind roses normally contain the wind speed, wind direction, time period for which wind data is valid, and other related information. To construct a wind rose, wind observations from anemometers or wind vanes attached to a building or similar structure are plotted on a polar coordinate wind rose. The wind rose contains both the average wind speed and direction during a certain period for a given location. Wind roses typically use 16 cardinal directions, such as NNW (north-northwest), SSW (south-southwest), and so forth, or divide the 360 degrees into sectors.

Figure 12-4 shows a division in eight wind sectors of the wind speed direction of two wind turbines. The graph is displayed using Streamlit’s st.plotly_chart element with the go.Scatterpolar class from plotly.graph_objects.
Figure 12-3

Graph with the different wind turbine power curves

Figure 12-4

Comparison of two wind turbine wind roses

12.1.4 Heat Maps

A heat map is a picture that depicts data using colors to represent values. A heat map can depict graphs other than numbers, for example, graphs of graphs. This is more typically known as a matrix plot. The heat map in Figure 12-5 graphs the average active power in watts produced by a wind turbine per hour during each month. Yellow cells signify a higher value (a maximum of 1000 watts), while purple indicates no production. This type of graph offers wind engineers a holistic view of the production patterns per turbine. For instance, and for this specific case, we can infer that November is the windiest month and that the hours around 5 am usually show lower production rates. The graph has been rendered using Plotly and is displayed using Streamlit.
Figure 12-5

Wind turbine hourly average production per month heat map

12.1.5 Closing Remarks

Beyond the visualization capabilities, Streamlit has proven to be a highly versatile tool for Iberdrola renewables, enabling us to render multiple datasets on demand by prompting the user to select what data they want to display, as opposed to having to manually program that into the source code. A two-way communication with charts in pure Python is also of great value, for instance, implementing the functionality provided by the lasso tool for manual filtering used in Figure 12-3 would have required some integration efforts with JavaScript or other workarounds. A final advantage is a possibility of rendering charts as HTML on a website, making them interactable with other widgets, as opposed to running it stand-alone locally without any other third-party interactions.

This publication is supported by Iberdrola S.A. as part of its innovation department research studies. Its contents are solely the responsibility of the authors and do not necessarily represent the official views of Iberdrola Group.

12.2 Streamlit in Industry: maxon Group

maxon Group is a Swiss manufacturer and distributor of industrial-scale electronic motors used for high-precision and cutting-edge applications. Specifically, maxon’s products are utilized extensively for a wide variety of industrial purposes, including but not limited to the healthcare, aerospace, automotive, and packaging industries, to name a few. The versatility of their products, combined with phenomenal build quality and impeccable customer service, enables developers to meet and exceed highly demanding performance requirements, both above and below the atmosphere. Their product catalog hosts a multitude of brushed, brushless, AC, and DC motors, with an assortment of gearboxes, encoders, Hall effect sensors, and most importantly a set of motor controllers that can be commanded via RS232, USB, CANopen, and EtherCAT communication protocols. In addition, maxon offers a high degree of customizability whereby the dimensions, mechanical interfaces, cables, bearings, and other features of the drive disposition can be configured exactly as they are required.
Figure 12-6

Disposition of a maxon GPX Speed 13 reduction gearbox, ECX Speed 13M brushless motor, and ENX13 encoder

Figure 12-7

maxon EPOS4 Compact 24/1.5 CAN motor controller

12.2.1 Developing a Novel Surgical Scope Adapter System for Minimally Invasive Laparoscopy

Minimally invasive surgery, otherwise known as laparoscopy, is becoming increasingly prevalent as the operation of choice for surgeries on the abdomen. Given the small size of the incisions that are made to the body, laparoscopy affords patients a shorter recovery period and a mitigated possibility of developing complications during and after the surgery. Currently, such operations are conducted manually with a surgical assistant holding and articulating the endoscope that is inserted into the abdomen to view the region being operated on in real time (shown in Figure 12-8). Considering that a human operator is involved in this arrangement, a high level of dexterity and hand-eye coordination is required; any inaccuracy, however slight, may introduce unwarranted error into the operation.

Consequently, a novel scope adapter concept (shown in Figure 12-9) was developed and prototyped by Dr. Nikhil Navkar and Mohammad Khorasani to mitigate the effects of including a human operator in the feedback loop. In this implementation, the endoscope and associated camera head are held and controlled via a UR5 robotic arm offering six degrees of freedom, with an additional two degrees of freedom built into the adapter itself enabling the rotation of the scope and camera head around its axis and the angulation of the scope tip. The rotation is powered by a maxon ECX brushless motor, while the angulation is powered by a maxon brushed DCX motor. Each motor is coupled with a reduction gearbox that offers a top speed of 20 and 16 RPM for the rotation and angulation motors, respectively, and a three-channel optical encoder that provides a resolution of 4096 and 2048 steps per revolution, respectively.

Other advantages associated with the surgical scope adapter include the following:
  • Ability to support different endoscopes, camera heads, and robotic arms

  • Can be controlled with a variety of inputs including a joystick or by tracking optical markers attached to the surgeon’s head

  • Can be programmed to reduce human error and unintended movements

  • Reduces operator strain and fatigue by eliminating the need to manually hold the scope

Figure 12-8

Schematic of an endoscope inserted into the abdomen

Figure 12-9

Engineering drawing of the maxon powered surgical scope adapter

12.2.2 Streamlit Command and Control Dashboard

Upon completion of the mechanical prototype of the surgical scope adapter, a Streamlit application was developed to render a dashboard with the speed and position of the rotation and angulation motors in real time as shown in Figure 12-10. In addition, the Streamlit application was interfaced with a three-axis joystick that was used to control each of the maxon motors as shown in Figure 12-11. Furthermore, by port forwarding the Streamlit application, it was possible to control the motors remotely over the Internet. This is of particular interest for telesurgery, whereby an operator can partake in a surgery without physically being present within the premises of the hospital. Albeit with certain limitations, since with remote control over long distances there is increased latency, which may inhibit the performance of the device.
Figure 12-10

Streamlit command and control dashboard for the surgical scope adapter

Figure 12-11

Prototype of the surgical scope adapter with the Streamlit command and control dashboard

12.2.3 Closing Remarks

While Streamlit is branded as a framework for machine learning and data science applications, it does possess enough versatility to be used for a variety of purposes. As shown in this instance, Streamlit was effectively utilized to bridge several nontrivial subsystems together into one contiguous system. Specifically, Streamlit was used to interface the maxon motors with a joystick, enable remote control over the local area network as well as the Internet, and also to provide a real-time dashboard displaying the motors’ position and speed all in a few lines of code.

This work was supported by National Priority Research Program (NPRP) award (NPRP13S-0116-200084) from the Qatar National Research Fund (a member of The Qatar Foundation) and IRGC-04-JI-17-138 award from Medical Research Center (MRC) at Hamad Medical Corporation (HMC). All opinions, findings, conclusions, or recommendations expressed in this work are those of the authors and do not necessarily reflect the views of our sponsors.

12.3 Summary

In this final chapter, we have been acquainted with two real-world instances of Streamlit being utilized effectively for commercial and industrial activities. Namely, the first case demonstrates how Iberdrola – a renewable energy firm – is using Streamlit to create a corporate data management application for their wind farms, to estimate electrical losses during production. The second case expands on an industrial use case whereby high-precision electronic motors manufactured by maxon Group are being commanded and controlled via a Streamlit application, for use within a surgical scope adapter system. Both examples serve to provide evidence of the utility that Streamlit is offering to the corporate world and beyond.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.117.182.179