{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# 11 — Simple instruments\n", "\n", "**Theme:** instruments that report a handful of values rather than a size\n", "distribution.\n", "\n", "A dosimeter, a gas monitor and a photometer all produce one or a few channels\n", "over time. They reuse the whole `Aerosol1D` machinery — activities, time\n", "operations, statistics, plotting — and add accessors named after what they\n", "actually measure.\n", "\n", "Instruments that do not count particles (gas monitors, environmental loggers,\n", "the Partector) deliberately have **no** `total_concentration`: reporting a\n", "chlorine reading as a particle number concentration would be wrong. Use their\n", "own accessors instead." ], "id": "cell-00" }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import aerosoltools as at" ], "id": "cell-01" }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Partector — lung-deposited surface area\n", "\n", "The Partector reports LDSA, the surface area of particles that deposits in the\n", "lung. The TEM variant also samples particles onto grids for microscopy, and\n", "records when it did so." ], "id": "cell-02" }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "partector = at.load_partector_file(\"../../tests/data/Sample_Partector.txt\")\n", "\n", "print(\"instrument:\", partector.instrument)\n", "print(\"columns :\", list(partector.data))\n", "print(\"unit :\", partector.unit)" ], "id": "cell-03" }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "print(\"LDSA :\", partector.ldsa.head(3).tolist(), partector.unit)\n", "print(\"flow :\", partector.flow.head(3).tolist())" ], "id": "cell-04" }, { "cell_type": "markdown", "metadata": {}, "source": [ "`tem_samples` reports the grid-sampling periods, so microscopy results can be\n", "tied back to the time series they came from." ], "id": "cell-05" }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "partector.tem_samples" ], "id": "cell-06" }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "fig, ax = partector.plot_total_conc()\n", "ax.set_title(\"Partector LDSA\")" ], "id": "cell-07" }, { "cell_type": "markdown", "metadata": {}, "source": [ "## DiSCmini — number, size and LDSA\n", "\n", "The DiSCmini reports a particle number concentration, a mean particle size and\n", "LDSA from the same measurement. It *does* count particles, so it keeps\n", "`total_concentration`." ], "id": "cell-08" }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "disc = at.load_discmini_file(\"../../tests/data/Sample_Discmini.txt\")\n", "\n", "print(\"columns:\", list(disc.data))\n", "print(f\"number : {disc.total_concentration.mean():.0f} {disc.unit}\")\n", "print(f\"size : {disc.size.mean():.1f} nm\")\n", "print(f\"LDSA : {disc.ldsa.mean():.1f}\")" ], "id": "cell-09" }, { "cell_type": "markdown", "metadata": {}, "source": [ "Mean size is a single number, not a distribution — the DiSCmini cannot\n", "distinguish a narrow distribution from a wide one with the same mean. For that\n", "you need a sizing instrument, see [8 — PSD fitting](08-psd-fitting.ipynb).\n", "\n", "## DustTrak — PM mass fractions\n", "\n", "The DustTrak DRX reports the standard mass fractions simultaneously." ], "id": "cell-10" }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "dust = at.load_dusttrak_file(\"../../tests/data/Sample_DustTrak.csv\")\n", "\n", "print(\"instrument :\", dust.instrument)\n", "print(\"serial number:\", dust.serial_number)\n", "print(\"columns :\", list(dust.data))\n", "print(\"units :\", dust.column_units)" ], "id": "cell-11" }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "print(f\"PM1 {dust.pm1.mean():7.1f}\")\n", "print(f\"PM2.5 {dust.pm2_5.mean():7.1f}\")\n", "print(f\"PM4 {dust.pm4.mean():7.1f}\")\n", "print(f\"PM10 {dust.pm10.mean():7.1f}\")\n", "print(f\"Total {dust.total.mean():7.1f} (all in ug/m3)\")" ], "id": "cell-12" }, { "cell_type": "markdown", "metadata": {}, "source": [ "The fractions are cumulative, so each is at least as large as the one below it.\n", "The gaps between them describe the coarseness of the aerosol." ], "id": "cell-13" }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import matplotlib.pyplot as plt\n", "\n", "fig, ax = plt.subplots(figsize=(9, 4))\n", "for name in [\"pm1\", \"pm2_5\", \"pm4\", \"pm10\"]:\n", " ax.plot(dust.time, getattr(dust, name), label=name.upper().replace(\"_\", \".\"))\n", "ax.set_ylabel(\"Mass concentration [ug/m3]\")\n", "ax.legend()\n", "ax.set_title(\"DustTrak cumulative mass fractions\")" ], "id": "cell-14" }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Gas monitors\n", "\n", "`Gas1D` covers instruments measuring one gas at a time. The reading is always\n", "`.concentration`; which gas it is lives in `.dtype`. That split means the same\n", "code works whatever the instrument is configured for.\n", "\n", "A Ranger uses interchangeable heads, so one file can contain several\n", "components — the loader returns one object per component." ], "id": "cell-15" }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "loaded = at.load_ranger_file(\"../../tests/data/Ranger_2605-1000088-A_20260612-0603.csv\")\n", "objects = loaded if isinstance(loaded, list) else [loaded]\n", "\n", "for obj in objects:\n", " dtype = obj.dtype if not isinstance(obj.dtype, dict) else \"PM channels\"\n", " print(f\"{type(obj).__name__:12s} {str(dtype):14s} {len(obj.data):5d} samples\")" ], "id": "cell-16" }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "chlorine = next(o for o in objects if o.dtype == \"Cl₂\")\n", "\n", "print(f\"gas : {chlorine.dtype}\")\n", "print(f\"unit : {chlorine.unit}\")\n", "print(f\"mean : {chlorine.concentration.mean():.4f} {chlorine.unit}\")" ], "id": "cell-17" }, { "cell_type": "markdown", "metadata": {}, "source": [ "A Tiger VOC monitor is the same class with a different gas, so the same\n", "accessor works unchanged." ], "id": "cell-18" }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "tiger = at.load_tiger_file(\"../../tests/data/Sample_Tiger.csv\")\n", "\n", "print(f\"gas : {tiger.dtype}\")\n", "print(f\"unit : {tiger.unit}\")\n", "print(f\"mean : {tiger.concentration.mean():.1f} {tiger.unit}\")" ], "id": "cell-19" }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "fig, ax = tiger.plot_total_conc()\n", "ax.set_title(f\"Tiger {tiger.dtype}\")" ], "id": "cell-20" }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Environmental loggers\n", "\n", "`Environmental1D` covers temperature, humidity and related channels. Only the\n", "channels actually present in the file are available." ], "id": "cell-21" }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "env = at.load_fourtec_file(\"../../tests/data/Sample_Fourtec.xlsx\")\n", "\n", "print(\"columns:\", list(env.data))\n", "print(f\"temperature: {env.temperature.mean():.2f} degC\")\n", "print(f\"RH : {env.rh.mean():.1f} %\")" ], "id": "cell-22" }, { "cell_type": "markdown", "metadata": {}, "source": [ "Asking for a channel the file does not contain raises a message naming what\n", "*is* available, rather than a bare `KeyError`." ], "id": "cell-23" }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "try:\n", " env.pressure\n", "except AttributeError as err:\n", " print(\"AttributeError:\", err)" ], "id": "cell-24" }, { "cell_type": "markdown", "metadata": {}, "source": [ "## The shared contract\n", "\n", "Non-particle instruments raise on `total_concentration` by design." ], "id": "cell-25" }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "for obj, label in [(tiger, \"Gas1D\"), (env, \"Environmental1D\"),\n", " (partector, \"Partector\")]:\n", " try:\n", " obj.total_concentration\n", " print(f\"{label:16s} has total_concentration\")\n", " except AttributeError:\n", " print(f\"{label:16s} correctly has no total_concentration\")" ], "id": "cell-26" }, { "cell_type": "markdown", "metadata": {}, "source": [ "Everything else does work on them — activities, cropping, summaries, plotting —\n", "because they are ordinary `Aerosol1D` objects underneath." ], "id": "cell-27" }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "tiger.mark_activities({\n", " \"Weaving\": [(str(tiger.time[100]), str(tiger.time[400]))],\n", "})\n", "tiger.summarize_activities()" ], "id": "cell-28" }, { "cell_type": "markdown", "metadata": {}, "source": [ "---\n", "\n", "**Next:** [12 — Aethalometer](12-aethalometer.ipynb)." ], "id": "cell-29" } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "name": "python", "version": "3.11" } }, "nbformat": 4, "nbformat_minor": 5 }