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

        public override void Initialize(string dataFile,
                                        PlugIns.ICore modelCore)
        {
            this.modelCore = modelCore;

            ParametersParser.SpeciesDataset = modelCore.Species;
            ParametersParser parser     = new ParametersParser();
            IParameters      parameters = Data.Load <IParameters>(dataFile,
                                                                  parser);

            Timestep        = parameters.Timestep;
            mapNameTemplate = parameters.MapNames;

            ILandscapeCohorts cohorts = modelCore.SuccessionCohorts as ILandscapeCohorts;

            if (cohorts == null)
            {
                throw new ApplicationException("Error: Cohorts don't support age-cohort interface");
            }

            selectedSpecies = new List <SpeciesMaxAgeCalculator>();
            foreach (ISpecies species in parameters.SelectedSpecies)
            {
                selectedSpecies.Add(new SpeciesMaxAgeCalculator(species, cohorts));
            }

            siteMaxAgeCalculator = new SiteMaxAgeCalculator(cohorts);

            ageBuffer = new BlockRowBuffer <ushort>(modelCore.Landscape);
        }
Exemplo n.º 2
0
        //---------------------------------------------------------------------

        public override void InitializeSites(string initialCommunities,
                                             string initialCommunitiesMap,
                                             PlugIns.ICore modelCore)
        {
            Landis.Model.iui.WriteLine("Loading initial communities from file \"{0}\" ...", initialCommunities);
            InitialCommunities.DatasetParser parser      = new InitialCommunities.DatasetParser(Timestep, Model.Core.Species);
            InitialCommunities.IDataset      communities = modelCore.Load <InitialCommunities.IDataset>(initialCommunities, parser);

            Landis.Model.iui.WriteLine("Reading initial communities map \"{0}\" ...", initialCommunitiesMap);
            IInputRaster <InitialCommunities.Pixel> map;

            map = Model.Core.OpenRaster <InitialCommunities.Pixel>(initialCommunitiesMap);
            using (map)
            {
                foreach (Site site in Model.Core.Landscape.AllSites)
                {
                    InitialCommunities.Pixel pixel = map.ReadPixel();
                    if (!site.IsActive)
                    {
                        continue;
                    }
                    ActiveSite activeSite = (ActiveSite)site;
                    ushort     mapCode    = pixel.Band0;
                    ICommunity community  = communities.Find(mapCode);
                    if (community == null)
                    {
                        throw new PixelException(activeSite.Location,
                                                 "Unknown map code for initial community: {0}",
                                                 mapCode);
                    }
                    InitializeSite(activeSite, community);
                }
            }
        }
Exemplo n.º 3
0
            //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

            public void Initialize(PlugIns.ICore modelCore)
            {
                Initialize(modelCore,
                           null,         // double[,] establishProbabilities,
                           SeedingAlgorithms.NoDispersal,
                           null);        // Reproduction.Delegates.AddNewCohort
            }
        //---------------------------------------------------------------------

        public override void Initialize(string dataFile,
                                        PlugIns.ICore modelCore)
        {
            this.modelCore = modelCore;

            ParametersParser.SpeciesDataset = modelCore.Species;
            ParametersParser parser     = new ParametersParser();
            IParameters      parameters = Data.Load <IParameters>(dataFile, parser);

            if (parameters == null)
            {
                throw new ApplicationException("Error: Missing required parameters.  Check the input parameter file");
            }


            Timestep              = parameters.Timestep;
            sppagestats_mapNames  = parameters.SppAgeStats_MapNames;
            siteagestats_mapNames = parameters.SiteAgeStats_MapNames;
            sitesppstats_mapNames = parameters.SiteSppStats_MapNames;
            ageStatSpecies        = parameters.AgeStatSpecies;
            siteAgeStats          = parameters.SiteAgeStats;
            siteSppStats          = parameters.SiteSppStats;

            cohorts = modelCore.SuccessionCohorts as ILandscapeCohorts;
            if (cohorts == null)
            {
                throw new ApplicationException("Error: Cohorts don't support age-cohort interface");
            }
        }
        //---------------------------------------------------------------------
        public override void Initialize(string        dataFile,
            PlugIns.ICore modelCore)
        {
            this.modelCore = modelCore;

            ParametersParser.SpeciesDataset = modelCore.Species;
            ParametersParser parser = new ParametersParser();
            IParameters parameters = Data.Load<IParameters>(dataFile,
                                                            parser);

            Timestep = parameters.Timestep;
            mapNameTemplate = parameters.MapNames;

            ILandscapeCohorts cohorts = modelCore.SuccessionCohorts as ILandscapeCohorts;
            if (cohorts == null)
                throw new ApplicationException("Error: Cohorts don't support age-cohort interface");

            selectedSpecies = new List<SpeciesMaxAgeCalculator>();
            foreach (ISpecies species in parameters.SelectedSpecies)
                selectedSpecies.Add(new SpeciesMaxAgeCalculator(species, cohorts));

            siteMaxAgeCalculator = new SiteMaxAgeCalculator(cohorts);

            ageBuffer = new BlockRowBuffer<ushort>(modelCore.Landscape);
        }
Exemplo n.º 6
0
        //---------------------------------------------------------------------

        /// <summary>
        /// Initializes the instance and its associated site variables.
        /// </summary>
        protected void Initialize(PlugIns.ICore modelCore,
                                  double[,]                           establishProbabilities,
                                  SeedingAlgorithms seedAlg,
                                  Reproduction.Delegates.AddNewCohort addNewCohort)
        {
            Model.Core = modelCore;
            SiteVars.Initialize();
            Seeding.InitializeMaxSeedNeighborhood();

            disturbedSites = new DisturbedSiteEnumerator(Model.Core.Landscape,
                                                         SiteVars.Disturbed);

            SeedingAlgorithm algorithm;

            switch (seedAlg)
            {
            case SeedingAlgorithms.NoDispersal:
                algorithm = NoDispersal.Algorithm;
                break;

            case SeedingAlgorithms.UniversalDispersal:
                algorithm = UniversalDispersal.Algorithm;
                break;

            case SeedingAlgorithms.WardSeedDispersal:
                algorithm = WardSeedDispersal.Algorithm;
                break;

            default:
                throw new ArgumentException(string.Format("Unknown seeding algorithm: {0}", seedAlg));
            }
            Reproduction.Initialize(establishProbabilities, algorithm,
                                    addNewCohort == null ? null : new Reproduction.Delegates.AddNewCohort(addNewCohort));
        }
            //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

            public void Initialize(PlugIns.ICore modelCore)
            {
                Initialize(modelCore,
                           null,                                   // double[,]                  establishProbabilities,
                           SeedingAlgorithms.NoDispersal,
                           (Reproduction.AddNewCohortMethod)null); // addNewCohort -- obsolete overload
            }
        //---------------------------------------------------------------------

        //  Create a 2-D array of establish probabilities that are all 1.0
        private static double[,] CreateEstablishProbabilities(PlugIns.ICore modelCore)
        {
            double[,] estabProbs = new double[modelCore.Ecoregions.Count,
                                              modelCore.Species.Count];
            foreach (IEcoregion ecoregion in modelCore.Ecoregions)
            {
                foreach (ISpecies species in modelCore.Species)
                {
                    estabProbs[ecoregion.Index, species.Index] = 1.0;
                }
            }
            return(estabProbs);
        }
Exemplo n.º 9
0
        protected void Initialize(PlugIns.ICore modelCore,
                                  double[,]                       establishProbabilities,
                                  SeedingAlgorithms seedAlg,
                                  Reproduction.AddNewCohortMethod addNewCohort)
        {
            Reproduction.Delegates.AddNewCohort wrappedMethod =
                delegate(ISpecies species,
                         ActiveSite site)
            {
                addNewCohort(species, site);
            };
            Initialize(modelCore, establishProbabilities, seedAlg, wrappedMethod);
            //new Reproduction.Delegates.AddNewCohort(addNewCohort));
//                       System.Delegate.CreateDelegate(typeof (Reproduction.Delegates.AddNewCohort),
//                                                     addNewCohort.Method));
        }
        //---------------------------------------------------------------------
        public override void Initialize(string        dataFile,
                                        PlugIns.ICore modelCore)
        {
            this.modelCore = modelCore;

            InputParametersParser parser = new InputParametersParser(modelCore.Species);
            IInputParameters parameters = Data.Load<IInputParameters>(dataFile, parser);

            Timestep = parameters.Timestep;
            this.selectedSpecies = parameters.SelectedSpecies;
            this.speciesMapNameTemplate = parameters.SpeciesMapNames;
            this.ageClasses = parameters.AgeClasses;

            cohorts = modelCore.SuccessionCohorts as ILandscapeCohorts;
            if (cohorts == null)
                throw new ApplicationException("Error: Cohorts don't support biomass interface");
        }
 public MockSuccession(PlugIns.ICore modelCore)
     : base("MockSuccession")
 {
     //  Initialize the succession library with the core.  The other
     //  3 parameters are passed to Reproduction's Initialize method
     //  but we want to use a mock seeding algorithm.  Since the
     //  base class' Initialize method uses an enumerated type to
     //  specify the seeding algorithm, we just pass in an arbitrary
     //  value, and then call Reproduction's Initialize method
     //  directly with the mock seeding algorithm.
     Initialize(modelCore,
                null,  // establishment probabilities
                SeedingAlgorithms.NoDispersal,
                null); // AddNewCohort delegate
     Reproduction.Initialize(CreateEstablishProbabilities(modelCore),
                             MySeedingAlgorithm,
                             MyAddNewCohort);
 }
        //---------------------------------------------------------------------
        public override void Initialize(string        dataFile,
            PlugIns.ICore modelCore)
        {
            this.modelCore = modelCore;

            ParametersParser.SpeciesDataset = modelCore.Species;
            ParametersParser parser = new ParametersParser();
            IParameters parameters = Data.Load<IParameters>(dataFile,
                                                            parser);

            Timestep = parameters.Timestep;
            mapNameTemplate = parameters.MapNames;
            selectedSpecies = parameters.SelectedSpecies;

            cohorts = modelCore.SuccessionCohorts as ILandscapeCohorts;
            if (cohorts == null)
                throw new ApplicationException("Error: Cohorts don't support age-cohort interface");
        }
        //---------------------------------------------------------------------
        /// <summary>
        /// Initializes the component with a data file.
        /// </summary>
        /// <param name="dataFile">
        /// Path to the file with initialization data.
        /// </param>
        /// <param name="startTime">
        /// Initial timestep (year): the timestep that will be passed to the
        /// first call to the component's Run method.
        /// </param>
        public override void Initialize(string dataFile,
            PlugIns.ICore modelCore)
        {
            this.modelCore = modelCore;

            ParametersParser.SpeciesDataset = modelCore.Species;
            ParametersParser parser = new ParametersParser();
            IParameters parameters = Data.Load<IParameters>(dataFile,
                                                            parser);
            Timestep = parameters.Timestep;
            //this.nextTimeToRun = startTime - 1;

            this.mapNameTemplate = parameters.MapFileNames;
            this.mapDefs = parameters.ReclassMaps;

            cohorts = modelCore.SuccessionCohorts as ILandscapeCohorts;
            if (cohorts == null)
                throw new ApplicationException("Error: Cohorts don't support biomass interface");
        }
        //---------------------------------------------------------------------

        public override void Initialize(string dataFile,
                                        PlugIns.ICore modelCore)
        {
            this.modelCore = modelCore;

            InputParametersParser.SpeciesDataset = modelCore.Species;
            InputParametersParser parser     = new InputParametersParser();
            IInputParameters      parameters = Data.Load <IInputParameters>(dataFile, parser);

            Timestep        = parameters.Timestep;
            mapNameTemplate = parameters.MapNames;
            selectedSpecies = parameters.SelectedSpecies;

            cohorts = modelCore.SuccessionCohorts as ILandscapeCohorts;
            if (cohorts == null)
            {
                throw new ApplicationException("Error: Cohorts don't support age-cohort interface");
            }
        }
        //---------------------------------------------------------------------
        public override void Initialize(string        dataFile,
            PlugIns.ICore modelCore)
        {
            this.modelCore = modelCore;

            ParametersParser.SpeciesDataset = modelCore.Species;
            ParametersParser parser = new ParametersParser();
            IParameters parameters = Data.Load<IParameters>(dataFile,parser);

            if (parameters==null)
                throw new ApplicationException("Error: Missing required parameters.  Check the input parameter file");

            Timestep = parameters.Timestep;
            sppagestats_mapNames = parameters.SppAgeStats_MapNames;
            siteagestats_mapNames = parameters.SiteAgeStats_MapNames;
            sitesppstats_mapNames = parameters.SiteSppStats_MapNames;
            ageStatSpecies = parameters.AgeStatSpecies;
            siteAgeStats = parameters.SiteAgeStats;
            siteSppStats = parameters.SiteSppStats;

            cohorts = modelCore.SuccessionCohorts as ILandscapeCohorts;
            if (cohorts == null)
                throw new ApplicationException("Error: Cohorts don't support age-cohort interface");
        }
        //---------------------------------------------------------------------

        public override void Initialize(string dataFile,
                                        PlugIns.ICore modelCore)
        {
        }
Exemplo n.º 17
0
        //---------------------------------------------------------------------

        private void AssertCellLength(float cellLength)
        {
            PlugIns.ICore core = model as PlugIns.ICore;
            Assert.AreEqual(cellLength, core.CellLength);
            Assert.AreEqual(ComputeCellArea(cellLength), core.CellArea);
        }
Exemplo n.º 18
0
        //---------------------------------------------------------------------
        /// <summary>
        /// Initializes the extension with a data file.
        /// </summary>
        public override void Initialize(string dataFile,
                                        PlugIns.ICore modelCore)
        {
            Model.Core = modelCore;

            InputParameterParser.EcoregionsDataset = Model.Core.Ecoregions;
            InputParameterParser parser     = new InputParameterParser();
            IInputParameters     parameters = Data.Load <IInputParameters>(dataFile, parser);

            Timestep        = parameters.Timestep;
            mapNameTemplate = parameters.MapNamesTemplate;
            srdMapNames     = parameters.SRDMapNames;
            nrdMapNames     = parameters.NRDMapNames;

            cohorts = Model.Core.SuccessionCohorts as ILandscapeCohorts;
            if (cohorts == null)
            {
                throw new ApplicationException("Error: Cohorts don't support age-cohort interface");
            }

            SiteVars.Initialize(cohorts);

            manyAgentParameters = parameters.ManyAgentParameters;
            foreach (IAgent activeAgent in manyAgentParameters)
            //   UI.WriteLine("Parameters did not load successfully.");

            {
                //foreach (ISpecies spp in Model.Species)
                //    UI.WriteLine("Spp={0}, MinorHostAge={1}.", spp.Name, activeAgent.SppParameters[spp.Index].SecondaryHostAge);

                if (activeAgent == null)
                {
                    UI.WriteLine("Agent Parameters NOT loading correctly.");
                }
                //UI.WriteLine("Name of Agent = {0}", activeAgent.AgentName);
                activeAgent.TimeToNextEpidemic = TimeToNext(activeAgent, Timestep);

                int i = 0;

                activeAgent.DispersalNeighbors
                    = GetDispersalNeighborhood(activeAgent, Timestep);
                if (activeAgent.DispersalNeighbors != null)
                {
                    foreach (RelativeLocation reloc in activeAgent.DispersalNeighbors)
                    {
                        i++;
                    }
                    UI.WriteLine("Dispersal Neighborhood = {0} neighbors.", i);
                }

                i = 0;
                activeAgent.ResourceNeighbors = GetResourceNeighborhood(activeAgent);
                if (activeAgent.ResourceNeighbors != null)
                {
                    foreach (RelativeLocationWeighted reloc in activeAgent.ResourceNeighbors)
                    {
                        i++;
                    }
                    UI.WriteLine("Resource Neighborhood = {0} neighbors.", i);
                }
            }

            string logFileName = parameters.LogFileName;

            UI.WriteLine("Opening BDA log file \"{0}\" ...", logFileName);
            log           = Data.CreateTextFile(logFileName);
            log.AutoFlush = true;
            log.Write("CurrentTime, ROS, NumCohortsKilled, NumSitesDamaged, MeanSeverity");
            log.WriteLine("");
        }