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); } } }
//--------------------------------------------------------------------- //--------------------------------------------------------------------- /// <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); } } } }