RUFAS.weather module#

class RUFAS.weather.Weather(weather_file: dict, time: RufasTime)#

Bases: object

The Weather class manages all weather data used to run a single simulation.

Parameters#

weather_filedict[str, List[Any]]

The weather dictionary read from the provided weather input source.

Attributes#

weather_datadict[datetime, CurrentDayCondition]

A dictionary that maps a date to the corresponding CurrentDayCondition.

mean_annual_temperatureint

Mean of mean daily temperatures over all the weather data used by the simulation (°C).

__init__(weather_file: dict, time: RufasTime)#

Initializes the Weather instance using user-supplied whether data and overall simulation parameters.

Parameters#

weather_filedict

All the weather data available to be used by the simulation.

timeRufasTime

The RufasTime instance containing time configuration information of the simulation.

Notes#

Contains daily weather information stored in 2D lists. Data lists are in the format Data[year][julian_day]. Allows daily information to be accessed by indexing to [time.year - 1][time.day - 1] (list indexing starts at 0, time starts at 1).

get_current_day_conditions(time: RufasTime, latitude: float | None = None) CurrentDayConditions#

Creates a CurrentDayConditions object containing all the weather conditions on the current day.

Parameters#

time: RufasTime

RufasTime object containing the current time of the simulation.

latitudefloat | None, default None

Latitude of the location which weather data is being collected for (degrees). If no latitude is provided, then the daylength will not be provided in the returned CurrentDayConditions instance.

Returns#

CurrentDayConditions

CurrentDayConditions instance including all the weather conditions of the specified date.

Raises#

KeyError

While attempting to collect weather conditions that are not contained in the Weather object.

get_conditions_series(time: RufasTime, starting_offset: int, ending_offset: int, latitude: float | None = None) list[CurrentDayConditions]#

Generates a series of CurrentDayConditions.

Parameters#

timeRufasTime

A RufasTime instance containing the current time information of the simulation.

starting_offsetint

Number of days before or after the given date to start the weather conditions series.

ending_offsetint

Number of days before or after the given date to end the weather conditions series.

latitudefloat | None, default None

The latitude of the location that weather conditions are being collected for (degrees). If no latitude is provided, then no daylengths will be included in weather conditions returned.

Returns#

list[CurrentDayConditions]

Series of current day conditions in chronological order.

record_weather(time: RufasTime) None#

Records the current weather conditions in the OutputManager.

Parameters#

time: RufasTime

RufasTime object containing the current time of the simulation.

static _calculate_average_annual_temperature(daily_average_temperatures: list[float]) float#

Calculates the average annual air temperature based on the daily average air temperatures.

Parameters#

daily_average_temperatureslist(float)

List of daily average air temperatures in the passed to be run by the simulation (degrees C).

Returns#

float

The average annual air temperature (degrees C).

Notes#

This method calculates the average annual air temperature by taking the average of all daily average air temperatures provided in the weather input file. Previous implementations calculated the average annual temperature for individual years, which led to the value fluctuating more than desired.

This method is intended to approximate SWAT’s method for calculating the average annual temperature. SWAT calculates average high and low temperatures for each month over every simulated year, then averages those values to get a single annual average air temperature for the entire simulation. The exact implementation for this can be found at in the SWAT source code file readwgn.f

static check_adequate_weather_data(weather_file: dict, time: RufasTime) None#

Checks that there is enough weather data to cover the whole simulation time.

Parameters#

weather_file: dict

File containing weather data.

time: RufasTime

The RufasTime instance containing time configuration information of the simulation.

Returns#

None