示例#1
0
        //---------------------------------------------------------------------
        ///<summary>
        // Go through all active sites and damage them.  Mortality should occur the year FOLLOWING an active year.
        ///</summary>
        public static void Mortality(IInsect insect)
        {
            //PlugIn.ModelCore.UI.WriteLine("   {0} mortality.  StartYear={1}, StopYear={2}, CurrentYear={3}.", insect.Name, insect.OutbreakStartYear, insect.OutbreakStopYear, PlugIn.ModelCore.CurrentTime);

            foreach (ActiveSite site in PlugIn.ModelCore.Landscape)
            {
                PartialDisturbance.ReduceCohortBiomass(site);

                if (insect.BiomassRemoved[site] > 0)
                {
                    //PlugIn.ModelCore.UI.WriteLine("  Biomass removed at {0}/{1}: {2}.", site.Location.Row, site.Location.Column, SiteVars.BiomassRemoved[site]);
                    SiteVars.TimeOfLastEvent[site] = PlugIn.ModelCore.CurrentTime;
                }
            }
        }
        //---------------------------------------------------------------------
        ///<summary>
        // Go through all active sites and damage them.  Mortality should occur the year FOLLOWING an active year.
        ///</summary>
        public static void Mortality(IInsect insect)
        {
            
            //PlugIn.ModelCore.Log.WriteLine("   {0} mortality.  StartYear={1}, StopYear={2}, CurrentYear={3}.", insect.Name, insect.OutbreakStartYear, insect.OutbreakStopYear, PlugIn.ModelCore.CurrentTime);

            foreach (ActiveSite site in PlugIn.ModelCore.Landscape) 
            {
                PartialDisturbance.ReduceCohortBiomass(site);
                    
                if (SiteVars.BiomassRemoved[site] > 0) 
                {
                    //PlugIn.ModelCore.Log.WriteLine("  Biomass removed at {0}/{1}: {2}.", site.Location.Row, site.Location.Column, SiteVars.BiomassRemoved[site]);
                    SiteVars.TimeOfLastEvent[site] = PlugIn.ModelCore.CurrentTime;
                } 
            }
        }
        //---------------------------------------------------------------------
        ///<summary>
        // Go through all active sites and damage them.  Mortality should occur the year FOLLOWING an active year.
        ///</summary>
        public static void Mortality(IInsect insect)
        {
            
            UI.WriteLine("   {0} mortality.  StartYear={1}, StopYear={2}, CurrentYear={3}.", insect.Name, insect.OutbreakStartYear, insect.OutbreakStopYear, Model.Core.CurrentTime);


            foreach (ActiveSite site in Model.Core.Landscape) 
            {

                PartialDisturbance.ReduceCohortBiomass(site);
                    
                if (SiteVars.BiomassRemoved[site] > 0) 
                {
                        SiteVars.TimeOfLastEvent[site] = Model.Core.CurrentTime;
                } 
            }
        }
        //---------------------------------------------------------------------
        ///<summary>
        // Go through all active sites and damage them.  Mortality should occur the year FOLLOWING an active year.
        ///</summary>
        public static void Mortality(IInsect insect)
        {
            
            // PlugIn.ModelCore.UI.WriteLine("   {0} mortality.  StartYear={1}, StopYear={2}, CurrentYear={3}.", insect.Name, insect.OutbreakStartYear, insect.OutbreakStopYear, PlugIn.ModelCore.CurrentTime);

            foreach (ActiveSite site in PlugIn.ModelCore.Landscape) 
            {
                //Try zeroing out biomass removed here @ start of each defoliation mortality year. Remove if doesn't work.
                if (SiteVars.BiomassRemoved[site] > 0)
                    SiteVars.BiomassRemoved[site] = 0;

                PartialDisturbance.ReduceCohortBiomass(site);
                    
                if (SiteVars.BiomassRemoved[site] > 0) 
                {
                    // PlugIn.ModelCore.UI.WriteLine("  Biomass removed at {0}/{1}: {2}.", site.Location.Row, site.Location.Column, SiteVars.BiomassRemoved[site]);
                    SiteVars.TimeOfLastEvent[site] = PlugIn.ModelCore.CurrentTime;
                    SiteVars.InsectName[site] = insect.Name;
                } 
            }
        }
        //---------------------------------------------------------------------
        ///<summary>
        // Go through all active sites and damage them.  Mortality should occur the year FOLLOWING an active year.
        ///</summary>
        public static void Mortality(IInsect insect)
        {
            
            UI.WriteLine("   {0} mortality.  StartYear={1}, StopYear={2}, CurrentYear={3}.", insect.Name, insect.OutbreakStartYear, insect.OutbreakStopYear, Model.Core.CurrentTime);


            foreach (ActiveSite site in Model.Core.Landscape) 
            {
                //Try zeroing out biomass removed here @ start of each defoliation mortality year. Remove if doesn't work.
                if (SiteVars.BiomassRemoved[site] > 0)
                  SiteVars.BiomassRemoved[site] = 0;

                PartialDisturbance.ReduceCohortBiomass(site);
                    
                if (SiteVars.BiomassRemoved[site] > 0) 
                {
                        SiteVars.TimeOfLastEvent[site] = Model.Core.CurrentTime;
                        //SiteVars.WoodyDebris[site].AddMass(SiteVars.BiomassRemoved[site], 0.1);
                } 
            }
        }
示例#6
0
        //---------------------------------------------------------------------
        ///<summary>
        // Go through all active sites and damage them.  Mortality should occur the year FOLLOWING an active year.
        ///</summary>
        public static void Mortality(IInsect insect)
        {
            // PlugIn.ModelCore.UI.WriteLine("   {0} mortality.  StartYear={1}, StopYear={2}, CurrentYear={3}.", insect.Name, insect.OutbreakStartYear, insect.OutbreakStopYear, PlugIn.ModelCore.CurrentTime);

            foreach (ActiveSite site in PlugIn.ModelCore.Landscape)
            {
                //Try zeroing out biomass removed here @ start of each defoliation mortality year. Remove if doesn't work.
                if (SiteVars.BiomassRemoved[site] > 0)
                {
                    SiteVars.BiomassRemoved[site] = 0;
                }

                //PlugIn.ModelCore.UI.WriteLine("  Reducing cohort biomass for {0}...", insect.Name);
                PartialDisturbance.ReduceCohortBiomass(site);
                //PartialDisturbance.AddPartialMortalityToWoodyDebris(site);

                if (SiteVars.BiomassRemoved[site] > 0)
                {
                    // PlugIn.ModelCore.UI.WriteLine("  Biomass removed at {0}/{1}: {2}.", site.Location.Row, site.Location.Column, SiteVars.BiomassRemoved[site]);
                    SiteVars.TimeOfLastEvent[site] = PlugIn.ModelCore.CurrentTime;
                }
            }
        }
示例#7
0
        //---------------------------------------------------------------------
        // Initialize landscape with patches of defoliation during the first year
        public static void InitializeDefoliationPatches(IInsect insect)
        {
            PlugIn.ModelCore.UI.WriteLine("   Initializing Defoliation Patches... ");
            SiteVars.InitialOutbreakProb.ActiveSiteValues   = 0.0;
            insect.Disturbed.ActiveSiteValues               = false;
            insect.NeighborhoodDefoliation.ActiveSiteValues = 0.0;

            foreach (ActiveSite site in PlugIn.ModelCore.Landscape)
            {
                double suscIndexSum = 0.0;
                double sumBio       = 0.0;


                foreach (ISpeciesCohorts speciesCohorts in SiteVars.Cohorts[site])
                //foreach (ISpeciesCohorts speciesCohorts in (Landis.Library.BiomassCohorts.ISpeciesCohorts) SiteVars.Cohorts[site]) // Rob's suggestion. Raised an error...
                {
                    foreach (ICohort cohort in speciesCohorts)
                    {
                        suscIndexSum += cohort.Biomass * (insect.SppTable[cohort.Species.Index].Susceptibility);
                        sumBio       += cohort.Biomass;
                    }
                }


                // If no biomass, no chance of defoliation, go to the next site.
                if (suscIndexSum <= 0 || sumBio <= 0)
                {
                    SiteVars.InitialOutbreakProb[site] = 0.0;
                    continue;
                }

                int suscIndex = (int)Math.Round(suscIndexSum / sumBio) - 1;

                if (suscIndex > 2.0 || suscIndex < 0)
                {
                    PlugIn.ModelCore.UI.WriteLine("SuscIndex < 0 || > 2.  Site R/C={0}/{1},suscIndex={2},suscIndexSum={3},sumBio={4}.", site.Location.Row, site.Location.Column, suscIndex, suscIndexSum, sumBio);
                    throw new ApplicationException("Error: SuscIndex is not between 2.0 and 0.0");
                }
                // Assume that there are no neighbors and draw initial defoliation from the most intense neighborhood distribution:
                DistributionType dist = insect.SusceptibleTable[suscIndex].Distribution_80.Name;


                // PlugIn.ModelCore.UI.WriteLine("suscIndex={0},suscIndexSum={1},cohortBiomass={2}.", suscIndex,suscIndexSum,sumBio);
                double value1 = insect.SusceptibleTable[suscIndex].Distribution_80.Value1;
                double value2 = insect.SusceptibleTable[suscIndex].Distribution_80.Value2;

                double probability = Distribution.GenerateRandomNum(dist, value1, value2);
                if (probability > 1.0 || probability < 0)
                {
                    PlugIn.ModelCore.UI.WriteLine("Initial Defoliation Probility < 0 || > 1.  Site R/C={0}/{1}.", site.Location.Row, site.Location.Column);
                    throw new ApplicationException("Error: Probability is not between 1.0 and 0.0");
                }
                // Try cleaning up defoliation patterns so areas outside main patches are less defoliated
                // How about using Brian's patch shape calibrator here instead. Divide probability by susIndex * PSC, to tie initial patch probs. more closely to host abundance...
                //SiteVars.InitialOutbreakProb[site] = probability;
                SiteVars.InitialOutbreakProb[site] = probability / ((double)suscIndex + 1);
                // PlugIn.ModelCore.UI.WriteLine("Susceptiblity index={0}.  Outbreak Probability={1:0.00}.  R/C={2}/{3}.", suscIndex, probability, site.Location.Row, site.Location.Column);
            }

            foreach (ActiveSite site in PlugIn.ModelCore.Landscape)
            {
                //get a random site from the stand
                double randomNum  = PlugIn.ModelCore.GenerateUniform();
                double randomNum2 = PlugIn.ModelCore.GenerateUniform();

                //Create random variability in outbreak area within a simulation so outbreaks are more variable.
                double initialAreaCalibratorRandomNum = (randomNum2 - 0.5) * insect.InitialPatchOutbreakSensitivity / 2;

                //Start spreading!
                if (randomNum < SiteVars.InitialOutbreakProb[site] * (insect.InitialPatchOutbreakSensitivity + initialAreaCalibratorRandomNum))
                {
                    //start with this site (if it's active)
                    ActiveSite currentSite = site;

                    //queue to hold sites to defoliate
                    Queue <ActiveSite> sitesToConsider = new Queue <ActiveSite>();

                    //put initial site on queue
                    sitesToConsider.Enqueue(currentSite);

                    DistributionType dist       = insect.InitialPatchDistr;
                    double           targetArea = Distribution.GenerateRandomNum(dist, insect.InitialPatchValue1, insect.InitialPatchValue2);

                    // PlugIn.ModelCore.UI.WriteLine("  Target Patch Area={0:0.0}.", targetArea);
                    double areaSelected = 0.0;

                    //loop through stand, defoliating patches of size target area
                    while (sitesToConsider.Count > 0 && areaSelected < targetArea)
                    {
                        currentSite = sitesToConsider.Dequeue();

                        // Because this is the first year, neighborhood defoliation is given a value.
                        // The value is used in Defoliate.DefoliateCohort()
                        insect.NeighborhoodDefoliation[currentSite] = SiteVars.InitialOutbreakProb[currentSite];
                        areaSelected += PlugIn.ModelCore.CellArea;
                        //insect.Disturbed[currentSite] = true;

                        //Next, add site's neighbors to the list of
                        //sites to consider.
                        //loop through the site's neighbors enqueueing all the good ones.

                        //double maxNeighborProb = 0.0;
                        //Site maxNeighbor = currentSite;
                        //bool foundNewNeighbor = false;

                        foreach (RelativeLocation loc in all_neighbor_locations)
                        {
                            Site neighbor = currentSite.GetNeighbor(loc);

                            //get a neighbor site (if it's non-null and active)
                            if (neighbor != null &&
                                neighbor.IsActive &&
                                !sitesToConsider.Contains((ActiveSite)neighbor) &&
                                !insect.Disturbed[neighbor])
                            {
                                insect.Disturbed[currentSite] = true;
                                randomNum = PlugIn.ModelCore.GenerateUniform();

                                /*if (SiteVars.InitialOutbreakProb[neighbor] > maxNeighborProb)
                                 * {
                                 *  maxNeighbor = currentSite.GetNeighbor(loc);
                                 *  maxNeighborProb = SiteVars.InitialOutbreakProb[neighbor];
                                 *  foundNewNeighbor = true;
                                 * }*/

                                //check if it's a valid neighbor:
                                if (SiteVars.InitialOutbreakProb[neighbor] > randomNum)
                                {
                                    sitesToConsider.Enqueue((ActiveSite)neighbor);
                                }
                            }
                        }

                        //if(foundNewNeighbor)
                        //    sitesToConsider.Enqueue((ActiveSite) maxNeighbor);
                    }

                    // PlugIn.ModelCore.UI.WriteLine("   Initial Patch Area Selected={0:0.0}.", areaSelected);
                }
            }
        }
示例#8
0
 //---------------------------------------------------------------------
 // Outbreak Constructor
 public Outbreak(IInsect insect)
 {
     this.outbreakParms = insect;
 }
        //---------------------------------------------------------------------
        // Initialize landscape with patches of defoliation during the first year
        public static void InitializeDefoliationPatches(IInsect insect)
        {

            UI.WriteLine("   Initializing Defoliation Patches... ");   
            SiteVars.InitialOutbreakProb.ActiveSiteValues = 0.0;
            insect.Disturbed.ActiveSiteValues = false;
            
            cohorts = Model.Core.SuccessionCohorts as ILandscapeCohorts;
            
            foreach(ActiveSite site in Model.Core.Landscape)
            {
            
                double suscIndexSum = 0.0;
                double sumBio = 0.0;


                foreach(ISpecies species in Model.Core.Species)
                {
                    ISpeciesCohorts speciesCohorts = cohorts[site][species];
                    
                    if(speciesCohorts == null)
                        continue;
                
                    foreach (ICohort cohort in speciesCohorts) 
                    {
                        suscIndexSum += cohort.Biomass * (insect.SppTable[cohort.Species.Index].Susceptibility);
                        sumBio += cohort.Biomass;
                    }
                }
                
                
                // If no biomass, no chance of defoliation, go to the next site.
                if(suscIndexSum <= 0 || sumBio <=0)
                {
                    SiteVars.InitialOutbreakProb[site] = 0.0;
                    continue;
                }
                
                int suscIndex = (int) Math.Round(suscIndexSum /sumBio) - 1;
                
                if (suscIndex > 2.0 || suscIndex < 0)
                {
                    UI.WriteLine("SuscIndex < 0 || > 2.  Site R/C={0}/{1},suscIndex={2},suscIndexSum={3},sumBio={4}.", site.Location.Row, site.Location.Column, suscIndex,suscIndexSum,sumBio);
                    throw new ApplicationException("Error: SuscIndex is not between 2.0 and 0.0");
                }
                // Assume that there are no neighbors whatsoever:
                DistributionType dist = insect.SusceptibleTable[suscIndex].Distribution_80.Name;


                //UI.WriteLine("suscIndex={0},suscIndexSum={1},cohortBiomass={2}.", suscIndex,suscIndexSum,sumBio);
                double value1 = insect.SusceptibleTable[suscIndex].Distribution_80.Value1;
                double value2 = insect.SusceptibleTable[suscIndex].Distribution_80.Value2;

                double probability = Distribution.GenerateRandomNum(dist, value1, value2);
                if(probability > 1.0 || probability < 0)
                {
                    UI.WriteLine("Initial Defoliation Probility < 0 || > 1.  Site R/C={0}/{1}.", site.Location.Row, site.Location.Column);
                    throw new ApplicationException("Error: Probability is not between 1.0 and 0.0");
                }
                
                SiteVars.InitialOutbreakProb[site] = probability;
                //UI.WriteLine("Susceptiblity index={0}.  Outbreak Probability={1:0.00}.  R/C={2}/{3}.", suscIndex, probability, site.Location.Row, site.Location.Column);
            }

            foreach(ActiveSite site in Model.Core.Landscape)
            {

                //get a random site from the stand
                double randomNum = Landis.Util.Random.GenerateUniform();
                
                if(randomNum < SiteVars.InitialOutbreakProb[site] * insect.InitialAreaCalibrator)  
                //Start spreading!
                {
            
                    //start with this site (if it's active)
                    ActiveSite currentSite = site;           
            
                    //queue to hold sites to defoliate
                    Queue<ActiveSite> sitesToConsider = new Queue<ActiveSite>();
            
                    //put initial site on queue
                    sitesToConsider.Enqueue(currentSite);
            
                    DistributionType dist = insect.InitialPatchDistr;
                    double targetArea = Distribution.GenerateRandomNum(dist, insect.InitialPatchValue1, insect.InitialPatchValue2);
                    
                    //UI.WriteLine("  Target Patch Area={0:0.0}.", targetArea);
                    double areaSelected = 0.0;
            
                    //loop through stand, defoliating patches of size target area
                    while (sitesToConsider.Count > 0 && areaSelected < targetArea) 
                    {

                        currentSite = sitesToConsider.Dequeue();
                    
                        // Because this is the first year, neighborhood defoliaiton is given a value.
                        // The value is used in Defoliate.DefoliateCohort()
                        SiteVars.NeighborhoodDefoliation[currentSite] = SiteVars.InitialOutbreakProb[currentSite];
                        areaSelected += Model.Core.CellArea;

                        //Next, add site's neighbors to the list of
                        //sites to consider.  
                        //loop through the site's neighbors enqueueing all the good ones.
                        foreach (RelativeLocation loc in all_neighbor_locations) 
                        {
                            Site neighbor = currentSite.GetNeighbor(loc);

                            //get a neighbor site (if it's non-null and active)
                            if (neighbor != null 
                                && neighbor.IsActive  
                                && !sitesToConsider.Contains((ActiveSite) neighbor)
                                && !insect.Disturbed[neighbor]) 
                            {
                                insect.Disturbed[currentSite] = true;
                                randomNum = Landis.Util.Random.GenerateUniform();
                                //UI.WriteLine("That darn Queue!  randomnum={0}, prob={1}.", randomNum, SiteVars.InitialOutbreakProb[neighbor]);
                                
                                //check if it's a valid neighbor:
                                if (SiteVars.InitialOutbreakProb[neighbor] > randomNum)
                                {
                                    sitesToConsider.Enqueue((ActiveSite) neighbor);
                                }
                            }
                        }
                    } //endwhile
                    
                    //UI.WriteLine("   Initial Patch Area Selected={0:0.0}.", areaSelected);
                } //endif

            } //endfor
        
        
        } //endfunc
 //---------------------------------------------------------------------
 // Outbreak Constructor
 public Outbreak(IInsect insect)
 {
     this.outbreakParms = insect;
 }
        //---------------------------------------------------------------------
        // Initialize landscape with patches of defoliation during the first year
        public static void InitializeDefoliationPatches(IInsect insect)
        {

            PlugIn.ModelCore.UI.WriteLine("   Initializing Defoliation Patches... ");   
            insect.InitialOutbreakProb.ActiveSiteValues = 0.0;
            insect.Disturbed.ActiveSiteValues = false;
            
            foreach(ActiveSite site in PlugIn.ModelCore.Landscape)
            {
            
                double suscIndexSum = 0.0;
                double sumBio = 0.0;
                double protectBiomass = 0.0;

                Landis.Library.BiomassCohorts.ISiteCohorts siteCohorts = SiteVars.Cohorts[site];

                foreach (ISpeciesCohorts speciesCohorts in siteCohorts)
                {
                    foreach (ICohort cohort in speciesCohorts) 
                    {
                        int sppSuscIndex = insect.Susceptibility[cohort.Species];
                        if (sppSuscIndex == 4)
                        {
                            protectBiomass += cohort.Biomass;
                            sppSuscIndex = 3;
                        }
                        suscIndexSum += cohort.Biomass * (sppSuscIndex);
                        sumBio += cohort.Biomass;
                    }
                }
                
                
                // If no biomass, no chance of defoliation, go to the next site.
                if(suscIndexSum <= 0 || sumBio <=0)
                {
                    insect.InitialOutbreakProb[site] = 0.0;
                    continue;
                }
                
                int siteSuscIndex = (int) Math.Round(suscIndexSum /sumBio) - 1;
                double protectProp = protectBiomass / sumBio;
                
                if (siteSuscIndex > 2.0 || siteSuscIndex < 0)
                {
                    PlugIn.ModelCore.UI.WriteLine("SuscIndex < 0 || > 2.  Site R/C={0}/{1},suscIndex={2},suscIndexSum={3},sumBio={4}.", site.Location.Row, site.Location.Column, siteSuscIndex,suscIndexSum,sumBio);
                    throw new ApplicationException("Error: SuscIndex is not between 2.0 and 0.0");
                }
                // Assume that there are no neighbors whatsoever:
                DistributionType dist = insect.SusceptibleTable[siteSuscIndex].Distribution_80.Name;


                //PlugIn.ModelCore.UI.WriteLine("suscIndex={0},suscIndexSum={1},cohortBiomass={2}.", suscIndex,suscIndexSum,sumBio);
                double value1 = insect.SusceptibleTable[siteSuscIndex].Distribution_80.Value1;
                double value2 = insect.SusceptibleTable[siteSuscIndex].Distribution_80.Value2;

                double probability = Distribution.GenerateRandomNum(dist, value1, value2);
                
                // Account for protective effect of Susc Class 4
                if (protectProp > 0)
                {
                    double slope = 1.0;
                    double protectReduce = 1- (protectProp * slope);
                    if (protectReduce > 1)
                        protectReduce = 1;
                    if (protectReduce < 0)
                        protectReduce = 0;
                    probability = probability * protectReduce;
                }
                if(probability > 1.0 || probability < 0)
                {
                    PlugIn.ModelCore.UI.WriteLine("Initial Defoliation Probility < 0 || > 1.  Site R/C={0}/{1}.", site.Location.Row, site.Location.Column);
                    throw new ApplicationException("Error: Probability is not between 1.0 and 0.0");
                }
                
                insect.InitialOutbreakProb[site] = probability; // This probability reflects the protective effects
                //PlugIn.ModelCore.UI.WriteLine("Susceptiblity index={0}.  Outbreak Probability={1:0.00}.  R/C={2}/{3}.", suscIndex, probability, site.Location.Row, site.Location.Column);
            }

            foreach(ActiveSite site in PlugIn.ModelCore.Landscape)
            {

                //get a random site from the stand
                double randomNum = PlugIn.ModelCore.GenerateUniform();
                double randomNum2 = PlugIn.ModelCore.GenerateUniform();
                
                //Create random variability in outbreak area within a simulation so outbreaks are more variable.
                double initialAreaCalibratorRandomNum = (randomNum2 - 0.5) * insect.InitialPatchOutbreakSensitivity / 2;

                //Start spreading!
                if (randomNum < insect.InitialOutbreakProb[site] * (insect.InitialPatchOutbreakSensitivity + initialAreaCalibratorRandomNum))  
                //if(randomNum < SiteVars.InitialOutbreakProb[site] * insect.InitialPatchOutbreakSensitivity)  
                {
            
                    //start with this site (if it's active)
                    ActiveSite currentSite = site;           
            
                    //queue to hold sites to defoliate
                    Queue<ActiveSite> sitesToConsider = new Queue<ActiveSite>();
            
                    //put initial site on queue
                    sitesToConsider.Enqueue(currentSite);
            
                    DistributionType dist = insect.InitialPatchDistr;
                    double targetArea = Distribution.GenerateRandomNum(dist, insect.InitialPatchValue1, insect.InitialPatchValue2);
                    
                    //PlugIn.ModelCore.UI.WriteLine("  Target Patch Area={0:0.0}.", targetArea);
                    double areaSelected = 0.0;
            
                    //loop through stand, defoliating patches of size target area
                    while (sitesToConsider.Count > 0 && areaSelected < targetArea) 
                    {

                        currentSite = sitesToConsider.Dequeue();
                    
                        // Because this is the first year, neighborhood defoliaiton is given a value.
                        // The value is used in Defoliate.DefoliateCohort()
                        insect.NeighborhoodDefoliation[currentSite] = insect.InitialOutbreakProb[currentSite];
                        areaSelected += PlugIn.ModelCore.CellArea;
                        insect.Disturbed[currentSite] = true;

                        //Next, add site's neighbors to the list of
                        //sites to consider.  
                        //loop through the site's neighbors enqueueing all the good ones.

                        //double maxNeighborProb = 0.0;
                        //Site maxNeighbor = currentSite;
                        //bool foundNewNeighbor = false;

                        foreach (RelativeLocation loc in all_neighbor_locations) 
                        {
                            Site neighbor = currentSite.GetNeighbor(loc);

                            //get a neighbor site (if it's non-null and active)
                            if (neighbor != null 
                                && neighbor.IsActive  
                                && !sitesToConsider.Contains((ActiveSite) neighbor)
                                && !insect.Disturbed[neighbor]) 
                            {
                                //insect.Disturbed[currentSite] = true;
                                randomNum = PlugIn.ModelCore.GenerateUniform();

                                /*if (SiteVars.InitialOutbreakProb[neighbor] > maxNeighborProb)
                                {
                                    maxNeighbor = currentSite.GetNeighbor(loc);
                                    maxNeighborProb = SiteVars.InitialOutbreakProb[neighbor];
                                    foundNewNeighbor = true;
                                }*/
                                
                                //check if it's a valid neighbor:
                                if (insect.InitialOutbreakProb[neighbor] * insect.InitialPatchShapeCalibrator > randomNum)
                                {
                                    sitesToConsider.Enqueue((ActiveSite) neighbor);
                                }
                            }
                        }

                        //if(foundNewNeighbor)
                        //    sitesToConsider.Enqueue((ActiveSite) maxNeighbor);

                    } 
                    
                    //PlugIn.ModelCore.UI.WriteLine("   Initial Patch Area Selected={0:0.0}.", areaSelected);
                } 

            } 
        } 
        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);
            }

            InputParameters parameters = new InputParameters();

            InputVar <int> timestep = new InputVar <int>("Timestep");

            ReadVar(timestep);
            parameters.Timestep = timestep.Value;

            //----------------------------------------------------------
            // Read in Map and Log file names.

            InputVar <string> mapNames = new InputVar <string>("MapNames");

            ReadVar(mapNames);
            parameters.MapNamesTemplate = mapNames.Value;

            InputVar <string> logFile = new InputVar <string>("LogFile");

            ReadVar(logFile);
            parameters.LogFileName = logFile.Value;

            //----------------------------------------------------------
            // Last, read in Insect File names,
            // then parse the data in those files into insect parameters.

            InputVar <string> insectFileName = new InputVar <string>("InsectInputFiles");

            ReadVar(insectFileName);

            List <IInsect> insectParameterList = new List <IInsect>();
            InsectParser   insectParser        = new InsectParser();

            IInsect insectParameters = Landis.Data.Load <IInsect>(insectFileName.Value, insectParser);

            insectParameterList.Add(insectParameters);

            // Check that insectParameters for first insect loaded correctly...
            if (insectParameters == null)
            {
                PlugIn.ModelCore.UI.WriteLine("   Biomass Insect:  Insect Parameters NOT loading correctly.");
            }
            else
            {
                PlugIn.ModelCore.UI.WriteLine("Name of Insect = {0}", insectParameters.Name);
            }

            while (!AtEndOfInput)
            {
                StringReader currentLine = new StringReader(CurrentLine);

                ReadValue(insectFileName, currentLine);

                insectParameters = Landis.Data.Load <IInsect>(insectFileName.Value, insectParser);

                insectParameterList.Add(insectParameters);

                // Try moving below loop here because right now it only lists the last insect in ManyInsect...
                //foreach (IInsect activeInsect in insectParameterList)
                //{
                // Check that insectParameters for 2+ insects loaded correctly...
                if (insectParameters == null)
                {
                    PlugIn.ModelCore.UI.WriteLine("   Biomass Insect:  Insect Parameters NOT loading correctly.");
                }
                else
                {
                    PlugIn.ModelCore.UI.WriteLine("Name of Insect = {0}", insectParameters.Name);
                }

                //}

                GetNextLine();
            }

            /*foreach(IInsect activeInsect in insectParameterList)
             * {
             *  if(insectParameters == null)
             *       PlugIn.ModelCore.UI.WriteLine("   Biomass Insect:  Insect Parameters NOT loading correctly.");
             *  else
             *       PlugIn.ModelCore.UI.WriteLine("Name of Insect = {0}", insectParameters.Name);
             *
             * }*/
            parameters.ManyInsect = insectParameterList;

            return(parameters);
        }
示例#13
0
        //---------------------------------------------------------------------
        // Initialize landscape with patches of defoliation during the first year
        public static void InitializeDefoliationPatches(IInsect insect)
        {
            PlugIn.ModelCore.UI.WriteLine("   Initializing Defoliation Patches... ");
            insect.InitialOutbreakProb.ActiveSiteValues = 0.0;
            insect.Disturbed.ActiveSiteValues           = false;

            foreach (ActiveSite site in PlugIn.ModelCore.Landscape)
            {
                double suscIndexSum   = 0.0;
                double sumBio         = 0.0;
                double protectBiomass = 0.0;

                Landis.Library.BiomassCohorts.ISiteCohorts siteCohorts = SiteVars.Cohorts[site];

                foreach (ISpeciesCohorts speciesCohorts in siteCohorts)
                {
                    foreach (ICohort cohort in speciesCohorts)
                    {
                        int sppSuscIndex = insect.Susceptibility[cohort.Species];
                        if (sppSuscIndex == 4)
                        {
                            protectBiomass += cohort.Biomass;
                            sppSuscIndex    = 3;
                        }
                        suscIndexSum += cohort.Biomass * (sppSuscIndex);
                        sumBio       += cohort.Biomass;
                    }
                }


                // If no biomass, no chance of defoliation, go to the next site.
                if (suscIndexSum <= 0 || sumBio <= 0)
                {
                    insect.InitialOutbreakProb[site] = 0.0;
                    continue;
                }

                int    siteSuscIndex = (int)Math.Round(suscIndexSum / sumBio) - 1;
                double protectProp   = protectBiomass / sumBio;

                if (siteSuscIndex > 2.0 || siteSuscIndex < 0)
                {
                    PlugIn.ModelCore.UI.WriteLine("SuscIndex < 0 || > 2.  Site R/C={0}/{1},suscIndex={2},suscIndexSum={3},sumBio={4}.", site.Location.Row, site.Location.Column, siteSuscIndex, suscIndexSum, sumBio);
                    throw new ApplicationException("Error: SuscIndex is not between 2.0 and 0.0");
                }
                // Assume that there are no neighbors whatsoever:
                DistributionType dist = insect.SusceptibleTable[siteSuscIndex].Distribution_80.Name;


                //PlugIn.ModelCore.UI.WriteLine("suscIndex={0},suscIndexSum={1},cohortBiomass={2}.", suscIndex,suscIndexSum,sumBio);
                double value1 = insect.SusceptibleTable[siteSuscIndex].Distribution_80.Value1;
                double value2 = insect.SusceptibleTable[siteSuscIndex].Distribution_80.Value2;

                double probability = Distribution.GenerateRandomNum(dist, value1, value2);

                // Account for protective effect of Susc Class 4
                if (protectProp > 0)
                {
                    double slope         = 1.0;
                    double protectReduce = 1 - (protectProp * slope);
                    if (protectReduce > 1)
                    {
                        protectReduce = 1;
                    }
                    if (protectReduce < 0)
                    {
                        protectReduce = 0;
                    }
                    probability = probability * protectReduce;
                }
                if (probability > 1.0 || probability < 0)
                {
                    PlugIn.ModelCore.UI.WriteLine("Initial Defoliation Probility < 0 || > 1.  Site R/C={0}/{1}.", site.Location.Row, site.Location.Column);
                    throw new ApplicationException("Error: Probability is not between 1.0 and 0.0");
                }

                insect.InitialOutbreakProb[site] = probability; // This probability reflects the protective effects
                //PlugIn.ModelCore.UI.WriteLine("Susceptiblity index={0}.  Outbreak Probability={1:0.00}.  R/C={2}/{3}.", suscIndex, probability, site.Location.Row, site.Location.Column);
            }

            foreach (ActiveSite site in PlugIn.ModelCore.Landscape)
            {
                //get a random site from the stand
                double randomNum  = PlugIn.ModelCore.GenerateUniform();
                double randomNum2 = PlugIn.ModelCore.GenerateUniform();

                //Create random variability in outbreak area within a simulation so outbreaks are more variable.
                double initialAreaCalibratorRandomNum = (randomNum2 - 0.5) * insect.InitialPatchOutbreakSensitivity / 2;

                //Start spreading!
                if (randomNum < insect.InitialOutbreakProb[site] * (insect.InitialPatchOutbreakSensitivity + initialAreaCalibratorRandomNum))
                //if(randomNum < SiteVars.InitialOutbreakProb[site] * insect.InitialPatchOutbreakSensitivity)
                {
                    //start with this site (if it's active)
                    ActiveSite currentSite = site;

                    //queue to hold sites to defoliate
                    Queue <ActiveSite> sitesToConsider = new Queue <ActiveSite>();

                    //put initial site on queue
                    sitesToConsider.Enqueue(currentSite);

                    DistributionType dist       = insect.InitialPatchDistr;
                    double           targetArea = Distribution.GenerateRandomNum(dist, insect.InitialPatchValue1, insect.InitialPatchValue2);

                    //PlugIn.ModelCore.UI.WriteLine("  Target Patch Area={0:0.0}.", targetArea);
                    double areaSelected = 0.0;

                    //loop through stand, defoliating patches of size target area
                    while (sitesToConsider.Count > 0 && areaSelected < targetArea)
                    {
                        currentSite = sitesToConsider.Dequeue();

                        // Because this is the first year, neighborhood defoliaiton is given a value.
                        // The value is used in Defoliate.DefoliateCohort()
                        insect.NeighborhoodDefoliation[currentSite] = insect.InitialOutbreakProb[currentSite];
                        areaSelected += PlugIn.ModelCore.CellArea;
                        insect.Disturbed[currentSite] = true;

                        //Next, add site's neighbors to the list of
                        //sites to consider.
                        //loop through the site's neighbors enqueueing all the good ones.

                        //double maxNeighborProb = 0.0;
                        //Site maxNeighbor = currentSite;
                        //bool foundNewNeighbor = false;

                        foreach (RelativeLocation loc in all_neighbor_locations)
                        {
                            Site neighbor = currentSite.GetNeighbor(loc);

                            //get a neighbor site (if it's non-null and active)
                            if (neighbor != null &&
                                neighbor.IsActive &&
                                !sitesToConsider.Contains((ActiveSite)neighbor) &&
                                !insect.Disturbed[neighbor])
                            {
                                //insect.Disturbed[currentSite] = true;
                                randomNum = PlugIn.ModelCore.GenerateUniform();

                                /*if (SiteVars.InitialOutbreakProb[neighbor] > maxNeighborProb)
                                 * {
                                 *  maxNeighbor = currentSite.GetNeighbor(loc);
                                 *  maxNeighborProb = SiteVars.InitialOutbreakProb[neighbor];
                                 *  foundNewNeighbor = true;
                                 * }*/

                                //check if it's a valid neighbor:
                                if (insect.InitialOutbreakProb[neighbor] * insect.InitialPatchShapeCalibrator > randomNum)
                                {
                                    sitesToConsider.Enqueue((ActiveSite)neighbor);
                                }
                            }
                        }

                        //if(foundNewNeighbor)
                        //    sitesToConsider.Enqueue((ActiveSite) maxNeighbor);
                    }

                    //PlugIn.ModelCore.UI.WriteLine("   Initial Patch Area Selected={0:0.0}.", areaSelected);
                }
            }
        }