Search in sources :

Example 1 with TSJobResultsTimeStats

use of org.vcell.util.document.TSJobResultsTimeStats in project vcell by virtualcell.

the class DataSetControllerImpl method calculateStatisticsFromWhole.

/**
 * Insert the method's description here.
 * Creation date: (2/16/2006 12:28:29 PM)
 */
private static TimeSeriesJobResults calculateStatisticsFromWhole(TimeSeriesJobSpec timeSeriesJobSpec, double[][][] timeSeriesFormatedValuesArr, double[] desiredTimeValues, SpatialStatsInfo spatialStatsInfo) throws Exception {
    if (timeSeriesJobSpec.isCalcTimeStats()) {
        double[][] timeMinArr = null;
        double[][] timeMaxArr = null;
        double[][] timeMeanArr = null;
        timeMinArr = new double[timeSeriesJobSpec.getVariableNames().length][];
        timeMaxArr = new double[timeSeriesJobSpec.getVariableNames().length][];
        timeMeanArr = new double[timeSeriesJobSpec.getVariableNames().length][];
        double val = 0;
        for (int i = 0; i < timeSeriesFormatedValuesArr.length; i += 1) {
            timeMinArr[i] = new double[timeSeriesJobSpec.getIndices()[i].length];
            timeMaxArr[i] = new double[timeSeriesJobSpec.getIndices()[i].length];
            timeMeanArr[i] = new double[timeSeriesJobSpec.getIndices()[i].length];
            for (int j = 1; j < timeSeriesFormatedValuesArr[i].length; j += 1) {
                // skip index 0 (has times)
                double min = Double.POSITIVE_INFINITY;
                double max = Double.NEGATIVE_INFINITY;
                double mean = 0;
                for (int k = 0; k < desiredTimeValues.length; k += 1) {
                    val = timeSeriesFormatedValuesArr[i][j][k];
                    if (val < min) {
                        min = val;
                    }
                    if (val > max) {
                        max = val;
                    }
                    mean += val;
                }
                mean /= desiredTimeValues.length;
                timeMinArr[i][j - 1] = min;
                timeMaxArr[i][j - 1] = max;
                timeMeanArr[i][j - 1] = mean;
            }
        }
        if (!timeSeriesJobSpec.isCalcSpaceStats()) {
            // No space stats
            return new TSJobResultsTimeStats(timeSeriesJobSpec.getVariableNames(), timeSeriesJobSpec.getIndices(), desiredTimeValues, timeMinArr, timeMaxArr, timeMeanArr);
        } else {
            double[] timeSpaceStatsMin = new double[timeSeriesFormatedValuesArr.length];
            double[] timeSpaceStatsMax = new double[timeSeriesFormatedValuesArr.length];
            double[] timeSpaceStatsUnweightedMean = new double[timeSeriesFormatedValuesArr.length];
            double[] timeSpaceStatsWeightedMean = new double[timeSeriesFormatedValuesArr.length];
            for (int i = 0; i < timeSeriesFormatedValuesArr.length; i += 1) {
                double min = Double.POSITIVE_INFINITY;
                double max = Double.NEGATIVE_INFINITY;
                double mean = 0;
                double wmean = 0;
                for (int j = 0; j < timeSeriesJobSpec.getIndices()[i].length; j += 1) {
                    if (timeMinArr[i][j] < min) {
                        min = timeMinArr[i][j];
                    }
                    if (timeMaxArr[i][j] > max) {
                        max = timeMaxArr[i][j];
                    }
                    mean += timeMeanArr[i][j];
                    if (spatialStatsInfo.bWeightsValid) {
                        wmean += timeMeanArr[i][j] * spatialStatsInfo.spaceWeight[i][j];
                    }
                }
                mean /= timeSeriesFormatedValuesArr[i].length;
                if (spatialStatsInfo.bWeightsValid) {
                    wmean /= spatialStatsInfo.totalSpace[i];
                }
                timeSpaceStatsMin[i] = min;
                timeSpaceStatsMax[i] = max;
                timeSpaceStatsUnweightedMean[i] = mean;
                timeSpaceStatsWeightedMean[i] = wmean;
            }
            return new TSJobResultsTimeStats(timeSeriesJobSpec.getVariableNames(), timeSeriesJobSpec.getIndices(), desiredTimeValues, timeSpaceStatsMin, timeSpaceStatsMax, timeSpaceStatsUnweightedMean, (spatialStatsInfo.bWeightsValid ? timeSpaceStatsWeightedMean : null));
        }
    } else if (timeSeriesJobSpec.isCalcSpaceStats()) {
        double val = 0;
        double[][] spaceStatsMin = new double[timeSeriesJobSpec.getVariableNames().length][desiredTimeValues.length];
        double[][] spaceStatsMax = new double[timeSeriesJobSpec.getVariableNames().length][desiredTimeValues.length];
        double[][] spaceStatsUnweightedMean = new double[timeSeriesJobSpec.getVariableNames().length][desiredTimeValues.length];
        double[][] spaceStatsWeightedMean = new double[timeSeriesJobSpec.getVariableNames().length][desiredTimeValues.length];
        double[][] spaceStatsUnweightedSum = new double[timeSeriesJobSpec.getVariableNames().length][desiredTimeValues.length];
        double[][] spaceStatsWeightedSum = new double[timeSeriesJobSpec.getVariableNames().length][desiredTimeValues.length];
        for (int k = 0; k < desiredTimeValues.length; k += 1) {
            // times
            for (int i = 0; i < timeSeriesFormatedValuesArr.length; i += 1) {
                // Variable names
                double min = Double.POSITIVE_INFINITY;
                double max = Double.NEGATIVE_INFINITY;
                double mean = 0;
                double wmean = 0;
                double sum = 0;
                double wsum = 0;
                for (int j = 1; j < timeSeriesFormatedValuesArr[i].length; j += 1) {
                    // index
                    val = timeSeriesFormatedValuesArr[i][j][k];
                    // }
                    if (val < min) {
                        min = val;
                    }
                    if (val > max) {
                        max = val;
                    }
                    sum += val;
                    if (spatialStatsInfo.bWeightsValid) {
                        wsum += val * spatialStatsInfo.spaceWeight[i][j - 1];
                    }
                }
                mean = sum / timeSeriesJobSpec.getIndices()[i].length;
                if (spatialStatsInfo.bWeightsValid) {
                    wmean = wsum / spatialStatsInfo.totalSpace[i];
                }
                spaceStatsMin[i][k] = min;
                spaceStatsMax[i][k] = max;
                spaceStatsUnweightedMean[i][k] = mean;
                spaceStatsWeightedMean[i][k] = wmean;
                spaceStatsUnweightedSum[i][k] = sum;
                spaceStatsWeightedSum[i][k] = wsum;
            }
        }
        return new TSJobResultsSpaceStats(timeSeriesJobSpec.getVariableNames(), timeSeriesJobSpec.getIndices(), desiredTimeValues, spaceStatsMin, spaceStatsMax, spaceStatsUnweightedMean, (spatialStatsInfo.bWeightsValid ? spaceStatsWeightedMean : null), spaceStatsUnweightedSum, (spatialStatsInfo.bWeightsValid ? spaceStatsWeightedSum : null), (spatialStatsInfo.bWeightsValid ? spatialStatsInfo.totalSpace : null));
    }
    throw new IllegalArgumentException("Couldn't determine format of data to return");
}
Also used : TSJobResultsSpaceStats(org.vcell.util.document.TSJobResultsSpaceStats) TSJobResultsTimeStats(org.vcell.util.document.TSJobResultsTimeStats)

Aggregations

TSJobResultsSpaceStats (org.vcell.util.document.TSJobResultsSpaceStats)1 TSJobResultsTimeStats (org.vcell.util.document.TSJobResultsTimeStats)1