public OutputMapSiteVar(string FileName, ISiteVar <T> values, Func <T, M> func) { try { using (IOutputRaster <IntPixel> outputRaster = PlugIn.ModelCore.CreateRaster <IntPixel>(FileName, PlugIn.ModelCore.Landscape.Dimensions)) { foreach (Site site in PlugIn.ModelCore.Landscape.AllSites) { if (site.IsActive) { try { outputRaster.BufferPixel.MapCode.Value = (int)double.Parse(func(values[site]).ToString());// int.Parse(values[site].ToString()); } catch (System.Exception e) { System.Console.WriteLine("Cannot write " + FileName + " for site " + site.Location.ToString() + " " + e.Message); } } else { outputRaster.BufferPixel.MapCode.Value = 0; } outputRaster.WriteBufferPixel(); } } } catch (System.Exception e) { System.Console.WriteLine("Cannot write " + FileName + " " + e.Message); } }
public void WriteOutputHist(ISiteVar <Landis.Library.Parameters.Species.AuxParm <List <T> > > values) { T[] extremes = Extremes(values); List <double>[] categorybounds = GetCategorieBounds(extremes); FileContent.Add(hdr(label, categorybounds[0], categorybounds[1])); if (cat_count_tot.Count() == 0) { return; } foreach (ISpecies species in PlugIn.ModelCore.Species) { string line = species.Name; foreach (ActiveSite site in PlugIn.ModelCore.Landscape) { if (values[site][species] == null) { continue; } for (int c = 0; c < categorybounds[1].Count; c++) { foreach (T var in values[site][species]) { T min = (T)System.Convert.ChangeType(categorybounds[0][c], typeof(T)); T max = (T)System.Convert.ChangeType(categorybounds[1][c], typeof(T)); if (var.CompareTo(min) >= 0 && var.CompareTo(max) < 0 || var.CompareTo(extremes[1]) == 0) { cat_count[c]++; cat_count_tot[c]++; } } } } for (int c = 0; c < cat_count.Count(); c++) { line += ", " + cat_count[c].ToString(); cat_count[c] = 0; } FileContent.Add(line); } string linetot = "Total"; for (int c = 0; c < cat_count.Count(); c++) { linetot += ", " + cat_count_tot[c].ToString(); cat_count[c] = 0; } FileContent.Add(linetot); System.IO.File.WriteAllLines(FileName, FileContent.ToArray()); }
public static ISiteVar <T> GetIsiteVar <T, M>(this ISiteVar <M> sitevar, Func <M, T> func) { ISiteVar <T> d = PlugIn.ModelCore.Landscape.NewSiteVar <T>(); foreach (ActiveSite site in PlugIn.ModelCore.Landscape) { d[site] = (T)Convert.ChangeType(func(sitevar[site]), typeof(T)); } return(d); }
private static T[] Extremes(ISiteVar <Landis.Library.Parameters.Species.AuxParm <List <T> > > values) { T[] extremes = new T[2]; if (typeof(T) == typeof(double)) { extremes[0] = (T)System.Convert.ChangeType(double.MaxValue, typeof(T)); extremes[1] = (T)System.Convert.ChangeType(double.MinValue, typeof(T)); } else if (typeof(T) == typeof(float)) { extremes[0] = (T)System.Convert.ChangeType(float.MaxValue, typeof(T)); extremes[1] = (T)System.Convert.ChangeType(float.MinValue, typeof(T)); } else if (typeof(T) == typeof(int)) { extremes[0] = (T)System.Convert.ChangeType(int.MaxValue, typeof(T)); extremes[1] = (T)System.Convert.ChangeType(int.MinValue, typeof(T)); } else if (typeof(T) == typeof(ushort)) { extremes[0] = (T)System.Convert.ChangeType(ushort.MaxValue, typeof(T)); extremes[1] = (T)System.Convert.ChangeType(ushort.MinValue, typeof(T)); } else if (typeof(T) == typeof(byte)) { extremes[0] = (T)System.Convert.ChangeType(byte.MaxValue, typeof(T)); extremes[1] = (T)System.Convert.ChangeType(byte.MinValue, typeof(T)); } else { throw new System.Exception("Cannot calculate Extremes for type " + typeof(T).ToString()); } foreach (ActiveSite site in PlugIn.ModelCore.Landscape) { foreach (ISpecies spc in PlugIn.ModelCore.Species) { if (values[site][spc] == null) { continue; } foreach (T var in values[site][spc]) { if (var.CompareTo(extremes[1]) > 0) { extremes[1] = var; } if (var.CompareTo(extremes[0]) < 0) { extremes[0] = var; } } } } return(extremes); }
private static void WriteMonthlyOutput(ISiteVar <int[]> montly, string MapNameTemplate) { string[] months = new string[] { "jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "okt", "nov", "dec" }; for (int mo = 0; mo < months.Count(); mo++) { ISiteVar <int> monthlyValue = PlugIn.ModelCore.Landscape.NewSiteVar <int>(); foreach (ActiveSite site in PlugIn.modelCore.Landscape) { monthlyValue[site] = montly[site][mo]; } string FileName = FileNames.ReplaceTemplateVars(MapNameTemplate, "", PlugIn.ModelCore.CurrentTime); FileName = System.IO.Path.ChangeExtension(FileName, null) + months[mo] + System.IO.Path.GetExtension(FileName); new OutputMapSiteVar <int, int>(FileName, monthlyValue, o => o); } }
public void WriteUpdate <T>(int year, ISiteVar <T> values) { string line = year + "\t"; Landis.Library.Parameters.Ecoregions.AuxParm <double> sum_values_per_ecoregion = new Library.Parameters.Ecoregions.AuxParm <double>(PlugIn.ModelCore.Ecoregions); Landis.Library.Parameters.Ecoregions.AuxParm <int> cnt_values_per_ecoregion = new Library.Parameters.Ecoregions.AuxParm <int>(PlugIn.ModelCore.Ecoregions); Landis.Library.Parameters.Ecoregions.AuxParm <double> avg_values_per_ecoregion = new Library.Parameters.Ecoregions.AuxParm <double>(PlugIn.ModelCore.Ecoregions); foreach (ActiveSite site in PlugIn.ModelCore.Landscape) { sum_values_per_ecoregion[PlugIn.ModelCore.Ecoregion[site]] += double.Parse(values[site].ToString()); cnt_values_per_ecoregion[PlugIn.ModelCore.Ecoregion[site]]++; avg_values_per_ecoregion[PlugIn.ModelCore.Ecoregion[site]] = sum_values_per_ecoregion[PlugIn.ModelCore.Ecoregion[site]] / ((double)cnt_values_per_ecoregion[PlugIn.ModelCore.Ecoregion[site]]); } foreach (IEcoregion e in PlugIn.ModelCore.Ecoregions) { line += avg_values_per_ecoregion[e] + "\t"; } FileContent.Add(line); System.IO.File.WriteAllLines(FileName, FileContent.ToArray()); }
public OutputMapSpecies(ISiteVar <int> values, ISpecies species, string MapNameTemplate) { FileName = FileNames.ReplaceTemplateVars(MapNameTemplate, species.Name, PlugIn.ModelCore.CurrentTime); Console.WriteLine(" Writing {0} map to {1} ...", species.Name, FileName); using (IOutputRaster <IntPixel> outputRaster = PlugIn.ModelCore.CreateRaster <IntPixel>(FileName, PlugIn.ModelCore.Landscape.Dimensions)) { IntPixel pixel = outputRaster.BufferPixel; foreach (Site site in PlugIn.ModelCore.Landscape.AllSites) { if (site.IsActive) { pixel.MapCode.Value = (int)values[site]; } else { pixel.MapCode.Value = 0; } outputRaster.WriteBufferPixel(); } } }
public static void Write <T>(string MapNameTemplate, string units, int TStep, ISiteVar <Landis.Library.Parameters.Species.AuxParm <T> > Values) { string FileName = FileNames.ReplaceTemplateVars(MapNameTemplate).Replace(".img", ".txt"); if (PlugIn.ModelCore.CurrentTime == 0) { FileNames.MakeFolders(FileName); System.IO.File.WriteAllLines(FileName, new string[] { Header(units) }); } AuxParm <ulong> Values_spc = new AuxParm <ulong>(PlugIn.ModelCore.Species); AuxParm <ulong> Values_cnt = new AuxParm <ulong>(PlugIn.ModelCore.Species); foreach (ActiveSite site in PlugIn.ModelCore.Landscape) { foreach (ISpecies spc in PlugIn.ModelCore.Species) { if (typeof(T) == typeof(bool)) { if (Values[site][spc].ToString() == bool.TrueString) { Values_spc[spc]++; } } else { ulong numeric = ulong.Parse(Values[site][spc].ToString()); Values_spc[spc] += numeric; } Values_cnt[spc]++; } } string line = TStep + "\t"; foreach (ISpecies spc in PlugIn.ModelCore.Species) { line += Values_spc[spc] / (float)Values_cnt[spc] + "\t"; } System.IO.StreamWriter sw = new System.IO.StreamWriter(FileName, true); sw.WriteLine(line); sw.Close(); }
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); }
public static void WriteNrOfCohortsBalance() { try { ISiteVar <int> CohortsPerSite = PlugIn.cohorts.GetIsiteVar(x => x.CohortCount); ISiteVar <float> CohortBiom = PlugIn.cohorts.GetIsiteVar(x => x.BiomassSum); ISiteVar <float> CohortWoodySenescence = PlugIn.cohorts.GetIsiteVar(x => x.WoodySenescenceSum); ISiteVar <float> FoliageWoodySenescence = PlugIn.cohorts.GetIsiteVar(x => x.FoliageSenescenceSum); ISiteVar <int> CohortAge = PlugIn.cohorts.GetIsiteVar(x => (x.CohortCount > 0) ? x.AverageAge : -1); ISiteVar <byte> CohortLAI = PlugIn.cohorts.GetIsiteVar(x => x.CanopyLAImax); ISiteVar <float> WaterPerSite = PlugIn.cohorts.GetIsiteVar(x => x.WaterMax); ISiteVar <float> SubCanopyRAD = PlugIn.cohorts.GetIsiteVar(x => x.SubCanopyParMAX); ISiteVar <double> Litter = PlugIn.cohorts.GetIsiteVar(x => x.Litter); ISiteVar <double> WoodyDebris = PlugIn.cohorts.GetIsiteVar(x => x.WoodyDebris); ISiteVar <uint> BelowGroundBiom = PlugIn.cohorts.GetIsiteVar(x => x.BelowGroundBiomass); ISiteVar <float> FoliageBiom = PlugIn.cohorts.GetIsiteVar(x => x.FoliageSum); ISiteVar <float> NSCBiom = PlugIn.cohorts.GetIsiteVar(x => x.NSCSum); ISiteVar <float> AET = PlugIn.cohorts.GetIsiteVar(x => x.AETSum); double Water_SUM = 0; double CohortBiom_SUM = 0; double BelowGroundBiom_SUM = 0; double FoliageBiom_SUM = 0; double NSCBiom_SUM = 0; double CohortAge_SUM = 0; double CohortLAI_SUM = 0; int CohortCount = 0; int siteCount = 0; double SubCanopyRad_SUM = 0; double Litter_SUM = 0; double Woody_debris_SUM = 0; double AET_SUM = 0; foreach (ActiveSite site in PlugIn.ModelCore.Landscape) { siteCount++; CohortCount += CohortsPerSite[site]; CohortBiom_SUM += CohortBiom[site]; BelowGroundBiom_SUM += BelowGroundBiom[site]; FoliageBiom_SUM += FoliageBiom[site]; NSCBiom_SUM += NSCBiom[site]; Water_SUM += WaterPerSite[site]; SubCanopyRad_SUM += SubCanopyRAD[site]; Litter_SUM += Litter[site]; Woody_debris_SUM += WoodyDebris[site]; AET_SUM += AET[site]; if (CohortsPerSite[site] > 0) { CohortAge_SUM += CohortAge[site]; CohortLAI_SUM += CohortLAI[site]; } } string c = CohortCount.ToString(); string CohortAge_av = (CohortAge_SUM / (float)siteCount).ToString(); string CohortBiom_av = (CohortBiom_SUM / (float)siteCount).ToString(); string BelowGroundBiom_av = (BelowGroundBiom_SUM / (float)siteCount).ToString(); string FoliageBiom_av = (FoliageBiom_SUM / (float)siteCount).ToString(); string NSCBiom_av = (NSCBiom_SUM / (float)siteCount).ToString(); string LAI_av = (CohortLAI_SUM / (float)siteCount).ToString(); string Water_av = (Water_SUM / (float)siteCount).ToString(); string SubCanopyRad_av = (SubCanopyRad_SUM / (float)siteCount).ToString(); string Litter_av = (Litter_SUM / (float)siteCount).ToString(); string Woody_debris_ave = (Woody_debris_SUM / (float)siteCount).ToString(); string AET_ave = (AET_SUM / (float)siteCount).ToString(); FileContent.Add(PlugIn.ModelCore.CurrentTime.ToString() + ", " + c + ", " + CohortAge_av + ", " + CohortBiom_av + ", " + LAI_av + ", " + Water_av + ", " + SubCanopyRad_av + ", " + Litter_av + ", " + Woody_debris_ave + ", " + BelowGroundBiom_av + ", " + FoliageBiom_av + ", " + NSCBiom_av + ", " + AET_ave); System.IO.File.WriteAllLines(FileName, FileContent.ToArray()); } catch (System.Exception e) { System.Console.WriteLine("Cannot write to " + FileName + " " + e.Message); } }
//--------------------------------------------------------------------- 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 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(); } }