aermet¶
aermet ¶
PyAERMOD AERMET Input Generator and Output Parser
Writes AERMET runstream (control) files and parses the AERMET output files AERMOD reads (.SFC surface and .PFL profile).
AERMET is EPA's meteorological preprocessor for AERMOD. Since version 11 (and in the current releases, 24142 and 26135) it runs in two stages:
- Stage 1 reads the raw upper-air, surface and on-site data
(
DATA), writes what it read (EXTRACT) and the quality-assured data (QAOUT). :class:AERMETStage1writes this deck. - Stage 2 reads the Stage 1
QAOUTfiles, merges them itself and computes the boundary-layer parameters on theMETPREPpathway, writing the.SFC(OUTPUT) and.PFL(PROFILE) files. :class:AERMETStage3writes this deck.
The separate merge stage of AERMET 06341 and earlier (the MERGE
pathway) no longer exists: AERMET ignores that pathway with warning W01.
:class:AERMETStage2 is kept only so old code still imports; it is
deprecated and writes no deck. Stage3 keeps its name, and the
stage3.inp deck name, so existing pipelines keep their file names.
The keyword syntax follows the AERMET Fortran (mod_read_input.f90,
mod_upperair.f90, mod_surface.f90, mod_onsite.f90,
mod_pbl.f90 and getloc in mod_main1.f90 of v24142 and
v26135). The rules the writers rely on are noted where they are used.
AERMETStation
dataclass
¶
Surface meteorological station information.
time_zone is the UTC offset in hours, negative west of Greenwich
(-5 for Eastern Standard Time). AERMET wants the opposite sign
(hours to subtract from GMT), and only for data recorded in GMT; the
writers convert it (see :class:AERMETStage1).
station_id is the station's WBAN number (13874 for Atlanta
Hartsfield, not the ICAO code KATL) when the station is Stage 1's
SURFACE station: METPREP reads that ID back as an integer and stops on
anything else. AERMET keeps at most 8 characters of any station ID.
UpperAirStation
dataclass
¶
Upper air (radiosonde) station information.
AERMET 24142 and later stop with error E05 when the UPPERAIR LOCATION
has no station elevation (upper_path in mod_upperair.f90), so
elevation (metres) is needed to write a Stage 1 deck. time_zone
is the UTC offset as on :class:AERMETStation; when it is None the
surface station's is used.
OnsiteData
dataclass
¶
Site-specific (ONSITE pathway) measurements for Stage 1.
AERMET reads on-site data with a Fortran format the user supplies:
each READ n record lists the variable names in the order they
appear on the n-th line of an observation, and FORMAT n gives the
Fortran format for that line. read_records[i] and
format_records[i] are record i + 1. Variable names are
AERMET's (OSYR OSMO OSDY OSHR, HT01, WS01, WD01,
SA01, TT01, ...; see the AERMET user's guide).
time_adjustment is written as LOCATION's GMT-to-LST field. On-site
data are normally recorded in local standard time, for which it is 0
(every EPA test case uses 0).
threshold (m/s) is the THRESHOLD keyword, which AERMET requires
when a wind speed is read (os_test in mod_onsite.f90).
to_lines ¶
The ONSITE pathway of a Stage 1 deck.
AERMETStage1
dataclass
¶
AERMET Stage 1: extract and quality-assure the observations.
Writes the UPPERAIR, SURFACE and (optionally) ONSITE pathways, each
with DATA, EXTRACT (not ONSITE, which has none), QAOUT, XDATES and
LOCATION. The QAOUT files are what :class:AERMETStage3 reads.
File names: output_file is the REPORT file, message_file the
MESSAGES file, extract_file and qa_file the surface EXTRACT
and QAOUT files. The upper-air EXTRACT and QAOUT default to the same
names with _ua added (stage1_ua.ext, stage1_ua.qa).
Time adjustment (LOCATION's fourth field): AERMET subtracts it from
every observation's hour, so it is -time_zone for data in GMT and
0 for data in local standard time. The writer derives it from the data
format (upper-air data and ISHD are GMT; CD144, CD144FB, SAMSON and
HUSWO are LST). For SCRAM and GHCN surface data, set
surface_time_adjustment; it always overrides the derived value, as
upper_air_time_adjustment does for upper air.
AERMETStage2
dataclass
¶
Deprecated: the separate AERMET merge stage no longer exists.
AERMET 11 and later merge the data inside the METPREP stage, which
:class:AERMETStage3 writes; AERMET ignores a MERGE pathway with
warning W01. The class stays importable so existing code keeps
running; :func:pyaermod.aermet_runner.run_aermet_pipeline skips it
and :meth:to_aermet_input raises.
to_aermet_input ¶
Raise: there is no merge-stage deck AERMET 11 or later would run.
AERMETStage3
dataclass
¶
AERMET Stage 2 (METPREP): merge the Stage 1 data and compute the
boundary-layer parameters, writing AERMOD's .SFC and .PFL.
(pyaermod calls this Stage3 for backward compatibility; AERMET
calls it stage 2.)
Inputs: the Stage 1 QAOUT files on the UPPERAIR, SURFACE and ONSITE
pathways (upper_air_qaout, surface_qaout, onsite_qaout).
When all three are None the deck names Stage 1's default upper-air and
surface QAOUT files; :meth:with_inputs_from copies the names from an
:class:AERMETStage1, and the pipeline does so automatically.
Surface characteristics, in order of precedence:
aersurf_file: an AERSURFACE output file (AERSURF keyword);site_char: SITE_CHAR records, each a string"f s albedo bowen z0"or a tuple(f, s, albedo, bowen, z0), withfrequency(ANNUAL, SEASONAL or MONTHLY; default ANNUAL),num_sectorsandsectors((start, end)degrees per sector; default one 0-360 sector);- otherwise the 12 monthly
albedo,bowenandroughnessvalues for one 0-360 sector: FREQ_SECT ANNUAL when all months are equal, MONTHLY otherwise.
methods are METHOD records such as ("REFLEVEL", "SUBNWS") or
("WIND_DIR", "RANDOM"). nws_height is the NWS anemometer
height (NWS_HGT WIND); it defaults to station.anemometer_height.
A deck with NWS surface data and no on-site data always gets
METHOD REFLEVEL SUBNWS (added when methods has no REFLEVEL
record): AERMET 26135 stops with E87 without it (mod_pbl.f90,
A097_SUBNWS), as the AERMET user's guide says it should. SUBNWS with
SURFACE data needs NWS_HGT (E72 otherwise), so such a deck raises
ValueError when neither nws_height nor station is set.
extra_lines are written verbatim at the end of METPREP.
merge_file is kept for compatibility and ignored: METPREP's DATA
keyword is obsolete (mod_read_input.f90 ignores it).
with_inputs_from ¶
A copy reading stage1's QAOUT files, unless this deck names its own.
Only the pathways Stage 1 processes are named, so a run without upper air does not point METPREP at an upper-air file that does not exist.
SurfaceFileHeader
dataclass
¶
Parsed header from an AERMET .SFC surface file.
ProfileFileHeader
dataclass
¶
Metadata for a .PFL file (no header line — metadata inferred from data).
SurfaceFilePeriod
dataclass
¶
The hours of met data an AERMET .SFC file holds.
Read by :func:read_surface_period. Times are the start of the first
hour and the end of the last one, so a file of the 96 hours of 1 to 4
March 1988 has first = 1988-03-01 00:00 and last = 1988-03-05
00:00. AERMET's hour 24 is the hour that ends at midnight.
Attributes:
| Name | Type | Description |
|---|---|---|
first, last |
The start of the first hour and the end of the last hour of data. |
|
hours |
int
|
The number of hourly records in the file. |
days |
int
|
The number of distinct days with at least one hour of data; AERMOD prints one "Now Processing Data For Day No." line for each. |
surface_station, upper_air_station |
The station IDs from the file's header ( |
complete_years
property
¶
How many years of data AERMOD counts in a run over the whole file.
This is AERMOD's NUMYRS at the end of such a run: the number of
times the data reach the end of a year, which is the hour before the
first hour, one year on (see the comment above this class). ANNUAL
averages need at least one; with none AERMOD stops with E480.
Assumes the hours between the first and the last are all present,
as AERMET writes them.
write_aermet_runfile ¶
Create a shell script that runs AERMET on one runstream file.
AERMET reads the runstream named on its command line (or aermet.inp
in the working directory); it does not read standard input. The script
changes to output_path and runs AERMET there, so the REPORT,
MESSAGES and output files land there and the data files the deck
names by relative path are looked up there. Both the deck and
output_path are written into the script as absolute paths,
resolved when the script is written (output_path defaults to the
current directory at that time), so the script behaves the same from
any directory, but only in this checkout.
Args: stage: Stage label for the script's name and messages. input_file: Path to the runstream file. output_path: Directory AERMET runs in.
Raises: ValueError: if the deck's absolute path is longer than the 300 characters AERMET reads for a file name.
parse_sfc_header ¶
Parse the header line of an AERMET .SFC file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
header_line
|
str
|
First line of the .SFC file. |
required |
Returns:
| Type | Description |
|---|---|
SurfaceFileHeader
|
Parsed header metadata. |
read_surface_file ¶
Parse an AERMET .SFC surface meteorology file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filepath
|
str or Path
|
Path to the .SFC file. |
required |
Returns:
| Type | Description |
|---|---|
dict
|
Dictionary with keys:
- |
read_profile_file ¶
Parse an AERMET .PFL profile meteorology file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filepath
|
str or Path
|
Path to the .PFL file. |
required |
Returns:
| Type | Description |
|---|---|
dict
|
Dictionary with keys:
- |
read_surface_period ¶
Read which hours of met data an AERMET .SFC file holds.
Reads the header's station IDs and the date and hour of every data record, without loading the data into a DataFrame, so it is quick even for a five-year file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filepath
|
str or Path
|
Path to the |
required |
Returns:
| Type | Description |
|---|---|
SurfaceFilePeriod
|
|
Raises:
| Type | Description |
|---|---|
OSError
|
If the file cannot be read. |
ValueError
|
If the file holds no data record (a line starting with year, month, day, Julian day and hour). |