{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# 13 — APS: dual size distributions\n", "\n", "**Theme:** an instrument that sizes the same particle two different ways at\n", "once.\n", "\n", "The TSI Aerodynamic Particle Sizer measures an **aerodynamic** diameter, from\n", "how a particle accelerates in a flow, and an **optical** diameter, from how much\n", "light it scatters. The two differ in a way that depends on particle shape and\n", "refractive index — so comparing them says something about what the particles\n", "*are*, not just how large they are.\n", "\n", "An APS export therefore loads as `Aerosol3d`: two size distributions over time,\n", "plus the correlation between them." ], "id": "cell-00" }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import matplotlib.pyplot as plt\n", "\n", "import aerosoltools as at\n", "\n", "aps = at.load_aps_file(\"../../tests/data/Sample_APS_correlated.txt\")\n", "\n", "print(\"type :\", type(aps).__name__)\n", "print(\"is_correlated:\", aps.is_correlated)" ], "id": "cell-01" }, { "cell_type": "markdown", "metadata": {}, "source": [ "`is_correlated` distinguishes the two kinds of export. A correlated file carries\n", "both axes and the joint distribution; an aerodynamic-only file loads as a plain\n", "`Aerosol2D`, because there is no second axis to pair with." ], "id": "cell-02" }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "aero_only = at.load_aps_file(\"../../tests/data/Sample_APS_aero.txt\")\n", "print(\"aerodynamic-only export loads as:\", type(aero_only).__name__)" ], "id": "cell-03" }, { "cell_type": "markdown", "metadata": {}, "source": [ "## The two axes\n", "\n", "Each axis is available as an ordinary size-resolved dataset, so everything from\n", "the earlier notebooks works on it. Note that they do not share a bin structure:\n", "the two sizing principles have different resolutions and cover different ranges." ], "id": "cell-04" }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "print(f\"aerodynamic: {len(aps.aerodynamic.bin_mids):2d} bins, \"\n", " f\"{aps.aerodynamic.bin_mids.min():7.1f} - {aps.aerodynamic.bin_mids.max():8.1f} nm\")\n", "print(f\"optical : {len(aps.optical.bin_mids):2d} bins, \"\n", " f\"{aps.optical.bin_mids.min():7.1f} - {aps.optical.bin_mids.max():8.1f} nm\")" ], "id": "cell-05" }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Comparing the two distributions\n", "\n", "Drawing both on one axes needs a colour per dataset. `plot_psd` normally\n", "colours by *activity*, so two datasets would otherwise come out the same colour\n", "and read as a single line doubling back on itself. Pass `color` and `label` to\n", "name the dataset instead.\n", "\n", "The shaded band around each curve is ±1 standard deviation across time, not an\n", "uncertainty on the mean." ], "id": "cell-06" }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "fig, ax = plt.subplots(figsize=(8, 5))\n", "\n", "aps.aerodynamic.plot_psd(ax=ax, activities=[\"All data\"],\n", " color=\"tab:blue\", label=\"aerodynamic\")\n", "aps.optical.plot_psd(ax=ax, activities=[\"All data\"],\n", " color=\"tab:orange\", label=\"optical\")\n", "\n", "ax.set_xscale(\"log\")\n", "ax.set_title(\"The same particles, sized two ways\")\n", "ax.legend(loc=\"upper right\")\n", "plt.tight_layout()" ], "id": "cell-07" }, { "cell_type": "markdown", "metadata": {}, "source": [ "The separation between the curves is the physical signal. For spherical\n", "particles of known refractive index the two sizings agree; they diverge as\n", "particles become irregular, porous, or optically unusual. The optical\n", "distribution here is both coarser and narrower, which is what a small number of\n", "wide bins produces.\n", "\n", "## Working with one axis\n", "\n", "`as_2d` returns an independent copy of one axis — modify it freely without\n", "touching the parent." ], "id": "cell-08" }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "standalone = aps.as_2d(\"aerodynamic\")\n", "print(type(standalone).__name__, \"with\", len(standalone.bin_mids), \"bins\")" ], "id": "cell-09" }, { "cell_type": "markdown", "metadata": {}, "source": [ "`axis_view` returns a *live* view instead, with activities kept in sync with the\n", "parent. Use `axis_view` when you want marked activities to follow, and `as_2d`\n", "when you want an independent object." ], "id": "cell-10" }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "view = aps.axis_view(\"optical\")\n", "print(type(view).__name__, \"- activities stay synced with the parent\")" ], "id": "cell-11" }, { "cell_type": "markdown", "metadata": {}, "source": [ "## The instrument's own comparison\n", "\n", "`plot_aero_vs_optical` shows the relationship between the two diameters\n", "directly, rather than as two separate distributions." ], "id": "cell-12" }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "fig, ax = aps.plot_aero_vs_optical()" ], "id": "cell-13" }, { "cell_type": "markdown", "metadata": {}, "source": [ "## The joint distribution\n", "\n", "For each time step the instrument records how many particles fell in each\n", "(aerodynamic, optical) pair of bins. `correlation_cube` returns that as a dense\n", "time × optical × aerodynamic array." ], "id": "cell-14" }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "cube = aps.correlation_cube()\n", "print(\"type:\", type(cube).__name__)" ], "id": "cell-15" }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "fig, ax = aps.plot_aero_optical_3d()" ], "id": "cell-16" }, { "cell_type": "markdown", "metadata": {}, "source": [ "This is what makes an APS more than two instruments in a box: it records which\n", "optical size each aerodynamically-sized particle had, rather than giving two\n", "independent histograms that happen to cover the same air.\n", "\n", "## Summaries\n", "\n", "Because each axis is a normal size-resolved dataset, mass fractions, statistics\n", "and exposure metrics all work per axis." ], "id": "cell-17" }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "aps.aerodynamic.summarize_activities(metrics=[\"PNC\"], stats=[\"mean\", \"median\", \"max\"])" ], "id": "cell-18" }, { "cell_type": "markdown", "metadata": {}, "source": [ "---\n", "\n", "**Next:** [15 — ACSM](15-acsm.ipynb)." ], "id": "cell-19" } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "name": "python", "version": "3.11" } }, "nbformat": 4, "nbformat_minor": 5 }