RUFAS.routines.animal.life_cycle.lactation_curve module#

RUFAS.routines.animal.life_cycle.lactation_curve.MILKING_FREQUENCY_THRESHOLD = 2.5#

Constants used to scale the adjustments for Wood’s m and n parameters, respectively, before using them to the adjust parameters.

RUFAS.routines.animal.life_cycle.lactation_curve.N_ADJUSTMENT_SCALING_FACTOR = 0.0001#

If user’s input for parity 1, 2, and 3+ fractions of the milking herd are invalid (i.e. do not sum to 1), then the below defaults will be used. Note that these defaults are ONLY used to adjust the lactation curve parameters, they are not used at all to determine herd structure. These numbers are from Li et al, 2023.

References#

of Dairy Science 106.9 (2023): 6232-6248.

RUFAS.routines.animal.life_cycle.lactation_curve.PARITY_3_DEFAULT_FRACTION_OF_MILKING_COWS = 0.333#

These constants regulate the range and precision used to fit Wood’s l lactation parameter to estimated 305 day milk yields.

RUFAS.routines.animal.life_cycle.lactation_curve.STEP_SIZE = 0.01#

Defines the accepted error tolerance when checking that fractions of parity 1, 2 and 3+ milking cows sum to 1.0.

class RUFAS.routines.animal.life_cycle.lactation_curve.LactationCurve(time: RufasTime)#

Bases: object

Manages Wood’s lactation curve parameters l, m, and n as they are used by the rest of the Animal module.

Parameters#

timeRufasTime

RufasTime instance that manages time in the simulation.

Attributes#

omOutputManager

The OutputManager for this module to use.

parity_1_parametersdict[str, float]

Contains the adjusted l, m, and n parameters for parity 1 cows.

parity_2_parametersdict[str, float]

Contains the adjusted l, m, and n parameters for parity 2 cows.

parity_3_parametersdict[str, float]

Contains the adjusted l, m, and n parameters for parity 3+ cows.

parity_to_parameter_mappingdict[int, dict[str, float]]

Maps the parity (1, 2, and 3+) to the associated sets of l, m and n parameters.

parity_to_std_dev_mappingdict[int, dict[str, float]]

Maps parities (1, 2, and 3+) to the standard devations of Wood’s l, m, and n parameters.

__init__(time: RufasTime) None#
_get_year_adjustments(year_adjustment_values: dict[str, dict[str, float]], time: RufasTime) dict[str, float]#

Retrieves the appropriate adjustment values based on the end year of the simulation.

_get_region_adjustments(region_adjustment_values: dict[str, dict[str, float]], region_mapping: dict[str, str], fips_code: int) dict[str, float]#

Retrieves the appropriate adjustment values for the region being simulated.

_get_milking_frequency_adjustments(milking_frequency_adjustments: dict[str, dict[str, float]], milking_frequency: float) dict[str, float]#

Retrieves the lactation curve adjustment values for the milking frequency of cows in the simulation.

_calculate_adjusted_wood_parameters(l_param: float, m_param: float, n_param: float, adjustments: list[dict[str, float]]) dict[str, float]#

Computes Wood’s Lactation Curve parameters adjusted for different factors.

Parameters#

l_paramfloat

Base value for Wood’s l parameter (unitless).

m_paramfloat

Base value for Wood’s m parameter (unitless).

n_paramfloat

Base value for Wood’s n parameter (unitless).

adjustmentslist[dict[str, float]]

List of adjustment sets, where each dictionary in the list represents the adjustments for a single factor (region, parity, etc.) and contains the keys “l”, “m”, and “n”.

Returns#

dict[str, float]

Dictionary containing the adjusted Wood l, m, and n parameters.

get_milk_yield_values_wood_curve(day_of_milk: int, l_param: float, m_param: float, n_param: float) float#

Calculates the milk yield on the given day using Wood’s lactation curve.

Parameters#

day_of_milkint

Days into milk of the cow.

l_param: float

Wood’s lactation curve parameter l.

m_param: float

Wood’s lactation curve parameter m.

n_param: float

Wood’s lactation curve parameter n.

Returns#

numpy.float64

Milk yield on the provided day (kg).

References#

Li, M., et al. “Investigating the effect of temporal, geographic, and management factors on US Holstein lactation curve parameters.” Journal of Dairy Science 105.9 (2022): 7525-7538.

calc_305_day_milk_yield(l_param: float, m_param: float, n_param: float) float#

Calculates the total milk yield from day 1 to day 305 of the lactation.

Parameters#

l_param: float

Wood’s lactation curve parameter l.

m_param: float

Wood’s lactation curve parameter m.

n_param: float

Wood’s lactation curve parameter n.

Returns#

float

305 day milk yield for a cow with the given lactation curve (kg).

get_wood_parameters(parity: int) dict[str, float]#

Adjusts the default lactation curve parameters based on farm-specific attributes.

Parameters#

parityint

The number of calves that a cow has had.

Returns#

dict[str, float]

Wood’s parameters l, m, and n for the specified parity.

_adjust_lactation_curve_to_milk_yield(animal_inputs: dict[str, Any], lactation_curve_inputs: dict[str, dict[str, Any]]) None#

Adjust the lactation parameters using predicted milk yields for the different parities of cows on the farm.

_estimate_305_day_milk_yield_by_parity(annual_milk_yield: float, num_milking_cows: int, parity_1_frac: float, parity_2_frac: float, parity_3_frac: float, parity_2_milk_yield_adjustment: float, parity_3_milk_yield_adjustment: float) dict[str, float]#

Calculates the 305-day milk yield for each lactation group based on total farm milk production.

Parameters#

annual_milk_yieldfloat

Annual milk yield of the farm (kg).

num_milking_cowsint

Number of milking cows on the farm.

parity_1_fracfloat

Fraction of cows on the farm that have a parity of 1.

parity_2_fracfloat

Fraction of cows on the farm that have a parity of 2.

parity_3_fracfloat

Fraction of cows on the farm that have a parity of 3 or more.

parity_2_milk_yield_adjustmentfloat

Factor used to adjust for parity 2 cows (unitless).

parity_3_milk_yield_adjustmentfloat

Factor used to adjust for parity 3 cows (unitless).

Returns#

dict[str, float]

Mapping of the parity (1, 2, 3+) to the estimated 305 day milk production of an individual cow of that parity (kg).

_fit_wood_l_param_to_milk_yield(l_param: float, m_param: float, n_param: float, milk_yield: float) float#

Modifies Wood’s l parameter to best fit a given 305 day milk yield.

Parameters#

l_paramfloat

Wood’s l lactation curve parameter.

m_paramfloat

Wood’s m lactation curve parameter.

n_paramfloat

Wood’s n lactation curve parameter.

milk_yieldfloat

305 day milk yield that Wood’s l parameter will be fitted to (kg).

Returns#

float

Wood’s l parameter adjusted to best fit the given milk yield.