RUFAS.biophysical.animal.milk.lactation_curve module#

RUFAS.biophysical.animal.milk.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.biophysical.animal.milk.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.biophysical.animal.milk.lactation_curve.PARITY_3_DEFAULT_FRACTION_OF_MILKING_COWS = 0.333#

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

RUFAS.biophysical.animal.milk.lactation_curve.LOWER_BOUND = -20#

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

class RUFAS.biophysical.animal.milk.lactation_curve.LactationCurve#

Bases: object

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

Attributes#

_omOutputManager

The OutputManager for this module to use.

_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.

_om = <RUFAS.output_manager.OutputManager object>#
_parity_to_parameter_mapping: dict[int, dict[str, float]] = {}#
_parity_to_std_dev_mapping: dict[int, dict[str, float]] = {}#
classmethod set_lactation_parameters(time: RufasTime) None#

Calculates Wood’s lactation curve parameters, adjusted based on the location, production, and management practices of the farm being simulated.

Parameters#

timeRufasTime

RufasTime instance that manages time in the simulation.

classmethod _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.

classmethod _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.

classmethod _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.

classmethod _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.

Notes#

Parameter adjustments: [AN.MLK.1], [AN.MLK.2], [AN.MLK.3]

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.

classmethod 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.

classmethod _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.

classmethod _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.

Notes#

Herd average 305-day milk yield: [AN.MLK.4] Parity specific 305-day milk yield: [AN.MLK.5], [AN.MLK.6], [AN.MLK.7]

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).

static _calculate_305_day_milk_yield_error(l_param: float, m_param: float, n_param: float, milk_yield: float) float#

Calculates absolute difference between an estimated 305 day milk yield and a predetermined one.

classmethod _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.

Notes#

[AN.MLK.8]

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.