Exemple #1
0
        //---------------------------------------------------------------------
        public override void Initialize()
        {
            PlugIn.ModelCore.UI.WriteLine("Initializing " + Names.ExtensionName + " version " + typeof(PlugIn).Assembly.GetName().Version);
            Cohort.DeathEvent += DeathEvent;
            Globals.InitializeCore(ModelCore, ((Parameter <ushort>)Names.GetParameter(Names.IMAX)).Value);
            EcoregionData.Initialize();
            SiteVars.Initialize();

            Landis.Utilities.Directory.EnsureExists("output");

            Timestep = ((Parameter <int>)Names.GetParameter(Names.Timestep)).Value;
            Parameter <string> CohortBinSizeParm = null;

            if (Names.TryGetParameter(Names.CohortBinSize, out CohortBinSizeParm))
            {
                if (Int32.TryParse(CohortBinSizeParm.Value, out CohortBinSize))
                {
                    if (CohortBinSize < Timestep)
                    {
                        throw new System.Exception("CohortBinSize cannot be smaller than Timestep.");
                    }
                    else
                    {
                        PlugIn.ModelCore.UI.WriteLine("Succession timestep = " + Timestep + "; CohortBinSize = " + CohortBinSize + ".");
                    }
                }
                else
                {
                    throw new System.Exception("CohortBinSize is not an integer value.");
                }
            }
            else
            {
                CohortBinSize = Timestep;
            }

            string Parallel = ((Parameter <string>)Names.GetParameter(Names.Parallel)).Value;

            if (Parallel == "false")
            {
                ParallelThreads = 1;
                PlugIn.ModelCore.UI.WriteLine("  MaxParallelThreads = " + ParallelThreads.ToString() + ".");
            }
            else if (Parallel == "true")
            {
                ParallelThreads = -1;
                PlugIn.ModelCore.UI.WriteLine("  MaxParallelThreads determined by system.");
            }
            else
            {
                if (Int32.TryParse(Parallel, out ParallelThreads))
                {
                    if (ParallelThreads < 1)
                    {
                        throw new System.Exception("Parallel cannot be < 1.");
                    }
                    else
                    {
                        PlugIn.ModelCore.UI.WriteLine("  MaxParallelThreads = " + ParallelThreads.ToString() + ".");
                    }
                }
                else
                {
                    throw new System.Exception("Parallel must be 'true', 'false' or an integer >= 1.");
                }
            }
            this.ThreadCount = ParallelThreads;

            FTimeStep = 1.0F / Timestep;

            //Latitude = ((Parameter<float>)PlugIn.GetParameter(Names.Latitude, 0, 90)).Value; // Now an ecoregion parameter

            ObservedClimate.Initialize();
            SpeciesPnET = new SpeciesPnET();
            Landis.Library.PnETCohorts.SpeciesParameters.LoadParameters(SpeciesPnET);

            Hydrology.Initialize();
            SiteCohorts.Initialize();
            string PARunits = ((Parameter <string>)Names.GetParameter(Names.PARunits)).Value;

            if (PARunits != "umol" && PARunits != "W/m2")
            {
                throw new System.Exception("PARunits are not 'umol' or 'W/m2'.");
            }
            InitializeClimateLibrary(); // John McNabb: initialize climate library after EcoregionPnET has been initialized
            //EstablishmentProbability.Initialize(Timestep);  // Not used

            // Initialize Reproduction routines:
            Reproduction.SufficientResources = SufficientResources;
            Reproduction.Establish           = Establish;
            Reproduction.AddNewCohort        = AddNewCohort;
            Reproduction.MaturePresent       = MaturePresent;
            Reproduction.PlantingEstablish   = PlantingEstablish;
            SeedingAlgorithms SeedAlgorithm = (SeedingAlgorithms)Enum.Parse(typeof(SeedingAlgorithms), Names.parameters["SeedingAlgorithm"].Value);

            base.Initialize(ModelCore, SeedAlgorithm);

            StartDate = new DateTime(((Parameter <int>)Names.GetParameter(Names.StartYear)).Value, 1, 15);

            PlugIn.ModelCore.UI.WriteLine("Spinning up biomass or reading from maps...");

            string InitialCommunitiesTXTFile = Names.GetParameter(Names.InitialCommunities).Value;
            string InitialCommunitiesMapFile = Names.GetParameter(Names.InitialCommunitiesMap).Value;

            InitialCommunitiesSpinup = Names.GetParameter(Names.InitialCommunitiesSpinup).Value;
            Parameter <string> LitterMapFile;
            bool litterMapFile = Names.TryGetParameter(Names.LitterMap, out LitterMapFile);
            Parameter <string> WoodyDebrisMapFile;
            bool woodyDebrisMapFile = Names.TryGetParameter(Names.WoodyDebrisMap, out WoodyDebrisMapFile);

            InitializeSites(InitialCommunitiesTXTFile, InitialCommunitiesMapFile, ModelCore);
            if (litterMapFile)
            {
                MapReader.ReadLitterFromMap(LitterMapFile.Value);
            }
            if (woodyDebrisMapFile)
            {
                MapReader.ReadWoodyDebrisFromMap(WoodyDebrisMapFile.Value);
            }

            // Convert PnET cohorts to biomasscohorts
            ISiteVar <Landis.Library.BiomassCohorts.ISiteCohorts> biomassCohorts = PlugIn.ModelCore.Landscape.NewSiteVar <Landis.Library.BiomassCohorts.ISiteCohorts>();

            foreach (ActiveSite site in PlugIn.ModelCore.Landscape)
            {
                biomassCohorts[site] = SiteVars.SiteCohorts[site];

                if (SiteVars.SiteCohorts[site] != null && biomassCohorts[site] == null)
                {
                    throw new System.Exception("Cannot convert PnET SiteCohorts to biomass site cohorts");
                }
            }
            ModelCore.RegisterSiteVar(biomassCohorts, "Succession.BiomassCohorts");

            ISiteVar <Landis.Library.AgeOnlyCohorts.ISiteCohorts> AgeCohortSiteVar = PlugIn.ModelCore.Landscape.NewSiteVar <Landis.Library.AgeOnlyCohorts.ISiteCohorts>();
            ISiteVar <ISiteCohorts> PnETCohorts = PlugIn.ModelCore.Landscape.NewSiteVar <ISiteCohorts>();

            foreach (ActiveSite site in PlugIn.ModelCore.Landscape)
            {
                AgeCohortSiteVar[site]   = SiteVars.SiteCohorts[site];
                PnETCohorts[site]        = SiteVars.SiteCohorts[site];
                SiteVars.FineFuels[site] = SiteVars.Litter[site].Mass;
                IEcoregionPnET ecoregion = EcoregionData.GetPnETEcoregion(PlugIn.ModelCore.Ecoregion[site]);
                IHydrology     hydrology = new Hydrology(ecoregion.FieldCap);
                SiteVars.PressureHead[site] = hydrology.GetPressureHead(ecoregion);
                if (UsingClimateLibrary)
                {
                    SiteVars.ExtremeMinTemp[site] = ((float)Enumerable.Min(Climate.Future_MonthlyData[Climate.Future_MonthlyData.Keys.Min()][ecoregion.Index].MonthlyTemp) - (float)(3.0 * ecoregion.WinterSTD));
                }
                else
                {
                    SiteVars.ExtremeMinTemp[site] = 999;
                }
            }

            ModelCore.RegisterSiteVar(AgeCohortSiteVar, "Succession.AgeCohorts");
            ModelCore.RegisterSiteVar(PnETCohorts, "Succession.CohortsPnET");
        }
        public void CompareWythersWithEarlier()
        {
            string ClimateFileName = @"C:\Users\debruijna\Desktop\PnET-Succession\EricCalibration\Oconto_weather_Temp0_Prec0_PAR0.txt";

            IObservedClimate observed = new ObservedClimate(ClimateFileName);

            //PnETSpeciesParameters	FolN	SLWmax	SLWDel	TOfol	AmaxA	AmaxB	HalfSat	H3	H4	PsnAgeRed	PsnTMin	PsnTOpt	k
            //tsugcana	            1.2	    190	    0	    0.3333	5.3 	21.5	230	    114	235	5	        1	    19	    0.5

            //PnETSpeciesParameters   WUEcnst	MaintResp	DNSC	FracBelowG	EstMoist	EstRad	FracFol	FrActWd
            //tsugcana                6	        0.0005	    0.05	0.33	    1	        1	    0.13	0.00005	<<tsugcan

            /*
            LandisData PnETGenericParameters
            PnETGenericParameters 		Value
            BFolResp			0.1
            TOroot				0.02
            TOwood				0.01
            MaxCanopyLayers			2
            IMAX				70
            >>DNSC				0.05 <<target NSCfraction
            >>MaintResp			0.0025
            PreventEstablishment		true
            wythers				true
            */
            Landis.Core.PostFireRegeneration postfireregen = Landis.Core.PostFireRegeneration.Resprout;
            float wuecnst = 6;
            float dnsc =0.05F;
            float cfracbiomass =0.45F;
            float kwdlit = 0.1F;
            float fracbelowg =0.33F;
            float fracfol =0.13F;
            float fractWd = 0.00005F;
            float psnagered =5;
            ushort h2 =0;
            ushort h3 =114;
            ushort h4 =235;
            float slwdel =0;
            float slwmax =190;
            float tofol =0.3333F;
            float toroot =0.02F;
            float halfsat =230F;
            float initialnsc =7;
            float k =0.5F;
            float towood =0.01F;
            float estrad =1;
            float estmoist =1;
            float follignin =0.2F;
            bool preventestablishment =false;
            float psntopt =19F;
            float q10 =2F;
            float psntmin =1F;
            float dvpd1 =0.05F;
            float dvpd2 =2F;
            float foln =1.2F;
            float amaxa =5.3F;
            float amaxb =21.5F;
            float maintresp =0.0005F;
            float bfolresp =0.1F;
            int Index =0;
            string name = "tsugcana";
            int maxSproutAge =0;
            int minSproutAge =0;
            int maxSeedDist =100;
            int effectiveSeedDist =30;
            float vegReprodProb = 0;
            byte fireTolerance =3;
            byte shadeTolerance =5;
            int maturity =60;
            int longevity =450;

            ISpeciesPNET species = new SpeciesPnET(Landis.Core.PostFireRegeneration.Resprout,
             wuecnst,dnsc,cfracbiomass,kwdlit,fracbelowg,fracfol,fractWd,psnagered,h2,h3,h4,slwdel,slwmax,tofol
            ,toroot,halfsat,initialnsc,k,towood,estrad,estmoist,follignin,preventestablishment,psntopt,q10,psntmin,dvpd1
            ,dvpd2,foln,amaxa,amaxb,maintresp,bfolresp,Index,name,maxSproutAge,minSproutAge,maxSeedDist,effectiveSeedDist,vegReprodProb
            ,fireTolerance,shadeTolerance,maturity,longevity);

            DateTime date = new DateTime(1910, 1,1);
            string fn = @"C:\Users\debruijna\Desktop\FTempRespDayRefResp.txt";
            System.IO.StreamWriter sw = new System.IO.StreamWriter(fn);
            sw.WriteLine("date" + "\t" + "FTempRespDayRefRespWythers" + "\t" + "FTempRespDayRefRespNoWythers");
            while (date < new DateTime(1950, 1, 1))
            {
                IObservedClimate climate =  ObservedClimate.GetData(observed, date);

                float FTempRespDayRefRespWythers = new EcoregionPnETVariables(climate, date, true, new System.Collections.Generic.List<ISpeciesPNET>() { species })[species.Name].FTempRespDayRefResp;

                float FTempRespDayRefRespNoWythers = new EcoregionPnETVariables(climate, date, false, new System.Collections.Generic.List<ISpeciesPNET>() { species })[species.Name].FTempRespDayRefResp;

                sw.WriteLine(date + "\t" + FTempRespDayRefRespWythers + "\t" + FTempRespDayRefRespNoWythers);

                date = date.AddMonths(1);
            }
            sw.Close();
        }
        public override void Initialize()
        {
            PlugIn.ModelCore.UI.WriteLine("Initializing " + Names.ExtensionName + " version " + typeof(PlugIn).Assembly.GetName().Version);
            Cohort.DeathEvent += DeathEvent;

            Litter         = PlugIn.ModelCore.Landscape.NewSiteVar <Landis.Library.Biomass.Pool>();
            WoodyDebris    = PlugIn.ModelCore.Landscape.NewSiteVar <Landis.Library.Biomass.Pool>();
            sitecohorts    = PlugIn.ModelCore.Landscape.NewSiteVar <SiteCohorts>();
            FineFuels      = ModelCore.Landscape.NewSiteVar <Double>();
            PressureHead   = ModelCore.Landscape.NewSiteVar <float>();
            ExtremeMinTemp = ModelCore.Landscape.NewSiteVar <float>();
            Landis.Utilities.Directory.EnsureExists("output");

            Timestep = ((Parameter <int>)GetParameter(Names.Timestep)).Value;
            Parameter <string> CohortBinSizeParm = null;

            if (TryGetParameter(Names.CohortBinSize, out CohortBinSizeParm))
            {
                if (Int32.TryParse(CohortBinSizeParm.Value, out CohortBinSize))
                {
                    if (CohortBinSize < Timestep)
                    {
                        throw new System.Exception("CohortBinSize cannot be smaller than Timestep.");
                    }
                    else
                    {
                        PlugIn.ModelCore.UI.WriteLine("Succession timestep = " + Timestep + "; CohortBinSize = " + CohortBinSize + ".");
                    }
                }
                else
                {
                    throw new System.Exception("CohortBinSize is not an integer value.");
                }
            }
            else
            {
                CohortBinSize = Timestep;
            }


            FTimeStep = 1.0F / Timestep;

            //Latitude = ((Parameter<float>)PlugIn.GetParameter(Names.Latitude, 0, 90)).Value; // Now an ecoregion parameter

            ObservedClimate.Initialize();

            SpeciesPnET = new SpeciesPnET();

            EcoregionPnET.Initialize();
            Hydrology.Initialize();
            SiteCohorts.Initialize();

            // John McNabb: initialize climate library after EcoregionPnET has been initialized
            InitializeClimateLibrary();

            EstablishmentProbability.Initialize(Timestep);

            IMAX = ((Parameter <ushort>)GetParameter(Names.IMAX)).Value;
            //LeakageFrostDepth = ((Parameter<float>)GetParameter(Names.LeakageFrostDepth)).Value; //Now an ecoregion parameter
            //PrecipEvents = ((Parameter<float>)GetParameter(Names.PrecipEvents)).Value;// Now an ecoregion parameter


            // Initialize Reproduction routines:
            Reproduction.SufficientResources = SufficientResources;
            Reproduction.Establish           = Establish;
            Reproduction.AddNewCohort        = AddNewCohort;
            Reproduction.MaturePresent       = MaturePresent;
            Reproduction.PlantingEstablish   = PlantingEstablish;


            SeedingAlgorithms SeedAlgorithm = (SeedingAlgorithms)Enum.Parse(typeof(SeedingAlgorithms), parameters["SeedingAlgorithm"].Value);

            base.Initialize(ModelCore, SeedAlgorithm);


            StartDate = new DateTime(((Parameter <int>)GetParameter(Names.StartYear)).Value, 1, 15);

            PlugIn.ModelCore.UI.WriteLine("Spinning up biomass or reading from maps...");

            string             InitialCommunitiesTXTFile = GetParameter(Names.InitialCommunities).Value;
            string             InitialCommunitiesMapFile = GetParameter(Names.InitialCommunitiesMap).Value;
            Parameter <string> LitterMapFile;
            bool litterMapFile = TryGetParameter(Names.LitterMap, out LitterMapFile);
            Parameter <string> WoodyDebrisMapFile;
            bool woodyDebrisMapFile = TryGetParameter(Names.WoodyDebrisMap, out WoodyDebrisMapFile);

            //Console.ReadLine();
            InitializeSites(InitialCommunitiesTXTFile, InitialCommunitiesMapFile, ModelCore);
            if (litterMapFile)
            {
                MapReader.ReadLitterFromMap(LitterMapFile.Value);
            }
            if (woodyDebrisMapFile)
            {
                MapReader.ReadWoodyDebrisFromMap(WoodyDebrisMapFile.Value);
            }

            // Convert PnET cohorts to biomasscohorts
            ISiteVar <Landis.Library.BiomassCohorts.ISiteCohorts> biomassCohorts = PlugIn.ModelCore.Landscape.NewSiteVar <Landis.Library.BiomassCohorts.ISiteCohorts>();


            foreach (ActiveSite site in PlugIn.ModelCore.Landscape)
            {
                biomassCohorts[site] = sitecohorts[site];

                if (sitecohorts[site] != null && biomassCohorts[site] == null)
                {
                    throw new System.Exception("Cannot convert PnET SiteCohorts to biomass site cohorts");
                }
            }
            ModelCore.RegisterSiteVar(biomassCohorts, "Succession.BiomassCohorts");
            ModelCore.RegisterSiteVar(WoodyDebris, "Succession.WoodyDebris");
            ModelCore.RegisterSiteVar(Litter, "Succession.Litter");


            ISiteVar <Landis.Library.AgeOnlyCohorts.ISiteCohorts> AgeCohortSiteVar = PlugIn.ModelCore.Landscape.NewSiteVar <Landis.Library.AgeOnlyCohorts.ISiteCohorts>();
            ISiteVar <ISiteCohorts> PnETCohorts = PlugIn.ModelCore.Landscape.NewSiteVar <ISiteCohorts>();


            foreach (ActiveSite site in PlugIn.ModelCore.Landscape)
            {
                AgeCohortSiteVar[site] = sitecohorts[site];
                PnETCohorts[site]      = sitecohorts[site];
                FineFuels[site]        = Litter[site].Mass;
                IEcoregionPnET ecoregion = EcoregionPnET.GetPnETEcoregion(PlugIn.ModelCore.Ecoregion[site]);
                IHydrology     hydrology = new Hydrology(ecoregion.FieldCap);
                PressureHead[site] = hydrology.GetPressureHead(ecoregion);
                if (UsingClimateLibrary)
                {
                    ExtremeMinTemp[site] = ((float)Enumerable.Min(Climate.Future_MonthlyData[Climate.Future_MonthlyData.Keys.Min()][ecoregion.Index].MonthlyTemp) - (float)(3.0 * ecoregion.WinterSTD));
                }
                else
                {
                    ExtremeMinTemp[site] = 999;
                }
            }

            ModelCore.RegisterSiteVar(AgeCohortSiteVar, "Succession.AgeCohorts");
            ModelCore.RegisterSiteVar(PnETCohorts, "Succession.CohortsPnET");
            ModelCore.RegisterSiteVar(FineFuels, "Succession.FineFuels");
            ModelCore.RegisterSiteVar(PressureHead, "Succession.PressureHead");
            ModelCore.RegisterSiteVar(ExtremeMinTemp, "Succession.ExtremeMinTemp");
        }
        public SpeciesPnET()
        {
            #region initialization of private static species variables
            wuecnst = ((Landis.Library.Parameters.Species.AuxParm<float>)(Parameter<float>)PlugIn.GetParameter("WUEcnst"));
            dnsc =  ((Landis.Library.Parameters.Species.AuxParm<float>)(Parameter<float>)PlugIn.GetParameter("DNSC"));
            cfracbiomass=  ((Landis.Library.Parameters.Species.AuxParm<float>)(Parameter<float>)PlugIn.GetParameter("CFracBiomass"));
            kwdlit = ((Landis.Library.Parameters.Species.AuxParm<float>)(Parameter<float>)PlugIn.GetParameter("kwdlit"));
            fracbelowg = ((Landis.Library.Parameters.Species.AuxParm<float>)(Parameter<float>)PlugIn.GetParameter("fracbelowg"));
            fracfol = ((Landis.Library.Parameters.Species.AuxParm<float>)(Parameter<float>)PlugIn.GetParameter("fracfol"));
            fractWd = ((Landis.Library.Parameters.Species.AuxParm<float>)(Parameter<float>)PlugIn.GetParameter("fractWd"));
            psnagered = ((Landis.Library.Parameters.Species.AuxParm<float>)(Parameter<float>)PlugIn.GetParameter("psnagered"));
            h2 = ((Landis.Library.Parameters.Species.AuxParm<ushort>)(Parameter<ushort>)PlugIn.GetParameter("h2"));
            h3 = ((Landis.Library.Parameters.Species.AuxParm<ushort>)(Parameter<ushort>)PlugIn.GetParameter("h3"));
            h4 = ((Landis.Library.Parameters.Species.AuxParm<ushort>)(Parameter<ushort>)PlugIn.GetParameter("h4"));
            slwdel = ((Landis.Library.Parameters.Species.AuxParm<float>)(Parameter<float>)PlugIn.GetParameter("slwdel"));
            slwmax = ((Landis.Library.Parameters.Species.AuxParm<float>)(Parameter<float>)PlugIn.GetParameter("slwmax"));
            tofol = ((Landis.Library.Parameters.Species.AuxParm<float>)(Parameter<float>)PlugIn.GetParameter("tofol"));
            halfsat = ((Landis.Library.Parameters.Species.AuxParm<float>)(Parameter<float>)PlugIn.GetParameter("halfsat"));
            toroot = ((Landis.Library.Parameters.Species.AuxParm<float>)(Parameter<float>)PlugIn.GetParameter("toroot"));
            initialnsc = ((Landis.Library.Parameters.Species.AuxParm<float>)(Parameter<float>)PlugIn.GetParameter("initialnsc")); ;
            k = ((Landis.Library.Parameters.Species.AuxParm<float>)(Parameter<float>)PlugIn.GetParameter("k")); ;
            towood = ((Landis.Library.Parameters.Species.AuxParm<float>)(Parameter<float>)PlugIn.GetParameter("towood")); ;
            estrad = ((Landis.Library.Parameters.Species.AuxParm<float>)(Parameter<float>)PlugIn.GetParameter("estrad")); ;
            estmoist = ((Landis.Library.Parameters.Species.AuxParm<float>)(Parameter<float>)PlugIn.GetParameter("estmoist"));
            follignin = ((Landis.Library.Parameters.Species.AuxParm<float>)(Parameter<float>)PlugIn.GetParameter("follignin"));
            preventestablishment = ((Landis.Library.Parameters.Species.AuxParm<bool>)(Parameter<bool>)PlugIn.GetParameter("preventestablishment"));
            psntopt = ((Landis.Library.Parameters.Species.AuxParm<float>)(Parameter<float>)PlugIn.GetParameter("psntopt"));
            q10 = ((Landis.Library.Parameters.Species.AuxParm<float>)(Parameter<float>)PlugIn.GetParameter("q10"));
            psntmin = ((Landis.Library.Parameters.Species.AuxParm<float>)(Parameter<float>)PlugIn.GetParameter("psntmin"));
            dvpd1 = ((Landis.Library.Parameters.Species.AuxParm<float>)(Parameter<float>)PlugIn.GetParameter("dvpd1"));
            dvpd2 = ((Landis.Library.Parameters.Species.AuxParm<float>)(Parameter<float>)PlugIn.GetParameter("dvpd2"));
            foln = ((Landis.Library.Parameters.Species.AuxParm<float>)(Parameter<float>)PlugIn.GetParameter("foln"));
            amaxa = ((Landis.Library.Parameters.Species.AuxParm<float>)(Parameter<float>)PlugIn.GetParameter("amaxa"));
            amaxb = ((Landis.Library.Parameters.Species.AuxParm<float>)(Parameter<float>)PlugIn.GetParameter("amaxb"));
            maintresp = ((Landis.Library.Parameters.Species.AuxParm<float>)(Parameter<float>)PlugIn.GetParameter("maintresp"));
            bfolresp = ((Landis.Library.Parameters.Species.AuxParm<float>)(Parameter<float>)PlugIn.GetParameter("bfolresp"));
            #endregion

            SpeciesCombinations = new List<Tuple<ISpecies, ISpeciesPNET>>();

            foreach (ISpecies spc in PlugIn.ModelCore.Species)
            {
                SpeciesPnET species = new SpeciesPnET(spc);

                SpeciesCombinations.Add(new Tuple<ISpecies, ISpeciesPNET>(spc, species));
            }
        }