Search in sources :

Example 26 with DataIdentifier

use of cbit.vcell.simdata.DataIdentifier in project vcell by virtualcell.

the class KymographPanel method initDataManagerVariable.

/**
 * Insert the method's description here.
 * Creation date: (12/14/2004 9:47:38 AM)
 * @param timeSeries double[][]
 * @param distances double[]
 */
private void initDataManagerVariable() /*final DataIdentifier dataIdentifer,*/
/*boolean bFromGUI*/
{
    final DataIdentifier dataIdentifer = (DataIdentifier) getVarNamesJComboBox().getSelectedItem();
    // Thread.dumpStack();
    if ((initVariableTimer = ClientTaskDispatcher.getBlockingTimer(this, multiTimePlotHelper.getPdeDatacontext(), null, initVariableTimer, new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            initDataManagerVariable();
        }
    }, "KymographPanel get '" + dataIdentifer.getName() + "'")) != null) {
        return;
    }
    // Create SymbolTableEntry for Copy/Paste functionality
    currentSymbolTablEntry = (symbolTable != null ? symbolTable.getEntry(dataIdentifer.getName()) : null);
    String taskName = "Retrieving data for variable '" + dataIdentifer.getName() + "'";
    AsynchClientTask task1 = new AsynchClientTask(taskName, AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {

        public void run(final Hashtable<String, Object> hashTable) throws Exception {
            double[] timeValues = multiTimePlotHelper.getPdeDatacontext().getTimePoints();
            final TimeSeriesJobSpec timeSeriesJobSpec = new TimeSeriesJobSpec(new String[] { dataIdentifer.getName() }, new int[][] { dataManagerIndices }, (crossingMembraneIndices != null ? new int[][] { crossingMembraneIndices } : null), resampleStartTimeOrig, resampleStepOrig, timeValues[timeValues.length - 1], VCDataJobID.createVCDataJobID(multiTimePlotHelper.getUser(), true));
            hashTable.put(PDEDataViewer.StringKey_timeSeriesJobSpec, timeSeriesJobSpec);
        }
    };
    // new TimeSeriesDataRetrievalTask(title, PDEDataViewer.this, PDEDataViewer.this.getPdeDataContext());//timeSeriesDataRetrievalTask;
    AsynchClientTask task2 = new PDEDataViewer.TimeSeriesDataRetrievalTask("Retrieving Data", multiTimePlotHelper, multiTimePlotHelper.getPdeDatacontext());
    AsynchClientTask task3 = new AsynchClientTask("Showing kymograph", AsynchClientTask.TASKTYPE_SWING_BLOCKING, false, false) {

        public void run(Hashtable<String, Object> hashTable) throws Exception {
            Throwable timeSeriesJobFailed = (Throwable) hashTable.get(PDEDataViewer.StringKey_timeSeriesJobException);
            if (timeSeriesJobFailed == null) {
                timeSeriesJobFailed = (Throwable) hashTable.get(ClientTaskDispatcher.TASK_ABORTED_BY_USER);
            }
            if (failMethod(timeSeriesJobFailed, dataIdentifer)) {
                return;
            }
            TSJobResultsNoStats tsJobResultsNoStats = (TSJobResultsNoStats) hashTable.get(PDEDataViewer.StringKey_timeSeriesJobResults);
            currentDataIdentifier = dataIdentifer;
            final double[][] timeSeries = tsJobResultsNoStats.getTimesAndValuesForVariable(currentDataIdentifier.getName());
            try {
                initStandAloneTimeSeries_private(timeSeries, dataManagerAccumDistances);
            } catch (Exception e) {
                failMethod(e, dataIdentifer);
                throw e;
            }
            if (isInit) {
                // set crosshair to init time
                // resampleStartTimeOrig;
                double initTime = initialLineScanTime;
                isInit = false;
                int closestTimeIndex = 0;
                double closestDiff = Double.MAX_VALUE;
                for (int i = 0; i < currentTimes.length; i += 1) {
                    double diff = Math.abs(initTime - currentTimes[i]);
                    if (diff < closestDiff) {
                        closestTimeIndex = i;
                        closestDiff = diff;
                    }
                }
                currentSelectionImg = new Point(0, closestTimeIndex);
                currentSelectionUnit = new Point2D.Double(0, (double) closestTimeIndex / (double) (currentTimes.length - 1));
                configurePlotData((int) currentSelectionImg.getX(), (int) currentSelectionImg.getY());
            // ChildWindowManager childWindowManager = ChildWindowManager.findChildWindowManager(pdeDataViewer);
            // //				final ChildWindow childWindow = childWindowManager.addChildWindow(new javax.swing.JPanel(),this,title);
            // final ChildWindow childWindow = childWindowManager.addChildWindow(KymographPanel.this,KymographPanel.this,title);
            // childWindow.setIsCenteredOnParent();
            // childWindow.pack();
            // childWindow.show();
            // Timer timer = new Timer(1000,new ActionListener() {
            // 
            // @Override
            // public void actionPerformed(ActionEvent e) {
            // childWindow.toFront();
            // }
            // });
            // System.out.println("Kymograph panel ChildWindow requesting focus.  Answer is: "+childWindow.requestFocusInWindow());
            // zoomToFill();
            } else {
                getImagePaneScroller1().zooming(new ZoomEvent(getimagePaneView1(), 0, 0));
            }
        }
    };
    AsynchClientTask[] tasks = (task2 == null ? new AsynchClientTask[] { task1, task3 } : new AsynchClientTask[] { task1, task2, task3 });
    ClientTaskDispatcher.dispatch(KymographPanel.this, new Hashtable<String, Object>(), tasks, false, true, true, null, false);
// if(bFromGUI){
// ClientTaskDispatcher.dispatch(KymographPanel.this,  new Hashtable<String, Object>(), tasks, false, true, true, null, false);
// System.out.println("Waiting here");
// }else{
// multiTimePlotHelper.addExtraTasks(tasks);
// }
}
Also used : AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) DataIdentifier(cbit.vcell.simdata.DataIdentifier) TimeSeriesJobSpec(org.vcell.util.document.TimeSeriesJobSpec) ActionEvent(java.awt.event.ActionEvent) Hashtable(java.util.Hashtable) Point(java.awt.Point) DataAccessException(org.vcell.util.DataAccessException) Point(java.awt.Point) ZoomEvent(cbit.image.ZoomEvent) ActionListener(java.awt.event.ActionListener) Point2D(java.awt.geom.Point2D) TSJobResultsNoStats(org.vcell.util.document.TSJobResultsNoStats)

Example 27 with DataIdentifier

use of cbit.vcell.simdata.DataIdentifier in project vcell by virtualcell.

the class SimResultsViewer method updateScanParamChoices.

private void updateScanParamChoices(final String message, ListReset listReset) {
    if ((paramScanChoiceTimer = ClientTaskDispatcher.getBlockingTimer(this, null, null, paramScanChoiceTimer, new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e2) {
            updateScanParamChoices(message, listReset);
        }
    }, message)) != null) {
        return;
    }
    int selectedJobIndex = getSelectedParamScanJobIndex();
    // update viewer
    if (selectedJobIndex == -1) {
        if (isODEData) {
            if (listReset != null && odeDataViewer != null && odeDataViewer.getVcDataIdentifier() != null) {
                listReset.reset(odeDataViewer.getVcDataIdentifier());
            } else {
                odeDataViewer.setOdeSolverResultSet(null);
            }
        } else {
            if (listReset != null && pdeDataViewer != null && pdeDataViewer.getPdeDataContext() != null && pdeDataViewer.getPdeDataContext().getVCDataIdentifier() != null) {
                listReset.reset(pdeDataViewer.getPdeDataContext().getVCDataIdentifier());
            } else {
                pdeDataViewer.setPdeDataContext(null);
            }
        }
        return;
    }
    final VCSimulationDataIdentifier vcdid = new VCSimulationDataIdentifier(getSimulation().getSimulationInfo().getAuthoritativeVCSimulationIdentifier(), selectedJobIndex);
    if (isODEData) {
        AsynchClientTask task1 = new AsynchClientTask("get ode results", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {

            @Override
            public void run(Hashtable<String, Object> hashTable) throws Exception {
                ODEDataManager odeDatamanager = ((ODEDataManager) dataManager).createNewODEDataManager(vcdid);
                hashTable.put("odeDatamanager", odeDatamanager);
            }
        };
        AsynchClientTask task2 = new AsynchClientTask("show results", AsynchClientTask.TASKTYPE_SWING_BLOCKING, false, false) {

            @Override
            public void run(Hashtable<String, Object> hashTable) throws Exception {
                if (hashTable.get(ClientTaskDispatcher.TASK_ABORTED_BY_ERROR) == null) {
                    ODEDataManager odeDatamanager = (ODEDataManager) hashTable.get("odeDatamanager");
                    odeDataViewer.setOdeSolverResultSet(odeDatamanager.getODESolverResultSet());
                    odeDataViewer.setVcDataIdentifier(vcdid);
                } else {
                    odeDataViewer.setOdeSolverResultSet(null);
                }
            }
        };
        ClientTaskDispatcher.dispatch(this, new Hashtable<String, Object>(), new AsynchClientTask[] { task1, task2 });
    } else {
        AsynchClientTask task1 = new AsynchClientTask("get pde results", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {

            @Override
            public void run(Hashtable<String, Object> hashTable) throws Exception {
                PDEDataManager pdeDatamanager = ((PDEDataManager) dataManager).createNewPDEDataManager(vcdid, null);
                PDEDataContext newPDEDC = pdeDatamanager.getPDEDataContext();
                PDEDataContext oldPDEDC = pdeDataViewer.getPdeDataContext();
                hashTable.put("newPDEDC", newPDEDC);
                if (oldPDEDC != null && oldPDEDC.getTimePoints().length <= newPDEDC.getTimePoints().length) {
                    DataIdentifier setDid = (newPDEDC.getDataIdentifier() == null ? newPDEDC.getDataIdentifiers()[0] : newPDEDC.getDataIdentifier());
                    if (Arrays.asList(newPDEDC.getDataIdentifiers()).contains(oldPDEDC.getDataIdentifier())) {
                        setDid = oldPDEDC.getDataIdentifier();
                        newPDEDC.setVariableAndTime(setDid, newPDEDC.getTimePoints()[BeanUtils.firstIndexOf(oldPDEDC.getTimePoints(), oldPDEDC.getTimePoint())]);
                    }
                }
            }
        };
        AsynchClientTask task2 = new AsynchClientTask("show results", AsynchClientTask.TASKTYPE_SWING_BLOCKING, false, false) {

            @Override
            public void run(Hashtable<String, Object> hashTable) throws Exception {
                if (hashTable.get(ClientTaskDispatcher.TASK_ABORTED_BY_ERROR) == null) {
                    ClientPDEDataContext newPDEDC = (ClientPDEDataContext) hashTable.get("newPDEDC");
                    pdeDataViewer.setPdeDataContext(newPDEDC);
                    pdeDataViewer.setSimNameSimDataID(new ExportSpecs.SimNameSimDataID(getSimulation().getName(), getSimulation().getSimulationInfo().getAuthoritativeVCSimulationIdentifier(), SimResultsViewer.getParamScanInfo(getSimulation(), vcdid.getJobIndex())));
                } else {
                    if (listReset != null && pdeDataViewer != null && pdeDataViewer.getPdeDataContext() != null && pdeDataViewer.getPdeDataContext().getVCDataIdentifier() != null) {
                        listReset.reset(pdeDataViewer.getPdeDataContext().getVCDataIdentifier());
                    } else {
                        pdeDataViewer.setPdeDataContext(null);
                        pdeDataViewer.setSimNameSimDataID(null);
                    }
                }
            }
        };
        // AsynchClientTask refreshTask = new AsynchClientTask("",AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
        // @Override
        // public void run(Hashtable<String, Object> hashTable) throws Exception {
        // ((ArrayList<AsynchClientTask>)hashTable.get(ClientTaskDispatcher.INTERMEDIATE_TASKS)).addAll(Arrays.asList(pdeDataViewer.getRefreshTasks()));
        // }
        // };
        ClientTaskDispatcher.dispatch(this, new Hashtable<String, Object>(), new AsynchClientTask[] { task1, task2 /*,refreshTask*/
        });
    }
}
Also used : PDEDataContext(cbit.vcell.simdata.PDEDataContext) ClientPDEDataContext(cbit.vcell.simdata.ClientPDEDataContext) AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) VCDataIdentifier(org.vcell.util.document.VCDataIdentifier) VCSimulationDataIdentifier(cbit.vcell.solver.VCSimulationDataIdentifier) DataIdentifier(cbit.vcell.simdata.DataIdentifier) ActionEvent(java.awt.event.ActionEvent) Hashtable(java.util.Hashtable) ExportSpecs(cbit.vcell.export.server.ExportSpecs) VCSimulationDataIdentifier(cbit.vcell.solver.VCSimulationDataIdentifier) ActionListener(java.awt.event.ActionListener) PDEDataManager(cbit.vcell.simdata.PDEDataManager) ODEDataManager(cbit.vcell.simdata.ODEDataManager) ClientPDEDataContext(cbit.vcell.simdata.ClientPDEDataContext)

Example 28 with DataIdentifier

use of cbit.vcell.simdata.DataIdentifier in project vcell by virtualcell.

the class MathTestingUtilities method comparePDEResults.

/**
 * Insert the method's description here.
 * Creation date: (8/20/2003 12:58:10 PM)
 */
public static SimulationComparisonSummary comparePDEResults(SimulationSymbolTable testSimSymbolTable, PDEDataManager testDataManager, SimulationSymbolTable refSimSymbolTable, PDEDataManager refDataManager, String[] varsToCompare, double absErrorThreshold, double relErrorThreshold, VCDocument refDocument, DataInfoProvider refDataInfoProvider, VCDocument testDocument, DataInfoProvider testDataInfoProvider) throws DataAccessException, ExpressionException {
    java.util.Hashtable<String, DataErrorSummary> tempVarHash = new java.util.Hashtable<String, DataErrorSummary>();
    boolean bTimesEqual = true;
    double[] testTimeArray = testDataManager.getDataSetTimes();
    double[] refTimeArray = refDataManager.getDataSetTimes();
    if (testTimeArray.length != refTimeArray.length) {
        bTimesEqual = false;
    // throw new RuntimeException("Data times for reference and test simulations don't match, cannot compare the two simulations!");
    } else {
        for (int i = 0; i < testTimeArray.length; i++) {
            if (testTimeArray[i] != refTimeArray[i]) {
                bTimesEqual = false;
            }
        }
    }
    // if (!checkSimVars(testSim, refSim)) {
    // //String errorS = "TestVars - ";
    // Variable[] testVars = testSim.getVariables();
    // //for(int i =0;i<vars.length;i+= 1){
    // //errorS+= vars[i].getName()+" ";
    // //}
    // //errorS+=" <<>> RefVars - ";
    // Variable[] refVars = refSim.getVariables();
    // //for(int i =0;i<vars.length;i+= 1){
    // //errorS+= vars[i].getName()+" ";
    // //}
    // throw new RuntimeException(
    // "VarNotMatch testLength="+(testVars != null?testVars.length+"":"null")+" refLength="+(refVars != null?refVars.length+"":"null"));
    // }
    CartesianMesh testMesh = testDataManager.getMesh();
    MathDescription testMathDesc = testSimSymbolTable.getSimulation().getMathDescription();
    // Variable[] refVars = refSim.getVariables();
    MathDescription refMathDesc = refSimSymbolTable.getSimulation().getMathDescription();
    CartesianMesh refMesh = refDataManager.getMesh();
    int[] membraneIndexMapping = null;
    // Get volumeSubdomains from mathDesc/mesh and store in lookupTable for testSimulation
    int testNumVol = testMesh.getSizeX() * testMesh.getSizeY() * testMesh.getSizeZ();
    CompartmentSubDomain[] testVolSubDomainLookup = new CompartmentSubDomain[testNumVol];
    for (int i = 0; i < testNumVol; i++) {
        int subVolumeIndex = testMesh.getSubVolumeFromVolumeIndex(i);
        SubVolume subVolume = testMathDesc.getGeometry().getGeometrySpec().getSubVolume(subVolumeIndex);
        CompartmentSubDomain compSubDomain = testMathDesc.getCompartmentSubDomain(subVolume.getName());
        testVolSubDomainLookup[i] = compSubDomain;
    }
    // Get membraneSubdomains from mathDesc/mesh and store in lookupTable for testSimulation
    int testNumMem = testMesh.getMembraneElements().length;
    MembraneSubDomain[] testMemSubDomainLookup = new MembraneSubDomain[testNumMem];
    for (int i = 0; i < testNumMem; i++) {
        int insideVolIndex = testMesh.getMembraneElements()[i].getInsideVolumeIndex();
        int outsideVolIndex = testMesh.getMembraneElements()[i].getOutsideVolumeIndex();
        MembraneSubDomain memSubDomain = testMathDesc.getMembraneSubDomain(testVolSubDomainLookup[insideVolIndex], testVolSubDomainLookup[outsideVolIndex]);
        testMemSubDomainLookup[i] = memSubDomain;
    }
    // Get volumeSubdomains from mathDesc/mesh and store in lookupTable for refSimulation
    int refNumVol = refMesh.getSizeX() * refMesh.getSizeY() * refMesh.getSizeZ();
    CompartmentSubDomain[] refVolSubDomainLookup = new CompartmentSubDomain[refNumVol];
    for (int i = 0; i < refNumVol; i++) {
        int subVolumeIndex = refMesh.getSubVolumeFromVolumeIndex(i);
        SubVolume subVolume = refMathDesc.getGeometry().getGeometrySpec().getSubVolume(subVolumeIndex);
        CompartmentSubDomain compSubDomain = refMathDesc.getCompartmentSubDomain(subVolume.getName());
        refVolSubDomainLookup[i] = compSubDomain;
    }
    // Get membraneSubdomains from mathDesc/mesh and store in lookupTable for refSimulation
    int refNumMem = refMesh.getMembraneElements().length;
    MembraneSubDomain[] refMemSubDomainLookup = new MembraneSubDomain[refNumMem];
    for (int i = 0; i < refNumMem; i++) {
        int insideVolIndex = refMesh.getMembraneElements()[i].getInsideVolumeIndex();
        int outsideVolIndex = refMesh.getMembraneElements()[i].getOutsideVolumeIndex();
        MembraneSubDomain memSubDomain = refMathDesc.getMembraneSubDomain(refVolSubDomainLookup[insideVolIndex], refVolSubDomainLookup[outsideVolIndex]);
        refMemSubDomainLookup[i] = memSubDomain;
    }
    SimulationComparisonSummary simComparisonSummary = new SimulationComparisonSummary();
    String hashKey = new String("");
    DataErrorSummary tempVar = null;
    DataIdentifier[] refDataIDs = refDataManager.getDataIdentifiers();
    // for each var, do the following :
    for (int i = 0; i < varsToCompare.length; i++) {
        DataIdentifier refDataID = null;
        for (int j = 0; j < refDataIDs.length; j++) {
            if (refDataIDs[j].getName().equals(varsToCompare[i])) {
                refDataID = refDataIDs[j];
                break;
            }
        }
        // 
        // Find REFERENCE variable
        // 
        Variable refVar = getSimVar(refSimSymbolTable, varsToCompare[i]);
        if (refVar == null) {
            // Should only happen if TEST sims were generated 'post-domains' and REFERENCE sims were generated 'pre-domains'
            if (refDataID != null) {
                throw new RuntimeException("Unexpected reference condition: '" + varsToCompare[i] + "' not found in symboltable but was found in dataidentifiers");
            }
            if (testDocument instanceof BioModel) {
                // Only BioModels need to be checked
                // Look in TEST for a speciescontext with matching species name
                System.out.println("ReferenceVariable: using alternate method to find '" + varsToCompare[i] + "'");
                BioModel refBioModel = (BioModel) refDocument;
                BioModel testBioModel = (BioModel) testDocument;
                SpeciesContext testSpeciesContext = testBioModel.getModel().getSpeciesContext(varsToCompare[i]);
                if (testSpeciesContext != null) {
                    refVar = refSimSymbolTable.getVariable(testSpeciesContext.getSpecies().getCommonName());
                    for (int j = 0; j < refDataIDs.length; j++) {
                        if (refDataIDs[j].getName().equals(testSpeciesContext.getSpecies().getCommonName())) {
                            refDataID = refDataIDs[j];
                            break;
                        }
                    }
                }
            }
            if (refVar == null || refDataID == null) {
                Simulation refSim = refSimSymbolTable.getSimulation();
                throw new RuntimeException("The variable " + varsToCompare[i] + " was not found in Simulation (" + refSim.getName() + " " + refSim.getVersion().getDate() + ")\n");
            }
        }
        // 
        // Find TEST variable (assumed to have sims generated with a software version later than REFERENCE)
        // 
        Variable testVar = getSimVar(testSimSymbolTable, varsToCompare[i]);
        if (testVar == null) {
            // Should only happen if TEST sims were generated 'post-domains' and REFERENCE sims were generated 'pre-domains'
            System.out.println("TestVariable: using alternate method to find '" + varsToCompare[i] + "'");
            BioModel testBioModel = (BioModel) testDocument;
            SpeciesContext[] speciesContexts = testBioModel.getModel().getSpeciesContexts();
            boolean bSkip = false;
            for (int j = 0; j < speciesContexts.length; j++) {
                if (speciesContexts[j].getSpecies().getCommonName().equals(varsToCompare[i])) {
                    testVar = testSimSymbolTable.getVariable(speciesContexts[j].getName());
                    if (testVar == null) {
                        throw new RuntimeException("Speciescontext name '" + speciesContexts[j].getName() + "' not found in testsimsymboltable");
                    }
                    // If we got here it means at least one matching speciescontext was found in TEST with
                    // a species name matching varsToCompare[i].  We can skip because the matching speciesconetext
                    // will be used to do a comparison at some point.
                    bSkip = true;
                    break;
                }
            }
            if (bSkip) {
                // these are tested already using full simcontext names
                System.out.println("Skipping '" + varsToCompare[i] + "' as lookup in testSimSymbolTable");
                continue;
            }
            Simulation refSim = refSimSymbolTable.getSimulation();
            throw new RuntimeException("The variable " + varsToCompare[i] + " was not found in Simulation (" + refSim.getName() + " " + refSim.getVersion().getDate() + ")\n");
        }
        // for each time in timeArray. ('t' is used to index the testTimeArray, for interpolation purposes.)
        int t = 0;
        for (int j = 0; j < refTimeArray.length; j++) {
            // get data block from varName, data from datablock
            SimDataBlock refSimDataBlock = refDataManager.getSimDataBlock(refVar.getName(), refTimeArray[j]);
            double[] refData = refSimDataBlock.getData();
            double[] resampledTestData = null;
            if (bTimesEqual) {
                // If time arrays for both sims are equal, no need to resample/interpolate, just obtain the datablock from dataManager
                SimDataBlock testSimDataBlock = testDataManager.getSimDataBlock(testVar.getName(), testTimeArray[j]);
                resampledTestData = testSimDataBlock.getData();
            } else {
                // Time resampling (interpolation) needed.
                while ((t < testTimeArray.length - 2) && (refTimeArray[j] >= testTimeArray[t + 1])) {
                    t++;
                }
                SimDataBlock testSimDataBlock_1 = testDataManager.getSimDataBlock(testVar.getName(), testTimeArray[t]);
                double[] testData_1 = testSimDataBlock_1.getData();
                SimDataBlock testSimDataBlock_2 = testDataManager.getSimDataBlock(testVar.getName(), testTimeArray[t + 1]);
                double[] testData_2 = testSimDataBlock_2.getData();
                resampledTestData = new double[testData_1.length];
                // 
                for (int m = 0; m < testData_1.length; m++) {
                    resampledTestData[m] = testData_1[m] + (testData_2[m] - testData_1[m]) * (refTimeArray[j] - testTimeArray[t]) / (testTimeArray[t + 1] - testTimeArray[t]);
                }
            }
            // Spatial resampling (interpolation) ...
            double[] spaceResampledData = new double[refData.length];
            if (!testMathDesc.getGeometry().getExtent().compareEqual(refMathDesc.getGeometry().getExtent()) || !testMathDesc.getGeometry().getOrigin().compareEqual(refMathDesc.getGeometry().getOrigin())) {
                throw new RuntimeException("Different origins and/or extents for the 2 geometries. Cannot compare the 2 simulations");
            }
            if (testMesh.getSizeX() != refMesh.getSizeX() || testMesh.getSizeY() != refMesh.getSizeY() || testMesh.getSizeZ() != refMesh.getSizeZ()) {
                if (testVar instanceof VolVariable) {
                    if (testMathDesc.getGeometry().getDimension() == 1 && refMathDesc.getGeometry().getDimension() == 1) {
                        spaceResampledData = resample1DSpatial(resampledTestData, testMesh, refMesh);
                    } else if (testMathDesc.getGeometry().getDimension() == 2 && refMathDesc.getGeometry().getDimension() == 2) {
                        spaceResampledData = resample2DSpatial(resampledTestData, testMesh, refMesh);
                    } else if (testMathDesc.getGeometry().getDimension() == 3 && refMathDesc.getGeometry().getDimension() == 3) {
                        spaceResampledData = resample3DSpatial(resampledTestData, testMesh, refMesh);
                    } else {
                        throw new RuntimeException("Comparison of 2 simulations with different geometry dimensions are not handled at this time!");
                    }
                } else {
                    throw new RuntimeException("spatial resampling for variable type: " + testVar.getClass().getName() + " not supported");
                }
            } else {
                // no space resampling required
                if (testVar instanceof MemVariable) {
                    // 
                    if (membraneIndexMapping == null) {
                        membraneIndexMapping = testMesh.getMembraneIndexMapping(refMesh);
                    }
                    spaceResampledData = new double[resampledTestData.length];
                    for (int k = 0; k < resampledTestData.length; k++) {
                        spaceResampledData[k] = resampledTestData[membraneIndexMapping[k]];
                    }
                } else {
                    // 
                    // no reordering needed for other variable types.
                    // 
                    spaceResampledData = resampledTestData;
                }
            }
            // for each point in data block ...
            testDataInfoProvider.getPDEDataContext().setVariableName(testVar.getName());
            for (int k = 0; k < refData.length; k++) {
                if (!testDataInfoProvider.isDefined(k)) {
                    continue;
                }
                // Determine maxRef, minRef, maxAbsErr for variable
                // SubDomain testSubDomain = null;
                String sn = null;
                VariableType refVarType = refDataID.getVariableType();
                if (refVarType.equals(VariableType.VOLUME)) {
                    // testSubDomain = refVolSubDomainLookup[k];
                    sn = refVolSubDomainLookup[k].getName();
                } else if (refVarType.equals(VariableType.MEMBRANE)) {
                    // testSubDomain = refMemSubDomainLookup[k];
                    sn = refMemSubDomainLookup[k].getName();
                } else if (refVarType.equals(VariableType.MEMBRANE_REGION)) {
                    sn = "MRV_" + i;
                } else if (refVarType.equals(VariableType.VOLUME_REGION)) {
                    sn = "VRV_" + i;
                } else {
                    throw new RuntimeException("Var " + refVar.getName() + " not supported yet!");
                }
                // hashKey = refVar.getName()+":"+testSubDomain.getName();
                hashKey = refVar.getName() + ":" + sn;
                tempVar = tempVarHash.get(hashKey);
                if (tempVar == null) {
                    tempVar = new DataErrorSummary(null);
                    tempVarHash.put(hashKey, tempVar);
                }
                tempVar.addDataValues(refData[k], spaceResampledData[k], refTimeArray[j], k, absErrorThreshold, relErrorThreshold);
            }
        // end for (k)
        }
    // end for (j)
    }
    // end for (i)
    Enumeration<String> enumKeys = tempVarHash.keys();
    while (enumKeys.hasMoreElements()) {
        String key = enumKeys.nextElement();
        DataErrorSummary tempVarSummary = tempVarHash.get(key);
        simComparisonSummary.addVariableComparisonSummary(new VariableComparisonSummary(key, tempVarSummary.getMinRef(), tempVarSummary.getMaxRef(), tempVarSummary.getMaxAbsoluteError(), tempVarSummary.getMaxRelativeError(), tempVarSummary.getL2Norm(), tempVarSummary.getTimeAtMaxAbsoluteError(), tempVarSummary.getIndexAtMaxAbsoluteError(), tempVarSummary.getTimeAtMaxRelativeError(), tempVarSummary.getIndexAtMaxRelativeError()));
    }
    return simComparisonSummary;
}
Also used : MembraneSubDomain(cbit.vcell.math.MembraneSubDomain) DataIdentifier(cbit.vcell.simdata.DataIdentifier) MembraneRegionVariable(cbit.vcell.math.MembraneRegionVariable) InsideVariable(cbit.vcell.math.InsideVariable) SensVariable(cbit.vcell.solver.ode.SensVariable) FilamentVariable(cbit.vcell.math.FilamentVariable) VolVariable(cbit.vcell.math.VolVariable) VolumeRegionVariable(cbit.vcell.math.VolumeRegionVariable) ReservedVariable(cbit.vcell.math.ReservedVariable) MemVariable(cbit.vcell.math.MemVariable) OutsideVariable(cbit.vcell.math.OutsideVariable) FilamentRegionVariable(cbit.vcell.math.FilamentRegionVariable) Variable(cbit.vcell.math.Variable) MathDescription(cbit.vcell.math.MathDescription) SpeciesContext(cbit.vcell.model.SpeciesContext) SimDataBlock(cbit.vcell.simdata.SimDataBlock) MemVariable(cbit.vcell.math.MemVariable) SubVolume(cbit.vcell.geometry.SubVolume) AnalyticSubVolume(cbit.vcell.geometry.AnalyticSubVolume) VariableType(cbit.vcell.math.VariableType) VolVariable(cbit.vcell.math.VolVariable) CartesianMesh(cbit.vcell.solvers.CartesianMesh) Simulation(cbit.vcell.solver.Simulation) CompartmentSubDomain(cbit.vcell.math.CompartmentSubDomain) BioModel(cbit.vcell.biomodel.BioModel)

Example 29 with DataIdentifier

use of cbit.vcell.simdata.DataIdentifier in project vcell by virtualcell.

the class HybridSolverTester method makeAltCSV.

private static void makeAltCSV(AltArgsHelper altArgsHelper, FileWriter fw, int runIndex, File userSimDataDir) throws Exception {
    VCSimulationIdentifier vcSimID = new VCSimulationIdentifier(new KeyValue(altArgsHelper.simID), altArgsHelper.user);
    boolean bInit = runIndex == 0;
    ArrayList<Double> simTimes = new ArrayList<Double>();
    StringTokenizer st = null;
    if (altArgsHelper.times.equals("all")) {
    } else {
        st = new StringTokenizer(altArgsHelper.times, ":");
        while (st.hasMoreTokens()) {
            double timePoint = Double.parseDouble(st.nextToken());
            simTimes.add(timePoint);
        }
    }
    SimLocHelper simLocHelper0 = null;
    ArrayList<String> simVars = new ArrayList<String>();
    st = new StringTokenizer(altArgsHelper.varnames, ":");
    while (st.hasMoreTokens()) {
        String var = st.nextToken();
        simVars.add(var);
    }
    int jobCounter = 0;
    final int TIME_SPACE_EXTRA = 0;
    double[][][] trialData = null;
    while (true) {
        VCSimulationDataIdentifier vcSimulationDataIdentifier = new VCSimulationDataIdentifier(vcSimID, jobCounter);
        SimulationData simData = null;
        DataOperationResults.DataProcessingOutputInfo dataProcessingOutputInfo = null;
        try {
            simData = new SimulationData(vcSimulationDataIdentifier, userSimDataDir, null, null);
            dataProcessingOutputInfo = (DataOperationResults.DataProcessingOutputInfo) DataSetControllerImpl.getDataProcessingOutput(new DataOperation.DataProcessingOutputInfoOP(vcSimulationDataIdentifier, true, null), new File(userSimDataDir, SimulationData.createCanonicalPostProcessFileName(vcSimulationDataIdentifier)));
        } catch (FileNotFoundException e) {
            if (jobCounter == 0) {
                System.out.println("found no trials matching SimID=" + altArgsHelper.simID + " in user dir " + userSimDataDir.getAbsolutePath());
            } else {
                System.out.println("found " + jobCounter + " trials in dir " + userSimDataDir.getAbsolutePath() + " matching SimID=" + altArgsHelper.simID);
            }
            break;
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (dataProcessingOutputInfo == null) {
            System.out.println("No postprocessing found for " + jobCounter + " trials in dir " + userSimDataDir.getAbsolutePath() + " matching SimID=" + altArgsHelper.simID);
            jobCounter++;
            continue;
        }
        if (simLocHelper0 == null && !altArgsHelper.dataIndexes.equals(POSTPROC)) {
            simLocHelper0 = calcSimLocs(altArgsHelper.dataIndexes, simData.getMesh());
        }
        if (jobCounter == 0) {
            double[] allDatasetTimes = simData.getDataTimes();
            if (altArgsHelper.times.equals("all")) {
                for (double thisTime : allDatasetTimes) {
                    simTimes.add(thisTime);
                }
            } else {
                // Convert user input times to actual data times
                for (int times = 0; times < simTimes.size(); times++) {
                    double masterDelta = Double.POSITIVE_INFINITY;
                    double timePoint = -1;
                    for (int j = 0; j < allDatasetTimes.length; j++) {
                        double tempDelta = Math.abs(simTimes.get(times) - allDatasetTimes[j]);
                        if (tempDelta < masterDelta) {
                            masterDelta = tempDelta;
                            timePoint = allDatasetTimes[j];
                            if (tempDelta == 0) {
                                break;
                            }
                        }
                    }
                    System.out.println("User time=" + simTimes.get(times) + " converted to dataset time=" + timePoint);
                    simTimes.set(times, timePoint);
                }
            }
            trialData = new double[simTimes.size()][(simLocHelper0 == null ? 1 : simLocHelper0.boxToLocs.size())][simVars.size()];
        }
        if (bInit && jobCounter == 0) {
            // print state vars
            DataIdentifier[] dataIdentifiers = simData.getVarAndFunctionDataIdentifiers(null);
            for (int j = 0; j < dataIdentifiers.length; j++) {
                System.out.println(dataIdentifiers[j]);
            }
            printheader(altArgsHelper, simTimes, simLocHelper0, simVars, fw, TIME_SPACE_EXTRA);
        }
        for (int times = 0; times < simTimes.size(); times++) {
            double timePoint = simTimes.get(times);
            for (int vars = 0; vars < simVars.size(); vars++) {
                double[] data = null;
                if (altArgsHelper.dataIndexes.equals(POSTPROC)) {
                    data = dataProcessingOutputInfo.getVariableStatValues().get(simVars.get(vars) + "_average");
                } else {
                    SimDataBlock simDataBlock = simData.getSimDataBlock(null, simVars.get(vars), timePoint);
                    data = simDataBlock.getData();
                }
                for (int locs = 0; locs < trialData[times].length; locs++) {
                    double val;
                    if (simLocHelper0 != null && simLocHelper0.boxToLocs.get(locs).size() == 1) {
                        // point
                        // System.out.println("pointIndex="+simLocHelper.boxToLocs.get(locs).get(0));
                        val = data[simLocHelper0.boxToLocs.get(locs).get(0)];
                    } else if (simLocHelper0 != null) {
                        // box, calculate the average, could be concentration or counts
                        double accum = 0;
                        for (Integer locIndex : simLocHelper0.boxToLocs.get(locs)) {
                            // System.out.println("boxIndex="+locIndex);
                            accum += data[locIndex];
                        }
                        val = accum / simLocHelper0.boxToLocs.get(locs).size();
                    } else {
                        // PostProcess
                        if (times < data.length) {
                            val = data[times];
                        } else {
                            val = Double.NaN;
                        }
                    }
                    trialData[times][locs][vars] = val;
                }
            }
        }
        fw.write("r=" + runIndex + " s=" + jobCounter + ",");
        for (int times = 0; times < simTimes.size(); times++) {
            for (int locs = 0; locs < trialData[times].length; locs++) {
                for (int vars = 0; vars < simVars.size(); vars++) {
                    // System.out.println("job="+jobCounter+" time="+simTimes.get(times)+" loc="+simLocHelper.boxToID.get(locs)+" var="+simVars.get(vars)+" data="+trialData[times][locs][vars]);
                    boolean isNan = Double.isNaN(trialData[times][locs][vars]);
                    fw.write((isNan ? "" : trialData[times][locs][vars]) + ",");
                }
                fw.write(",");
            }
            for (int timeSpace = 0; timeSpace < TIME_SPACE_EXTRA; timeSpace++) {
                fw.write(",");
            }
        }
        fw.write("\n");
        jobCounter++;
    }
    fw.flush();
}
Also used : VCSimulationIdentifier(cbit.vcell.solver.VCSimulationIdentifier) KeyValue(org.vcell.util.document.KeyValue) VCSimulationDataIdentifier(cbit.vcell.solver.VCSimulationDataIdentifier) DataIdentifier(cbit.vcell.simdata.DataIdentifier) ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) BigString(org.vcell.util.BigString) SimDataBlock(cbit.vcell.simdata.SimDataBlock) DataOperation(cbit.vcell.simdata.DataOperation) VCSimulationDataIdentifier(cbit.vcell.solver.VCSimulationDataIdentifier) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) StringTokenizer(java.util.StringTokenizer) SimulationData(cbit.vcell.simdata.SimulationData) DataOperationResults(cbit.vcell.simdata.DataOperationResults) File(java.io.File)

Example 30 with DataIdentifier

use of cbit.vcell.simdata.DataIdentifier in project vcell by virtualcell.

the class FieldDataGUIPanel method copyMethod.

private void copyMethod(int copyMode) {
    String delimiter = "";
    if (copyMode == COPY_NL) {
        delimiter = "\n";
    } else if (copyMode == COPY_CRNL) {
        delimiter = "\r\n";
    } else if (copyMode == COPY_CSV) {
        delimiter = ",";
    } else if (copyMode == COPY_SPACE) {
        delimiter = " ";
    }
    String copyString = "";
    javax.swing.tree.TreePath selPath = getJTree1().getSelectionPath();
    if (selPath != null) {
        javax.swing.tree.DefaultMutableTreeNode lastPathComponent = (javax.swing.tree.DefaultMutableTreeNode) selPath.getLastPathComponent();
        if (lastPathComponent.equals(getJTree1().getModel().getRoot())) {
            int childCount = lastPathComponent.getChildCount();
            for (int i = 0; i < childCount; i += 1) {
                if (i != 0) {
                    copyString += delimiter;
                }
                copyString += ((FieldDataMainList) ((DefaultMutableTreeNode) lastPathComponent.getChildAt(i)).getUserObject()).externalDataIdentifier.getName();
            }
        } else if (lastPathComponent.getUserObject() instanceof FieldDataOriginList) {
            Origin origin = ((FieldDataOriginList) lastPathComponent.getUserObject()).origin;
            copyString = origin.getX() + delimiter + origin.getY() + delimiter + origin.getZ();
        } else if (lastPathComponent.getUserObject() instanceof FieldDataExtentList) {
            Extent extent = ((FieldDataExtentList) lastPathComponent.getUserObject()).extent;
            copyString = extent.getX() + delimiter + extent.getY() + delimiter + extent.getZ();
        } else if (lastPathComponent.getUserObject() instanceof FieldDataISizeList) {
            ISize isize = ((FieldDataISizeList) lastPathComponent.getUserObject()).isize;
            copyString = isize.getX() + delimiter + isize.getY() + delimiter + isize.getZ();
        } else if (lastPathComponent.getUserObject() instanceof FieldDataTimeList) {
            double[] times = ((FieldDataTimeList) lastPathComponent.getUserObject()).times;
            for (int i = 0; i < times.length; i += 1) {
                if (i != 0) {
                    copyString += delimiter;
                }
                copyString += times[i] + "";
            }
        } else if (lastPathComponent.getUserObject() instanceof FieldDataMainList) {
            ExternalDataIdentifier extDataID = ((FieldDataMainList) lastPathComponent.getUserObject()).externalDataIdentifier;
            copyString = extDataID.getName();
        } else if (lastPathComponent.getUserObject() instanceof FieldDataVarList) {
            DataIdentifier dataIdentifier = ((FieldDataVarList) lastPathComponent.getUserObject()).dataIdentifier;
            copyString = dataIdentifier.getName();
        } else if (lastPathComponent.getUserObject() instanceof FieldDataVarMainList) {
            int childCount = lastPathComponent.getChildCount();
            for (int i = 0; i < childCount; i += 1) {
                if (i != 0) {
                    copyString += delimiter;
                }
                copyString += ((FieldDataVarList) ((DefaultMutableTreeNode) lastPathComponent.getChildAt(i)).getUserObject()).dataIdentifier.getName();
            }
        }
        if (copyString.length() > 0) {
            VCellTransferable.sendToClipboard(copyString);
        }
    }
}
Also used : Origin(org.vcell.util.Origin) DataIdentifier(cbit.vcell.simdata.DataIdentifier) ExternalDataIdentifier(org.vcell.util.document.ExternalDataIdentifier) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) TreePath(javax.swing.tree.TreePath) Extent(org.vcell.util.Extent) ISize(org.vcell.util.ISize) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) ExternalDataIdentifier(org.vcell.util.document.ExternalDataIdentifier)

Aggregations

DataIdentifier (cbit.vcell.simdata.DataIdentifier)35 ArrayList (java.util.ArrayList)13 VCDataIdentifier (org.vcell.util.document.VCDataIdentifier)13 AsynchClientTask (cbit.vcell.client.task.AsynchClientTask)11 AnnotatedFunction (cbit.vcell.solver.AnnotatedFunction)11 VCSimulationDataIdentifier (cbit.vcell.solver.VCSimulationDataIdentifier)11 Hashtable (java.util.Hashtable)11 ExternalDataIdentifier (org.vcell.util.document.ExternalDataIdentifier)10 VariableType (cbit.vcell.math.VariableType)9 CartesianMesh (cbit.vcell.solvers.CartesianMesh)9 OutputContext (cbit.vcell.simdata.OutputContext)8 Point (java.awt.Point)8 DataAccessException (org.vcell.util.DataAccessException)8 TimeSeriesJobSpec (org.vcell.util.document.TimeSeriesJobSpec)8 SimDataBlock (cbit.vcell.simdata.SimDataBlock)6 File (java.io.File)6 ExportSpecs (cbit.vcell.export.server.ExportSpecs)5 DataOperation (cbit.vcell.simdata.DataOperation)5 ActionEvent (java.awt.event.ActionEvent)5 ActionListener (java.awt.event.ActionListener)5