Package 'agriclimr'

Title: Agricultural Climate Data Processing and Agrometeorological Tools
Description: Tools for downloading and processing climate data of agricultural interest.
Authors: Joao Batista Tolentino Jr. [aut, cre]
Maintainer: Joao Batista Tolentino Jr. <[email protected]>
License: MIT + file LICENSE
Version: 0.1.0
Built: 2026-10-07 12:20:59 UTC
Source: https://github.com/joaobtj/agriclimr

Help Index


Disaggregate Daily Weather Data to Hourly Leaf Wetness Duration

Description

Takes a daily data frame containing temperature extrema and average relative humidity, reconstructs the hourly parameters internally, and computes the hourly leaf wetness presence along with its daily operational hour sum.

Usage

daily_to_hourly_lwd(
  data,
  date_col,
  t_min_col,
  t_max_col,
  rh_daily_col,
  lat_col,
  rh_threshold = 85
)

Arguments

data

A data frame containing the daily weather records.

date_col

Unquoted name of the column containing the Date object.

t_min_col

Unquoted name of the column containing the current day's minimum temperature (°C).

t_max_col

Unquoted name of the column containing the current day's maximum temperature (°C).

rh_daily_col

Unquoted name of the column containing the daily average relative humidity (%).

lat_col

Unquoted name of the column containing the latitude (decimal degrees).

rh_threshold

A single numeric value indicating the RH percentage above which leaf wetness is assumed to occur. Default is 85% based on optimized regional validations.

Value

A tibble (data frame) expanded to hourly resolution (24 rows per original daily row) with four columns: datetime (POSIXct), temperature_hourly (°C), rh_hourly (\ leaf_wetness_hourly (binary 0/1), and lwd_daily_sum (total wet hours in that day).

Examples

# Sample daily dataset matching your exact input structure with 5 continuous days
daily_series <- tibble::tibble(
  date = as.Date("2026-06-01") + 0:4,
  lat = rep(-27.3, 5),
  tmin = c(12.0, 13.5, 11.0, 10.5, 14.0),
  tmax = c(22.0, 24.5, 21.0, 19.5, 23.0),
  rh_mean = c(80, 75, 85, 90, 70)
)

daily_to_hourly_lwd(daily_series, date, tmin, tmax, rh_mean, lat, rh_threshold = 85)

Disaggregate Daily Weather Data to Hourly Relative Humidity

Description

Takes a daily data frame containing temperature extrema and average relative humidity, reconstructs the hourly temperature internally, and uses it to generate a 24-hour profile of relative humidity for each day. Returns a clean time-series data frame with combined datetime.

Usage

daily_to_hourly_rh(data, date_col, t_min_col, t_max_col, rh_daily_col, lat_col)

Arguments

data

A data frame containing the daily weather records.

date_col

Unquoted name of the column containing the Date object.

t_min_col

Unquoted name of the column containing the current day's minimum temperature (°C).

t_max_col

Unquoted name of the column containing the current day's maximum temperature (°C).

rh_daily_col

Unquoted name of the column containing the daily average relative humidity (%).

lat_col

Unquoted name of the column containing the latitude (decimal degrees).

Value

A tibble (data frame) expanded to hourly resolution (24 rows per original daily row) with three columns: datetime (POSIXct), temperature_hourly (°C), and rh_hourly (%).

Examples

# Sample daily dataset matching your exact input structure with 5 continuous days
daily_series <- tibble::tibble(
  date = as.Date("2026-06-01") + 0:4,
  lat = rep(-27.3, 5),
  tmin = c(12.0, 13.5, 11.0, 10.5, 14.0),
  tmax = c(22.0, 24.5, 21.0, 19.5, 23.0),
  rh_mean = c(80, 75, 85, 90, 70)
)

daily_to_hourly_rh(daily_series, date, tmin, tmax, rh_mean, lat)

Expand Daily Temperature Data Frame to Hourly Scale

Description

Takes a data frame containing daily records (minimum and maximum temperatures) and expands it into an hourly data frame (24 rows per day) using a sine-exponential reconstruction model. Returns a clean time-series data frame with combined datetime.

Usage

daily_to_hourly_temp(
  data,
  date_col,
  t_min_col,
  t_max_col,
  lat_col,
  lon_col = NULL,
  tz = NULL
)

Arguments

data

A data frame containing the daily weather records.

date_col

Unquoted name of the column containing the Date object.

t_min_col

Unquoted name of the column containing the current day's minimum temperature (°C).

t_max_col

Unquoted name of the column containing the current day's maximum temperature (°C).

lat_col

Unquoted name of the column containing the latitude (decimal degrees).

lon_col

Optional unquoted name of the column containing the longitude (decimal degrees). Default is NULL.

tz

Optional numeric value indicating the time zone offset from UTC in hours (e.g., -3). Default is NULL.

Value

A tibble (data frame) expanded to hourly resolution (24 rows per original daily row) with two columns: datetime (POSIXct) and temperature_hourly (°C).

Examples

# Sample daily dataset representing 5 continuous days
daily_series <- tibble::tibble(
  date = as.Date("2026-06-01") + 0:4,
  lat = rep(-27.3, 5),
  lon = rep(-50.6, 5),
  tmin = c(12.0, 13.5, 11.0, 10.5, 14.0),
  tmax = c(22.0, 24.5, 21.0, 19.5, 23.0)
)

# Standard usage (solar time)
daily_to_hourly_temp(daily_series, date, tmin, tmax, lat)

# With longitude, time zone, and custom alpha parameter via ...
daily_to_hourly_temp(
  daily_series, date, tmin, tmax, lat,
  lon_col = lon, tz = -3
)

Estimate Astronomical Day Length (Photoperiod)

Description

Calculates the astronomical day length (photoperiod) in decimal hours.

Usage

estimate_daylength(lat, doy)

Arguments

lat

Latitude in decimal degrees (negative for South).

doy

A numeric vector of day of the year (Julian day, 1 to 365/366) or a vector of Date / POSIXt objects.

Value

A numeric vector of day length values in decimal hours.

Examples

estimate_daylength(lat = -27.28, doy = 172) # Winter solstice
estimate_daylength(lat = -27.28, doy = 355) # Summer solstice

Estimate Hourly Relative Humidity from Daily Metrics

Description

Reconstructs a 24-hour profile of hourly relative humidity values based on daily average relative humidity, daily average temperature, and a vector of hourly temperatures. It assumes that the actual vapor pressure remains constant throughout the day.

Usage

estimate_hourly_rh(rh_daily, t_daily, t_hourly)

Arguments

rh_daily

A single numeric value representing the daily average relative humidity (%).

t_daily

A single numeric value representing the daily average temperature (°C).

t_hourly

A numeric vector of length 24 containing the hourly temperatures (°C).

Value

A numeric vector of length 24 containing estimated hourly relative humidity values (%).

Examples

daily_rh <- 80
daily_t <- 20
hourly_t <- c(16, 15, 14, 14, 15, 17, 19, 21, 23, 24, 25, 25,
              24, 23, 22, 21, 20, 19, 18, 17, 17, 16, 16, 16)

estimate_hourly_rh(rh_daily = daily_rh, t_daily = daily_t, t_hourly = hourly_t)

Reconstruct Hourly Temperatures from Daily Extrema

Description

Reconstructs a 24-hour hourly temperature profile from daily minimum, maximum, and the next day's minimum temperatures using a sine-exponential model.

Usage

estimate_hourly_temp(
  t_min,
  t_max,
  t_min_next,
  lat,
  doy,
  lon = NULL,
  tz = NULL,
  alpha = 2.75,
  beta = 1.4,
  gamma = 2.75
)

Arguments

t_min

Single numeric value of the current day's minimum temperature (°C).

t_max

Single numeric value of the current day's maximum temperature (°C).

t_min_next

Single numeric value of the next day's minimum temperature (°C).

lat

Latitude of the location in decimal degrees.

doy

Day of the year (Julian day, 1 to 365/366).

lon

Optional. Longitude of the location in decimal degrees (negative for West). Default is NULL (assumes local solar time where noon is 12:00).

tz

Optional. Time zone offset from UTC in hours (e.g., -3 for UTC-3). Default is NULL.

alpha

Parameters for the time lag between solar noon and maximum temperature (hours). Default is 2.75.

beta

Parameters for the time lag between minimum temperature and sunrise (hours). Default is 1.40.

gamma

Parameter representing the temperature characteristics decay rate at night. Default is 2.75.

Value

A numeric vector of length 24 containing the reconstructed hourly temperatures (°C) from 00:00 to 23:00.

Examples

# Using default local solar time
estimate_hourly_temp(t_min = 12, t_max = 25, t_min_next = 13, lat = -27.28, doy = 150)

# Accounting for civil time with longitude and time zone offset
estimate_hourly_temp(
  t_min = 12, t_max = 25, t_min_next = 13,
  lat = -27.28, doy = 150, lon = -50.58, tz = -3
)

Estimate Leaf Wetness Duration (LWD)

Description

Estimates the number of hours of leaf wetness based on a Relative Humidity (RH) threshold. This is a standard empirical approach used in agricultural meteorology to predict plant disease risks.

Usage

estimate_lwd_rh(rh, threshold = 90)

Arguments

rh

A numeric vector containing hourly Relative Humidity values (0 to 100).

threshold

A numeric value indicating the RH percentage above which leaf wetness is assumed to occur. Default is 90%.

Value

A numeric vector of the same length as rh containing binary values: 1 (wet) or 0 (dry).

Examples

hourly_rh <- c(85, 88, 91, 95, 92, 87, 80)
estimate_lwd_rh(hourly_rh, threshold = 90)

Estimate Solar Noon

Description

Calculates the solar noon time in decimal hours. By default, it returns local solar noon (12.0 h), but it can compute civil standard clock time when longitude and time zone offset are provided.

Usage

estimate_solar_noon(doy, lon = NULL, tz = NULL)

Arguments

doy

A numeric vector of day of the year (Julian day, 1 to 365/366) or a vector of Date / POSIXt objects.

lon

Optional. Longitude in decimal degrees (negative for West). If omitted, local solar noon is returned (12.0).

tz

Optional. Time zone offset from UTC in hours (e.g., -3 for UTC-3).

Value

A numeric vector representing solar noon in decimal hours (0 to 24).

Examples

# Local solar noon (default)
estimate_solar_noon(doy = 180)

# Civil clock time for solar noon with longitude and UTC offset
estimate_solar_noon(doy = 180, lon = -50.58, tz = -3)

Estimate Sunrise Time

Description

Computes sunrise time in decimal hours based on latitude, day of the year, and solar noon.

Usage

estimate_sunrise(lat, doy, solar_noon = 12)

Arguments

lat

Latitude in decimal degrees (negative for South).

doy

A numeric vector of day of the year (Julian day, 1 to 365/366) or a vector of Date / POSIXt objects.

solar_noon

Optional. Numeric vector or scalar indicating solar noon in decimal hours. Default is 12.0.

Value

A numeric vector containing sunrise times in decimal hours.

Examples

# Sunrise on summer solstice for southern hemisphere (lat = -27.28)
estimate_sunrise(lat = -27.28, doy = 355)

Estimate Sunset Time

Description

Computes sunset time in decimal hours based on latitude, day of the year, and solar noon.

Usage

estimate_sunset(lat, doy, solar_noon = 12)

Arguments

lat

Latitude in decimal degrees (negative for South).

doy

A numeric vector of day of the year (Julian day, 1 to 365/366) or a vector of Date / POSIXt objects.

solar_noon

Optional. Numeric vector or scalar indicating solar noon in decimal hours. Default is 12.0.

Value

A numeric vector containing sunset times in decimal hours.

Examples

estimate_sunset(lat = -27.28, doy = 355)