//---------------------------------------------------------------------

		public OutputRaster(string     path,
		                    Dimensions dimensions,
		                    IMetadata  metadata)
			: base(path, dimensions, metadata)
		{
			this.pixelsWritten = 0;
			this.disposed = false;
		}
		public void Init()
		{
			List<IParameters> ecoregionParms = new List<IParameters>();
			ecoregionParms.Add(new Parameters("eco0", "Ecoregion A", 0, true));
			ecoregionParms.Add(new Parameters("eco11", "Ecoregion B", 11, false));
			ecoregionParms.Add(new Parameters("eco222", "Ecoregion C", 222, true));
			ecoregionParms.Add(new Parameters("eco3333", "Ecoregion D", 3333, false));
			ecoregionParms.Add(new Parameters("eco-65535", "Ecoregion E", 65535, true));

			dataset = new Dataset(ecoregionParms);
			rasterDriverMgr = new RasterDriverManager();

			//	Initialize 8-bit ecoregion data
			ecoregions8Bit = new byte[,] {
				{   0,   0,  11, 222,  11 },
				{   0,  11,  11, 222,  11 },
				{   0,  11,  11, 222, 222 },
				{  11,  11,  11, 222, 222 },
				{  11,  11, 222, 222, 222 },
				{  11,  11, 222, 222, 222 }
			};
			dims8Bit = new Dimensions(ecoregions8Bit.GetLength(0),
			                          ecoregions8Bit.GetLength(1));
			rasterDriverMgr.SetData(path8Bit, ecoregions8Bit);

			//	Initialize 16-bit ecoregion data
			ecoregions16Bit = new ushort[,] {
				{   0,   0,  11, 222,  11,  3333,     0 },
				{   0,  11,  11, 222,  11,  3333, 65535 },
				{   0,  11,  11, 222, 222,  3333, 65535 },
				{  11,  11,  11, 222, 222,  3333, 65535 },
				{  11,  11, 222, 222, 222,  3333, 65535 },
				{  11,  11, 222, 222, 222, 65535, 65535 },
				{   0,   0, 222, 222, 222, 65535, 65535 }
			};
			dims16Bit = new Dimensions(ecoregions16Bit.GetLength(0),
			                           ecoregions16Bit.GetLength(1));
			rasterDriverMgr.SetData(path16Bit, ecoregions16Bit);
		}
		public void Init()
		{
			List<IParameters> ecoregionParms = new List<IParameters>();
			ecoregionParms.Add(new Parameters("eco0", "Ecoregion A", 0, true));
			ecoregionParms.Add(new Parameters("eco11", "Ecoregion B", 11, false));
			ecoregionParms.Add(new Parameters("eco222", "Ecoregion C", 222, true));
			ecoregionParms.Add(new Parameters("eco3333", "Ecoregion D", 3333, false));
			ecoregionParms.Add(new Parameters("eco-65535", "Ecoregion E", 65535, true));

			dataset = new Dataset(ecoregionParms);

			//	Write 8-bit ecoregion map
			ecoregions8Bit = new byte[,] {
				{   0,   0,  11, 222,  11 },
				{   0,  11,  11, 222,  11 },
				{   0,  11,  11, 222, 222 },
				{  11,  11,  11, 222, 222 },
				{  11,  11, 222, 222, 222 },
				{  11,  11, 222, 222, 222 }
			};
			dims8Bit = new RasterIO.Dimensions(ecoregions8Bit.GetLength(0),
			                                   ecoregions8Bit.GetLength(1));
			path8Bit = Data.MakeOutputPath("map-8-bit.gis");
			IOutputRaster<Pixel8Bit> map8Bit;
			map8Bit = Landis.Util.Raster.Create<Pixel8Bit>(path8Bit,
			                                               dims8Bit,
			                                               null  /* Metadata */);
			using (map8Bit) {
				Pixel8Bit pixel = new Pixel8Bit();
				for (int row = 0; row < dims8Bit.Rows; ++row) {
					for (int column = 0; column< dims8Bit.Columns; ++column) {
						pixel.Band0 = ecoregions8Bit[row, column];
						map8Bit.WritePixel(pixel);
					}
				}
			}

			//	Write 16-bit ecoregion map
			ecoregions16Bit = new ushort[,] {
				{   0,   0,  11, 222,  11,  3333,     0 },
				{   0,  11,  11, 222,  11,  3333, 65535 },
				{   0,  11,  11, 222, 222,  3333, 65535 },
				{  11,  11,  11, 222, 222,  3333, 65535 },
				{  11,  11, 222, 222, 222,  3333, 65535 },
				{  11,  11, 222, 222, 222, 65535, 65535 },
				{   0,   0, 222, 222, 222, 65535, 65535 }
			};
			dims16Bit = new RasterIO.Dimensions(ecoregions16Bit.GetLength(0),
			                                    ecoregions16Bit.GetLength(1));
			path16Bit = Data.MakeOutputPath("map-16-bit.gis");
			IOutputRaster<Pixel16Bit> map16Bit;
			map16Bit = Landis.Util.Raster.Create<Pixel16Bit>(path16Bit,
			                                                 dims16Bit,
			                                                 null  /* Metadata */);
			using (map16Bit) {
				Pixel16Bit pixel = new Pixel16Bit();
				for (int row = 0; row < dims16Bit.Rows; ++row) {
					for (int column = 0; column< dims16Bit.Columns; ++column) {
						pixel.Band0 = ecoregions16Bit[row, column];
						map16Bit.WritePixel(pixel);
					}
				}
			}
		}
		public void Equals_DiffObjs()
		{
			Dimensions dimsA = new Dimensions(22, 4444);
			Dimensions dimsB = new Dimensions(dimsA.Rows, dimsA.Columns);
			Assert.IsTrue(dimsA == dimsB);
		}
		public void Equals_Null()
		{
			Dimensions dims = new Dimensions(100, 77);
			Assert.IsFalse(dims == null);
			Assert.IsFalse(null == dims);
		}
		public void Equals_SameObj()
		{
			Dimensions dims = new Dimensions(10, 333);
			Assert.IsTrue(dims == dims);
		}
Example #7
0
        //---------------------------------------------------------------------

        /// <summary>
        /// Runs a model scenario.
        /// </summary>
        public static void Run(string scenarioPath)
        {
            //  Initialize plug-ins manager with the default plug-ins
            //	database in the folder where application resides.
            PlugIns.Manager.Initialize(PlugIns.Database.DefaultPath);

            IScenario scenario  = LoadScenario(scenarioPath);
            int       startTime = 1;

            InitializeRandomNumGenerator(scenario.RandomNumberSeed);

            LoadSpecies(scenario.Species);
            LoadEcoregions(scenario.Ecoregions);

            UI.WriteLine("Initializing landscape from ecoregions map \"{0}\" ...", scenario.EcoregionsMap);
            Ecoregions.Map ecoregionsMap = new Ecoregions.Map(scenario.EcoregionsMap,
                                                              Model.Ecoregions);
            ProcessMetadata(ecoregionsMap.Metadata, scenario);
            using (Landscape.IInputGrid <bool> grid = ecoregionsMap.OpenAsInputGrid()) {
                UI.WriteLine("Map dimensions: {0} = {1:#,##0} cell{2}", grid.Dimensions,
                             grid.Count, (grid.Count == 1 ? "" : "s"));
                landscape = new Landscape.Landscape(grid);
            }
            UI.WriteLine("Sites: {0:#,##0} active ({1:p1}), {2:#,##0} inactive ({3:p1})",
                         landscape.ActiveSiteCount, (landscape.Count > 0 ? ((double)landscape.ActiveSiteCount) / landscape.Count : 0),
                         landscape.InactiveSiteCount, (landscape.Count > 0 ? ((double)landscape.InactiveSiteCount) / landscape.Count : 0));
            landscapeMapDims = new RasterIO.Dimensions((int)landscape.Rows,
                                                       (int)landscape.Columns);
            siteVars = new SiteVariables(landscape, ecoregionsMap);

            DisturbedSiteEnumerator disturbedSites = new DisturbedSiteEnumerator(landscape,
                                                                                 SiteVars.Disturbed);

            plugInsWith2PhaseInit = new List <PlugIns.I2PhaseInitialization>();
            plugInsWithCleanUp    = new List <PlugIns.ICleanUp>();
            try {
                //  Load and initialize plug-ins.

                UI.WriteLine("Loading {0} plug-in ...", scenario.Succession.Info.Name);
                succession = PlugIns.Manager.Load <ISuccession>(scenario.Succession.Info);
                succession.Initialize(scenario.Succession.InitFile, startTime);
                succession.InitializeSites(scenario.InitialCommunities,
                                           scenario.InitialCommunitiesMap);

                IDisturbance[] disturbancePlugIns = LoadPlugIns <IDisturbance>(scenario.Disturbances, startTime);
                IOutput[]      outputPlugIns      = LoadPlugIns <IOutput>(scenario.Outputs, startTime);

                //	Perform 2nd phase of initialization for those plug-ins
                //	that have it.
                foreach (PlugIns.I2PhaseInitialization plugIn in plugInsWith2PhaseInit)
                {
                    plugIn.InitializePhase2();
                }

                //  Run those output plug-ins whose next time to run is startTime-1.
                foreach (IOutput outPlugIn in GetPlugInsToRun <IOutput>(outputPlugIns, startTime - 1))
                {
                    outPlugIn.Run(startTime - 1);
                }

                //******************// for Rob
                //  Main time loop  //
                //******************//
                // currentTime (years)
                int endTime = startTime + scenario.Duration - 1;
                for (int currentTime = startTime; currentTime <= endTime; ++currentTime)
                {
                    List <IDisturbance> distPlugInsToRun;
                    distPlugInsToRun = GetPlugInsToRun <IDisturbance>(disturbancePlugIns, currentTime);
                    bool isDistTimestep = distPlugInsToRun.Count > 0;

                    List <IOutput> outPlugInsToRun;
                    outPlugInsToRun = GetPlugInsToRun <IOutput>(outputPlugIns, currentTime);
                    bool isOutTimestep = outPlugInsToRun.Count > 0;

                    bool isSuccTimestep = succession.NextTimeToRun == currentTime;

                    //  If not a succession timestep, a disturance timestep or
                    //  an output timestep, then go to the next timestep.
                    if (!(isSuccTimestep || isDistTimestep || isOutTimestep))
                    {
                        continue;
                    }

                    UI.WriteLine("Current time: {0}", currentTime);

                    if (isDistTimestep)
                    {
                        if (scenario.DisturbancesRandomOrder)
                        {
                            Util.Random.Shuffle(distPlugInsToRun);
                        }
                        foreach (IDisturbance distPlugIn in distPlugInsToRun)
                        {
                            distPlugIn.Run(currentTime);
                        }
                    }

                    if (isSuccTimestep || isDistTimestep)
                    {
                        IEnumerable <MutableActiveSite> sites;
                        if (isSuccTimestep)
                        {
                            sites = Model.Landscape.ActiveSites;
                        }
                        else
                        {
                            sites = disturbedSites;
                        }
                        succession.AgeCohorts(sites, currentTime);
                        succession.ComputeShade(sites);
                        succession.ReproduceCohorts(sites);
                    }

                    //  Run output plug-ins.
                    foreach (IOutput outPlugIn in outPlugInsToRun)
                    {
                        outPlugIn.Run(currentTime);
                    }

                    if (!isSuccTimestep)
                    {
                        SiteVars.Disturbed.ActiveSiteValues = false;
                    }
                }                  // main time loop
            }
            finally {
                foreach (PlugIns.ICleanUp plugIn in plugInsWithCleanUp)
                {
                    plugIn.CleanUp();
                }
            }
        }
Example #8
0
		//---------------------------------------------------------------------

		/// <summary>
		/// Initializes a new instance.
		/// </summary>
		public Raster(string     path,
		              Dimensions dimensions,
		              IMetadata  metadata)
		{
			this.path = path;
			this.dimensions = dimensions;
			this.metadata = metadata;
			this.disposed = false;
			UpdatePixelCount();
		}