public static void InitializeMetadata( int Timestep, string mapNameTemplate, string pctConiferMapNameTemplate, string pctDeadFirMapNameTemplate ) { 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 }; //--------------------------------------- // 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_Fuel = new OutputMetadata() { Type = OutputType.Map, Name = "Fuel Map", FilePath = MapNames.ReplaceTemplateVars(mapNameTemplate, PlugIn.ModelCore.CurrentTime), Map_DataType = MapDataType.Continuous, Visualize = true, }; OutputMetadata mapOut_Confir = new OutputMetadata() { Type = OutputType.Map, Name = "Conifer Map", FilePath = MapNames.ReplaceTemplateVars(pctConiferMapNameTemplate, PlugIn.ModelCore.CurrentTime), Map_DataType = MapDataType.Continuous, Visualize = true, }; OutputMetadata mapOut_Dead = new OutputMetadata() { Type = OutputType.Map, Name = "Dead Fir Map", FilePath = MapNames.ReplaceTemplateVars(pctDeadFirMapNameTemplate, PlugIn.ModelCore.CurrentTime), Map_DataType = MapDataType.Continuous, Visualize = true, }; Extension.OutputMetadatas.Add(mapOut_Fuel); Extension.OutputMetadatas.Add(mapOut_Confir); Extension.OutputMetadatas.Add(mapOut_Dead); //--------------------------------------- MetadataProvider mp = new MetadataProvider(Extension); mp.WriteMetadataToXMLFile("Metadata", Extension.Name, Extension.Name); }
//--------------------------------------------------------------------- /// <summary> /// Runs the component for a particular timestep. /// </summary> /// <param name="currentTime"> /// The current model timestep. /// </param> public override void Run() { modelCore.UI.WriteLine(" Re-initializing all values to zero..."); SiteVars.FuelType.ActiveSiteValues = 0; SiteVars.DecidFuelType.ActiveSiteValues = 0; modelCore.UI.WriteLine(" Calculating the Fuel Type Index for all active cells..."); foreach (ActiveSite site in modelCore.Landscape) //ActiveSites { CalcFuelType(site, fuelTypes, disturbanceTypes); SiteVars.PercentDeadFir[site] = CalcPercentDeadFir(site); } string path = MapNames.ReplaceTemplateVars(mapNameTemplate, modelCore.CurrentTime); modelCore.UI.WriteLine(" Writing Fuel map to {0}...", path); 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) { pixel.MapCode.Value = (byte)((int)SiteVars.FuelType[site] + 1); } else { pixel.MapCode.Value = 0; } outputRaster.WriteBufferPixel(); } } string conpath = MapNames.ReplaceTemplateVars(pctConiferMapNameTemplate, modelCore.CurrentTime); modelCore.UI.WriteLine(" Writing % Conifer map to {0} ...", conpath); using (IOutputRaster <BytePixel> outputRaster = modelCore.CreateRaster <BytePixel>(conpath, modelCore.Landscape.Dimensions)) { BytePixel pixel = outputRaster.BufferPixel; foreach (Site site in modelCore.Landscape.AllSites) { if (site.IsActive) { pixel.MapCode.Value = (byte)((int)SiteVars.PercentConifer[site]); } else { pixel.MapCode.Value = 0; } outputRaster.WriteBufferPixel(); } } string firpath = MapNames.ReplaceTemplateVars(pctDeadFirMapNameTemplate, modelCore.CurrentTime); modelCore.UI.WriteLine(" Writing % Dead Fir map to {0} ...", firpath); using (IOutputRaster <BytePixel> outputRaster = modelCore.CreateRaster <BytePixel>(firpath, modelCore.Landscape.Dimensions)) { BytePixel pixel = outputRaster.BufferPixel; foreach (Site site in modelCore.Landscape.AllSites) { if (site.IsActive) { pixel.MapCode.Value = (byte)((int)SiteVars.PercentDeadFir[site]); } else { pixel.MapCode.Value = 0; } outputRaster.WriteBufferPixel(); } } }