//--------------------------------------------------------------------- /// <summary> /// Adds some biomass for a species to the foliar LITTER pools at a site. /// </summary> public static void AddFoliageLitter(double foliarBiomass, ISpecies species, ActiveSite site) { double inputDecayValue = 1.0; // Decay value is calculated for surface/soil layers (leaf/fine root), // therefore, this is just a dummy value. if(foliarBiomass > 0) { SiteVars.LitterfallC[site] += foliarBiomass * 0.47; LitterLayer.PartitionResidue( foliarBiomass, inputDecayValue, SpeciesData.LeafCN[species], SpeciesData.LeafLignin[species], OtherData.StructuralCN, LayerName.Leaf, LayerType.Surface, site); } }
//--------------------------------------------------------------------- /// <summary> /// Default seed dispersal method. /// </summary> public static float Default(ISpecies species, ActiveSite sourceSite, ActiveSite destinationSite) { // TODO - Based on Brendan Ward's thesis return 0.0f; }
public ProbabilityComputer(ISpecies species) { effDist = species.EffectiveSeedDist; maxDist = species.MaxSeedDist; lambda1 = Math.Log((1-ratio)/effDist); lambda2 = Math.Log(0.01)/maxDist; }
//--------------------------------------------------------------------- public void AddNewCohort(ISpecies species, ActiveSite site) { cohorts[site].AddNewCohort(species, CohortBiomass.InitialBiomass(cohorts[site], site, species)); }
public static float GetFWater(ISpecies species, float pressurehead) { if (pressurehead < 0 || pressurehead > species.H4()) return 0; else if (pressurehead > species.H3()) return 1 - ((pressurehead - species.H3()) / (species.H4() - species.H3())); else if (pressurehead < species.H2()) return pressurehead / species.H2(); else return 1; }
//--------------------------------------------------------------------- public static void MyAddNewCohort(ISpecies species, ActiveSite site) { Assert.IsTrue(speciesThatReproduce.Contains(species)); Assert.AreEqual(expectedSite, site); actualSpecies_AddNewCohort.Add(species); }
public static double Calculate_Establishment(ISpecies Species, float PAR, float PressureHead) { double frad = Math.Pow(SubCanopyLayer.CumputeFrad(PAR, Species.HalfSat()), Species.EstRad()); double fwater = Math.Pow(SubCanopyLayer.GetFWater(Species, PressureHead), Species.EstMoist()); return frad * fwater; }
/// <inheritdoc /> public int PerformAntiSelection(Random rnd, ISpecies species) { int worstIndex = rnd.Next(species.Members.Count); IGenome worst = species.Members[worstIndex]; BasicEA.CalculateScoreAdjustment(worst, Trainer.ScoreAdjusters); for (int i = 0; i < Rounds; i++) { int competitorIndex = rnd.Next(species.Members.Count - 1); IGenome competitor = species.Members[competitorIndex]; // force an invalid genome to lose if (Double.IsInfinity(competitor.AdjustedScore) || Double.IsNaN(competitor.AdjustedScore)) { return competitorIndex; } BasicEA.CalculateScoreAdjustment(competitor, Trainer.ScoreAdjusters); if (!Trainer.SelectionComparer.IsBetterThan(competitor, worst)) { worst = competitor; worstIndex = competitorIndex; } } return worstIndex; }
public static bool Algorithm(ISpecies species, ActiveSite site) { return Reproduction.SufficientLight(species, site) && Reproduction.Establish(species, site) && Reproduction.MaturePresent(species, site); }
public CohortBiomass(ActiveSite Site, ICohort Cohort, int Index) { this.cohort = Cohort; fRad = 0; site = Site; spc = Cohort.Species; }
//--------------------------------------------------------------------- /// <summary> /// Computes the initial biomass for a cohort at a site. /// </summary> public static float[] InitialBiomass(ISpecies species, ISiteCohorts siteCohorts, ActiveSite site) { IEcoregion ecoregion = PlugIn.ModelCore.Ecoregion[site]; double leafFrac = FunctionalType.Table[SpeciesData.FuncType[species]].FCFRACleaf; double branchFraction = FunctionalType.Table[SpeciesData.FuncType[species]].FCFRACbranch; //double Ndemand = 0.0; double B_ACT = SiteVars.ActualSiteBiomass(site); double B_MAX = SpeciesData.B_MAX_Spp[species][ecoregion]; // Initial biomass exponentially declines in response to // competition. double initialBiomass = 0.002 * B_MAX * Math.Exp(-1.6 * B_ACT / B_MAX); //Initial biomass is limited by nitrogen availability. //initialBiomass *= SpeciesData.NLimits[species]; initialBiomass = Math.Max(initialBiomass, 5.0); double initialLeafB = initialBiomass * leafFrac; double initialBranchB = initialBiomass* branchFraction; double initialWoodB = initialBiomass*(1 - leafFrac - branchFraction); double[] initialB = new double[3] { initialWoodB, initialBranchB, initialLeafB }; //PlugIn.ModelCore.Log.WriteLine("Yr={0},Mo={1}, InitialB={2:0.0}, InitBleaf={3:0.00}, InitBwood={4:0.00}. LeafFrac={5:0.0}", PlugIn.ModelCore.CurrentTime, month, initialBiomass, initialB[1], initialB[0], leafFrac); //PlugIn.ModelCore.Log.WriteLine("Yr={0},Mo={1}, B_MAX={2:0.0}, B_ACT={3:0.00}", PlugIn.ModelCore.CurrentTime, month, B_MAX, B_ACT); float[] initialWoodLeafBiomass = new float[3] { (float)initialB[0], (float)initialB[1], (float)initialB[2] }; //wang? return initialWoodLeafBiomass; }
//--------------------------------------------------------------------- /// <summary> /// Initializes a new instance with one young cohort (age = 1). /// </summary> public SpeciesCohorts(ISpecies species) { this.species = species; this.ages = new List<ushort>(); this.isMaturePresent = false; AddNewCohort(); }
//--------------------------------------------------------------------- /// <summary> /// Adds frass for a species to the foliar LITTER pools at a site. /// Assumes that some of the N has been resorbed. /// </summary> public static void AddFrassLitter(double defoliatedLeafBiomass, ISpecies species, ActiveSite site) { double inputDecayValue = 1.0; // Decay value is calculated for surface/soil layers (leaf/fine root), // therefore, this is just a dummy value. if (defoliatedLeafBiomass > 0) { SiteVars.LitterfallC[site] += defoliatedLeafBiomass * 0.47; double frassBiomass = Math.Max(0.0, OtherData.frassdepk * defoliatedLeafBiomass); double frassBiomassC = frassBiomass * 0.47; SiteVars.FrassC[site] += frassBiomassC; LitterLayer.PartitionResidue( frassBiomass, inputDecayValue, OtherData.CNratiofrass, 1.0, 1.0, //OtherData.CNratiofrass, LayerName.Leaf, LayerType.Surface, site); } }
//--------------------------------------------------------------------- public void AddNewCohort(ISpecies species, ActiveSite site) { SiteVars.Cohorts[site].AddNewCohort(species, CohortBiomass.InitialBiomass(species, SiteVars.Cohorts[site], site)); }
//--------------------------------------------------------------------- /// <summary> /// Adds frass for a species to the foliar LITTER pools at a site. /// Assumes that some of the N has been resorbed. /// </summary> public static void AddFrassLitter(double inputFrassBiomass, ISpecies species, ActiveSite site) { double inputDecayValue = 1.0; // Decay value is calculated for surface/soil layers (leaf/fine root), // therefore, this is just a dummy value. if (inputFrassBiomass > 0) { //SiteVars.LitterfallC[site] += defoliatedLeafBiomass * 0.47; //double frassBiomass = Math.Max(0.0, OtherData.frassdepk * defoliatedLeafBiomass); // Frass C added is a function of defoliated leaf biomass, but adjusted for the CN of litter and frass // Any C lost is due to insect metabolism double inputFrassC = inputFrassBiomass * 0.47; double inputFrassN = inputFrassC / (double) SpeciesData.LeafLitterCN[species]; double actualFrassC = inputFrassN * (double) OtherData.CNratiofrass; // the difference between input and actual is C lost to insect metabolism double actualFrassBiomass = actualFrassC / 0.47; //PlugIn.ModelCore.UI.WriteLine("AddFrass.Month={0:0}, inputfrassN={1:0.000}, inputfrassbiomass={2:0.00}, actualfrassbiomass={3:0.00} ", Century.Month, inputFrassN, inputFrassBiomass, actualFrassBiomass); SiteVars.FrassC[site] += actualFrassC; LitterLayer.PartitionResidue( actualFrassBiomass, inputDecayValue, OtherData.CNratiofrass, 0.1, OtherData.StructuralCN, LayerName.Leaf, LayerType.Surface, site); } }
//--------------------------------------------------------------------- /// <summary> /// Computes the initial biomass for a cohort at a site. /// </summary> public static float[] InitialBiomass(ISpecies species, ISiteCohorts siteCohorts, ActiveSite site) { IEcoregion ecoregion = PlugIn.ModelCore.Ecoregion[site]; double leafFrac = FunctionalType.Table[SpeciesData.FuncType[species]].FCFRACleaf; double B_ACT = SiteVars.ActualSiteBiomass(site); double B_MAX = SpeciesData.B_MAX_Spp[species][ecoregion]; // Initial biomass exponentially declines in response to // competition. double initialBiomass = 0.002 * B_MAX * Math.Exp(-1.6 * B_ACT / B_MAX); initialBiomass = Math.Max(initialBiomass, 5.0); double initialLeafB = initialBiomass * leafFrac; double initialWoodB = initialBiomass - initialLeafB; double[] initialB = new double[2]{initialWoodB, initialLeafB}; float[] initialWoodLeafBiomass = new float[2] { (float)initialB[0], (float)initialB[1] }; //PlugIn.ModelCore.UI.WriteLine("Yr={0},Mo={1}, InitialB={2:0.0}, InitBleaf={3:0.00}, InitBwood={4:0.00}. LeafFrac={5:0.0}", PlugIn.ModelCore.CurrentTime, month, initialBiomass, initialB[1], initialB[0], leafFrac); //PlugIn.ModelCore.UI.WriteLine("Yr={0},Mo={1}, B_MAX={2:0.0}, B_ACT={3:0.00}", PlugIn.ModelCore.CurrentTime, month, B_MAX, B_ACT); return initialWoodLeafBiomass; }
/// <summary> /// Adds some biomass for a species to the WOODY pools at a site. /// </summary> public static void AddWoody(double woodyBiomass, ISpecies species, ActiveSite site) { SiteVars.WoodyDebris[site].AddMass(woodyBiomass, SpeciesData.WoodyDebrisDecay[species]); }
float GetFWater(ISpecies species, float pressurehead) { if (pressurehead < 0 || pressurehead > H4[species]) return 0; else if (pressurehead > H3[species]) return 1 - ((pressurehead - H3[species]) / (H4[species] - H3[species])); else if (pressurehead < H2[species]) return pressurehead / H2[species]; else return 1; }
public ReproductionEvent(ILocation location, int generation, Type reproductionType, ISpecies mate, params ISpecies[] children) : base(location, generation) { this.Mate = mate; this.Offspring = new List<ISpecies>(children); this.ReproductionType = reproductionType; }
/// <summary> /// Default method for computing how much a cohort is defoliated at /// a site. /// </summary> /// <returns> /// 0% /// </returns> public static double Compute( ActiveSite site, ISpecies species, int cohortBiomass, int siteBiomass) { return 0.0; }
//--------------------------------------------------------------------- public Cohort(ISpecies species, ushort age, int biomass) { this.species = species; this.data.Age = age; this.data.Biomass = biomass; }
//--------------------------------------------------------------------- public static bool MySeedingAlgorithm(ISpecies species, ActiveSite site) { Assert.IsTrue(expectedSpecies.Contains(species)); Assert.AreEqual(expectedSite, site); actualSpecies_SeedingAlg.Add(species); return speciesThatReproduce.Contains(species); }
public static bool Algorithm(ISpecies species, ActiveSite site) { return Reproduction.SufficientResources(species, site) && Reproduction.Establish(species, site) && Reproduction.MaturePresent(species, site); //SiteVars.Cohorts[site].IsMaturePresent(species); }
public float this[ISpecies species, int pressurehead] { get { if(pressurehead < table[species].Length) return table[species][pressurehead]; return 0; } }
//--------------------------------------------------------------------- /// <summary> /// Determines if there is sufficient light at a site for a species to /// germinate/resprout. /// </summary> public static bool SufficientLight(ISpecies species, ActiveSite site) { byte siteShade = SiteVars.Shade[site]; return (species.ShadeTolerance <= 4 && species.ShadeTolerance > siteShade) || (species.ShadeTolerance == 5 && siteShade > 1); // pg 14, Model description, this ----------------^ may be 2? }
//--------------------------------------------------------------------- /// <summary> /// Calculates available nitrogen from external and internal sources. /// </summary> public static double GetTransN(ISpecies species, double annualLeafTurnover, double leafMortality) { double transN = (annualLeafTurnover + leafMortality) * (SpeciesData.LeafFractionN[species] - SpeciesData.LitterFractionN[species]); return transN; }
//public static bool Establish(double[,] establishment) //--------------------------------------------------------------------- /// <summary> /// Determines if a species can establish on a site. /// </summary> public static bool Establish(ISpecies species, ActiveSite site) { double establishProbability = 0; // Reproduction.GetEstablishProbability(species, site); //return Landis.Model.GenerateUniform() < establishment; return Model.Core.GenerateUniform() < establishProbability; }
//--------------------------------------------------------------------- public void AddNewCohort(ISpecies species, ActiveSite site) { float[] initialBiomass = CohortBiomass.InitialBiomass(SiteVars.Cohorts[site], site, species); float initialWoodMass = initialBiomass[0]; float initialLeafMass = initialBiomass[1]; SiteVars.Cohorts[site].AddNewCohort(species, initialWoodMass, initialLeafMass); }
/// <summary> /// Construct the EA worker. /// </summary> /// <param name="theTrain">The trainer.</param> /// <param name="theSpecies">The species.</param> public EAWorker(BasicEA theTrain, ISpecies theSpecies) { _train = theTrain; _species = theSpecies; _rnd = _train.RandomNumberFactory.Factor(); _parents = new IGenome[_train.Operators.MaxParents()]; _children = new IGenome[_train.Operators.MaxOffspring()]; }
public static float[] ReadEstablishmentTable(string Keyword, string Filename, ISpecies species) { keyword = Keyword; filename = Filename; string line=""; try { List<string> content = new List<string>(System.IO.File.ReadAllLines(filename)); MakeSureFileContains(Keyword); MakeSureFileContains("CategoryMin"); MakeSureFileContains(species.Name); for (int l = 0; l < content.Count; l++) { line = content[l]; if (line.Contains("<<")) { line= line.Remove(line.IndexOf("<<")); } if (line.Contains("CategoryMin")) { string[] terms = line.Trim().Split('\t'); CategoryMin = new int[terms.Count() - 1]; CategoryValues = new float[terms.Count() - 1]; for (int t = 1; t < terms.Count(); t++) { CategoryMin[t - 1] = (int)(100 * float.Parse(terms[t])); } } if (line.Contains(species.Name)) { string[] terms = line.Trim().Split('\t'); for (int t = 1; t < terms.Count(); t++) { if (float.TryParse(terms[t],out CategoryValues[t - 1])==false) { throw new System.Exception("Irregular value in "+ filename); } } } } MakeSureValuesAreFractions(CategoryValues); MakeSureCategoriesDescend(CategoryValues); MakeSureCategoriesDescend(CategoryMin); return GetProbabilityArray(CategoryMin, CategoryValues); } catch(System.Exception e) { throw new System.Exception("Cannot read "+ filename + " " + e.Message +" "+ line); } }
//--------------------------------------------------------------------- /// <summary> /// Add a new cohort to a site following reproduction or planting. Does not include initial communities. /// This is a Delegate method to base succession. /// </summary> public void AddNewCohort(ISpecies species, ActiveSite site) { float[] initialBiomass = CohortBiomass.InitialBiomass(species, SiteVars.Cohorts[site], site); SiteVars.Cohorts[site].AddNewCohort(species, 1, initialBiomass[0], initialBiomass[1]); }
//--------------------------------------------------------------------- private double UpdateDeadBiomass(ICohort cohort, double actualANPP, double totalMortality, ActiveSite site, double newBiomass) { ISpecies species = cohort.Species; double leafLongevity = SpeciesData.LeafLongevity[species]; double cohortBiomass = newBiomass; // Mortality is for the current year's biomass. double leafFraction = ComputeFractionANPPleaf(species); // First, deposit the a portion of the leaf mass directly onto the forest floor. // In this way, the actual amount of leaf biomass is added for the year. // In addition, add the equivalent portion of fine roots to the surface layer. // 0.8 was used to calibrate the model to steady-state Nitrogen. Without this reduction, total N // increases by 0.038% each year. // Remove jan 2020 to more closely match code with the current Biomass succession model //double annualLeafANPP = actualANPP * leafFraction * 0.8; double annualLeafANPP = actualANPP * leafFraction; // -------------------------------------------------------------------------------- // The next section allocates mortality from standing (wood and leaf) biomass, i.e., // biomass that has accrued from previous years' growth. // Subtract annual leaf growth as that was taken care of above. totalMortality -= annualLeafANPP; // Assume that standing foliage is equal to this years annualLeafANPP * leaf longevity // minus this years leaf ANPP. This assumes that actual ANPP has been relatively constant // over the past 2 or 3 years (if coniferous). double standing_nonwood = (annualLeafANPP * leafLongevity) - annualLeafANPP; double standing_wood = Math.Max(0, cohortBiomass - standing_nonwood); double fractionStandingNonwood = standing_nonwood / cohortBiomass; // Assume that the remaining mortality is divided proportionally // between the woody mass and non-woody mass (Niklaus & Enquist, // 2002). Do not include current years growth. double mortality_nonwood = Math.Max(0.0, totalMortality * fractionStandingNonwood); double mortality_wood = Math.Max(0.0, totalMortality - mortality_nonwood); if (mortality_wood < 0 || mortality_nonwood < 0) { throw new ApplicationException("Error: Woody input is < 0"); } // Total mortality not including annual leaf litter M_noLeafLitter = (int)mortality_wood; SiteVars.soilClass[site].CollectBiomassMortality(species, cohort.Age, mortality_wood, (mortality_nonwood + annualLeafANPP), 0); //add root biomass information - now calculated based on both woody and non-woody biomass Roots.CalculateRootTurnover(site, species, cohortBiomass); SiteVars.soilClass[site].CollectBiomassMortality(species, cohort.Age, Roots.CoarseRootTurnover, Roots.FineRootTurnover, 1); //if biomass is going down, then we need to capture a decrease in the roots as well. if (cohortBiomass < cohort.Biomass) { double preMortRoots = Roots.CalculateRootBiomass(site, species, cohort.Biomass); double preMortCoarse = Roots.CoarseRoot; double preMortFine = Roots.FineRoot; double TotRoots = Roots.CalculateRootBiomass(site, species, cohortBiomass); if (preMortRoots > TotRoots) //if the root biomass went down, then we need to allocate that difference. { //We will allocate the total root decline to the different pools based on the relative proportions //prior to the decline. (Note that we are not calculating actual declines for each type because //sometimes if we are changing calculation methods, we may change the allocation and may cause a large //decrease in one pool and an increase in the other.) double diffFine = (preMortFine / preMortRoots) * (preMortRoots - TotRoots); double diffCoarse = (preMortRoots - TotRoots) - diffFine; SiteVars.soilClass[site].CollectBiomassMortality(species, cohort.Age, diffCoarse, diffFine, 1); //write a note to the file if the allocation changes unexpectedly, but not during spin-up if (((preMortCoarse - Roots.CoarseRoot) < 0 || (preMortFine - Roots.FineRoot) < 0) && PlugIn.ModelCore.CurrentTime > 0) { string strCombo = "from: " + preMortCoarse; strCombo += " to: " + Roots.CoarseRoot; string strCombo2 = "from: " + preMortFine; strCombo2 += " to: " + Roots.FineRoot; PlugIn.ModelCore.UI.WriteLine("Root Dynamics: Overall root biomass declined but note change in coarse root allocation " + strCombo + " and fine root allocation" + strCombo2); } } else if (PlugIn.ModelCore.CurrentTime > 0) { //write a note to the file if the root biomass increases while abio decreases, but not during spin-up string strCombo = "from: " + cohort.Biomass; strCombo += " to: " + cohortBiomass; string strCombo2 = "from: " + preMortRoots; strCombo2 += " to: " + TotRoots; PlugIn.ModelCore.UI.WriteLine("Root Dynamics: Note that aboveground biomass decreased " + strCombo + " but root biomass increased " + strCombo2); } } if (PlugIn.ModelCore.CurrentTime == 0) { SiteVars.soilClass[site].CollectBiomassMortality(species, cohort.Age, standing_wood, standing_nonwood, 3); Roots.CalculateRootTurnover(site, species, (standing_wood + standing_nonwood)); SiteVars.soilClass[site].CollectBiomassMortality(species, cohort.Age, Roots.CoarseRootTurnover, Roots.FineRootTurnover, 4); } return(annualLeafANPP + mortality_nonwood + mortality_wood); }
//--------------------------------------------------------------------- public void SetLeafLongevity(ISpecies species, InputValue <double> newValue) { Debug.Assert(species != null); leafLongevity[species] = newValue.CheckInRange(1.0, 10.0, "leafLongevity"); }
//--------------------------------------------------------------------- protected override ISuitabilityParameters Parse() { InputVar <string> landisData = new InputVar <string>("LandisData"); ReadVar(landisData); if (landisData.Value.Actual != "HabitatSuitabilityFile") { throw new InputValueException(landisData.Value.String, "The value is not \"{0}\"", "HabitatSuitabilityFile"); } SuitabilityParameters suitabilityParameters = new SuitabilityParameters(PlugIn.ModelCore.Species.Count); InputVar <string> habitatName = new InputVar <string>("HabitatName"); ReadVar(habitatName); suitabilityParameters.HabitatName = habitatName.Value; InputVar <string> suitabilityType = new InputVar <string>("SuitabilityType"); ReadVar(suitabilityType); if ((suitabilityType.Value.Actual != "AgeClass_ForestType") & (suitabilityType.Value.Actual != "AgeClass_TimeSinceDisturbance") & (suitabilityType.Value.Actual != "ForestType_TimeSinceDisturbance")) { throw new InputValueException(suitabilityType.Value.String, "The value is not \"{0}\"", "AgeClass_ForestType or AgeClass_TimeSinceDisturbance or ForestType_TimeSinceDisturbance"); } suitabilityParameters.SuitabilityType = suitabilityType.Value; List <string> keywordList = new List <string>(); if (suitabilityType.Value == "AgeClass_ForestType") { keywordList.Add("ReclassCoefficients"); keywordList.Add("ForestTypeTable"); keywordList.Add("SuitabilityTable"); } else if (suitabilityType.Value == "AgeClass_TimeSinceDisturbance") { keywordList.Add("DisturbanceTable"); keywordList.Add("SuitabilityTable"); } else if (suitabilityType.Value == "ForestType_TimeSinceDisturbance") { keywordList.Add("ReclassCoefficients"); keywordList.Add("ForestTypeTable"); keywordList.Add("DisturbanceTable"); keywordList.Add("SuitabilityTable"); } InputVar <string> speciesName = new InputVar <string>("Species"); int keywordIndex = 0; foreach (string keyword in keywordList) { if (keyword == "ReclassCoefficients") { // Table of reclass coefficients ReadName("ReclassCoefficients"); InputVar <double> reclassCoeff = new InputVar <double>("Reclass Coefficient"); Dictionary <string, int> lineNumbers = new Dictionary <string, int>(); bool continueLoop = true; while (continueLoop) { StringReader currentLine = new StringReader(CurrentLine); ReadValue(speciesName, currentLine); ISpecies species = GetSpecies(speciesName.Value); CheckForRepeatedName(speciesName.Value, "species", lineNumbers); ReadValue(reclassCoeff, currentLine); suitabilityParameters.ReclassCoefficients[species.Index] = reclassCoeff.Value; CheckNoDataAfter(string.Format("the {0} column", reclassCoeff.Name), currentLine); GetNextLine(); if (keywordIndex + 1 == keywordList.Count) { continueLoop = !AtEndOfInput; } else { continueLoop = (CurrentName != keywordList[keywordIndex + 1]); } } } if (keyword == "ForestTypeTable") { // Table of forest types ReadName("ForestTypeTable"); InputVar <string> forestType = new InputVar <string>("Forest Type"); Dictionary <string, int> forestTypeLineNumbers = new Dictionary <string, int>(); IMapDefinition mapDefn = null; mapDefn = new MapDefinition(); mapDefn.Name = "ForestTypes"; suitabilityParameters.ForestTypes.Add(mapDefn); bool continueLoop = true; while (continueLoop) { StringReader currentLine = new StringReader(CurrentLine); ReadValue(forestType, currentLine); CheckForRepeatedName(forestType.Value, "forest type", forestTypeLineNumbers); IForestType currentForestType = new ForestType(PlugIn.ModelCore.Species.Count); currentForestType.Name = forestType.Value; mapDefn.ForestTypes.Add(currentForestType); // Read species for forest types List <string> speciesNames = new List <string>(); TextReader.SkipWhitespace(currentLine); while (currentLine.Peek() != -1) { ReadValue(speciesName, currentLine); string name = speciesName.Value.Actual; bool negativeMultiplier = name.StartsWith("-"); if (negativeMultiplier) { name = name.Substring(1); if (name.Length == 0) { throw new InputValueException(speciesName.Value.String, "No species name after \"-\""); } } ISpecies species = GetSpecies(new InputValue <string>(name, speciesName.Value.String)); if (speciesNames.Contains(species.Name)) { throw NewParseException("The species {0} appears more than once.", species.Name); } speciesNames.Add(species.Name); currentForestType[species.Index] = negativeMultiplier ? -1 : 1; TextReader.SkipWhitespace(currentLine); } if (speciesNames.Count == 0) { throw NewParseException("At least one species is required."); } GetNextLine(); if (keywordIndex + 1 == keywordList.Count) { continueLoop = !AtEndOfInput; } else { continueLoop = (CurrentName != keywordList[keywordIndex + 1]); } } } if (keyword == "DisturbanceTable") { // Table of Disturbance classes InputVar <string> disturbanceType = new InputVar <string>("DisturbanceTable"); ReadVar(disturbanceType); Dictionary <int, double> fireSeverityTable = new Dictionary <int, double>(); Dictionary <string, double> prescriptionTable = new Dictionary <string, double>(); if (disturbanceType.Value == "Fire") { InputVar <int> severityClass = new InputVar <int>("Fire Severity Class"); InputVar <double> fireSuitability = new InputVar <double>("Fire Class Suitability"); suitabilityParameters.DisturbanceType = "Fire"; bool continueLoop = true; while (continueLoop) { StringReader currentLine = new StringReader(CurrentLine); TextReader.SkipWhitespace(currentLine); ReadValue(severityClass, currentLine); ReadValue(fireSuitability, currentLine); fireSeverityTable.Add(severityClass.Value, fireSuitability.Value); GetNextLine(); if (keywordIndex + 1 == keywordList.Count) { continueLoop = !AtEndOfInput; } else { continueLoop = (CurrentName != keywordList[keywordIndex + 1]); } } } else if (disturbanceType.Value == "Harvest") { InputVar <string> prescriptionName = new InputVar <string>("Prescription Name"); InputVar <double> prescriptionSuitability = new InputVar <double>("Prescription Suitability"); suitabilityParameters.DisturbanceType = "Harvest"; bool continueLoop = true; while (continueLoop) { StringReader currentLine = new StringReader(CurrentLine); TextReader.SkipWhitespace(currentLine); ReadValue(prescriptionName, currentLine); ReadValue(prescriptionSuitability, currentLine); prescriptionTable.Add(prescriptionName.Value, prescriptionSuitability.Value); GetNextLine(); if (keywordIndex + 1 == keywordList.Count) { continueLoop = !AtEndOfInput; } else { continueLoop = (CurrentName != keywordList[keywordIndex + 1]); } } } else { throw new InputValueException(disturbanceType.Value.String, "The value is not \"{0}\"", "Fire or Harvest"); } suitabilityParameters.FireSeverities = fireSeverityTable; suitabilityParameters.HarvestPrescriptions = prescriptionTable; } if (keyword == "SuitabilityTable") { // Table of suitabilities ReadName("SuitabilityTable"); Dictionary <string, Dictionary <int, double> > suitabilityTable = new Dictionary <string, Dictionary <int, double> >(); InputVar <int> ageCutoff = new InputVar <int>("Age Cutoff"); InputVar <string> suitabilityClass = new InputVar <string>("Suitability Class"); InputVar <double> suitabilityValue = new InputVar <double>("Suitability Value"); List <int> ageList = new List <int>(); StringReader currentLine = new StringReader(CurrentLine); while (currentLine.Peek() != -1) { ReadValue(ageCutoff, currentLine); ageList.Add(ageCutoff.Value); } GetNextLine(); bool continueLoop = true; while (continueLoop) { currentLine = new StringReader(CurrentLine); //TextReader.SkipWhitespace(currentLine); ReadValue(suitabilityClass, currentLine); Dictionary <int, double> suitabilityRow = new Dictionary <int, double>(); foreach (int age in ageList) { ReadValue(suitabilityValue, currentLine); suitabilityRow.Add(age, suitabilityValue.Value); } suitabilityTable.Add(suitabilityClass.Value, suitabilityRow); GetNextLine(); if (keywordIndex + 1 == keywordList.Count) { continueLoop = !AtEndOfInput; } else { continueLoop = (CurrentName != keywordList[keywordIndex + 1]); } } suitabilityParameters.Suitabilities = suitabilityTable; } keywordIndex++; } return(suitabilityParameters); }
public void SetMaxBiomass(ISpecies species, int newValue) { Debug.Assert(species != null); maxBiomass[species] = VerifyRange(newValue, 2, 100000); }
public void SetGDDmin(ISpecies species, int newValue) { Debug.Assert(species != null); gddMin[species] = VerifyRange(newValue, 1, 4000); }
public void SetMinJanTemp(ISpecies species, int newValue) { Debug.Assert(species != null); minJanTemp[species] = VerifyRange(newValue, -60, 20); }
//--------------------------------------------------------------------- protected override Dictionary <int, IDynamicInputRecord[, ]> Parse() { ReadLandisDataVar(); //InputVar<string> landisData = new InputVar<string>("LandisData"); //ReadVar(landisData); //if (landisData.Value.Actual != PlugIn.ExtensionName) // throw new InputValueException(landisData.Value.String, "The value is not \"{0}\"", PlugIn.ExtensionName); Dictionary <int, IDynamicInputRecord[, ]> allData = new Dictionary <int, IDynamicInputRecord[, ]>(); //--------------------------------------------------------------------- //Read in climate data: InputVar <int> year = new InputVar <int>("Time step for updating values"); InputVar <string> ecoregionName = new InputVar <string>("Ecoregion Name"); InputVar <string> speciesName = new InputVar <string>("Species Name"); InputVar <double> pest = new InputVar <double>("Probability of Establishment"); //InputVar<int> anpp = new InputVar<int>("ANPP"); //InputVar<int> bmax = new InputVar<int>("Maximum Biomass"); while (!AtEndOfInput) { StringReader currentLine = new StringReader(CurrentLine); ReadValue(year, currentLine); int yr = year.Value.Actual; if (!allData.ContainsKey(yr)) { IDynamicInputRecord[,] inputTable = new IDynamicInputRecord[PlugIn.ModelCore.Species.Count, PlugIn.ModelCore.Ecoregions.Count]; allData.Add(yr, inputTable); PlugIn.ModelCore.UI.WriteLine(" Dynamic Input Parser: Add new year = {0}.", yr); } ReadValue(ecoregionName, currentLine); IEcoregion ecoregion = GetEcoregion(ecoregionName.Value); ReadValue(speciesName, currentLine); ISpecies species = GetSpecies(speciesName.Value); IDynamicInputRecord dynamicInputRecord = new DynamicInputRecord(); ReadValue(pest, currentLine); dynamicInputRecord.ProbEst = pest.Value; //ReadValue(anpp, currentLine); //dynamicInputRecord.ANPP_MAX_Spp = anpp.Value; //ReadValue(bmax, currentLine); //dynamicInputRecord.B_MAX_Spp = bmax.Value; allData[yr][species.Index, ecoregion.Index] = dynamicInputRecord; CheckNoDataAfter("the " + pest.Name + " column", currentLine); GetNextLine(); } return(allData); }
public void SetLeafLignin(ISpecies species, double newValue) { Debug.Assert(species != null); leafLignin[species] = VerifyRange(newValue, 0.0, 0.4); }
public static bool Algorithm(ISpecies species, ActiveSite site) { return(Reproduction.SufficientResources(species, site) && Reproduction.Establish(species, site)); }
//--------------------------------------------------------------------- public void SetWoodyDecayRate(ISpecies species, InputValue <double> newValue) { Debug.Assert(species != null); woodyDecayRate[species] = newValue.CheckInRange(0.0, 1.0, "woodyDecayRate"); }
//--------------------------------------------------------------------- /// <summary> /// Are the conditions necessary for planting a species at site /// satified? /// </summary> protected override bool PreconditionsSatisfied(ISpecies species, ActiveSite site) { return(true); //return Reproduction.GetEstablishProbability(species, site) > 0; }
//--------------------------------------------------------------------- public void SetMortCurveShapeParm(ISpecies species, InputValue <double> newValue) { Debug.Assert(species != null); mortCurveShapeParm[species] = newValue.CheckInRange(5.0, 25.0, "mortCurveShapeParm"); }
/// <inheritdoc/> public int PerformAntiSelection(Random rnd, ISpecies species) { return(species.Members.Count - PerformSelection(rnd, species)); }
//--------------------------------------------------------------------- /// <summary> /// Records an amount of biomass that has been cut for a species. /// </summary> public static void RecordHarvest(ISpecies species, int biomass) { biomassHarvested[species] += biomass; }
//--------------------------------------------------------------------- /// <summary> /// Determines if there is a mature cohort at a site. /// This is a Delegate method to base succession. /// </summary> public bool MaturePresent(ISpecies species, ActiveSite site) { return(SiteVars.Cohorts[site].IsMaturePresent(species)); }
public void SetLeafLongevity(ISpecies species, double newValue) { Debug.Assert(species != null); leafLongevity[species] = VerifyRange(newValue, 1.0, 10.0); }
//--------------------------------------------------------------------- protected override IInputParameters Parse() { //InputVar<string> landisData = new InputVar<string>("LandisData"); //ReadVar(landisData); //if (landisData.Value.Actual != PlugIn.ExtensionName) // throw new InputValueException(landisData.Value.String, "The value is not \"{0}\"", PlugIn.ExtensionName); ReadLandisDataVar(); InputParameters parameters = new InputParameters(PlugIn.ModelCore.Species.Count); InputVar <int> timestep = new InputVar <int>("Timestep"); ReadVar(timestep); parameters.Timestep = timestep.Value; // Table of reclass coefficients InputVar <string> speciesName = new InputVar <string>("Species"); InputVar <double> reclassCoeff = new InputVar <double>("Reclass Coefficient"); Dictionary <string, int> lineNumbers = new Dictionary <string, int>(); const string ReclassMaps = "ReclassMaps"; while (!AtEndOfInput && CurrentName != ReclassMaps) { StringReader currentLine = new StringReader(CurrentLine); ReadValue(speciesName, currentLine); ISpecies species = GetSpecies(speciesName.Value); CheckForRepeatedName(speciesName.Value, "species", lineNumbers); ReadValue(reclassCoeff, currentLine); parameters.ReclassCoefficients[species.Index] = reclassCoeff.Value; CheckNoDataAfter(string.Format("the {0} column", reclassCoeff.Name), currentLine); GetNextLine(); } // Read definitions of reclass maps ReadName(ReclassMaps); InputVar <string> mapName = new InputVar <string>("Map Name"); InputVar <string> forestType = new InputVar <string>("Forest Type"); lineNumbers.Clear(); Dictionary <string, int> forestTypeLineNumbers = new Dictionary <string, int>(); const string MapFileNames = "MapFileNames"; const string nameDelimiter = "->"; // delimiter that separates map name and forest type IMapDefinition mapDefn = null; while (!AtEndOfInput && CurrentName != MapFileNames) { StringReader currentLine = new StringReader(CurrentLine); // If the current line has the delimiter, then read the map // name. if (CurrentLine.Contains(nameDelimiter)) { ReadValue(mapName, currentLine); CheckForRepeatedName(mapName.Value, "map name", lineNumbers); mapDefn = new MapDefinition(); mapDefn.Name = mapName.Value; parameters.ReclassMaps.Add(mapDefn); TextReader.SkipWhitespace(currentLine); string word = TextReader.ReadWord(currentLine); if (word != nameDelimiter) { throw NewParseException("Expected \"{0}\" after the map name {1}.", nameDelimiter, mapName.Value.String); } forestTypeLineNumbers.Clear(); } else { // If there is no name delimiter and we don't have the // name for the first map yet, then it's an error. if (mapDefn == null) { throw NewParseException("Expected a line with map name followed by \"{0}\"", nameDelimiter); } } ReadValue(forestType, currentLine); CheckForRepeatedName(forestType.Value, "forest type", forestTypeLineNumbers); IForestType currentForestType = new ForestType(PlugIn.ModelCore.Species.Count); currentForestType.Name = forestType.Value; mapDefn.ForestTypes.Add(currentForestType); // Read species for forest types List <string> speciesNames = new List <string>(); TextReader.SkipWhitespace(currentLine); while (currentLine.Peek() != -1) { ReadValue(speciesName, currentLine); string name = speciesName.Value.Actual; bool negativeMultiplier = name.StartsWith("-"); if (negativeMultiplier) { name = name.Substring(1); if (name.Length == 0) { throw new InputValueException(speciesName.Value.String, "No species name after \"-\""); } } ISpecies species = GetSpecies(new InputValue <string>(name, speciesName.Value.String)); if (speciesNames.Contains(species.Name)) { throw NewParseException("The species {0} appears more than once.", species.Name); } speciesNames.Add(species.Name); currentForestType[species.Index] = negativeMultiplier ? -1 : 1; TextReader.SkipWhitespace(currentLine); } if (speciesNames.Count == 0) { throw NewParseException("At least one species is required."); } GetNextLine(); } // Template for filenames of reclass maps InputVar <string> mapFileNames = new InputVar <string>(MapFileNames); ReadVar(mapFileNames); parameters.MapFileNames = mapFileNames.Value; CheckNoDataAfter(string.Format("the {0} parameter", MapFileNames)); return(parameters); //.GetComplete(); }
public void SetMaxDrought(ISpecies species, double newValue) { Debug.Assert(species != null); maxDrought[species] = VerifyRange(newValue, 0.0, 1.0); }
//--------------------------------------------------------------------- /// <summary> /// Initializes a new instance with no cohorts. /// </summary> /// <remarks> /// Private constructor used by Clone method. /// </remarks> private SpeciesCohorts(ISpecies species) { this.species = species; }
public void SetGDDmax(ISpecies species, int newValue) { Debug.Assert(species != null); gddMax[species] = VerifyRange(newValue, 500, 7000); }
//--------------------------------------------------------------------- protected override IInputParameters Parse() { ReadLandisDataVar(); int numLitterTypes = 4; int numFunctionalTypes = 25; InputParameters parameters = new InputParameters(speciesDataset, numLitterTypes, numFunctionalTypes); InputVar <int> timestep = new InputVar <int>("Timestep"); ReadVar(timestep); parameters.Timestep = timestep.Value; InputVar <SeedingAlgorithms> seedAlg = new InputVar <SeedingAlgorithms>("SeedingAlgorithm"); ReadVar(seedAlg); parameters.SeedAlgorithm = seedAlg.Value; //--------------------------------------------------------------------------------- InputVar <string> initCommunities = new InputVar <string>("InitialCommunities"); ReadVar(initCommunities); parameters.InitialCommunities = initCommunities.Value; InputVar <string> communitiesMap = new InputVar <string>("InitialCommunitiesMap"); ReadVar(communitiesMap); parameters.InitialCommunitiesMap = communitiesMap.Value; InputVar <string> climateConfigFile = new InputVar <string>("ClimateConfigFile"); ReadVar(climateConfigFile); parameters.ClimateConfigFile = climateConfigFile.Value; InputVar <string> ageOnlyDisturbanceParms = new InputVar <string>("AgeOnlyDisturbances:BiomassParameters"); ReadVar(ageOnlyDisturbanceParms); parameters.AgeOnlyDisturbanceParms = ageOnlyDisturbanceParms.Value; InputVar <string> soilDepthMapName = new InputVar <string>("SoilDepthMapName"); ReadVar(soilDepthMapName); parameters.SoilDepthMapName = soilDepthMapName.Value; InputVar <string> soilDrainMapName = new InputVar <string>("SoilDrainMapName"); ReadVar(soilDrainMapName); parameters.SoilDrainMapName = soilDrainMapName.Value; InputVar <string> soilBaseFlowMapName = new InputVar <string>("SoilBaseFlowMapName"); ReadVar(soilBaseFlowMapName); parameters.SoilBaseFlowMapName = soilBaseFlowMapName.Value; InputVar <string> soilStormFlowMapName = new InputVar <string>("SoilStormFlowMapName"); ReadVar(soilStormFlowMapName); parameters.SoilStormFlowMapName = soilStormFlowMapName.Value; InputVar <string> soilFCMapName = new InputVar <string>("SoilFieldCapacityMapName"); ReadVar(soilFCMapName); parameters.SoilFieldCapacityMapName = soilFCMapName.Value; InputVar <string> soilWPMapName = new InputVar <string>("SoilWiltingPointMapName"); ReadVar(soilWPMapName); parameters.SoilWiltingPointMapName = soilWPMapName.Value; InputVar <string> soilSandMapName = new InputVar <string>("SoilPercentSandMapName"); ReadVar(soilSandMapName); parameters.SoilPercentSandMapName = soilSandMapName.Value; InputVar <string> soilClayMapName = new InputVar <string>("SoilPercentClayMapName"); ReadVar(soilClayMapName); parameters.SoilPercentClayMapName = soilClayMapName.Value; InputVar <string> som1CsurfMapName = new InputVar <string>("InitialSOM1CsurfMapName"); ReadVar(som1CsurfMapName); parameters.InitialSOM1CSurfaceMapName = som1CsurfMapName.Value; InputVar <string> som1NsurfMapName = new InputVar <string>("InitialSOM1NsurfMapName"); ReadVar(som1NsurfMapName); parameters.InitialSOM1NSurfaceMapName = som1NsurfMapName.Value; InputVar <string> som1CsoilMapName = new InputVar <string>("InitialSOM1CsoilMapName"); ReadVar(som1CsoilMapName); parameters.InitialSOM1CSoilMapName = som1CsoilMapName.Value; InputVar <string> som1NsoilMapName = new InputVar <string>("InitialSOM1NsoilMapName"); ReadVar(som1NsoilMapName); parameters.InitialSOM1NSoilMapName = som1NsoilMapName.Value; InputVar <string> som2CMapName = new InputVar <string>("InitialSOM2CMapName"); ReadVar(som2CMapName); parameters.InitialSOM2CMapName = som2CMapName.Value; InputVar <string> som2NMapName = new InputVar <string>("InitialSOM2NMapName"); ReadVar(som2NMapName); parameters.InitialSOM2NMapName = som2NMapName.Value; InputVar <string> som3CMapName = new InputVar <string>("InitialSOM3CMapName"); ReadVar(som3CMapName); parameters.InitialSOM3CMapName = som3CMapName.Value; InputVar <string> som3NMapName = new InputVar <string>("InitialSOM3NMapName"); ReadVar(som3NMapName); parameters.InitialSOM3NMapName = som3NMapName.Value; InputVar <string> deadSurfMapName = new InputVar <string>("InitialDeadWoodSurfaceMapName"); ReadVar(deadSurfMapName); parameters.InitialDeadSurfaceMapName = deadSurfMapName.Value; InputVar <string> deadSoilMapName = new InputVar <string>("InitialDeadCoarseRootsMapName"); ReadVar(deadSoilMapName); parameters.InitialDeadSoilMapName = deadSoilMapName.Value; InputVar <bool> calimode = new InputVar <bool>("CalibrateMode"); if (ReadOptionalVar(calimode)) { parameters.CalibrateMode = calimode.Value; } else { parameters.CalibrateMode = false; } InputVar <string> wt = new InputVar <string>("WaterDecayFunction"); ReadVar(wt); parameters.WType = WParse(wt.Value); InputVar <double> pea = new InputVar <double>("ProbabilityEstablishAdjust"); ReadVar(pea); parameters.ProbEstablishAdjustment = pea.Value; InputVar <double> iMN = new InputVar <double>("InitialMineralN"); ReadVar(iMN); parameters.SetInitMineralN(iMN.Value); InputVar <double> ans = new InputVar <double>("AtmosphericNSlope"); ReadVar(ans); parameters.SetAtmosNslope(ans.Value); InputVar <double> ani = new InputVar <double>("AtmosphericNIntercept"); ReadVar(ani); parameters.SetAtmosNintercept(ani.Value); InputVar <double> lat = new InputVar <double>("Latitude"); ReadVar(lat); parameters.SetLatitude(lat.Value); InputVar <double> denits = new InputVar <double>("DenitrificationRate"); ReadVar(denits); parameters.SetDenitrif(denits.Value); InputVar <double> drsoms = new InputVar <double>("DecayRateSurf"); ReadVar(drsoms); parameters.SetDecayRateSurf(drsoms.Value); InputVar <double> drsom1 = new InputVar <double>("DecayRateSOM1"); ReadVar(drsom1); parameters.SetDecayRateSOM1(drsom1.Value); InputVar <double> drsom2 = new InputVar <double>("DecayRateSOM2"); ReadVar(drsom2); parameters.SetDecayRateSOM2(drsom2.Value); InputVar <double> drsom3 = new InputVar <double>("DecayRateSOM3"); ReadVar(drsom3); parameters.SetDecayRateSOM3(drsom3.Value); InputVar <string> anppMaps = new InputVar <string>("ANPPMapNames"); if (ReadOptionalVar(anppMaps)) { PlugIn.ANPPMapNames = anppMaps.Value; InputVar <int> anppMapFreq = new InputVar <int>("ANPPMapFrequency"); ReadVar(anppMapFreq); PlugIn.ANPPMapFrequency = anppMapFreq.Value; } InputVar <string> aneeMaps = new InputVar <string>("ANEEMapNames"); if (ReadOptionalVar(aneeMaps)) { PlugIn.ANEEMapNames = aneeMaps.Value; InputVar <int> aneeMapFreq = new InputVar <int>("ANEEMapFrequency"); ReadVar(aneeMapFreq); PlugIn.ANEEMapFrequency = aneeMapFreq.Value; } InputVar <string> soilCarbonMaps = new InputVar <string>("SoilCarbonMapNames"); if (ReadOptionalVar(soilCarbonMaps)) { PlugIn.SoilCarbonMapNames = soilCarbonMaps.Value; InputVar <int> soilCarbonMapFreq = new InputVar <int>("SoilCarbonMapFrequency"); ReadVar(soilCarbonMapFreq); PlugIn.SoilCarbonMapFrequency = soilCarbonMapFreq.Value; } InputVar <string> soilNitrogenMaps = new InputVar <string>("SoilNitrogenMapNames"); if (ReadOptionalVar(soilNitrogenMaps)) { PlugIn.SoilNitrogenMapNames = soilNitrogenMaps.Value; InputVar <int> soilNitrogenMapFreq = new InputVar <int>("SoilNitrogenMapFrequency"); ReadVar(soilNitrogenMapFreq); PlugIn.SoilNitrogenMapFrequency = soilNitrogenMapFreq.Value; } InputVar <string> totalCMaps = new InputVar <string>("TotalCMapNames"); if (ReadOptionalVar(totalCMaps)) { PlugIn.TotalCMapNames = totalCMaps.Value; InputVar <int> totalCMapFreq = new InputVar <int>("TotalCMapFrequency"); ReadVar(totalCMapFreq); PlugIn.TotalCMapFrequency = totalCMapFreq.Value; } //-------------------------- // MinRelativeBiomass table ReadName("MaximumLAI"); InputVar <byte> shadeClassVar = new InputVar <byte>("Shade Class"); InputVar <double> maxLAI = new InputVar <double>("Maximum LAI"); for (byte shadeClass = 1; shadeClass <= 5; shadeClass++) { if (AtEndOfInput) { throw NewParseException("Expected a line with available light class {0}", shadeClass); } StringReader currentLine = new StringReader(CurrentLine); ReadValue(shadeClassVar, currentLine); if (shadeClassVar.Value.Actual != shadeClass) { throw new InputValueException(shadeClassVar.Value.String, "Expected the available light class {0}", shadeClass); } ReadValue(maxLAI, currentLine); parameters.SetMaximumShadeLAI(shadeClass, maxLAI.Value); CheckNoDataAfter("the " + maxLAI + " column", currentLine); GetNextLine(); } //---------------------------------------------------------- // Read table of sufficient light probabilities. // Available light classes are in increasing order. ReadName("LightEstablishmentTable"); InputVar <byte> sc = new InputVar <byte>("Available Light Class"); InputVar <double> pl0 = new InputVar <double>("Probability of Germination - Light Level 0"); InputVar <double> pl1 = new InputVar <double>("Probability of Germination - Light Level 1"); InputVar <double> pl2 = new InputVar <double>("Probability of Germination - Light Level 2"); InputVar <double> pl3 = new InputVar <double>("Probability of Germination - Light Level 3"); InputVar <double> pl4 = new InputVar <double>("Probability of Germination - Light Level 4"); InputVar <double> pl5 = new InputVar <double>("Probability of Germination - Light Level 5"); int previousNumber = 0; while (!AtEndOfInput && CurrentName != Names.SpeciesParameters && previousNumber != 6) { StringReader currentLine = new StringReader(CurrentLine); ISufficientLight suffLight = new SufficientLight(); ReadValue(sc, currentLine); suffLight.ShadeClass = sc.Value; // Check that the current shade class is 1 more than // the previous number (numbers are must be in increasing order). if (sc.Value.Actual != (byte)previousNumber + 1) { throw new InputValueException(sc.Value.String, "Expected the severity number {0}", previousNumber + 1); } previousNumber = (int)sc.Value.Actual; ReadValue(pl0, currentLine); suffLight.ProbabilityLight0 = pl0.Value; ReadValue(pl1, currentLine); suffLight.ProbabilityLight1 = pl1.Value; ReadValue(pl2, currentLine); suffLight.ProbabilityLight2 = pl2.Value; ReadValue(pl3, currentLine); suffLight.ProbabilityLight3 = pl3.Value; ReadValue(pl4, currentLine); suffLight.ProbabilityLight4 = pl4.Value; ReadValue(pl5, currentLine); suffLight.ProbabilityLight5 = pl5.Value; parameters.LightClassProbabilities.Add(suffLight); CheckNoDataAfter("the " + pl5.Name + " column", currentLine); GetNextLine(); } if (parameters.LightClassProbabilities.Count == 0) { throw NewParseException("No sufficient light probabilities defined."); } if (previousNumber != 5) { throw NewParseException("Expected shade class {0}", previousNumber + 1); } //------------------------- // Species Parameters table ReadName("SpeciesParameters"); speciesLineNums.Clear(); // If parser re-used (i.e., for testing purposes) InputVar <int> ft = new InputVar <int>("Functional Type"); InputVar <bool> nt = new InputVar <bool>("Nitrogen Fixer"); InputVar <int> gddmn = new InputVar <int>("Growing Degree Day Minimum"); InputVar <int> gddmx = new InputVar <int>("Growing Degree Day Maximum"); InputVar <int> mjt = new InputVar <int>("Minimum January Temperature"); InputVar <double> maxd = new InputVar <double>("Maximum Allowable Drought"); InputVar <double> leafLongevity = new InputVar <double>("Leaf Longevity"); InputVar <bool> epicorm = new InputVar <bool>("Epicormic: Y/N"); InputVar <double> leafLignin = new InputVar <double>("Leaf Percent Lignin"); InputVar <double> wLignin = new InputVar <double>("Wood Percent Lignin"); InputVar <double> crLignin = new InputVar <double>("Coarse Root Percent Lignin"); InputVar <double> frLignin = new InputVar <double>("Fine Root Percent Lignin"); InputVar <double> leafCN = new InputVar <double>("Leaf CN Ratio"); InputVar <double> woodCN = new InputVar <double>("Wood CN Ratio"); InputVar <double> cRootCN = new InputVar <double>("Coarse Root CN Ratio"); InputVar <double> foliarCN = new InputVar <double>("Foliage CN Ratio"); InputVar <double> fRootCN = new InputVar <double>("Fine Root CN Ratio"); InputVar <int> maxANPP = new InputVar <int>("Maximum ANPP"); InputVar <int> maxBiomass = new InputVar <int>("Maximum Aboveground Biomass"); string lastColumn = "the " + maxBiomass.Name + " column"; while (!AtEndOfInput && CurrentName != Names.FunctionalGroupParameters) { StringReader currentLine = new StringReader(CurrentLine); ISpecies species = ReadSpecies(currentLine); ReadValue(ft, currentLine); parameters.SetFunctionalType(species, ft.Value); ReadValue(nt, currentLine); parameters.NFixer[species] = nt.Value; ReadValue(gddmn, currentLine); parameters.SetGDDmin(species, gddmn.Value); ReadValue(gddmx, currentLine); parameters.SetGDDmax(species, gddmx.Value); ReadValue(mjt, currentLine); parameters.SetMinJanTemp(species, mjt.Value); ReadValue(maxd, currentLine); parameters.SetMaxDrought(species, maxd.Value); ReadValue(leafLongevity, currentLine); parameters.SetLeafLongevity(species, leafLongevity.Value); ReadValue(epicorm, currentLine); parameters.Epicormic[species] = epicorm.Value; ReadValue(leafLignin, currentLine); parameters.SetLeafLignin(species, leafLignin.Value); ReadValue(frLignin, currentLine); parameters.SetFineRootLignin(species, frLignin.Value); ReadValue(wLignin, currentLine); parameters.SetWoodLignin(species, wLignin.Value); ReadValue(crLignin, currentLine); parameters.SetCoarseRootLignin(species, crLignin.Value); ReadValue(leafCN, currentLine); parameters.SetLeafCN(species, leafCN.Value); ReadValue(fRootCN, currentLine); parameters.SetFineRootCN(species, fRootCN.Value); ReadValue(woodCN, currentLine); parameters.SetWoodCN(species, woodCN.Value); ReadValue(cRootCN, currentLine); parameters.SetCoarseRootCN(species, cRootCN.Value); ReadValue(foliarCN, currentLine); parameters.SetFoliageLitterCN(species, foliarCN.Value); ReadValue(maxANPP, currentLine); parameters.SetMaxANPP(species, maxANPP.Value); ReadValue(maxBiomass, currentLine); parameters.SetMaxBiomass(species, maxBiomass.Value); CheckNoDataAfter(lastColumn, currentLine); GetNextLine(); } //--------- Read In Functional Group Table ------------------------------- PlugIn.ModelCore.UI.WriteLine(" Begin parsing FUNCTIONAL GROUP table."); ReadName("FunctionalGroupParameters"); InputVar <string> ftname = new InputVar <string>("Name"); InputVar <int> ftindex = new InputVar <int>("Index (< 25)"); InputVar <double> tempcurve1 = new InputVar <double>("TempCurve(1)"); InputVar <double> tempcurve2 = new InputVar <double>("TempCurve(2)"); InputVar <double> tempcurve3 = new InputVar <double>("TempCurve(3)"); InputVar <double> tempcurve4 = new InputVar <double>("TempCurve(4)"); InputVar <double> fcfleaf = new InputVar <double>("FCFRAC: Leaf"); InputVar <double> btolai = new InputVar <double>("BTOLAI"); InputVar <double> klai = new InputVar <double>("KLAI"); InputVar <double> maxlai = new InputVar <double>("MAXLAI"); InputVar <double> mwm = new InputVar <double>("Monthly Wood Mortality"); InputVar <double> wdr = new InputVar <double>("Wood Decay Rate"); InputVar <double> mortCurveShapeParm = new InputVar <double>("Mortality Curve Shape Parameter"); InputVar <int> leafNeedleDrop = new InputVar <int>("Leaf or Needle Drop Month"); InputVar <double> ppr2 = new InputVar <double>("MoistureCurve2"); InputVar <double> ppr3 = new InputVar <double>("MoistureCurve3"); InputVar <double> coarseRootFraction = new InputVar <double>("CRootFrac"); InputVar <double> fineRootFraction = new InputVar <double>("FRootFrac"); while (!AtEndOfInput && CurrentName != Names.FireReductionParameters) { StringReader currentLine = new StringReader(CurrentLine); ReadValue(ftname, currentLine); ReadValue(ftindex, currentLine); int ln = ftindex.Value.Actual; if (ln >= numFunctionalTypes) { throw new InputValueException(ftindex.Value.String, "The index: {0} exceeds the allowable number of functional groups, {1}", ftindex.Value.String, numFunctionalTypes - 1); } FunctionalType funcTParms = new FunctionalType(); parameters.FunctionalTypes[ln] = funcTParms; ReadValue(tempcurve1, currentLine); funcTParms.TempCurve1 = tempcurve1.Value; ReadValue(tempcurve2, currentLine); funcTParms.TempCurve2 = tempcurve2.Value; ReadValue(tempcurve3, currentLine); funcTParms.TempCurve3 = tempcurve3.Value; ReadValue(tempcurve4, currentLine); funcTParms.TempCurve4 = tempcurve4.Value; ReadValue(fcfleaf, currentLine); funcTParms.FCFRACleaf = fcfleaf.Value; ReadValue(btolai, currentLine); funcTParms.BTOLAI = btolai.Value; ReadValue(klai, currentLine); funcTParms.KLAI = klai.Value; ReadValue(maxlai, currentLine); funcTParms.MAXLAI = maxlai.Value; ReadValue(ppr2, currentLine); funcTParms.MoistureCurve2 = ppr2.Value; ReadValue(ppr3, currentLine); funcTParms.MoistureCurve3 = ppr3.Value; ReadValue(wdr, currentLine); funcTParms.WoodDecayRate = wdr.Value; ReadValue(mwm, currentLine); funcTParms.MonthlyWoodMortality = mwm.Value; ReadValue(mortCurveShapeParm, currentLine); funcTParms.MortCurveShape = mortCurveShapeParm.Value; ReadValue(leafNeedleDrop, currentLine); funcTParms.LeafNeedleDrop = leafNeedleDrop.Value; ReadValue(coarseRootFraction, currentLine); funcTParms.CoarseRootFraction = coarseRootFraction.Value; ReadValue(fineRootFraction, currentLine); funcTParms.FineRootFraction = fineRootFraction.Value; CheckNoDataAfter("the " + fineRootFraction.Name + " column", currentLine); GetNextLine(); } //--------- Read In Fire Reductions Table --------------------------- PlugIn.ModelCore.UI.WriteLine(" Begin reading FIRE REDUCTION parameters."); ReadName(Names.FireReductionParameters); InputVar <int> frindex = new InputVar <int>("Fire Severity Index MUST = 1-5"); InputVar <double> wred = new InputVar <double>("Wood Reduction"); InputVar <double> lred = new InputVar <double>("Litter Reduction"); while (!AtEndOfInput && CurrentName != Names.HarvestReductionParameters && CurrentName != Names.AgeOnlyDisturbanceParms) { StringReader currentLine = new StringReader(CurrentLine); ReadValue(frindex, currentLine); int ln = frindex.Value.Actual; if (ln < 1 || ln > 5) { throw new InputValueException(ftindex.Value.String, "The fire severity index: {0} must be 1-5,", frindex.Value.String); } FireReductions inputFireReduction = new FireReductions(); // ignoring severity = zero parameters.FireReductionsTable[ln] = inputFireReduction; ReadValue(wred, currentLine); inputFireReduction.WoodReduction = wred.Value; ReadValue(lred, currentLine); inputFireReduction.LitterReduction = lred.Value; CheckNoDataAfter("the " + lred.Name + " column", currentLine); GetNextLine(); } //--------- Read In Harvest Reductions Table --------------------------- ReadOptionalName(Names.HarvestReductionParameters); { PlugIn.ModelCore.UI.WriteLine(" Begin reading HARVEST REDUCTION parameters."); InputVar <string> prescriptionName = new InputVar <string>("Prescription"); InputVar <double> wred_pr = new InputVar <double>("Wood Reduction"); InputVar <double> lred_pr = new InputVar <double>("Litter Reduction"); while (!AtEndOfInput && CurrentName != Names.AgeOnlyDisturbanceParms) { HarvestReductions harvReduction = new HarvestReductions(); parameters.HarvestReductionsTable.Add(harvReduction); StringReader currentLine = new StringReader(CurrentLine); ReadValue(prescriptionName, currentLine); harvReduction.PrescriptionName = prescriptionName.Value; ReadValue(wred_pr, currentLine); harvReduction.WoodReduction = wred.Value; ReadValue(lred_pr, currentLine); harvReduction.LitterReduction = lred.Value; GetNextLine(); } } return(parameters); }
public void SetFunctionalType(ISpecies species, int newValue) { Debug.Assert(species != null); sppFunctionalType[species] = VerifyRange(newValue, 0, 100); }
//--------------------------------------------------------------------- public void SetMaxANPP(ISpecies species, InputValue <int> newValue) { Debug.Assert(species != null); maxANPP[species] = VerifyRange(newValue, 2, 1000); }
//--------------------------------------------------------------------- public void SetLeafLignin(ISpecies species, InputValue <double> newValue) { Debug.Assert(species != null); leafLignin[species] = newValue.CheckInRange(0, 0.4, "leafLignin"); }
//--------------------------------------------------------------------- protected override IAgent Parse() { //PlugIn.ModelCore.Log.WriteLine("Parsing 1; sppCnt={0}", Model.Species.Count); //Agent agentParameters = new Agent(PlugIn.ModelCore.Species.Count, PlugIn.ModelCore.Ecoregions.Count, (int) DisturbanceType.Null); //The last disturb Type is Null InputVar<string> landisData = new InputVar<string>("LandisData"); ReadVar(landisData); if (landisData.Value.Actual != LandisDataValue) throw new InputValueException(landisData.Value.String, "The value is not \"{0}\"", LandisDataValue); Agent agentParameters = new Agent(PlugIn.ModelCore.Species.Count, PlugIn.ModelCore.Ecoregions.Count); InputVar<string> agentName = new InputVar<string>("BDAAgentName"); ReadVar(agentName); agentParameters.AgentName = agentName.Value; InputVar<int> bdpc = new InputVar<int>("BDPCalibrator"); ReadVar(bdpc); agentParameters.BDPCalibrator = bdpc.Value; InputVar<SRDmode> srd = new InputVar<SRDmode>("SRDMode"); ReadVar(srd); agentParameters.SRDmode = srd.Value; InputVar<int> startYear = new InputVar<int>("StartYear"); if (CurrentName == "StartYear") { ReadVar(startYear); agentParameters.StartYear = startYear.Value; } else agentParameters.StartYear = 0; InputVar<int> endYear = new InputVar<int>("EndYear"); if (CurrentName == "EndYear") { ReadVar(endYear); agentParameters.EndYear = endYear.Value; } else agentParameters.EndYear = PlugIn.ModelCore.EndTime; InputVar<OutbreakPattern> rf = new InputVar<OutbreakPattern>("OutbreakPattern"); ReadVar(rf); agentParameters.RandFunc = rf.Value; InputVar<double> normMean = new InputVar<double>("Mean"); InputVar<double> normStDev = new InputVar<double>("StDev"); InputVar<int> tSLE = new InputVar<int>("TimeSinceLastEpidemic"); if ((rf.Value.ToString()) == "CyclicNormal") { ReadVar(normMean); agentParameters.NormMean = normMean.Value; ReadVar(normStDev); agentParameters.NormStDev = normStDev.Value; ReadVar(tSLE); agentParameters.TimeSinceLastEpidemic = tSLE.Value; } else { agentParameters.NormMean = 0; agentParameters.NormStDev = 0; } InputVar<double> maxInterval = new InputVar<double>("MaxInterval"); InputVar<double> minInterval = new InputVar<double>("MinInterval"); if (rf.Value.ToString() == "CyclicUniform") { ReadVar(maxInterval); agentParameters.MaxInterval = maxInterval.Value; ReadVar(minInterval); agentParameters.MinInterval = minInterval.Value; ReadVar(tSLE); agentParameters.TimeSinceLastEpidemic = tSLE.Value; } else { agentParameters.MaxInterval = 0; agentParameters.MinInterval = 0; } InputVar<TemporalType> tt = new InputVar<TemporalType>("TemporalType"); ReadVar(tt); agentParameters.TempType = tt.Value; InputVar<int> minROS = new InputVar<int>("MinROS"); ReadVar(minROS); agentParameters.MinROS = minROS.Value; InputVar<int> maxROS = new InputVar<int>("MaxROS"); ReadVar(maxROS); agentParameters.MaxROS = maxROS.Value; InputVar<bool> d = new InputVar<bool>("Dispersal"); ReadVar(d); agentParameters.Dispersal = d.Value; InputVar<int> dr = new InputVar<int>("DispersalRate"); ReadVar(dr); agentParameters.DispersalRate = dr.Value; InputVar<double> et = new InputVar<double>("EpidemicThresh"); ReadVar(et); agentParameters.EpidemicThresh = et.Value; InputVar<int> ien = new InputVar<int>("InitialEpicenterNum"); ReadVar(ien); agentParameters.EpicenterNum = ien.Value; InputVar<double> oec = new InputVar<double>("OutbreakEpicenterCoeff"); ReadVar(oec); agentParameters.OutbreakEpicenterCoeff = oec.Value; InputVar<double> outEpiThresh = new InputVar<double>("OutbreakEpicenterThresh"); ReadVar(outEpiThresh); agentParameters.OutbreakEpicenterThresh = outEpiThresh.Value; InputVar<bool> se = new InputVar<bool>("SeedEpicenter"); ReadVar(se); agentParameters.SeedEpicenter = se.Value; InputVar<double> sec = new InputVar<double>("SeedEpicenterCoeff"); ReadVar(sec); agentParameters.SeedEpicenterCoeff = sec.Value; InputVar<DispersalTemplate> dispt = new InputVar<DispersalTemplate>("DispersalTemplate"); ReadVar(dispt); agentParameters.DispersalTemp = dispt.Value; InputVar<bool> nf = new InputVar<bool>("NeighborFlag"); ReadVar(nf); agentParameters.NeighborFlag = nf.Value; InputVar<NeighborSpeed> nspeed = new InputVar<NeighborSpeed>("NeighborSpeedUp"); ReadVar(nspeed); agentParameters.NeighborSpeedUp = nspeed.Value; InputVar<int> nr = new InputVar<int>("NeighborRadius"); ReadVar(nr); agentParameters.NeighborRadius = nr.Value; InputVar<NeighborShape> ns = new InputVar<NeighborShape>("NeighborShape"); ReadVar(ns); agentParameters.ShapeOfNeighbor = ns.Value; InputVar<double> nw = new InputVar<double>("NeighborWeight"); ReadVar(nw); agentParameters.NeighborWeight = nw.Value; InputVar<double> class2_SV = new InputVar<double>("IntensityClass2_BDP"); ReadVar(class2_SV); agentParameters.Class2_SV = class2_SV.Value; InputVar<double> class3_SV = new InputVar<double>("IntensityClass3_BDP"); ReadVar(class3_SV); agentParameters.Class3_SV = class3_SV.Value; //--------- Read In Ecoreigon Table --------------------------------------- PlugIn.ModelCore.UI.WriteLine("Begin parsing ECOREGION table."); InputVar<string> ecoName = new InputVar<string>("Ecoregion Name"); InputVar<double> ecoModifier = new InputVar<double>("Ecoregion Modifier"); Dictionary <string, int> lineNumbers = new Dictionary<string, int>(); const string DistParms = "DisturbanceModifiers"; const string SppParms = "BDASpeciesParameters"; while (! AtEndOfInput && CurrentName != DistParms && CurrentName != SppParms) { StringReader currentLine = new StringReader(CurrentLine); ReadValue(ecoName, currentLine); IEcoregion ecoregion = EcoregionsDataset[ecoName.Value.Actual]; if (ecoregion == null) throw new InputValueException(ecoName.Value.String, "{0} is not an ecoregion name.", ecoName.Value.String); int lineNumber; if (lineNumbers.TryGetValue(ecoregion.Name, out lineNumber)) throw new InputValueException(ecoName.Value.String, "The ecoregion {0} was previously used on line {1}", ecoName.Value.String, lineNumber); else lineNumbers[ecoregion.Name] = LineNumber; IEcoParameters ecoParms = new EcoParameters(); agentParameters.EcoParameters[ecoregion.Index] = ecoParms; ReadValue(ecoModifier, currentLine); ecoParms.EcoModifier = ecoModifier.Value; CheckNoDataAfter("the " + ecoModifier.Name + " column", currentLine); GetNextLine(); } if (CurrentName == DistParms) { //--------- Read In Disturbance Modifier Table ------------------------------- PlugIn.ModelCore.UI.WriteLine("Begin parsing DISTURBANCE table."); ReadName(DistParms); InputVar<string> prescriptionName = new InputVar<string>("Disturbance Type"); InputVar<int> duration = new InputVar<int>("Duration"); InputVar<double> distModifier = new InputVar<double>("Disturbance Modifier"); lineNumbers = new Dictionary<string, int>(); Dictionary<int, int> DisturbanceTypeLineNumbers = new Dictionary<int, int>(); while (!AtEndOfInput && CurrentName != SppParms) { StringReader currentLine = new StringReader(CurrentLine); ReadValue(distModifier, currentLine); IDisturbanceType currentDisturbanceType = new DisturbanceType(); agentParameters.DisturbanceTypes.Add(currentDisturbanceType); currentDisturbanceType.SRDModifier = distModifier.Value; //IDistParameters distParms = new DistParameters(); //agentParameters.DistParameters[dt] = distParms; ReadValue(duration, currentLine); currentDisturbanceType.MaxAge = duration.Value; List<string> prescriptionNames = new List<string>(); TextReader.SkipWhitespace(currentLine); while (currentLine.Peek() != -1) { ReadValue(prescriptionName, currentLine); prescriptionNames.Add(prescriptionName.Value); TextReader.SkipWhitespace(currentLine); } if (prescriptionNames.Count == 0) throw NewParseException("At least one disturbance type is required."); currentDisturbanceType.PrescriptionNames = prescriptionNames; //ReadValue(distType, currentLine); //int dt = (int)distType.Value.Actual; CheckNoDataAfter("the " + distModifier.Name + " column", currentLine); GetNextLine(); } } //--------- Read In Species Table --------------------------------------- PlugIn.ModelCore.UI.WriteLine("Begin parsing SPECIES table."); ReadName(SppParms); //const string FireCurves = "FireCurveTable"; InputVar<string> sppName = new InputVar<string>("Species"); InputVar<int> minorHostAge = new InputVar<int>("Minor Host Age"); InputVar<double> minorHostSRD = new InputVar<double>("Minor Host SRDProb"); InputVar<int> secondaryHostAge = new InputVar<int>("Second Host Age"); InputVar<double> secondaryHostSRD = new InputVar<double>("Secondary Host SRDProb"); InputVar<int> primaryHostAge = new InputVar<int>("Primary Host Age"); InputVar<double> primaryHostSRD = new InputVar<double>("Primary Host SRDProb"); InputVar<int> resistantHostAge = new InputVar<int>("Resistant Host Age"); InputVar<double> resistantHostVuln = new InputVar<double>("Resistant Host VulnProb"); InputVar<int> tolerantHostAge = new InputVar<int>("Tolerant Host Age"); InputVar<double> tolerantHostVuln = new InputVar<double>("Tolerant Host VulnProb"); InputVar<int> vulnerableHostAge = new InputVar<int>("Vulnerable Host Age"); InputVar<double> vulnerableHostVuln = new InputVar<double>("Vulnerable Host VulnProb"); InputVar<bool> cfsConifer = new InputVar<bool>("CFS Conifer type: yes/no"); const string NegSpp = "IgnoredSpecies"; const string AdvRegenSpp = "AdvancedRegenSpecies"; const string AdvRegenMaxAge = "AgeCutoff"; while ((!AtEndOfInput) && (CurrentName != NegSpp) && (CurrentName != AdvRegenSpp) && (CurrentName != AdvRegenMaxAge)) { StringReader currentLine = new StringReader(CurrentLine); ReadValue(sppName, currentLine); ISpecies species = SpeciesDataset[sppName.Value.Actual]; if (species == null) throw new InputValueException(sppName.Value.String, "{0} is not a species name.", sppName.Value.String); int lineNumber; if (lineNumbers.TryGetValue(species.Name, out lineNumber)) throw new InputValueException(sppName.Value.String, "The species {0} was previously used on line {1}", sppName.Value.String, lineNumber); else lineNumbers[species.Name] = LineNumber; ISppParameters sppParms = new SppParameters(); agentParameters.SppParameters[species.Index] = sppParms; ReadValue(minorHostAge, currentLine); sppParms.MinorHostAge = minorHostAge.Value; ReadValue(minorHostSRD, currentLine); sppParms.MinorHostSRD = minorHostSRD.Value; ReadValue(secondaryHostAge, currentLine); sppParms.SecondaryHostAge = secondaryHostAge.Value; ReadValue(secondaryHostSRD, currentLine); sppParms.SecondaryHostSRD = secondaryHostSRD.Value; ReadValue(primaryHostAge, currentLine); sppParms.PrimaryHostAge = primaryHostAge.Value; ReadValue(primaryHostSRD, currentLine); sppParms.PrimaryHostSRD = primaryHostSRD.Value; ReadValue(resistantHostAge, currentLine); sppParms.ResistantHostAge = resistantHostAge.Value; ReadValue(resistantHostVuln, currentLine); sppParms.ResistantHostVuln = resistantHostVuln.Value; ReadValue(tolerantHostAge, currentLine); sppParms.TolerantHostAge = tolerantHostAge.Value; ReadValue(tolerantHostVuln, currentLine); sppParms.TolerantHostVuln = tolerantHostVuln.Value; ReadValue(vulnerableHostAge, currentLine); sppParms.VulnerableHostAge = vulnerableHostAge.Value; ReadValue(vulnerableHostVuln, currentLine); sppParms.VulnerableHostVuln = vulnerableHostVuln.Value; ReadValue(cfsConifer, currentLine); sppParms.CFSConifer = cfsConifer.Value; CheckNoDataAfter("the " + cfsConifer.Name + " column", currentLine); GetNextLine(); } //--------- Read In Ignored Species List --------------------------------------- List<ISpecies> negSppList = new List<ISpecies>(); if (!AtEndOfInput && (CurrentName != AdvRegenSpp) && (CurrentName != AdvRegenMaxAge)) { ReadName(NegSpp); InputVar<string> negSppName = new InputVar<string>("Ignored Spp Name"); while (!AtEndOfInput && (CurrentName != AdvRegenSpp) && (CurrentName != AdvRegenMaxAge)) { StringReader currentLine = new StringReader(CurrentLine); ReadValue(negSppName, currentLine); ISpecies species = SpeciesDataset[negSppName.Value.Actual]; if (species == null) throw new InputValueException(negSppName.Value.String, "{0} is not a species name.", negSppName.Value.String); int lineNumber; if (lineNumbers.TryGetValue(species.Name, out lineNumber)) PlugIn.ModelCore.UI.WriteLine("WARNING: The species {0} was previously used on line {1}. Being listed in the IgnoredSpecies list will override any settings in the Host table.", negSppName.Value.String, lineNumber); else lineNumbers[species.Name] = LineNumber; negSppList.Add(species); GetNextLine(); } } agentParameters.NegSppList = negSppList; //--------- Read In Advanced Regen Species List --------------------------------------- List<ISpecies> advRegenSppList = new List<ISpecies>(); if (!AtEndOfInput && (CurrentName != AdvRegenMaxAge)) { ReadName(AdvRegenSpp); InputVar<string> advRegenSppName = new InputVar<string>("Advanced Regen Spp Name"); while (!AtEndOfInput && CurrentName != "AgeCutoff") { StringReader currentLine = new StringReader(CurrentLine); ReadValue(advRegenSppName, currentLine); ISpecies species = SpeciesDataset[advRegenSppName.Value.Actual]; if (species == null) throw new InputValueException(advRegenSppName.Value.String, "{0} is not a species name.", advRegenSppName.Value.String); lineNumbers[species.Name] = LineNumber; advRegenSppList.Add(species); GetNextLine(); } } agentParameters.AdvRegenSppList = advRegenSppList; InputVar<int> advRegenAgeCutoff = new InputVar<int>("AgeCutoff"); if (!AtEndOfInput) { ReadVar(advRegenAgeCutoff); agentParameters.AdvRegenAgeCutoff = advRegenAgeCutoff.Value; } else { agentParameters.AdvRegenAgeCutoff = 0; } return agentParameters; //.GetComplete(); }
//--------------------------------------------------------------------- /// <summary> /// Add a new cohort to a site. /// This is a Delegate method to base succession. /// </summary> public void AddNewCohort(ISpecies species, ActiveSite site, string reproductionType) { SiteVars.Cohorts[site].AddNewCohort(species); }
//--------------------------------------------------------------------- public void SetGrowthCurveShapeParm(ISpecies species, InputValue <double> newValue) { Debug.Assert(species != null); growthCurveShapeParm[species] = newValue.CheckInRange(0, 1.0, "growthCurveShapeParm"); }
//--------------------------------------------------------------------- /// <summary> /// Determines if a species can establish on a site. /// This is a Delegate method to base succession. /// </summary> public bool Establish(ISpecies species, ActiveSite site) { double establishProbability = Establishment.Calculate(species, site); return(modelCore.GenerateUniform() < establishProbability); }
//--------------------------------------------------------------------- /// <summary> /// Predicts additive probability of tree death in current simulation year /// as a function of <paramref name="host"/>, <paramref name="PCD"/>, and <paramref name="age"/>. /// </summary> /// <param name="host">SBW host species.</param> /// <param name="PCD"> /// Periodic (5-year) average cumulative defoliation /// as defined by MacLean et al. (2001). /// </param> /// <param name="age">Tree age.</param> /// <returns>Additive tree mortality rate (probability of death in current year).</returns> public static double GetMortalityRate_AGE(ISpecies species, double PCD, int age) { if (PCD < 0.35) { return(0); //Avoid extrapolation issues. } else { PCD *= 100; //Convert units to percent } double rate = 0; double[] b = null; if (species.Name == "abiebals") { b = params_MR_AGE_BF; if (age > 90) { age = 90; //Cap to avoid extrapolation issues. } } else if (species.Name == "picemari") { b = params_MR_AGE_BS; if (age > 125) { age = 125; } } else if (species.Name == "picerube") { b = params_MR_AGE_RS; if (age > 125) { age = 125; } } else if (species.Name == "piceglau") { b = params_MR_AGE_WS; if (age > 125) { age = 125; } } else { b = params_MR_AGE_NONHOST; } //Periodic (5 year) Mortality Rate = Intercept + AGE + CD*AGE + CD^2 + CD^3 rate = b[0] + b[1] * age + b[2] * age * PCD + b[3] * PCD * PCD + b[4] * PCD * PCD * PCD; //Trap out of bounds extrapolated predictions. if (rate < 0) { return(0); } else if (rate > 1) { return(1); } //Convert from periodic (5 year) to annual mortality rate using the reverse compound interest formula //(original fit was based on 5 year mortality rates, so we need to first predict periodic, then convert to annual). rate = 1 - Math.Pow(1 - rate, 1 / 5.0); return(rate); }