//---------------------------------------------------------------------

        public LandUse(
            string name,
            ushort mapCode,
            bool harvestingAllowed,
            LandCover.IChange initialLCC)
        {
            Name = name;
            MapCode = mapCode;
            AllowHarvest = harvestingAllowed;
            LandCoverChange = initialLCC;
        }
Beispiel #2
0
        LandCover.IChange ProcessLandCoverChange(InputVar <string> landCoverChangeType)
        {
            InputVar <bool> repeatableHarvest = new InputVar <bool>("RepeatHarvest?");
            bool            repeatHarvest     = false;

            if (ReadOptionalVar(repeatableHarvest))
            {
                repeatHarvest = repeatableHarvest.Value.Actual;
            }
            LandCover.IChange landCoverChange = null;
            if (landCoverChangeType.Value.Actual == LandCover.NoChange.TypeName)
            {
                landCoverChange = noLandCoverChange;
            }
            else if (landCoverChangeType.Value.Actual == LandCover.RemoveTrees.TypeName)
            {
                LandCover.LandCover.DontParseTrees = true;
                PartialThinning.CohortSelectors.Clear();    //Clear static storage selector to prevent writing across land uses
                InputValues.Register <AgeRange>(PartialThinning.ReadAgeOrRange);
                ICohortSelector selector = selector = ReadSpeciesAndCohorts("LandUse",
                                                                            ParameterNames.Plant,
                                                                            "Tony Bonanza",
                                                                            "LandCoverChange");
                ICohortCutter cohortCutter = CohortCutterFactory.CreateCutter(selector,
                                                                              Main.ExtType);
                Planting.SpeciesList speciesToPlant = ReadSpeciesToPlant();

                landCoverChange = new LandCover.RemoveTrees(cohortCutter, speciesToPlant, repeatHarvest);
                PartialThinning.CohortSelectors.Clear();    //Prevent interactions with Biomass Harvest
                LandCover.LandCover.DontParseTrees = false;
            }
            else if (landCoverChangeType.Value.Actual == LandCover.InsectDefoliation.TypeName)
            {
                //Insects will reduce biomass of cohorts rather than directly affecting demographics
                InputValues.Register <AgeRange>(LandCover.LandCover.ReadAgeOrRange);
                ICohortSelector selector = ReadSpeciesAndCohorts("LandUse",
                                                                 ParameterNames.Plant,
                                                                 "Vito Tortellini",
                                                                 "LandCoverChange");
                Planting.SpeciesList speciesToPlant = ReadSpeciesToPlant();
                landCoverChange = new LandCover.InsectDefoliation(LandCover.LandCover.CohortSelectors, speciesToPlant, repeatHarvest);
                LandCover.LandCover.CohortSelectors.Clear();    //Clear static storage selector to prevent writing across land uses
            }
            else
            {
                throw new InputValueException(landCoverChangeType.Value.String,
                                              "\"{0}\" is not a type of land cover change",
                                              landCoverChangeType.Value.Actual);
            }
            //landCoverChange.PrintLandCoverDetails();
            return(landCoverChange);
        }
Beispiel #3
0
        //---------------------------------------------------------------------

        public LandUse(
            string name,
            ushort mapCode,
            bool harvestingAllowed,
            bool establishmentAllowed,
            LandCover.IChange initialLCC)
        {
            Name               = name;
            MapCode            = mapCode;
            AllowHarvest       = harvestingAllowed;
            AllowEstablishment = establishmentAllowed;
            LandCoverChange    = initialLCC;
        }
Beispiel #4
0
        //---------------------------------------------------------------------

        protected void ReadLandUses()
        {
            InputVar <string> name                = new InputVar <string>("LandUse");
            InputVar <ushort> mapCode             = new InputVar <ushort>("MapCode");
            InputVar <bool>   allowHarvest        = new InputVar <bool>("AllowHarvest?");
            InputVar <string> landCoverChangeType = new InputVar <string>("LandCoverChange");

            Dictionary <string, int> nameLineNumbers    = new Dictionary <string, int>();
            Dictionary <ushort, int> mapCodeLineNumbers = new Dictionary <ushort, int>();

            PartialThinning.InitializeClass();
            while (!AtEndOfInput)
            {
                int nameLineNum = LineNumber;
                ReadVar(name);
                int lineNumber;
                if (nameLineNumbers.TryGetValue(name.Value.Actual, out lineNumber))
                {
                    throw new InputValueException(name.Value.String,
                                                  "The land use \"{0}\" was previously used on line {1}",
                                                  name.Value.Actual, lineNumber);
                }
                else
                {
                    nameLineNumbers[name.Value.Actual] = nameLineNum;
                }

                int mapCodeLineNum = LineNumber;
                ReadVar(mapCode);
                if (mapCodeLineNumbers.TryGetValue(mapCode.Value.Actual, out lineNumber))
                {
                    throw new InputValueException(mapCode.Value.String,
                                                  "The map code \"{0}\" was previously used on line {1}",
                                                  mapCode.Value.Actual, lineNumber);
                }
                else
                {
                    mapCodeLineNumbers[mapCode.Value.Actual] = mapCodeLineNum;
                }

                ReadVar(allowHarvest);

                // By default, a land use allows trees to establish.
                bool allowEstablishment = true;
                if (ReadPreventEstablishment())
                {
                    allowEstablishment = false;
                }

                Dictionary <string, LandCover.IChange> landCoverChanges =
                    new Dictionary <string, LandCover.IChange>();
                List <LandCover.IChange> landCoverList = new List <LandCover.IChange>();
                ReadVar(landCoverChangeType);
                LandCover.IChange landCoverChange = ProcessLandCoverChange(landCoverChangeType);
                landCoverChanges[landCoverChange.Type] = landCoverChange;
                landCoverList.Add(landCoverChange);
                while (ReadOptionalVar(landCoverChangeType)) //Get extra LandCoverChanges
                {
                    if (landCoverChanges.TryGetValue(landCoverChangeType.Value.Actual, out landCoverChange))
                    {
                        throw new InputValueException(landCoverChangeType.Value.String,
                                                      "The land cover change \"{0}\" has already been defined for land use: {1}",
                                                      landCoverChangeType.Value.Actual, name.Value.Actual);
                    }
                    else
                    {
                        landCoverChange = ProcessLandCoverChange(landCoverChangeType);
                        landCoverChanges[landCoverChange.Type] = landCoverChange;
                        landCoverList.Add(landCoverChange);
                    }
                }

                LandCover.IChange[] changes = new LandCover.IChange[landCoverList.Count];
                for (int i = 0; i < landCoverList.Count; i++)
                {
                    changes[i] = landCoverList[i];
                }

                LandUse landUse = new LandUse(name.Value.Actual,
                                              mapCode.Value.Actual,
                                              allowHarvest.Value.Actual,
                                              allowEstablishment,
                                              changes);
                LandUseRegistry.Register(landUse);
            }
        }
        //---------------------------------------------------------------------

        public override void Run()
        {
            if (SiteLog.Enabled)
            {
                SiteLog.TimestepSetUp();
            }

            if (pauseFunction != null)
            {
                pauseFunction.PauseTimestep();
            }

            ProcessInputMap(
                delegate(Site site,
                         LandUse newLandUse)
            {
                LandUse currentLandUse = SiteVars.LandUse[site];
                string siteKey         = null;

                if (newLandUse != currentLandUse)
                {
                    SiteVars.LandUse[site] = newLandUse;
                    siteKey = string.Format("{0} --> {1}", currentLandUse.Name, newLandUse.Name);
                    if (!currentLandUse.AllowEstablishment && newLandUse.AllowEstablishment)
                    {
                        Reproduction.EnableEstablishment((ActiveSite)site);
                    }
                    else if (currentLandUse.AllowEstablishment && !newLandUse.AllowEstablishment)
                    {
                        Reproduction.PreventEstablishment((ActiveSite)site);
                    }

                    if (isDebugEnabled)
                    {
                        log.DebugFormat("    LU at {0}: {1}", site.Location, siteKey);
                    }

                    for (int i = 0; i < newLandUse.LandCoverChanges.Length; i++)
                    {
                        LandCover.IChange LandCoverChange = newLandUse.LandCoverChanges[i];
                        LandCoverChange.ApplyTo((ActiveSite)site, true);
                    }
                }
                else
                {
                    /*if (!currentLandUse.AllowEstablishment)
                     * {
                     *  Reproduction.PreventEstablishment((ActiveSite)site);
                     * }
                     * else
                     * {
                     *  Reproduction.EnableEstablishment((ActiveSite)site);
                     * }*/

                    for (int i = 0; i < currentLandUse.LandCoverChanges.Length; i++)
                    {
                        LandCover.IChange LandCoverChange = newLandUse.LandCoverChanges[i];
                        LandCoverChange.ApplyTo((ActiveSite)site, false);
                    }
                }

                if (SiteLog.Enabled)
                {
                    SiteLog.WriteTotalsFor((ActiveSite)site);
                }

                return(siteKey);
            });

            if (SiteLog.Enabled)
            {
                SiteLog.TimestepTearDown();
            }
        }
        //---------------------------------------------------------------------

        protected void ReadLandUses()
        {
            InputVar <string> name                = new InputVar <string>("LandUse");
            InputVar <ushort> mapCode             = new InputVar <ushort>("MapCode");
            InputVar <bool>   allowHarvest        = new InputVar <bool>("AllowHarvest?");
            InputVar <string> landCoverChangeType = new InputVar <string>("LandCoverChange");

            Dictionary <string, int> nameLineNumbers    = new Dictionary <string, int>();
            Dictionary <ushort, int> mapCodeLineNumbers = new Dictionary <ushort, int>();

            while (!AtEndOfInput)
            {
                int nameLineNum = LineNumber;
                ReadVar(name);
                int lineNumber;
                if (nameLineNumbers.TryGetValue(name.Value.Actual, out lineNumber))
                {
                    throw new InputValueException(name.Value.String,
                                                  "The land use \"{0}\" was previously used on line {1}",
                                                  name.Value.Actual, lineNumber);
                }
                else
                {
                    nameLineNumbers[name.Value.Actual] = nameLineNum;
                }

                int mapCodeLineNum = LineNumber;
                ReadVar(mapCode);
                if (mapCodeLineNumbers.TryGetValue(mapCode.Value.Actual, out lineNumber))
                {
                    throw new InputValueException(mapCode.Value.String,
                                                  "The map code \"{0}\" was previously used on line {1}",
                                                  mapCode.Value.Actual, lineNumber);
                }
                else
                {
                    mapCodeLineNumbers[mapCode.Value.Actual] = mapCodeLineNum;
                }

                ReadVar(allowHarvest);

                // By default, a land use allows trees to establish.
                bool allowEstablishment = true;

                ReadVar(landCoverChangeType);
                LandCover.IChange landCoverChange = null;
                if (landCoverChangeType.Value.Actual == LandCover.NoChange.TypeName)
                {
                    landCoverChange = noLandCoverChange;
                }
                else if (landCoverChangeType.Value.Actual == LandCover.RemoveTrees.TypeName)
                {
                    ICohortSelector selector = ReadSpeciesAndCohorts("LandUse",
                                                                     ParameterNames.Plant,
                                                                     ParameterNames.PreventEstablishment);
                    ICohortCutter cohortCutter = CohortCutterFactory.CreateCutter(selector,
                                                                                  Main.ExtType);
                    Planting.SpeciesList speciesToPlant = ReadSpeciesToPlant();
                    landCoverChange = new LandCover.RemoveTrees(cohortCutter, speciesToPlant);

                    if (ReadPreventEstablishment())
                    {
                        allowEstablishment = false;
                    }
                }
                else
                {
                    throw new InputValueException(landCoverChangeType.Value.String,
                                                  "\"{0}\" is not a type of land cover change",
                                                  landCoverChangeType.Value.Actual);
                }

                LandUse landUse = new LandUse(name.Value.Actual,
                                              mapCode.Value.Actual,
                                              allowHarvest.Value.Actual,
                                              allowEstablishment,
                                              landCoverChange);
                LandUseRegistry.Register(landUse);
            }
        }