Ejemplo n.º 1
0
        public static void InitializeMetadata(string speciesAgeMap, string siteAgeMap, string siteSpeciesMap, Dictionary <string, IEnumerable <ISpecies> > ageStatSpecies, List <string> siteAgeStats, List <string> siteSppStats)
        {
            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_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);

            foreach (KeyValuePair <string, IEnumerable <ISpecies> > sppAgeStatIter in ageStatSpecies)
            {
                CohortUtils.SpeciesCohortStatDelegate species_stat_func;

                switch (sppAgeStatIter.Key)
                {
                case "MAX":
                    species_stat_func = new CohortUtils.SpeciesCohortStatDelegate(CohortUtils.GetMaxAge);
                    break;

                case "MIN":
                    species_stat_func = new CohortUtils.SpeciesCohortStatDelegate(CohortUtils.GetMinAge);
                    break;

                case "MED":
                    species_stat_func = new CohortUtils.SpeciesCohortStatDelegate(CohortUtils.GetMedianAge);
                    break;

                case "AVG":
                    species_stat_func = new CohortUtils.SpeciesCohortStatDelegate(CohortUtils.GetAvgAge);
                    break;

                case "SD":
                    species_stat_func = new CohortUtils.SpeciesCohortStatDelegate(CohortUtils.GetStdDevAge);
                    break;

                default:
                    //this shouldn't ever occur
                    System.Console.WriteLine("Unhandled statistic: {0}, using MaxAge Instead", sppAgeStatIter.Key);
                    species_stat_func = new CohortUtils.SpeciesCohortStatDelegate(CohortUtils.GetMaxAge);
                    break;
                }

                foreach (ISpecies species in sppAgeStatIter.Value)
                {
                    OutputMetadata mapOut_age_stats = new OutputMetadata()
                    {
                        Type         = OutputType.Map,
                        Name         = species.Name + "_age_stats_map",
                        FilePath     = SpeciesMapNames.ReplaceTemplateVars(speciesAgeMap, species.Name, sppAgeStatIter.Key, PlugIn.ModelCore.CurrentTime),
                        Map_DataType = MapDataType.Continuous,
                        Visualize    = true,
                        //Map_Unit = "categorical",
                    };
                    Extension.OutputMetadatas.Add(mapOut_age_stats);
                }
            }

            foreach (string ageStatIter in siteAgeStats)
            {
                CohortUtils.SiteCohortStatDelegate site_stat_func;
                switch (ageStatIter)
                {
                case "MAX":
                    site_stat_func = new CohortUtils.SiteCohortStatDelegate(CohortUtils.GetMaxAge);
                    break;

                case "MIN":
                    site_stat_func = new CohortUtils.SiteCohortStatDelegate(CohortUtils.GetMinAge);
                    break;

                case "MED":
                    site_stat_func = new CohortUtils.SiteCohortStatDelegate(CohortUtils.GetMedianAge);
                    break;

                case "AVG":
                    site_stat_func = new CohortUtils.SiteCohortStatDelegate(CohortUtils.GetAvgAge);
                    break;

                case "SD":
                    site_stat_func = new CohortUtils.SiteCohortStatDelegate(CohortUtils.GetStdDevAge);
                    break;

                case "COUNT":
                    site_stat_func = new CohortUtils.SiteCohortStatDelegate(CohortUtils.GetCohortCount);
                    break;

                case "RICH":
                    site_stat_func = new CohortUtils.SiteCohortStatDelegate(CohortUtils.GetAgeRichness);
                    break;

                case "EVEN":
                    site_stat_func = new CohortUtils.SiteCohortStatDelegate(CohortUtils.GetAgeEvenness);
                    break;

                default:
                    System.Console.WriteLine("Unhandled statistic: {0}, using MaxAge Instead", ageStatIter);
                    site_stat_func = new CohortUtils.SiteCohortStatDelegate(CohortUtils.GetMaxAge);
                    break;
                }

                OutputMetadata mapOut_site_age_stats = new OutputMetadata()
                {
                    Type         = OutputType.Map,
                    Name         = ageStatIter + "_age_stats_map",
                    FilePath     = SiteMapNames.ReplaceTemplateVars(siteAgeMap, ageStatIter, PlugIn.ModelCore.CurrentTime),
                    Map_DataType = MapDataType.Continuous,
                    Visualize    = true,
                    //Map_Unit = "categorical",
                };
                Extension.OutputMetadatas.Add(mapOut_site_age_stats);
            }
            foreach (string sppStatIter in siteSppStats)
            {
                CohortUtils.SiteCohortStatDelegate site_stat_func;
                switch (sppStatIter)
                {
                case "RICH":
                    //FIXME
                    site_stat_func = new CohortUtils.SiteCohortStatDelegate(CohortUtils.GetSppRichness);
                    break;

                //add in richness
                default:
                    System.Console.WriteLine("Unhandled statistic: {0}, using Species Richness Instead", sppStatIter);
                    site_stat_func = new CohortUtils.SiteCohortStatDelegate(CohortUtils.GetSppRichness);
                    break;
                }

                OutputMetadata mapOut_site_species_stats = new OutputMetadata()
                {
                    Type         = OutputType.Map,
                    Name         = sppStatIter + "_age_stats_map",
                    FilePath     = SiteMapNames.ReplaceTemplateVars(siteSpeciesMap, sppStatIter, PlugIn.ModelCore.CurrentTime),
                    Map_DataType = MapDataType.Continuous,
                    Visualize    = true,
                    //Map_Unit = "categorical",
                };
                Extension.OutputMetadatas.Add(mapOut_site_species_stats);
            }

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

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

        public override void Run()
        {
            IOutputRaster <AgePixel> map;
            AgePixel pixel;

            //1) Create the output species age stats maps
            foreach (KeyValuePair <string, IEnumerable <ISpecies> > sppAgeStatIter in ageStatSpecies)
            {
                //statIter.Key = statistic name
                //set a function pointer here for the statistic, so we don't have to do the switch operation for every single pixel every single time??
                CohortUtils.SpeciesCohortStatDelegate species_stat_func;

                switch (sppAgeStatIter.Key)
                {
                case "MAX":
                    species_stat_func = new CohortUtils.SpeciesCohortStatDelegate(CohortUtils.GetMaxAge);
                    break;

                case "MIN":
                    species_stat_func = new CohortUtils.SpeciesCohortStatDelegate(CohortUtils.GetMinAge);
                    break;

                case "MED":
                    species_stat_func = new CohortUtils.SpeciesCohortStatDelegate(CohortUtils.GetMedianAge);
                    break;

                case "AVG":
                    species_stat_func = new CohortUtils.SpeciesCohortStatDelegate(CohortUtils.GetAvgAge);
                    break;

                case "SD":
                    species_stat_func = new CohortUtils.SpeciesCohortStatDelegate(CohortUtils.GetStdDevAge);
                    break;

                default:
                    //this shouldn't ever occur
                    System.Console.WriteLine("Unhandled statistic: {0}, using MaxAge Instead", sppAgeStatIter.Key);
                    species_stat_func = new CohortUtils.SpeciesCohortStatDelegate(CohortUtils.GetMaxAge);
                    break;
                }

                foreach (ISpecies species in sppAgeStatIter.Value)
                {
                    map = CreateSppMap(species.Name, sppAgeStatIter.Key);
                    using (map)
                    {
                        foreach (Site site in modelCore.Landscape.AllSites)
                        {
                            pixel = new AgePixel();
                            if (!site.IsActive) // and has the spp we want
                            {
                                pixel.Band0 = 0;
                            }
                            else
                            {
                                //need to do a switch on statistic
                                pixel.Band0 = species_stat_func(cohorts[site][species]);
                            }
                            map.WritePixel(pixel);
                        }
                    }
                }
            }

            //2) Create the output site age stats maps
            foreach (string ageStatIter in siteAgeStats)
            {
                CohortUtils.SiteCohortStatDelegate site_stat_func;
                switch (ageStatIter)
                {
                case "MAX":
                    site_stat_func = new CohortUtils.SiteCohortStatDelegate(CohortUtils.GetMaxAge);
                    break;

                case "MIN":
                    site_stat_func = new CohortUtils.SiteCohortStatDelegate(CohortUtils.GetMinAge);
                    break;

                case "MED":
                    site_stat_func = new CohortUtils.SiteCohortStatDelegate(CohortUtils.GetMedianAge);
                    break;

                case "AVG":
                    site_stat_func = new CohortUtils.SiteCohortStatDelegate(CohortUtils.GetAvgAge);
                    break;

                case "SD":
                    site_stat_func = new CohortUtils.SiteCohortStatDelegate(CohortUtils.GetStdDevAge);
                    break;

                case "RICH":
                    //FIXME
                    site_stat_func = new CohortUtils.SiteCohortStatDelegate(CohortUtils.GetAgeRichness);
                    break;

                case "EVEN":

                    //FIXME!
                    site_stat_func = new CohortUtils.SiteCohortStatDelegate(CohortUtils.GetAgeEvenness);
                    break;

                default:
                    System.Console.WriteLine("Unhandled statistic: {0}, using MaxAge Instead", ageStatIter);
                    site_stat_func = new CohortUtils.SiteCohortStatDelegate(CohortUtils.GetMaxAge);
                    break;
                }

                map = CreateSiteMap(siteagestats_mapNames, ageStatIter);
                using (map)
                {
                    pixel = new AgePixel();
                    foreach (Site site in modelCore.Landscape.AllSites)
                    {
                        if (!site.IsActive)
                        {
                            pixel.Band0 = 0;
                        }
                        else
                        {
                            pixel.Band0 = site_stat_func(cohorts[site]);
                        }

                        map.WritePixel(pixel);
                    }
                }
            }

            //3) Create the output site species stats maps
            foreach (string sppStatIter in siteSppStats)
            {
                CohortUtils.SiteCohortStatDelegate site_stat_func;
                switch (sppStatIter)
                {
                case "RICH":
                    //FIXME
                    site_stat_func = new CohortUtils.SiteCohortStatDelegate(CohortUtils.GetSppRichness);
                    break;

                //add in richness
                default:
                    System.Console.WriteLine("Unhandled statistic: {0}, using Species Richness Instead", sppStatIter);
                    site_stat_func = new CohortUtils.SiteCohortStatDelegate(CohortUtils.GetSppRichness);
                    break;
                }

                map = CreateSiteMap(sitesppstats_mapNames, sppStatIter);
                using (map)
                {
                    pixel = new AgePixel();
                    foreach (Site site in modelCore.Landscape.AllSites)
                    {
                        if (!site.IsActive)
                        {
                            pixel.Band0 = 0;
                        }
                        else
                        {
                            pixel.Band0 = site_stat_func(cohorts[site]);
                        }

                        map.WritePixel(pixel);
                    }
                }
            }
        }
        //---------------------------------------------------------------------
        public override void Run()
        {
            IOutputRaster<AgePixel> map;
            AgePixel pixel;

            //1) Create the output species age stats maps
            foreach (KeyValuePair<string, IEnumerable<ISpecies>> sppAgeStatIter in ageStatSpecies)
            {
                //statIter.Key = statistic name
                //set a function pointer here for the statistic, so we don't have to do the switch operation for every single pixel every single time??
                CohortUtils.SpeciesCohortStatDelegate species_stat_func;

                switch (sppAgeStatIter.Key)
                {
                    case "MAX":
                        species_stat_func = new CohortUtils.SpeciesCohortStatDelegate(CohortUtils.GetMaxAge);
                        break;
                    case "MIN":
                        species_stat_func = new CohortUtils.SpeciesCohortStatDelegate(CohortUtils.GetMinAge);
                        break;
                    case "MED":
                        species_stat_func = new CohortUtils.SpeciesCohortStatDelegate(CohortUtils.GetMedianAge);
                        break;
                    case "AVG":
                        species_stat_func = new CohortUtils.SpeciesCohortStatDelegate(CohortUtils.GetAvgAge);
                        break;
                    case "SD":
                        species_stat_func = new CohortUtils.SpeciesCohortStatDelegate(CohortUtils.GetStdDevAge);
                        break;

                    default:
                        //this shouldn't ever occur
                        System.Console.WriteLine("Unhandled statistic: {0}, using MaxAge Instead",sppAgeStatIter.Key);
                        species_stat_func = new CohortUtils.SpeciesCohortStatDelegate(CohortUtils.GetMaxAge);
                        break;
                }

                foreach (ISpecies species in sppAgeStatIter.Value)
                {
                    map = CreateSppMap(species.Name, sppAgeStatIter.Key);
                    using (map)
                    {
                        foreach (Site site in modelCore.Landscape.AllSites)
                        {
                            pixel = new AgePixel();
                            if (!site.IsActive) // and has the spp we want
                                pixel.Band0 = 0;
                            else
                            {
                                //need to do a switch on statistic
                                pixel.Band0 = species_stat_func(cohorts[site][species]);
                            }
                            map.WritePixel(pixel);
                        }
                    }
                }
            }

            //2) Create the output site age stats maps
            foreach(string ageStatIter in siteAgeStats)
            {
                CohortUtils.SiteCohortStatDelegate site_stat_func;
                switch (ageStatIter)
                {
                    case "MAX":
                        site_stat_func = new CohortUtils.SiteCohortStatDelegate(CohortUtils.GetMaxAge);
                        break;
                    case "MIN":
                        site_stat_func = new CohortUtils.SiteCohortStatDelegate(CohortUtils.GetMinAge);
                        break;
                    case "MED":
                        site_stat_func = new CohortUtils.SiteCohortStatDelegate(CohortUtils.GetMedianAge);
                        break;
                    case "AVG":
                        site_stat_func = new CohortUtils.SiteCohortStatDelegate(CohortUtils.GetAvgAge);
                        break;
                    case "SD":
                        site_stat_func = new CohortUtils.SiteCohortStatDelegate(CohortUtils.GetStdDevAge);
                        break;
                    case "RICH":
                        //FIXME
                        site_stat_func = new CohortUtils.SiteCohortStatDelegate(CohortUtils.GetAgeRichness);
                        break;
                    case "EVEN":

                        //FIXME!
                        site_stat_func = new CohortUtils.SiteCohortStatDelegate(CohortUtils.GetAgeEvenness);
                        break;

                    default:
                        System.Console.WriteLine("Unhandled statistic: {0}, using MaxAge Instead", ageStatIter);
                        site_stat_func = new CohortUtils.SiteCohortStatDelegate(CohortUtils.GetMaxAge);
                        break;
                }

                map = CreateSiteMap(siteagestats_mapNames, ageStatIter);
                using (map)
                {
                    pixel = new AgePixel();
                    foreach (Site site in modelCore.Landscape.AllSites)
                    {
                        if (!site.IsActive)
                            pixel.Band0 = 0;
                        else
                            pixel.Band0 = site_stat_func(cohorts[site]);

                        map.WritePixel(pixel);
                    }
                }
            }

            //3) Create the output site species stats maps
            foreach (string sppStatIter in siteSppStats)
            {
                CohortUtils.SiteCohortStatDelegate site_stat_func;
                switch (sppStatIter)
                {
                    case "RICH":
                        //FIXME
                        site_stat_func = new CohortUtils.SiteCohortStatDelegate(CohortUtils.GetSppRichness);
                        break;
                    //add in richness
                    default:
                        System.Console.WriteLine("Unhandled statistic: {0}, using Species Richness Instead", sppStatIter);
                        site_stat_func = new CohortUtils.SiteCohortStatDelegate(CohortUtils.GetSppRichness);
                        break;
                }

                map = CreateSiteMap(sitesppstats_mapNames, sppStatIter);
                using (map)
                {
                    pixel = new AgePixel();
                    foreach (Site site in modelCore.Landscape.AllSites)
                    {
                        if (!site.IsActive)
                            pixel.Band0 = 0;
                        else
                            pixel.Band0 = site_stat_func(cohorts[site]);

                        map.WritePixel(pixel);
                    }
                }
            }
        }
        //---------------------------------------------------------------------
        public override void Run()
        {
            //1) Create the output species age stats maps
            foreach (KeyValuePair<string, IEnumerable<ISpecies>> sppAgeStatIter in ageStatSpecies)
            {
                //statIter.Key = statistic name
                //set a function pointer here for the statistic, so we don't have to do the switch operation for every single pixel every single time??
                CohortUtils.SpeciesCohortStatDelegate species_stat_func;

                switch (sppAgeStatIter.Key)
                {
                    case "MAX":
                        species_stat_func = new CohortUtils.SpeciesCohortStatDelegate(CohortUtils.GetMaxAge);
                        break;
                    case "MIN":
                        species_stat_func = new CohortUtils.SpeciesCohortStatDelegate(CohortUtils.GetMinAge);
                        break;
                    case "MED":
                        species_stat_func = new CohortUtils.SpeciesCohortStatDelegate(CohortUtils.GetMedianAge);
                        break;
                    case "AVG":
                        species_stat_func = new CohortUtils.SpeciesCohortStatDelegate(CohortUtils.GetAvgAge);
                        break;
                    case "SD":
                        species_stat_func = new CohortUtils.SpeciesCohortStatDelegate(CohortUtils.GetStdDevAge);
                        break;

                    default:
                        //this shouldn't ever occur
                        System.Console.WriteLine("Unhandled statistic: {0}, using MaxAge Instead",sppAgeStatIter.Key);
                        species_stat_func = new CohortUtils.SpeciesCohortStatDelegate(CohortUtils.GetMaxAge);
                        break;
                }

                foreach (ISpecies species in sppAgeStatIter.Value)
                {
                    string path = SpeciesMapNames.ReplaceTemplateVars(sppagestats_mapNames, species.Name, sppAgeStatIter.Key, modelCore.CurrentTime);
                    ModelCore.UI.WriteLine("   Writing {0} map for {1} to {2} ...", sppAgeStatIter.Key, species.Name, path);
                    using (IOutputRaster<IntPixel> outputRaster = modelCore.CreateRaster<IntPixel>(path, modelCore.Landscape.Dimensions))
                    {
                        IntPixel pixel = outputRaster.BufferPixel;
                        foreach (Site site in modelCore.Landscape.AllSites)
                        {
                            if (!site.IsActive) // and has the spp we want
                                pixel.MapCode.Value = 0;
                            else
                            {
                                //need to do a switch on statistic
                                pixel.MapCode.Value = (int) species_stat_func(species, site);
                            }

                            outputRaster.WriteBufferPixel();
                        }
                    }
                }
            }

            //2) Create the output site age stats maps
            foreach(string ageStatIter in siteAgeStats)
            {
                CohortUtils.SiteCohortStatDelegate site_stat_func;
                switch (ageStatIter)
                {
                    case "MAX":
                        site_stat_func = new CohortUtils.SiteCohortStatDelegate(CohortUtils.GetMaxAge);
                        break;
                    case "MIN":
                        site_stat_func = new CohortUtils.SiteCohortStatDelegate(CohortUtils.GetMinAge);
                        break;
                    case "MED":
                        site_stat_func = new CohortUtils.SiteCohortStatDelegate(CohortUtils.GetMedianAge);
                        break;
                    case "AVG":
                        site_stat_func = new CohortUtils.SiteCohortStatDelegate(CohortUtils.GetAvgAge);
                        break;
                    case "SD":
                        site_stat_func = new CohortUtils.SiteCohortStatDelegate(CohortUtils.GetStdDevAge);
                        break;
                    case "COUNT":
                        site_stat_func = new CohortUtils.SiteCohortStatDelegate(CohortUtils.GetCohortCount);
                        break;
                    case "RICH":
                        site_stat_func = new CohortUtils.SiteCohortStatDelegate(CohortUtils.GetAgeRichness);
                        break;
                    case "EVEN":
                        site_stat_func = new CohortUtils.SiteCohortStatDelegate(CohortUtils.GetAgeEvenness);
                        break;

                    default:
                        System.Console.WriteLine("Unhandled statistic: {0}, using MaxAge Instead", ageStatIter);
                        site_stat_func = new CohortUtils.SiteCohortStatDelegate(CohortUtils.GetMaxAge);
                        break;
                }

                string path = SiteMapNames.ReplaceTemplateVars(siteagestats_mapNames, ageStatIter, modelCore.CurrentTime);
                ModelCore.UI.WriteLine("   Writing {0} site map to {1} ...", ageStatIter, path);
                using (IOutputRaster<IntPixel> outputRaster = modelCore.CreateRaster<IntPixel>(path, modelCore.Landscape.Dimensions))
                {
                    IntPixel pixel = outputRaster.BufferPixel;
                    foreach (Site site in modelCore.Landscape.AllSites)
                    {
                        if (!site.IsActive)
                            pixel.MapCode.Value = 0;
                        else
                            pixel.MapCode.Value = (int) site_stat_func(site);

                        outputRaster.WriteBufferPixel();
                    }
                }
            }

            //3) Create the output site species stats maps
            foreach (string sppStatIter in siteSppStats)
            {
                CohortUtils.SiteCohortStatDelegate site_stat_func;
                switch (sppStatIter)
                {
                    case "RICH":
                        //FIXME
                        site_stat_func = new CohortUtils.SiteCohortStatDelegate(CohortUtils.GetSppRichness);
                        break;
                    //add in richness
                    default:
                        System.Console.WriteLine("Unhandled statistic: {0}, using Species Richness Instead", sppStatIter);
                        site_stat_func = new CohortUtils.SiteCohortStatDelegate(CohortUtils.GetSppRichness);
                        break;
                }

                string path = SiteMapNames.ReplaceTemplateVars(sitesppstats_mapNames, sppStatIter, modelCore.CurrentTime);
                ModelCore.UI.WriteLine("   Writing {0} site map to {1} ...", sppStatIter, path);
                using (IOutputRaster<IntPixel> outputRaster = modelCore.CreateRaster<IntPixel>(path, modelCore.Landscape.Dimensions))
                {
                    IntPixel pixel = outputRaster.BufferPixel;
                    foreach (Site site in modelCore.Landscape.AllSites)
                    {
                        if (!site.IsActive)
                            pixel.MapCode.Value = 0;
                        else
                            pixel.MapCode.Value = (int) site_stat_func(site);

                        outputRaster.WriteBufferPixel();
                    }
                }
            }
        }
Ejemplo n.º 5
0
        //---------------------------------------------------------------------

        public override void Run()
        {
            //1) Create the output species age stats maps
            foreach (KeyValuePair <string, IEnumerable <ISpecies> > sppAgeStatIter in ageStatSpecies)
            {
                //statIter.Key = statistic name
                //set a function pointer here for the statistic, so we don't have to do the switch operation for every single pixel every single time??
                CohortUtils.SpeciesCohortStatDelegate species_stat_func;

                switch (sppAgeStatIter.Key)
                {
                case "MAX":
                    species_stat_func = new CohortUtils.SpeciesCohortStatDelegate(CohortUtils.GetMaxAge);
                    break;

                case "MIN":
                    species_stat_func = new CohortUtils.SpeciesCohortStatDelegate(CohortUtils.GetMinAge);
                    break;

                case "MED":
                    species_stat_func = new CohortUtils.SpeciesCohortStatDelegate(CohortUtils.GetMedianAge);
                    break;

                case "AVG":
                    species_stat_func = new CohortUtils.SpeciesCohortStatDelegate(CohortUtils.GetAvgAge);
                    break;

                case "SD":
                    species_stat_func = new CohortUtils.SpeciesCohortStatDelegate(CohortUtils.GetStdDevAge);
                    break;

                default:
                    //this shouldn't ever occur
                    System.Console.WriteLine("Unhandled statistic: {0}, using MaxAge Instead", sppAgeStatIter.Key);
                    species_stat_func = new CohortUtils.SpeciesCohortStatDelegate(CohortUtils.GetMaxAge);
                    break;
                }

                foreach (ISpecies species in sppAgeStatIter.Value)
                {
                    string path = SpeciesMapNames.ReplaceTemplateVars(sppagestats_mapNames, species.Name, sppAgeStatIter.Key, modelCore.CurrentTime);
                    ModelCore.UI.WriteLine("   Writing {0} map for {1} to {2} ...", sppAgeStatIter.Key, species.Name, path);
                    using (IOutputRaster <IntPixel> outputRaster = modelCore.CreateRaster <IntPixel>(path, modelCore.Landscape.Dimensions))
                    {
                        IntPixel pixel = outputRaster.BufferPixel;
                        foreach (Site site in modelCore.Landscape.AllSites)
                        {
                            if (!site.IsActive) // and has the spp we want
                            {
                                pixel.MapCode.Value = 0;
                            }
                            else
                            {
                                //need to do a switch on statistic
                                pixel.MapCode.Value = (int)species_stat_func(species, site);
                            }

                            outputRaster.WriteBufferPixel();
                        }
                    }
                }
            }

            //2) Create the output site age stats maps
            foreach (string ageStatIter in siteAgeStats)
            {
                CohortUtils.SiteCohortStatDelegate site_stat_func;
                switch (ageStatIter)
                {
                case "MAX":
                    site_stat_func = new CohortUtils.SiteCohortStatDelegate(CohortUtils.GetMaxAge);
                    break;

                case "MIN":
                    site_stat_func = new CohortUtils.SiteCohortStatDelegate(CohortUtils.GetMinAge);
                    break;

                case "MED":
                    site_stat_func = new CohortUtils.SiteCohortStatDelegate(CohortUtils.GetMedianAge);
                    break;

                case "AVG":
                    site_stat_func = new CohortUtils.SiteCohortStatDelegate(CohortUtils.GetAvgAge);
                    break;

                case "SD":
                    site_stat_func = new CohortUtils.SiteCohortStatDelegate(CohortUtils.GetStdDevAge);
                    break;

                case "COUNT":
                    site_stat_func = new CohortUtils.SiteCohortStatDelegate(CohortUtils.GetCohortCount);
                    break;

                case "RICH":
                    site_stat_func = new CohortUtils.SiteCohortStatDelegate(CohortUtils.GetAgeRichness);
                    break;

                case "EVEN":
                    site_stat_func = new CohortUtils.SiteCohortStatDelegate(CohortUtils.GetAgeEvenness);
                    break;

                default:
                    System.Console.WriteLine("Unhandled statistic: {0}, using MaxAge Instead", ageStatIter);
                    site_stat_func = new CohortUtils.SiteCohortStatDelegate(CohortUtils.GetMaxAge);
                    break;
                }

                string path = SiteMapNames.ReplaceTemplateVars(siteagestats_mapNames, ageStatIter, modelCore.CurrentTime);
                ModelCore.UI.WriteLine("   Writing {0} site map to {1} ...", ageStatIter, path);
                using (IOutputRaster <IntPixel> outputRaster = modelCore.CreateRaster <IntPixel>(path, modelCore.Landscape.Dimensions))
                {
                    IntPixel pixel = outputRaster.BufferPixel;
                    foreach (Site site in modelCore.Landscape.AllSites)
                    {
                        if (!site.IsActive)
                        {
                            pixel.MapCode.Value = 0;
                        }
                        else
                        {
                            pixel.MapCode.Value = (int)site_stat_func(site);
                        }

                        outputRaster.WriteBufferPixel();
                    }
                }
            }

            //3) Create the output site species stats maps
            foreach (string sppStatIter in siteSppStats)
            {
                CohortUtils.SiteCohortStatDelegate site_stat_func;
                switch (sppStatIter)
                {
                case "RICH":
                    //FIXME
                    site_stat_func = new CohortUtils.SiteCohortStatDelegate(CohortUtils.GetSppRichness);
                    break;

                //add in richness
                default:
                    System.Console.WriteLine("Unhandled statistic: {0}, using Species Richness Instead", sppStatIter);
                    site_stat_func = new CohortUtils.SiteCohortStatDelegate(CohortUtils.GetSppRichness);
                    break;
                }

                string path = SiteMapNames.ReplaceTemplateVars(sitesppstats_mapNames, sppStatIter, modelCore.CurrentTime);
                ModelCore.UI.WriteLine("   Writing {0} site map to {1} ...", sppStatIter, path);
                using (IOutputRaster <IntPixel> outputRaster = modelCore.CreateRaster <IntPixel>(path, modelCore.Landscape.Dimensions))
                {
                    IntPixel pixel = outputRaster.BufferPixel;
                    foreach (Site site in modelCore.Landscape.AllSites)
                    {
                        if (!site.IsActive)
                        {
                            pixel.MapCode.Value = 0;
                        }
                        else
                        {
                            pixel.MapCode.Value = (int)site_stat_func(site);
                        }

                        outputRaster.WriteBufferPixel();
                    }
                }
            }
        }