{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# 4 — Statistics and exposure\n", "\n", "**Theme:** turning a marked record into numbers — task statistics, and the\n", "metrics used for occupational exposure assessment.\n", "\n", "Everything here builds on the activities from\n", "[3 — Activities](03-activities.ipynb)." ], "id": "cell-00" }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import aerosoltools as at\n", "\n", "elpi = at.load_elpi_file(\"../../tests/data/Sample_ELPI.txt\")\n", "elpi.mark_activities({\n", " \"Background\": [(\"2023-09-07 09:06:50\", \"2023-09-07 09:07:50\")],\n", " \"Emission\": [(\"2023-09-07 09:07:55\", \"2023-09-07 09:08:30\")],\n", " \"Decay\": [(\"2023-09-07 09:09:00\", \"2023-09-07 09:10:50\")],\n", "})\n", "elpi.activities" ], "id": "cell-01" }, { "cell_type": "markdown", "metadata": {}, "source": [ "## What can this dataset be summarised on?\n", "\n", "Which quantities are available depends on the instrument. A size-resolved\n", "instrument can produce mass and number fractions at any cut diameter; a\n", "single-channel one cannot. `available_metrics` reports what this particular\n", "dataset supports." ], "id": "cell-02" }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "for metric in elpi.available_metrics():\n", " print(f\"{metric.key:12s} {metric.label:28s} [{metric.unit}]\")" ], "id": "cell-03" }, { "cell_type": "markdown", "metadata": {}, "source": [ "## One channel at a time\n", "\n", "`summarize` gives descriptive statistics for a single channel, split by\n", "activity." ], "id": "cell-04" }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "elpi.summarize()" ], "id": "cell-05" }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Every activity at once\n", "\n", "`summarize_activities` is the usual starting point: descriptive statistics per\n", "activity, including duration and — for size-resolved data — size metrics such as\n", "mode and geometric mean diameter." ], "id": "cell-06" }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "elpi.summarize_activities()" ], "id": "cell-07" }, { "cell_type": "markdown", "metadata": {}, "source": [ "You can restrict it to particular metrics or statistics rather than taking the\n", "default set." ], "id": "cell-08" }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "elpi.summarize_activities(metrics=[\"PNC\", \"PM2.5\"], stats=[\"mean\", \"median\", \"max\"])" ], "id": "cell-09" }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Exposure assessment\n", "\n", "`summarize_exposure` answers the occupational-hygiene question: given this\n", "measurement, what is the exposure, and how does it compare with a limit?\n", "\n", "It reports a time-weighted average over `twa_window` (8 h by convention), the\n", "short-term exceedances over `short_window` (15 min by convention), peak counts,\n", "high percentiles, and the time spent above each limit." ], "id": "cell-10" }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "exposure = elpi.summarize_exposure(\n", " metric=\"PM4.2\", # respirable dust\n", " activities=[\"Emission\"],\n", " background=\"Background\", # subtract the mean of this activity\n", " exposure_hours=None, # None -> use the measured task duration\n", " short_limit=1.0, # STEL, in metric units\n", " long_limit=1.0, # 8 h OEL, in metric units\n", " short_window=\"15min\",\n", " twa_window=\"8h\",\n", ")\n", "exposure" ], "id": "cell-11" }, { "cell_type": "markdown", "metadata": {}, "source": [ "Three arguments carry most of the meaning:\n", "\n", "- **`background`** — either a number, or the name of an activity whose average\n", " is used. Subtracting a measured background separates the process\n", " contribution from what was already in the room.\n", "- **`exposure_hours`** — how long the worker is assumed to be exposed. `None`\n", " uses the measured duration of the activity; give a number to extrapolate a\n", " short measurement to a full shift.\n", "- **`metric`** — which quantity the limit applies to.\n", "\n", "Compare a short task assumed to last the whole shift against the same task\n", "taken at its measured length:" ], "id": "cell-12" }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "measured = elpi.summarize_exposure(metric=\"PM4.2\", activities=[\"Emission\"],\n", " background=\"Background\", exposure_hours=None)\n", "full_shift = elpi.summarize_exposure(metric=\"PM4.2\", activities=[\"Emission\"],\n", " background=\"Background\", exposure_hours=8.0)\n", "\n", "twa_cols = [c for c in measured.columns if \"TWA\" in c]\n", "\n", "print(\"assumed duration = measured task length\")\n", "print(measured[[\"Segment\"] + twa_cols].to_string(index=False))\n", "print()\n", "print(\"assumed duration = 8 h\")\n", "print(full_shift[[\"Segment\"] + twa_cols].to_string(index=False))" ], "id": "cell-13" }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Choosing a metric\n", "\n", "For size-resolved data the metric can be any of:\n", "\n", "- `\"PNC\"` — total number concentration\n", "- `\"MASS\"` — total mass concentration\n", "- `\"PM\"`, `\"PN\"`, `\"PS\"`, `\"PV\"` — cumulative mass, number, surface\n", " or volume below cut diameter `` in µm, e.g. `\"PM2.5\"`\n", "- `\"PM-\"` — the band between two diameters, e.g. `\"PM1-4\"`, computed with\n", " the EN 481 / ISO 7708 penetration curves\n", "\n", "Several activities can be summarised in one call, which is the convenient form\n", "when comparing tasks." ], "id": "cell-14" }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "elpi.summarize_exposure(\n", " metric=\"PM10\",\n", " activities=[\"Emission\", \"Decay\"],\n", " background=\"Background\",\n", " long_limit=5.0,\n", " short_limit=10.0,\n", ")" ], "id": "cell-15" }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Single-channel instruments\n", "\n", "A 1D instrument has no size distribution, so the metric is its own measurement —\n", "`\"PNC\"` for a CPC." ], "id": "cell-16" }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "cpc = at.load_cpc_file(\"../../tests/data/Sample_CPC_AIM.txt\")\n", "cpc.mark_activities({\n", " \"Task\": [(\"2023-08-14 11:14:00\", \"2023-08-14 11:18:00\")],\n", "})\n", "\n", "cpc.summarize_exposure(\n", " metric=\"PNC\",\n", " activities=[\"Task\"],\n", " exposure_hours=8.0,\n", " long_limit=1e4,\n", " short_limit=2e4,\n", ")" ], "id": "cell-17" }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Saving the result\n", "\n", "Both summary functions accept `filename` and append to a CSV or Excel file, so\n", "results from several measurements accumulate in one place.\n", "\n", "```python\n", "elpi.summarize_activities(filename=\"campaign_summary.xlsx\",\n", " sheet_name=\"2023-09-07\")\n", "```\n", "\n", "---\n", "\n", "**Next:** [5 — Plotting](05-plotting.ipynb)." ], "id": "cell-18" } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "name": "python", "version": "3.11" } }, "nbformat": 4, "nbformat_minor": 5 }