Search in sources :

Example 1 with VCSimulationDataIdentifier

use of cbit.vcell.solver.VCSimulationDataIdentifier in project vcell by virtualcell.

the class ODETimePlotMultipleScansPanel method updateScanParamChoices.

/**
 * Insert the method's description here.
 * Creation date: (10/18/2005 12:44:06 AM)
 */
private void updateScanParamChoices() {
    AsynchClientTask task1 = new AsynchClientTask("get ode results", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {

        @Override
        public void run(Hashtable<String, Object> hashTable) throws Exception {
            int[] jobIndexes = scanChoiceTable.getSelectedRows();
            VCSimulationIdentifier vcSimulationIdentifier = simulation.getSimulationInfo().getAuthoritativeVCSimulationIdentifier();
            int plotCount = jobIndexes.length * variableNames.length;
            SymbolTableEntry[] symbolTableEntries = new SymbolTableEntry[plotCount];
            double[][] dataValues = new double[plotCount + 1][];
            PlotData[] plotDatas = new PlotData[plotCount];
            String[] plotNames = new String[plotCount];
            int plotIndex = 0;
            dataValues[0] = null;
            for (int ji = 0; ji < jobIndexes.length; ji++) {
                int jobIndex = jobIndexes[ji];
                final VCDataIdentifier vcdid = new VCSimulationDataIdentifier(vcSimulationIdentifier, jobIndex);
                ODEDataManager odeDatamanager = ((ODEDataManager) dataManager).createNewODEDataManager(vcdid);
                ODESolverResultSet odeSolverResultSet = odeDatamanager.getODESolverResultSet();
                if (ji == 0) {
                    plotPane.setStepViewVisible(simulation.getSolverTaskDescription().getSolverDescription().isNonSpatialStochasticSolver(), odeSolverResultSet.isMultiTrialData());
                    hashTable.put("bMultiTrial", new Boolean(odeSolverResultSet.isMultiTrialData()));
                }
                double[] tdata = null;
                if (!odeSolverResultSet.isMultiTrialData()) {
                    int tcol = odeSolverResultSet.findColumn(ReservedVariable.TIME.getName());
                    tdata = odeSolverResultSet.extractColumn(tcol);
                    if (dataValues[0] == null) {
                        dataValues[0] = tdata;
                    }
                }
                for (int v = 0; v < variableNames.length; v++) {
                    String varname = variableNames[v];
                    int varcol = odeSolverResultSet.findColumn(varname);
                    double[] vdata = odeSolverResultSet.extractColumn(varcol);
                    if (!odeSolverResultSet.isMultiTrialData()) {
                        dataValues[plotIndex + 1] = vdata;
                        // plotNames[plotIndex] = varname + " -- " + JOB_PLOT_NAME + " " + jobIndex;
                        plotDatas[plotIndex] = new PlotData(tdata, vdata);
                    // symbolTableEntries[plotIndex] = simulation.getMathDescription().getVariable(varname);
                    } else {
                        Point2D[] histogram = ODESolverPlotSpecificationPanel.generateHistogram(vdata);
                        double[] x = new double[histogram.length];
                        double[] y = new double[histogram.length];
                        for (int j = 0; j < histogram.length; j++) {
                            x[j] = histogram[j].getX();
                            y[j] = histogram[j].getY();
                        }
                        plotDatas[plotIndex] = new PlotData(x, y);
                    }
                    plotNames[plotIndex] = varname + " -- " + JOB_PLOT_NAME + " " + jobIndex;
                    symbolTableEntries[plotIndex] = simulation.getMathDescription().getVariable(varname);
                    plotIndex++;
                }
            }
            hashTable.put("dataValues", dataValues);
            hashTable.put("plotDatas", plotDatas);
            hashTable.put("plotNames", plotNames);
            hashTable.put("symbolTableEntries", symbolTableEntries);
        }
    };
    AsynchClientTask task2 = new AsynchClientTask("show results", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {

        @Override
        public void run(Hashtable<String, Object> hashTable) throws Exception {
            double[][] dataValues = (double[][]) hashTable.get("dataValues");
            PlotData[] plotDatas = (PlotData[]) hashTable.get("plotDatas");
            String[] plotNames = (String[]) hashTable.get("plotNames");
            SymbolTableEntry[] symbolTableEntries = (SymbolTableEntry[]) hashTable.get("symbolTableEntries");
            if (plotDatas == null || plotDatas.length == 0 || (plotDatas.length == 1 && plotDatas[0] == null) || plotNames == null) {
                plotPane.setPlot2D(null);
                return;
            }
            Plot2D plot2D = null;
            if (hashTable.get("bMultiTrial") instanceof Boolean && (Boolean) hashTable.get("bMultiTrial")) {
                plot2D = new Plot2D(symbolTableEntries, null, plotNames, plotDatas, new String[] { "Probability Distribution of Species", "Number of Particles", "" });
            } else if (simulation.getSolverTaskDescription().getOutputTimeSpec() instanceof DefaultOutputTimeSpec) {
                plot2D = new Plot2D(symbolTableEntries, null, plotNames, plotDatas, new String[] { "Time Plot", ReservedVariable.TIME.getName(), "" });
            } else {
                plot2D = new SingleXPlot2D(symbolTableEntries, null, ReservedVariable.TIME.getName(), plotNames, dataValues);
            }
            plotPane.setPlot2D(plot2D);
        }
    };
    ClientTaskDispatcher.dispatch(this, new Hashtable<String, Object>(), new AsynchClientTask[] { task1, task2 });
}
Also used : AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) VCSimulationIdentifier(cbit.vcell.solver.VCSimulationIdentifier) SymbolTableEntry(cbit.vcell.parser.SymbolTableEntry) Point2D(java.awt.geom.Point2D) ODESolverResultSet(cbit.vcell.solver.ode.ODESolverResultSet) PlotData(cbit.plot.PlotData) Hashtable(java.util.Hashtable) VCSimulationDataIdentifier(cbit.vcell.solver.VCSimulationDataIdentifier) SingleXPlot2D(cbit.plot.SingleXPlot2D) ODEDataManager(cbit.vcell.simdata.ODEDataManager) SingleXPlot2D(cbit.plot.SingleXPlot2D) Plot2D(cbit.plot.Plot2D) VCDataIdentifier(org.vcell.util.document.VCDataIdentifier) DefaultOutputTimeSpec(cbit.vcell.solver.DefaultOutputTimeSpec)

Example 2 with VCSimulationDataIdentifier

use of cbit.vcell.solver.VCSimulationDataIdentifier in project vcell by virtualcell.

the class ClientRequestManager method getDataViewerController.

/**
 * Insert the method's description here.
 * Creation date: (6/11/2004 10:53:47 AM)
 * @return cbit.vcell.desktop.controls.DataManager
 * @param vcDataIdentifier cbit.vcell.server.VCDataIdentifier
 */
public DataViewerController getDataViewerController(OutputContext outputContext, Simulation simulation, int jobIndex) throws DataAccessException {
    VCSimulationIdentifier vcSimulationIdentifier = simulation.getSimulationInfo().getAuthoritativeVCSimulationIdentifier();
    final VCDataIdentifier vcdataIdentifier = new VCSimulationDataIdentifier(vcSimulationIdentifier, jobIndex);
    DataManager dataManager = getDataManager(outputContext, vcdataIdentifier, simulation.isSpatial());
    return new SimResultsViewerController(dataManager, simulation);
}
Also used : VCSimulationIdentifier(cbit.vcell.solver.VCSimulationIdentifier) VCDataManager(cbit.vcell.simdata.VCDataManager) PDEDataManager(cbit.vcell.simdata.PDEDataManager) ODEDataManager(cbit.vcell.simdata.ODEDataManager) DataManager(cbit.vcell.simdata.DataManager) VCDataIdentifier(org.vcell.util.document.VCDataIdentifier) VCSimulationDataIdentifier(cbit.vcell.solver.VCSimulationDataIdentifier)

Example 3 with VCSimulationDataIdentifier

use of cbit.vcell.solver.VCSimulationDataIdentifier in project vcell by virtualcell.

the class FRAPOptData method refreshDimensionReducedRefData.

public void refreshDimensionReducedRefData(final ClientTaskStatusSupport progressListener) throws Exception {
    System.out.println("run simulation...");
    KeyValue referenceSimKeyValue = null;
    referenceSimKeyValue = runRefSimulation(progressListener);
    System.out.println("simulation done...");
    VCSimulationIdentifier vcSimID = new VCSimulationIdentifier(referenceSimKeyValue, LocalWorkspace.getDefaultOwner());
    VCSimulationDataIdentifier vcSimDataID = new VCSimulationDataIdentifier(vcSimID, FieldDataFileOperationSpec.JOBINDEX_DEFAULT);
    // read results from netCDF file
    File hdf5File = new File(getLocalWorkspace().getDefaultSimDataDirectory(), vcSimDataID.getID() + SimDataConstants.DATA_PROCESSING_OUTPUT_EXTENSION_HDF5);
    // get dataprocessing output
    DataOperationResults.DataProcessingOutputInfo dataProcessingOutputInfo = (DataOperationResults.DataProcessingOutputInfo) DataSetControllerImpl.getDataProcessingOutput(new DataOperation.DataProcessingOutputInfoOP(null, /*no vcDataIdentifier OK*/
    false, null), hdf5File);
    DataOperationResults.DataProcessingOutputDataValues dataProcessingOutputDataValues = (DataOperationResults.DataProcessingOutputDataValues) DataSetControllerImpl.getDataProcessingOutput(new DataOperation.DataProcessingOutputDataValuesOP(null, /*no vcDataIdentifier OK*/
    FRAPStudy.ROI_EXTDATA_NAME, TimePointHelper.createAllTimeTimePointHelper(), DataIndexHelper.createSliceDataIndexHelper(0), null, null), hdf5File);
    // DataProcessingOutput dataProcessingOutput = getRawReferenceDataFromHDF5(hdf5File);
    // get ref sim time points
    double[] rawRefDataTimePoints = dataProcessingOutputInfo.getVariableTimePoints();
    // get shifted time points
    refDataTimePoints = shiftTimeForBaseDiffRate(rawRefDataTimePoints);
    // get summarized raw ref data
    double[][] rawData = new double[dataProcessingOutputInfo.getVariableISize(FRAPStudy.ROI_EXTDATA_NAME).getXYZ()][rawRefDataTimePoints.length];
    for (int i = 0; i < rawRefDataTimePoints.length; i++) {
        double[] temp = dataProcessingOutputDataValues.getDataValues()[i];
        for (int j = 0; j < temp.length; j++) {
            rawData[j][i] = temp[j];
        }
    }
    // contains only 8rois +1(the area that beyond 8 rois)
    // extend to whole roi data
    dimensionReducedRefData = FRAPOptimizationUtils.extendSimToFullROIData(expFrapStudy.getFrapData(), rawData, refDataTimePoints.length);
    System.out.println("generating dimension reduced ref data, done ....");
    // if reference simulation completes successfully, we save reference data info and remove old simulation files.
    boolean[] selectedROIs = new boolean[FRAPData.VFRAP_ROI_ENUM.values().length];
    Arrays.fill(selectedROIs, true);
    getExpFrapStudy().setStoredRefData(FRAPOptimizationUtils.doubleArrayToSimpleRefData(dimensionReducedRefData, getRefDataTimePoints(), 0, selectedROIs));
    // remove reference simulation files
    FRAPStudy.removeSimulationFiles(referenceSimKeyValue, getLocalWorkspace());
    // remove experimental and roi external files
    FRAPStudy.removeExternalFiles(getExpFrapStudy().getFrapDataExternalDataInfo().getExternalDataIdentifier(), getExpFrapStudy().getRoiExternalDataInfo().getExternalDataIdentifier(), getLocalWorkspace());
}
Also used : VCSimulationIdentifier(cbit.vcell.solver.VCSimulationIdentifier) KeyValue(org.vcell.util.document.KeyValue) VCSimulationDataIdentifier(cbit.vcell.solver.VCSimulationDataIdentifier) DataOperationResults(cbit.vcell.simdata.DataOperationResults) File(java.io.File)

Example 4 with VCSimulationDataIdentifier

use of cbit.vcell.solver.VCSimulationDataIdentifier in project vcell by virtualcell.

the class FrapDataUtils method importFRAPDataFromVCellSimulationData.

public static FRAPData importFRAPDataFromVCellSimulationData(File vcellSimLogFile, String variableName, String bleachedMaskVarName, Double maxIntensity, boolean bNoise, final ClientTaskStatusSupport progressListener) throws Exception {
    // bleachedMaskVarName = "laserMask_cell";
    VCSimulationIdentifier vcSimulationIdentifier = getVCSimulationIdentifierFromVCellSimulationData(vcellSimLogFile);
    VCSimulationDataIdentifier vcSimulationDataIdentifier = new VCSimulationDataIdentifier(vcSimulationIdentifier, 0);
    DataSetControllerImpl dataSetControllerImpl = 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 = getDataIdentiferListFromVCellSimulationData(vcellSimLogFile, 0);
    DataIdentifier variableNameDataIdentifier = null;
    for (int i = 0; i < dataIdentifiers.length; i++) {
        if (dataIdentifiers[i].getName().equals(variableName)) {
            variableNameDataIdentifier = dataIdentifiers[i];
            break;
        }
    }
    if (variableNameDataIdentifier == null) {
        throw new IllegalArgumentException("Variable " + variableName + " not found.");
    }
    if (!variableNameDataIdentifier.getVariableType().equals(VariableType.VOLUME)) {
        throw new IllegalArgumentException("Variable " + variableName + " 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[] { variableName }, new BitSet[] { allBitset }, times[0], 1, times[times.length - 1], true, false, VCDataJobID.createVCDataJobID(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 " + variableName + "...");
    }
    for (int i = 0; i < times.length; i++) {
        double[] rawData = dataSetControllerImpl.getSimDataBlock(null, vcSimulationDataIdentifier, variableName, 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 imageDataSet = new ImageDataset(scaledDataImages, times, cartesianMesh.getSizeZ());
    FRAPData frapData = new FRAPData(imageDataSet, new String[] { FRAPData.VFRAP_ROI_ENUM.ROI_BLEACHED.name(), FRAPData.VFRAP_ROI_ENUM.ROI_CELL.name(), FRAPData.VFRAP_ROI_ENUM.ROI_BACKGROUND.name() });
    // get rois from log file
    if (bleachedMaskVarName != null) {
        // set message to load cell ROI variable
        if (progressListener != null) {
            progressListener.setMessage("Loading ROIs...");
        }
        double[] rawROIBleached = dataSetControllerImpl.getSimDataBlock(null, vcSimulationDataIdentifier, bleachedMaskVarName, 0).getData();
        short[] scaledCellDataShort = new short[rawROIBleached.length];
        short[] scaledBleachedDataShort = new short[rawROIBleached.length];
        short[] scaledBackgoundDataShort = new short[rawROIBleached.length];
        for (int j = 0; j < scaledCellDataShort.length; j++) {
            boolean isCell = cartesianMesh.getCompartmentSubdomainNamefromVolIndex(j).equals("subVolume1");
            boolean isBackground = cartesianMesh.getCompartmentSubdomainNamefromVolIndex(j).equals("subVolume0");
            if (isCell) {
                scaledCellDataShort[j] = 1;
            }
            if (isBackground) {
                scaledBackgoundDataShort[j] = 1;
            }
            if (rawROIBleached[j] > 0.2) {
                scaledBleachedDataShort[j] = 1;
            }
        }
        UShortImage cellImage = new UShortImage(scaledCellDataShort, cartesianMesh.getOrigin(), cartesianMesh.getExtent(), cartesianMesh.getSizeX(), cartesianMesh.getSizeY(), cartesianMesh.getSizeZ());
        UShortImage bleachedImage = new UShortImage(scaledBleachedDataShort, cartesianMesh.getOrigin(), cartesianMesh.getExtent(), cartesianMesh.getSizeX(), cartesianMesh.getSizeY(), cartesianMesh.getSizeZ());
        UShortImage backgroundImage = new UShortImage(scaledBackgoundDataShort, cartesianMesh.getOrigin(), cartesianMesh.getExtent(), cartesianMesh.getSizeX(), cartesianMesh.getSizeY(), cartesianMesh.getSizeZ());
        if (progressListener != null) {
            progressListener.setProgress(100);
        }
        frapData.getRoi(FRAPData.VFRAP_ROI_ENUM.ROI_CELL.name()).setROIImages(new UShortImage[] { cellImage });
        frapData.getRoi(FRAPData.VFRAP_ROI_ENUM.ROI_BLEACHED.name()).setROIImages(new UShortImage[] { bleachedImage });
        frapData.getRoi(FRAPData.VFRAP_ROI_ENUM.ROI_BACKGROUND.name()).setROIImages(new UShortImage[] { backgroundImage });
    }
    return frapData;
}
Also used : VCSimulationIdentifier(cbit.vcell.solver.VCSimulationIdentifier) ExternalDataIdentifier(org.vcell.util.document.ExternalDataIdentifier) VCSimulationDataIdentifier(cbit.vcell.solver.VCSimulationDataIdentifier) DataIdentifier(cbit.vcell.simdata.DataIdentifier) TimeSeriesJobSpec(org.vcell.util.document.TimeSeriesJobSpec) ImageDataset(cbit.vcell.VirtualMicroscopy.ImageDataset) FRAPData(cbit.vcell.microscopy.FRAPData) 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)

Example 5 with VCSimulationDataIdentifier

use of cbit.vcell.solver.VCSimulationDataIdentifier in project vcell by virtualcell.

the class ClientSimManager method showSimulationResults0.

private AsynchClientTask[] showSimulationResults0(final boolean isLocal, final ViewerType viewerType) {
    // Create the AsynchClientTasks
    ArrayList<AsynchClientTask> taskList = new ArrayList<AsynchClientTask>();
    taskList.add(new AsynchClientTaskFunction(h -> {
        h.put(H_LOCAL_SIM, isLocal);
        h.put(H_VIEWER_TYPE, viewerType);
    }, "setLocal", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING));
    final DocumentWindowManager documentWindowManager = getDocumentWindowManager();
    AsynchClientTask retrieveResultsTask = new AsynchClientTask("Retrieving results", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {

        @SuppressWarnings("unchecked")
        public void run(Hashtable<String, Object> hashTable) throws Exception {
            Simulation[] simsToShow = (Simulation[]) hashTable.get("simsArray");
            for (int i = 0; i < simsToShow.length; i++) {
                final Simulation sim = simsToShow[i];
                final VCSimulationIdentifier vcSimulationIdentifier = sim.getSimulationInfo().getAuthoritativeVCSimulationIdentifier();
                final SimulationWindow simWindow = documentWindowManager.haveSimulationWindow(vcSimulationIdentifier);
                OutputContext outputContext = (OutputContext) hashTable.get("outputContext");
                if (simWindow == null && (viewerType == ViewerType.BothNativeAndPython || viewerType == ViewerType.NativeViewer_only)) {
                    try {
                        // make the manager and wire it up
                        DataViewerController dataViewerController = null;
                        if (!isLocal) {
                            dataViewerController = documentWindowManager.getRequestManager().getDataViewerController(outputContext, sim, 0);
                            // For changes in time or variable
                            documentWindowManager.addDataListener(dataViewerController);
                        } else {
                            // ---- preliminary : construct the localDatasetControllerProvider
                            File primaryDir = ResourceUtil.getLocalRootDir();
                            User usr = sim.getVersion().getOwner();
                            DataSetControllerImpl dataSetControllerImpl = new DataSetControllerImpl(null, primaryDir, null);
                            ExportServiceImpl localExportServiceImpl = new ExportServiceImpl();
                            LocalDataSetControllerProvider localDSCProvider = new LocalDataSetControllerProvider(usr, dataSetControllerImpl, localExportServiceImpl);
                            VCDataManager vcDataManager = new VCDataManager(localDSCProvider);
                            File localSimDir = ResourceUtil.getLocalSimDir(User.tempUser.getName());
                            LocalVCDataIdentifier vcDataId = new LocalVCSimulationDataIdentifier(vcSimulationIdentifier, 0, localSimDir);
                            DataManager dataManager = null;
                            if (sim.isSpatial()) {
                                dataManager = new PDEDataManager(outputContext, vcDataManager, vcDataId);
                            } else {
                                dataManager = new ODEDataManager(outputContext, vcDataManager, vcDataId);
                            }
                            dataViewerController = new SimResultsViewerController(dataManager, sim);
                            dataSetControllerImpl.addDataJobListener(documentWindowManager);
                        }
                        // make the viewer
                        Hashtable<VCSimulationIdentifier, DataViewerController> dataViewerControllers = (Hashtable<VCSimulationIdentifier, DataViewerController>) hashTable.get(H_DATA_VIEWER_CONTROLLERS);
                        if (dataViewerControllers == null) {
                            dataViewerControllers = new Hashtable<VCSimulationIdentifier, DataViewerController>();
                            hashTable.put(H_DATA_VIEWER_CONTROLLERS, dataViewerControllers);
                        }
                        dataViewerControllers.put(vcSimulationIdentifier, dataViewerController);
                    } catch (Throwable exc) {
                        exc.printStackTrace(System.out);
                        saveFailure(hashTable, sim, exc);
                    }
                }
                try {
                    if (viewerType == ViewerType.PythonViewer_only || viewerType == ViewerType.BothNativeAndPython) {
                        VtkManager vtkManager = null;
                        if (!isLocal) {
                            vtkManager = documentWindowManager.getRequestManager().getVtkManager(outputContext, new VCSimulationDataIdentifier(vcSimulationIdentifier, 0));
                        } else {
                            // ---- preliminary : construct the localDatasetControllerProvider
                            File primaryDir = ResourceUtil.getLocalRootDir();
                            User usr = sim.getVersion().getOwner();
                            DataSetControllerImpl dataSetControllerImpl = new DataSetControllerImpl(null, primaryDir, null);
                            ExportServiceImpl localExportServiceImpl = new ExportServiceImpl();
                            LocalDataSetControllerProvider localDSCProvider = new LocalDataSetControllerProvider(usr, dataSetControllerImpl, localExportServiceImpl);
                            VCDataManager vcDataManager = new VCDataManager(localDSCProvider);
                            File localSimDir = ResourceUtil.getLocalSimDir(User.tempUser.getName());
                            VCSimulationDataIdentifier simulationDataIdentifier = new LocalVCSimulationDataIdentifier(vcSimulationIdentifier, 0, localSimDir);
                            vtkManager = new VtkManager(outputContext, vcDataManager, simulationDataIdentifier);
                        }
                        // 
                        // test ability to read data
                        // 
                        VtuVarInfo[] vtuVarInfos = vtkManager.getVtuVarInfos();
                        double[] times = vtkManager.getDataSetTimes();
                        // 
                        // create the SimulationDataSetRef
                        // 
                        VCDocument modelDocument = null;
                        if (documentWindowManager instanceof BioModelWindowManager) {
                            modelDocument = ((BioModelWindowManager) documentWindowManager).getBioModel();
                        } else if (documentWindowManager instanceof MathModelWindowManager) {
                            modelDocument = ((MathModelWindowManager) documentWindowManager).getMathModel();
                        }
                        SimulationDataSetRef simulationDataSetRef = VCellClientDataServiceImpl.createSimulationDataSetRef(sim, modelDocument, 0, isLocal);
                        // Hashtable<VCSimulationIdentifier, SimulationDataSetRef> simDataSetRefs = (Hashtable<VCSimulationIdentifier, SimulationDataSetRef>)hashTable.get(H_SIM_DATASET_REFS);
                        // if (simDataSetRefs == null) {
                        // simDataSetRefs = new Hashtable<VCSimulationIdentifier, SimulationDataSetRef>();
                        // hashTable.put(H_SIM_DATASET_REFS, simDataSetRefs);
                        // }
                        // simDataSetRefs.put(vcSimulationIdentifier, simulationDataSetRef);
                        File visitExe = VCellConfiguration.getFileProperty(PropertyLoader.visitExe);
                        if (visitExe != null) {
                            VisitSupport.launchVisTool(visitExe, simulationDataSetRef);
                        }
                    }
                } catch (Throwable exc) {
                    exc.printStackTrace(System.out);
                    saveFailure(hashTable, sim, exc);
                }
            }
        }
    };
    taskList.add(retrieveResultsTask);
    AsynchClientTask displayResultsTask = new AsynchClientTask("Showing results", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {

        @SuppressWarnings("unchecked")
        public void run(Hashtable<String, Object> hashTable) throws Exception {
            boolean isLocal = fetch(hashTable, H_LOCAL_SIM, Boolean.class, true);
            SimulationWindow.LocalState localState = isLocal ? LocalState.LOCAL : LocalState.SERVER;
            Hashtable<Simulation, Throwable> failures = (Hashtable<Simulation, Throwable>) hashTable.get(H_FAILURES);
            Simulation[] simsToShow = (Simulation[]) hashTable.get("simsArray");
            for (int i = 0; i < simsToShow.length; i++) {
                final Simulation sim = simsToShow[i];
                if (failures != null && failures.containsKey(sim)) {
                    continue;
                }
                final VCSimulationIdentifier vcSimulationIdentifier = simsToShow[i].getSimulationInfo().getAuthoritativeVCSimulationIdentifier();
                final SimulationWindow simWindow = documentWindowManager.haveSimulationWindow(vcSimulationIdentifier);
                if (simWindow != null) {
                    ChildWindowManager childWindowManager = ChildWindowManager.findChildWindowManager(documentWindowManager.getComponent());
                    ChildWindow childWindow = childWindowManager.getChildWindowFromContext(simWindow);
                    if (childWindow == null) {
                        childWindow = childWindowManager.addChildWindow(simWindow.getDataViewer(), simWindow);
                        childWindow.pack();
                        childWindow.setIsCenteredOnParent();
                        childWindow.show();
                    }
                    setFinalWindow(hashTable, childWindow);
                    simWindow.setLocalState(localState);
                } else {
                    // wire it up the viewer
                    Hashtable<VCSimulationIdentifier, DataViewerController> dataViewerControllers = (Hashtable<VCSimulationIdentifier, DataViewerController>) hashTable.get(H_DATA_VIEWER_CONTROLLERS);
                    DataViewerController viewerController = dataViewerControllers.get(vcSimulationIdentifier);
                    Throwable ex = (failures == null ? null : failures.get(sim));
                    if (viewerController != null && ex == null) {
                        // no failure
                        DataViewer viewer = viewerController.createViewer();
                        getSimWorkspace().getSimulationOwner().getOutputFunctionContext().addPropertyChangeListener(viewerController);
                        documentWindowManager.addExportListener(viewer);
                        // For data related activities such as calculating statistics
                        documentWindowManager.addDataJobListener(viewer);
                        viewer.setSimulationModelInfo(new SimulationWorkspaceModelInfo(getSimWorkspace().getSimulationOwner(), sim.getName()));
                        viewer.setDataViewerManager(documentWindowManager);
                        SimulationWindow newWindow = new SimulationWindow(vcSimulationIdentifier, sim, getSimWorkspace().getSimulationOwner(), viewer);
                        BeanUtils.addCloseWindowKeyboardAction(newWindow.getDataViewer());
                        documentWindowManager.addResultsFrame(newWindow);
                        setFinalWindow(hashTable, viewer);
                        newWindow.setLocalState(localState);
                    }
                }
            }
            StringBuffer failMessage = new StringBuffer();
            if (failures != null) {
                if (!failures.isEmpty()) {
                    failMessage.append("Error, " + failures.size() + " of " + simsToShow.length + " sim results failed to display:\n");
                    Enumeration<Simulation> en = failures.keys();
                    while (en.hasMoreElements()) {
                        Simulation sim = en.nextElement();
                        Throwable exc = (Throwable) failures.get(sim);
                        failMessage.append("'" + sim.getName() + "' - " + exc.getMessage());
                    }
                }
            }
            if (failMessage.length() > 0) {
                PopupGenerator.showErrorDialog(ClientSimManager.this.getDocumentWindowManager(), failMessage.toString());
            }
        }
    };
    if (viewerType == ViewerType.BothNativeAndPython || viewerType == ViewerType.NativeViewer_only) {
        taskList.add(displayResultsTask);
    }
    // Dispatch the tasks using the ClientTaskDispatcher.
    AsynchClientTask[] taskArray = new AsynchClientTask[taskList.size()];
    taskList.toArray(taskArray);
    return taskArray;
}
Also used : User(org.vcell.util.document.User) DataViewerController(cbit.vcell.client.data.DataViewerController) SimulationMessage(cbit.vcell.solver.server.SimulationMessage) Enumeration(java.util.Enumeration) LocalVCDataIdentifier(org.vcell.util.document.LocalVCDataIdentifier) SimulationWindow(cbit.vcell.client.desktop.simulation.SimulationWindow) EventObject(java.util.EventObject) VCSimulationIdentifier(cbit.vcell.solver.VCSimulationIdentifier) Vector(java.util.Vector) DataViewer(cbit.vcell.client.data.DataViewer) FieldDataIdentifierSpec(cbit.vcell.field.FieldDataIdentifierSpec) SmoldynSolver(org.vcell.solver.smoldyn.SmoldynSolver) AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) VCSimulationDataIdentifier(cbit.vcell.solver.VCSimulationDataIdentifier) SimulationContext(cbit.vcell.mapping.SimulationContext) PrintWriter(java.io.PrintWriter) VisitSupport(cbit.vcell.resource.VisitSupport) Simulation(cbit.vcell.solver.Simulation) NetworkGenerationRequirements(cbit.vcell.mapping.SimulationContext.NetworkGenerationRequirements) VCDataManager(cbit.vcell.simdata.VCDataManager) BeanUtils(org.vcell.util.BeanUtils) Solver(cbit.vcell.solver.server.Solver) Collection(java.util.Collection) SimulationWorkspace(cbit.vcell.client.desktop.simulation.SimulationWorkspace) SolverListener(cbit.vcell.solver.server.SolverListener) VtkManager(cbit.vcell.simdata.VtkManager) SolverEvent(cbit.vcell.solver.server.SolverEvent) AsynchClientTaskFunction(cbit.vcell.client.task.AsynchClientTaskFunction) Dimension(java.awt.Dimension) SimulationJob(cbit.vcell.solver.SimulationJob) ClientTaskDispatcher(cbit.vcell.client.task.ClientTaskDispatcher) VCellConfiguration(cbit.vcell.resource.VCellConfiguration) ExportServiceImpl(cbit.vcell.export.server.ExportServiceImpl) DataProcessingInstructions(cbit.vcell.solver.DataProcessingInstructions) SimulationOwner(cbit.vcell.solver.SimulationOwner) ChildWindow(cbit.vcell.client.ChildWindowManager.ChildWindow) SimulationWorkspaceModelInfo(cbit.vcell.client.data.SimulationWorkspaceModelInfo) DataSetControllerImpl(cbit.vcell.simdata.DataSetControllerImpl) VCellClientDataServiceImpl(cbit.vcell.client.data.VCellClientDataServiceImpl) OutputContext(cbit.vcell.simdata.OutputContext) SimulationTask(cbit.vcell.messaging.server.SimulationTask) VCDocument(org.vcell.util.document.VCDocument) VtuVarInfo(org.vcell.vis.io.VtuVarInfo) TempSimulation(cbit.vcell.solver.TempSimulation) ArrayList(java.util.ArrayList) LocalState(cbit.vcell.client.desktop.simulation.SimulationWindow.LocalState) SolverFactory(cbit.vcell.solver.server.SolverFactory) SolverStatus(cbit.vcell.solver.server.SolverStatus) SimDataConstants(cbit.vcell.simdata.SimDataConstants) SolverException(cbit.vcell.solver.SolverException) Hashtable(java.util.Hashtable) SimulationStatusDetailsPanel(cbit.vcell.client.desktop.simulation.SimulationStatusDetailsPanel) SimulationStatus(cbit.vcell.server.SimulationStatus) SimulationDataSetRef(cbit.vcell.client.pyvcellproxy.SimulationDataSetRef) PDEDataManager(cbit.vcell.simdata.PDEDataManager) AnnotatedFunction(cbit.vcell.solver.AnnotatedFunction) ResourceUtil(cbit.vcell.resource.ResourceUtil) ODEDataManager(cbit.vcell.simdata.ODEDataManager) SmoldynFileWriter(org.vcell.solver.smoldyn.SmoldynFileWriter) IOException(java.io.IOException) PropertyLoader(cbit.vcell.resource.PropertyLoader) InputStreamReader(java.io.InputStreamReader) File(java.io.File) SolverUtilities(cbit.vcell.solver.SolverUtilities) TokenMangler(org.vcell.util.TokenMangler) SolverDescription(cbit.vcell.solver.SolverDescription) DialogUtils(org.vcell.util.gui.DialogUtils) SimulationStatusDetails(cbit.vcell.client.desktop.simulation.SimulationStatusDetails) ProgressDialogListener(org.vcell.util.ProgressDialogListener) DataManager(cbit.vcell.simdata.DataManager) InputStream(java.io.InputStream) UserCancelException(org.vcell.util.UserCancelException) LocalState(cbit.vcell.client.desktop.simulation.SimulationWindow.LocalState) VtuVarInfo(org.vcell.vis.io.VtuVarInfo) AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) VCSimulationIdentifier(cbit.vcell.solver.VCSimulationIdentifier) User(org.vcell.util.document.User) ArrayList(java.util.ArrayList) SimulationDataSetRef(cbit.vcell.client.pyvcellproxy.SimulationDataSetRef) AsynchClientTaskFunction(cbit.vcell.client.task.AsynchClientTaskFunction) DataViewerController(cbit.vcell.client.data.DataViewerController) DataViewer(cbit.vcell.client.data.DataViewer) ExportServiceImpl(cbit.vcell.export.server.ExportServiceImpl) VCDataManager(cbit.vcell.simdata.VCDataManager) SimulationWorkspaceModelInfo(cbit.vcell.client.data.SimulationWorkspaceModelInfo) VCDocument(org.vcell.util.document.VCDocument) Hashtable(java.util.Hashtable) VCDataManager(cbit.vcell.simdata.VCDataManager) PDEDataManager(cbit.vcell.simdata.PDEDataManager) ODEDataManager(cbit.vcell.simdata.ODEDataManager) DataManager(cbit.vcell.simdata.DataManager) LocalVCDataIdentifier(org.vcell.util.document.LocalVCDataIdentifier) VtkManager(cbit.vcell.simdata.VtkManager) VCSimulationDataIdentifier(cbit.vcell.solver.VCSimulationDataIdentifier) ChildWindow(cbit.vcell.client.ChildWindowManager.ChildWindow) OutputContext(cbit.vcell.simdata.OutputContext) Simulation(cbit.vcell.solver.Simulation) TempSimulation(cbit.vcell.solver.TempSimulation) PDEDataManager(cbit.vcell.simdata.PDEDataManager) SimulationWindow(cbit.vcell.client.desktop.simulation.SimulationWindow) DataSetControllerImpl(cbit.vcell.simdata.DataSetControllerImpl) ODEDataManager(cbit.vcell.simdata.ODEDataManager) File(java.io.File)

Aggregations

VCSimulationDataIdentifier (cbit.vcell.solver.VCSimulationDataIdentifier)47 VCSimulationIdentifier (cbit.vcell.solver.VCSimulationIdentifier)27 File (java.io.File)25 KeyValue (org.vcell.util.document.KeyValue)24 User (org.vcell.util.document.User)15 VCDataIdentifier (org.vcell.util.document.VCDataIdentifier)15 Simulation (cbit.vcell.solver.Simulation)11 BioModel (cbit.vcell.biomodel.BioModel)8 DataSetControllerImpl (cbit.vcell.simdata.DataSetControllerImpl)8 AsynchClientTask (cbit.vcell.client.task.AsynchClientTask)7 PDEDataManager (cbit.vcell.simdata.PDEDataManager)7 BigString (org.vcell.util.BigString)7 DataIdentifier (cbit.vcell.simdata.DataIdentifier)6 ODEDataManager (cbit.vcell.simdata.ODEDataManager)6 CartesianMesh (cbit.vcell.solvers.CartesianMesh)6 OutputContext (cbit.vcell.simdata.OutputContext)5 VCDataManager (cbit.vcell.simdata.VCDataManager)5 AnnotatedFunction (cbit.vcell.solver.AnnotatedFunction)5 IOException (java.io.IOException)5 Hashtable (java.util.Hashtable)5