private MpiObjectiveScores CalculateCatchmentScores(CatchmentDefinition catchment, SerializableDictionary <string, MpiTimeSeries> catchmentTimeSeries, MpiSysConfig sysConfig)
        {
            // convert back to the Time.Data.TimeSeries objects for use by the statistics objects.
            SerializableDictionary <string, TimeSeries> convertedCatchmentTimeSeries = new SerializableDictionary <string, TimeSeries>();

            foreach (KeyValuePair <string, MpiTimeSeries> keyValuePair in catchmentTimeSeries)
            {
                MpiTimeSeries value = keyValuePair.Value;
                convertedCatchmentTimeSeries.Add(keyValuePair.Key, new TimeSeries(value.Start, value.TimeStep, value.TimeSeries));
            }

            // make the pre-calculated time series look like a point time series model so it can be used by the statistics evaluator
            PointTimeSeriesSimulationDictionaryAdapter catchmentTimeSeriesAdapter = new PointTimeSeriesSimulationDictionaryAdapter(convertedCatchmentTimeSeries);

            catchmentTimeSeriesAdapter.SetPeriod(catchment.Cells[0].ModelRunDefinition.StartDate, catchment.Cells[0].ModelRunDefinition.EndDate);

            // retrieve the statistics evaluator for this catchment
            Log.DebugFormat("Rank {0}: Catchment '{1}' creating score evaluator", WorldRank, catchment.Id);
            var catchmentScoreEvaluator = GetCatchmentStatisticsEvaluator(catchment, catchmentTimeSeriesAdapter);

            catchmentScoreEvaluator.SetModelRunner(catchmentTimeSeriesAdapter);
            Log.DebugFormat("Rank {0}: Catchment '{1}' evaluating score", WorldRank, catchment.Id);
            MpiObjectiveScores calculateCatchmentScores = new MpiObjectiveScores(catchmentScoreEvaluator.EvaluateScore(catchmentTimeSeriesAdapter, sysConfig), catchment.Id);

            return(calculateCatchmentScores);
        }
Exemplo n.º 2
0
        //public unsafe void ApplyWeighting_Unsafe(float weight)
        //{
        //    int length = timeSeries.Length;
        //    fixed (double* pFixedTs = timeSeries)
        //    {
        //        double* pTs = pFixedTs;
        //        for (int i = 0; i < length; i++)
        //        {
        //            *pTs *= weight;
        //            pTs++;
        //        }
        //    }
        //}

        /// <summary>
        /// In-place element-wise addition of a time series to the current instance.
        /// Note, I have not defined this as an operator to avoid the overhead of duplicating the objects
        /// </summary>
        /// <param name="source">The source.</param>
        public void InplaceAdd(MpiTimeSeries source)
        {
            if (source.TimeSeries.Length != this.TimeSeries.Length)
            {
                throw new ArgumentOutOfRangeException("MpiTimeSeries length mismatch");
            }
            for (int i = 0; i < TimeSeries.Length; i++)
            {
                TimeSeries[i] += source[i];
            }
        }
        private SerializableDictionary <string, TimeSeries> AverageCellTimeSeries(SerializableDictionary <string, MpiTimeSeries>[] allCellResults, int cellCount)
        {
            SerializableDictionary <string, MpiTimeSeries> averages = new SerializableDictionary <string, MpiTimeSeries>();

            foreach (SerializableDictionary <string, MpiTimeSeries> cellResult in allCellResults)
            {
                foreach (KeyValuePair <string, MpiTimeSeries> cellResultTimeSeries in cellResult)
                {
                    if (averages.ContainsKey(cellResultTimeSeries.Key))
                    {
                        // add the time series values
                        double[] dst = averages[cellResultTimeSeries.Key].TimeSeries;
                        double[] src = cellResultTimeSeries.Value.TimeSeries;

                        for (int i = 0; i < src.Length; i++)
                        {
                            dst[i] += src[i];
                        }
                    }
                    else
                    {
                        averages.Add(cellResultTimeSeries.Key, (MpiTimeSeries)cellResultTimeSeries.Value.Clone());
                    }
                }
            }

            // convert the sums to the mean
            foreach (MpiTimeSeries value in averages.Values)
            {
                for (int i = 0; i < value.TimeSeries.Length; i++)
                {
                    value[i] /= cellCount;
                }
            }

            // convert back to the Time.Data.TimeSeries objects for use by the statistics objects.
            SerializableDictionary <string, TimeSeries> result = new SerializableDictionary <string, TimeSeries>();

            foreach (KeyValuePair <string, MpiTimeSeries> keyValuePair in averages)
            {
                MpiTimeSeries value = keyValuePair.Value;
                result.Add(keyValuePair.Key, new TimeSeries(value.Start, value.TimeStep, value.TimeSeries));
            }

            return(result);
        }