Map aerosol optical depth over New Mexico
View code · Download Python script · Download complete ZIP
Map aerosol optical depth over New Mexico
Section titled “Map aerosol optical depth over New Mexico”Where did aerosols extinguish the most 550 nm light across this region on 1 January 2025 at 18:00 UTC? The CAMS EAC4 reanalysis estimates optical depth for the full atmospheric column. A larger value means stronger attenuation by aerosol scattering and absorption along a vertical path. The map compares individual grid cells within a rectangle around New Mexico.
Download the example ZIP, extract it, and install the plotting and GRIB packages
with python -m pip install numpy matplotlib eccodes. Run
python example.py --output cams-aod.png from the
folder containing the script. The 300-byte original GRIB and the exact ADS
request are included. To use a fresh download, pass --grib PATH.
The Copernicus guide shows how to
save a token and retrieve the field using Particula.
Read one analysis time
Section titled “Read one analysis time”ecCodes identifies the physical quantity and valid time in the GRIB message. Pair each value with its own coordinates before arranging the map south to north and west to east. This keeps the ordering independent of the file’s scan direction. The example expects one complete regional latitude/longitude grid with at least two cells in each direction.
Python · section 1
import argparsefrom datetime import datetimefrom pathlib import Path
import matplotlib.pyplot as pltimport numpy as np
def bundled_grib() -> Path: """Locate the input in the example ZIP or repository checkout.""" relative = Path("docs/data/copernicus-eac4/aod550.grib") for base in (Path.cwd(), *Path(__file__).resolve().parents): if (base / relative).is_file(): return base / relative raise FileNotFoundError("Extract the example ZIP or supply --grib PATH.")
def read_field(path: Path) -> dict: """Read total 550 nm AOD and its geographic coordinates from one GRIB.""" import eccodes as ec
with path.open("rb") as stream: handle = ec.codes_grib_new_from_file(stream) if handle is None: raise ValueError("The file contains no GRIB message.") try: if ( ec.codes_get(handle, "paramId") != 210207 or ec.codes_get(handle, "gridType") != "regular_ll" or ec.codes_get(handle, "numberOfMissing") != 0 ): raise ValueError("Expected complete regular-grid 550 nm AOD.") day = ec.codes_get(handle, "validityDate") clock = ec.codes_get(handle, "validityTime") time = datetime.strptime(f"{day}{clock:04d}", "%Y%m%d%H%M") lat = ec.codes_get_array(handle, "latitudes") lon = (ec.codes_get_array(handle, "longitudes") + 180) % 360 - 180 values = ec.codes_get_values(handle) finally: ec.codes_release(handle) if stream.read(1): raise ValueError("Select a file containing a single GRIB message.")
y, iy = np.unique(lat, return_inverse=True) x, ix = np.unique(lon, return_inverse=True) if ( min(len(y), len(x)) < 2 or len(values) != len(y) * len(x) or len(np.unique(iy * len(x) + ix)) != len(values) or not np.allclose(np.diff(x), x[1] - x[0]) or not np.allclose(np.diff(y), y[1] - y[0]) ): raise ValueError("Expected one sample per cell on a regular grid.") grid = np.empty((len(y), len(x))) grid[iy, ix] = values return { "latitude": y.tolist(), "longitude": x.tolist(), "aod550": grid.tolist(), "valid_utc": time.strftime("%Y-%m-%d %H:%M UTC"), }Compare grid cells at the same wavelength and time
Section titled “Compare grid cells at the same wavelength and time”Each colored tile is centered on an EAC4 grid point. The rectangular footprint shows the sampling resolution, with no smoothing between centers. L and H mark the lowest and highest cells. The median treats each sampled center equally. For a statewide average, clip the cells to the boundary and weight by their areas inside it.
Python · section 2
def plot_results(report): """Map dimensionless column AOD with native cells and labeled extrema.""" from matplotlib.ticker import MaxNLocator
x, y = np.array(report["longitude"]), np.array(report["latitude"]) aod = np.array(report["aod550"]) fig, ax = plt.subplots(figsize=(6.6, 6.5)) fig.subplots_adjust(left=0.12, right=0.76, bottom=0.21, top=0.83) mesh = ax.pcolormesh(x, y, aod, shading="nearest", cmap="viridis") ax.set_aspect(1 / np.cos(np.deg2rad(y.mean()))) ax.set(xlabel="Longitude (°E)", ylabel="Latitude (°N)") ax.xaxis.set_major_locator(MaxNLocator(5, integer=True)) ax.yaxis.set_major_locator(MaxNLocator(6, integer=True)) for index, label in ((aod.argmin(), "L"), (aod.argmax(), "H")): row, col = np.unravel_index(index, aod.shape) ax.text( x[col], y[row], label, ha="center", va="center", fontsize=9, color="white", weight="bold", bbox=dict(boxstyle="circle,pad=0.25", fc="#222b35", ec="white"), ) bar = fig.colorbar(mesh, cax=ax.inset_axes([1.06, 0, 0.05, 1])) bar.set_label("Optical depth (dimensionless)") fig.suptitle( "Aerosol optical depth at 550 nm", x=0.12, y=0.96, ha="left", fontsize=20, weight="bold", ) fig.text( 0.12, 0.875, f"CAMS EAC4 reanalysis · {report['valid_utc']}", size=12, ) fig.text( 0.12, 0.077, f"L {aod.min():.4f} • Median {np.median(aod):.4f}" f" • H {aod.max():.4f}", size=11, ) fig.text( 0.12, 0.031, "Source: Copernicus Atmosphere Monitoring Service / ECMWF", size=9, color="#44515a", ) return fig
if __name__ == "__main__": parser = argparse.ArgumentParser(description=plot_results.__doc__) parser.add_argument("--grib", type=Path, help="Single regional aod550 GRIB") parser.add_argument("--output", type=Path, help="Destination figure path") args = parser.parse_args() figure = plot_results(read_field(args.grib or bundled_grib())) if args.output: figure.savefig(args.output, dpi=300) else: plt.show()Explicit cpu invocation
report = read_field(bundled_grib())figure = plot_results(report)
The largest optical depth, 0.1317, lies on the eastern edge at 36.00° N, 103.50° W. At the same latitude the westernmost cell has the minimum, 0.0154. The median across the 64 grid centers is 0.0556. These are differences in column extinction at a single analysis time. To investigate which particles contributed to the eastern maximum, retrieve the EAC4 dust, sea-salt, sulfate, organic-matter and black-carbon optical depths at the same wavelength, time and coordinates, then compare their contributions against the total.
Contains Copernicus Atmosphere Monitoring Service information (2026). Original EAC4 data distributed by ECMWF via the Atmosphere Data Store under CC BY 4.0. The figure visualizes a regional subset of the CAMS global reanalysis (EAC4).
Study resources
Section titled “Study resources”Explore this topic: Optical properties · Atmospheric processes