Esempio n. 1
0
        //---------------------------------------------------------------------

        /// <summary>
        /// Runs the component for a particular timestep.
        /// </summary>
        /// <param name="currentTime">
        /// The current model timestep.
        /// </param>
        public override void Run()
        {
            if (SiteVars.TimeOfLastFire == null)
            {
                SiteVars.ReInitialize();
            }

            SiteVars.FuelType.ActiveSiteValues      = 0;
            SiteVars.DecidFuelType.ActiveSiteValues = 0;

            modelCore.UI.WriteLine("  Calculating the Dynamic Fuel Type for all active cells...");
            foreach (ActiveSite site in modelCore.Landscape)
            {
                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();
                }
            }
        }
Esempio n. 2
0
        public static void InitializeMetadata(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 = PlugIn.ModelCore.CurrentTime,
                ScenarioReplicationMetadata = scenRep
            };

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

            OutputMetadata mapOut_fuel = new OutputMetadata()
            {
                Type         = OutputType.Map,
                Name         = "Fuel_Map",
                FilePath     = MapNames.ReplaceTemplateVars(mapNameTemplate, PlugIn.ModelCore.CurrentTime),
                Map_DataType = MapDataType.Continuous,
                Visualize    = true,
                //Map_Unit = "categorical",
            };

            Extension.OutputMetadatas.Add(mapOut_fuel);

            OutputMetadata mapOut_pctCon = new OutputMetadata()
            {
                Type         = OutputType.Map,
                Name         = "Percent_Connifer",
                FilePath     = MapNames.ReplaceTemplateVars(pctConiferMapNameTemplate, PlugIn.ModelCore.CurrentTime),
                Map_DataType = MapDataType.Continuous,
                Visualize    = true,
                //Map_Unit = "categorical",
            };

            Extension.OutputMetadatas.Add(mapOut_pctCon);

            OutputMetadata mapOut_pctFir = new OutputMetadata()
            {
                Type         = OutputType.Map,
                Name         = "Percent_Dead_Fir",
                FilePath     = MapNames.ReplaceTemplateVars(pctDeadFirMapNameTemplate, PlugIn.ModelCore.CurrentTime),
                Map_DataType = MapDataType.Continuous,
                Visualize    = true,
                //Map_Unit = "categorical",
            };

            Extension.OutputMetadatas.Add(mapOut_pctFir);

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

            mp.WriteMetadataToXMLFile("Metadata", Extension.Name, Extension.Name);
        }