A practical lesson in climate thresholds, daily co-occurrence, and interpreting annual variation
A day can be unusually hot, receive very little rain, or satisfy both conditions. These are different statements. To investigate them, we use daily NASA POWER maximum air temperature and corrected precipitation for a gridded point near Multan, Pakistan, from January 1981 through December 2025.
The central question is straightforward: how often do unusually hot and low-rainfall days coincide during April–June, and how much does the answer depend on the definition? This tutorial uses the statistical idea of a fixed reference climatology, classifies the daily records, and summarizes annual variation. It does not equate an individual rainless day with drought.
A compound hot-and-low-rain day here is one whose maximum temperature exceeds the month-specific 1991–2020 ninetieth-percentile threshold and whose daily precipitation is below one millimetre. This is an operational daily indicator, not a soil-water, crop-impact or established drought index.
1. A daily climate record needs careful validation
A daily indicator is only meaningful when temperature and rainfall refer to the same calendar day. Missing or duplicated dates change the denominator; unit mistakes can change the event classification. Our first code section verifies all 16,436 calendar dates, numeric values, and the time coverage. NASA POWER is a gridded product rather than a ground rain-gauge or farm-weather-station measurement.
# Daily maximum temperature and corrected precipitation are paired by date.
input_file <- "01_data/nasa_power_multan_daily_1981_2025.csv"
stopifnot(file.exists(input_file))
weather <- read.csv(input_file, stringsAsFactors = FALSE)
needed <- c("date", "year", "month", "day", "tmax_c", "precip_mm_day")
stopifnot(all(needed %in% names(weather)))
weather$date <- as.Date(weather$date)
stopifnot(!anyNA(weather[, needed]), nrow(weather) == 16436L)
stopifnot(!anyDuplicated(weather$date))
calendar <- seq(as.Date("1981-01-01"), as.Date("2025-12-31"), by = "day")
stopifnot(length(calendar) == nrow(weather))
stopifnot(all(as.numeric(weather$date) == as.numeric(calendar)))
stopifnot(all(weather$year == as.integer(format(weather$date, "%Y"))))
stopifnot(all(weather$month == as.integer(format(weather$date, "%m"))))
stopifnot(all(weather$day == as.integer(format(weather$date, "%d"))))
stopifnot(all(is.finite(weather$tmax_c)),
all(is.finite(weather$precip_mm_day)),
all(weather$precip_mm_day >= 0))
cat("Validated daily rows:", nrow(weather), "\n")Validated daily rows: 16436
The record contains 16,436 consecutive daily pairs from 1981 through 2025. The next step uses a consistent seasonal window rather than mixing a cool winter day with the onset of summer.
2. A reference period gives “unusual heat” its meaning
Heat is defined relative to 1991–2020, a thirty-year reference period, rather than an arbitrary fixed temperature. Separate ninetieth percentiles are calculated for April, May, and June. This preserves the predictable progression of pre-monsoon heat; it also lets a warm April day be judged against April conditions instead of June conditions.
# Compare an April day only with past Aprils, a May day with Mays, etc.
season <- subset(weather, month %in% 4:6)
baseline <- subset(season, year >= 1991 & year <= 2020)
stopifnot(nrow(season) == 4095L, nrow(baseline) == 2730L)
heat_thresholds <- data.frame(
month = 4:6,
heat_p90_c = as.numeric(tapply(baseline$tmax_c, baseline$month,
quantile, probs = 0.90, type = 7))
)
season$heat_p90_c <- heat_thresholds$heat_p90_c[
match(season$month, heat_thresholds$month)
]
print(heat_thresholds) month heat_p90_c
1 4 43.661
2 5 47.541
3 6 48.290
Across the 2,730 baseline seasonal days, the thresholds are approximately 43.66°C in April, 47.54°C in May and 48.29°C in June. A strict greater-than rule is used to avoid classifying values exactly on the cutoff as exceedances. The quantile method is R’s type-seven interpolated sample percentile, and small changes in the reference years or quantile convention can alter individual classifications.
3. Put both conditions on the same date
We compare every maximum temperature with its month-specific cutoff, then flag days with less than one millimetre of corrected precipitation. Only days satisfying both flags form the compound subset. The logical intersection is important: adding the number of hot days to the number of dry days would count the overlap incorrectly.
# Same-day co-occurrence is not the same thing as meteorological drought.
season$hot <- season$tmax_c > season$heat_p90_c
season$low_rain <- season$precip_mm_day < 1
season$compound <- season$hot & season$low_rain
summary_overall <- data.frame(
season_days = nrow(season),
hot_days = sum(season$hot),
low_rain_days = sum(season$low_rain),
compound_days = sum(season$compound),
compound_pct = 100 * mean(season$compound),
pct_hot_also_low_rain = 100 * mean(season$low_rain[season$hot])
)
stopifnot(summary_overall$hot_days == 447L,
summary_overall$compound_days == 443L)
print(summary_overall) season_days hot_days low_rain_days compound_days compound_pct
1 4095 447 3713 443 10.81807
pct_hot_also_low_rain
1 99.10515
monthly <- aggregate(
cbind(hot = as.integer(season$hot),
low_rain = as.integer(season$low_rain),
compound = as.integer(season$compound)),
by = list(month = season$month), FUN = sum
)
monthly$days <- as.integer(table(season$month))
monthly$compound_pct <- 100 * monthly$compound / monthly$days
print(monthly) month hot low_rain compound days compound_pct
1 4 150 1211 149 1350 11.03704
2 5 159 1295 159 1395 11.39785
3 6 138 1207 135 1350 10.00000
The full forty-five-season sample contains 4,095 April–June days: 447 unusually hot days, 3,713 low-rainfall days, and 443 days satisfying both conditions. That is 10.82% of seasonal days. More strikingly, 99.11% of unusually hot days also had rainfall below one millimetre. The widespread low-rain condition means this compound indicator largely follows the heat indicator in these data; that is a substantive finding, not a flaw to conceal.
4. Counts become interpretable when the denominator is fixed
Each April–June season contains ninety-one days. The same denominator allows counts to be expressed as annual percentages and compared over time. We also retain the four unusually hot days that did not meet the low-rainfall rule. Those counterexamples demonstrate that the joint classification is not a tautology.
# All 45 seasons contain 91 days, making annual percentages comparable.
annual <- aggregate(
cbind(hot = as.integer(season$hot),
low_rain = as.integer(season$low_rain),
compound = as.integer(season$compound)),
by = list(year = season$year), FUN = sum
)
annual$days <- as.integer(table(season$year))
annual$compound_pct <- 100 * annual$compound / annual$days
stopifnot(nrow(annual) == 45L, all(annual$days == 91L))
non_dry_hot <- subset(season, hot & !low_rain,
select = c(date, tmax_c, precip_mm_day))
print(head(annual, 5)) year hot low_rain compound days compound_pct
1 1981 31 87 31 91 34.065934
2 1982 2 70 2 91 2.197802
3 1983 5 81 5 91 5.494505
4 1984 15 88 15 91 16.483516
5 1985 6 84 6 91 6.593407
print(non_dry_hot) date tmax_c precip_mm_day
7851 2002-06-30 48.30 2.87
8192 2003-06-06 49.32 2.37
9250 2006-04-29 43.74 1.54
9661 2007-06-14 48.34 1.81
Annual frequencies are far from constant. The record contains 31 compound days in 1981, none in 2023, and 28 in 2025. A high count in one year does not, by itself, diagnose a long-term trend; nor does a quiet year disprove the existence of heat risk. Both the absolute counts and the percentages should be shown so a reader can judge the magnitude.
5. A fitted line is a description, not proof of climate causation
An ordinary least-squares line provides one transparent summary of annual variation. Its slope is measured in percentage points of the ninety-one-day season per decade, not degrees Celsius per decade and not percent relative change. The model is intentionally simple and makes no adjustment for temporal dependence, shifts in data-product characteristics, or possible nonlinearity.
# This OLS line is a descriptive summary, not climate-change attribution.
trend_fit <- lm(compound_pct ~ year, data = annual)
annual$trend_fitted_pct <- predict(trend_fit)
trend_table <- data.frame(
slope_percentage_points_per_decade = 10 * unname(coef(trend_fit)["year"]),
naive_ols_p_value = summary(trend_fit)$coefficients["year", "Pr(>|t|)"],
r_squared = summary(trend_fit)$r.squared
)
print(trend_table) slope_percentage_points_per_decade naive_ols_p_value r_squared
1 -0.9512227 0.2720055 0.0279888
The fitted slope is approximately −0.95 percentage points per decade. The corresponding naive OLS p-value is about 0.27 and its R-squared is only 0.028. The visual conclusion is large year-to-year variation and little explanatory value from a straight line alone. This does not prove that climate risk is decreasing, does not establish a null climate trend, and is not an attribution analysis.
6. Examine sensitivity before treating a definition as natural law
The ninety-fifth percentile defines a more selective hot-day category than the ninetieth percentile. Likewise, the same day’s precipitation could be assessed at several alternative cutoffs. Recomputing the joint count shows which choices drive the reported frequency. Scientific communication is stronger when a conventional threshold is explicitly treated as a choice.
# Test stricter heat definitions and different low-rain cutoffs.
sensitivity <- expand.grid(
heat_quantile = c(0.90, 0.95),
low_rain_cutoff_mm = c(0.1, 0.5, 1, 2)
)
sensitivity$compound_days <- vapply(seq_len(nrow(sensitivity)), function(i) {
threshold <- tapply(baseline$tmax_c, baseline$month, quantile,
probs = sensitivity$heat_quantile[i], type = 7)
hot_i <- season$tmax_c > as.numeric(threshold[as.character(season$month)])
sum(hot_i & season$precip_mm_day < sensitivity$low_rain_cutoff_mm[i])
}, integer(1))
sensitivity$compound_pct <- 100 * sensitivity$compound_days / nrow(season)
print(sensitivity) heat_quantile low_rain_cutoff_mm compound_days compound_pct
1 0.90 0.1 432 10.549451
2 0.95 0.1 223 5.445665
3 0.90 0.5 441 10.769231
4 0.95 0.5 226 5.518926
5 0.90 1.0 443 10.818071
6 0.95 1.0 227 5.543346
7 0.90 2.0 445 10.866911
8 0.95 2.0 227 5.543346
With the ninetieth-percentile heat rule, counts change from 432 for precipitation below 0.1 millimetre to 443 below one millimetre and 445 below two millimetres. Using the ninety-fifth-percentile heat rule with the one-millimetre cutoff yields 227 compound days. This tells us that heat-percentile selection has much more leverage here than modest changes to the low-rain threshold.
7. Four figures expose different parts of the evidence
The calendar heat map places events on their actual seasonal day and year rather than compressing everything into one annual statistic. The annual line chart then shows how strongly frequencies fluctuate. The monthly threshold chart explains why one temperature cutoff would be inappropriate, and the overlap chart makes the near-complete hot-day/low-rain overlap visible.
if (!requireNamespace("ggplot2", quietly = TRUE)) {
stop("Install ggplot2 before running: install.packages('ggplot2')")
}
library(ggplot2)
figure_dir <- "04_outputs/r_figures"
dir.create(figure_dir, recursive = TRUE, showWarnings = FALSE)
season$season_day <- as.integer(season$date - as.Date(
paste0(season$year, "-04-01"))) + 1L
p_calendar <- ggplot(season, aes(season_day, year, fill = compound)) +
geom_tile(height = 0.95, width = 0.95) +
scale_fill_manual(values = c("FALSE" = "#edf2f4", "TRUE" = "#dd6b43"),
labels = c("No event", "Compound event")) +
labs(title = "Hot and low-rain days across 45 seasons",
x = "Day within April–June", y = "Year", fill = NULL) +
theme_minimal(base_size = 12) + theme(legend.position = "bottom")
p_annual <- ggplot(annual, aes(year, compound_pct)) +
geom_line(color = "#23577d") + geom_point(color = "#23577d", size = 1.7) +
geom_line(aes(y = trend_fitted_pct), color = "#dd6b43", linetype = 2) +
labs(title = "Annual compound-event frequency",
x = "Year", y = "April–June days (%)") + theme_minimal(base_size = 12)
heat_thresholds$month_name <- factor(c("April", "May", "June"),
levels = c("April", "May", "June"))
p_threshold <- ggplot(heat_thresholds, aes(month_name, heat_p90_c)) +
geom_col(fill = "#3978a4", width = 0.62) +
geom_text(aes(label = sprintf("%.2f°C", heat_p90_c)), vjust = -0.4) +
coord_cartesian(ylim = c(0, 55)) +
labs(title = "1991–2020 month-specific heat thresholds",
x = NULL, y = "Maximum temperature (°C)") + theme_minimal(base_size = 12)
overlap <- data.frame(
class = c("Hot and low rain", "Hot with at least 1 mm rain"),
days = c(sum(season$compound), sum(season$hot & !season$low_rain))
)
p_overlap <- ggplot(overlap, aes(reorder(class, days), days)) +
geom_col(fill = "#dd6b43", width = 0.6) +
geom_text(aes(label = days), hjust = -0.2) +
coord_flip(ylim = c(0, 500)) +
labs(title = "Most unusually hot days were also low-rain days",
x = NULL, y = "Count of unusually hot days") + theme_minimal(base_size = 12)
plots <- list(p_calendar, p_annual, p_threshold, p_overlap)
names(plots) <- c("01_event_calendar_R.png", "02_annual_frequency_R.png",
"03_heat_thresholds_R.png", "04_hot_rain_overlap_R.png")
for (name in names(plots)) {
ggsave(file.path(figure_dir, name), plots[[name]],
width = 10, height = 5.8, dpi = 240, bg = "white")
}
8. Preserve the tables that justify the figures
A reproducible study should retain its baseline thresholds, yearly denominators, counterexample dates, sensitivity outcomes and computational environment. The final section exports these items for independent inspection. The original daily data are not modified.
table_dir <- "04_outputs/r_tables"
dir.create(table_dir, recursive = TRUE, showWarnings = FALSE)
write.csv(heat_thresholds, file.path(table_dir, "01_monthly_thresholds.csv"),
row.names = FALSE)
write.csv(annual, file.path(table_dir, "02_annual_frequency.csv"),
row.names = FALSE)
write.csv(monthly, file.path(table_dir, "03_monthly_event_summary.csv"),
row.names = FALSE)
write.csv(summary_overall, file.path(table_dir, "04_overall_summary.csv"),
row.names = FALSE)
write.csv(trend_table, file.path(table_dir, "05_descriptive_trend.csv"),
row.names = FALSE)
write.csv(sensitivity, file.path(table_dir, "06_threshold_sensitivity.csv"),
row.names = FALSE)
write.csv(overlap, file.path(table_dir, "07_hot_day_overlap.csv"),
row.names = FALSE)
write.csv(non_dry_hot, file.path(table_dir, "08_hot_rain_counterexamples.csv"),
row.names = FALSE)
writeLines(capture.output(sessionInfo()),
file.path(table_dir, "09_R_session_info.txt"))Agricultural interpretation: what is—and is not—established
Hot weather can increase atmospheric evaporative demand and affect plant stress, while rainfall influences potential water inputs. But the daily precipitation flag does not measure root-zone water availability. Irrigation, stored soil moisture, crop stage, humidity, wind and soil type all matter. These NASA POWER estimates are a single spatial point and not a field experiment. There is no yield outcome and no causal treatment contrast in this dataset.
The exceptional gridded precipitation estimate of 217.60 mm on 11 March 2020 agrees with the original NASA POWER JSON but is outside the April–June classification window. It remains appropriate to seek independent gauge or another precipitation-product corroboration, especially before using these data for broader rainfall-extreme claims.
What this analysis teaches
The core lesson is a distinction between relative extreme heat, a low-rainfall day and their intersection. Month-aware reference thresholds improve fairness across the season; a fixed date-level join avoids false compound events; denominators make annual comparisons legible; sensitivity analysis reveals which part of an operational definition drives the result. For a crop-focused extension, the next necessary information would be soil moisture, irrigation, exposure duration and phenological stage—not simply another daily rainfall cutoff.
Data and methodological references
- NASA POWER: Daily point data and variable documentation.
- World Meteorological Organization: Climatological normals and reference periods.
- R: Sample quantiles (
stats::quantile). - This study’s record: NASA POWER daily point at latitude 30.1978° N and longitude 71.4720° E; AG community, local solar time; variables
T2M_MAXandPRECTOTCORR, 1981–2025. The daily CSV and original response JSON accompany the reproducible analysis.
Comments
Post a Comment