animal

package
v0.0.0-...-7bae67f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 16, 2021 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

GenBV

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

herd project herd.go

Defines an animal and its characteristics

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

breed

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

herd document

genAnimal

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

herd project herd.go Defines the herd characteristics and members There can be more than 1 herd - e.g., spring and fall

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

phenotype

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Index

Constants

View Source
const (
	Bull   string = "M" // Breeding male or calf
	Heifer string = "F" // Young female not yet selected
	Cow    string = "C" // A breeding female
	Steer  string = "S" // Going to be fed
)

Variables

View Source
var BackgroundDays float64
View Source
var BreedTraitSexAod map[BTS_t]float64 // mapped by Breed then trait
View Source
var BreedingRecordsDumpFile = "" // name of file in breedingrecordsdump:
View Source
var BreedingRecordsYearTable map[HerdYear_t]BreedingRecordsTable_t
View Source
var Breeds map[Component_t]BreedEffects_t // See animal.go and technical documentation for this struct type
View Source
var BreedsList []string // A list of the breeds in the master.hjson.  It is the 1st line of the BreedsEffects: key
View Source
var BullBatteryBreedCompositionTable []BreedComposition_t
View Source
var BullMerit []float64 // Genetic merit of the foundation bulls fro meritFoundationBulls key
View Source
var BumpComponent *string // Name,Name of the component  to bump the bulls 1 unit after burnin
View Source
var Burnin int // Number of years to simulate before calculating the MEV
View Source
var CDPhenotypeFilePointer *os.File
View Source
var CDVar float64 // phenotypic variance for CDF
View Source
var CalfAumAt500 float64 // Amount of Aum at 500 lbs calf
View Source
var CarcassPhenotypeFile *os.File // For optional write of slaughter cattle phenotypes QG,YQ, etc.
View Source
var ComponentList []Component_t
View Source
var Components []string
View Source
var CowAgeFile *os.File // For cowagefilename: in master.hjson if exists
View Source
var CowAumAt1000 float64 // Amount of AUM at 1000 lbs animal
View Source
var CowResetList []Animal // List of Records[] to reset to active cows when bumping index components

var HeiferResetList []int // List of heifer locates in Records that need to be reset to heifer when bumping index components

View Source
var CowsExposedPerYear map[int]int // Counts of the number of cows exposed each year
View Source
var CurrentCalvesBreedCompositionTable []BreedComposition_t
View Source
var DaysOnFeed float64
View Source
var FoundationCowHerdBreedCompositionTable []BreedComposition_t
View Source
var HPPhenotypeFilePointer *os.File
View Source
var Herds map[string]Herd // can be more than 1 such as spring v fall
View Source
var HeterosisCodes map[string]string // The breed to breed classification categories in the HeterosisCodes: key in master.hjson
View Source
var HeterosisCrossClasses []string // The cross class designations from the HeterosisValues talbe 1st line in the master.hjson
View Source
var HeterosisValues map[Component_t]HeterosisValues_t // These are mapped according to their Component_t
View Source
var IndexTerminal bool
View Source
var IndexType string
View Source
var MaxCowAge int

For the culling policy it is the length of ageDist in master.hjson

View Source
var NHeifersBred map[int]int
View Source
var PhenotypeFile string // File name to write output

Optional file to write out a phenotype components for debugging

View Source
var PhenotypeFilePointer *os.File
View Source
var PhenotypeOutputTrait string // A valid trait name in the master.hjson
View Source
var Records []Animal
View Source
var RecordsDumpFile = "" // name of file in recordsdump:
View Source
var ResidualHpStdDev float64
View Source
var ResidualStayStdDev float64
View Source
var Rng *rand.Rand
View Source
var SexCodes []string
View Source
var StayPhenotypeFilePointer *os.File // For debugging cow conception routines
View Source
var TraitAgeEffects map[string]InterceptSlope_t
View Source
var TraitList = []Trait{}
View Source
var TraitMean = make(map[string]float64) // Means of traits mapped to trait name.  Coms from the Traits: key in master.hjson
View Source
var Traits []string
View Source
var WtCullCows map[int]Sales_t
View Source
var YearsPlanningHorizon int // Total Number of years to run the simulation after the burnin for MEV calculation

Functions

func AgeEffect

func AgeEffect(trait string, thisAnimal Animal) (effect float64)

func BackgroundingWtPhenotype

func BackgroundingWtPhenotype(calf Animal) float64

Return the phenotype of the animal at the end of the background period.

func Breed

func Breed(herd *Herd, year int)

Breed the cow herds

func BreedEffect

func BreedEffect(trait string, thisAnimal Animal) (effect float64)

Return the breed effect on

func Calve

func Calve(herd *Herd, year int, gvCholesky mat.Cholesky, rvCholesky mat.Cholesky)

Calve and produce phenotypes for the calves for entire life not just this year.

func CalvingDifficultyPhenotype

func CalvingDifficultyPhenotype(thisAnimal Animal, thisBreeding BreedingRec) (pheno float64)

Calculate the calving difficulty phenotype for of the initial heifer population This is used to parameterize the distribution

func CullAum

func CullAum(thisCow *Animal, year int, loc int)

Determine the AUM a cow consumed in the year it was culled

func CullOld

func CullOld(herd *Herd, year int)

Cull the open cows and older than maximum age allowed in master.hjson

func CullOpen

func CullOpen(herd *Herd, year int)

Cull the open cows and older than maximum age allowed in master.hjson

func DetermineAumThruBackgrounding

func DetermineAumThruBackgrounding(newCalf *Animal)

Calculate monthly AUM consumption of new animal to yearling age This also determines the weight at the end of the background period

func DetermineAumToWeaning

func DetermineAumToWeaning(newCalf *Animal)

Calculate monthly AUM consumption of new animal to yearling age

func DetermineCowAum

func DetermineCowAum(h *Herd, year int)

Determine the AUM consumption for active cows at end of year Considering that some may be heifers that entered

func DetermineFeedlotFeedIntake

func DetermineFeedlotFeedIntake(newCalf *Animal)

Calculate this animal's total feedlot feed intake And slaughter weight

func DumpBreedingRecords

func DumpBreedingRecords()

func DumpRecords

func DumpRecords()

func GenBullBatteryBreedComposition

func GenBullBatteryBreedComposition(a *Animal)

Generate the breed composition of the initial bull battery animal from the BullBatteryBreedComposition: key

func GenFoundation

func GenFoundation(a *Animal, gvCholesky mat.Cholesky, rvCholesky mat.Cholesky)

Generate a foundation animal - sire and dam unknown

func GenFoundationBreedComposition

func GenFoundationBreedComposition(a *Animal)

Generate the breed composition of a foundation animal from the CowHerdBreedComposition: key

func GenFromMating

func GenFromMating(a *Animal, year int, gvCholesky mat.Cholesky, rvCholesky mat.Cholesky)

Generate an animal from a mating Determine if the heifer or calf died in calving

func GeneticEffect

func GeneticEffect(indx int, animal Animal) (u float64)

Return the additive genetic effect

func GeneticIndex

func GeneticIndex(traitName string, comp string) (index int)

Return the index of this genetic component in the genetic variance matrix

func GestationLengthError

func GestationLengthError() int

func HeiferPregnancyPhenotype

func HeiferPregnancyPhenotype(thisAnimal Animal, today Date) (pheno float64)

Calculate the heifer pregnancy phenotype at a particular day - e.g. at breeding

func HeterosisEffect

func HeterosisEffect(trait string, thisAnimal Animal) (effect float64, l bool)

Return the heterosis effect

func MakeFoundationBulls

func MakeFoundationBulls(
	gvCholesky mat.Cholesky,
	rvCholesky mat.Cholesky,
	param map[string]interface{})

Foundation bulls

func MakeFoundationCowHerd

func MakeFoundationCowHerd(
	gvCholesky mat.Cholesky,
	rvCholesky mat.Cholesky,
	param map[string]interface{}) (cowHerdSize int)

Make a herd of foundation cows

func MakeFoundationHeifers

func MakeFoundationHeifers(
	gvCholesky mat.Cholesky,
	rvCholesky mat.Cholesky,
	param map[string]interface{}) (cowHerdSize int)

Make the foundation heifers

func MatureWeightAtAgePhenotype

func MatureWeightAtAgePhenotype(thisAnimal Animal, today Date) (pheno float64)

Calculate the mature weight phenotype at a particular day - e.g. at weaning

func Phenotype

func Phenotype(thisAnimal Animal, thisTrait string) (pheno float64, l bool)

Calculate raw phenotype

func PhenotypeAtMeanAge

func PhenotypeAtMeanAge(thisAnimal Animal, thisTrait string) (pheno float64, l bool)

Calculate phenotype without adjusting for age

func Puberty

func Puberty(herd *Herd, i int, bredDate Date) bool

Has this animal reached puberty

func Replace

func Replace(herd *Herd, year int)

Select the replacement heifers to enter the cow herd

func ResidualIndex

func ResidualIndex(traitName string) (index int)

Return the trait index in the traits array list

func SetBreedComposition

func SetBreedComposition(a *Animal)

Determine an animal's breed composition from sire and dam

func SexAgeOfDamEffect

func SexAgeOfDamEffect(trait string, thisAnimal Animal) (effect float64)

Return the net AOD effect of even crossbreeds

func SimulateBase

func SimulateBase(Param map[string]interface{}, gvCholesky mat.Cholesky, rvCholesky mat.Cholesky)

Simulate a base set of records to calculate where the MEV deviate from

func Stay2Concept21days

func Stay2Concept21days(s float64) float64

Convert a stayability value to a conception rate in 21 days value Assumes the stayability is for a 60 d breeding season - really 63 but who's counting

func StayAtAgePhenotype

func StayAtAgePhenotype(thisAnimal Animal, today Date) (pheno float64)

Calculate the stayability phenotype at a particular day - e.g. at breeding This is 6 yoa conception rate adjusted to a conception rate at a particular age.

func WeaningWtPhenotype

func WeaningWtPhenotype(thisAnimal Animal) (float64, bool)

phenotype of weaning wt

func WhatAod

func WhatAod(thisAnimal Animal) (aod int)

Return the BIF aod catagory where 0=2yoa, 1=3yoa, 2=4yoa, 3=5 thru9yoa, and 10 = >=10 yoa

func WhatSex

func WhatSex(i int) (code string)

Return the string of codes generated by a number usually random

func WriteCowAgeDistribution

func WriteCowAgeDistribution(herds map[string]Herd, thisYear int, param map[string]interface{})

func PrintCowAgeDistribution(herds []Herd, thisYear int, param map[string]interface{}) {

for h := range herds {
	herds[h].Cows = ActiveCows(&herds[h])

	thisHerd := &herds[h]

	//array := param["ageDist"].([]interface{})

	var ageCounts = make([]int, MaxCowAge+1)

	fmt.Println("Herd name:", thisHerd.HerdName)
	fmt.Println("Total number of cows in this herd (after culling opens): ", len(thisHerd.Cows))
	fmt.Println("Number cows calved by age for Year: ", thisYear+1)
	for i := 0; i < len(thisHerd.Cows); i++ {

		thisAge := int(math.Round((float64(
			thisHerd.Cows[i].BreedingRecords[len(thisHerd.Cows[i].BreedingRecords)-1].CalvingDate-
				thisHerd.Cows[i].BirthDate) / 365.)))
		//fmt.Println("LOC 3", thisAge)
		ageCounts[thisAge]++
	}

	for i := 2; i < len(ageCounts); i++ {
		fmt.Printf("% 5d % 5d\n", i, ageCounts[i])
	}
}

}

func Year

func Year(birthDate Date) int

Types

type Animal

type Animal struct {
	Id        AnimalId // This animal's simulation ID
	Sire      AnimalId // This animal's sire simulation ID
	Dam       AnimalId // This animal's dam simulation ID
	Sex       string   // Sex of this animal
	BirthDate Date     // To calculate age
	YearBorn  int      // Year of simulation born
	Dead      Date     // Animal died - e.g. calving difficulty

	Active         bool // Is this an active member of the herd - Cow or Bull
	DateCowEntered int  // Date a heifer became an active cow
	DateCowCulled  int  // If this is a cow, what year was she culled

	HerdName string // Name of the Herd last active in

	BreedingValue *mat.VecDense // Breeding Values
	Residual      *mat.VecDense // Residual values

	BreedComposition map[string]float64 //
	BreedingRecords  []BreedingRec      // Day of simulation bred if Cow

	AumToWeaning             []Aum_t // By month and year
	AumWeanThruBackgrounding []Aum_t // By month
	CowAum                   []Aum_t

	FeedlotTotalFeedIntake float64 // This animal's feedlot total feed consumption
	HarvestWeight          float64 // Weight as a fat animal at slaughter

	CarcassWeight    float64 // actual carcass weight
	MarblingScore    float64 // actual marbling score when slaughtered
	BackFatThickness float64 // actual backfat thickness when slaughtered
	RibEyArea        float64 // actual ribeye area when slaughtered
}

This is the animal class

func ActiveBulls

func ActiveBulls(herd *Herd) []*Animal

Refresh the list of active cows in the herd

func ActiveCows

func ActiveCows(herd *Herd) []*Animal

Refresh the list of active cows in the herd

type AnimalId

type AnimalId uint32 // Animal identification numbers sequentially generated starting at 1

type Aum_t

type Aum_t struct {
	Year        int     // Year this AUM is incurred
	MonthOfYear int     // Calendar month of the year this Aum was accounted
	Aum         float64 // Aum consumed this month
	Weight      float64 // weight end of this month
	Location    int     // For debug where the call came from
}

type BTS_t

type BTS_t struct {
	Breed string
	Trait string
	Sex   string
	Aod   int
}

Sex by aod by breed by trait

type Bred

type Bred bool // Is the animal pregnant
const (
	Open     Bred = false // Not pregnant
	Pregnant Bred = true  // Is bred
)

type BreedComposition_t

type BreedComposition_t struct {
	Proportion       float64 // cumulative 1st field of CowHerdBreedComposition: key so last value is 100% or 1.0
	BreedProportions map[string]float64
}

type BreedEffects_t

type BreedEffects_t struct {
	TraitName string
	Component string             // "D" for Direct, "M" for Maternal
	CowOrCalf string             // Trait of a cow or trait of a calf - e.g., stay or bw direct
	Effects   map[string]float64 // Array of breed effects in order of the breeds in the 1st row of the BreedEffects: key in master.hjson
}

type BreedingRec

type BreedingRec struct {
	YearBred    int      // Simulation calendar year of breeding
	DateBred    Date     // Within year Simulation date of breeding date. Year = 1 is start of simulation year
	Bred        Bred     // Open or Pregnant
	Bull        AnimalId // Id of sire
	CalvingDate Date     // Simulation date of calving
}

type BreedingRecordsTable_t

type BreedingRecordsTable_t struct {
	CowsExposed        int
	CowsBred           int
	CowsCulledOpen     int
	CowsCulledOld      int
	HeifersExposed     int
	HeifersBred        int
	HeifersCulledOpen  int
	HeifersDiedCalving int
}

type BumpComponent_t

type BumpComponent_t struct {
	TraitName string
	Component string
	Value     float64
}

type Bv

type Bv int

type Component_t

type Component_t struct {
	TraitName string
	Component string
}

type Date

type Date int // Simulation date

func GestationLength

func GestationLength() Date

type FedType

type FedType int // Type of feeding program to slaughter
const (
	CalfFed      FedType = 0 // Fed at younger ages close to weaning
	Conventional FedType = 1 // Fed at conventional ages slaughters around 22 months
	CullHeifer   FedType = 2 // Open heifer bred to calv at 2yoa
	CullCow      FedType = 3 // Any cull older female not a heifer
)

How the animal was finished

type Herd

type Herd struct {

	// These are the parameters read from herds: in the hjson
	HerdName          string  // For example "Spring" or "Fall"
	NumberCows        int     // Target number of cows in this herd
	StartBreeding     Date    // Date starting to breed
	BreedingSeasonLen Date    // Length of breeding season in days
	CowConceptionRate float64 // Average Conception rate per 21 d cycle
	Mean3CycleRate    float64 // stay is based on 3 cycles of exposure

	CalvingDifficultyDistribution distuv.Normal // Unadjusted phenotype probability threshold for breeding set in MakeFoundationHeifers()
	InitialCalvingDeathLessRate   float64       // Initial calving difficulty death loss rate

	// These are periodically reset
	Cows   []*Animal // List of cows active in the herd
	Calves []*Animal // List of pre-weaning calves active in the herd
	Bulls  []*Animal // Herd bulls - can be cleanup

	SumBirthDates []float64 // Sum of the birth dates within a year
	NBorn         []float64 // number of calves born in a birth year

}

type HerdYear_t

type HerdYear_t struct {
	Herd string
	Year int
}

type HeterosisValues_t

type HeterosisValues_t struct {
	TraitName string
	Component string
	Values    map[string]float64 // These are mapped by the string of HeterosisCrossClasses
}

type InterceptSlope_t

type InterceptSlope_t struct {
	Slope float64
	Age   float64
}

Age effects in days

type Sales_t

type Sales_t struct {
	NheadOpen float64 // number of head sold open - e.g., cows
	NheadOld  float64 // number of head sold old
	CumWt     float64 // cumulative weight of nhead
}

type Trait

type Trait string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL