public static void InitializeMetadata(int Timestep, OutputVariable LAI, OutputVariable Biomass, OutputVariable AbovegroundBiomass, OutputVariable EstablishmentProbability, ISiteVar <Landis.Library.Parameters.Species.AuxParm <bool> > SpeciesWasThere, OutputVariable AnnualPsn, OutputVariable BelowGround, OutputVariable CohortsPerSpc, OutputVariable Water, OutputVariable SubCanopyPAR, OutputVariable NonWoodyDebris, OutputVariable WoodyDebris, OutputVariable AgeDistribution, OutputVariable MonthlyFolResp, OutputVariable MonthlyGrossPsn, OutputVariable MonthlyNetPsn, OutputVariable MonthlyMaintResp, OutputVariable SpeciesEstablishment, ISiteVar <Library.Parameters.Species.AuxParm <int> > LastBiom, OutputAggregatedTable overalloutputs, string OutputTableMap)
        {
            ScenarioReplicationMetadata scenRep = new ScenarioReplicationMetadata()
            {
                RasterOutCellArea = PlugIn.ModelCore.CellArea,
                TimeMin           = PlugIn.ModelCore.StartTime,
                TimeMax           = PlugIn.ModelCore.EndTime,
            };

            Extension = new ExtensionMetadata(PlugIn.ModelCore)
                        //Extension = new ExtensionMetadata()
            {
                Name         = PlugIn.ExtensionName,
                TimeInterval = Timestep,
                ScenarioReplicationMetadata = scenRep
            };
            //---------------------------------------
            //          table outputs:
            //---------------------------------------
            if (overalloutputs != null)
            {
                PlugIn.ModelCore.UI.WriteLine("   Generating summary table...");
                CreateDirectory(OutputTableMap);

                OutputMetadata tblOut_OverallOutputs = new OutputMetadata()
                {
                    Type         = OutputType.Table,
                    Name         = Path.GetFileName(OutputTableMap),
                    FilePath     = OutputTableMap,
                    Map_DataType = MapDataType.Continuous,
                    Visualize    = true,
                };
                tblOut_OverallOutputs.RetriveFields(typeof(OutputAggregatedTable));
                Extension.OutputMetadatas.Add(tblOut_OverallOutputs);
            }


            //---------------------------------------
            //          map outputs:
            //---------------------------------------

            //OutputMetadata mapOut_BiomassRemoved = new OutputMetadata()
            //{
            //    Type = OutputType.Map,
            //    Name = "biomass removed",
            //    FilePath = @HarvestMapName,
            //    Map_DataType = MapDataType.Continuous,
            //    Map_Unit = FieldUnits.Mg_ha,
            //    Visualize = true,
            //};
            //Extension.OutputMetadatas.Add(mapOut_BiomassRemoved);

            if (LAI != null)
            {
                OutputMetadata mapOut_LAI = new OutputMetadata()
                {
                    Type         = OutputType.Map,
                    Name         = FileNames.ReplaceTemplateVars(LAI.MapNameTemplate, "", PlugIn.ModelCore.CurrentTime),
                    FilePath     = FileNames.ReplaceTemplateVars(LAI.MapNameTemplate, "", PlugIn.ModelCore.CurrentTime),
                    Map_DataType = MapDataType.Continuous,
                    Visualize    = true,
                    //Map_Unit = "categorical",
                };
                Extension.OutputMetadatas.Add(mapOut_LAI);
            }

            if (Biomass != null)
            {
                foreach (ISpecies spc in PlugIn.SelectedSpecies)
                {
                    OutputMetadata mapOut_Biomass = new OutputMetadata()
                    {
                        Type         = OutputType.Map,
                        Name         = FileNames.ReplaceTemplateVars(Biomass.MapNameTemplate, spc.Name, PlugIn.ModelCore.CurrentTime),
                        FilePath     = FileNames.ReplaceTemplateVars(Biomass.MapNameTemplate, spc.Name, PlugIn.ModelCore.CurrentTime),
                        Map_DataType = MapDataType.Continuous,
                        Visualize    = true,
                        //Map_Unit = "categorical",
                    };
                    Extension.OutputMetadatas.Add(mapOut_Biomass);
                }
            }
            if (AbovegroundBiomass != null)
            {
                foreach (ISpecies spc in PlugIn.SelectedSpecies)
                {
                    OutputMetadata mapOut_AbvBiomass = new OutputMetadata()
                    {
                        Type         = OutputType.Map,
                        Name         = FileNames.ReplaceTemplateVars(AbovegroundBiomass.MapNameTemplate, spc.Name, PlugIn.ModelCore.CurrentTime),
                        FilePath     = FileNames.ReplaceTemplateVars(AbovegroundBiomass.MapNameTemplate, spc.Name, PlugIn.ModelCore.CurrentTime),
                        Map_DataType = MapDataType.Continuous,
                        Visualize    = true,
                        //Map_Unit = "categorical",
                    };
                    Extension.OutputMetadatas.Add(mapOut_AbvBiomass);
                }
            }
            if (MonthlyFolResp != null)
            {
                OutputMetadata mapOut_Monthly = new OutputMetadata()
                {
                    Type         = OutputType.Map,
                    Name         = FileNames.ReplaceTemplateVars(MonthlyFolResp.MapNameTemplate, "", PlugIn.ModelCore.CurrentTime),
                    FilePath     = FileNames.ReplaceTemplateVars(MonthlyFolResp.MapNameTemplate, "", PlugIn.ModelCore.CurrentTime),
                    Map_DataType = MapDataType.Continuous,
                    Visualize    = true,
                    //Map_Unit = "categorical",
                };
                Extension.OutputMetadatas.Add(mapOut_Monthly);
            }
            if (MonthlyGrossPsn != null)
            {
                OutputMetadata mapOut_Monthly = new OutputMetadata()
                {
                    Type         = OutputType.Map,
                    Name         = FileNames.ReplaceTemplateVars(MonthlyGrossPsn.MapNameTemplate, "", PlugIn.ModelCore.CurrentTime),
                    FilePath     = FileNames.ReplaceTemplateVars(MonthlyGrossPsn.MapNameTemplate, "", PlugIn.ModelCore.CurrentTime),
                    Map_DataType = MapDataType.Continuous,
                    Visualize    = true,
                    //Map_Unit = "categorical",
                };
                Extension.OutputMetadatas.Add(mapOut_Monthly);
            }
            if (MonthlyNetPsn != null)
            {
                OutputMetadata mapOut_Monthly = new OutputMetadata()
                {
                    Type         = OutputType.Map,
                    Name         = FileNames.ReplaceTemplateVars(MonthlyNetPsn.MapNameTemplate, "", PlugIn.ModelCore.CurrentTime),
                    FilePath     = FileNames.ReplaceTemplateVars(MonthlyNetPsn.MapNameTemplate, "", PlugIn.ModelCore.CurrentTime),
                    Map_DataType = MapDataType.Continuous,
                    Visualize    = true,
                    //Map_Unit = "categorical",
                };
                Extension.OutputMetadatas.Add(mapOut_Monthly);
            }
            if (MonthlyMaintResp != null)
            {
                OutputMetadata mapOut_Monthly = new OutputMetadata()
                {
                    Type         = OutputType.Map,
                    Name         = FileNames.ReplaceTemplateVars(MonthlyMaintResp.MapNameTemplate, "", PlugIn.ModelCore.CurrentTime),
                    FilePath     = FileNames.ReplaceTemplateVars(MonthlyMaintResp.MapNameTemplate, "", PlugIn.ModelCore.CurrentTime),
                    Map_DataType = MapDataType.Continuous,
                    Visualize    = true,
                    //Map_Unit = "categorical",
                };
                Extension.OutputMetadatas.Add(mapOut_Monthly);
            }
            if (BelowGround != null)
            {
                OutputMetadata mapOut_BelowGround = new OutputMetadata()
                {
                    Type         = OutputType.Map,
                    Name         = FileNames.ReplaceTemplateVars(BelowGround.MapNameTemplate, "", PlugIn.ModelCore.CurrentTime),
                    FilePath     = FileNames.ReplaceTemplateVars(BelowGround.MapNameTemplate, "", PlugIn.ModelCore.CurrentTime),
                    Map_DataType = MapDataType.Continuous,
                    Visualize    = true,
                    //Map_Unit = "categorical",
                };
                Extension.OutputMetadatas.Add(mapOut_BelowGround);
            }
            if (CohortsPerSpc != null)
            {
                foreach (ISpecies spc in PlugIn.ModelCore.Species)
                {
                    OutputMetadata mapOut_LAI = new OutputMetadata()
                    {
                        Type         = OutputType.Map,
                        Name         = FileNames.ReplaceTemplateVars(CohortsPerSpc.MapNameTemplate, "", PlugIn.ModelCore.CurrentTime),
                        FilePath     = FileNames.ReplaceTemplateVars(CohortsPerSpc.MapNameTemplate, "", PlugIn.ModelCore.CurrentTime),
                        Map_DataType = MapDataType.Continuous,
                        Visualize    = true,
                        //Map_Unit = "categorical",
                    };
                    Extension.OutputMetadatas.Add(mapOut_LAI);
                }
            }
            if (EstablishmentProbability != null)
            {
                foreach (ISpecies spc in PlugIn.SelectedSpecies)
                {
                    OutputMetadata mapOut_EProb = new OutputMetadata()
                    {
                        Type         = OutputType.Map,
                        Name         = FileNames.ReplaceTemplateVars(EstablishmentProbability.MapNameTemplate, spc.Name, PlugIn.ModelCore.CurrentTime),
                        FilePath     = FileNames.ReplaceTemplateVars(EstablishmentProbability.MapNameTemplate, spc.Name, PlugIn.ModelCore.CurrentTime),
                        Map_DataType = MapDataType.Continuous,
                        Visualize    = true,
                        //Map_Unit = "categorical",
                    };
                    Extension.OutputMetadatas.Add(mapOut_EProb);
                }
            }
            if (SpeciesEstablishment != null)
            {
                if (SpeciesWasThere != null)
                {
                    foreach (ISpecies spc in PlugIn.ModelCore.Species)
                    {
                        OutputMetadata mapOut_SpeciesE = new OutputMetadata()
                        {
                            Type         = OutputType.Map,
                            Name         = FileNames.ReplaceTemplateVars(SpeciesEstablishment.MapNameTemplate, spc.Name, PlugIn.ModelCore.CurrentTime),
                            FilePath     = FileNames.ReplaceTemplateVars(SpeciesEstablishment.MapNameTemplate, spc.Name, PlugIn.ModelCore.CurrentTime),
                            Map_DataType = MapDataType.Continuous,
                            Visualize    = true,
                            //Map_Unit = "categorical",
                        };
                        Extension.OutputMetadatas.Add(mapOut_SpeciesE);
                    }
                }

                OutputMetadata mapOut_SpeciesE2 = new OutputMetadata()
                {
                    Type         = OutputType.Map,
                    Name         = FileNames.ReplaceTemplateVars(SpeciesEstablishment.MapNameTemplate).Replace(".img", ".txt"),
                    FilePath     = FileNames.ReplaceTemplateVars(SpeciesEstablishment.MapNameTemplate).Replace(".img", ".txt"),
                    Map_DataType = MapDataType.Continuous,
                    Visualize    = true,
                    //Map_Unit = "categorical",
                };
                Extension.OutputMetadatas.Add(mapOut_SpeciesE2);
            }
            if (AnnualPsn != null)
            {
                if (LastBiom != null)
                {
                    foreach (ISpecies spc in PlugIn.ModelCore.Species)
                    {
                        OutputMetadata mapOut_AnnualPsn = new OutputMetadata()
                        {
                            Type         = OutputType.Map,
                            Name         = FileNames.ReplaceTemplateVars(AnnualPsn.MapNameTemplate, spc.Name, PlugIn.ModelCore.CurrentTime),
                            FilePath     = FileNames.ReplaceTemplateVars(AnnualPsn.MapNameTemplate, spc.Name, PlugIn.ModelCore.CurrentTime),
                            Map_DataType = MapDataType.Continuous,
                            Visualize    = true,
                            //Map_Unit = "categorical",
                        };
                        Extension.OutputMetadatas.Add(mapOut_AnnualPsn);
                    }
                }
            }
            if (Water != null)
            {
                OutputMetadata mapOut_Water = new OutputMetadata()
                {
                    Type         = OutputType.Map,
                    Name         = FileNames.ReplaceTemplateVars(Water.MapNameTemplate, "", PlugIn.ModelCore.CurrentTime),
                    FilePath     = FileNames.ReplaceTemplateVars(Water.MapNameTemplate, "", PlugIn.ModelCore.CurrentTime),
                    Map_DataType = MapDataType.Continuous,
                    Visualize    = true,
                    //Map_Unit = "categorical",
                };
                Extension.OutputMetadatas.Add(mapOut_Water);
            }
            if (SubCanopyPAR != null)
            {
                OutputMetadata mapOut_SubCanopyPAR = new OutputMetadata()
                {
                    Type         = OutputType.Map,
                    Name         = FileNames.ReplaceTemplateVars(SubCanopyPAR.MapNameTemplate, "", PlugIn.ModelCore.CurrentTime),
                    FilePath     = FileNames.ReplaceTemplateVars(SubCanopyPAR.MapNameTemplate, "", PlugIn.ModelCore.CurrentTime),
                    Map_DataType = MapDataType.Continuous,
                    Visualize    = true,
                    //Map_Unit = "categorical",
                };
                Extension.OutputMetadatas.Add(mapOut_SubCanopyPAR);
            }
            if (NonWoodyDebris != null)
            {
                OutputMetadata mapOut_NonWoodyDebris = new OutputMetadata()
                {
                    Type         = OutputType.Map,
                    Name         = FileNames.ReplaceTemplateVars(NonWoodyDebris.MapNameTemplate, "", PlugIn.ModelCore.CurrentTime),
                    FilePath     = FileNames.ReplaceTemplateVars(NonWoodyDebris.MapNameTemplate, "", PlugIn.ModelCore.CurrentTime),
                    Map_DataType = MapDataType.Continuous,
                    Visualize    = true,
                    //Map_Unit = "categorical",
                };
                Extension.OutputMetadatas.Add(mapOut_NonWoodyDebris);
            }
            if (WoodyDebris != null)
            {
                OutputMetadata mapOut_WoodyDebris = new OutputMetadata()
                {
                    Type         = OutputType.Map,
                    Name         = FileNames.ReplaceTemplateVars(WoodyDebris.MapNameTemplate, "", PlugIn.ModelCore.CurrentTime),
                    FilePath     = FileNames.ReplaceTemplateVars(WoodyDebris.MapNameTemplate, "", PlugIn.ModelCore.CurrentTime),
                    Map_DataType = MapDataType.Continuous,
                    Visualize    = true,
                    //Map_Unit = "categorical",
                };
                Extension.OutputMetadatas.Add(mapOut_WoodyDebris);
            }
            if (AgeDistribution != null)
            {
                OutputMetadata mapOut_AgeDistribution = new OutputMetadata()
                {
                    Type         = OutputType.Map,
                    Name         = FileNames.ReplaceTemplateVars(AgeDistribution.MapNameTemplate, "", PlugIn.ModelCore.CurrentTime),
                    FilePath     = FileNames.ReplaceTemplateVars(AgeDistribution.MapNameTemplate, "", PlugIn.ModelCore.CurrentTime),
                    Map_DataType = MapDataType.Continuous,
                    Visualize    = true,
                    //Map_Unit = "categorical",
                };
                Extension.OutputMetadatas.Add(mapOut_AgeDistribution);
            }

            //---------------------------------------
            MetadataProvider mp = new MetadataProvider(Extension);

            mp.WriteMetadataToXMLFile("Metadata", Extension.Name, Extension.Name);
        }
Пример #2
0
        public override void Run()
        {
            if (LAI != null)
            {
                System.Console.WriteLine("Updating output variable: LAI");
                // Total LAI per site

                ISiteVar <byte> values = cohorts.GetIsiteVar(o => o.CanopyLAImax);

                string FileName = FileNames.ReplaceTemplateVars(LAI.MapNameTemplate, "", PlugIn.ModelCore.CurrentTime);

                new OutputMapSiteVar <byte, byte>(FileName, values, o => o);

                // Values per species each time step
                LAI.output_table_ecoregions.WriteUpdate(PlugIn.ModelCore.CurrentTime, values);
            }
            if (Biomass != null)
            {
                System.Console.WriteLine("Updating output variable: Biomass");

                ISiteVar <Landis.Library.Parameters.Species.AuxParm <int> > Biom = cohorts.GetIsiteVar(o => o.BiomassPerSpecies);

                foreach (ISpecies spc in PlugIn.SelectedSpecies)
                {
                    ISiteVar <int> Biom_spc = modelCore.Landscape.NewSiteVar <int>();

                    foreach (ActiveSite site in PlugIn.modelCore.Landscape)
                    {
                        Biom_spc[site] = Biom[site][spc];
                    }

                    new OutputMapSpecies(Biom_spc, spc, Biomass.MapNameTemplate);
                }

                OutputFilePerTStepPerSpecies.Write <int>(Biomass.MapNameTemplate, Biomass.units, PlugIn.ModelCore.CurrentTime, Biom);

                ISiteVar <float> Biomass_site = cohorts.GetIsiteVar(x => x.BiomassSum);

                Biomass.output_table_ecoregions.WriteUpdate <float>(PlugIn.ModelCore.CurrentTime, Biomass_site);
            }
            if (AbovegroundBiomass != null)
            {
                System.Console.WriteLine("Updating output variable: Aboveground Biomass");

                ISiteVar <Landis.Library.Parameters.Species.AuxParm <int> > AGBiom = cohorts.GetIsiteVar(o => o.AbovegroundBiomassPerSpecies);

                foreach (ISpecies spc in PlugIn.SelectedSpecies)
                {
                    ISiteVar <int> AGBiom_spc = modelCore.Landscape.NewSiteVar <int>();

                    foreach (ActiveSite site in PlugIn.modelCore.Landscape)
                    {
                        AGBiom_spc[site] = AGBiom[site][spc];
                    }

                    new OutputMapSpecies(AGBiom_spc, spc, AbovegroundBiomass.MapNameTemplate);
                }

                OutputFilePerTStepPerSpecies.Write <int>(AbovegroundBiomass.MapNameTemplate, AbovegroundBiomass.units, PlugIn.ModelCore.CurrentTime, AGBiom);

                ISiteVar <float> AGBiomass_site = cohorts.GetIsiteVar(x => x.AbovegroundBiomassSum);

                AbovegroundBiomass.output_table_ecoregions.WriteUpdate <float>(PlugIn.ModelCore.CurrentTime, AGBiomass_site);
            }
            if (WoodySenescence != null)
            {
                System.Console.WriteLine("Updating output variable: Woody Senescence");

                ISiteVar <Landis.Library.Parameters.Species.AuxParm <int> > Senes = cohorts.GetIsiteVar(o => o.WoodySenescencePerSpecies);

                /*
                 * foreach (ISpecies spc in PlugIn.SelectedSpecies)
                 * {
                 *  ISiteVar<int> Senes_spc = modelCore.Landscape.NewSiteVar<int>();
                 *
                 *  foreach (ActiveSite site in PlugIn.modelCore.Landscape)
                 *  {
                 *      Senes_spc[site] = Senes[site][spc];
                 *
                 *  }
                 *
                 *  new OutputMapSpecies(Senes_spc, spc, WoodySenescence.MapNameTemplate);
                 * }
                 */
                OutputFilePerTStepPerSpecies.Write <int>(WoodySenescence.MapNameTemplate, WoodySenescence.units, PlugIn.ModelCore.CurrentTime, Senes);

                ISiteVar <float> Senescence_site = cohorts.GetIsiteVar(x => x.WoodySenescenceSum);

                WoodySenescence.output_table_ecoregions.WriteUpdate <float>(PlugIn.ModelCore.CurrentTime, Senescence_site);
            }
            if (FoliageSenescence != null)
            {
                System.Console.WriteLine("Updating output variable: Foliage Senescence");

                ISiteVar <Landis.Library.Parameters.Species.AuxParm <int> > Senes = cohorts.GetIsiteVar(o => o.FoliageSenescencePerSpecies);

                /*foreach (ISpecies spc in PlugIn.SelectedSpecies)
                 * {
                 *  ISiteVar<int> Senes_spc = modelCore.Landscape.NewSiteVar<int>();
                 *
                 *  foreach (ActiveSite site in PlugIn.modelCore.Landscape)
                 *  {
                 *      Senes_spc[site] = Senes[site][spc];
                 *  }
                 *
                 *  new OutputMapSpecies(Senes_spc, spc, FoliageSenescence.MapNameTemplate);
                 * }
                 */
                OutputFilePerTStepPerSpecies.Write <int>(FoliageSenescence.MapNameTemplate, FoliageSenescence.units, PlugIn.ModelCore.CurrentTime, Senes);

                ISiteVar <float> Senescence_site = cohorts.GetIsiteVar(x => x.FoliageSenescenceSum);

                FoliageSenescence.output_table_ecoregions.WriteUpdate <float>(PlugIn.ModelCore.CurrentTime, Senescence_site);
            }
            if (AETAvg != null)
            {
                ISiteVar <float> AET_site = cohorts.GetIsiteVar(x => x.AETSum);

                AETAvg.output_table_ecoregions.WriteUpdate <float>(PlugIn.ModelCore.CurrentTime, AET_site);
            }
            if (MonthlyFolResp != null)
            {
                ISiteVar <int[]> monthlyFolResp = cohorts.GetIsiteVar(site => site.FolResp);

                WriteMonthlyOutput(monthlyFolResp, MonthlyFolResp.MapNameTemplate);
            }
            if (MonthlyGrossPsn != null)
            {
                ISiteVar <int[]> monthlyGrossPsn = cohorts.GetIsiteVar(site => site.GrossPsn);

                WriteMonthlyOutput(monthlyGrossPsn, MonthlyGrossPsn.MapNameTemplate);
            }
            if (MonthlyNetPsn != null)
            {
                ISiteVar <int[]> monthlyNetPsn = cohorts.GetIsiteVar(site => site.NetPsn);

                WriteMonthlyOutput(monthlyNetPsn, MonthlyNetPsn.MapNameTemplate);
            }
            if (MonthlyMaintResp != null)
            {
                ISiteVar <int[]> monthlyMaintResp = cohorts.GetIsiteVar(site => site.MaintResp);

                WriteMonthlyOutput(monthlyMaintResp, MonthlyMaintResp.MapNameTemplate);
            }
            if (BelowGround != null)
            {
                System.Console.WriteLine("Updating output variable: BelowGround");

                ISiteVar <uint> values = cohorts.GetIsiteVar(o => o.BelowGroundBiomass);

                string FileName = FileNames.ReplaceTemplateVars(BelowGround.MapNameTemplate, "", PlugIn.ModelCore.CurrentTime);

                new OutputMapSiteVar <uint, uint>(FileName, values, o => o);
            }
            if (CohortsPerSpc != null)
            {
                System.Console.WriteLine("Updating output variable: CohortsPerSpc");
                // Nr of Cohorts per site and per species

                ISiteVar <Landis.Library.Parameters.Species.AuxParm <int> > cps = cohorts.GetIsiteVar(x => x.CohortCountPerSpecies);

                new OutputHistogramCohort <int>(CohortsPerSpc.MapNameTemplate, "CohortsPerSpcPerSite", 10).WriteOutputHist(cps);

                foreach (ISpecies spc in PlugIn.SelectedSpecies)
                {
                    string FileName = FileNames.ReplaceTemplateVars(CohortsPerSpc.MapNameTemplate, spc.Name, PlugIn.ModelCore.CurrentTime);

                    new OutputMapSiteVar <Landis.Library.Parameters.Species.AuxParm <int>, int>(FileName, cps, o => o[spc]);
                }

                OutputFilePerTStepPerSpecies.Write <int>(CohortsPerSpc.MapNameTemplate, CohortsPerSpc.units, PlugIn.ModelCore.CurrentTime, cps);
            }
            if (EstablishmentProbability != null)
            {
                System.Console.WriteLine("Updating output variable: EstablishmentProbability");

                ISiteVar <Landis.Library.Parameters.Species.AuxParm <byte> > pest = (ISiteVar <Landis.Library.Parameters.Species.AuxParm <byte> >)cohorts.GetIsiteVar(o => o.EstablishmentProbability.Probability);

                foreach (ISpecies spc in PlugIn.SelectedSpecies)
                {
                    ISiteVar <int> _pest = modelCore.Landscape.NewSiteVar <int>();

                    foreach (ActiveSite site in PlugIn.modelCore.Landscape)
                    {
                        _pest[site] = pest[site][spc];
                    }

                    new OutputMapSpecies(_pest, spc, EstablishmentProbability.MapNameTemplate);
                }
            }
            if (SpeciesEstablishment != null)
            {
                System.Console.WriteLine("Updating output variable: SpeciesEstablishment");

                ISiteVar <Landis.Library.Parameters.Species.AuxParm <bool> > SpeciesIsThere = cohorts.GetIsiteVar(o => o.SpeciesPresent);

                if (SpeciesWasThere != null)
                {
                    foreach (ISpecies spc in PlugIn.modelCore.Species)
                    {
                        ISiteVar <int> comp = PlugIn.modelCore.Landscape.NewSiteVar <int>();

                        MapComparison m = new MapComparison();
                        foreach (ActiveSite site in PlugIn.modelCore.Landscape)
                        {
                            if (SpeciesWasThere[site] == null)
                            {
                                SpeciesWasThere[site] = new Library.Parameters.Species.AuxParm <bool>(PlugIn.modelCore.Species);
                            }

                            comp[site] = m[SpeciesWasThere[site][spc], SpeciesIsThere[site][spc]];

                            SpeciesWasThere[site][spc] = SpeciesIsThere[site][spc];
                        }


                        OutputMapSpecies output_map = new OutputMapSpecies(comp, spc, SpeciesEstablishment.MapNameTemplate);

                        // map label text
                        m.PrintLabels(SpeciesEstablishment.MapNameTemplate, spc);
                    }
                }
                else
                {
                    SpeciesWasThere = modelCore.Landscape.NewSiteVar <Landis.Library.Parameters.Species.AuxParm <bool> >();

                    foreach (ActiveSite site in PlugIn.modelCore.Landscape)
                    {
                        SpeciesWasThere[site] = new Library.Parameters.Species.AuxParm <bool>(PlugIn.modelCore.Species);
                    }
                }

                ISiteVar <Landis.Library.Parameters.Species.AuxParm <bool> > Established_spc = cohorts.GetIsiteVar(x => x.SpeciesPresent);

                Landis.Library.Parameters.Species.AuxParm <int> Est_Sum = new Landis.Library.Parameters.Species.AuxParm <int>(PlugIn.modelCore.Species);

                foreach (ActiveSite site in PlugIn.ModelCore.Landscape)
                {
                    foreach (ISpecies spc in PlugIn.modelCore.Species)
                    {
                        if (Established_spc[site][spc] == true)
                        {
                            Est_Sum[spc]++;
                        }
                    }
                }

                OutputFilePerTStepPerSpecies.Write <int>(SpeciesEstablishment.MapNameTemplate, SpeciesEstablishment.units, PlugIn.ModelCore.CurrentTime, Est_Sum);
            }
            if (AnnualPsn != null)
            {
                System.Console.WriteLine("Updating output variable: AnnualPsn");

                ISiteVar <Landis.Library.Parameters.Species.AuxParm <int> > Biom = cohorts.GetIsiteVar(o => o.BiomassPerSpecies);

                if (LastBiom != null)
                {
                    foreach (ISpecies spc in PlugIn.modelCore.Species)
                    {
                        ISiteVar <int> comp = PlugIn.modelCore.Landscape.NewSiteVar <int>();

                        MapComparison m = new MapComparison();
                        foreach (ActiveSite site in PlugIn.modelCore.Landscape)
                        {
                            if (LastBiom[site] == null)
                            {
                                LastBiom[site] = new Library.Parameters.Species.AuxParm <int>(PlugIn.modelCore.Species);
                            }

                            comp[site] = Biom[site][spc] - LastBiom[site][spc];

                            LastBiom[site][spc] = Biom[site][spc];
                        }

                        OutputMapSpecies output_map = new OutputMapSpecies(comp, spc, AnnualPsn.MapNameTemplate);
                    }
                }
                else
                {
                    LastBiom = modelCore.Landscape.NewSiteVar <Landis.Library.Parameters.Species.AuxParm <int> >();

                    foreach (ActiveSite site in PlugIn.modelCore.Landscape)
                    {
                        LastBiom[site] = new Library.Parameters.Species.AuxParm <int>(PlugIn.modelCore.Species);
                    }
                }
            }

            if (Water != null)
            {
                System.Console.WriteLine("Updating output variable: Water");

                ISiteVar <ushort> Water_site = cohorts.GetIsiteVar(x => x.WaterMax);

                string FileName = FileNames.ReplaceTemplateVars(Water.MapNameTemplate, "", PlugIn.ModelCore.CurrentTime);

                new OutputMapSiteVar <ushort, ushort>(FileName, Water_site, o => o);

                Water.output_table_ecoregions.WriteUpdate(PlugIn.ModelCore.CurrentTime, Water_site);
            }

            if (SubCanopyPAR != null)
            {
                System.Console.WriteLine("Updating output variable: SubCanopyPAR");

                ISiteVar <float> SubCanopyRadiation = cohorts.GetIsiteVar(x => x.SubCanopyParMAX);

                string FileName = FileNames.ReplaceTemplateVars(SubCanopyPAR.MapNameTemplate, "", PlugIn.ModelCore.CurrentTime);

                new OutputMapSiteVar <float, float>(FileName, SubCanopyRadiation, o => o);
            }
            if (NonWoodyDebris != null)
            {
                System.Console.WriteLine("Updating output variable: NonWoodyDebris");

                ISiteVar <double> Litter = cohorts.GetIsiteVar(x => x.Litter);

                string FileName = FileNames.ReplaceTemplateVars(NonWoodyDebris.MapNameTemplate, "", PlugIn.ModelCore.CurrentTime);

                new OutputMapSiteVar <double, double>(FileName, Litter, o => o);
            }

            if (WoodyDebris != null)
            {
                System.Console.WriteLine("Updating output variable: WoodyDebris");

                ISiteVar <double> woody_debris = cohorts.GetIsiteVar(x => x.WoodyDebris);

                string FileName = FileNames.ReplaceTemplateVars(WoodyDebris.MapNameTemplate, "", PlugIn.ModelCore.CurrentTime);

                new OutputMapSiteVar <double, double>(FileName, woody_debris, o => o);
            }

            if (AgeDistribution != null)
            {
                System.Console.WriteLine("Updating output variable: AgeDistribution");

                ISiteVar <Landis.Library.Parameters.Species.AuxParm <List <ushort> > > values = cohorts.GetIsiteVar(o => o.CohortAges);

                new OutputHistogramCohort <ushort>(AgeDistribution.MapNameTemplate, "NrOfCohortsAtAge", 10).WriteOutputHist(values);


                System.Console.WriteLine("Updating output variable: MaxAges");

                ISiteVar <int> maxage = cohorts.GetIsiteVar(x => x.AgeMax);

                string FileName = FileNames.ReplaceTemplateVars(AgeDistribution.MapNameTemplate, "", PlugIn.ModelCore.CurrentTime);

                new OutputMapSiteVar <int, int>(FileName, maxage, o => o);
            }
            if (overalloutputs != null)
            {
                System.Console.WriteLine("Updating output variable: overalloutputs");
                OutputAggregatedTable.WriteNrOfCohortsBalance();
            }
        }
Пример #3
0
        //---------------------------------------------------------------------

        public override void Initialize()
        {
            Timestep        = parameters.Timestep;
            selectedspecies = parameters.SelectedSpecies;

            tstep = parameters.Timestep;

            cohorts     = PlugIn.ModelCore.GetSiteVar <Landis.Extension.Succession.BiomassPnET.ISiteCohorts>("Succession.CohortsPnET");
            woodyDebris = PlugIn.ModelCore.GetSiteVar <Landis.Library.Biomass.Pool>("Succession.WoodyDebris");
            litter      = PlugIn.ModelCore.GetSiteVar <Landis.Library.Biomass.Pool>("Succession.Litter");

            if (parameters.CohortsPerSpecies != null)
            {
                CohortsPerSpc = new OutputVariable(parameters.CohortsPerSpecies, "#");
            }
            if (parameters.SpeciesBiom != null)
            {
                Biomass = new OutputVariable(parameters.SpeciesBiom, "g/m2");
                Biomass.output_table_ecoregions = new OutputTableEcoregions(Biomass.MapNameTemplate);
            }
            if (parameters.SpeciesAbovegroundBiom != null)
            {
                AbovegroundBiomass = new OutputVariable(parameters.SpeciesAbovegroundBiom, "g/m2");
                AbovegroundBiomass.output_table_ecoregions = new OutputTableEcoregions(AbovegroundBiomass.MapNameTemplate);
            }
            if (parameters.SpeciesWoodySenescence != null)
            {
                WoodySenescence = new OutputVariable(parameters.SpeciesWoodySenescence, "g/m2");
                WoodySenescence.output_table_ecoregions = new OutputTableEcoregions(WoodySenescence.MapNameTemplate);
            }
            if (parameters.SpeciesFoliageSenescence != null)
            {
                FoliageSenescence = new OutputVariable(parameters.SpeciesFoliageSenescence, "g/m2");
                FoliageSenescence.output_table_ecoregions = new OutputTableEcoregions(FoliageSenescence.MapNameTemplate);
            }
            if (parameters.AETAvg != null)
            {
                AETAvg = new OutputVariable(parameters.AETAvg, "");
                AETAvg.output_table_ecoregions = new OutputTableEcoregions(AETAvg.MapNameTemplate);
            }
            if (parameters.BelowgroundBiomass != null)
            {
                BelowGround = new OutputVariable(parameters.BelowgroundBiomass, "g/m2");
            }
            if (parameters.LeafAreaIndex != null)
            {
                LAI = new OutputVariable(parameters.LeafAreaIndex, "m2");
                LAI.output_table_ecoregions = new OutputTableEcoregions(LAI.MapNameTemplate);
            }
            if (parameters.MonthlyFolResp != null)
            {
                MonthlyFolResp = new OutputVariable(parameters.MonthlyFolResp, "gC/mo");
            }
            if (parameters.MonthlyGrossPsn != null)
            {
                MonthlyGrossPsn = new OutputVariable(parameters.MonthlyGrossPsn, "gC/mo");
            }
            if (parameters.MonthlyMaintResp != null)
            {
                MonthlyMaintResp = new OutputVariable(parameters.MonthlyMaintResp, "gC/mo");
            }
            if (parameters.MonthlyNetPsn != null)
            {
                MonthlyNetPsn = new OutputVariable(parameters.MonthlyNetPsn, "gC/mo");
            }

            if (parameters.EstablishmentProbability != null)
            {
                EstablishmentProbability = new OutputVariable(parameters.EstablishmentProbability, "");
            }
            if (parameters.SpeciesEst != null)
            {
                SpeciesEstablishment = new OutputVariable(parameters.SpeciesEst, "");
            }
            if (parameters.Water != null)
            {
                Water = new OutputVariable(parameters.Water, "mm");
                Water.output_table_ecoregions = new OutputTableEcoregions(Water.MapNameTemplate);
            }
            if (parameters.SubCanopyPAR != null)
            {
                SubCanopyPAR = new OutputVariable(parameters.SubCanopyPAR, "W/m2 or mmol/m2");
            }
            if (parameters.Litter != null)
            {
                NonWoodyDebris = new OutputVariable(parameters.Litter, "g/m2");
            }
            if (parameters.WoodyDebris != null)
            {
                WoodyDebris = new OutputVariable(parameters.WoodyDebris, "g/m2");
            }
            if (parameters.AgeDistribution != null)
            {
                AgeDistribution = new OutputVariable(parameters.AgeDistribution, "yr");
            }
            if (parameters.AnnualPsn != null)
            {
                AnnualPsn = new OutputVariable(parameters.AnnualPsn, "g/m2");
            }
            if (parameters.CohortBalance != null)
            {
                overalloutputs = new OutputAggregatedTable(parameters.CohortBalance);
            }


            MetadataHandler.InitializeMetadata(Timestep, LAI, Biomass, AbovegroundBiomass, EstablishmentProbability,
                                               SpeciesWasThere, AnnualPsn, BelowGround, CohortsPerSpc, Water, SubCanopyPAR, NonWoodyDebris,
                                               WoodyDebris, AgeDistribution, MonthlyFolResp, MonthlyGrossPsn, MonthlyNetPsn, MonthlyMaintResp,
                                               SpeciesEstablishment, LastBiom, overalloutputs, parameters.CohortBalance);
        }
        //---------------------------------------------------------------------
        public override void Initialize()
        {
            Timestep = parameters.Timestep;
            selectedspecies = parameters.SelectedSpecies;

            tstep = parameters.Timestep;

            cohorts = PlugIn.ModelCore.GetSiteVar<Landis.Extension.Succession.BiomassPnET.ISiteCohorts>("Succession.CohortsPnET");
            woodyDebris = PlugIn.ModelCore.GetSiteVar<Landis.Library.Biomass.Pool>("Succession.WoodyDebris");
            litter = PlugIn.ModelCore.GetSiteVar<Landis.Library.Biomass.Pool>("Succession.Litter");

            if (parameters.CohortsPerSpecies != null) CohortsPerSpc = new OutputVariable(parameters.CohortsPerSpecies, "#");
            if (parameters.SpeciesBiom != null)
            {
                Biomass = new OutputVariable(parameters.SpeciesBiom, "g/m2");
                Biomass.output_table_ecoregions = new OutputTableEcoregions(Biomass.MapNameTemplate);
            }
            if (parameters.SpeciesAbovegroundBiom != null)
            {
                AbovegroundBiomass = new OutputVariable(parameters.SpeciesAbovegroundBiom, "g/m2");
                AbovegroundBiomass.output_table_ecoregions = new OutputTableEcoregions(AbovegroundBiomass.MapNameTemplate);
            }
            if (parameters.SpeciesWoodySenescence != null)
            {
                WoodySenescence = new OutputVariable(parameters.SpeciesWoodySenescence, "g/m2");
                WoodySenescence.output_table_ecoregions = new OutputTableEcoregions(WoodySenescence.MapNameTemplate);
            }
            if (parameters.SpeciesFoliageSenescence != null)
            {
                FoliageSenescence = new OutputVariable(parameters.SpeciesFoliageSenescence, "g/m2");
                FoliageSenescence.output_table_ecoregions = new OutputTableEcoregions(FoliageSenescence.MapNameTemplate);
            }
            if (parameters.BelowgroundBiomass != null) BelowGround = new OutputVariable(parameters.BelowgroundBiomass, "g/m2");
            if (parameters.LeafAreaIndex != null)
            {
                LAI = new OutputVariable(parameters.LeafAreaIndex, "m2");
                LAI.output_table_ecoregions = new OutputTableEcoregions(LAI.MapNameTemplate);
            }
            if (parameters.MonthlyFolResp != null)
            {
                MonthlyFolResp = new OutputVariable(parameters.MonthlyFolResp, "gC/mo");
            }
            if (parameters.MonthlyGrossPsn != null)
            {
                MonthlyGrossPsn = new OutputVariable(parameters.MonthlyGrossPsn, "gC/mo");
            }
            if (parameters.MonthlyMaintResp != null)
            {
                MonthlyMaintResp = new OutputVariable(parameters.MonthlyMaintResp, "gC/mo");
            }
            if (parameters.MonthlyNetPsn != null)
            {
                MonthlyNetPsn = new OutputVariable(parameters.MonthlyNetPsn, "gC/mo");
            }

            if (parameters.EstablishmentProbability != null)
            {
                EstablishmentProbability = new OutputVariable(parameters.EstablishmentProbability, "");

            }
            if (parameters.SpeciesEst != null)
            {
                SpeciesEstablishment = new OutputVariable(parameters.SpeciesEst, "");

            }
            if (parameters.Water != null)
            {
                Water = new OutputVariable(parameters.Water, "mm");
                Water.output_table_ecoregions = new OutputTableEcoregions(Water.MapNameTemplate);
            }
            if (parameters.SubCanopyPAR != null) SubCanopyPAR = new OutputVariable(parameters.SubCanopyPAR,  "W/m2 pr mmol/m2");
            if (parameters.Litter != null) NonWoodyDebris = new OutputVariable(parameters.Litter, "g/m2");
            if (parameters.WoodyDebris != null) WoodyDebris = new OutputVariable(parameters.WoodyDebris,  "g/m2");
            if (parameters.AgeDistribution != null) AgeDistribution = new OutputVariable(parameters.AgeDistribution,"yr");
            if (parameters.AnnualPsn != null) AnnualPsn = new OutputVariable(parameters.AnnualPsn, "g/m2");
            if (parameters.CohortBalance != null) overalloutputs = new OutputAggregatedTable(parameters.CohortBalance);
        }