コード例 #1
0
        //---------------------------------------------------------------------
        public static void ReadMap(string path, int agentIndex)
        {
            IInputRaster <BytePixel> map;

            try
            {
                map = PlugIn.ModelCore.OpenRaster <BytePixel>(path);
            }
            catch (FileNotFoundException)
            {
                string mesg = string.Format("Error: The file {0} does not exist", path);
                throw new System.ApplicationException(mesg);
            }

            if (map.Dimensions != PlugIn.ModelCore.Landscape.Dimensions)
            {
                string mesg = string.Format("Error: The input map {0} does not have the same dimension (row, column) as the ecoregions map", path);
                throw new System.ApplicationException(mesg);
            }

            using (map)
            {
                BytePixel pixel = map.BufferPixel;
                foreach (Site site in PlugIn.ModelCore.Landscape.AllSites)
                {
                    map.ReadBufferPixel();
                    byte mapCode = pixel.MapCode.Value;
                    if (mapCode > 1)
                    {
                        string mesg = string.Format("Error: The input map {0} must have 0-1 values, where 0 = susceptible, 1 = infected", path);
                        throw new System.ApplicationException(mesg);
                    }

                    if (site.IsActive)
                    {
                        SiteVars.InfStatus[site][agentIndex] = mapCode;
                        if (mapCode == 0)
                        {
                            SiteVars.PSusceptible[site][agentIndex] = 1;
                            SiteVars.PInfected[site][agentIndex]    = mapCode;
                        }
                        else
                        {
                            SiteVars.PSusceptible[site][agentIndex] = 0;
                            SiteVars.PInfected[site][agentIndex]    = mapCode;
                        }
                    }
                }
            }
        }
コード例 #2
0
        //---------------------------------------------------------------------
        ///<summary>
        /// Run the EDA extension at a particular timestep.
        ///</summary>
        public override void Run()
        {
            ModelCore.UI.WriteLine("   Processing landscape for EDA events ...");
            if (!reinitialized)
            {
                InitializePhase2();
            }

            int eventCount = 0;

            int agentIndex = 0;

            foreach (IAgent activeAgent in manyAgentParameters)
            {
                Epidemic.Initialize(activeAgent);

                if (activeAgent.DispersalType == DispersalType.STATIC)
                {
                    ModelCore.UI.WriteLine("   Simulating spread of epidemic...");
                    Epidemic currentEpic = Epidemic.Simulate(activeAgent, ModelCore.CurrentTime, agentIndex);
                    if (currentEpic != null)
                    {
                        LogEvent(ModelCore.CurrentTime, currentEpic, activeAgent);

                        //----- Write Infection Status maps (SUSCEPTIBLE (0), INFECTED (cryptic-non symptomatic) (1), DISEASED (symptomatic) (2) --------
                        string path = MapNames.ReplaceTemplateVars(statusMapName, activeAgent.AgentName, ModelCore.CurrentTime);
                        modelCore.UI.WriteLine("   Writing infection status map to {0} ...", path);
                        using (IOutputRaster <BytePixel> outputRaster = modelCore.CreateRaster <BytePixel>(path, modelCore.Landscape.Dimensions))
                        {
                            BytePixel pixel = outputRaster.BufferPixel;
                            foreach (Site site in ModelCore.Landscape.AllSites)
                            {
                                if (site.IsActive)
                                {
                                    pixel.MapCode.Value = (byte)(SiteVars.InfStatus[site][agentIndex] + 1);
                                }
                                else
                                {
                                    //Inactive site
                                    pixel.MapCode.Value = 0;
                                }
                                outputRaster.WriteBufferPixel();
                            }
                        }

                        if (!(mortMapNames == null))
                        {
                            //----- Write Cohort Mortality Maps (number dead cohorts for selected species) --------
                            string path2 = MapNames.ReplaceTemplateVars(mortMapNames, activeAgent.AgentName, ModelCore.CurrentTime);
                            modelCore.UI.WriteLine("   Writing cohort mortality map to {0} ...", path2);
                            using (IOutputRaster <ShortPixel> outputRaster = modelCore.CreateRaster <ShortPixel>(path2, modelCore.Landscape.Dimensions))
                            {
                                ShortPixel pixel = outputRaster.BufferPixel;
                                foreach (Site site in ModelCore.Landscape.AllSites)
                                {
                                    if (site.IsActive)
                                    {
                                        pixel.MapCode.Value = (short)(SiteVars.NumberMortSppKilled[site][agentIndex]);
                                    }
                                    else
                                    {
                                        //Inactive site
                                        pixel.MapCode.Value = -999; //should work with "short" type
                                    }
                                    outputRaster.WriteBufferPixel();
                                }
                            }
                        }

                        eventCount++;
                    }
                }
                else if (activeAgent.DispersalType == DispersalType.DYNAMIC)
                {
                    /*****************TODO*******************/
                    Console.WriteLine("Dynamic dispersal type has not been implemented yet!!");
                }

                agentIndex++;
            }
        }