/// <summary> /// Constructor for process tracker: Initialises the trackers for individual processes /// </summary> /// <param name="numTimesteps">The number of time steps in the model</param> /// <param name="lats">The latitudes of active grid cells in the model</param> /// <param name="lons">The longitudes of active grid cells in the model</param> /// <param name="cellIndices">List of indices of active cells in the model grid</param> /// <param name="Filenames">The filenames of the output files to write the tracking results to</param> /// <param name="trackProcesses">Whether to track processes</param> /// <param name="cohortDefinitions">The definitions for cohort functional groups in the model</param> /// <param name="missingValue">The missing value to use in process tracking output files</param> /// <param name="outputFileSuffix">The suffix to be applied to output files from process tracking</param> /// <param name="outputPath">The path to the folder to be used for process tracking outputs</param> /// <param name="trackerMassBins">The mass bins to use for categorising output data in the process trackers</param> /// <param name="specificLocations">Whether the model is being run for specific locations</param> /// <param name="initialisation">The Madingley Model initialisation</param> /// <param name="latCellSize">The size of grid cells latitudinally</param> /// <param name="lonCellSize">The size of grid cells longitudinally</param> public GlobalProcessTracker(uint numTimesteps, float[] lats, float[] lons, List<uint[]> cellIndices, SortedList<string, string> Filenames, Boolean trackProcesses, FunctionalGroupDefinitions cohortDefinitions, FunctionalGroupDefinitions stockDefinitions, double missingValue, string outputFileSuffix, string outputPath, MassBinsHandler trackerMassBins, Boolean specificLocations, MadingleyModelInitialisation initialisation, float latCellSize, float lonCellSize) { // Initialise trackers for ecological processes _TrackProcesses = trackProcesses; if (_TrackProcesses) { _TrackNPP = new GlobalNPPTracker(outputPath, lats.Length, lons.Length, lats, lons, latCellSize, lonCellSize, (int)numTimesteps,stockDefinitions.GetNumberOfFunctionalGroups(),outputFileSuffix); } }
/// <summary> /// Reads the initalization file to get information for the set of simulations to be run /// </summary> /// <param name="initialisationFile">The name of the initialization file with information on the simulations to be run</param> /// <param name="outputPath">The path to folder in which outputs will be stored</param> public MadingleyModelInitialisation(string simulationInitialisationFilename, string definitionsFilename, string outputsFilename, string outputPath) #endif { // Write to console Console.WriteLine("Initializing model...\n"); // Initialize the mass bins to be used during the model run _ModelMassBins = new MassBinsHandler(); // Read the intialisation files and copy them to the output directory #if true ReadAndCopyInitialisationFiles(simulationInitialisationFilename, definitionsFilename, outputsFilename, outputPath, inputPath); #else ReadAndCopyInitialisationFiles(simulationInitialisationFilename, definitionsFilename, outputsFilename, outputPath); // Copy parameter values to an output file //Don't do this now as the parameter values are read in from file and this file is copied to the output directory //CopyParameterValues(outputPath); #endif }
/// <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> /// 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 process tracker: Initialises the trackers for individual processes /// </summary> /// <param name="numTimesteps">The number of time steps in the model</param> /// <param name="lats">The latitudes of active grid cells in the model</param> /// <param name="lons">The longitudes of active grid cells in the model</param> /// <param name="cellIndices">List of indices of active cells in the model grid</param> /// <param name="Filenames">The filenames of the output files to write the tracking results to</param> /// <param name="trackProcesses">Whether to track processes</param> /// <param name="cohortDefinitions">The definitions for cohort functional groups in the model</param> /// <param name="missingValue">The missing value to use in process tracking output files</param> /// <param name="outputFileSuffix">The suffix to be applied to output files from process tracking</param> /// <param name="outputPath">The path to the folder to be used for process tracking outputs</param> /// <param name="trackerMassBins">The mass bins to use for categorising output data in the process trackers</param> /// <param name="specificLocations">Whether the model is being run for specific locations</param> /// <param name="initialisation">The Madingley Model initialisation</param> /// <param name="latCellSize">The size of grid cells latitudinally</param> /// <param name="lonCellSize">The size of grid cells longitudinally</param> public GlobalProcessTracker(uint numTimesteps, float[] lats, float[] lons, List <uint[]> cellIndices, SortedList <string, string> Filenames, Boolean trackProcesses, FunctionalGroupDefinitions cohortDefinitions, FunctionalGroupDefinitions stockDefinitions, double missingValue, string outputFileSuffix, string outputPath, MassBinsHandler trackerMassBins, Boolean specificLocations, MadingleyModelInitialisation initialisation, float latCellSize, float lonCellSize) { // Initialise trackers for ecological processes _TrackProcesses = trackProcesses; if (_TrackProcesses) { _TrackNPP = new GlobalNPPTracker(outputPath, lats.Length, lons.Length, lats, lons, latCellSize, lonCellSize, (int)numTimesteps, stockDefinitions.GetNumberOfFunctionalGroups()); } }
/// <summary> /// Constructor for process tracker: Initialises the trackers for individual processes /// </summary> /// <param name="numTimesteps">The number of time steps in the model</param> /// <param name="lats">The latitudes of active grid cells in the model</param> /// <param name="lons">The longitudes of active grid cells in the model</param> /// <param name="cellIndices">List of indices of active cells in the model grid</param> /// <param name="Filenames">The filenames of the output files to write the tracking results to</param> /// <param name="trackProcesses">Whether to track processes</param> /// <param name="cohortDefinitions">The definitions for cohort functional groups in the model</param> /// <param name="missingValue">The missing value to use in process tracking output files</param> /// <param name="outputFileSuffix">The suffix to be applied to output files from process tracking</param> /// <param name="outputPath">The path to the folder to be used for process tracking outputs</param> /// <param name="trackerMassBins">The mass bins to use for categorising output data in the process trackers</param> /// <param name="specificLocations">Whether the model is being run for specific locations</param> /// <param name="cellIndex">The index of the current cell in the list of all cells to run the model for</param> /// <param name="initialisation">The Madingley Model initialisation</param> /// <param name="marineCell">Whether the current cell is a marine cell</param> /// <param name="latCellSize">The size of grid cells in the latitudinal direction</param> /// <param name="lonCellSize">The size of grid cells in the longitudinal direction</param> public ProcessTracker(uint numTimesteps, float[] lats, float[] lons, List <uint[]> cellIndices, SortedList <string, string> Filenames, Boolean trackProcesses, FunctionalGroupDefinitions cohortDefinitions, double missingValue, string outputFileSuffix, string outputPath, MassBinsHandler trackerMassBins, Boolean specificLocations, int cellIndex, MadingleyModelInitialisation initialisation, bool marineCell, float latCellSize, float lonCellSize) { // Initialise trackers for ecological processes _TrackProcesses = trackProcesses; if (_TrackProcesses) { _TrackReproduction = new ReproductionTracker(numTimesteps, (uint)lats.Length, (uint)lons.Length, cellIndices, Filenames["NewCohortsOutput"], Filenames["MaturityOutput"], outputFileSuffix, outputPath, cellIndex); _TrackEating = new EatingTracker((uint)lats.Length, (uint)lons.Length, Filenames["TrophicFlowsOutput"], outputFileSuffix, outputPath, cellIndex, initialisation, marineCell); _TrackGrowth = new GrowthTracker(numTimesteps, (uint)lats.Length, (uint)lons.Length, cellIndices, Filenames["GrowthOutput"], outputFileSuffix, outputPath, cellIndex); _TrackMortality = new MortalityTracker(numTimesteps, (uint)lats.Length, (uint)lons.Length, cellIndices, Filenames["MortalityOutput"], outputFileSuffix, outputPath, cellIndex); _TrackExtinction = new ExtinctionTracker(Filenames["ExtinctionOutput"], outputPath, outputFileSuffix, cellIndex); _TrackMetabolism = new MetabolismTracker(Filenames["MetabolismOutput"], outputPath, outputFileSuffix, cellIndex); // Initialise the predation and herbivory trackers only for runs with specific locations if (specificLocations == true) { _TrackPredation = new PredationTracker(numTimesteps, cellIndices, Filenames["PredationFlowsOutput"], cohortDefinitions, missingValue, outputFileSuffix, outputPath, trackerMassBins, cellIndex); } } }
/// <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; }
/// <summary> /// Constructor for process tracker: Initialises the trackers for individual processes /// </summary> /// <param name="numTimesteps">The number of time steps in the model</param> /// <param name="lats">The latitudes of active grid cells in the model</param> /// <param name="lons">The longitudes of active grid cells in the model</param> /// <param name="cellIndices">List of indices of active cells in the model grid</param> /// <param name="Filenames">The filenames of the output files to write the tracking results to</param> /// <param name="trackProcesses">Whether to track processes</param> /// <param name="cohortDefinitions">The definitions for cohort functional groups in the model</param> /// <param name="missingValue">The missing value to use in process tracking output files</param> /// <param name="outputFileSuffix">The suffix to be applied to output files from process tracking</param> /// <param name="outputPath">The path to the folder to be used for process tracking outputs</param> /// <param name="trackerMassBins">The mass bins to use for categorising output data in the process trackers</param> /// <param name="specificLocations">Whether the model is being run for specific locations</param> /// <param name="cellIndex">The index of the current cell in the list of all cells to run the model for</param> /// <param name="initialisation">The Madingley Model initialisation</param> /// <param name="marineCell">Whether the current cell is a marine cell</param> /// <param name="latCellSize">The size of grid cells in the latitudinal direction</param> /// <param name="lonCellSize">The size of grid cells in the longitudinal direction</param> public ProcessTracker(uint numTimesteps, float[] lats, float[] lons, List<uint[]> cellIndices, SortedList<string, string> Filenames, Boolean trackProcesses, FunctionalGroupDefinitions cohortDefinitions, double missingValue, string outputFileSuffix, string outputPath, MassBinsHandler trackerMassBins, Boolean specificLocations, int cellIndex, MadingleyModelInitialisation initialisation, bool marineCell, float latCellSize, float lonCellSize) { // Initialise trackers for ecological processes _TrackProcesses = trackProcesses; if (_TrackProcesses) { _TrackReproduction = new ReproductionTracker(numTimesteps, (uint)lats.Length, (uint)lons.Length, cellIndices, Filenames["NewCohortsOutput"], Filenames["MaturityOutput"], outputFileSuffix, outputPath, cellIndex); _TrackEating = new EatingTracker((uint)lats.Length, (uint)lons.Length, Filenames["TrophicFlowsOutput"], outputFileSuffix, outputPath, cellIndex, initialisation, marineCell); _TrackGrowth = new GrowthTracker(numTimesteps, (uint)lats.Length, (uint)lons.Length, cellIndices, Filenames["GrowthOutput"], outputFileSuffix, outputPath, cellIndex); _TrackMortality = new MortalityTracker(numTimesteps, (uint)lats.Length, (uint)lons.Length, cellIndices, Filenames["MortalityOutput"], outputFileSuffix, outputPath, cellIndex); _TrackExtinction = new ExtinctionTracker(Filenames["ExtinctionOutput"], outputPath, outputFileSuffix, cellIndex); _TrackMetabolism = new MetabolismTracker(Filenames["MetabolismOutput"], outputPath, outputFileSuffix, cellIndex); // Initialise the predation and herbivory trackers only for runs with specific locations if (specificLocations == true) { _TrackPredation = new PredationTracker(numTimesteps, cellIndices, Filenames["PredationFlowsOutput"], cohortDefinitions, missingValue, outputFileSuffix, outputPath, trackerMassBins, cellIndex); } } }
/// <summary> /// Reads the initalization file to get information for the set of simulations to be run /// </summary> /// <param name="initialisationFile">The name of the initialization file with information on the simulations to be run</param> /// <param name="outputPath">The path to folder in which outputs will be stored</param> public MadingleyModelInitialisation(string simulationInitialisationFilename, string definitionsFilename, string outputsFilename, string outputPath) { // Write to console Console.WriteLine("Initializing model...\n"); // Initialize the mass bins to be used during the model run _ModelMassBins = new MassBinsHandler(); // Initialize the lists for storing information about model states _ModelStatePath = new List<string>(); _ModelStateFilename = new List<string>(); // Read the intialisation files and copy them to the output directory ReadAndCopyInitialisationFiles(simulationInitialisationFilename, definitionsFilename, outputsFilename, outputPath); // Copy parameter values to an output file //Don't do this now as the parameter values are read in from file and this file is copied to the output directory //CopyParameterValues(outputPath); }