# BAM1020 Beta Attenuation Monitor

The BAM1020 is a beta attenuation monitor used for measuring PM2.5 mass concentrations in ambient air.

::: AeroViz.rawDataReader.script.BAM1020.Reader

## Data Format

- File format: CSV files
- Sampling frequency: 1 hour
- File naming pattern: Various formats supported
- Data columns: PM2.5 mass concentration and related parameters

## Measurement Parameters

The BAM1020 provides:

| Parameter | Unit | Description |
|-----------|------|-------------|
| Conc | μg/m³ | PM2.5 mass concentration |
| Status | - | Instrument status codes |
| Flow | L/min | Sample flow rate |
| Temperature | °C | Internal temperature |
| Pressure | hPa | Atmospheric pressure |

## Data Processing

### Data Reading

- Reads CSV format files with automatic column detection
- Handles various timestamp formats
- Processes instrument status information
- Validates data integrity

### Quality Control

The BAM1020 reader uses the declarative **QCFlagBuilder** system with the following rules:

```
+-----------------------------------------------------------------------+
|                         QC Thresholds                                 |
+-----------------------------------------------------------------------+
| MIN_CONC = 0         μg/m³                                            |
| MAX_CONC = 1000      μg/m³                                            |
+-----------------------------------------------------------------------+

+-----------------------------------------------------------------------+
|                            _QC() Pipeline                             |
+-----------------------------------------------------------------------+
|                                                                       |
|  +---------------------------+    +---------------------------+       |
|  | Rule: Invalid Conc        |    | Rule: Spike               |       |
|  +---------------------------+    +---------------------------+       |
|  | Conc <= 0 OR              |    | Sudden value change       |       |
|  | Conc > 500 μg/m³          |    | (vectorized detection)    |       |
|  +---------------------------+    +---------------------------+       |
|                                                                       |
+-----------------------------------------------------------------------+
```

#### QC Rules Applied

| Rule | Condition | Description |
|------|-----------|-------------|
| **Invalid Conc** | Conc ≤ 0 OR Conc > 500 μg/m³ | Concentration outside valid range |
| **Spike** | Sudden value change | Unreasonable sudden change detected |

#### Valid Concentration Range

```
    Conc (μg/m³)
       ^
  1000 +-------------------------------- MAX_CONC
       |   +-----------------------+    (reject if exceeded)
       |   |    VALID RANGE        |
       |   +-----------------------+
     0 +-------------------------------- MIN_CONC
       +----------------------------> Time
```

## Output Data

The processed data contains:

| Column | Unit | Description |
|--------|------|-------------|
| Conc | μg/m³ | PM2.5 mass concentration |

!!! note "QC_Flag Handling"

    - The intermediate file (`_read_bam1020_qc.pkl/csv`) contains the `QC_Flag` column
    - The final output has invalid data set to NaN and `QC_Flag` column removed

## Notes

- Beta attenuation technology provides real-time PM2.5 measurements
- Regular calibration and maintenance are required for accurate results
- Status codes indicate instrument health and measurement validity
- Suitable for continuous ambient air quality monitoring