//--------------------------------------------------------------------- public static void ReadMap(string path, ISiteVar <double> siteVar) { IInputRaster <IntPixel> map; try { map = PlugIn.ModelCore.OpenRaster <IntPixel>(path); } catch (FileNotFoundException) { string messege = string.Format("Error: The file {0} does not exist", path); throw new System.ApplicationException(messege); } if (map.Dimensions != PlugIn.ModelCore.Landscape.Dimensions) { string messege = string.Format("Error: The input map {0} does not have the same dimension (row, column) as the ecoregions map", path); throw new System.ApplicationException(messege); } using (map) { IntPixel pixel = map.BufferPixel; foreach (Site site in PlugIn.ModelCore.Landscape.AllSites) { map.ReadBufferPixel(); double mapCode = (int)pixel.MapCode.Value; if (site.IsActive) { siteVar[site] = mapCode; } } } }
//--------------------------------------------------------------------- internal static void ReadUphillSlopeAzimuthMap(string path) { PlugIn.ModelCore.UI.WriteLine(" Reading in {0}", path); IInputRaster <IntPixel> map; try { map = PlugIn.ModelCore.OpenRaster <IntPixel>(path); } catch (FileNotFoundException) { string mesg = string.Format("Error: The file {0} does not exist", path); throw new System.ApplicationException(mesg); } if (map.Dimensions != PlugIn.ModelCore.Landscape.Dimensions) { string mesg = string.Format("Error: The input map {0} does not have the same dimension (row, column) as the ecoregions map", path); throw new System.ApplicationException(mesg); } using (map) { IntPixel pixel = map.BufferPixel; foreach (Site site in PlugIn.ModelCore.Landscape.AllSites) { map.ReadBufferPixel(); double mapCode = pixel.MapCode.Value; if (site.IsActive) { if (mapCode < 0 || mapCode > 360) { string mesg = string.Format("Uphill slope azimuth invalid map code (<0 or >360): {0}", mapCode); throw new System.ApplicationException(mesg); } SiteVars.UphillSlopeAzimuth[site] = (ushort)mapCode; } } } }
//--------------------------------------------------------------------- private void WriteMaps(int currentTime) { string[] paths = { "scrapple-fire", "special-dead-wood-{timestep}.img" }; //string path = MapNames.ReplaceTemplateVars("scrapple-fire/special-dead-wood-{timestep}.img", currentTime); string path = MapNames.ReplaceTemplateVars(Path.Combine(paths), currentTime); using (IOutputRaster <IntPixel> outputRaster = modelCore.CreateRaster <IntPixel>(path, modelCore.Landscape.Dimensions)) { IntPixel pixel = outputRaster.BufferPixel; foreach (Site site in PlugIn.ModelCore.Landscape.AllSites) { if (site.IsActive) { if (SiteVars.Disturbed[site] && SiteVars.Intensity[site] > 0) { pixel.MapCode.Value = (int)(SiteVars.SpecialDeadWood[site]); } else { pixel.MapCode.Value = 0; } } else { // Inactive site pixel.MapCode.Value = 0; } outputRaster.WriteBufferPixel(); } } string[] paths2 = { "scrapple-fire", "ignition-type-{timestep}.img" }; //path = MapNames.ReplaceTemplateVars("scrapple-fire/ignition-type-{timestep}.img", currentTime); path = MapNames.ReplaceTemplateVars(Path.Combine(paths2), currentTime); using (IOutputRaster <ShortPixel> outputRaster = modelCore.CreateRaster <ShortPixel>(path, modelCore.Landscape.Dimensions)) { ShortPixel pixel = outputRaster.BufferPixel; foreach (Site site in PlugIn.ModelCore.Landscape.AllSites) { if (site.IsActive) { if (SiteVars.Disturbed[site] && SiteVars.Intensity[site] > 0) { pixel.MapCode.Value = (short)(SiteVars.TypeOfIginition[site] + 1); } else { pixel.MapCode.Value = 0; } } else { // Inactive site pixel.MapCode.Value = 0; } outputRaster.WriteBufferPixel(); } } string[] paths3 = { "scrapple-fire", "fire-intensity-{timestep}.img" }; path = MapNames.ReplaceTemplateVars(Path.Combine(paths3), currentTime); //path = MapNames.ReplaceTemplateVars("scrapple-fire/fire-intensity-{timestep}.img", currentTime); using (IOutputRaster <ShortPixel> outputRaster = modelCore.CreateRaster <ShortPixel>(path, modelCore.Landscape.Dimensions)) { ShortPixel pixel = outputRaster.BufferPixel; foreach (Site site in PlugIn.ModelCore.Landscape.AllSites) { if (site.IsActive) { if (SiteVars.Disturbed[site] && SiteVars.Intensity[site] > 0) { pixel.MapCode.Value = (short)(SiteVars.Intensity[site]); } else { pixel.MapCode.Value = 0; } } else { // Inactive site pixel.MapCode.Value = 0; } outputRaster.WriteBufferPixel(); } } string[] paths4 = { "scrapple-fire", "fire-spread-probability-{timestep}.img" }; path = MapNames.ReplaceTemplateVars(Path.Combine(paths4), currentTime); //path = MapNames.ReplaceTemplateVars("scrapple-fire/fire-spread-probability-{timestep}.img", currentTime); using (IOutputRaster <ShortPixel> outputRaster = modelCore.CreateRaster <ShortPixel>(path, modelCore.Landscape.Dimensions)) { ShortPixel pixel = outputRaster.BufferPixel; foreach (Site site in PlugIn.ModelCore.Landscape.AllSites) { if (site.IsActive) { if (SiteVars.Disturbed[site] && SiteVars.Intensity[site] > 0) { pixel.MapCode.Value = (short)(SiteVars.SpreadProbability[site] * 100); } else { pixel.MapCode.Value = 0; } } else { // Inactive site pixel.MapCode.Value = 0; } outputRaster.WriteBufferPixel(); } } string[] paths5 = { "scrapple-fire", "day-of-fire-{timestep}.img" }; path = MapNames.ReplaceTemplateVars(Path.Combine(paths5), currentTime); //path = MapNames.ReplaceTemplateVars("scrapple-fire/day-of-fire-{timestep}.img", currentTime); using (IOutputRaster <ShortPixel> outputRaster = modelCore.CreateRaster <ShortPixel>(path, modelCore.Landscape.Dimensions)) { ShortPixel pixel = outputRaster.BufferPixel; foreach (Site site in PlugIn.ModelCore.Landscape.AllSites) { if (site.IsActive) { if (SiteVars.Disturbed[site] && SiteVars.Intensity[site] > 0) { pixel.MapCode.Value = (short)(SiteVars.DayOfFire[site]); } else { pixel.MapCode.Value = 0; } } else { // Inactive site pixel.MapCode.Value = 0; } outputRaster.WriteBufferPixel(); } } string[] paths6 = { "scrapple-fire", "smolder-consumption-{timestep}.img" }; path = MapNames.ReplaceTemplateVars(Path.Combine(paths6), currentTime); //path = MapNames.ReplaceTemplateVars("scrapple-fire/smolder-consumption-{timestep}.img", currentTime); using (IOutputRaster <IntPixel> outputRaster = modelCore.CreateRaster <IntPixel>(path, modelCore.Landscape.Dimensions)) { IntPixel pixel = outputRaster.BufferPixel; foreach (Site site in PlugIn.ModelCore.Landscape.AllSites) { if (site.IsActive) { if (SiteVars.Disturbed[site] && SiteVars.Intensity[site] > 0) { pixel.MapCode.Value = SiteVars.SmolderConsumption[site]; } else { pixel.MapCode.Value = 0; } } else { // Inactive site pixel.MapCode.Value = 0; } outputRaster.WriteBufferPixel(); } } string[] paths7 = { "scrapple-fire", "flaming-consumptions-{timestep}.img" }; path = MapNames.ReplaceTemplateVars(Path.Combine(paths7), currentTime); //path = MapNames.ReplaceTemplateVars("scrapple-fire/flaming-consumption-{timestep}.img", currentTime); using (IOutputRaster <IntPixel> outputRaster = modelCore.CreateRaster <IntPixel>(path, modelCore.Landscape.Dimensions)) { IntPixel pixel = outputRaster.BufferPixel; foreach (Site site in PlugIn.ModelCore.Landscape.AllSites) { if (site.IsActive) { if (SiteVars.Disturbed[site] && SiteVars.Intensity[site] > 0) { pixel.MapCode.Value = SiteVars.FlamingConsumption[site]; } else { pixel.MapCode.Value = 0; } } else { // Inactive site pixel.MapCode.Value = 0; } outputRaster.WriteBufferPixel(); } } string[] paths8 = { "scrapple-fire", "event-ID-{timestep}.img" }; path = MapNames.ReplaceTemplateVars(Path.Combine(paths8), currentTime); //path = MapNames.ReplaceTemplateVars("scrapple-fire/event-ID-{timestep}.img", currentTime); using (IOutputRaster <IntPixel> outputRaster = modelCore.CreateRaster <IntPixel>(path, modelCore.Landscape.Dimensions)) { IntPixel pixel = outputRaster.BufferPixel; foreach (Site site in PlugIn.ModelCore.Landscape.AllSites) { if (site.IsActive) { if (SiteVars.Disturbed[site] && SiteVars.Intensity[site] > 0) { pixel.MapCode.Value = SiteVars.EventID[site]; } else { pixel.MapCode.Value = 0; } } else { // Inactive site pixel.MapCode.Value = 0; } outputRaster.WriteBufferPixel(); } } }
//--------------------------------------------------------------------- private void WriteMaps(int currentTime) { string path = MapNames.ReplaceTemplateVars("scrapple-fire/special-dead-wood-{timestep}.img", currentTime); using (IOutputRaster <IntPixel> outputRaster = modelCore.CreateRaster <IntPixel>(path, modelCore.Landscape.Dimensions)) { IntPixel pixel = outputRaster.BufferPixel; foreach (Site site in PlugIn.ModelCore.Landscape.AllSites) { if (site.IsActive) { if (SiteVars.Disturbed[site]) { pixel.MapCode.Value = (int)(SiteVars.SpecialDeadWood[site]); } else { pixel.MapCode.Value = 0; } } else { // Inactive site pixel.MapCode.Value = 0; } outputRaster.WriteBufferPixel(); } } path = MapNames.ReplaceTemplateVars("scrapple-fire/ignition-type-{timestep}.img", currentTime); using (IOutputRaster <ShortPixel> outputRaster = modelCore.CreateRaster <ShortPixel>(path, modelCore.Landscape.Dimensions)) { ShortPixel pixel = outputRaster.BufferPixel; foreach (Site site in PlugIn.ModelCore.Landscape.AllSites) { if (site.IsActive) { if (SiteVars.Disturbed[site]) { pixel.MapCode.Value = (short)(SiteVars.TypeOfIginition[site] + 1); } else { pixel.MapCode.Value = 0; } } else { // Inactive site pixel.MapCode.Value = 0; } outputRaster.WriteBufferPixel(); } } path = MapNames.ReplaceTemplateVars("scrapple-fire/fire-intensity-{timestep}.img", currentTime); using (IOutputRaster <ShortPixel> outputRaster = modelCore.CreateRaster <ShortPixel>(path, modelCore.Landscape.Dimensions)) { ShortPixel pixel = outputRaster.BufferPixel; foreach (Site site in PlugIn.ModelCore.Landscape.AllSites) { if (site.IsActive) { if (SiteVars.Disturbed[site]) { pixel.MapCode.Value = (short)(SiteVars.Intensity[site]); } else { pixel.MapCode.Value = 0; } } else { // Inactive site pixel.MapCode.Value = 0; } outputRaster.WriteBufferPixel(); } } path = MapNames.ReplaceTemplateVars("scrapple-fire/fire-spread-probability-{timestep}.img", currentTime); using (IOutputRaster <ShortPixel> outputRaster = modelCore.CreateRaster <ShortPixel>(path, modelCore.Landscape.Dimensions)) { ShortPixel pixel = outputRaster.BufferPixel; foreach (Site site in PlugIn.ModelCore.Landscape.AllSites) { if (site.IsActive) { if (SiteVars.Disturbed[site]) { pixel.MapCode.Value = (short)(SiteVars.SpreadProbability[site] * 100); } else { pixel.MapCode.Value = 0; } } else { // Inactive site pixel.MapCode.Value = 0; } outputRaster.WriteBufferPixel(); } } path = MapNames.ReplaceTemplateVars("scrapple-fire/day-of-fire-{timestep}.img", currentTime); using (IOutputRaster <ShortPixel> outputRaster = modelCore.CreateRaster <ShortPixel>(path, modelCore.Landscape.Dimensions)) { ShortPixel pixel = outputRaster.BufferPixel; foreach (Site site in PlugIn.ModelCore.Landscape.AllSites) { if (site.IsActive) { if (SiteVars.Disturbed[site]) { pixel.MapCode.Value = (short)(SiteVars.DayOfFire[site]); } else { pixel.MapCode.Value = 0; } } else { // Inactive site pixel.MapCode.Value = 0; } outputRaster.WriteBufferPixel(); } } path = MapNames.ReplaceTemplateVars("scrapple-fire/smolder-consumption-{timestep}.img", currentTime); using (IOutputRaster <IntPixel> outputRaster = modelCore.CreateRaster <IntPixel>(path, modelCore.Landscape.Dimensions)) { IntPixel pixel = outputRaster.BufferPixel; foreach (Site site in PlugIn.ModelCore.Landscape.AllSites) { if (site.IsActive) { if (SiteVars.Disturbed[site]) { pixel.MapCode.Value = SiteVars.SmolderConsumption[site]; } else { pixel.MapCode.Value = 0; } } else { // Inactive site pixel.MapCode.Value = 0; } outputRaster.WriteBufferPixel(); } } path = MapNames.ReplaceTemplateVars("scrapple-fire/flaming-consumption-{timestep}.img", currentTime); using (IOutputRaster <IntPixel> outputRaster = modelCore.CreateRaster <IntPixel>(path, modelCore.Landscape.Dimensions)) { IntPixel pixel = outputRaster.BufferPixel; foreach (Site site in PlugIn.ModelCore.Landscape.AllSites) { if (site.IsActive) { if (SiteVars.Disturbed[site]) { pixel.MapCode.Value = SiteVars.FlamingConsumption[site]; } else { pixel.MapCode.Value = 0; } } else { // Inactive site pixel.MapCode.Value = 0; } outputRaster.WriteBufferPixel(); } } }