Search in sources :

Example 6 with TSJobResultsSpaceStats

use of org.vcell.util.document.TSJobResultsSpaceStats 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)

Example 7 with TSJobResultsSpaceStats

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

the class ImportRawTimeSeriesFrom2DVCellConcentrationsOp method importRawTimeSeries.

private static ImageDataset importRawTimeSeries(File vcellSimLogFile, String fluorFunctionName, Double maxIntensity, boolean bNoise, final ClientTaskStatusSupport progressListener) throws Exception {
    VCSimulationIdentifier vcSimulationIdentifier = VCellSimReader.getVCSimulationIdentifierFromVCellSimulationData(vcellSimLogFile);
    VCSimulationDataIdentifier vcSimulationDataIdentifier = new VCSimulationDataIdentifier(vcSimulationIdentifier, 0);
    DataSetControllerImpl dataSetControllerImpl = VCellSimReader.getDataSetControllerImplFromVCellSimulationData(vcellSimLogFile);
    final DataJobEvent[] bStatus = new DataJobEvent[] { null };
    DataJobListener dataJobListener = new DataJobListener() {

        public void dataJobMessage(DataJobEvent event) {
            bStatus[0] = event;
            if (progressListener != null) {
                progressListener.setProgress((int) (event.getProgress() / 100.0 * .75));
            }
        }
    };
    dataSetControllerImpl.addDataJobListener(dataJobListener);
    DataIdentifier[] dataIdentifiers = VCellSimReader.getDataIdentiferListFromVCellSimulationData(vcellSimLogFile, 0);
    DataIdentifier variableNameDataIdentifier = null;
    for (int i = 0; i < dataIdentifiers.length; i++) {
        if (dataIdentifiers[i].getName().equals(fluorFunctionName)) {
            variableNameDataIdentifier = dataIdentifiers[i];
            break;
        }
    }
    if (variableNameDataIdentifier == null) {
        throw new IllegalArgumentException("Variable " + fluorFunctionName + " not found.");
    }
    if (!variableNameDataIdentifier.getVariableType().equals(VariableType.VOLUME)) {
        throw new IllegalArgumentException("Variable " + fluorFunctionName + " is not VOLUME type.");
    }
    double[] times = dataSetControllerImpl.getDataSetTimes(vcSimulationDataIdentifier);
    CartesianMesh cartesianMesh = dataSetControllerImpl.getMesh(vcSimulationDataIdentifier);
    BitSet allBitset = new BitSet(cartesianMesh.getNumVolumeElements());
    allBitset.set(0, cartesianMesh.getNumVolumeElements() - 1);
    TimeSeriesJobSpec timeSeriesJobSpec = new TimeSeriesJobSpec(new String[] { fluorFunctionName }, new BitSet[] { allBitset }, times[0], 1, times[times.length - 1], true, false, VCDataJobID.createVCDataJobID(VCellSimReader.getDotUser(), true));
    TSJobResultsSpaceStats tsJobResultsSpaceStats = (TSJobResultsSpaceStats) dataSetControllerImpl.getTimeSeriesValues(null, vcSimulationDataIdentifier, timeSeriesJobSpec);
    // wait for job to finish
    while (bStatus[0] == null || bStatus[0].getEventTypeID() != DataJobEvent.DATA_COMPLETE) {
        Thread.sleep(100);
    }
    double allTimesMin = tsJobResultsSpaceStats.getMinimums()[0][0];
    double allTimesMax = allTimesMin;
    for (int i = 0; i < times.length; i++) {
        allTimesMin = Math.min(allTimesMin, tsJobResultsSpaceStats.getMinimums()[0][i]);
        allTimesMax = Math.max(allTimesMax, tsJobResultsSpaceStats.getMaximums()[0][i]);
    }
    // double SCALE_MAX = maxIntensity.doubleValue();/*Math.pow(2,16)-1;*///Scale to 16 bits
    double linearScaleFactor = 1;
    if (maxIntensity != null) {
        linearScaleFactor = maxIntensity.doubleValue() / allTimesMax;
    }
    System.out.println("alltimesMin=" + allTimesMin + " allTimesMax=" + allTimesMax + " linearScaleFactor=" + linearScaleFactor);
    UShortImage[] scaledDataImages = new UShortImage[times.length];
    Random rnd = new Random();
    int shortMax = 65535;
    // set messge to load variable
    if (progressListener != null) {
        progressListener.setMessage("Loading variable " + fluorFunctionName + "...");
    }
    for (int i = 0; i < times.length; i++) {
        double[] rawData = dataSetControllerImpl.getSimDataBlock(null, vcSimulationDataIdentifier, fluorFunctionName, times[i]).getData();
        short[] scaledDataShort = new short[rawData.length];
        for (int j = 0; j < scaledDataShort.length; j++) {
            double scaledRawDataJ = rawData[j] * linearScaleFactor;
            if (bNoise) {
                double ran = rnd.nextGaussian();
                double scaledRawDataJ_withNoise = Math.max(0, (scaledRawDataJ + ran * Math.sqrt(scaledRawDataJ)));
                scaledRawDataJ_withNoise = Math.min(shortMax, scaledRawDataJ_withNoise);
                int scaledValue = (int) (scaledRawDataJ_withNoise);
                scaledDataShort[j] &= 0x0000;
                scaledDataShort[j] |= 0x0000FFFF & scaledValue;
            } else {
                int scaledValue = (int) (scaledRawDataJ);
                scaledDataShort[j] &= 0x0000;
                scaledDataShort[j] |= 0x0000FFFF & scaledValue;
            }
        }
        scaledDataImages[i] = new UShortImage(scaledDataShort, cartesianMesh.getOrigin(), cartesianMesh.getExtent(), cartesianMesh.getSizeX(), cartesianMesh.getSizeY(), cartesianMesh.getSizeZ());
        if (progressListener != null) {
            int progress = (int) (((i + 1) * 1.0 / times.length) * 100);
            progressListener.setProgress(progress);
        }
    }
    ImageDataset rawImageDataSet = new ImageDataset(scaledDataImages, times, cartesianMesh.getSizeZ());
    return rawImageDataSet;
}
Also used : VCSimulationIdentifier(cbit.vcell.solver.VCSimulationIdentifier) DataIdentifier(cbit.vcell.simdata.DataIdentifier) VCSimulationDataIdentifier(cbit.vcell.solver.VCSimulationDataIdentifier) TimeSeriesJobSpec(org.vcell.util.document.TimeSeriesJobSpec) ImageDataset(cbit.vcell.VirtualMicroscopy.ImageDataset) BitSet(java.util.BitSet) TSJobResultsSpaceStats(org.vcell.util.document.TSJobResultsSpaceStats) UShortImage(cbit.vcell.VirtualMicroscopy.UShortImage) VCSimulationDataIdentifier(cbit.vcell.solver.VCSimulationDataIdentifier) DataJobEvent(cbit.rmi.event.DataJobEvent) CartesianMesh(cbit.vcell.solvers.CartesianMesh) Random(java.util.Random) DataSetControllerImpl(cbit.vcell.simdata.DataSetControllerImpl) DataJobListener(cbit.rmi.event.DataJobListener)

Aggregations

TSJobResultsSpaceStats (org.vcell.util.document.TSJobResultsSpaceStats)7 CartesianMesh (cbit.vcell.solvers.CartesianMesh)4 TimeSeriesJobSpec (org.vcell.util.document.TimeSeriesJobSpec)4 DataIdentifier (cbit.vcell.simdata.DataIdentifier)3 VCSimulationDataIdentifier (cbit.vcell.solver.VCSimulationDataIdentifier)3 BitSet (java.util.BitSet)3 DataJobEvent (cbit.rmi.event.DataJobEvent)2 DataJobListener (cbit.rmi.event.DataJobListener)2 ImageDataset (cbit.vcell.VirtualMicroscopy.ImageDataset)2 UShortImage (cbit.vcell.VirtualMicroscopy.UShortImage)2 AsynchClientTask (cbit.vcell.client.task.AsynchClientTask)2 SinglePoint (cbit.vcell.geometry.SinglePoint)2 SymbolTableEntry (cbit.vcell.parser.SymbolTableEntry)2 DataSetControllerImpl (cbit.vcell.simdata.DataSetControllerImpl)2 AnnotatedFunction (cbit.vcell.solver.AnnotatedFunction)2 VCSimulationIdentifier (cbit.vcell.solver.VCSimulationIdentifier)2 Point (java.awt.Point)2 Hashtable (java.util.Hashtable)2 ExternalDataIdentifier (org.vcell.util.document.ExternalDataIdentifier)2 VCDataIdentifier (org.vcell.util.document.VCDataIdentifier)2