Beispiel #1
0
        //---------------------------------------------------------------------
        public static void Initialize(string climateConfigFilename, bool writeOutput, ICore mCore)
        {
            InputParametersParser inParamsParser = new InputParametersParser();

            configParameters = Landis.Data.Load <IInputParameters>(climateConfigFilename, inParamsParser);

            modelCore = mCore;
            MetadataHandler.InitializeMetadata(1, modelCore);

            ModelCore.UI.WriteLine("   Loading weather data ...");
            Climate.future_allData = new Dictionary <int, IClimateRecord[, ]>();
            Climate.spinup_allData = new Dictionary <int, IClimateRecord[, ]>();

            Future_MonthlyData  = new Dictionary <int, AnnualClimate_Monthly[]>();
            Spinup_MonthlyData  = new Dictionary <int, AnnualClimate_Monthly[]>();
            Future_DailyData    = new Dictionary <int, AnnualClimate_Daily[]>();
            Spinup_DailyData    = new Dictionary <int, AnnualClimate_Daily[]>();
            LandscapeAnnualPDSI = new double[Climate.ModelCore.EndTime - Climate.ModelCore.StartTime + 1];

            ModelCore.UI.WriteLine("   Loading spin-up weather data from file {0} ...", configParameters.SpinUpClimateFile);
            Climate.ConvertFileFormat_FillOutAllData(configParameters.SpinUpClimateTimeSeries, configParameters.SpinUpClimateFile, configParameters.SpinUpClimateFileFormat, Climate.Phase.SpinUp_Climate);

            ModelCore.UI.WriteLine("   Loading future weather data from file {0} ...", configParameters.ClimateFile);
            Climate.ConvertFileFormat_FillOutAllData(configParameters.ClimateTimeSeries, configParameters.ClimateFile, configParameters.ClimateFileFormat, Climate.Phase.Future_Climate);


            //string climateOption = Climate.ConfigParameters.ClimateTimeSeries;
            //if (this.climatePhase == Climate.Phase.SpinUp_Climate)
            //    climateOption = Climate.ConfigParameters.SpinUpClimateTimeSeries;

            //switch (climateOption)
            //{
            //    case "MonthlyAverage":
            //        {
            //            break;
            //        }
            //    case "MonthlyRandom":
            //        {
            //            break;
            //        }
            //    case "DailyHistRandom":
            //        {
            //            break;
            //        }
            //    case "DailyHistAverage":
            //        {
            //            return;
            //        }
            //    case "MonthlyStandard":
            //        {
            //            break;
            //        }
            //    case "DailyGCM":
            //        {
            //        }
            //    case "MonthlyGCM":
            //        {
            //            break;
            //        }
            //    default:
            //        throw new ApplicationException(String.Format("Unknown Climate Time Series: {}", climateOption));

            //}


            if (Climate.ConfigParameters.ClimateTimeSeries.ToLower().Contains("random"))
            {
                Climate.randSelectedTimeSteps_future = new int[Climate.future_allData.Count];//should be future_allData.Count or it needs to be different?
                for (int i = 0; i < Climate.future_allData.Count; i++)
                {
                    Climate.randSelectedTimeSteps_future[i] = (int)Math.Round(Climate.ModelCore.GenerateUniform() * (Climate.future_allData.Count - 1));
                }
            }

            if (Climate.ConfigParameters.SpinUpClimateTimeSeries.ToLower().Contains("random"))
            {
                //int maxSpeciesAge = modelCore.Species.Max(sp => sp.Longevity);
                int maxSpeciesAge = 0;
                foreach (ISpecies sp in ModelCore.Species)
                {
                    if (sp.Longevity > maxSpeciesAge)
                    {
                        maxSpeciesAge = sp.Longevity;
                    }
                }

                Climate.randSelectedTimeSteps_spinup = new int[maxSpeciesAge];
                for (int i = 0; i < maxSpeciesAge; i++)
                {
                    Climate.randSelectedTimeSteps_spinup[i] = (int)Math.Round(Climate.ModelCore.GenerateUniform() * (Climate.spinup_allData.Count - 1));
                }
            }
            foreach (KeyValuePair <int, IClimateRecord[, ]> timeStep in spinup_allData)
            {
                //Climate.TimestepData = timeStep.Value;
                IClimateRecord[,] timestepData = timeStep.Value;
                int year = timeStep.Key;
                //Write(timestepData, year, "SpinUp");

                Spinup_MonthlyData.Add(timeStep.Key, new AnnualClimate_Monthly[modelCore.Ecoregions.Count]);
                Spinup_DailyData.Add(timeStep.Key, new AnnualClimate_Daily[modelCore.Ecoregions.Count]);
                Climate.Write(timestepData, timeStep.Key, Climate.Phase.SpinUp_Climate.ToString());
            }
            foreach (KeyValuePair <int, IClimateRecord[, ]> timeStep in future_allData)
            {
                //Climate.TimestepData = timeStep.Value;
                IClimateRecord[,] timestepData = timeStep.Value;
                int year = timeStep.Key;
                //Write(timestepData, year, "Future");

                Future_MonthlyData.Add(timeStep.Key, new AnnualClimate_Monthly[modelCore.Ecoregions.Count]);
                Future_DailyData.Add(timeStep.Key, new AnnualClimate_Daily[modelCore.Ecoregions.Count]);
                Climate.Write(timestepData, timeStep.Key, Climate.Phase.Future_Climate.ToString());
            }
        }
Beispiel #2
0
        //---------------------------------------------------------------------
        public static void Initialize(string climateConfigFilename, bool writeOutput, ICore mCore)
        {
            InputParametersParser inParamsParser = new InputParametersParser();

            configParameters = Landis.Data.Load <IInputParameters>(climateConfigFilename, inParamsParser);

            modelCore = mCore;
            MetadataHandler.InitializeMetadata(1, modelCore);

            ModelCore.UI.WriteLine("   Loading weather data ...");
            Climate.future_allData = new Dictionary <int, ClimateRecord[][]>();
            Climate.spinup_allData = new Dictionary <int, ClimateRecord[][]>();

            Future_MonthlyData  = new Dictionary <int, AnnualClimate_Monthly[]>();
            Spinup_MonthlyData  = new Dictionary <int, AnnualClimate_Monthly[]>();
            Future_DailyData    = new Dictionary <int, AnnualClimate_Daily[]>();
            Spinup_DailyData    = new Dictionary <int, AnnualClimate_Daily[]>();
            LandscapeAnnualPDSI = new double[Climate.ModelCore.EndTime - Climate.ModelCore.StartTime + 1];

            ModelCore.UI.WriteLine("   Loading spin-up weather data from file {0} ...", configParameters.SpinUpClimateFile);
            Climate.ConvertFileFormat_FillOutAllData(configParameters.SpinUpClimateTimeSeries, configParameters.SpinUpClimateFile, configParameters.SpinUpClimateFileFormat, Climate.Phase.SpinUp_Climate);

            ModelCore.UI.WriteLine("   Loading future weather data from file {0} ...", configParameters.ClimateFile);
            Climate.ConvertFileFormat_FillOutAllData(configParameters.ClimateTimeSeries, configParameters.ClimateFile, configParameters.ClimateFileFormat, Climate.Phase.Future_Climate);


            // **
            // spinup

            // write input data to the log
            foreach (KeyValuePair <int, ClimateRecord[][]> timeStep in spinup_allData)
            {
                Climate.WriteSpinupInputLog(timeStep.Value, timeStep.Key); //, Climate.Phase.SpinUp_Climate.ToString());
            }

            // find maxSpeciesAge as the maximum possible time step count for spin up
            int maxSpeciesAge = 0;

            foreach (ISpecies sp in ModelCore.Species)
            {
                if (sp.Longevity > maxSpeciesAge)
                {
                    maxSpeciesAge = sp.Longevity;
                }
            }

            var spinupTimeStepKeys  = new List <int>();
            var spinupKeyList       = new List <int>(Climate.spinup_allData.Keys);
            var spinupStartYear     = spinupKeyList.Min();
            var spinupTimeStepCount = maxSpeciesAge;

            for (var i = 0; i < spinupTimeStepCount; ++i)
            {
                spinupTimeStepKeys.Add(spinupStartYear + i);
            }

            if (Climate.ConfigParameters.SpinUpClimateTimeSeries.ToLower().Contains("random"))
            {
                // generate random keys for the length of maxSpeciesAge
                Climate.randSelectedTimeKeys_spinup = new List <int>();

                // pick a random year key from allData
                for (var i = 0; i < spinupTimeStepCount; ++i)
                {
                    Climate.randSelectedTimeKeys_spinup.Add(spinupKeyList[(int)(spinupKeyList.Count * Climate.ModelCore.GenerateUniform())]);
                }
            }

            // initialize Spinup data arrays
            foreach (var timeStepKey in spinupTimeStepKeys)
            {
                Spinup_MonthlyData.Add(timeStepKey, new AnnualClimate_Monthly[modelCore.Ecoregions.Count]);
                Spinup_DailyData.Add(timeStepKey, new AnnualClimate_Daily[modelCore.Ecoregions.Count]);
            }


            // **
            // future

            // write input data to the log
            foreach (KeyValuePair <int, ClimateRecord[][]> timeStep in future_allData)
            {
                Climate.WriteFutureInputLog(timeStep.Value, timeStep.Key); //, future_allData_granularity);
            }

            var futureTimeStepKeys  = new List <int>();
            var futureKeyList       = new List <int>(Climate.future_allData.Keys);
            var futureStartYear     = futureKeyList.Min();
            var futureTimeStepCount = ModelCore.EndTime - ModelCore.StartTime;

            for (var i = 0; i < futureTimeStepCount; ++i)
            {
                futureTimeStepKeys.Add(futureStartYear + i);
            }

            if (Climate.ConfigParameters.ClimateTimeSeries.ToLower().Contains("random"))
            {
                // generate random keys for the length of the simulation
                Climate.randSelectedTimeKeys_future = new List <int>();

                // pick a random year key from allData
                for (var i = 0; i < futureTimeStepCount; ++i)
                {
                    Climate.randSelectedTimeKeys_future.Add(futureKeyList[(int)(futureKeyList.Count * Climate.ModelCore.GenerateUniform())]);
                }
            }

            // initialize Future data arrays
            foreach (var timeStepKey in futureTimeStepKeys)
            {
                Future_MonthlyData.Add(timeStepKey, new AnnualClimate_Monthly[modelCore.Ecoregions.Count]);
                Future_DailyData.Add(timeStepKey, new AnnualClimate_Daily[modelCore.Ecoregions.Count]);
            }
        }