RUFAS.routines.field.manager.schedule module#
- class RUFAS.routines.field.manager.schedule.Schedule(name: str, years: list[int], days: list[int], pattern_skip: int = 0, pattern_repeat: int = 0)#
Bases:
object
Base class for scheduling events in the Crop and Soil module, provides a generic structure for creating and managing schedules for various agricultural and environmental processes.
Parameters#
- namestr
The name of the schedule, serving as a unique identifier.
- yearslist[int]
The years in which scheduled events are to occur.
- dayslist[int]
The Julian days corresponding to each event within the specified years.
- pattern_skipint, optional, default 0.0
The number of years to skip between repetitions of the schedule.
- pattern_repeatint, optional, default 0.0
The number of times the schedule pattern is repeated.
Attributes#
- namestr
Name of the schedule, uniquely identifying it within the simulation.
- yearslist[int]
List of years during which the scheduled events will occur.
- dayslist[int]
Elongated list of days to ensure a day value for each specified year, aligning with the years attribute.
- pattern_skipint
Specifies the interval of years between each cycle of the schedule.
- pattern_repeatint
Indicates how many times the schedule cycle is to be repeated.
- __init__(name: str, years: list[int], days: list[int], pattern_skip: int = 0, pattern_repeat: int = 0)#
- static _validate_days(years: list[int], days: list[int]) bool #
Checks that all values passed for days are in the correct range.
Parameters#
- yearslist[int]
Calendar year(s) in which this event will occur.
- dayslist[int]
Julian day(s) in which this event will occur.
Returns#
- bool
True if all days are valid.
Notes#
A day is ‘valid’ if it is in the range [1, 366] in leap years, and in the range [1, 365] in non-leap years.
- static _validate_years(years: list[int]) bool #
Checks that all years passed are valid and ordered.
Parameters#
years : List[int]
Returns#
- bool
True if years are valid and ordered, False if not.
Notes#
A list of years is valid if every year is > 0, and the list of years does not descend at all.
- generate_events(years: list[int], days: list[int], additional_attributes: list[Any] | None, additional_attributes_events: list[list[Any]], event_class: Any, pattern_skip: int, pattern_repeat: int) list[Any] #
Generic method to generate application events.
Parameters#
- yearslist[int]
List of years for the schedule.
- dayslist[int]
List of days for the schedule.
- additional_attributeslist[List]
Additional general attributes for the events (e.g., crop reference).
- additional_attributes_eventslist[List]
Additional attributes for each of the events (e.g., nitrogen_mass, phosphorus_mass, etc.).
- event_classAny
The class to instantiate for each event.
- pattern_skipint
Number of years to skip.
- pattern_repeatint
Number of times the pattern should repeat.
Returns#
- list
List of instantiated event objects.
- prepare_events(years: list[int], days: list[int], additional_attributes_events: list[list[Any]], pattern_skip: int, pattern_repeat: int) list[Any] #
Prepares the attributes to pass into the event classes constructor.
Parameters#
- yearslist[int]
List of years for the schedule.
- dayslist[int]
List of days for the schedule.
- additional_attributes_eventslist[list]
Additional attributes for each of the events (e.g., nitrogen_mass, phosphorus_mass, etc.).
- pattern_skipint
Number of years to skip.
- pattern_repeatint
Number of times the pattern should repeat.
Returns#
- list
list of prepared event arguments for event initialization.
- static validate_positive_values(values: list[float]) bool #
Checks that values passed are greater than 0.
Parameters#
- valueslist[float]
list of values to be validated.
Returns#
- bool
True if all values are greater than 0, False otherwise.
- static validate_equal_lengths(header: str, **kwargs: Any) bool #
Validates that all provided iterables have the same length.
Parameters#
- header: str
Error header when for when an error is raised.
- kwargslist of iterables
The iterables to check for length equality.
Returns#
- bool
True if all lengths are equal.
Raises#
- ValueError
If the lengths of the provided iterables are not all equal.
Examples#
>>> Schedule.validate_equal_lengths("example", {"arg1": [1, 2, 3], "arg2": [4, 5, 6]}) True
>>> Schedule.validate_equal_lengths("example", {"arg1": [1, 2, 3], "arg2": [4, 5, 6, 7]}) ValueError("example Mismatch in length of parameters. Provided parameters are: arg1=[1, 2, 3], arg2=[4, 5, 6, 7] . Lengths are: {'arg1': 3, 'arg2': 4}.")
- classmethod _validate_parameters(non_negative_parameters: list[tuple[str, list[Any]] | None], fraction_parameters: list[tuple[str, list[Any]] | None], years: list[int], days: list[int], name: str) None #
General validations for schedule parameter.
Parameters#
- non_negative_parameters: list[tuple[str, list]]
A list of tuples containing parameter names and associated non-negative values.
- fraction_parameters: list[tuple[str, list]]
A list of tuples containing parameter names and associated values that should be fractions.
- years: list[int]
list of event years.
- days: list[int]
list of event days.
- namestr
The name of the schedule, serving as a unique identifier.
Raises#
- ValueError
If non-negative values are negative. If fraction is out of range [0.0, 1.0]. If not all years > 0 and in non-descending order. If not all days to be in range [1, 366].
- static repeat_pattern(pattern: list[int | float], skip: int = 0, repeat: int = 0) list[int] #
Extends a pattern of numbers by repeating it a specified number of times. The pattern’s differences between consecutive numbers are calculated and used for repetition, with an optional gap (skip) added between each repetition.
Parameters#
- patternlist[int | float]
The pattern to be repeated.
- skipint
Number of steps to skip between repeats (0 if no steps should be skipped).
- repeatint
Number of times pattern should be repeated.
Returns#
- list[int]
The full repeated pattern of numbers.