protected override void InitializeMode() { var maDataSet = new ManagementAreaDataset(); foreach (var agentToManagementArea in sheParameters.AgentToManagementAreaList) { foreach (var managementAreaName in agentToManagementArea.ManagementAreas) { var managementArea = new ManagementArea(ushort.Parse(managementAreaName)); maDataSet.Add(managementArea); } } Landis.Library.HarvestManagement.SiteVars.GetExternalVars(); foreach (ManagementArea mgmtArea in maDataSet) { mgmtArea.FinishInitialization(); } foreach (var agentToManagementArea in sheParameters.AgentToManagementAreaList) { foreach (var managementAreaName in agentToManagementArea.ManagementAreas) { Area area; if (!Areas.TryGetValue(managementAreaName, out area)) { area = new Area(); area.Initialize(maDataSet.First(ma => ma.MapCode.ToString() == managementAreaName)); Areas.Add(managementAreaName, area); } area.AssignedAgents.Add(agentToManagementArea.Agent); } } }
private void ApplyPrescription(ManagementArea managementArea, ExtendedPrescription extendedPrescription) { managementArea.ApplyPrescription(extendedPrescription.Prescription, new Percentage(extendedPrescription.HarvestAreaPercent), new Percentage(extendedPrescription.HarvestStandsAreaPercent), extendedPrescription.StartTime, extendedPrescription.EndTime); managementArea.FinishInitialization(); }
public static void WriteSummaryLogEntry(ManagementArea mgmtArea, AppliedPrescription prescription, uint repeatNumber = 0, bool lastHarvest = false) { double[] species_cohorts = new double[modelCore.Species.Count]; double[] species_biomass = new double[modelCore.Species.Count]; foreach (ISpecies species in modelCore.Species) { species_cohorts[species.Index] = totalSpeciesCohorts[prescription.Prescription.Number, species.Index]; species_biomass[species.Index] = totalSpeciesBiomass[prescription.Prescription.Number, species.Index]; } if (totalSites[prescription.Prescription.Number] > 0 && prescriptionReported[prescription.Prescription.Number] != true) { string name = prescription.Prescription.Name; if (repeatNumber > 0) { name = name + "(" + repeatNumber + ")"; } summaryLog.Clear(); SummaryLog sl = new SummaryLog(); sl.Time = modelCore.CurrentTime; sl.ManagementArea = mgmtArea.MapCode; sl.Prescription = name; sl.HarvestedSites = totalDamagedSites[prescription.Prescription.Number]; sl.TotalBiomassHarvested = totalBiomassRemoved[prescription.Prescription.Number]; sl.TotalCohortsPartialHarvest = totalCohortsDamaged[prescription.Prescription.Number]; sl.TotalCohortsCompleteHarvest = totalCohortsKilled[prescription.Prescription.Number]; sl.CohortsHarvested_ = species_cohorts; sl.BiomassHarvestedMg_ = species_biomass; summaryLog.AddObject(sl); summaryLog.WriteToFile(); // Do not mark this as recorded until the final summary is logged. Because repeat steps will be // recorded first and then new initiations, mark this as reported once the initiation step is complete if (repeatNumber == 0 || (ModelCore.CurrentTime > prescription.EndTime && lastHarvest)) { prescriptionReported[prescription.Prescription.Number] = true; } // Clear the log for the initial harvests if (lastHarvest) { totalDamagedSites[prescription.Prescription.Number] = 0; totalBiomassRemoved[prescription.Prescription.Number] = 0; totalCohortsDamaged[prescription.Prescription.Number] = 0; totalCohortsKilled[prescription.Prescription.Number] = 0; foreach (ISpecies species in modelCore.Species) { totalSpeciesCohorts[prescription.Prescription.Number, species.Index] = 0; totalSpeciesBiomass[prescription.Prescription.Number, species.Index] = 0; } } } }
public ExtendedPrescription( HarvestManagement.Prescription prescription, ManagementArea managementArea, Percentage harvestAreaPercent, Percentage harvestStandsAreaPercent, int startTime, int endTime ) { Prescription = prescription; ManagementArea = managementArea; HarvestAreaPercent = harvestAreaPercent; HarvestStandsAreaPercent = harvestStandsAreaPercent; StartTime = startTime; EndTime = endTime; }
public void Initialize(ManagementArea managementArea) { Name = managementArea.MapCode.ToString(); ManagementArea = managementArea; foreach (var stand in ManagementArea) { foreach (var activeSite in stand) { _sites.Add(activeSite); } } }
public static ExtendedPrescription ToExtendedPrescription( this AppliedPrescription appliedPrescription, ManagementArea managementArea) { var prescription = appliedPrescription.Prescription; var areaToHarvest = appliedPrescription.PercentageToHarvest; var standsToHarvest = appliedPrescription.PercentStandsToHarvest; var beginTime = appliedPrescription.BeginTime; var endTime = appliedPrescription.EndTime; return(new ExtendedPrescription(prescription, managementArea, areaToHarvest, standsToHarvest, beginTime, endTime)); }
protected override void InitializeMode() { _prescriptions = sheParameters.Prescriptions; _harvestPrescriptionName = PlugIn.ModelCore.GetSiteVar <string>("Harvest.PrescriptionName"); _siteCohorts = PlugIn.ModelCore.GetSiteVar <ISiteCohorts>("Succession.BiomassCohorts"); var maDataSet = new ManagementAreaDataset(); foreach (var agentToManagementArea in sheParameters.AgentToManagementAreaList) { foreach (var managementAreaName in agentToManagementArea.ManagementAreas) { var managementArea = new ManagementArea(ushort.Parse(managementAreaName)); maDataSet.Add(managementArea); } } ManagementAreas.ReadMap(sheParameters.ManagementAreaFileName, maDataSet); Stands.ReadMap(sheParameters.StandsFileName); Landis.Library.HarvestManagement.SiteVars.GetExternalVars(); foreach (ManagementArea mgmtArea in maDataSet) { mgmtArea.FinishInitialization(); } foreach (var agentToManagementArea in sheParameters.AgentToManagementAreaList) { foreach (var managementAreaName in agentToManagementArea.ManagementAreas) { Area area; if (!Areas.TryGetValue(managementAreaName, out area)) { area = new Area(); area.Initialize(maDataSet.First(ma => ma.MapCode.ToString() == managementAreaName)); Areas.Add(managementAreaName, area); } area.AssignedAgents.Add(agentToManagementArea.Agent); } } }
//--------------------------------------------------------------------- public void WriteLogEntry(ManagementArea mgmtArea, Stand stand) { int damagedSites = 0; int cohortsDamaged = 0; int cohortsKilled = 0; int standPrescriptionNumber = 0; double biomassRemoved = 0.0; double biomassRemovedPerHa = 0.0; IDictionary <ISpecies, double> totalBiomassBySpecies = new Dictionary <ISpecies, double>(); //ModelCore.UI.WriteLine("BiomassHarvest: PlugIn.cs: WriteLogEntry: mgmtArea {0}, Stand {1} ", mgmtArea.Prescriptions.Count, stand.MapCode); foreach (ActiveSite site in stand) { //set the prescription name for this site if (HarvestMgmtLib.SiteVars.Prescription[site] != null) { standPrescriptionNumber = HarvestMgmtLib.SiteVars.Prescription[site].Number; HarvestMgmtLib.SiteVars.PrescriptionName[site] = HarvestMgmtLib.SiteVars.Prescription[site].Name; HarvestMgmtLib.SiteVars.TimeOfLastEvent[site] = modelCore.CurrentTime; } cohortsDamaged += Landis.Library.BiomassHarvest.SiteVars.CohortsPartiallyDamaged[site]; cohortsKilled += (HarvestMgmtLib.SiteVars.CohortsDamaged[site] - Landis.Library.BiomassHarvest.SiteVars.CohortsPartiallyDamaged[site]); if (Landis.Library.BiomassHarvest.SiteVars.CohortsPartiallyDamaged[site] > 0 || HarvestMgmtLib.SiteVars.CohortsDamaged[site] > 0) { damagedSites++; //Conversion from [g m-2] to [Mg ha-1] to [Mg] biomassRemoved += SiteVars.BiomassRemoved[site] / 100.0 * modelCore.CellArea; IDictionary <ISpecies, int> siteBiomassBySpecies = SiteVars.BiomassBySpecies[site]; if (siteBiomassBySpecies != null) { // Sum up total biomass for each species foreach (ISpecies species in modelCore.Species) { int addValue = 0; siteBiomassBySpecies.TryGetValue(species, out addValue); double oldValue; if (totalBiomassBySpecies.TryGetValue(species, out oldValue)) { totalBiomassBySpecies[species] += addValue / 100.0 * modelCore.CellArea; } else { totalBiomassBySpecies.Add(species, addValue / 100.0 * modelCore.CellArea); } } } } } totalSites[standPrescriptionNumber] += stand.SiteCount; totalDamagedSites[standPrescriptionNumber] += damagedSites; totalCohortsDamaged[standPrescriptionNumber] += cohortsDamaged; totalCohortsKilled[standPrescriptionNumber] += cohortsKilled; totalBiomassRemoved[standPrescriptionNumber] += biomassRemoved; double[] species_cohorts = new double[modelCore.Species.Count]; double[] species_biomass = new double[modelCore.Species.Count]; double biomass_value; foreach (ISpecies species in modelCore.Species) { int cohortCount = stand.DamageTable[species]; species_cohorts[species.Index] = cohortCount; totalSpeciesCohorts[standPrescriptionNumber, species.Index] += cohortCount; totalBiomassBySpecies.TryGetValue(species, out biomass_value); species_biomass[species.Index] = biomass_value; totalSpeciesBiomass[standPrescriptionNumber, species.Index] += biomass_value; } //now that the damage table for this stand has been recorded, clear it!! stand.ClearDamageTable(); //write to log file: if (biomassRemoved > 0.0) { biomassRemovedPerHa = biomassRemoved / (double)damagedSites / modelCore.CellArea; } eventLog.Clear(); EventsLog el = new EventsLog(); el.Time = modelCore.CurrentTime; el.ManagementArea = mgmtArea.MapCode; el.Prescription = stand.PrescriptionName; el.Stand = stand.MapCode; el.EventID = stand.EventId; el.StandAge = stand.Age; el.StandRank = Convert.ToInt32(stand.HarvestedRank); el.NumberOfSites = stand.SiteCount; el.HarvestedSites = damagedSites; el.MgBiomassRemoved = biomassRemoved; el.MgBioRemovedPerDamagedHa = biomassRemovedPerHa; el.TotalCohortsPartialHarvest = cohortsDamaged; el.TotalCohortsCompleteHarvest = cohortsKilled; el.CohortsHarvested_ = species_cohorts; el.BiomassHarvestedMg_ = species_biomass; eventLog.AddObject(el); eventLog.WriteToFile(); }
//--------------------------------------------------------------------- public void WriteLogEntry(ManagementArea mgmtArea, Stand stand) { int damagedSites = 0; int cohortsDamaged = 0; int standPrescriptionNumber = 0; foreach (ActiveSite site in stand) { //set the prescription name for this site if (SiteVars.Prescription[site] != null) { standPrescriptionNumber = SiteVars.Prescription[site].Number; SiteVars.PrescriptionName[site] = SiteVars.Prescription[site].Name; SiteVars.TimeOfLastEvent[site] = PlugIn.ModelCore.CurrentTime; } int cohortsDamagedAtSite = SiteVars.CohortsDamaged[site]; cohortsDamaged += cohortsDamagedAtSite; if (cohortsDamagedAtSite > 0) { damagedSites++; } } totalSites[standPrescriptionNumber] += stand.SiteCount; totalDamagedSites[standPrescriptionNumber] += damagedSites; //csv string for log file, contains species kill count string species_count = ""; foreach (ISpecies species in PlugIn.ModelCore.Species) { int cohortCount = stand.DamageTable[species]; species_count += string.Format("{0},", cohortCount); totalSpeciesCohorts[standPrescriptionNumber, species.Index] += cohortCount; } //now that the damage table for this stand has been recorded, clear it!! stand.ClearDamageTable(); //write to log file: //current time //management area's map code //the prescription that caused this harvest //stand's map code //stand's age //stand's current rank //total sites in the stand //damaged sites from this stand //cohorts killed in this stand, by this harvest //and only record stands where a site has been damaged log.WriteLine("{0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10}", PlugIn.ModelCore.CurrentTime, mgmtArea.MapCode, stand.PrescriptionName, stand.MapCode, stand.EventId, stand.Age, stand.HarvestedRank, stand.SiteCount, damagedSites, cohortsDamaged, species_count); }
//--------------------------------------------------------------------- public void WriteLogEntry(ManagementArea mgmtArea, Stand stand) { int damagedSites = 0; int cohortsDamaged = 0; int standPrescriptionNumber = 0; foreach (ActiveSite site in stand) { //set the prescription name for this site if (SiteVars.Prescription[site] != null) { standPrescriptionNumber = SiteVars.Prescription[site].Number; SiteVars.PrescriptionName[site] = SiteVars.Prescription[site].Name; SiteVars.TimeOfLastEvent[site] = PlugIn.ModelCore.CurrentTime; } int cohortsDamagedAtSite = SiteVars.CohortsDamaged[site]; cohortsDamaged += cohortsDamagedAtSite; if (cohortsDamagedAtSite > 0) { damagedSites++; } } totalSites[standPrescriptionNumber] += stand.SiteCount; totalDamagedSites[standPrescriptionNumber] += damagedSites; //csv string for log file, contains species kill count //string species_count = ""; double[] species_count = new double[modelCore.Species.Count]; foreach (ISpecies species in PlugIn.ModelCore.Species) { int cohortCount = stand.DamageTable[species]; species_count[species.Index] += cohortCount; totalSpeciesCohorts[standPrescriptionNumber, species.Index] += cohortCount; } //Trim trailing comma so we don't add an extra column //species_count = species_count.TrimEnd(','); //now that the damage table for this stand has been recorded, clear it!! stand.ClearDamageTable(); //write to log file: //current time //management area's map code //the prescription that caused this harvest //stand's map code //stand's age //stand's current rank //total sites in the stand //damaged sites from this stand //cohorts killed in this stand, by this harvest //and only record stands where a site has been damaged //log.WriteLine("{0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10}", // PlugIn.ModelCore.CurrentTime, mgmtArea.MapCode, stand.PrescriptionName, stand.MapCode, stand.EventId, // stand.Age, stand.HarvestedRank, stand.SiteCount, damagedSites, cohortsDamaged, species_count); eventLog.Clear(); EventsLog el = new EventsLog(); el.Time = modelCore.CurrentTime; el.ManagementArea = mgmtArea.MapCode; el.Prescription = stand.PrescriptionName; el.Stand = stand.MapCode; el.EventID = stand.EventId; el.StandAge = stand.Age; el.StandRank = Convert.ToInt32(stand.HarvestedRank); el.NumberOfSites = stand.SiteCount; el.HarvestedSites = damagedSites; el.TotalCohortsHarvested = cohortsDamaged; el.CohortsHarvested_ = species_count; eventLog.AddObject(el); eventLog.WriteToFile(); }