Pyra: Automated EM27/SUN Greenhouse Gas Measurement Software

The human activity of burning fossil fuels is the driving factor of global warming (Arias et al., 2021). To promote global climate change mitigation policies, a profound greenhouse gases (GHG) observational data basis is required to understand and quantify the sources and sinks of GHG emissions (Arias et al., 2021). Ground-based remote sensing instruments that analyze direct sunlight using, for example, EM27/SUN fourier-transform infrared spectrometers (FTIR) (Gisi et al., 2011) fill the gap between ground-based in situ measurements and space-based measurements by satellites (Hase et al., 2015; Rißmann et al., 2022). Due to its dependency on direct sunlight and clear skies, the EM27/SUN generally requires a trained operator on site. Depending on the weather conditions, the operator needs to manually control the instrument and measurement times. This is time and cost-intensive, in particular, if more than one instrument is involved. However, state-of-the-art EM27/SUN networks consist of up to 6 instruments to estimate the emissions of cities (Che et al., 2022; Dietrich et al., 2021; Hase et al., 2015; Ionov et al., 2021; Jones et al., 2021; Tu et al., 2022; Vogel et al., 2019) or local and regional GHG sources (Chen et al., 2016, 2020; Klappenbach F. et al., 2022; Luther et al., 2022; Toja-Silva et al., 2017; Tu et al., 2020, 2022). These setups generally require at least one operator to operate and closely monitor each instrument. Pyra is an automation software that does not require a trained operator and enables the user to perform EM27/SUN measurements with a workload limited to system monitoring. This also guarantees continuous measurements during weekends, holidays, and at remote locations resulting in an optimized data yield while saving time and human resources. Pyra’s open-source code and documentation will reduce operator training efforts.


Statement of need
The human activity of burning fossil fuels is the driving factor of global warming (Arias et al., 2021). To promote global climate change mitigation policies, a profound greenhouse gases (GHG) observational data basis is required to understand and quantify the sources and sinks of GHG emissions (Arias et al., 2021). Ground-based remote sensing instruments that analyze direct sunlight using, for example, EM27/SUN fourier-transform infrared spectrometers (FTIR) (Gisi et al., 2011) fill the gap between ground-based in situ measurements and space-based measurements by satellites Rißmann et al., 2022). Due to its dependency on direct sunlight and clear skies, the EM27/SUN generally requires a trained operator on site. Depending on the weather conditions, the operator needs to manually control the instrument and measurement times. This is time and cost-intensive, in particular, if more than one instrument is involved. However, state-of-the-art EM27/SUN networks consist of up to 6 instruments to estimate the emissions of cities (Che et al., 2022;Dietrich et al., 2021;Ionov et al., 2021;Jones et al., 2021;Tu et al., 2022;Vogel et al., 2019) or local and regional GHG sources Klappenbach F. et al., 2022;Luther et al., 2022;Toja-Silva et al., 2017;Tu et al., 2020Tu et al., , 2022. These setups generally require at least one operator to operate and closely monitor each instrument. Pyra is an automation software that does not require a trained operator and enables the user to perform EM27/SUN measurements with a workload limited to system monitoring. This also guarantees continuous measurements during weekends, holidays, and at remote locations resulting in an optimized data yield while saving time and human resources. Pyra's open-source code and documentation will reduce operator training efforts.
Previous versions of Pyra were successfully operated during measurement campaigns Humpage et al., 2021) and continuous GHG observations Tu et al., 2020). Due to the closed-source nature of these versions, users are dependent on software and hardware support from Technical University of Munich (TUM). To make Pyra a useful tool for the growing community we disentangled it from the dependency on TUM hardware Heinle & Chen, 2018) and reworked the codebase architecture to allow for easier integration of new features.

Summary
Pyra consists of three different parts ( Figure 1): Pyra Core (continuous background process), Pyra Command Line Interface (Pyra CLI), and Pyra User Interface (Pyra UI) (both are used for on-demand user interaction with Pyra Core). Measurements with an EM27/SUN require to run CamTracker (Gisi et al., 2011), a software that tracks the sun position and operates the mirrors accordingly, and OPUS 1 , a software that sends commands to the EM27/SUN and collects the output data into interferogram files. As CamTracker and the official OPUS version only run on a Windows Operating System, Pyra is also required to be run on Windows for full functionality.

Pyra Core
Pyra Core is implemented as a continuous main loop that manages measurements based on prevalent weather conditions. Before every loop, it reads the latest version of the configuration file config.json and adapts accordingly. Pyra Core is designed to run 24/7 and handle runtime exceptions without human interaction. Pyra Core allows for three different operation modes: Manual, Automatic, and CLI. In Manual mode, the user has full control over whether measurements should be active. The usercontrolled state can be updated within the Pyra UI. In Automatic mode, three different triggers are considered: Sun Elevation, Time, and Helios. Helios evaluates direct sunlight by analyzing the sharpness of shadow edges created by an external setup precisely designed for this application . The user can select which of these triggers are to be considered. Measurements are only set to be running if all selected triggers are fulfilled. In CLI mode, triggers from external sources can be considered. This option is aimed at teams that use their own custom-built weather protection enclosures.
In the continuous loop, Pyra Core will run a sequence of modules that operate the individual components required to perform EM27/SUN measurements autonomously: EnclosureControl, OPUSMeasurements, SunTracking, and SystemChecks.
EnclosureControl operates the custom TUM weather protection enclosure Heinle & Chen, 2018). Without a respective enclosure, this module can be skipped. The module communicates with the enclosure's built-in Siemens S7 PLC and powers down the spectrometer at dusk to extend the overall spectrometer lifetime. At dawn, it powers up the spectrometer again. Based on the previously described measurement triggers the module will open and close the cover. Protecting the instrument from bad weather conditions is always prioritized over performing measurements.
OPUSMeasurements manages the FTIR spectrometer measurement software OPUS. It communicates with OPUS via a Dynamic Data Exchange (DDE) connection to load measurement macro files, and start and stop measurements. During the day OPUS is kept up and running. During the night OPUS is shut down to reset after a full day of measurements.
SunTracking operates the CamTracker software which controls the mirrors of the EM27/SUN. By controlling two motors these mirrors are in sync with the current sun position to ensure sunlight is directed into the instrument. During CamTrackers operation Pyra Core will monitor the difference between motor positions and calculated sun position in azimuth and elevation. Whenever the motor offset reaches a certain threshold the CamTracker software will be reinitialized by Pyra.
Finally, SystemChecks monitors important OS parameters (i.e. CPU, memory, disk space, power supply) and raises exceptions on certain thresholds.
Whenever exceptions occur or are resolved in any part of Pyra Core, a list of operators will be notified via email.
Since the measurement data will be post-processed and used on other machines, Pyra Core includes an upload client that allows uploading interferograms (produced by the EM27/SUN) and other auxiliary data using SSH while ensuring full data integrity. The upload client runs in parallel to the measurement procedures.

Pyra CLI
Pyra CLI is designed to offer a text-based interface, which allows full control over Pyra Core without the need for a graphical user interface. Switching to CLI mode enables different teams of the community to easily integrate Pyra into their existing hardware solutions and keep their custom control logic for measurements. It is possible to temporarily disable external CLI-based measurement decisions by switching back to Manual mode. The CLI is structured into different command groups (config, core, logs, plc, state). The config commands can read and write the config.json file and validate its structural integrity before updating to a new configuration, while the state commands read the latest content of state.json. The core commands allow direct interaction with the Pyra Core process and ensure that only one instance of the Pyra Core process is running at a time. The PLC commands interact with the integrated sensors and actors inside the TUM enclosures.
Pyra CLI is also integrated into Pyra UI and handles communication between the graphical user interface and Pyra Core.

Pyra UI
Pyra UI provides a graphical user interface ( Figure 2) to interact with Pyra Core. In the background, Pyra CLI sends commands and reads the state-and log files from the file system.
In the Overview tab, a collection of relevant information is presented for a quick check on Pyra's activity. In the Automation tab, the different measurement modes (Manual, Automation, and CLI) can be selected and Pyra Core can be started or stopped. The Configuration tab is used to edit the configuration parameters. Since the CLI is used for config updates, all updated parameter values will be validated and the validation result shown in the UI. In the Logs tab, the stream of log lines from Pyra Core is displayed. Debug log lines can be hidden and the updates can be paused for a detailed analysis. If TUM hardware is enabled in the configuration there is an additional PLC Controls tab. By default, Pyra Core has full control over the enclosure. If required the user can take over control and interact with the PLC directly. Examples of manual interaction are adjusting the cover position or toggling power relays.

Software Dependencies
The Pyra codebase consists of three software stacks: The Core and the CLI are written in Python 2 and the UI is written in TypeScript 3 . The documentation is written in Markdown and rendered as HTML using Docusaurus 4 .
For Pyra Core and Pyra CLI, we are using Python 3.10 and Python Poetry 5 as the dependency management tool. All Python libraries in use can be found in the pyproject.toml file. Tests can be run using pytest 6 . The whole codebase has static type annotations which can be checked using MyPy 7 . In addition to that, we are reusing the static type annotations to validate the JSON files loaded from the location file system with pydantic 8 .
Pyra UI is written in HTML/CSS and TypeScript using the ReactJS framework 9 and Tail-windCSS 10 . We are using Vite 11 as a build tool and Tauri 12 to bundle the web-based UI into a Windows application. The libraries used by the UI codebase can be found in packages/ui/package.json.
The Pyra Setup Tool depends on Git 13 and also comes with a pyproject.toml file. Pyra itself communicates with OPUS and CamTracker 14 .

Author Contributions
PA worked on the concept, architecture, and implementation of the original Pyra software; PA coordinated the development of Pyra 4; PA and MM developed the architecture of Pyra 4; PA and MM implemented Pyra Core and integrated it on all MUCCnet stations; MM developed Pyra CLI and Pyra UI; MM developed Pyra's DevOps concept and wrote its documentation website; AL helped with beta testing and gave feedback on Pyra alpha and beta versions as the operator of MUCCnet; JC and FD designed the concept of an autonomously operating EM27/SUN network; JC initialized the development of this software; JC, FD and AL helped with their expertise in working with EM27/SUN spectrometers; PA, MM, and AL wrote the manuscript; JC and FD edited the manuscript. 13 https://git-scm.com/ 14 https://www.bruker.com/en/products-and-solutions/infrared-and-raman/remote-sensing/em27-sun-solarabsorption-spectrometer.html