Skip to content

AnimalHerd

Livestock production is managed through specific AnimalHerd modules (i.e. child classes of AnimalHerd) for each species and in some cases breed. Each production unit is defined by a species, breed, production system (prod_system), sub-system (sub_system), and region. The AnimalHerd modules calculates herd structure, i.e. the number of different animal categories in relation to a defining animal category (e.g. cows for the CattleHerd module).

The .scale() method scales all AnimalHerd´s data attributes with the scalable=True flag based on a new number of the defining animal category.


%%{init: {
  "flowchart": {
    "nodeSpacing": 10,
    "rankSpacing": 20,
    "padding": 3,
    "curve": "linear"
  },
  "themeVariables": {
    "fontSize": "12px"
  }
}}%%


flowchart TD

  %% -------------------------
  %% Main (module family)
  %% -------------------------

  A["**AnimalHerd**"]:::mod_main
  A --> C["**.calculate()**"]:::method
  A --> SC["**.scale()**"]:::method

  %% Typical upstream source of x0 and region structure
  R["**Regions**"]:::mod_main --> A


  %% -------------------------
  %% Calculate() – typical sequence
  %% -------------------------

  C --> HS["**.calculate_herd()**"]:::method
  FEED["**.calculate_feed_req()**"]:::method
  PROD["**.calculate_production()**"]:::method

  %% -------------------------
  %% Herd structure
  %% -------------------------
  P_HS["
  **AnimalHerd.par.**
  Many different parameters depending on animal species (and breed)
  "]:::param
  P_HS --> HS

  HS --> DA_HS["**AnimalHerd.data_attr.**
heads, lwg, slaughtered_n, lost_n, lost_lw"]:::data

  DA_HS ---> PROD

  %% -------------------------
  %% Feed requirements
  %% -------------------------

  DA_HS ---> FEED
  P_FEED["
  **AnimalHerd.par.**
  Different parameters depending on animal species (and breed)
  "]:::param --> FEED

  FEED --> DA_FEED["**AnimalHerd.data_attr.**
feed_req_eq, feed_req_min, feed_req_max, feed_req_of_DM_min, feed_req_of_DM_max"]:::data

  %% -------------------------
  %% Livestock product outputs
  %% -------------------------
  P_PROD["
  **AnimalHerd.par.**
  slaughter_weight, milk_prod, milk_loss, milk_protein, milk_fat
  "]:::param --> PROD

  PROD --> DA_PROD["**AnimalHerd.data_attr.**
production"]:::data


  %% -------------------------
  %% Styles
  %% -------------------------
  classDef mod_main fill:#509e2f80,stroke:#203f13,stroke-width:2px,font-size:13,color:#203f13;
  classDef mod_mgmt fill:#6ad1e380,stroke:#125560,stroke-width:2px,font-size:13,color:#125560;
  classDef mod_opt  fill:#d9d9d680,stroke:#43433e,stroke-width:2px,font-size:13,color:#43433e;

  classDef data  fill:#fee8c880,stroke:#b30000,stroke-width:0.5px,font-size:11,color:#b30000;
  classDef param fill:#d7f4ee80,stroke:#165044,stroke-width:0.5px,font-size:11,color:#165044;

  classDef method   fill:#ffffff80,stroke:#000000,stroke-width:1px,font-size:12,color:#000000;
  classDef helper   fill:#f5f5f580,stroke:#616161,stroke-width:2px,font-size:12,color:#212121;
  classDef settings fill:#ffd5f680,stroke:#aa0088,stroke-width:1px,font-size:11,color:#aa0088;
Hold "Alt" / "Option" to enable pan & zoom
View Docstring
Signature:
AnimalHerd(
    par: ParameterRetriever,
    index: pd.Index,
    **kwargs
)

Docstring:
Class that handels animal herd structure, feed requirements, production etc.

Parameters
----------
par : ParameterRetriever object
index : pandas.Index or pandas.MultiIndex
    Index for the rows. This is also passed on to the ParameterRetriever.
    Should have one level 'region'
**kwargs : str or list
    Keyword arguments to be passed on as filters to the ParameterRetriever, along with
    the index, self.species. Special cases are 'breed', 'prod_system' and 'sub_system'
    which if supplied are also stored as attributes in the AnimalHerd object.

Attributes set on init
----------------------
index : pandas.Index or padnas.MultiIndex
    Index for rows

species : str
    Animal species (depends on which AnimalHerd sub-class is used)
breed : str
    Specifies the breed (e.g. dairy or beef breed)
prod_system : str
    Specifies the production system which links feed
sub_system : str

animals : list
    List of str specifying animal categories in the herd (depends on which AnimalHerd
    sub-class is used)

File: CIBUSmod/main_modules/animal_herd.py

Specific AnimalHerd child modules

CattleHerd

PigHerd

LayerHerd

BroilerHerd

SheepHerd

GoatHerd

HorseHerd

AquacultureHerd

FisheriesHerd

Helper functions

make_herds()

View Docstring
Signature:
make_herds(regions, class_map, sub_systems)

Docstring:
Helper function to instantiate AnimalHerd objects and put them in a pandas.Series.

Parameters
----------
regions : Regions object
class_map : dict
sub_systems : dict

Returns
-------
pandas.Series : A series containing AnimalHerd objects representing all animals
                in regions 'x0_animals' data attribute

File: CIBUSmod/main_modules/animal_herd.py

concat_herds()

View Docstring
Signature:
concat_herds(herds, attrs)

Docstring:
Combines multiple AnimalHerd objects

Parameters
----------
herds : itterable of AnimalHerd objects
attrs : list of str or None, default None
    List of data attributes to include in concatenated herd object
    If None, all data attributes present in all animal herd objects
    are included

Returns
-------
StaticAnimalHerd object

File: CIBUSmod/main_modules/animal_herd.py