コード例 #1
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++;
            }
        }
コード例 #2
0
        public static void InitializeMetadata(int Timestep,
                                              string statusMapFileName,
                                              string mortalityMapFileName,
                                              string logFileName,
                                              IEnumerable <IAgent> manyAgentParameters,
                                              ICore mCore)
        {
            ScenarioReplicationMetadata scenRep = new ScenarioReplicationMetadata()
            {
                //String outputFolder = OutputPath.ReplaceTemplateVars("", FINISH ME LATER);
                //FolderName = System.IO.Directory.GetCurrentDirectory().Split("\\".ToCharArray()).Last(),
                RasterOutCellArea = PlugIn.ModelCore.CellArea,
                TimeMin           = PlugIn.ModelCore.StartTime,
                TimeMax           = PlugIn.ModelCore.EndTime,
                //ProjectionFilePath = "Projection.?" //How do we get projections???
            };

            Extension = new ExtensionMetadata(mCore)
            {
                Name         = PlugIn.ExtensionName,
                TimeInterval = Timestep, //change this to PlugIn.TimeStep for other extensions
                ScenarioReplicationMetadata = scenRep
            };

            //---------------------------------------
            //          table outputs:
            //---------------------------------------
            if (logFileName != null)
            {
                System.IO.Directory.CreateDirectory(Path.GetDirectoryName(logFileName));
                PlugIn.EventLog = new MetadataTable <EventsLog>(logFileName);
                //PlugIn.EventLog = new MetadataTable<EventsLog>("eda-log.csv");

                OutputMetadata tblOut_events = new OutputMetadata()
                {
                    Type      = OutputType.Table,
                    Name      = "EventLog",
                    FilePath  = PlugIn.EventLog.FilePath,
                    Visualize = false,
                };
                tblOut_events.RetriveFields(typeof(EventsLog));
                Extension.OutputMetadatas.Add(tblOut_events);
            }

            //---------------------------------------
            //          map outputs:
            //---------------------------------------

            foreach (IAgent activeAgent in manyAgentParameters)
            {
                string mapTypePath = MapNames.ReplaceTemplateVarsMetadata(statusMapFileName, activeAgent.AgentName);

                OutputMetadata mapOut_Status = new OutputMetadata()
                {
                    Type         = OutputType.Map,
                    Name         = string.Format(activeAgent.AgentName + " Cell Infection Status "),
                    FilePath     = @mapTypePath,
                    Map_DataType = MapDataType.Ordinal,
                    Map_Unit     = FieldUnits.Severity_Rank, //based on the metadata library (https://github.com/LANDIS-II-Foundation/Libraries/blob/master/metadata/trunk/src/FieldUnits.cs)
                    Visualize    = true,                     //it seems like Severity_Rank can have values between 1-5
                };
                Extension.OutputMetadatas.Add(mapOut_Status);

                if (mortalityMapFileName != null)
                {
                    mapTypePath = MapNames.ReplaceTemplateVarsMetadata(mortalityMapFileName, activeAgent.AgentName);
                    OutputMetadata mapOut_MORT = new OutputMetadata()
                    {
                        Type         = OutputType.Map,
                        Name         = "Cohort Mortality (Flagged Species)",
                        FilePath     = @mapTypePath,
                        Map_DataType = MapDataType.Continuous,
                        Map_Unit     = FieldUnits.Count,
                        Visualize    = false,
                    };
                    Extension.OutputMetadatas.Add(mapOut_MORT);
                }
            }
            //---------------------------------------
            MetadataProvider mp = new MetadataProvider(Extension);

            mp.WriteMetadataToXMLFile("Metadata", Extension.Name, Extension.Name);
        }