Add external variables to WRF input files (wrfinput)
Project description
wrfaddvar
Add external variables to WRF input files (wrfinput).
Installation
Basic install (bilinear / nearest interpolation only)
pip install wrfaddvar
[!WARNING] Conservative remapping (
--method conservative) requiresxesmf, which cannot be installed via pip alone — the underlying ESMF Fortran library must come from conda-forge. If you use conservative interpolation without installing these packages, you will see a red error and a yellow hint in the terminal telling you exactly what to run.
Full install with conservative remapping support
conda install -c conda-forge esmf esmpy xesmf
pip install wrfaddvar
[!NOTE]
wrfaddaheuses conservative remapping by default (--method conservative). Install the conda packages above if you want to use this command without switching to--method bilinear.
Commands
wrfaddvar — general-purpose
wrfaddvar --varname VARNAME [OPTIONS] SOURCE_FILE WRFINPUT_FILE
Reads VARNAME from SOURCE_FILE, interpolates it to the WRF grid, and
writes it into WRFINPUT_FILE.
Supported source formats (auto-detected from extension):
| Extension | Format |
|---|---|
.nc / .nc4 |
NetCDF — variable + lat/lon coordinates |
.csv |
CSV — columns lat, lon, <varname> |
.tif / .tiff |
GeoTIFF (requires rasterio) |
Options
| Flag | Default | Description |
|---|---|---|
--varname |
(required) | Variable name to write into wrfinput |
--source-varname |
same as --varname |
Variable name inside SOURCE_FILE |
--method |
bilinear |
Interpolation method: bilinear, conservative, or nearest |
--output / -o |
(in-place) | Write to a new file instead of modifying wrfinput |
Examples
# Add AHE from a GeoTIFF (bilinear by default)
wrfaddvar --varname AHE emissions.tif wrfinput.d01
# Add ERA5 2-m temperature (t2m) as T2_OBS, write to a new file
wrfaddvar --varname T2_OBS --source-varname t2m era5.nc wrfinput.d01 -o wrfinput.d01.new
# Nearest-neighbour interpolation from a CSV point dataset
wrfaddvar --varname NDVI --method nearest ndvi_stations.csv wrfinput.d01
wrfaddahe — anthropogenic heat emissions shortcut
wrfaddahe [OPTIONS] TIF_FILE WRFINPUT_FILE
Convenience wrapper that reads a GeoTIFF band and writes an AHE variable
with WRF-compatible attributes (units = "W m-2", FieldType = 104, etc.).
Conservative remapping is used by default, which preserves the spatial
integral of the flux field.
wrfaddahe Options
| Flag | Default | Description |
|---|---|---|
--band |
1 |
GeoTIFF band number |
--varname |
AHE |
Variable name in wrfinput |
--method |
conservative |
Interpolation method |
--output / -o |
(in-place) | Write to a new file |
wrfaddahe Examples
# Annual mean AHE (conservative remapping)
wrfaddahe ahe_2020.tif wrfinput.d01
# July (band 7), save to a new file
wrfaddahe --band 7 --output wrfinput.d01.ahe monthly_ahe.tif wrfinput.d01
Python API
from wrfaddvar import read_geotiff, to_wrf_grid, write_to_wrfinput
import netCDF4 as nc
import numpy as np
src = read_geotiff("ahe_2020.tif", band=1)
with nc.Dataset("wrfinput.d01") as ds:
wrf_lats = np.array(ds.variables["XLAT"][0])
wrf_lons = np.array(ds.variables["XLONG"][0])
data_on_wrf = to_wrf_grid(src, wrf_lats, wrf_lons, method="conservative")
write_to_wrfinput("wrfinput.d01", "AHE", data_on_wrf,
attrs={"units": "W m-2", "description": "ANTHROPOGENIC HEAT FLUX"})
Publishing
pip install build twine
python -m build
twine upload dist/*
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file wrfaddvar-0.1.0.tar.gz.
File metadata
- Download URL: wrfaddvar-0.1.0.tar.gz
- Upload date:
- Size: 92.8 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d65f5fb1333ff4517321d8a1968a2bdb47290eed68956d1ef79760228144a8fe
|
|
| MD5 |
7f6f7b1799179dbe3529a23d81b16146
|
|
| BLAKE2b-256 |
3b6d0ebb9570f8554a08cfdcf8d135d670558b020826e418ed715586cc9bf2b6
|
File details
Details for the file wrfaddvar-0.1.0-py3-none-any.whl.
File metadata
- Download URL: wrfaddvar-0.1.0-py3-none-any.whl
- Upload date:
- Size: 13.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0ce9de8d7f2b8451d7e7e19d967e7fa38952a5c3d0820101f753de608772c1ff
|
|
| MD5 |
ff02fc0a3738b2c522a8b77e3e228d68
|
|
| BLAKE2b-256 |
36111f4160135c0073bfd7b3bf3230a573bee76b513c39170456fae604ff277f
|