public void OutputCurrentModelState(ModelGrid currentModelGrid, List <uint[]> cellIndices, uint currentTimestep)
        {
            GridCellCohortHandler TempCohorts;
            GridCellStockHandler  TempStocks;

            string context;
            string organism;

            context = Convert.ToString(currentTimestep) + "\t";

            foreach (uint[] cell in cellIndices)
            {
                context = Convert.ToString(currentTimestep) + "\t" +
                          Convert.ToString(currentModelGrid.GetCellLatitude(cell[0])) + "\t" +
                          Convert.ToString(currentModelGrid.GetCellLongitude(cell[1])) + "\t";

                TempStocks  = currentModelGrid.GetGridCellStocks(cell[0], cell[1]);
                TempCohorts = currentModelGrid.GetGridCellCohorts(cell[0], cell[1]);

                foreach (List <Stock> ListS in TempStocks)
                {
                    foreach (Stock S in ListS)
                    {
                        organism = "-999\tS" + Convert.ToString(S.FunctionalGroupIndex) + "\t" +
                                   "-999\t-999\t" + Convert.ToString(S.IndividualBodyMass) + "\t" +
                                   Convert.ToString(S.TotalBiomass) + "\t" +
                                   "-999\t-999\t-999\t-999\t-999\t-999";
                        SyncStateWriter.WriteLine(context + organism);
                    }
                }

                foreach (List <Cohort> ListC in TempCohorts)
                {
                    foreach (Cohort C in ListC)
                    {
                        organism = Convert.ToString(C.CohortID) + "\t" +
                                   Convert.ToString(C.FunctionalGroupIndex) + "\t" +
                                   Convert.ToString(C.JuvenileMass) + "\t" +
                                   Convert.ToString(C.AdultMass) + "\t" +
                                   Convert.ToString(C.IndividualBodyMass) + "\t" +
                                   Convert.ToString(C.CohortAbundance) + "\t" +
                                   Convert.ToString(C.IndividualReproductivePotentialMass) + "\t" +
                                   Convert.ToString(C.BirthTimeStep) + "\t" +
                                   Convert.ToString(C.MaturityTimeStep) + "\t" +
                                   Convert.ToString(C.LogOptimalPreyBodySizeRatio) + "\t" +
                                   Convert.ToString(C.MaximumAchievedBodyMass) + "\t" +
                                   Convert.ToString(C.TrophicIndex) + "\t" +
                                   Convert.ToString(C.ProportionTimeActive);

                        SyncStateWriter.WriteLine(context + organism);
                    }
                }
            }
        }
        public void OutputCurrentModelState(ModelGrid currentModelGrid, List<uint[]> cellIndices, uint currentTimestep)
        {

            GridCellCohortHandler TempCohorts;
            GridCellStockHandler TempStocks;

            string context;
            string organism;

            context = Convert.ToString(currentTimestep) + "\t";

            using (var StateWriter = File.AppendText(this.FileName))
            {
                foreach (uint[] cell in cellIndices)
                {
                    context = Convert.ToString(currentTimestep) + "\t" +
                            Convert.ToString(currentModelGrid.GetCellLatitude(cell[0])) + "\t" +
                                Convert.ToString(currentModelGrid.GetCellLongitude(cell[1])) + "\t";

                    TempStocks = currentModelGrid.GetGridCellStocks(cell[0], cell[1]);
                    TempCohorts = currentModelGrid.GetGridCellCohorts(cell[0], cell[1]);

                    foreach (List<Stock> ListS in TempStocks)
                    {
                        foreach (Stock S in ListS)
                        {
                            organism = "-999\tS" + Convert.ToString(S.FunctionalGroupIndex) + "\t" +
                                        "-999\t-999\t" + Convert.ToString(S.IndividualBodyMass) + "\t" +
                                        Convert.ToString(S.TotalBiomass / S.IndividualBodyMass) + "\t" +
                                        "-999\t-999\t-999\t-999\t-999\t-999";
                            StateWriter.WriteLine(context + organism);
                        }
                    }

                    foreach (List<Cohort> ListC in TempCohorts)
                    {
                        foreach (Cohort C in ListC)
                        {
#if true
                            var cohortIds = C.CohortID.Select(id => Convert.ToString(id));

                            organism = String.Join(";", cohortIds) + "\t" +
#else
                            organism = Convert.ToString(C.CohortID) + "\t" +
#endif
 Convert.ToString(C.FunctionalGroupIndex) + "\t" +
                                        Convert.ToString(C.JuvenileMass) + "\t" +
                                        Convert.ToString(C.AdultMass) + "\t" +
                                        Convert.ToString(C.IndividualBodyMass) + "\t" +
                                        Convert.ToString(C.CohortAbundance) + "\t" +
                                        Convert.ToString(C.BirthTimeStep) + "\t" +
                                        Convert.ToString(C.MaturityTimeStep) + "\t" +
                                        Convert.ToString(C.LogOptimalPreyBodySizeRatio) + "\t" +
                                        Convert.ToString(C.MaximumAchievedBodyMass) + "\t" +
                                        Convert.ToString(C.TrophicIndex) + "\t" +
                                        Convert.ToString(C.ProportionTimeActive);

                            StateWriter.WriteLine(context + organism);
                        }
                    }
                }
            }
        }
        /// <summary>
        /// Record dispersal events in the dispersal tracker
        /// </summary>
        /// <param name="inboundCohorts">The cohorts arriving in a grid cell in the current time step</param>
        /// <param name="outboundCohorts">The cohorts leaving a ce  ll in the current time step</param>
        /// <param name="outboundCohortWeights">The body masses of cohorts leaving the cell in the current time step</param>
        /// <param name="currentTimeStep">The current model time step</param>
        /// <param name="madingleyModelGrid">The model grid</param>
        public void RecordDispersal(uint[, ,] inboundCohorts, uint[, ,] outboundCohorts, List<double>[,] outboundCohortWeights, uint currentTimeStep, ModelGrid madingleyModelGrid)
        {
            // Loop through cells in the grid and write out the necessary data
            for (uint ii = 0; ii < outboundCohorts.GetLength(0); ii++)
            {
                for (uint jj = 0; jj < outboundCohorts.GetLength(1); jj++)
                {
                    double MeanOutboundCohortWeight = new double();

                    // Calculate the mean weight of outbound cohorts (ignoring abundance)
                    if (outboundCohortWeights[ii, jj].Count == 0)
                    {
                        MeanOutboundCohortWeight = 0.0;
                    }
                    else
                    {
                        MeanOutboundCohortWeight = outboundCohortWeights[ii, jj].Average();
                    }

                    // Calculate the mean weight of all cohorts (ignoring abundance)
                    List<double> TempList = new List<double>();

                    GridCellCohortHandler Temp1 = madingleyModelGrid.GetGridCellCohorts(ii, jj);

                    // Loop through functional groups
                    for (int kk = 0; kk < Temp1.Count; kk++)
                    {
                        // Loop through cohorts
                        for (int hh = 0; hh < Temp1[kk].Count;hh++)
                        {
                            // Add the cohort weight to the list
                            TempList.Add(Temp1[kk][hh].IndividualBodyMass);
                        }
                    }

                    // Calculate the mean weight
                    double MeanCohortWeight = new double();
                    if (TempList.Count == 0)
                    {
                        MeanCohortWeight = 0.0;
                    }
                    else
                    {
                        MeanCohortWeight = TempList.Average();
                    }

                    string newline = Convert.ToString(currentTimeStep) + '\t' + Convert.ToString(ii) + '\t' +
                        Convert.ToString(jj) + '\t' + Convert.ToString(madingleyModelGrid.GetCellLatitude(ii)) + '\t' +
                        Convert.ToString(madingleyModelGrid.GetCellLongitude(jj)) + '\t' +
                       Convert.ToString(outboundCohorts[ii, jj, 0]) + '\t' + Convert.ToString(outboundCohorts[ii, jj, 1]) + '\t' +
                       Convert.ToString(outboundCohorts[ii, jj, 2]) + '\t' + Convert.ToString(outboundCohorts[ii, jj, 3]) + '\t' +
                       Convert.ToString(outboundCohorts[ii, jj, 4]) + '\t' + Convert.ToString(outboundCohorts[ii, jj, 5]) + '\t' +
                       Convert.ToString(outboundCohorts[ii, jj, 6]) + '\t' + Convert.ToString(outboundCohorts[ii, jj, 7]) + '\t' +
                       Convert.ToString(inboundCohorts[ii, jj, 0]) + '\t' + Convert.ToString(inboundCohorts[ii, jj, 1]) + '\t' +
                       Convert.ToString(inboundCohorts[ii, jj, 2]) + '\t' + Convert.ToString(inboundCohorts[ii, jj, 3]) + '\t' +
                       Convert.ToString(inboundCohorts[ii, jj, 4]) + '\t' + Convert.ToString(inboundCohorts[ii, jj, 5]) + '\t' +
                       Convert.ToString(inboundCohorts[ii, jj, 6]) + '\t' + Convert.ToString(inboundCohorts[ii, jj, 7]) + '\t' +
                       Convert.ToString(String.Format("{0:.000000}", MeanOutboundCohortWeight) + '\t' +
                       Convert.ToString(String.Format("{0:.000000}", MeanCohortWeight)));

                    SyncedDispersalWriter.WriteLine(newline);
                }
            }
        }
示例#4
0
        public void OutputCurrentModelState(ModelGrid currentModelGrid, List <uint[]> cellIndices, uint currentTimestep)
        {
            GridCellCohortHandler TempCohorts;
            GridCellStockHandler  TempStocks;

            string context;
            string organism;

            context = Convert.ToString(currentTimestep) + "\t";

            using (var StateWriter = File.AppendText(this.FileName))
            {
                foreach (uint[] cell in cellIndices)
                {
                    context = Convert.ToString(currentTimestep) + "\t" +
                              Convert.ToString(currentModelGrid.GetCellLatitude(cell[0])) + "\t" +
                              Convert.ToString(currentModelGrid.GetCellLongitude(cell[1])) + "\t";

                    TempStocks  = currentModelGrid.GetGridCellStocks(cell[0], cell[1]);
                    TempCohorts = currentModelGrid.GetGridCellCohorts(cell[0], cell[1]);

                    foreach (List <Stock> ListS in TempStocks)
                    {
                        foreach (Stock S in ListS)
                        {
                            organism = "-999\tS" + Convert.ToString(S.FunctionalGroupIndex) + "\t" +
                                       "-999\t-999\t" + Convert.ToString(S.IndividualBodyMass) + "\t" +
                                       Convert.ToString(S.TotalBiomass / S.IndividualBodyMass) + "\t" +
                                       "-999\t-999\t-999\t-999\t-999\t-999";
                            StateWriter.WriteLine(context + organism);
                        }
                    }

                    foreach (List <Cohort> ListC in TempCohorts)
                    {
                        foreach (Cohort C in ListC)
                        {
#if true
                            var cohortIds = C.CohortID.Select(id => Convert.ToString(id));

                            organism = String.Join(";", cohortIds) + "\t" +
#else
                            organism = Convert.ToString(C.CohortID) + "\t" +
#endif
                                       Convert.ToString(C.FunctionalGroupIndex) + "\t" +
                                       Convert.ToString(C.JuvenileMass) + "\t" +
                                       Convert.ToString(C.AdultMass) + "\t" +
                                       Convert.ToString(C.IndividualBodyMass) + "\t" +
                                       Convert.ToString(C.CohortAbundance) + "\t" +
                                       Convert.ToString(C.BirthTimeStep) + "\t" +
                                       Convert.ToString(C.MaturityTimeStep) + "\t" +
                                       Convert.ToString(C.LogOptimalPreyBodySizeRatio) + "\t" +
                                       Convert.ToString(C.MaximumAchievedBodyMass) + "\t" +
                                       Convert.ToString(C.TrophicIndex) + "\t" +
                                       Convert.ToString(C.ProportionTimeActive);

                            StateWriter.WriteLine(context + organism);
                        }
                    }
                }
            }
        }
示例#5
0
        /// <summary>
        /// Record dispersal events in the dispersal tracker
        /// </summary>
        /// <param name="inboundCohorts">The cohorts arriving in a grid cell in the current time step</param>
        /// <param name="outboundCohorts">The cohorts leaving a ce  ll in the current time step</param>
        /// <param name="outboundCohortWeights">The body masses of cohorts leaving the cell in the current time step</param>
        /// <param name="currentTimeStep">The current model time step</param>
        /// <param name="madingleyModelGrid">The model grid</param>
        public void RecordDispersal(uint[, ,] inboundCohorts, uint[, ,] outboundCohorts, List <double>[,] outboundCohortWeights, uint currentTimeStep, ModelGrid madingleyModelGrid)
        {
            // Loop through cells in the grid and write out the necessary data
            for (uint ii = 0; ii < outboundCohorts.GetLength(0); ii++)
            {
                for (uint jj = 0; jj < outboundCohorts.GetLength(1); jj++)
                {
                    double MeanOutboundCohortWeight = new double();

                    // Calculate the mean weight of outbound cohorts (ignoring abundance)
                    if (outboundCohortWeights[ii, jj].Count == 0)
                    {
                        MeanOutboundCohortWeight = 0.0;
                    }
                    else
                    {
                        MeanOutboundCohortWeight = outboundCohortWeights[ii, jj].Average();
                    }

                    // Calculate the mean weight of all cohorts (ignoring abundance)
                    List <double> TempList = new List <double>();

                    GridCellCohortHandler Temp1 = madingleyModelGrid.GetGridCellCohorts(ii, jj);

                    // Loop through functional groups
                    for (int kk = 0; kk < Temp1.Count; kk++)
                    {
                        // Loop through cohorts
                        for (int hh = 0; hh < Temp1[kk].Count; hh++)
                        {
                            // Add the cohort weight to the list
                            TempList.Add(Temp1[kk][hh].IndividualBodyMass);
                        }
                    }

                    // Calculate the mean weight
                    double MeanCohortWeight = new double();
                    if (TempList.Count == 0)
                    {
                        MeanCohortWeight = 0.0;
                    }
                    else
                    {
                        MeanCohortWeight = TempList.Average();
                    }

                    string newline = Convert.ToString(currentTimeStep) + '\t' + Convert.ToString(ii) + '\t' +
                                     Convert.ToString(jj) + '\t' + Convert.ToString(madingleyModelGrid.GetCellLatitude(ii)) + '\t' +
                                     Convert.ToString(madingleyModelGrid.GetCellLongitude(jj)) + '\t' +
                                     Convert.ToString(outboundCohorts[ii, jj, 0]) + '\t' + Convert.ToString(outboundCohorts[ii, jj, 1]) + '\t' +
                                     Convert.ToString(outboundCohorts[ii, jj, 2]) + '\t' + Convert.ToString(outboundCohorts[ii, jj, 3]) + '\t' +
                                     Convert.ToString(outboundCohorts[ii, jj, 4]) + '\t' + Convert.ToString(outboundCohorts[ii, jj, 5]) + '\t' +
                                     Convert.ToString(outboundCohorts[ii, jj, 6]) + '\t' + Convert.ToString(outboundCohorts[ii, jj, 7]) + '\t' +
                                     Convert.ToString(inboundCohorts[ii, jj, 0]) + '\t' + Convert.ToString(inboundCohorts[ii, jj, 1]) + '\t' +
                                     Convert.ToString(inboundCohorts[ii, jj, 2]) + '\t' + Convert.ToString(inboundCohorts[ii, jj, 3]) + '\t' +
                                     Convert.ToString(inboundCohorts[ii, jj, 4]) + '\t' + Convert.ToString(inboundCohorts[ii, jj, 5]) + '\t' +
                                     Convert.ToString(inboundCohorts[ii, jj, 6]) + '\t' + Convert.ToString(inboundCohorts[ii, jj, 7]) + '\t' +
                                     Convert.ToString(String.Format("{0:.000000}", MeanOutboundCohortWeight) + '\t' +
                                                      Convert.ToString(String.Format("{0:.000000}", MeanCohortWeight)));

                    SyncedDispersalWriter.WriteLine(newline);
                }
            }
        }