public static ReplaceTemplateVars ( string template, int timestep ) : string | ||
template | string | |
timestep | int | |
Результат | string |
///<summary> /// Run the plug-in at a particular timestep. ///</summary> public override void Run() { PlugIn.ModelCore.UI.WriteLine(" Processing landscape for Fire events ..."); SiteVars.InitializeDisturbances(Timestep); SiteVars.Event.SiteValues = null; SiteVars.Severity.ActiveSiteValues = 0; SiteVars.Disturbed.ActiveSiteValues = false; // Update the FireRegions Map as necessary: foreach (IDynamicFireRegion dyneco in dynamicEcos) { if (dyneco.Year == PlugIn.modelCore.CurrentTime) { PlugIn.ModelCore.UI.WriteLine(" Reading in new Fire Regions Map {0}.", dyneco.MapName); FireRegions.ReadMap(dyneco.MapName); } } foreach (IFireRegion fireregion in FireRegions.Dataset) { summaryFireRegionEventCount[fireregion.Index] = 0; } summaryTotalSites = 0; summaryEventCount = 0; foreach (ActiveSite site in PlugIn.modelCore.Landscape) { Event FireEvent = Event.Initiate(site, PlugIn.modelCore.CurrentTime, Timestep); if (FireEvent != null) { LogEvent(PlugIn.modelCore.CurrentTime, FireEvent); summaryEventCount++; } } // Write Fire severity map string path = MapNames.ReplaceTemplateVars(mapNameTemplate, PlugIn.modelCore.CurrentTime); using (IOutputRaster <BytePixel> outputRaster = modelCore.CreateRaster <BytePixel>(path, modelCore.Landscape.Dimensions)) { BytePixel pixel = outputRaster.BufferPixel; foreach (Site site in modelCore.Landscape.AllSites) { if (site.IsActive) { if (SiteVars.Disturbed[site]) { pixel.MapCode.Value = (byte)(SiteVars.Severity[site] + 1); } else { pixel.MapCode.Value = 1; } } else { // Inactive site pixel.MapCode.Value = 0; } outputRaster.WriteBufferPixel(); } } WriteSummaryLog(PlugIn.modelCore.CurrentTime); }
public static void InitializeMetadata(int Timestep, string MapFileName, string eventLogName, string summaryLogName) { ScenarioReplicationMetadata scenRep = new ScenarioReplicationMetadata() { RasterOutCellArea = PlugIn.ModelCore.CellArea, TimeMin = PlugIn.ModelCore.StartTime, TimeMax = PlugIn.ModelCore.EndTime, }; Extension = new ExtensionMetadata(PlugIn.ModelCore) { Name = PlugIn.ExtensionName, TimeInterval = Timestep, //change this to PlugIn.TimeStep for other extensions ScenarioReplicationMetadata = scenRep }; //--------------------------------------- // table outputs: //--------------------------------------- CreateDirectory(eventLogName); CreateDirectory(summaryLogName); PlugIn.eventLog = new MetadataTable <EventsLog>(eventLogName); PlugIn.summaryLog = new MetadataTable <SummaryLog>(summaryLogName); //PlugIn.eventLog = new MetadataTable<EventsLog>("Fire-event-log.csv"); //PlugIn.summaryLog = new MetadataTable<SummaryLog>("Fire-summary-log.csv"); PlugIn.ModelCore.UI.WriteLine(" Generating event table..."); OutputMetadata tblOut_events = new OutputMetadata() { Type = OutputType.Table, Name = "FireEventsLog", FilePath = PlugIn.eventLog.FilePath, Visualize = false, }; tblOut_events.RetriveFields(typeof(EventsLog)); Extension.OutputMetadatas.Add(tblOut_events); PlugIn.ModelCore.UI.WriteLine(" Generating summary table..."); OutputMetadata tblOut_summary = new OutputMetadata() { Type = OutputType.Table, Name = "FireSummaryLog", FilePath = PlugIn.summaryLog.FilePath, Visualize = true, }; tblOut_summary.RetriveFields(typeof(SummaryLog)); Extension.OutputMetadatas.Add(tblOut_summary); //--------------------------------------- // 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); OutputMetadata mapOut_FireSeverity = new OutputMetadata() { Type = OutputType.Map, Name = "Fire_Severity", FilePath = MapNames.ReplaceTemplateVars(MapFileName, Timestep), Map_DataType = MapDataType.Continuous, Visualize = true, //Map_Unit = "categorical", }; Extension.OutputMetadatas.Add(mapOut_FireSeverity); //--------------------------------------- MetadataProvider mp = new MetadataProvider(Extension); mp.WriteMetadataToXMLFile("Metadata", Extension.Name, Extension.Name); }