Skip to content

Spectrometer

This welcome notebook shows how to load and analyse Pandora spectrometer data. Pandora is a sun-pointing spectrometer of the Pandonia Global Network (PGN): from the direct sun spectra it retrieves total columns of trace gases such as nitrogen dioxide (NO₂), ozone (O₃) or formaldehyde (HCHO). The data is downloaded from the PGN API with the gathering package.

The notebook uses the L2 NO₂ total column of Pandora 111 in Bucharest over three months, and goes from one file to a weekday versus weekend comparison of the urban NO₂.

Notebook data_access/instruments/Spectrometer.ipynb (welcome-notebooks repository)
Data source Pandonia Global Network
Gatherer Task.pandora
Station Bucharest, Romania: Pandora 111, MARS Atmospheric Observatory (INOE)
Dates 1 May to 31 July 2023 (the instrument has no data after 21 July)
Product rnvs3 (NO₂ total column), level L2

PGN files

PGN files are organised by:

Parameter Meaning Example
station PGN location name "Bucharest"
instrument_id Pandora number at that station "111"
level L2Fit (spectral fitting output) or L2 (final products with quality flags) "L2"
product Product code "rnvs3" (NO₂ total column), "rout2" (O₃), "rfus5" (HCHO)

Before you start

The first cell installs the gathering package from the wheel shipped next to the notebook and imports what the notebook needs:

!pip install gathering-0.4.2-py3-none-any.whl

from pathlib import Path

import matplotlib.pyplot as plt
import numpy as np
import pandas as pd

from gathering import Pipeline, Task

1. Downloading the data

The task downloads every daily file of the period. The files are cached, so running the cell again does not download them again:

task = Task.pandora(
    station="Bucharest",
    instrument_id="111",  # Pandora 111 (INOE, MARS Atmospheric Observatory)
    product="rnvs3",  # NO2 total column
    level="L2",
    start_date="2023-05-01",
    end_date="2023-07-31",
)
results = Pipeline([task]).run()

files = sorted(results.to_dataframe()["files"].iloc[0])

It gives 81 daily files, with names like Pandora111s1_Bucharest_20230501_L2_rnvs3c1d20200901p1-8.txt.

2. Reading a PGN L2 file

Each file is plain text with three parts, separated by lines of dashes:

  1. A header with the metadata (instrument, location, data status, ...).
  2. The description of every column.
  3. The data, one row per measurement.

The helper read_pandora_l2 reads one file into a pandas DataFrame whose columns are numbered as in the file (1, 2, ...). It also returns the header and the column descriptions:

def read_pandora_l2(path):
    """Read a PGN L2 file: (data, header, column descriptions)."""
    lines = Path(path).read_text(encoding="latin-1").splitlines()
    separators = [i for i, line in enumerate(lines) if line.startswith("---")]

    header = dict(line.split(": ", 1) for line in lines[: separators[0]] if ": " in line)
    descriptions = {}
    for line in lines[separators[0] + 1 : separators[1]]:
        number, text = line.split(": ", 1)
        descriptions[int(number.split()[1])] = text

    rows = [line.split() for line in lines[separators[1] + 1 :] if line.strip()]
    data = pd.DataFrame(rows, columns=range(1, len(rows[0]) + 1))
    time = pd.to_datetime(data.pop(1), format="%Y%m%dT%H%M%S.%fZ", utc=True)
    data = data.apply(pd.to_numeric)
    data.insert(0, 1, time)
    return data, header, descriptions

The header confirms the location (MARS Atmospheric Observatory, 44.344° N, 26.012° E) and the data status ("Nitrogen dioxide data are official").

3. Selecting the columns

The files have more than 50 columns. The notebook keeps these ones:

Column Name Content
1 time UT date and time of the measurement centre
4 sza Solar zenith angle
36 quality_flag L2 data quality flag for NO₂
39 no2_total NO₂ total vertical column
43 no2_total_uncertainty Total uncertainty of the column
53 no2_stratosphere Climatological stratospheric column

Every day is read and the columns are joined into one table. The columns are given in mol/m²; the notebook converts them to Dobson units (1 DU = 4.4615·10⁻⁴ mol/m²), the usual unit for total columns, and adds the local time:

MOL_M2_PER_DU = 4.4615e-4

no2 = pd.concat(
    [read_pandora_l2(f)[0][list(COLUMNS)].rename(columns=COLUMNS) for f in files],
    ignore_index=True,
)
for column in ["no2_total", "no2_total_uncertainty", "no2_stratosphere"]:
    no2[column] = no2[column] / MOL_M2_PER_DU
no2["local_time"] = no2["time"].dt.tz_convert("Europe/Bucharest")

4. Quality flags

Every measurement has an L2 quality flag:

Flag Meaning
0, 1, 2 Assured high, medium and low quality
10, 11, 12 High, medium and low quality, not assured (the data has not gone through the final quality assurance yet)
20 or more Unusable

This period only has not-assured data, so the notebook keeps the high and medium quality measurements:

good = no2[no2["quality_flag"].isin([0, 1, 10, 11])]

5. One day of measurements

Pandora measures every few minutes while the sun is visible. The notebook plots one day (21 June 2023) with every measurement coloured by its quality flag and the total uncertainty as error bars. The low-quality points are the ones that were dropped: some of them are far off (even negative) and fall outside the plot.

6. The whole period

The total column includes the stratosphere, which barely changes from day to day. Subtracting the climatological stratospheric column given in the file leaves the tropospheric part, where the local pollution is. The notebook plots the daily median of both columns from May to July:

good = good.assign(no2_troposphere=good["no2_total"] - good["no2_stratosphere"])
daily = good.groupby(good["local_time"].dt.date)[["no2_total", "no2_troposphere"]].median()

7. Weekdays versus weekends

Most of the urban NO₂ comes from traffic. Taking the median of the tropospheric column by hour of the day, weekdays show a morning peak (rush hour, 7 to 10 local time) that is about 30% weaker on Saturdays and Sundays. The shaded areas of the plot go from the 25th to the 75th percentile:

good = good.assign(hour=good["local_time"].dt.hour,
                   weekend=good["local_time"].dt.day_of_week >= 5)

for weekend, label in [(False, "Monday to Friday"), (True, "Saturday and Sunday")]:
    hourly = good[good["weekend"] == weekend].groupby("hour")["no2_troposphere"]
    median, q25, q75 = hourly.median(), hourly.quantile(0.25), hourly.quantile(0.75)

Going further

  • Change the product to rout2 (O₃) or rfus5 (HCHO), or the station and instrument, to explore other gases and PGN sites. The column numbers can differ between products: check them in the column descriptions returned by read_pandora_l2.
  • The other instrument notebooks follow the same pattern: Photometer, Lidar, Ceilometer and Radar.