//---------------------------------------------------------------------
        static DisturbedSites()
        {
            // columns:    123456789
            string[] rows = new string[]{ "---------",    // row 1
                                          "---aaDa--",    // row 2
                                          "--aDDaa--",    // row 3
                                          "--aaaaaa-",    // row 4
                                          "-aaa--DD-",    // row 5
                                          "-Da---aaa",    // row 6
                                          "--aa--D--"};   // row 7
            bool[,] array = Bool.Make2DimArray(rows, "aD");
            int rowCount = array.GetLength(0);
            int colCount = array.GetLength(1);
            DataGrid<EcoregionCode> grid = new DataGrid<EcoregionCode>(rowCount, colCount);
            for (int row = 1; row <= rowCount; row++) {
                for (int col = 1; col <= colCount; col++) {
                    if (array[row-1, col-1])
                        grid[row, col] = new EcoregionCode(1, true);
                    else
                        grid[row, col] = new EcoregionCode(0, false);
                }
            }
            mixedLandscape = new Landscape(grid, 1);

            List<Location> locList = new List<Location>();
            foreach (ActiveSite site in mixedLandscape) {
                int row = site.Location.Row;
                int column = site.Location.Column;
                if (rows[row-1][column-1] == 'D')
                    locList.Add(site.Location);
            }
            locations = locList.ToArray();
        }
Example #2
0
        //---------------------------------------------------------------------

        /// <summary>
        /// Creates a site variable with ecoregions.
        /// </summary>
        public ISiteVar <IEcoregion> CreateSiteVar(ILandscape landscape)
        {
            ISiteVar <IEcoregion>         siteVar = landscape.NewSiteVar <IEcoregion>();
            IInputRaster <EcoregionPixel> map     = rasterFactory.OpenRaster <EcoregionPixel>(path);

            Console.WriteLine("  reading in ecoregion from {0} ", path);
            using (map)
            {
                EcoregionPixel pixel = map.BufferPixel;
                foreach (Site site in landscape.AllSites)
                {
                    map.ReadBufferPixel();
                    ushort mapCode = (ushort)pixel.MapCode.Value;
                    if (site.IsActive)
                    {
                        siteVar[site] = ecoregions.Find(mapCode);
                    }
                    if (!site.IsActive && ecoregions.Find(mapCode).Active)
                    {
                        String msg = String.Format("  Site not active and ecoregion is active.  Ecoreigon = {0}", ecoregions.Find(mapCode).Name);
                        throw new ApplicationException(msg);
                        //Console.WriteLine("  Site not active");
                    }
                    if (site.IsActive && !ecoregions.Find(mapCode).Active)
                    {
                        String msg = String.Format("  Site is active and ecoregion is not active.  Ecoreigon = {0}", ecoregions.Find(mapCode).Name);
                        throw new ApplicationException(msg);
                    }
                }
            }
            return(siteVar);
        }
Example #3
0
        //---------------------------------------------------------------------

        /// <summary>
        /// Initializes a new instance for a site on a landscape.
        /// </summary>
        /// <param name="landscape">
        ///  The landscape where the site is located.
        /// </param>
        /// <param name="locationAndIndex">
        ///  The location of the site, and the index of its data for site
        ///  variables.
        /// </param>
        internal protected Site(ILandscape landscape,
                                LocationAndIndex locationAndIndex)
        {
            Debug.Assert(landscape.IsValid(locationAndIndex.Location));
            this.landscape        = landscape;
            this.locationAndIndex = locationAndIndex;
        }
        //---------------------------------------------------------------------

        static DisturbedSites()
        {
            // columns:    123456789
            string[] rows = new string[] { "---------",   // row 1
                                           "---aaDa--",   // row 2
                                           "--aDDaa--",   // row 3
                                           "--aaaaaa-",   // row 4
                                           "-aaa--DD-",   // row 5
                                           "-Da---aaa",   // row 6
                                           "--aa--D--" }; // row 7
            bool[,] array = Bool.Make2DimArray(rows, "aD");
            DataGrid <bool> grid = new DataGrid <bool>(array);

            mixedLandscape = new Landscape(grid);

            List <Location> locList = new List <Location>();

            foreach (ActiveSite site in mixedLandscape)
            {
                int row    = (int)(site.Location.Row);
                int column = (int)(site.Location.Column);
                if (rows[row - 1][column - 1] == 'D')
                {
                    locList.Add(site.Location);
                }
            }
            locations = locList.ToArray();
        }
Example #5
0
 //---------------------------------------------------------------------
 /// <summary>
 /// Creates a site variable with ecoregions.
 /// </summary>
 public ISiteVar<IEcoregion> CreateSiteVar(ILandscape landscape)
 {
     ISiteVar<IEcoregion> siteVar = landscape.NewSiteVar<IEcoregion>();
     IInputRaster<EcoregionPixel> map = rasterFactory.OpenRaster<EcoregionPixel>(path);
     Console.WriteLine("  reading in ecoregion from {0} ", path);
     using (map)
     {
         EcoregionPixel pixel = map.BufferPixel;
         foreach (Site site in landscape.AllSites)
         {
             map.ReadBufferPixel();
             ushort mapCode = (ushort)pixel.MapCode.Value;
             if (site.IsActive)
             {
                 siteVar[site] = ecoregions.Find(mapCode);
             }
             if (!site.IsActive && ecoregions.Find(mapCode).Active)
             {
                 String msg = String.Format("  Site not active and ecoregion is active.  Ecoreigon = {0}", ecoregions.Find(mapCode).Name);
                 throw new ApplicationException(msg);
                 //Console.WriteLine("  Site not active");
             }
             if (site.IsActive && !ecoregions.Find(mapCode).Active)
             {
                 String msg = String.Format("  Site is active and ecoregion is not active.  Ecoreigon = {0}", ecoregions.Find(mapCode).Name);
                 throw new ApplicationException(msg);
             }
         }
     }
     return siteVar;
 }
Example #6
0
        //-----------------------------------------------------------------

        public SiteVariables(ILandscape landscape,
                             Ecoregions.Map ecoregionMap)
        {
            ecoregion      = ecoregionMap.CreateSiteVar(landscape);
            disturbed      = landscape.NewSiteVar <bool>();
            registeredVars = new Dictionary <string, ISiteVariable>();
        }
        public void Init()
        {
            bool[,] array = new bool[0,0];
            DataGrid<bool> grid = new DataGrid<bool>(array);
            landscape = new Landscape(grid);

            siteVarRegistry = new SiteVarRegistry();
        }
        //---------------------------------------------------------------------

        internal MutableSite(ILandscape landscape,
                             Location location,
                             bool isActive,
                             uint dataIndex)
            : base(landscape, location, dataIndex)
        {
            this.isActive = isActive;
        }
        public void Init()
        {
            EcoregionCode[,] array = new EcoregionCode[0,0];
            DataGrid<EcoregionCode> grid = new DataGrid<EcoregionCode>(array);
            landscape = new Landscape(grid, 1);

            siteVarRegistry = new SiteVarRegistry();
        }
Example #10
0
        //---------------------------------------------------------------------

        /// <summary>
        /// Initializes a new instance for a site on a landscape.
        /// </summary>
        /// <param name="landscape">
        ///  The landscape where the site is located.
        /// </param>
        /// <param name="location">
        ///  The location of the site.
        /// </param>
        /// <param name="dataIndex">
        ///  The index of the site's data for site variables.
        /// </param>
        internal protected Site(ILandscape landscape,
                                Location location,
                                uint dataIndex)
        {
            Debug.Assert(landscape.IsValid(location));
            this.landscape        = landscape;
            this.locationAndIndex = new LocationAndIndex(location, dataIndex);
        }
Example #11
0
		//---------------------------------------------------------------------

		/// <summary>
		/// Initializes a new instance for a site on a landscape.
		/// </summary>
		/// <param name="landscape">
		///  The landscape where the site is located.
		/// </param>
		/// <param name="location">
		///  The location of the site.
		/// </param>
		/// <param name="dataIndex">
		///  The index of the site's data for site variables.
		/// </param>
		internal protected Site(ILandscape landscape,
				                Location   location,
				                uint	   dataIndex)
		{
           	Debug.Assert( landscape.IsValid(location) );
			this.landscape = landscape;
			this.locationAndIndex = new LocationAndIndex(location, dataIndex);
		}
		//---------------------------------------------------------------------

		internal MutableSite(ILandscape landscape,
		               	     Location   location,
		               	     bool       isActive,
		               	     uint       dataIndex)
			: base(landscape, location, dataIndex)
		{
			this.isActive = isActive;
		}
Example #13
0
        //---------------------------------------------------------------------

        /// <summary>
        /// Initializes a new instance for a site on a landscape.
        /// </summary>
        /// <param name="landscape">
        ///  The landscape where the site is located.
        /// </param>
        /// <param name="location">
        ///  The location of the site.
        /// </param>
        /// <param name="dataIndex">
        ///  The index of the site's data for site variables.
        /// </param>
        internal protected Site(ILandscape landscape,
                                Location location,
                                uint dataIndex)
        {
            Debug.Assert(landscape.IsValid(location));
            this.landscape = landscape;
            this.location  = location;
            this.index     = dataIndex;
        }
        public void Init()
        {
            EcoregionCode[,] array = new EcoregionCode[0, 0];
            DataGrid <EcoregionCode> grid = new DataGrid <EcoregionCode>(array);

            landscape = new Landscape(grid, 1);

            siteVarRegistry = new SiteVarRegistry();
        }
 //---------------------------------------------------------------------
 /// <summary>
 /// Initializes a new instance for a site on a landscape.
 /// </summary>
 /// <param name="landscape">
 ///  The landscape where the site is located.
 /// </param>
 /// <param name="location">
 ///  The location of the site.
 /// </param>
 /// <param name="dataIndex">
 ///  The index of the site's data for site variables.
 /// </param>
 internal Site(ILandscape landscape,
     Location   location,
     uint       dataIndex)
 {
     Debug.Assert( landscape.IsValid(location) );
     this.landscape = landscape;
     this.location = location;
     this.dataIndex = dataIndex;
 }
Example #16
0
 private static bool IsLake(ILandscape tempWater, ILandscape water)
 {
     if (MathF.Abs(tempWater.SquareMorph - water.SquareMorph) != 1)
     {
         return(true);
     }
     return((!(MathF.Abs(tempWater.X - water.X) <= 1) || tempWater.Y != water.Y) &&
            (!(MathF.Abs(tempWater.Y - water.Y) <= 1) || tempWater.X != water.X));
 }
Example #17
0
        public void Init()
        {
            bool[,] array = new bool[0, 0];
            DataGrid <bool> grid = new DataGrid <bool>(array);

            landscape = new Landscape(grid);

            siteVarRegistry = new SiteVarRegistry();
        }
        public void Init()
        {
            core         = new SimpleCore();
            core.Species = CreateSpeciesDataset();

            List <Ecoregions.IParameters> ecoregionParms = new List <Ecoregions.IParameters>();

            ecoregionParms.Add(new Ecoregions.Parameters("Ecoregion A", // Name
                                                         "ecoregion A", // Description
                                                         1,             // Map Code,
                                                         true));        // Is Active?
            ecoregionParms.Add(new Ecoregions.Parameters("Ecoregion D", // Name
                                                         "ecoregion D", // Description
                                                         2,             // Map Code,
                                                         true));        // Is Active?
            core.Ecoregions = new Ecoregions.Dataset(ecoregionParms);

            int A = core.Ecoregions[0].MapCode;
            int D = core.Ecoregions[1].MapCode;
            int i = -1;   // inactive ecoregion
            DataGrid <EcoregionCode> ecoregionGrid = new DataGrid <EcoregionCode>(
                Data.MakeEcoregionCodes(new int[, ] {
                //1 2
                { A, A },    // 1
                { A, A },    // 2

                { A, A },    // 3
                { A, D },    // 4

                { i, D },    // 5
                { D, i }     // 6
            }));

            landscape      = new Landscape(ecoregionGrid, blockSize);
            core.Landscape = landscape;

            core.Ecoregion = landscape.NewSiteVar <IEcoregion>();
            foreach (ActiveSite activeSite in landscape)
            {
                ushort mapCode = (ushort)(ecoregionGrid[activeSite.Location]);
                core.Ecoregion[activeSite] = core.Ecoregions.Find(mapCode);
            }

            //  Reproduction.Initialize method accesses the succession
            //  plug-in's via the age-cohort interfaces.  So to avoid an
            //  exception, we just create an empty landscape cohorts object.
            core.SuccessionCohorts = new AgeCohort.LandscapeCohorts(null);

            MockSuccession mockSuccessionPlugIn = new MockSuccession(core);

            expectedSpecies      = new List <ISpecies>(core.Species.Count);
            speciesThatReproduce = new List <ISpecies>(core.Species.Count);

            actualSpecies_SeedingAlg   = new List <ISpecies>(core.Species.Count);
            actualSpecies_AddNewCohort = new List <ISpecies>(core.Species.Count);
        }
        //---------------------------------------------------------------------

        /// <summary>
        /// Initializes a new instance for an active site on a landscape.
        /// </summary>
        /// <param name="landscape">
        ///  The landscape where the site is located.
        /// </param>
        /// <param name="location">
        ///  The location of the site.
        /// </param>
        /// <param name="dataIndex">
        ///  The index of the site's data for site variables.
        /// </param>
        internal ActiveSite(ILandscape landscape,
                            Location location,
                            uint dataIndex)
        {
            Debug.Assert(landscape.IsValid(location));
            this.landscape = landscape;
            this.location  = location;
            Debug.Assert(dataIndex != InactiveSite.DataIndex);
            this.dataIndex = dataIndex;
        }
 //---------------------------------------------------------------------
 /// <summary>
 /// Initializes a new instance for an active site on a landscape.
 /// </summary>
 /// <param name="landscape">
 ///  The landscape where the site is located.
 /// </param>
 /// <param name="location">
 ///  The location of the site.
 /// </param>
 /// <param name="dataIndex">
 ///  The index of the site's data for site variables.
 /// </param>
 internal ActiveSite(ILandscape landscape,
     Location   location,
     uint       dataIndex)
 {
     Debug.Assert( landscape.IsValid(location) );
     this.landscape = landscape;
     this.location = location;
     Debug.Assert( dataIndex != InactiveSite.DataIndex );
     this.dataIndex = dataIndex;
 }
		public void Init()
		{
			bool[,] array = new bool[0,0];
			DataGrid<bool> grid = new DataGrid<bool>(array);
			landscape = new Landscape.Landscape(grid);

			Ecoregions.IDataset ecoregions = new Ecoregions.Dataset(null);
			ecoregionsMap = new Ecoregions.Map(Data.MakeInputPath("ecoregions-0by0.gis"),
			                                   ecoregions);
			siteVars = new SiteVariables(landscape, ecoregionsMap);
		}
        //---------------------------------------------------------------------

        public static BlockRowBuffer <IDictionary <ushort, int> > GetCodeCountBuffer(ILandscape landscape)
        {
            BlockRowBuffer <IDictionary <ushort, int> > buffer =
                new BlockRowBuffer <IDictionary <ushort, int> >(landscape);

            for (int col = 1; col <= buffer.Columns; col++)
            {
                buffer[col] = new Dictionary <ushort, int>();
            }
            return(buffer);
        }
        public void Init()
        {
            species        = Data.Species[0];
            expectedSender = null;
            deadCohorts    = new List <ICohort>();

            ILandscape landscape = Data.Make1by1Landscape();

            activeSite = landscape[1, 1];

            Cohort.DeathEvent += MySenescenceDeathMethod;
        }
Example #24
0
        public void Init()
        {
            bool[,] array = new bool[0, 0];
            DataGrid <bool> grid = new DataGrid <bool>(array);

            landscape = new Landscape.Landscape(grid);

            Ecoregions.IDataset ecoregions = new Ecoregions.Dataset(null);
            ecoregionsMap = new Ecoregions.Map(Data.MakeInputPath("ecoregions-0by0.gis"),
                                               ecoregions);
            siteVars = new SiteVariables(landscape, ecoregionsMap);
        }
        //---------------------------------------------------------------------

        public DisturbedSiteEnumerator(ILandscape landscape,
                                       ISiteVar <bool> disturbedSiteVar)
        {
            Require.ArgumentNotNull(landscape);
            Require.ArgumentNotNull(disturbedSiteVar);
            if (disturbedSiteVar.Landscape != landscape)
            {
                throw new ArgumentException("Disturbed site variable refers to different landscape");
            }

            activeSiteEtor = landscape.ActiveSites.GetEnumerator();
            disturbed      = disturbedSiteVar;
        }
		public void Init()
		{
			                            // 12345678
			string[] rows = new string[]{ "...XX...",   // 1
				                          "..XXX..X",   // 2
				                          ".XXXX.XX",   // 3
				                          "...XXXX.",   // 4
				                          "....XX..",   // 5
			                              "........" }; // 6
			activeSites = Bool.Make2DimArray(rows, "X");
			DataGrid<bool> grid = new DataGrid<bool>(activeSites);
			landscape = new Landscape.Landscape(grid);
		}
        public void Init()
        {
            // 12345678
            string[] rows = new string[] { "...XX...",              // 1
                                           "..XXX..X",              // 2
                                           ".XXXX.XX",              // 3
                                           "...XXXX.",              // 4
                                           "....XX..",              // 5
                                           "........" };            // 6
            activeSites = Bool.Make2DimArray(rows, "X");
            DataGrid <bool> grid = new DataGrid <bool>(activeSites);

            landscape = new Landscape.Landscape(grid);
        }
Example #28
0
		//---------------------------------------------------------------------

		/// <summary>
		/// Creates a site variable with ecoregions.
		/// </summary>
		public ISiteVar<IEcoregion> CreateSiteVar(ILandscape landscape)
		{
			ISiteVar<IEcoregion> siteVar = landscape.NewSiteVar<IEcoregion>();
			IInputRaster<Pixel> map = Util.Raster.Open<Pixel>(path);
			foreach (Site site in landscape.AllSites) {
				Pixel pixel = map.ReadPixel();
				if (site.IsActive) {
					ushort mapCode = pixel.Band0;
					siteVar[site] = ecoregions.Find(mapCode);
				}
			}
			map.Close();
			return siteVar;
		}
		//---------------------------------------------------------------------

		internal SiteEnumerator(ILandscape landscape)
		{
			this.landscape = landscape;
			atEnd = (landscape.Count == 0);
			moveNextNotCalled = true;
			if (! atEnd) {
				activeSiteEtor = landscape.ActiveSites.GetEnumerator() as ActiveSiteEnumerator;
				if (landscape.InactiveSiteCount > 0) {
					inactiveSite = new MutableSite(landscape,
					                               landscape.FirstInactiveSite,
					                               false, /* isActive? */
					                               landscape.InactiveSiteDataIndex);
				}
			}
		}
Example #30
0
        //---------------------------------------------------------------------

        /// <summary>
        /// Creates a site variable with ecoregions.
        /// </summary>
        public ISiteVar<IEcoregion> CreateSiteVar(ILandscape landscape)
        {
            ISiteVar<IEcoregion> siteVar = landscape.NewSiteVar<IEcoregion>();
            IInputRaster<Pixel> map = rasterFactory.OpenRaster<Pixel>(path);
            using (map) {
                foreach (Site site in landscape.AllSites) {
                    Pixel pixel = map.ReadPixel();
                    if (site.IsActive) {
                        ushort mapCode = pixel.Band0;
                        siteVar[site] = ecoregions.Find(mapCode);
                    }
                }
            }
            return siteVar;
        }
Example #31
0
        public void Init()
        {
            abiebals = Data.Species["abiebals"];
            betualle = Data.Species["betualle"];

            ILandscape landscape = Data.Make1by1Landscape();

            activeSite = landscape[1, 1];

            disturbance             = new MockSpeciesCohortsDisturbance();
            disturbance.CurrentSite = activeSite;
            deadCohorts             = new Dictionary <ISpecies, List <ushort> >();

            Cohort.DeathEvent += MyCohortDiedMethod;
        }
        //---------------------------------------------------------------------

        internal ActiveSiteEnumerator(ILandscape landscape,
                                      ActiveSiteMap activeSiteMap)
        {
            locationAndIndex = new LocationAndIndex();
            mapEtor          = activeSiteMap.GetEnumerator();
            mapEtor.UseForCurrentEntry(locationAndIndex);

            if (landscape.ActiveSiteCount > 0)
            {
                //	Get location of first active site so we have a valid
                //	location for mutable active site ctor.
                mapEtor.MoveNext();
                currentSite = new MutableActiveSite(landscape, locationAndIndex);
                mapEtor.Reset();
            }
        }
Example #33
0
        //---------------------------------------------------------------------

        private void CheckGetSite_RowColumn(ILandscape landscape)
        {
            uint inactiveDataIndex = (uint)landscape.ActiveSiteCount;

            int      index = 0;
            Location?nextActiveSite;

            if (index < activeSites.Count)
            {
                nextActiveSite = activeSites[index];
            }
            else
            {
                nextActiveSite = null;
            }
            for (uint row = 1; row <= grid.Rows; ++row)
            {
                for (uint col = 1; col <= grid.Columns; ++col)
                {
                    Location location = new Location(row, col);
                    Site     site     = landscape.GetSite(row, col);
                    if (nextActiveSite != null && nextActiveSite == location)
                    {
                        Assert.AreEqual(location, site.Location);
                        Assert.AreEqual(index, site.DataIndex);
                        Assert.AreEqual(landscape, site.Landscape);
                        Assert.AreEqual(true, site.IsActive);
                        index++;
                        if (index < activeSites.Count)
                        {
                            nextActiveSite = activeSites[index];
                        }
                        else
                        {
                            nextActiveSite = null;
                        }
                    }
                    else
                    {
                        Assert.AreEqual(location, site.Location);
                        Assert.AreEqual(inactiveDataIndex, site.DataIndex);
                        Assert.AreEqual(landscape, site.Landscape);
                        Assert.AreEqual(false, site.IsActive);
                    }
                }
            }
        }
Example #34
0
        public void AllInactiveSites()
        {
            ILandscape landscape = MakeHomogeneousLandscape("");

            Assert.AreEqual(landscape.SiteCount, landscape.InactiveSiteCount);
            Assert.AreEqual(0, landscape.ActiveSiteCount);

            foreach (Site site in landscape.AllSites)
            {
                Assert.IsFalse(site.IsActive);
            }

            foreach (ActiveSite site in landscape.ActiveSites)
            {
                Assert.Fail("Expected no active sites");
            }
        }
Example #35
0
        public ILandscape Generate(ILandscape input, IParameterProvider paramProvider)
        {
            var pointsCount = paramProvider.Get <int>("num");
            var width       = paramProvider.Get <int>("w");
            var height      = paramProvider.Get <int>("h");
            var rng         = new BlumBlumShub(DateTime.Now.Ticks);

            return(new ImmutableLandscapeBuilder()
                   .SetWidth(width)
                   .SetHeight(height)
                   .SetPoints(
                       Enumerable.Range(0, pointsCount)
                       .Select(x => new Point(rng.Next(width), rng.Next(height)))
                       .ToList()
                       )
                   .Build());
        }
Example #36
0
        //---------------------------------------------------------------------

        /// <summary>
        /// Creates a site variable with ecoregions.
        /// </summary>
        public ISiteVar <IEcoregion> CreateSiteVar(ILandscape landscape)
        {
            ISiteVar <IEcoregion> siteVar = landscape.NewSiteVar <IEcoregion>();
            IInputRaster <Pixel>  map     = Util.Raster.Open <Pixel>(path);

            foreach (Site site in landscape.AllSites)
            {
                Pixel pixel = map.ReadPixel();
                if (site.IsActive)
                {
                    ushort mapCode = pixel.Band0;
                    siteVar[site] = ecoregions.Find(mapCode);
                }
            }
            map.Close();
            return(siteVar);
        }
Example #37
0
        //---------------------------------------------------------------------

        /// <summary>
        /// Creates a site variable with ecoregions.
        /// </summary>
        public ISiteVar <IEcoregion> CreateSiteVar(ILandscape landscape)
        {
            ISiteVar <IEcoregion> siteVar = landscape.NewSiteVar <IEcoregion>();
            IInputRaster <Pixel>  map     = rasterFactory.OpenRaster <Pixel>(path);

            using (map) {
                foreach (Site site in landscape.AllSites)
                {
                    Pixel pixel = map.ReadPixel();
                    if (site.IsActive)
                    {
                        ushort mapCode = pixel.Band0;
                        siteVar[site] = ecoregions.Find(mapCode);
                    }
                }
            }
            return(siteVar);
        }
        public void RenderTo(ILandscape landscape, string filename)
        {
            using (var bitmap = new Bitmap(landscape.Width, landscape.Height)) {
                using (var graphics = Graphics.FromImage(bitmap)) {
                    var pointBrush = Brushes.CornflowerBlue;
                    var pointPen   = Pens.Orange;

                    foreach (var point in landscape.Points)
                    {
                        var rect = new Rectangle(point.X - PointSize / 2, point.Y - PointSize / 2, PointSize, PointSize);
                        graphics.FillEllipse(pointBrush, rect);
                        graphics.DrawEllipse(pointPen, rect);
                    }

                    bitmap.Save(filename);
                }
            }
        }
Example #39
0
        //---------------------------------------------------------------------

        static DisturbedSites()
        {
            // columns:    123456789
            string[] rows = new string[] { "---------",   // row 1
                                           "---aaDa--",   // row 2
                                           "--aDDaa--",   // row 3
                                           "--aaaaaa-",   // row 4
                                           "-aaa--DD-",   // row 5
                                           "-Da---aaa",   // row 6
                                           "--aa--D--" }; // row 7
            bool[,] array = Bool.Make2DimArray(rows, "aD");
            int rowCount = array.GetLength(0);
            int colCount = array.GetLength(1);
            DataGrid <EcoregionCode> grid = new DataGrid <EcoregionCode>(rowCount, colCount);

            for (int row = 1; row <= rowCount; row++)
            {
                for (int col = 1; col <= colCount; col++)
                {
                    if (array[row - 1, col - 1])
                    {
                        grid[row, col] = new EcoregionCode(1, true);
                    }
                    else
                    {
                        grid[row, col] = new EcoregionCode(0, false);
                    }
                }
            }
            mixedLandscape = new Landscape(grid, 1);

            List <Location> locList = new List <Location>();

            foreach (ActiveSite site in mixedLandscape)
            {
                int row    = site.Location.Row;
                int column = site.Location.Column;
                if (rows[row - 1][column - 1] == 'D')
                {
                    locList.Add(site.Location);
                }
            }
            locations = locList.ToArray();
        }
        //---------------------------------------------------------------------

        /// <summary>
        /// Reads a fine-scale input map using majority rule.
        /// </summary>
        /// <param name="map">
        /// The input map to read.
        /// </param>
        /// <param name="landscape">
        /// The landscape that the input map is associated with.
        /// </param>
        /// <param name="initSiteMethod">
        /// The method that's called to process a map code for a site.
        /// </param>
        public static void ReadWithMajorityRule <TPixel>(IInputRaster <TPixel> map,
                                                         ILandscape landscape,
                                                         Delegates.InitializeSite initSiteMethod)
            where TPixel : SingleBandPixel <ushort>, new()
        {
            BlockRowBuffer <IDictionary <ushort, int> > codeCountBuffer = GetCodeCountBuffer(landscape);
            Location lowerRight = new Location(landscape.BlockSize,
                                               landscape.BlockSize);

            foreach (Site site in landscape.AllSites)
            {
                TPixel pixel = map.ReadPixel();
                if (site.IsActive)
                {
                    ActiveSite activeSite = (ActiveSite)site;
                    ushort     mapCode    = pixel.Band0;
                    if (activeSite.SharesData)
                    {
                        // Increment the count for the current map code.
                        Location blockLocation = activeSite.BroadScaleLocation;
                        IDictionary <ushort, int> codeCounts = codeCountBuffer[blockLocation.Column];
                        int count;
                        codeCounts.TryGetValue(mapCode, out count);
                        codeCounts[mapCode] = count + 1;

                        if (activeSite.LocationInBlock == lowerRight)
                        {
                            // Last site in the block, so select one of
                            // map codes by majority rule.
                            ushort selectedMapCode = MajorityRule.SelectMapCode(codeCounts);
                            initSiteMethod(activeSite, selectedMapCode);
                            codeCounts.Clear();
                        }
                    }
                    else
                    {
                        // Active site has a unique data index
                        initSiteMethod(activeSite, mapCode);
                    }
                }
            }
        }
        public void MixedLandscape()
        {
            // columns:    123456789
            ILandscape landscape = MakeLandscape("---------",                   // row 1
                                                 "---XXXX--",                   // row 2
                                                 "--XXXXX--",                   // row 3
                                                 "--XXXXXX-",                   // row 4
                                                 "-XXX--XX-",                   // row 5
                                                 "-XX---XXX",                   // row 6
                                                 "--XX--X--");                  // row 7

            ISiteVar <bool> disturbed = landscape.NewSiteVar <bool>();

            Location[] disturbedLocs = new Location[] {
                new Location(2, 6),
                new Location(3, 4),
                new Location(3, 5),
                new Location(5, 7),
                new Location(5, 8),
                new Location(6, 2),
                new Location(7, 7)
            };
            foreach (Location loc in disturbedLocs)
            {
                ActiveSite site = landscape[loc];
                Assert.IsNotNull(site);
                disturbed[site] = true;
            }

            DisturbedSiteEnumerator disturbedSites;

            disturbedSites = new DisturbedSiteEnumerator(landscape, disturbed);
            int count = 0;

            foreach (ActiveSite site in disturbedSites)
            {
                count++;
                Assert.IsTrue(count <= disturbedLocs.Length);
                Assert.AreEqual(disturbedLocs[count - 1], site.Location);
            }
            Assert.AreEqual(count, disturbedLocs.Length);
        }
Example #42
0
        public void AllActiveSites()
        {
            ILandscape landscape = MakeHomogeneousLandscape("X");

            Assert.AreEqual(landscape.SiteCount, landscape.ActiveSiteCount);
            Assert.AreEqual(0, landscape.InactiveSiteCount);

            foreach (Site site in landscape.AllSites)
            {
                Assert.IsTrue(site.IsActive);
            }

            int index = 0;

            foreach (ActiveSite site in landscape.ActiveSites)
            {
                index++;
                Assert.AreEqual(index, site.DataIndex);
            }
        }
        //---------------------------------------------------------------------

        static DisturbedSites()
        {
                            // columns:    123456789
            string[] rows = new string[]{ "---------",    // row 1
                                          "---aaDa--",    // row 2
                                          "--aDDaa--",    // row 3
                                          "--aaaaaa-",    // row 4
                                          "-aaa--DD-",    // row 5
                                          "-Da---aaa",    // row 6
                                          "--aa--D--"};   // row 7
            bool[,] array = Bool.Make2DimArray(rows, "aD");
            DataGrid<bool> grid = new DataGrid<bool>(array);
            mixedLandscape = new Landscape.Landscape(grid);

            List<Location> locList = new List<Location>();
            foreach (ActiveSite site in mixedLandscape) {
                int row = (int) (site.Location.Row);
                int column = (int) (site.Location.Column);
                if (rows[row-1][column-1] == 'D')
                    locList.Add(site.Location);
            }
            locations = locList.ToArray();
        }
		//---------------------------------------------------------------------

		internal ImmutableInactiveSite(ILandscape landscape,
		               	               Location   location,
		               	               uint       dataIndex)
			: base(landscape, location, dataIndex)
		{
		}
 //---------------------------------------------------------------------
 /// <summary>
 /// Creates a new inactive site on a landscape.
 /// </summary>
 /// <param name="landscape">
 ///  The landscape where the site is located.
 /// </param>
 /// <param name="location">
 ///  The location of the site.
 /// </param>
 internal static Site Create(ILandscape landscape,
     Location   location)
 {
     return new Site(landscape, location, DataIndex);
 }
Example #46
0
		//---------------------------------------------------------------------

		/// <summary>
		/// Initializes a new instance for a site on a landscape.
		/// </summary>
		/// <param name="landscape">
		///  The landscape where the site is located.
		/// </param>
		/// <param name="locationAndIndex">
		///  The location of the site, and the index of its data for site
		///  variables.
		/// </param>
		internal protected Site(ILandscape       landscape,
				                LocationAndIndex locationAndIndex)
		{
           	Debug.Assert( landscape.IsValid(locationAndIndex.Location) );
			this.landscape = landscape;
			this.locationAndIndex  = locationAndIndex;
		}
		//---------------------------------------------------------------------

		internal ActiveSite(ILandscape landscape,
		               	    Location   location,
		               	    uint		 dataIndex)
			: base(landscape, location, dataIndex)
		{
		}
        public void Init()
        {
            core = new SimpleCore();
            core.Species = CreateSpeciesDataset();

            List<Ecoregions.IParameters> ecoregionParms = new List<Ecoregions.IParameters>();
            ecoregionParms.Add(new Ecoregions.Parameters("Ecoregion A", // Name
                                                         "ecoregion A", // Description
                                                         1,             // Map Code,
                                                         true));        // Is Active?
            ecoregionParms.Add(new Ecoregions.Parameters("Ecoregion D", // Name
                                                         "ecoregion D", // Description
                                                         2,             // Map Code,
                                                         true));        // Is Active?
            core.Ecoregions = new Ecoregions.Dataset(ecoregionParms);

            int A =  core.Ecoregions[0].MapCode;
            int D =  core.Ecoregions[1].MapCode;
            int i = -1;   // inactive ecoregion
            DataGrid<EcoregionCode> ecoregionGrid = new DataGrid<EcoregionCode>(
                Data.MakeEcoregionCodes(new int[,]{
                    //1 2
                    { A,A }, // 1
                    { A,A }, // 2

                    { A,A }, // 3
                    { A,D }, // 4

                    { i,D }, // 5
                    { D,i }  // 6
                }));

            landscape = new Landscape(ecoregionGrid, blockSize);
            core.Landscape = landscape;

            core.Ecoregion = landscape.NewSiteVar<IEcoregion>();
            foreach (ActiveSite activeSite in landscape) {
                ushort mapCode = (ushort) (ecoregionGrid[activeSite.Location]);
                core.Ecoregion[activeSite] = core.Ecoregions.Find(mapCode);
            }

            //  Reproduction.Initialize method accesses the succession
            //  plug-in's via the age-cohort interfaces.  So to avoid an
            //  exception, we just create an empty landscape cohorts object.
            core.SuccessionCohorts = new AgeCohort.LandscapeCohorts(null);

            MockSuccession mockSuccessionPlugIn = new MockSuccession(core);

            expectedSpecies = new List<ISpecies>(core.Species.Count);
            speciesThatReproduce = new List<ISpecies>(core.Species.Count);

            actualSpecies_SeedingAlg = new List<ISpecies>(core.Species.Count);
            actualSpecies_AddNewCohort = new List<ISpecies>(core.Species.Count);
        }
		//---------------------------------------------------------------------

		private void CheckGetSite_RowColumn(ILandscape landscape)
		{
			uint inactiveDataIndex = (uint) landscape.ActiveSiteCount;

			int index = 0;
			Location? nextActiveSite;
			if (index < activeSites.Count)
				nextActiveSite = activeSites[index];
			else
				nextActiveSite = null;
			for (uint row = 1; row <= grid.Rows; ++row)
				for (uint col = 1; col <= grid.Columns; ++col) {
					Location location = new Location(row, col);
					Site site = landscape.GetSite(row, col);
					if (nextActiveSite != null && nextActiveSite == location) {
						Assert.AreEqual(location, site.Location);
						Assert.AreEqual(index, site.DataIndex);
						Assert.AreEqual(landscape, site.Landscape);
						Assert.AreEqual(true, site.IsActive);
						index++;
						if (index < activeSites.Count)
							nextActiveSite = activeSites[index];
						else
							nextActiveSite = null;
					}
					else {
						Assert.AreEqual(location, site.Location);
						Assert.AreEqual(inactiveDataIndex, site.DataIndex);
						Assert.AreEqual(landscape, site.Landscape);
						Assert.AreEqual(false, site.IsActive);
					}
				}
		}
		//---------------------------------------------------------------------

		internal MutableActiveSite(ILandscape       landscape,
		                           LocationAndIndex locationAndIndex)
			: base(landscape, locationAndIndex)
		{
		}