geospatial¶
geospatial ¶
PyAERMOD Geospatial Utilities
Coordinate transformations (UTM <-> WGS84), GeoDataFrame creation, contour polygon generation, and GIS export (GeoTIFF, Shapefile, GeoPackage).
Requires optional dependencies: pyproj, geopandas, rasterio, shapely. Install with: pip install pyaermod[geo]
CoordinateTransformer
dataclass
¶
Bidirectional UTM <-> WGS84 coordinate transformer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
utm_zone
|
int
|
UTM zone number (1-60). |
required |
hemisphere
|
str
|
'N' or 'S' for northern/southern hemisphere. Default 'N'. |
'N'
|
datum
|
str
|
Datum string: 'WGS84', 'NAD83', or 'NAD27'. Default 'WGS84'. |
'WGS84'
|
from_aermap_domain
classmethod
¶
Create transformer from an AERMAPDomain object.
Reads utm_zone and datum from the domain. Hemisphere is
inferred as 'N' (AERMOD is predominantly used in the northern
hemisphere); override after creation if needed.
from_latlon
classmethod
¶
Auto-detect UTM zone from a lat/lon point.
utm_to_latlon ¶
Convert UTM easting/northing to (latitude, longitude).
latlon_to_utm ¶
Convert (latitude, longitude) to UTM (easting, northing).
transform_dataframe ¶
transform_dataframe(df: DataFrame, x_col: str = 'x', y_col: str = 'y', to_latlon: bool = True) -> pd.DataFrame
Add transformed coordinate columns to a DataFrame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Input DataFrame. |
required |
x_col
|
str
|
Column names for existing coordinates. |
'x'
|
y_col
|
str
|
Column names for existing coordinates. |
'x'
|
to_latlon
|
bool
|
If True (default), adds |
True
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Copy of df with new columns appended. |
GeoDataFrameFactory ¶
Create GeoDataFrames from pyaermod objects.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
transformer
|
CoordinateTransformer
|
Coordinate transformer for CRS assignment. |
required |
sources_to_geodataframe ¶
Convert a list of source objects to a GeoDataFrame.
Returns Point geometries for point and volume sources, Polygon
geometries for AREA, AREACIRC, AREAPOLY and OPENPIT sources,
LineString geometries for line and roadway sources and
MultiLineString for buoyant lines of several segments. The
outlines are the ones AERMOD builds (:mod:pyaermod.footprints):
an AREA or OPENPIT LOCATION is its south-west corner and the
rectangle is rotated clockwise about it.
sources_from_results ¶
Convert parsed AERMODResults source summaries to a GeoDataFrame.
receptors_to_geodataframe ¶
Convert a ReceptorPathway to a GeoDataFrame of receptor points.
Expands CartesianGrid and PolarGrid definitions into individual
receptor locations. A polar grid is centred on its
origin_source_id source when that source is in sources
(the LOCATION of GRIDPOLR ORIG srcid), otherwise on
x_origin/y_origin.
concentrations_to_geodataframe ¶
concentrations_to_geodataframe(df: DataFrame, value_col: str = 'concentration', x_col: str = 'x', y_col: str = 'y') -> gpd.GeoDataFrame
Convert a concentration DataFrame to a GeoDataFrame with Point geometries.
postfile_to_geodataframe ¶
Convert a PostfileResult to a GeoDataFrame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
PostfileResult
|
Parsed POSTFILE data. |
required |
timestep
|
str
|
If given, filter to this YYMMDDHH date string. |
None
|
ContourGenerator ¶
Generate contour polygons from concentration data.
Uses scipy.griddata interpolation and matplotlib contourf to compute filled contour paths, then converts them to Shapely Polygons.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
transformer
|
CoordinateTransformer
|
For CRS assignment on output GeoDataFrames. |
required |
generate_contours ¶
generate_contours(df: DataFrame, levels: Optional[List[float]] = None, n_levels: int = 10, method: str = 'cubic', grid_resolution: int = 200, x_col: str = 'x', y_col: str = 'y', value_col: str = 'concentration') -> gpd.GeoDataFrame
Generate filled contour polygons as a GeoDataFrame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Must contain x_col, y_col, and value_col columns. |
required |
levels
|
list of float
|
Explicit contour levels. If None, n_levels equally-spaced levels are computed from the data range. |
None
|
n_levels
|
int
|
Number of auto-computed levels when levels is None. |
10
|
method
|
str
|
Interpolation method for |
'cubic'
|
grid_resolution
|
int
|
Number of cells in each direction for the interpolation grid. |
200
|
x_col
|
str
|
Column names. |
'x'
|
y_col
|
str
|
Column names. |
'x'
|
value_col
|
str
|
Column names. |
'x'
|
Returns:
| Type | Description |
|---|---|
GeoDataFrame
|
Columns: |
generate_contours_latlon ¶
Same as generate_contours but reprojected to WGS84 (EPSG:4326).
RasterExporter ¶
Export concentration data as georeferenced GeoTIFF rasters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
transformer
|
CoordinateTransformer
|
Provides the CRS for the output raster. |
required |
export_geotiff ¶
export_geotiff(df: DataFrame, output_path: Union[str, Path], resolution: Optional[float] = None, method: str = 'cubic', nodata: float = -9999.0, x_col: str = 'x', y_col: str = 'y', value_col: str = 'concentration') -> Path
Export a concentration DataFrame as a single-band GeoTIFF.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Must have x_col, y_col, and value_col columns. |
required |
output_path
|
str or Path
|
Destination |
required |
resolution
|
float
|
Pixel size in meters. If None, auto-detected from data spacing. The receptors are the pixel centres, so a 100 m grid gives 100 m pixels whose edges lie 50 m beyond the outer receptors. |
None
|
method
|
str
|
Interpolation method for |
'cubic'
|
nodata
|
float
|
NoData value written to the raster. |
-9999.0
|
Returns:
| Type | Description |
|---|---|
Path
|
The written file path. |
VectorExporter ¶
Export pyaermod data as vector GIS files (Shapefile, GeoPackage, GeoJSON).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
factory
|
GeoDataFrameFactory
|
For creating GeoDataFrames from pyaermod objects. |
required |
export_sources ¶
Export source objects as one vector file.
A shapefile holds one geometry type, so driver='ESRI Shapefile'
raises ValueError for sources that mix points, lines and
polygons: use :meth:export_sources_by_kind for one shapefile per
kind. GeoPackage and GeoJSON hold them together.
export_sources_by_kind ¶
export_sources_by_kind(sources: list, output_path: Union[str, Path], driver: str = 'ESRI Shapefile') -> Dict[str, Path]
Export source objects as one vector file per geometry kind.
For formats that hold one geometry type per file, which is to say
shapefiles. output_path gives the folder, stem and extension:
out/sources.shp writes out/sources_point.shp (stacks, volume
sources), out/sources_line.shp (line and buoyant-line sources)
and out/sources_polygon.shp (area, circular-area, polygon-area
and open-pit sources), leaving out a kind that has no source. The
files share their columns and coordinate system.
Returns the paths written, keyed "point", "line" and
"polygon".
export_receptors ¶
export_receptors(receptors, output_path: Union[str, Path], driver: str = 'GPKG', sources=()) -> Path
Export receptor locations as a point vector file.
sources places a polar grid centred on a source (see
:meth:GeoDataFrameFactory.receptors_to_geodataframe).
export_concentrations ¶
export_concentrations(df: DataFrame, output_path: Union[str, Path], driver: str = 'GPKG', as_contours: bool = False, contour_levels: Optional[List[float]] = None) -> Path
Export concentration data as points or contour polygons.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Concentration DataFrame with x, y, concentration columns. |
required |
output_path
|
str or Path
|
Output file path. |
required |
driver
|
str
|
OGR driver name ( |
'GPKG'
|
as_contours
|
bool
|
If True, generate filled contour polygons instead of points. |
False
|
contour_levels
|
list of float
|
Contour levels (only used when |
None
|
export_all ¶
export_all(project, results=None, output_dir: Union[str, Path] = '.', driver: str = 'GPKG') -> Dict[str, Path]
Export all project components to a directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
project
|
AERMODProject
|
The project to export. |
required |
results
|
AERMODResults
|
Parsed results (required for concentration export). |
None
|
output_dir
|
str or Path
|
Output directory. |
'.'
|
driver
|
str
|
OGR driver. With |
'GPKG'
|
Returns:
| Type | Description |
|---|---|
dict
|
Mapping of component name to output file path: |
utm_to_latlon ¶
utm_to_latlon(x: float, y: float, utm_zone: int, hemisphere: str = 'N', datum: str = 'WGS84') -> Tuple[float, float]
Quick single-point UTM to (latitude, longitude) conversion.
latlon_to_utm ¶
Quick single-point (lat, lon) to UTM conversion.
Returns:
| Type | Description |
|---|---|
tuple
|
|
export_concentration_geotiff ¶
export_concentration_geotiff(df: DataFrame, output_path: Union[str, Path], utm_zone: int, hemisphere: str = 'N', datum: str = 'WGS84', **kwargs) -> Path
One-liner GeoTIFF export from a concentration DataFrame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Must have |
required |
output_path
|
str or Path
|
Destination |
required |
utm_zone
|
int
|
UTM zone number. |
required |
**kwargs
|
Passed to |
{}
|
Returns:
| Type | Description |
|---|---|
Path
|
Written file path. |
export_concentration_shapefile ¶
export_concentration_shapefile(df: DataFrame, output_path: Union[str, Path], utm_zone: int, hemisphere: str = 'N', datum: str = 'WGS84', as_contours: bool = True, driver: str = 'GPKG', **kwargs) -> Path
One-liner vector export from a concentration DataFrame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Must have |
required |
output_path
|
str or Path
|
Destination file. |
required |
utm_zone
|
int
|
UTM zone number. |
required |
as_contours
|
bool
|
If True, export filled contour polygons; if False, export points. |
True
|
driver
|
str
|
OGR driver name (default |
'GPKG'
|
Returns:
| Type | Description |
|---|---|
Path
|
Written file path. |