Introduction
Meteorological inputs—temperature, precipitation, and barometric pressure—are essential for computing dissolved oxygen saturation and gas exchange in stream metabolism models. This vignette shows how to find NOAA daily-summary stations near Kings Creek at Konza Prairie Biological Station, Kansas, and download the weather data needed to accompany the built-in kings_discharge dataset (water year 2025: 2024-10-01 through 2025-09-30).
preMetabolizer provides three helpers for station discovery:
-
get_noaa_stations()searches for GHCND stations via the NCEI Search Service API. -
closest_noaa_stations()finds stations within a distance of a target coordinate and ranks them by geodesic distance. -
ncei_stations()is the lower-level function underlying both helpers; it can search any NCEI dataset.
Note: All functions in this vignette contact the NCEI API. Set
PREMETABOLIZER_RUN_VIGNETTES=trueto run the API chunks; they are skipped by default during package installation and checks.
Study site
Kings Creek drains the Konza Prairie Biological Station near Manhattan, Kansas (39.1069°N, 96.6117°W). The USGS monitoring location USGS-06879650 records daily discharge, gage height, and water temperature throughout water year 2025.
lat_kings <- 39.1068806
lon_kings <- -96.6117151
wy_start <- "2024-10-01"
wy_end <- "2025-09-30"Search for stations
Use ncei_bbox() to build a bounding box from a center point and radius, then pass it to get_noaa_stations():
bbox <- ncei_bbox(latitude = lat_kings, longitude = lon_kings, dist_km = 100)
bbox
ks_stations <- get_noaa_stations(bbox = bbox)
glimpse(ks_stations)Filter to stations that carry the variables you need and span at least part of water year 2025:
wx_stations <- get_noaa_stations(
bbox = bbox,
data_types = c("TMAX", "TMIN", "PRCP"),
start_date = wy_start,
end_date = wy_end
)
wx_stations |>
select(station_id, station_name, latitude, longitude, start_date, end_date) |>
arrange(station_name)Find nearby stations
closest_noaa_stations() builds the bounding box automatically and returns stations sorted by geodesic distance from the target point:
konza_noaa <- closest_noaa_stations(
latitude = lat_kings,
longitude = lon_kings,
dist_km = 50,
data_types = c("TMAX", "TMIN", "PRCP"),
start_date = wy_start,
end_date = wy_end
)
konza_noaa |>
select(distance_km, station_id, station_name, latitude, longitude)Map the candidates before choosing a station:
ggplot(konza_noaa, aes(longitude, latitude)) +
geom_point(aes(size = distance_km), color = "#2c7fb8") +
annotate("point", x = lon_kings, y = lat_kings, color = "#d95f0e", size = 3) +
coord_quickmap() +
labs(
x = "Longitude",
y = "Latitude",
size = "Distance (km)",
title = "NOAA stations near Kings Creek"
) +
theme_bw()Download daily weather data
Pick the nearest station and download daily temperature and precipitation for water year 2025 with ncei_data():
With units = "metric" (the default), ncei_data() returns tmax and tmin in °C and prcp in mm. The date column is already a Date:
Barometric pressure and PAR
GHCND covers temperature and precipitation well, but barometric pressure records are sparse in this region. For pressure and photosynthetically active radiation (PAR), use get_nasa_data() to pull modeled values from NASA POWER, or get_ghcnh() to download observed hourly pressure from the GHCNh archive.
stream_data <- tibble(
dateTime = seq(
as.POSIXct(paste(wy_start, "00:00:00"), tz = "UTC"),
as.POSIXct(paste(wy_end, "23:00:00"), tz = "UTC"),
by = "1 hour"
)
)
nasa_wx <- get_nasa_data(
data = stream_data,
latitude = lat_kings,
longitude = lon_kings,
elev_m = 320
)
glimpse(nasa_wx)The PSC column contains elevation-corrected barometric pressure (kPa), light.obs contains PAR (µmol/m²/s), T2M air temperature (°C), and PRECTOTCORR precipitation (mm/hr).
Use station IDs with GHCNh data
The station_id values returned by closest_noaa_stations() also identify GHCNh files. Pass them directly to get_ghcnh():
station_idSee vignette("ghcnh", package = "preMetabolizer") for a full hourly-data workflow.