Ejemplo n.º 1
0
        /// <summary>
        /// Constructor for the global output class
        /// </summary>
        /// <param name="outputDetail">The level of detail to be used in model outputs</param>
        /// <param name="modelInitialisation">Model intialisation object</param>
        public OutputGlobal(string outputDetail, MadingleyModelInitialisation modelInitialisation)
        {
            // Set the output path
            _OutputPath = modelInitialisation.OutputPath;

            // Set the output detail level
            if (outputDetail == "low")
            {
                ModelOutputDetail = OutputDetailLevel.Low;
            }
            else if (outputDetail == "medium")
            {
                ModelOutputDetail = OutputDetailLevel.Medium;
            }
            else if (outputDetail == "high")
            {
                ModelOutputDetail = OutputDetailLevel.High;
            }
            else
            {
                Debug.Fail("Specified output detail level is not valid, must be 'low', 'medium' or 'high'");
            }

            // Initialise the data converter
            DataConverter = new ArraySDSConvert();

            // Initialise the SDS object creator
            SDSCreator = new CreateSDSObject();
        }
Ejemplo n.º 2
0
        public OutputGrid(string outputDetail, MadingleyModelInitialisation modelInitialisation)
        {
            // Set the output path
            _OutputPath = modelInitialisation.OutputPath;

            // Initialise the grid viewer
            GridViewer = new ViewGrid();

            // Set the output detail level
            if (outputDetail == "low")
            {
                ModelOutputDetail = OutputDetailLevel.Low;
            }
            else if (outputDetail == "medium")
            {
                ModelOutputDetail = OutputDetailLevel.Medium;
            }
            else if (outputDetail == "high")
            {
                ModelOutputDetail = OutputDetailLevel.High;
            }
            else
            {
                Debug.Fail("Specified output detail level is not valid, must be 'low', 'medium' or 'high'");
            }


            // Get whether to track marine specifics
            OutputMetrics = modelInitialisation.OutputMetrics;

            //Initialise the EcosystemMetrics class
            Metrics = new EcosytemMetrics();

            // Initialise the data converter
            DataConverter = new ArraySDSConvert();

            // Initialise the SDS object creator
            SDSCreator = new CreateSDSObject();

            // Set the local variable designating whether to display live outputs during this model run
            if (modelInitialisation.LiveOutputs)
            {
                LiveOutputs = true;
            }

            Utils = new UtilityFunctions();
        }
        public OutputModelState(MadingleyModelInitialisation modelInitialisation, string suffix, int simulation)
        {
            //Initialise output path and variables
            // Set the output path
            _OutputPath = modelInitialisation.OutputPath;

            // Initialise the data converter
            DataConverter = new ArraySDSConvert();

            // Initialise the SDS object creator
            SDSCreator = new CreateSDSObject();

            StateWriter = new StreamWriter(_OutputPath + "State" + suffix + simulation.ToString() + ".txt");
            // Create a threadsafe textwriter to write outputs to the Maturity stream
            SyncStateWriter = TextWriter.Synchronized(StateWriter);
            SyncStateWriter.WriteLine("TimeStep\tLatitude\tLongitude\tID" +
                                      "\tFunctionalGroup\tJuvenileMass\tAdultMass\tIndividualBodyMass\tCohortAbundance\tReproductiveMass\tBirthTimeStep" +
                                      "\tMaturityTimeStep\tLogOptimalPreyBodySizeRatio\tMaximumAchievedBodyMass\tTrophicIndex\tProportionTimeActive");

            Simulation = simulation;
        }
        public OutputModelState(MadingleyModelInitialisation modelInitialisation, string suffix, int simulation)
        {
            //Initialise output path and variables
            // Set the output path
            _OutputPath = modelInitialisation.OutputPath;

            // Initialise the data converter
            DataConverter = new ArraySDSConvert();

            // Initialise the SDS object creator
            SDSCreator = new CreateSDSObject();

            StateWriter = new StreamWriter(_OutputPath + "State" + suffix + simulation.ToString() + ".txt");
            // Create a threadsafe textwriter to write outputs to the Maturity stream
            SyncStateWriter = TextWriter.Synchronized(StateWriter);
            SyncStateWriter.WriteLine("TimeStep\tLatitude\tLongitude\tID" +
            "\tFunctionalGroup\tJuvenileMass\tAdultMass\tIndividualBodyMass\tCohortAbundance\tBirthTimeStep" +
                "\tMaturityTimeStep\tLogOptimalPreyBodySizeRatio\tMaximumAchievedBodyMass\tTrophicIndex\tProportionTimeActive");

            Simulation = simulation;
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Set up the predation tracker
        /// </summary>_
        /// <param name="numTimeSteps">The total number of timesteps for this simulation</param>
        /// <param name="cellIndices">List of indices of active cells in the model grid</param>
        /// <param name="massFlowsFilename">Filename for outputs of the flows of mass between predators and prey</param>
        /// <param name="cohortDefinitions">The functional group definitions for cohorts in the model</param>
        /// <param name="missingValue">The missing value to be used in the output file</param>
        /// <param name="outputFileSuffix">The suffix to be applied to the output file</param>
        /// <param name="outputPath">The path to write the output file to</param>
        /// <param name="trackerMassBins">The mass bin handler containing the mass bins to be used for predation tracking</param>
        /// <param name="cellIndex">The index of the current cell in the list of all cells to run the model for</param>
        public PredationTracker(uint numTimeSteps,
                                List <uint[]> cellIndices,
                                string massFlowsFilename,
                                FunctionalGroupDefinitions cohortDefinitions,
                                double missingValue,
                                string outputFileSuffix,
                                string outputPath, MassBinsHandler trackerMassBins, int cellIndex)
        {
            // Assign the missing value
            _MissingValue = missingValue;

            // Get the mass bins to use for the predation tracker and the number of mass bins that this correpsonds to
            _MassBins    = trackerMassBins.GetSpecifiedMassBins();
            _NumMassBins = trackerMassBins.NumMassBins;

            // Initialise the array to hold data on mass flows between mass bins
            _MassFlows = new double[_NumMassBins, _NumMassBins];

            // Define the model time steps to be used in the output file
            float[] TimeSteps = new float[numTimeSteps];
            for (int i = 1; i <= numTimeSteps; i++)
            {
                TimeSteps[i - 1] = i;
            }

            // Initialise the data converter
            DataConverter = new ArraySDSConvert();

            // Initialise the SDS object creator
            SDSCreator = new CreateSDSObject();

            // Create an SDS object to hold the predation tracker data
            MassFlowsDataSet = SDSCreator.CreateSDS("netCDF", massFlowsFilename + outputFileSuffix + "_Cell" + cellIndex, outputPath);

            // Define the dimensions to be used in the predation tracker output file
            string[] dimensions = { "Predator mass bin", "Prey mass bin", "Time steps" };

            // Add the mass flow variable to the predation tracker
            DataConverter.AddVariable(MassFlowsDataSet, "Log mass (g)", 3, dimensions, _MissingValue, _MassBins, _MassBins, TimeSteps);
        }
Ejemplo n.º 6
0
        public OutputModelState(MadingleyModelInitialisation modelInitialisation, string suffix, int simulation)
        {
            //Initialise output path and variables
            // Set the output path
            _OutputPath = modelInitialisation.OutputPath;

            // Initialise the data converter
            DataConverter = new ArraySDSConvert();

            // Initialise the SDS object creator
            SDSCreator = new CreateSDSObject();

            this.FileName = _OutputPath + "State" + suffix + simulation.ToString() + ".txt";

            using (var StateWriter = new StreamWriter(this.FileName))
            {
                StateWriter.WriteLine("TimeStep\tLatitude\tLongitude\tID" +
                                      "\tFunctionalGroup\tJuvenileMass\tAdultMass\tIndividualBodyMass\tCohortAbundance\tBirthTimeStep" +
                                      "\tMaturityTimeStep\tLogOptimalPreyBodySizeRatio\tMaximumAchievedBodyMass\tTrophicIndex\tProportionTimeActive");
            }

            Simulation = simulation;
        }
        /// <summary>
        /// Constructor for the cell output class
        /// </summary>
        /// <param name="outputDetail">The level of detail to include in the ouputs: 'low', 'medium' or 'high'</param>
        /// <param name="modelInitialisation">Model initialisation object</param>
        /// <param name="cellIndex">The index of the current cell in the list of all cells to run the model for</param>
        public OutputCell(string outputDetail, MadingleyModelInitialisation modelInitialisation, 
            int cellIndex)
        {
            // Set the output path
            _OutputPath = modelInitialisation.OutputPath;

            // Set the initial maximum value for the y-axis of the live display
            MaximumYValue = 1000000;

            // Set the local copy of the mass bin handler from the model initialisation
            _MassBinHandler = modelInitialisation.ModelMassBins;

            // Get the number of mass bins to be used
            MassBinNumber = _MassBinHandler.NumMassBins;

            // Get the specified mass bins
            MassBins = modelInitialisation.ModelMassBins.GetSpecifiedMassBins();

            // Set the output detail level
            if (outputDetail == "low")
                ModelOutputDetail = OutputDetailLevel.Low;
            else if (outputDetail == "medium")
                ModelOutputDetail = OutputDetailLevel.Medium;
            else if (outputDetail == "high")
                ModelOutputDetail = OutputDetailLevel.High;
            else
                Debug.Fail("Specified output detail level is not valid, must be 'low', 'medium' or 'high'");

            // Get whether to track marine specifics
            TrackMarineSpecifics = modelInitialisation.TrackMarineSpecifics;

            // Get whether to track marine specifics
            OutputMetrics = modelInitialisation.OutputMetrics;

            //Initialise the EcosystemMetrics class
            Metrics = new EcosytemMetrics();

            // Initialise the data converter
            DataConverter = new ArraySDSConvert();

            // Initialise the SDS object creator
            SDSCreator = new CreateSDSObject();

            // Initialise the grid viewer
            GridViewer = new ViewGrid();

            // Set the local variable designating whether to display live outputs
            if (modelInitialisation.LiveOutputs)
                LiveOutputs = true;
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Constructor for the global NPP tracker: sets up the output file and the data arrays
        /// </summary>
        /// <param name="outputPath">Path to the file to output NPP data to</param>
        /// <param name="numLats">The number of cells latitudinally in the NPP output grid</param>
        /// <param name="numLons">The number of cells longitudinally in the NPP output grid</param>
        /// <param name="lats">The latitudes of cells in the grid to output</param>
        /// <param name="lons">The longitudes of cells in the grid to output</param>
        /// <param name="latCellSize">The latitudinal cell size of the grid to output</param>
        /// <param name="lonCellSize">The longitudinal cell size of the grid to output</param>
        /// <param name="numTimeSteps">The number of time steps to output NPP data for</param>
        public GlobalNPPTracker(string outputPath, int numLats, int numLons, float[] lats, float[] lons, float latCellSize, float lonCellSize,
                                int numTimeSteps, int numStocks)
        {
            _NumLats = numLats;
            _NumLons = numLons;

            // Initialise the data converter
            DataConverter = new ArraySDSConvert();

            // Initialise the SDS object creator
            SDSCreator = new CreateSDSObject();

            // Create an SDS object to hold NPP data
            NPPOutput = SDSCreator.CreateSDS("netCDF", "NPPOutput", outputPath);
            // Create an SDS object to hold total abundance and biomass data
            HANPPOutput = SDSCreator.CreateSDS("netCDF", "HANPPOutput", outputPath);

            // Create vector to hold the values of the time dimension
            float[] TimeSteps = new float[numTimeSteps];

            // Fill other values from 0 (this will hold outputs during the model run)
            for (int i = 0; i < numTimeSteps; i++)
            {
                TimeSteps[i] = i;
            }

            // Declare vectors for geographical dimension data
            float[] outLats = new float[numLats];
            float[] outLons = new float[numLons];

            // Populate the dimension variable vectors with cell centre latitude and longitudes
            for (int i = 0; i < numLats; i++)
            {
                outLats[i] = lats[i] + (latCellSize / 2);
            }

            for (int jj = 0; jj < numLons; jj++)
            {
                outLons[jj] = lons[jj] + (lonCellSize / 2);
            }

            // Add output variables that are dimensioned geographically and temporally to grid output file
            string[] GeographicalDimensions = { "Latitude", "Longitude", "Time step" };
            for (int ii = 0; ii < numStocks; ii++)
            {
                DataConverter.AddVariable(NPPOutput, "NPP_" + ii.ToString(), 3, GeographicalDimensions, -9999.0, outLats, outLons, TimeSteps);
                DataConverter.AddVariable(HANPPOutput, "HANPP_" + ii.ToString(), 3, GeographicalDimensions, -9999.0, outLats, outLons, TimeSteps);
            }

            NPP   = new double[numLats, numLons, numStocks];
            HANPP = new double[numLats, numLons, numStocks];

            for (int ii = 0; ii < numLats; ii++)
            {
                for (int jj = 0; jj < numLons; jj++)
                {
                    for (int kk = 0; kk < numStocks; kk++)
                    {
                        NPP[ii, jj, kk]   = -9999.0;
                        HANPP[ii, jj, kk] = -9999.0;
                    }
                }
            }

            this.FileName = outputPath + "NPPOutput.nc";
        }
Ejemplo n.º 9
0
 /// <summary>
 /// Constructor for the grid viewer: initialses relevant objects
 /// </summary>
 public ViewGrid()
 {
     DataConverter = new ArraySDSConvert();
 }
Ejemplo n.º 10
0
        /// <summary>
        /// Constructor for the global output class
        /// </summary>
        /// <param name="outputDetail">The level of detail to be used in model outputs</param>
        /// <param name="modelInitialisation">Model intialisation object</param>
        public OutputGlobal(string outputDetail, MadingleyModelInitialisation modelInitialisation)
        {
            // Set the output path
            _OutputPath = modelInitialisation.OutputPath;

            // Set the output detail level
            if (outputDetail == "low")
                ModelOutputDetail = OutputDetailLevel.Low;
            else if (outputDetail == "medium")
                ModelOutputDetail = OutputDetailLevel.Medium;
            else if (outputDetail == "high")
                ModelOutputDetail = OutputDetailLevel.High;
            else
                Debug.Fail("Specified output detail level is not valid, must be 'low', 'medium' or 'high'");

            // Initialise the data converter
            DataConverter = new ArraySDSConvert();

            // Initialise the SDS object creator
            SDSCreator = new CreateSDSObject();

        }
        /// <summary>
        /// Set up the predation tracker
        /// </summary>_
        /// <param name="numTimeSteps">The total number of timesteps for this simulation</param>
        /// <param name="cellIndices">List of indices of active cells in the model grid</param>
        /// <param name="massFlowsFilename">Filename for outputs of the flows of mass between predators and prey</param>
        /// <param name="cohortDefinitions">The functional group definitions for cohorts in the model</param>
        /// <param name="missingValue">The missing value to be used in the output file</param>
        /// <param name="outputFileSuffix">The suffix to be applied to the output file</param>
        /// <param name="outputPath">The path to write the output file to</param>
        /// <param name="trackerMassBins">The mass bin handler containing the mass bins to be used for predation tracking</param>
        /// <param name="cellIndex">The index of the current cell in the list of all cells to run the model for</param>
        public PredationTracker(uint numTimeSteps,
            List<uint[]> cellIndices,
            string massFlowsFilename,
            FunctionalGroupDefinitions cohortDefinitions,
            double missingValue,
            string outputFileSuffix,
            string outputPath, MassBinsHandler trackerMassBins, int cellIndex)
        {
            // Assign the missing value
            _MissingValue = missingValue;

            // Get the mass bins to use for the predation tracker and the number of mass bins that this correpsonds to
            _MassBins = trackerMassBins.GetSpecifiedMassBins();
            _NumMassBins = trackerMassBins.NumMassBins;

            // Initialise the array to hold data on mass flows between mass bins
            _MassFlows = new double[_NumMassBins, _NumMassBins];

            // Define the model time steps to be used in the output file
            float[] TimeSteps = new float[numTimeSteps];
            for (int i = 1; i <= numTimeSteps; i++)
            {
                TimeSteps[i - 1] = i;
            }

            // Initialise the data converter
            DataConverter = new ArraySDSConvert();

            // Initialise the SDS object creator
            SDSCreator = new CreateSDSObject();

            // Create an SDS object to hold the predation tracker data
            MassFlowsDataSet = SDSCreator.CreateSDS("netCDF", massFlowsFilename + outputFileSuffix + "_Cell" + cellIndex, outputPath);

            // Define the dimensions to be used in the predation tracker output file
            string[] dimensions = { "Predator mass bin", "Prey mass bin", "Time steps" };

            // Add the mass flow variable to the predation tracker
            DataConverter.AddVariable(MassFlowsDataSet, "Log mass (g)", 3, dimensions, _MissingValue, _MassBins, _MassBins, TimeSteps);
        }
        /// <summary>
        /// Constructor for the global NPP tracker: sets up the output file and the data arrays
        /// </summary>
        /// <param name="outputPath">Path to the file to output NPP data to</param>
        /// <param name="numLats">The number of cells latitudinally in the NPP output grid</param>
        /// <param name="numLons">The number of cells longitudinally in the NPP output grid</param>
        /// <param name="lats">The latitudes of cells in the grid to output</param>
        /// <param name="lons">The longitudes of cells in the grid to output</param>
        /// <param name="latCellSize">The latitudinal cell size of the grid to output</param>
        /// <param name="lonCellSize">The longitudinal cell size of the grid to output</param>
        /// <param name="numTimeSteps">The number of time steps to output NPP data for</param>
        public GlobalNPPTracker(string outputPath, int numLats, int numLons, float[] lats, float[] lons, float latCellSize, float lonCellSize,
            int numTimeSteps, int numStocks)
        {
            _NumLats = numLats;
            _NumLons = numLons;

            // Initialise the data converter
            DataConverter = new ArraySDSConvert();

            // Initialise the SDS object creator
            SDSCreator = new CreateSDSObject();

            // Create an SDS object to hold NPP data
            NPPOutput = SDSCreator.CreateSDS("netCDF", "NPPOutput", outputPath);
            // Create an SDS object to hold total abundance and biomass data
            HANPPOutput = SDSCreator.CreateSDS("netCDF", "HANPPOutput", outputPath);

            // Create vector to hold the values of the time dimension
            float[] TimeSteps = new float[numTimeSteps];

            // Fill other values from 0 (this will hold outputs during the model run)
            for (int i = 0; i < numTimeSteps; i++)
            {
                TimeSteps[i] = i;
            }

            // Declare vectors for geographical dimension data
            float[] outLats = new float[numLats];
            float[] outLons = new float[numLons];

            // Populate the dimension variable vectors with cell centre latitude and longitudes
            for (int i = 0; i < numLats; i++)
            {
                outLats[i] = lats[i] + (latCellSize / 2);
            }

            for (int jj = 0; jj < numLons; jj++)
            {
                outLons[jj] = lons[jj] + (lonCellSize / 2);
            }

            // Add output variables that are dimensioned geographically and temporally to grid output file
            string[] GeographicalDimensions = { "Latitude", "Longitude", "Time step" };
            for (int ii = 0; ii < numStocks; ii++)
            {
                DataConverter.AddVariable(NPPOutput, "NPP_" + ii.ToString(), 3, GeographicalDimensions, -9999.0, outLats, outLons, TimeSteps);
                DataConverter.AddVariable(HANPPOutput, "HANPP_" + ii.ToString(), 3, GeographicalDimensions, -9999.0, outLats, outLons, TimeSteps);
            }

            NPP = new double[numLats, numLons, numStocks];
            HANPP = new double[numLats, numLons, numStocks];

            for (int ii = 0; ii < numLats; ii++)
            {
                for (int jj = 0; jj < numLons; jj++)
                {
                    for (int kk = 0; kk < numStocks; kk++)
                    {
                        NPP[ii, jj, kk] = -9999.0;
                        HANPP[ii, jj, kk] = -9999.0;
                    }
                }

            }

            this.FileName = outputPath + "NPPOutput.nc";
        }
        public OutputGrid(string outputDetail, MadingleyModelInitialisation modelInitialisation)
        {
            // Set the output path
            _OutputPath = modelInitialisation.OutputPath;

            // Initialise the grid viewer
            GridViewer = new ViewGrid();

            // Set the output detail level
            if (outputDetail == "low")
                ModelOutputDetail = OutputDetailLevel.Low;
            else if (outputDetail == "medium")
                ModelOutputDetail = OutputDetailLevel.Medium;
            else if (outputDetail == "high")
                ModelOutputDetail = OutputDetailLevel.High;
            else
                Debug.Fail("Specified output detail level is not valid, must be 'low', 'medium' or 'high'");

            // Get whether to track marine specifics
            OutputMetrics = modelInitialisation.OutputMetrics;

            //Initialise the EcosystemMetrics class
            Metrics = new EcosytemMetrics();

            // Initialise the data converter
            DataConverter = new ArraySDSConvert();

            // Initialise the SDS object creator
            SDSCreator = new CreateSDSObject();

            // Set the local variable designating whether to display live outputs during this model run
            if (modelInitialisation.LiveOutputs)
                LiveOutputs = true;
        }
        public void WriteFeedingInteractions(uint timestep)
        {
            int nrows = FeedingInteractionsMatrixPredation.GetLength(0);
            int ncols = FeedingInteractionsMatrixPredation.GetLength(1);

            int MaxLengthPredation = 0;

            for (int i = 0; i < nrows; i++)
            {
                for (int j = 0; j < ncols; j++)
                {
                    if (FeedingInteractionsMatrixPredation[i, j].Count > MaxLengthPredation) MaxLengthPredation = FeedingInteractionsMatrixPredation[i, j].Count;
                }
            }

            double[, ,] FGIndicesPredation = new double[nrows, ncols, MaxLengthPredation];
            double[, ,] FGIndicesHerbivory = new double[nrows, ncols, 2];

            double[, ,] CIndicesPredation = new double[nrows, ncols, MaxLengthPredation];
            double[, ,] CIndicesHerbivory = new double[nrows, ncols, 2];

            double[, ,] BiomassAssimilatedPredation = new double[nrows, ncols, MaxLengthPredation];
            double[, ,] BiomassAssimilatedHerbivory = new double[nrows, ncols, 2];

            double[, ,] BiomassIngestedPredation = new double[nrows, ncols, MaxLengthPredation];
            double[, ,] BiomassIngestedHerbivory = new double[nrows, ncols, 2];

            float[] FGIndices = new float[nrows];
            float[] CIndices = new float[ncols];
            float[] PredationIndices = new float[MaxLengthPredation];
            float[] HerbivoryIndices = new float[2] {0,1};

            for (int i = 0; i < nrows; i++)
            {
                FGIndices[i] = i;
            }

            for (int i = 0; i < ncols; i++)
            {
                CIndices[i] = i;
            }

            for (int i = 0; i < MaxLengthPredation; i++)
            {
                PredationIndices[i] = i;
            }

            for (int f = 0; f < nrows; f++)
            {
                for (int c = 0; c < ncols; c++)
                {

                    //Populate output data matrices for predation feeding events
                    for (int i = 0; i < FeedingInteractionsMatrixPredation[f, c].Count; i++)
                    {
                        FGIndicesPredation[f, c, i] = Convert.ToDouble(FeedingInteractionsMatrixPredation[f, c].ElementAt(i).Item1);
                        CIndicesPredation[f, c, i] = Convert.ToDouble(FeedingInteractionsMatrixPredation[f, c].ElementAt(i).Item2);
                        BiomassAssimilatedPredation[f, c, i] = (FeedingInteractionsMatrixPredation[f, c].ElementAt(i).Item3);
                        BiomassIngestedPredation[f, c, i] = (FeedingInteractionsMatrixPredation[f, c].ElementAt(i).Item4);
                    }

                    //Populate output data matrices for herbivory feeding events
                    for (int i = 0; i < FeedingInteractionsMatrixHerbivory[f,c].Count; i++)
                    {
                        FGIndicesHerbivory[f, c, i] = Convert.ToDouble(FeedingInteractionsMatrixHerbivory[f, c].ElementAt(i).Item1);
                        CIndicesHerbivory[f, c, i] = Convert.ToDouble(FeedingInteractionsMatrixHerbivory[f, c].ElementAt(i).Item2);
                        BiomassAssimilatedHerbivory[f, c, i] = (FeedingInteractionsMatrixHerbivory[f, c].ElementAt(i).Item3);
                        BiomassIngestedHerbivory[f, c, i] = (FeedingInteractionsMatrixHerbivory[f, c].ElementAt(i).Item4);

                    }
                }
            }

            // Initialise the data converter
            DataConverter = new ArraySDSConvert();

            // Initialise the SDS object creator
            SDSCreator = new CreateSDSObject();

            // Create an SDS object to hold the predation tracker data
            _FeedingInteractionsDS = SDSCreator.CreateSDS("netCDF", _Filename + _OutputFileSuffix + timestep, _OutputPath);

            string[] PredationDimensions = new string[3] {"Functional Group Indices","Cohort Indices","Predation Interaction Dimension"};
            string[] HerbivoryDimensions = new string[3] { "Functional Group Indices", "Cohort Indices", "Herbivory Interaction Dimension" };

            string[] PredD1 = new string [1] { PredationDimensions[0] };
            string[] PredD2 = new string[1] { PredationDimensions[1] };
            string[] PredD3 = new string[1] { PredationDimensions[2] };
            string[] HerbD3 = new string[1] { HerbivoryDimensions[2] };

            DataConverter.AddVariable(_FeedingInteractionsDS, PredationDimensions[0], "index", 1, PredD1, _MV, FGIndices);
            DataConverter.AddVariable(_FeedingInteractionsDS, PredationDimensions[1], "index", 1, PredD2, _MV, CIndices);
            DataConverter.AddVariable(_FeedingInteractionsDS, PredationDimensions[2], "index", 1, PredD3, _MV, PredationIndices);
            DataConverter.AddVariable(_FeedingInteractionsDS, HerbivoryDimensions[2], "index", 1, HerbD3, _MV, HerbivoryIndices);

            /*DataConverter.AddVariable(_FeedingInteractionsDS, "Predation Interactions Functional Groups", 3, PredationDimensions, _MV, FGIndices, CIndices, PredationIndices);
            DataConverter.AddVariable(_FeedingInteractionsDS, "Predation Interactions Cohort Index", 3, PredationDimensions, _MV, FGIndices, CIndices, PredationIndices);
            DataConverter.AddVariable(_FeedingInteractionsDS, "Predation Interactions Biomass Assimilated", 3, PredationDimensions, _MV, FGIndices, CIndices, PredationIndices);
            DataConverter.AddVariable(_FeedingInteractionsDS, "Predation Interactions Biomass Ingested", 3, PredationDimensions, _MV, FGIndices, CIndices, PredationIndices);

            DataConverter.AddVariable(_FeedingInteractionsDS, "Herbivory Interactions Functional Groups", 3, HerbivoryDimensions, _MV, FGIndices, CIndices, HerbivoryIndices);
            DataConverter.AddVariable(_FeedingInteractionsDS, "Herbivory Interactions Stock Index", 3, HerbivoryDimensions, _MV, FGIndices, CIndices, HerbivoryIndices);
            DataConverter.AddVariable(_FeedingInteractionsDS, "Herbivory Interactions Biomass Assimilated", 3, HerbivoryDimensions, _MV, FGIndices, CIndices, HerbivoryIndices);
            DataConverter.AddVariable(_FeedingInteractionsDS, "Herbivory Interactions Biomass Ingested", 3, HerbivoryDimensions, _MV, FGIndices, CIndices, HerbivoryIndices);*/

            //Add variable to SDS
            var FGIPredOut = _FeedingInteractionsDS.AddVariable<double>("Predation Interactions Functional Groups", FGIndicesPredation, PredationDimensions);
            FGIPredOut.Metadata["DisplayName"] = "Predation Interactions Functional Groups";
            FGIPredOut.Metadata["MissingValue"] = _MV;

            //Add variable to SDS
            var CIPredOut = _FeedingInteractionsDS.AddVariable<double>("Predation Interactions Cohort Index", CIndicesPredation, PredationDimensions);
            CIPredOut.Metadata["DisplayName"] = "Predation Interactions Cohort Index";
            CIPredOut.Metadata["MissingValue"] = _MV;

            //Add variable to SDS
            var BAPredOut = _FeedingInteractionsDS.AddVariable<double>("Predation Interactions Biomass Assimilated", BiomassAssimilatedPredation, PredationDimensions);
            BAPredOut.Metadata["DisplayName"] = "Predation Interactions Biomass Assimilated";
            BAPredOut.Metadata["MissingValue"] = _MV;

            //Add variable to SDS
            var BIPredOut = _FeedingInteractionsDS.AddVariable<double>("Predation Interactions Biomass Ingested", BiomassIngestedPredation, PredationDimensions);
            BIPredOut.Metadata["DisplayName"] = "Predation Interactions Biomass Ingested";
            BIPredOut.Metadata["MissingValue"] = _MV;

            //Add variable to SDS
            var FGIHerbOut = _FeedingInteractionsDS.AddVariable<double>("Herbivory Interactions Functional Groups", FGIndicesHerbivory, HerbivoryDimensions);
            FGIHerbOut.Metadata["DisplayName"] = "Herbivory Interactions Functional Groups";
            FGIHerbOut.Metadata["MissingValue"] = _MV;

            //Add variable to SDS
            var CIHerbOut = _FeedingInteractionsDS.AddVariable<double>("Herbivory Interactions Cohort Index", CIndicesHerbivory, HerbivoryDimensions);
            CIHerbOut.Metadata["DisplayName"] = "Herbivory Interactions Cohort Index";
            CIHerbOut.Metadata["MissingValue"] = _MV;

            //Add variable to SDS
            var BAHerbOut = _FeedingInteractionsDS.AddVariable<double>("Herbivory Interactions Biomass Assimilated", BiomassAssimilatedHerbivory, HerbivoryDimensions);
            BAHerbOut.Metadata["DisplayName"] = "Herbivory Interactions Biomass Assimilated";
            BAHerbOut.Metadata["MissingValue"] = _MV;

            //Add variable to SDS
            var BIHerbOut = _FeedingInteractionsDS.AddVariable<double>("Herbivory Interactions Biomass Ingested", BiomassIngestedHerbivory, HerbivoryDimensions);
            BIHerbOut.Metadata["DisplayName"] = "Herbivory Interactions Biomass Ingested";
            BIHerbOut.Metadata["MissingValue"] = _MV;

            //Commit changes
            _FeedingInteractionsDS.Commit();
        }
Ejemplo n.º 15
0
 /// <summary>
 /// Constructor for the grid viewer: initialses relevant objects
 /// </summary>
 public ViewGrid()
 {
     DataConverter = new ArraySDSConvert();
 }
        public void WriteFeedingInteractions(uint timestep)
        {
            int nrows = FeedingInteractionsMatrixPredation.GetLength(0);
            int ncols = FeedingInteractionsMatrixPredation.GetLength(1);

            int MaxLengthPredation = 0;

            for (int i = 0; i < nrows; i++)
            {
                for (int j = 0; j < ncols; j++)
                {
                    if (FeedingInteractionsMatrixPredation[i, j].Count > MaxLengthPredation)
                    {
                        MaxLengthPredation = FeedingInteractionsMatrixPredation[i, j].Count;
                    }
                }
            }

            double[, ,] FGIndicesPredation = new double[nrows, ncols, MaxLengthPredation];
            double[, ,] FGIndicesHerbivory = new double[nrows, ncols, 2];

            double[, ,] CIndicesPredation = new double[nrows, ncols, MaxLengthPredation];
            double[, ,] CIndicesHerbivory = new double[nrows, ncols, 2];

            double[, ,] BiomassAssimilatedPredation = new double[nrows, ncols, MaxLengthPredation];
            double[, ,] BiomassAssimilatedHerbivory = new double[nrows, ncols, 2];

            double[, ,] BiomassIngestedPredation = new double[nrows, ncols, MaxLengthPredation];
            double[, ,] BiomassIngestedHerbivory = new double[nrows, ncols, 2];


            float[] FGIndices        = new float[nrows];
            float[] CIndices         = new float[ncols];
            float[] PredationIndices = new float[MaxLengthPredation];
            float[] HerbivoryIndices = new float[2] {
                0, 1
            };

            for (int i = 0; i < nrows; i++)
            {
                FGIndices[i] = i;
            }

            for (int i = 0; i < ncols; i++)
            {
                CIndices[i] = i;
            }

            for (int i = 0; i < MaxLengthPredation; i++)
            {
                PredationIndices[i] = i;
            }

            for (int f = 0; f < nrows; f++)
            {
                for (int c = 0; c < ncols; c++)
                {
                    //Populate output data matrices for predation feeding events
                    for (int i = 0; i < FeedingInteractionsMatrixPredation[f, c].Count; i++)
                    {
                        FGIndicesPredation[f, c, i]          = Convert.ToDouble(FeedingInteractionsMatrixPredation[f, c].ElementAt(i).Item1);
                        CIndicesPredation[f, c, i]           = Convert.ToDouble(FeedingInteractionsMatrixPredation[f, c].ElementAt(i).Item2);
                        BiomassAssimilatedPredation[f, c, i] = (FeedingInteractionsMatrixPredation[f, c].ElementAt(i).Item3);
                        BiomassIngestedPredation[f, c, i]    = (FeedingInteractionsMatrixPredation[f, c].ElementAt(i).Item4);
                    }

                    //Populate output data matrices for herbivory feeding events
                    for (int i = 0; i < FeedingInteractionsMatrixHerbivory[f, c].Count; i++)
                    {
                        FGIndicesHerbivory[f, c, i]          = Convert.ToDouble(FeedingInteractionsMatrixHerbivory[f, c].ElementAt(i).Item1);
                        CIndicesHerbivory[f, c, i]           = Convert.ToDouble(FeedingInteractionsMatrixHerbivory[f, c].ElementAt(i).Item2);
                        BiomassAssimilatedHerbivory[f, c, i] = (FeedingInteractionsMatrixHerbivory[f, c].ElementAt(i).Item3);
                        BiomassIngestedHerbivory[f, c, i]    = (FeedingInteractionsMatrixHerbivory[f, c].ElementAt(i).Item4);
                    }
                }
            }



            // Initialise the data converter
            DataConverter = new ArraySDSConvert();

            // Initialise the SDS object creator
            SDSCreator = new CreateSDSObject();

            // Create an SDS object to hold the predation tracker data
            _FeedingInteractionsDS = SDSCreator.CreateSDS("netCDF", _Filename + _OutputFileSuffix + timestep, _OutputPath);

            string[] PredationDimensions = new string[3] {
                "Functional Group Indices", "Cohort Indices", "Predation Interaction Dimension"
            };
            string[] HerbivoryDimensions = new string[3] {
                "Functional Group Indices", "Cohort Indices", "Herbivory Interaction Dimension"
            };

            string[] PredD1 = new string [1] {
                PredationDimensions[0]
            };
            string[] PredD2 = new string[1] {
                PredationDimensions[1]
            };
            string[] PredD3 = new string[1] {
                PredationDimensions[2]
            };
            string[] HerbD3 = new string[1] {
                HerbivoryDimensions[2]
            };

            DataConverter.AddVariable(_FeedingInteractionsDS, PredationDimensions[0], "index", 1, PredD1, _MV, FGIndices);
            DataConverter.AddVariable(_FeedingInteractionsDS, PredationDimensions[1], "index", 1, PredD2, _MV, CIndices);
            DataConverter.AddVariable(_FeedingInteractionsDS, PredationDimensions[2], "index", 1, PredD3, _MV, PredationIndices);
            DataConverter.AddVariable(_FeedingInteractionsDS, HerbivoryDimensions[2], "index", 1, HerbD3, _MV, HerbivoryIndices);

            /*DataConverter.AddVariable(_FeedingInteractionsDS, "Predation Interactions Functional Groups", 3, PredationDimensions, _MV, FGIndices, CIndices, PredationIndices);
             * DataConverter.AddVariable(_FeedingInteractionsDS, "Predation Interactions Cohort Index", 3, PredationDimensions, _MV, FGIndices, CIndices, PredationIndices);
             * DataConverter.AddVariable(_FeedingInteractionsDS, "Predation Interactions Biomass Assimilated", 3, PredationDimensions, _MV, FGIndices, CIndices, PredationIndices);
             * DataConverter.AddVariable(_FeedingInteractionsDS, "Predation Interactions Biomass Ingested", 3, PredationDimensions, _MV, FGIndices, CIndices, PredationIndices);
             *
             * DataConverter.AddVariable(_FeedingInteractionsDS, "Herbivory Interactions Functional Groups", 3, HerbivoryDimensions, _MV, FGIndices, CIndices, HerbivoryIndices);
             * DataConverter.AddVariable(_FeedingInteractionsDS, "Herbivory Interactions Stock Index", 3, HerbivoryDimensions, _MV, FGIndices, CIndices, HerbivoryIndices);
             * DataConverter.AddVariable(_FeedingInteractionsDS, "Herbivory Interactions Biomass Assimilated", 3, HerbivoryDimensions, _MV, FGIndices, CIndices, HerbivoryIndices);
             * DataConverter.AddVariable(_FeedingInteractionsDS, "Herbivory Interactions Biomass Ingested", 3, HerbivoryDimensions, _MV, FGIndices, CIndices, HerbivoryIndices);*/

            //Add variable to SDS
            var FGIPredOut = _FeedingInteractionsDS.AddVariable <double>("Predation Interactions Functional Groups", FGIndicesPredation, PredationDimensions);

            FGIPredOut.Metadata["DisplayName"]  = "Predation Interactions Functional Groups";
            FGIPredOut.Metadata["MissingValue"] = _MV;

            //Add variable to SDS
            var CIPredOut = _FeedingInteractionsDS.AddVariable <double>("Predation Interactions Cohort Index", CIndicesPredation, PredationDimensions);

            CIPredOut.Metadata["DisplayName"]  = "Predation Interactions Cohort Index";
            CIPredOut.Metadata["MissingValue"] = _MV;

            //Add variable to SDS
            var BAPredOut = _FeedingInteractionsDS.AddVariable <double>("Predation Interactions Biomass Assimilated", BiomassAssimilatedPredation, PredationDimensions);

            BAPredOut.Metadata["DisplayName"]  = "Predation Interactions Biomass Assimilated";
            BAPredOut.Metadata["MissingValue"] = _MV;

            //Add variable to SDS
            var BIPredOut = _FeedingInteractionsDS.AddVariable <double>("Predation Interactions Biomass Ingested", BiomassIngestedPredation, PredationDimensions);

            BIPredOut.Metadata["DisplayName"]  = "Predation Interactions Biomass Ingested";
            BIPredOut.Metadata["MissingValue"] = _MV;


            //Add variable to SDS
            var FGIHerbOut = _FeedingInteractionsDS.AddVariable <double>("Herbivory Interactions Functional Groups", FGIndicesHerbivory, HerbivoryDimensions);

            FGIHerbOut.Metadata["DisplayName"]  = "Herbivory Interactions Functional Groups";
            FGIHerbOut.Metadata["MissingValue"] = _MV;

            //Add variable to SDS
            var CIHerbOut = _FeedingInteractionsDS.AddVariable <double>("Herbivory Interactions Cohort Index", CIndicesHerbivory, HerbivoryDimensions);

            CIHerbOut.Metadata["DisplayName"]  = "Herbivory Interactions Cohort Index";
            CIHerbOut.Metadata["MissingValue"] = _MV;

            //Add variable to SDS
            var BAHerbOut = _FeedingInteractionsDS.AddVariable <double>("Herbivory Interactions Biomass Assimilated", BiomassAssimilatedHerbivory, HerbivoryDimensions);

            BAHerbOut.Metadata["DisplayName"]  = "Herbivory Interactions Biomass Assimilated";
            BAHerbOut.Metadata["MissingValue"] = _MV;

            //Add variable to SDS
            var BIHerbOut = _FeedingInteractionsDS.AddVariable <double>("Herbivory Interactions Biomass Ingested", BiomassIngestedHerbivory, HerbivoryDimensions);

            BIHerbOut.Metadata["DisplayName"]  = "Herbivory Interactions Biomass Ingested";
            BIHerbOut.Metadata["MissingValue"] = _MV;


            //Commit changes
            _FeedingInteractionsDS.Commit();
        }