public override void InitializeSites(string initialCommunitiesText, string initialCommunitiesMap, ICore modelCore)
        {
            ModelCore.UI.WriteLine("   Loading initial communities from file \"{0}\" ...", initialCommunitiesText);
            Landis.Library.InitialCommunities.DatasetParser parser      = new Landis.Library.InitialCommunities.DatasetParser(Timestep, ModelCore.Species);
            Landis.Library.InitialCommunities.IDataset      communities = Landis.Data.Load <Landis.Library.InitialCommunities.IDataset>(initialCommunitiesText, parser);

            ModelCore.UI.WriteLine("   Reading initial communities map \"{0}\" ...", initialCommunitiesMap);
            IInputRaster <uintPixel> map;

            map = ModelCore.OpenRaster <uintPixel>(initialCommunitiesMap);
            using (map)
            {
                uintPixel pixel = map.BufferPixel;
                foreach (Site site in ModelCore.Landscape.AllSites)
                {
                    map.ReadBufferPixel();
                    uint mapCode = pixel.MapCode.Value;
                    if (!site.IsActive)
                    {
                        continue;
                    }

                    ActiveSite activeSite = (ActiveSite)site;
                    initialCommunity = communities.Find(mapCode);
                    if (initialCommunity == null)
                    {
                        throw new ApplicationException(string.Format("Unknown map code for initial community: {0}", mapCode));
                    }

                    InitializeSite(activeSite); //, community);
                }
            }
        }
示例#2
0
        //---------------------------------------------------------------------

        //---------------------------------------------------------------------
        /// <summary>
        /// Reads the initial communities map, finds all unique site keys, and sets aside sites to process first and second
        /// </summary>
        private void ProcessInitialCommunitiesMap(string initialCommunitiesMap,
                                                  Landis.Library.InitialCommunities.IDataset communities, ref List <ActiveSite> processFirst,
                                                  ref List <ActiveSite> processSecond)
        {
            IInputRaster <uintPixel>      map        = ModelCore.OpenRaster <uintPixel>(initialCommunitiesMap);
            Dictionary <uint, ActiveSite> uniqueKeys = new Dictionary <uint, ActiveSite>();

            using (map)
            {
                uintPixel pixel = map.BufferPixel;
                foreach (Site site in ModelCore.Landscape.AllSites)
                {
                    map.ReadBufferPixel();
                    uint mapCode = pixel.MapCode.Value;
                    if (!site.IsActive)
                    {
                        continue;
                    }

                    ActiveSite activeSite       = (ActiveSite)site;
                    var        initialCommunity = communities.Find(mapCode);
                    if (initialCommunity == null)
                    {
                        throw new ApplicationException(string.Format("Unknown map code for initial community: {0}", mapCode));
                    }

                    sitesAndCommunities.Add(activeSite, initialCommunity);
                    uint key = SiteCohorts.ComputeKey((ushort)initialCommunity.MapCode, Globals.ModelCore.Ecoregion[site].MapCode);

                    if (!uniqueKeys.ContainsKey(key))
                    {
                        uniqueKeys.Add(key, activeSite);
                        processFirst.Add(activeSite);
                    }
                    else
                    {
                        processSecond.Add(activeSite);
                    }

                    if (!allKeys.ContainsKey(activeSite))
                    {
                        allKeys.Add(activeSite, key);
                    }
                }
            }
        }
示例#3
0
        //---------------------------------------------------------------------
        public override void InitializeSites(string initialCommunitiesText, string initialCommunitiesMap, ICore modelCore)
        {
            ModelCore.UI.WriteLine("   Loading initial communities from file \"{0}\" ...", initialCommunitiesText);
            Landis.Library.InitialCommunities.DatasetParser parser = new Landis.Library.InitialCommunities.DatasetParser(CohortBinSize, ModelCore.Species);

            //Landis.Library.InitialCommunities.DatasetParser parser = new Landis.Library.InitialCommunities.DatasetParser(Timestep, ModelCore.Species);
            Landis.Library.InitialCommunities.IDataset communities = Landis.Data.Load <Landis.Library.InitialCommunities.IDataset>(initialCommunitiesText, parser);

            List <ActiveSite> processFirst  = new List <ActiveSite>();
            List <ActiveSite> processSecond = new List <ActiveSite>();

            ModelCore.UI.WriteLine("   Reading initial communities map \"{0}\" ...", initialCommunitiesMap);
            ProcessInitialCommunitiesMap(initialCommunitiesMap, communities, ref processFirst, ref processSecond);

            if (this.ThreadCount != 1)
            {
                // Handle creation of initial community sites first
                Parallel.ForEach(processFirst, new ParallelOptions {
                    MaxDegreeOfParallelism = this.ThreadCount
                }, site =>
                {
                    InitializeSite(site);
                });

                Parallel.ForEach(processSecond, new ParallelOptions {
                    MaxDegreeOfParallelism = this.ThreadCount
                }, site =>
                {
                    InitializeSite(site);
                });
            }
            else
            {
                // First, process sites so that the initial communities are set up
                foreach (ActiveSite site in processFirst)
                {
                    InitializeSite(site);
                }

                foreach (ActiveSite site in processSecond)
                {
                    InitializeSite((ActiveSite)site);
                }
            }
        }