Skip to content

design_values

design_values

Regulatory design-value calculations from POSTFILE output.

This module turns raw concentration time series (parsed via :mod:pyaermod.postfile) into the percentile / design-value figures that NAAQS regulatory submittals quote. Each function is annotated with its 40 CFR Part 50 citation and the EPA design-value guidance that prescribes the math.

All functions accept a :class:pandas.DataFrame shaped like the data attribute of :class:pyaermod.postfile.PostfileResult, i.e. with columns x, y, concentration, date (string in YYMMDDHH form), ave, grp.

Background concentrations (uniform or time-varying) can be added via :func:add_background before computing design values; per- pollutant pairing rules are in the function docstring.

Years are meteorological years, as AERMOD counts them: a year ends on the anniversary of the first met hour (CHK_ENDYR in aermod.f, with the boundary set in meset.f). Every design-value function takes year_start: None (the default) reads the boundary from the first date in the data, "calendar" groups by calendar year, and a (month, day) pair names the boundary. For data that start on 1 January the met year is the calendar year and nothing changes. Where 40 CFR Part 50 speaks of a calendar year (the annual NO2 mean of 50.11(e) and Appendix S, the annual statistics of Appendices N, S and T), the modelled met year stands in for it. The boundary is taken at day level: a run whose first hour is not hour 01 starts its year at midnight of that day here, a few hours earlier than AERMOD does.

DesignValue dataclass

Result of a design-value computation at one receptor.

naaqs_percentile_rank

naaqs_percentile_rank(n_days: int, percentile: float) -> int

Rank of the percentile-th value in a descending-sorted year.

Parameters:

Name Type Description Default
n_days int

Number of days in the year with valid data.

required
percentile float

98.0 or 99.0 (any percentile in (0, 100) is accepted and uses the same closed form the appendices tabulate).

required

Returns:

Type Description
int

1 for the highest value, 2 for the second highest, and so on -- ceil((1 - percentile/100) * n_days), clamped to at least 1.

Notes

Per 40 CFR 50 Appendix S Table 1, a full year (351-366 days) puts the 98th percentile at the 8th highest daily value; Appendix T Table 1 puts the 99th percentile at the 4th highest. Linear interpolation between order statistics -- what a naive Series.quantile does -- lands between ranks and reports a value the regulation never defines.

add_background

add_background(df: DataFrame, background: Union[float, Series, dict]) -> pd.DataFrame

Add a background concentration to every row of df.

Parameters:

Name Type Description Default
df DataFrame

POSTFILE-shaped DataFrame.

required
background Union[float, Series, dict]

Either a uniform number (any real number, numpy scalars such as np.float32 included, but not a bool), a pd.Series indexed by date (YYMMDDHH), or a dict mapping date -> float. Dates and keys are matched as 8-character YYMMDDHH stamps, so text, integers and whole-number floats all match (2005's first hour reads "05010101", 5010101 or 5010101.0). Two keys naming the same stamp raise :class:ValueError.

required

Returns:

Type Description
A new DataFrame with ``concentration`` += background; ``date`` is
left as given. Rows whose date has no background value are left
unchanged, with a warning naming how many dates that is: a background
that matches no date at all (usually keys that are not YYMMDDHH
stamps) or only some of them (hours missing from the background
series), since those hours then get no background.

Raises:

Type Description
TypeError

If background is none of those (a bool, a string, a list ...).

annual_mean

annual_mean(df: DataFrame, *, pollutant: str = '', year_start: YearStart = None) -> pd.DataFrame

Annual-mean design-value calculation.

Used for the PM2.5 annual NAAQS (40 CFR 50.20(a)-(b), Appendix N), whose form is the three-year average of annual means, and the NO2 annual NAAQS (40 CFR 50.11(a), (e); Appendix S), whose form is one calendar year's mean. This returns the mean of each year at each receptor; :func:naaqs_compliance_report combines the years in the form of each standard. The year is the met year (see the module docstring and year_start); it stands in for the calendar year of the rule, and year in the result is the calendar year the met year starts in.

NOTE: Appendix N (4.4(a)-(b)) forms the annual PM2.5 mean as the mean of the calendar quarters' means of the daily values. This function averages every row of the year instead, and that is the form kept here for modelled values. The two differ slightly for a complete year (the quarters have different lengths) and can differ more with gaps. AERMOD's own ANNUAL average is also over hours, but it divides by the hours that were neither calm nor missing (PERAVE in output.f), where a mean of hourly POSTFILE rows counts those hours as zeros.

Hourly (1-HR) input warns once that the mean divides by the number of rows (:func:pyaermod.postfile.warn_hourly_mean_limitation).

Returns one row per (x, y, year) with column concentration.

nth_highest_daily_max_design_value

nth_highest_daily_max_design_value(df: DataFrame, rank: int, *, daily: str = 'max', n_years: Optional[int] = None, pollutant: str = '', averaging_period: str = '', year_start: YearStart = None) -> pd.DataFrame

Multi-year average of the annual rank-th-highest daily value.

This is the general form behind the 1-hour NO2, 1-hour SO2 and 24-hour PM2.5 standards, and the one AERMOD itself computes under NO2AVE / SO2AVE / PM25AVE: rank each year's daily series independently, then take the arithmetic mean of those annual values across the years modelled (SUMHNH / NUMYRS in aermod.f). The years are met years, as AERMOD's are (see year_start).

Parameters:

Name Type Description Default
df DataFrame

POSTFILE-shaped frame for a single source group.

required
rank int

1 for the annual maximum, 8 for the NO2/PM2.5 98th percentile of a full year, 4 for the SO2 99th percentile of a full year. See :func:naaqs_percentile_rank to derive it from a percentile.

required
daily str

"max" (default) to take each day's maximum sub-daily value, "mean" to take each day's 24-hour average.

'max'
n_years Optional[int]

Number of years the standard is defined over; a mismatch with the data warns rather than fails.

None
year_start YearStart

Where each year begins: None (default) from the first date in the data, as AERMOD's met year does (CHK_ENDYR); "calendar" for calendar years; or a (month, day) pair. Data that start on 1 January give calendar years either way.

None

Returns:

Type Description
One row per receptor with ``x``, ``y``, ``concentration`` and the
actual ``n_years`` averaged.

pm25_24hr_design_value

pm25_24hr_design_value(df: DataFrame, *, n_years: int = 3, year_start: YearStart = None) -> pd.DataFrame

PM2.5 24-hour design value: 3-year avg of annual 98th percentiles.

Per 40 CFR 50.20(a), (c) and Appendix N. Standard: 35 µg/m³.

The daily value is the 24-hour average, so hourly input (AVE='1-HR') is averaged within each (receptor, day) group, with a warning that such a mean divides by the number of rows (:func:pyaermod.postfile.warn_hourly_mean_limitation); input that already carries AERMOD's AVE='24-HR' block averages is used as-is. Each year's 98th percentile is the rank Appendix N Table 1 assigns to that year's day count -- the 8th highest for a full year -- and the design value is the mean of those annual values. The years are met years (year_start, see :func:nth_highest_daily_max_design_value), standing in for the calendar years of Appendix N.

no2_1hr_design_value

no2_1hr_design_value(df: DataFrame, *, n_years: int = 3, year_start: YearStart = None) -> pd.DataFrame

NO2 1-hour design value: 3-year avg of annual 98th percentile of daily max 1-hour concentrations.

Per 40 CFR 50.11(b), (f) and Appendix S. Standard: 100 ppb. The annual 98th percentile is the rank Appendix S Table 1 assigns to that year's day count -- the 8th highest daily maximum for a full year. The years are met years (year_start, see :func:nth_highest_daily_max_design_value), standing in for the calendar years of Appendix S.

so2_1hr_design_value

so2_1hr_design_value(df: DataFrame, *, n_years: int = 3, year_start: YearStart = None) -> pd.DataFrame

SO2 1-hour design value: 3-year avg of annual 99th percentile of daily max 1-hour concentrations.

Per 40 CFR 50.17(b) and Appendix T. Standard: 75 ppb. The annual 99th percentile is the rank Appendix T Table 1 assigns to that year's day count -- the 4th highest daily maximum for a full year. The years are met years (year_start, see :func:nth_highest_daily_max_design_value), standing in for the calendar years of Appendix T.

pm10_24hr_design_value

pm10_24hr_design_value(df: DataFrame, *, rank: Optional[int] = None, year_start: YearStart = None) -> pd.DataFrame

PM10 24-hour design value: highest Nth-highest 24-hour value.

The standard (150 µg/m³, 40 CFR 50.6(a), Appendix K) is met when the expected number of days per calendar year above 150 µg/m³ is at most one, averaged over three years. Unlike the percentile standards this value is not an average across years: it ranks the pooled multi-year record and takes the highest (N+1)-th-high value for N years of meteorology, N allowed exceedances plus one: the highest second-high (H2H) with one year, H3H, H4H and H5H with two, three and four, and the highest sixth-high (H6H) with five. That modelling rule is the High-N+1-High of the AERMOD User's Guide (section 3.2.16.2), carried over from the pre-2017 Guideline on Air Quality Models (Appendix W, 7.2.1.1(b)); it is not in Part 50 or in the 2017 or current Appendix W.

rank defaults to N+1 for a record of N years and can be set explicitly. The years counted are met years (year_start, see :func:nth_highest_daily_max_design_value), so four July-to-June years are four years, not five. A partial year counts as a year and so raises the rank; a warning names it. The daily value is the 24-hour average, so hourly input is averaged within each day (with the warning of :func:pyaermod.postfile.warn_hourly_mean_limitation).

NOTE: Appendix K (1.0(b)) rounds each daily value to the nearest 10 µg/m³ before comparing it with 150, so only values of 155 and above are exceedances there, while Appendix W 9.2.2(b) says modelled values are not rounded; this function and :func:naaqs_compliance_report compare the unrounded value with 150.

calm_and_missing_hours

calm_and_missing_hours(sfc_file: Union[str, Path]) -> list[str]

YYMMDDHH stamps of the hours AERMOD computes nothing for.

Read from the AERMET surface file as AERMOD reads it: a calm hour has a reference wind speed of exactly 0 (CHKCLM in metext.f) and a missing hour fails one of the checks of CHKMSG. For such an hour AERMOD does not call CALC and adds no background (HRLOOP in aermod.f), yet POSTFL still writes the hour to a 1-HR POSTFILE, as a row of 0.0 for every receptor with no flag. Pass the result to :func:o3_8hr_design_value so that those zeros are not averaged as concentrations.

NOTE: an hour with a mixing height of zero or less (AERMOD message 470) is also written as zero but counts as a valid hour in AERMOD's own averages, so it is not listed.

o3_8hr_design_value

o3_8hr_design_value(df: DataFrame, *, n_years: int = 3, year_start: YearStart = None, calm_missing: Optional[Iterable] = None) -> pd.DataFrame

O3 8-hour design value: 3-year avg of annual 4th-highest daily max 8-hour average concentration.

Per 40 CFR 50.19 and Appendix U. Standard: 70 ppb. The years are met years (year_start, see :func:nth_highest_daily_max_design_value).

Give it 1-hour values (AVE='1-HR'). The daily maximum is then formed as Appendix U 3(b)-(d) forms it: the running 8-hour mean is computed for every hour and kept at its first hour; a mean is valid with at least 6 of its 8 hours, divided by the hours present; the day's value is the highest of the 17 means starting from 07:00 to 23:00, the last running to 07:00 the next day; and a day is valid with at least 13 of the 17, or with a value above the level. The stamps are read as AERMOD writes them, the hour ending at HH in local standard time, so the mean starting at 07:00 covers the rows stamped 08 to 15. AERMOD stamps a row with the date and hour of the surface file record, unchanged (KURDAT in metext.f), hours 1 to 24 with hour 24 the last of its day, so the stamps are in the time the meteorology is in; AERMET writes hour-ending local standard time. A day belongs to the year its first hour falls in. The first seven hours of a record belong to no day in it, and its last day has only 12 of its 17 means (those starting 07:00 to 18:00), so that day is left out unless it is above the level.

Calm and missing hours. AERMOD computes nothing for a calm or missing hour and adds no background to it, but still writes it to a 1-HR POSTFILE as 0.0 with no flag (HRLOOP and POSTFL). Read as concentrations, those zeros lower every running mean they fall in. Pass the hours as calm_missing (YYMMDDHH stamps; :func:calm_and_missing_hours reads them from the surface file) and each mean leaves them out and divides by the hours that remain, or by 6 if fewer remain. That is the divisor of AERMOD's own 8-hour average (AVER in calc2.f), and with six or more hours it is also Appendix U's. Without calm_missing every row counts as an hour of data and a warning says so. Hours with no row at all, or NaN, follow the Appendix U validity rules above.

The "above the level" tests take the concentrations to be in µg/m³, AERMOD's default for concentration (EMIFAC = 1.0D06, MICROGRAMS/M**3 in coset.f), and compare them with 70 ppb converted at 25 °C. A POSTFILE does not name its units, so a run with EMISUNIT or CONCUNIT must be converted first.

AERMOD's own 8-hour averages (AVE='8-HR') are still read, with a warning. AERMOD forms an N-HR average only at the hours that are multiples of N (MOD(IHOUR, KAVE) == 0 in aermod.f), so an 8-HR POSTFILE holds three fixed blocks per day (ending at hours 8, 16 and 24) and no running means. The highest of three blocks is never above the highest running mean, so that value can understate the Appendix U one.

NOTE: the completeness test of Appendix U 4(b) (90 % of the days of the ozone season) and the truncation to 0.001 ppm (3(e)) are for monitored data and are not applied; Appendix W 9.2.2(b) says modelled values are not rounded.

Raises:

Type Description
ValueError

If the frame mixes 1-HR rows with another averaging period.

read_maxdaily

read_maxdaily(path: Union[str, Path]) -> pd.DataFrame

Read an AERMOD OU MAXDAILY file.

The file holds every day's maximum 1-hour value (24-hour value for PM2.5) at every receptor, which is exactly the daily series the NAAQS percentile forms rank. The frame has the POSTFILE columns (x, y, concentration, ave, grp, date in YYMMDDHH) plus zelev, zhill, zflag, jday, hr and netid, so it feeds :func:no2_1hr_design_value, :func:so2_1hr_design_value and :func:pm25_24hr_design_value directly.

read_mxdybyyr

read_mxdybyyr(path: Union[str, Path]) -> pd.DataFrame

Read an AERMOD OU MXDYBYYR file.

One row per receptor, year and rank: the ranked daily maxima AERMOD itself computed (rank 1 is that year's highest daily value). The date column carries the day the ranked value occurred.

mxdybyyr_design_value

mxdybyyr_design_value(df: DataFrame, rank: int) -> pd.DataFrame

Design value from AERMOD's own ranked daily maxima.

Averages the rank-th ranked value across the years in an MXDYBYYR frame (:func:read_mxdybyyr), receptor by receptor: the same SUMHNH / NUMYRS form AERMOD prints, and the cross-check for :func:no2_1hr_design_value / :func:so2_1hr_design_value computed from the MAXDAILY series.

AERMOD writes one rank-rank row per receptor for each of its met years, so the year count is the number of those rows at a receptor, not the number of calendar years their dates fall in (a July-to-June year can put its ranked days in two calendar years). The function needs no year_start: AERMOD has already grouped the years.

naaqs_output_pathway

naaqs_output_pathway(pollutant: str, *, source_group: str = 'ALL', stem: str = 'design', threshold: Optional[float] = None, receptor_table_rank: Optional[int] = None) -> OutputPathway

An :class:~pyaermod.pathways.OutputPathway for a NAAQS design value.

Requests the three AERMOD outputs the 1-hour NO2/SO2 and 24-hour PM2.5 design-value workflow needs, with the rank taken from the NAAQS table rather than typed by hand:

  • MAXDAILY (<stem>_maxdaily.dat): the daily series, for :func:read_maxdaily and the design-value functions;
  • MXDYBYYR (<stem>_mxdybyyr.dat): AERMOD's ranked values, for :func:mxdybyyr_design_value as a cross-check;
  • MAXDCONT (<stem>_maxdcont.dat): source-group contributions at the design rank, or from the design rank down to threshold when one is given (the THRESH form).

receptor_table_rank defaults to the design rank, or to the smallest range AERMOD accepts for the THRESH form (design rank plus five, ouset.f E273). The control pathway must select the matching processing: POLLUTID NO2/SO2 with AVERTIME 1, or PM25 with AVERTIME 24; :class:pyaermod.validator.Validator checks that.

naaqs_compliance_report

naaqs_compliance_report(pollutant: str, df: DataFrame, *, background: Optional[Union[float, dict, Series]] = None, n_years: int = 3, no2_annual: str = 'highest_year', year_start: YearStart = None, calm_missing: Optional[Iterable] = None) -> pd.DataFrame

One-stop compliance roll-up: design value + NAAQS comparison.

Dispatches to the right design-value function for pollutant, optionally adds background, joins the NAAQS row, and flags receptors that exceed.

Returns a DataFrame with columns:

  • x, y: receptor coords
  • design_value: numeric DV
  • naaqs_level, units, cfr_reference: the standard as 40 CFR 50 sets it (ppb for SO2, NO2 and O3)
  • naaqs_level_ugm3: the level in µg/m³, the unit AERMOD reports
  • exceeds: bool, design_value > naaqs_level_ugm3

The design value is in AERMOD's µg/m³, so exceeds compares it with the level converted to µg/m³ (75 ppb of SO2 is 196.4 µg/m³), never with a level in ppb. Modelled values are compared unrounded, as Appendix W (40 CFR 51) 9.2.2(b) says modelled concentrations should not be rounded; the rounding and truncation conventions of the Part 50 appendices (N, S, T, U, K) apply to monitored design values.

Supported pollutants: PM2.5 (24-hour), PM10, NO2 (1-hour), SO2 (1-hour), O3 (from 1-hour values, see :func:o3_8hr_design_value), plus annual forms via pollutant="PM2.5_annual", "NO2_annual" and "SO2_annual". The last is the secondary SO2 standard (40 CFR 50.21, 10 ppb): the average of the annual means, formed as the annual PM2.5 value is.

Years are met years: year_start (default None, read from the first date in the data; "calendar"; or a (month, day) pair) is passed to the design-value function, as described in :func:nth_highest_daily_max_design_value. Where Part 50 speaks of a calendar year the modelled met year stands in for it; data starting on 1 January give calendar years either way.

Hourly (1-HR) input to a form built from means (PM2.5, PM10, PM2.5_annual, NO2_annual, SO2_annual) warns once that the means divide by the number of rows (:func:pyaermod.postfile.warn_hourly_mean_limitation).

The annual PM2.5 form is the average of the annual means (40 CFR 50.20(a)-(b), Appendix N). NOTE: Appendix N 4.4 forms each year's mean as the mean of its calendar quarters' means; this report averages every row of the year (see :func:annual_mean). The annual NO2 standard is a single calendar year's mean (40 CFR 50.11(a), (e); Appendix S), so with several years of data no2_annual="highest_year" (the default) takes the highest year's mean at each receptor. Only years with data on at least 75% of their hours count (Appendix S 3.1(b) treats an annual mean as valid from 75% coverage), so a few days of a following year cannot set the design value; the years left out are named in a :class:UserWarning. The frame must hold one averaging period (one ave value). Coverage is counted in hours for 1-HR (and other sub-daily block) values, so two hours a day is not a complete year; a 24-HR POSTFILE (or one without an ave column) counts days, a MONTH POSTFILE counts months, and a PERIOD mean, which covers the whole run rather than one calendar year, is used as it is with a warning. An ANNUAL value is used only when it covers one year: over several years (AERMOD writes NUMYRS where the date would be) it is the average of the years' means, a lower bound on the design value, so it raises :class:ValueError, as does an ANNUAL value whose number of years cannot be read. If no year at a receptor reaches 75% (a record of a few months, say), the design value there is the mean over its whole record and a warning says so. no2_annual="multi_year_mean" averages the years instead, which some reviewing agencies accept for five years of NWS met data; it can be below the highest year, and it averages every year present, complete or not. It too needs one averaging period. An ANNUAL value, which over several years is already the average of the years' means, is that mean as it is, whatever its number of years; a PERIOD mean is used as it is, with the same warning as above.

calm_missing (YYMMDDHH stamps, see :func:calm_and_missing_hours) is used by the O3 form only: those hours are left out of the running 8-hour means (:func:o3_8hr_design_value). A background is added to every row, calm and missing hours included, where AERMOD's own BACKGRND adds none to them.

background is added before the design value is formed. A date-keyed background (dict or Series) cannot be matched to ANNUAL or PERIOD values, whose date field is not an hour, so it raises :class:ValueError there; pass a single number instead.