bovidaeta 0.2.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
bovidaeta/__init__.py ADDED
@@ -0,0 +1,138 @@
1
+ """Top-level public API for bovidaeta."""
2
+
3
+ from importlib.metadata import PackageNotFoundError
4
+ from importlib.metadata import version as _version
5
+
6
+ from .cow import BreedPart, Cow
7
+ from .enums import (
8
+ AggregationPeriod,
9
+ AnimalGender,
10
+ Breed,
11
+ BreedingType,
12
+ CalvingEaseType,
13
+ ConfirmationStatus,
14
+ DepartureReason,
15
+ DepartureType,
16
+ DiagnosisMethod,
17
+ DiagnosisSampleType,
18
+ DiagnosisSeverity,
19
+ DiagnosisStage,
20
+ DiagnosticSource,
21
+ DiseaseCode,
22
+ EventType,
23
+ GenderSorting,
24
+ GenomicSampleSource,
25
+ HerdEntryType,
26
+ LamenessAffectedLeg,
27
+ LamenessObservationContext,
28
+ ParturitionBirthStatusType,
29
+ RouteOfAdministration,
30
+ SensorMeasurementType,
31
+ TreatmentResponseStatus,
32
+ )
33
+ from .event import Event
34
+ from .event_metadata import (
35
+ ALL_METADATA,
36
+ AggregatedMilkMeterYieldsMetadata,
37
+ BirthMetadata,
38
+ BodyConditionScoreMetadata,
39
+ BodyWeightKgMetadata,
40
+ BreedingMetadata,
41
+ CalvingMetadata,
42
+ DiagnosisMetadata,
43
+ DiagnosisSampleMetadata,
44
+ DiseaseMetadata,
45
+ EventMetadataModel,
46
+ ExitMetadata,
47
+ FeedIntakeMetadata,
48
+ GenomeTestMetadata,
49
+ HerdEntryMetadata,
50
+ HerdMoveMetadata,
51
+ LamenessScoreMetadata,
52
+ MilkMeterYieldsMetadata,
53
+ MilkRecordingMetadata,
54
+ SensorMeasurementMetadata,
55
+ TreatmentMetadata,
56
+ )
57
+ from .herd import Herd
58
+ from .io import DairyData
59
+ from .lactation import (
60
+ load_daily_milk_yields,
61
+ load_lactation_records,
62
+ load_lactations,
63
+ select_lactations,
64
+ )
65
+
66
+ try:
67
+ __version__ = _version("bovidaeta")
68
+ except (
69
+ PackageNotFoundError
70
+ ): # pragma: no cover - running from a source tree without installing
71
+ __version__ = "0.0.0"
72
+
73
+ __all__ = [
74
+ "ALL_METADATA",
75
+ "AggregatedMilkMeterYieldsMetadata",
76
+ "AggregationPeriod",
77
+ "AnimalGender",
78
+ "BirthMetadata",
79
+ "BodyConditionScoreMetadata",
80
+ "BodyWeightKgMetadata",
81
+ "Breed",
82
+ "BreedPart",
83
+ "BreedingMetadata",
84
+ "BreedingType",
85
+ "CalvingEaseType",
86
+ "CalvingMetadata",
87
+ "ConfirmationStatus",
88
+ "Cow",
89
+ "DairyData",
90
+ "DepartureReason",
91
+ "DepartureType",
92
+ "DiagnosisMetadata",
93
+ "DiagnosisMethod",
94
+ "DiagnosisSampleMetadata",
95
+ "DiagnosisSampleType",
96
+ "DiagnosisSeverity",
97
+ "DiagnosisStage",
98
+ "DiagnosticSource",
99
+ "DiseaseCode",
100
+ "DiseaseMetadata",
101
+ "Event",
102
+ "EventMetadataModel",
103
+ "EventType",
104
+ "ExitMetadata",
105
+ "FeedIntakeMetadata",
106
+ "GenderSorting",
107
+ "GenomeTestMetadata",
108
+ "GenomicSampleSource",
109
+ "Herd",
110
+ "HerdEntryMetadata",
111
+ "HerdEntryType",
112
+ "HerdMoveMetadata",
113
+ "LamenessAffectedLeg",
114
+ "LamenessObservationContext",
115
+ "LamenessScoreMetadata",
116
+ "MilkMeterYieldsMetadata",
117
+ "MilkRecordingMetadata",
118
+ "ParturitionBirthStatusType",
119
+ "RouteOfAdministration",
120
+ "SensorMeasurementMetadata",
121
+ "SensorMeasurementType",
122
+ "TreatmentMetadata",
123
+ "TreatmentResponseStatus",
124
+ "load_daily_milk_yields",
125
+ "load_lactation_records",
126
+ "load_lactations",
127
+ "select_lactations",
128
+ "to_polars",
129
+ ]
130
+
131
+
132
+ def __getattr__(name: str):
133
+ """Expose `to_polars` lazily; it needs pyspark, the rest of the package does not."""
134
+ if name == "to_polars":
135
+ from .io import to_polars
136
+
137
+ return to_polars
138
+ raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
bovidaeta/cow.py ADDED
@@ -0,0 +1,165 @@
1
+ from __future__ import annotations
2
+
3
+ from datetime import date
4
+ from uuid import UUID
5
+
6
+ from pydantic import BaseModel, ConfigDict, Field
7
+
8
+ from .enums import AnimalGender, Breed
9
+
10
+
11
+ class BreedPart(BaseModel):
12
+ """
13
+ A class to represent the breed composition of a cow.
14
+
15
+ Breed is expressed as percentages, often in eighths. A cow can be, for
16
+ example, 100% HOL (8/8), 50% HOL and 50% JER (4/8 + 4/8), or 50% HOL and
17
+ 25% JER and 25% AAN.
18
+
19
+ Reference: https://interbull.org/ib/icarbreedcodes.
20
+ """
21
+
22
+ model_config = ConfigDict(extra="forbid", use_enum_values=True)
23
+
24
+ breed_code: Breed = Field(
25
+ description='The name/code of the breed (for example: "HOL", "JER", or "AAN").',
26
+ )
27
+ proportion: float = Field(
28
+ ge=0,
29
+ le=1,
30
+ description=(
31
+ "The proportion of this breed in the cow (for example: 1.0 for 100% HOL, "
32
+ "0.5 or 4/8 for 50% HOL)."
33
+ ),
34
+ )
35
+
36
+ def __str__(self) -> str:
37
+ return f"{self.breed_code} {int(self.proportion * 100)}%"
38
+
39
+
40
+ class Cow(BaseModel):
41
+ """
42
+ A class to represent a cow.
43
+
44
+ Specify at least `animal_id`, `herd_id`, and `gender` when creating a new cow;
45
+ `birth_date` is optional because not every source records it.
46
+
47
+ """
48
+
49
+ model_config = ConfigDict(extra="forbid")
50
+
51
+ animal_id: UUID = Field(
52
+ description=(
53
+ "UUID identifier for the animal record. This identifier is "
54
+ "linked to `herd_id` and remains stable over time."
55
+ ),
56
+ )
57
+ herd_id: UUID = Field(
58
+ description="UUID identifier of the herd this cow belongs to.",
59
+ )
60
+
61
+ gender: AnimalGender = Field(
62
+ description=(
63
+ "The animal's gender (male/female), based on ICAR enumeration for sex of "
64
+ "animal using species-independent English names, including "
65
+ "neuter/cryptorchid variations."
66
+ ),
67
+ )
68
+ birth_date: date | None = Field(
69
+ default=None,
70
+ description=(
71
+ "Day the animal was born as recorded by the farmer, format YYYY-MM-DD, "
72
+ "if available add time. Empty when the source does not record birth dates."
73
+ ),
74
+ )
75
+ exit_date: date | None = Field(
76
+ description=("Day the animal left the herd."),
77
+ )
78
+ animal_ear_tag: str | None = Field(
79
+ default=None,
80
+ description=(
81
+ "The animal's ear tag number, which is official and unique in most (but "
82
+ "not all) countries. In Europe, every cow receives a unique official ear "
83
+ "tag linked to that animal for life (for example EG 911/2004 and "
84
+ "EG1760/2000)."
85
+ ),
86
+ )
87
+ animal_farm_name: str | None = Field(
88
+ default=None,
89
+ description="The animal's name most commonly used on the farm (barn name).",
90
+ )
91
+ animal_farm_number: int | None = Field(
92
+ default=None,
93
+ gt=0,
94
+ description=(
95
+ "The animal's number most commonly used on the farm (work number), for "
96
+ "example on a collar or burn mark; it can be reused over time on the farm."
97
+ ),
98
+ )
99
+ genetic_dam_ear_tag: str | None = Field(
100
+ default=None,
101
+ description="The animal's dam ear tag number.",
102
+ )
103
+ genetic_dam_id: UUID | None = Field(
104
+ default=None,
105
+ description="UUID identifier of the animal's dam.",
106
+ )
107
+ sire_ear_tag: str | None = Field(
108
+ default=None,
109
+ description="The animal's sire ear tag number.",
110
+ )
111
+ sire_id: UUID | None = Field(
112
+ default=None,
113
+ description="UUID identifier of the animal's sire.",
114
+ )
115
+ animal_legal_id: str | None = Field(
116
+ default=None,
117
+ description="In EU countries, this is typically the same as the animal ear tag.",
118
+ )
119
+ animal_isorfid_starting_manufacturer: str | None = Field(
120
+ default=None,
121
+ description="ISO RFID tag starting with manufacturer code.",
122
+ )
123
+ animal_isorfid_starting_country_code: str | None = Field(
124
+ default=None,
125
+ description=(
126
+ "ISO RFID tag starting with country code "
127
+ "(https://en.wikipedia.org/wiki/ISO_11784_%26_11785)."
128
+ ),
129
+ )
130
+ animal_herd_book_name: str | None = Field(
131
+ default=None,
132
+ description="A name given to the animal by an official herd book.",
133
+ )
134
+ animal_usda: str | None = Field(
135
+ default=None,
136
+ description=(
137
+ "A number used by the US Department of Agriculture for animal "
138
+ "identification "
139
+ "(https://www.aphis.usda.gov/aphis/ourfocus/animalhealth/nvap/"
140
+ "NVAP-Reference-Guide/Animal-Identification/Animal-Identification)."
141
+ ),
142
+ )
143
+ animal_dhia: str | None = Field(
144
+ default=None,
145
+ description="A number used by the US DHIA (http://www.dhia.org).",
146
+ )
147
+ recipient_dam_id: UUID | None = Field(
148
+ default=None,
149
+ description=(
150
+ "UUID identifier of the animal's surrogate dam; only applies when the "
151
+ "cow was born using assisted reproductive technologies such as in vitro "
152
+ "embryo production or embryo transfer."
153
+ ),
154
+ )
155
+ breed: list[BreedPart] = Field(
156
+ default=[BreedPart(breed_code=Breed.HOL, proportion=0.99)],
157
+ description=(
158
+ "The animal's breed expressed as a list of `BreedPart`. When unknown, "
159
+ "the default is 99% HOL."
160
+ ),
161
+ )
162
+ born_on_farm: bool | None = Field(
163
+ default=None,
164
+ description="Boolean indicating if the animal was born on the herd linked to the herd identifier.",
165
+ )