Search in sources :

Example 21 with DataIdentifier

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

the class PDEDataViewer method plotSpaceStats.

void plotSpaceStats(TSJobResultsSpaceStats tsjrss) {
    // Determine if Volume or Membrane
    DataIdentifier[] diArr = getPdeDataContext().getDataIdentifiers();
    boolean bVolume = true;
    for (int i = 0; i < diArr.length; i += 1) {
        if (diArr[i].getName().equals(tsjrss.getVariableNames()[0])) {
            if (diArr[i].getVariableType().equals(VariableType.MEMBRANE) || diArr[i].getVariableType().equals(VariableType.MEMBRANE_REGION)) {
                bVolume = false;
                break;
            }
        }
    }
    SymbolTableEntry[] symbolTableEntries = null;
    if (tsjrss.getVariableNames().length == 1) {
        // max.mean.min,sum
        symbolTableEntries = new SymbolTableEntry[3];
        if (getSimulation() != null && getSimulation().getMathDescription() != null) {
            symbolTableEntries[0] = getSimulation().getMathDescription().getEntry(tsjrss.getVariableNames()[0]);
        } else {
            symbolTableEntries[0] = new SimpleSymbolTable(tsjrss.getVariableNames()).getEntry(tsjrss.getVariableNames()[0]);
        }
        symbolTableEntries[1] = symbolTableEntries[0];
        symbolTableEntries[2] = symbolTableEntries[0];
    }
    SymbolTableEntry[] finalSymbolTableEntries = symbolTableEntries;
    boolean finalBVolume = bVolume;
    PlotPane plotPane = new cbit.plot.gui.PlotPane();
    plotPane.setPlot2D(new SingleXPlot2D(finalSymbolTableEntries, getSimulationModelInfo().getDataSymbolMetadataResolver(), "Time", new String[] { "Max", (tsjrss.getWeightedMean() != null ? "WeightedMean" : "UnweightedMean"), "Min" /*,
				(tsjrss.getWeightedSum() != null?"WeightedSum":"UnweightedSum")*/
    }, new double[][] { tsjrss.getTimes(), tsjrss.getMaximums()[0], (tsjrss.getWeightedMean() != null ? tsjrss.getWeightedMean()[0] : tsjrss.getUnweightedMean()[0]), tsjrss.getMinimums()[0] /*,
				(tsjrss.getWeightedSum() != null?tsjrss.getWeightedSum()[0]:tsjrss.getUnweightedSum()[0])*/
    }, new String[] { "Statistics Plot for " + tsjrss.getVariableNames()[0] + (tsjrss.getTotalSpace() != null ? " (ROI " + (finalBVolume ? "volume" : "area") + "=" + tsjrss.getTotalSpace()[0] + ")" : ""), ReservedVariable.TIME.getName(), "[" + tsjrss.getVariableNames()[0] + "]" }));
    String title = "Statistics: (" + tsjrss.getVariableNames()[0] + ") ";
    if (getSimulationModelInfo() != null) {
        title += getSimulationModelInfo().getContextName() + " " + getSimulationModelInfo().getSimulationName();
    }
    ChildWindowManager childWindowManager = ChildWindowManager.findChildWindowManager(PDEDataViewer.this);
    ChildWindow childWindow = childWindowManager.addChildWindow(plotPane, plotPane, title);
    childWindow.setIsCenteredOnParent();
    childWindow.pack();
    childWindow.show();
}
Also used : VCSimulationDataIdentifier(cbit.vcell.solver.VCSimulationDataIdentifier) LocalVCSimulationDataIdentifier(cbit.vcell.client.ClientSimManager.LocalVCSimulationDataIdentifier) ExternalDataIdentifier(org.vcell.util.document.ExternalDataIdentifier) VCDataIdentifier(org.vcell.util.document.VCDataIdentifier) DataIdentifier(cbit.vcell.simdata.DataIdentifier) ChildWindowManager(cbit.vcell.client.ChildWindowManager) ChildWindow(cbit.vcell.client.ChildWindowManager.ChildWindow) Point(java.awt.Point) SinglePoint(cbit.vcell.geometry.SinglePoint) SingleXPlot2D(cbit.plot.SingleXPlot2D) SymbolTableEntry(cbit.vcell.parser.SymbolTableEntry) SimpleSymbolTable(cbit.vcell.parser.SimpleSymbolTable) PlotPane(cbit.plot.gui.PlotPane)

Example 22 with DataIdentifier

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

the class PDEDataViewer method calcAutoAllTimes.

private void calcAutoAllTimes() throws Exception {
    HashSet<String> stateVarNames = null;
    Variable theVariable = null;
    boolean bStateVar = true;
    boolean isFieldData = getPdeDataContext().getVCDataIdentifier() instanceof ExternalDataIdentifier || getPdeDataContext().getVCDataIdentifier() instanceof MergedDataInfo;
    if (isFieldData) {
        // fielddata
        DataIdentifier[] dataids = getPdeDataContext().getDataIdentifiers();
        stateVarNames = new HashSet<>();
        for (int i = 0; i < dataids.length; i++) {
            if (!dataids[i].isFunction()) {
                stateVarNames.add(dataids[i].getName());
            }
        // System.out.println("name:'"+dataids[i].getName()+"' type:"+dataids[i].getVariableType()+" func:"+dataids[i].isFunction());
        }
        bStateVar = !getPdeDataContext().getDataIdentifier().isFunction();
        if (bStateVar) {
            theVariable = new VolVariable(getPdeDataContext().getDataIdentifier().getName(), getPdeDataContext().getDataIdentifier().getDomain());
        } else {
            AnnotatedFunction[] funcs = getPdeDataContext().getFunctions();
            for (int i = 0; i < funcs.length; i++) {
                if (funcs[i].getName().equals(getPdeDataContext().getDataIdentifier().getName())) {
                    theVariable = funcs[i];
                    break;
                }
            }
        }
    } else {
        stateVarNames = getSimulation().getMathDescription().getStateVariableNames();
        theVariable = getSimulation().getMathDescription().getVariable(getPdeDataContext().getVariableName());
        if (theVariable == null) {
            theVariable = ((ClientPDEDataContext) getPdeDataContext()).getDataManager().getOutputContext().getOutputFunction(getPdeDataContext().getVariableName());
        }
        if (theVariable == null) {
            DataProcessingOutputInfo dataProcessingOutputInfo = DataProcessingResultsPanel.getDataProcessingOutputInfo(getPdeDataContext());
            if (dataProcessingOutputInfo != null && Arrays.asList(dataProcessingOutputInfo.getVariableNames()).contains(getPdeDataContext().getVariableName())) {
                // PostProcess Variable
                return;
            }
        }
        bStateVar = stateVarNames.contains(getPdeDataContext().getVariableName());
    }
    if (theVariable == null) {
        throw new Exception("Unexpected Alltimes... selected variable '" + getPdeDataContext().getVariableName() + "' is not stateVariable or OutputFunction");
    }
    if (getPDEDataContextPanel1().getdisplayAdapterService1().getAllTimes()) {
        // min-max over all timepoints (allTimes)
        if (theVariable.isConstant()) {
            getPDEDataContextPanel1().getdisplayAdapterServicePanel1().changeAllTimesButtonText(DisplayAdapterServicePanel.ALL_TIMES__STATE_TEXT);
            double constVal = theVariable.getExpression().evaluateConstant();
            getPDEDataContextPanel1().setFunctionStatisticsRange(new Range(constVal, constVal));
        } else if (bStateVar) {
            getPDEDataContextPanel1().getdisplayAdapterServicePanel1().changeAllTimesButtonText(DisplayAdapterServicePanel.ALL_TIMES__STATE_TEXT);
            ArrayList<VarStatistics> varStatsArr = calcVarStat(getPdeDataContext(), new String[] { theVariable.getName() });
            if (errorAutoAllTimes(varStatsArr != null, (varStatsArr == null ? null : varStatsArr.size() > 0), isFieldData)) {
                // no postprocessinfo
                return;
            }
            FunctionStatistics functionStatistics = new FunctionStatistics(varStatsArr.get(0).minValuesOverTime, varStatsArr.get(0).maxValuesOverTime);
            getPDEDataContextPanel1().setFunctionStatisticsRange(new Range(functionStatistics.getMinOverTime(), functionStatistics.getMaxOverTime()));
        } else if (theVariable instanceof Function) {
            getPDEDataContextPanel1().getdisplayAdapterServicePanel1().changeAllTimesButtonText(DisplayAdapterServicePanel.ALL_TIMES__APPROX_TEXT);
            Function flattened = MathDescription.getFlattenedFunctions(SimulationSymbolTable.createMathSymbolTableFactory(), getSimulation().getMathDescription(), new String[] { theVariable.getName() })[0];
            if (flattened == null) {
                flattened = (Function) theVariable;
            }
            ArrayList<VarStatistics> varStatsArr = calcVarStat(getPdeDataContext(), stateVarNames.toArray(new String[0]));
            if (errorAutoAllTimes(varStatsArr != null, (varStatsArr == null ? null : varStatsArr.size() > 0), isFieldData)) {
                // check for no postprocessinfo
                return;
            }
            if (varStatsArr.size() == stateVarNames.size()) {
                if (getSimulation().getMeshSpecification().getGeometry().getGeometrySurfaceDescription().getRegionImage() == null) {
                    getSimulation().getMeshSpecification().getGeometry().getGeometrySurfaceDescription().updateAll();
                }
                FunctionStatistics functionStatistics = FunctionRangeGenerator.getFunctionStatistics(flattened.getExpression(), varStatsArr.toArray(new VarStatistics[0]), getPdeDataContext().getTimePoints(), getPdeDataContext().getCartesianMesh(), calcInDomainBitSet(), getPdeDataContext().getDataIdentifier().getVariableType());
                getPDEDataContextPanel1().setFunctionStatisticsRange(new Range(functionStatistics.getMinOverTime(), functionStatistics.getMaxOverTime()));
            } else {
                throw new Exception("Unexpectede AllTimes... calculated state var stats size != mathdescr state var size");
            }
        } else {
            throw new Exception("Unexpected AllTimes... not constant, stateVar or function");
        }
    } else {
        // min-max at each timepoint (currTime)
        if (!(theVariable instanceof Function)) {
            getPDEDataContextPanel1().getdisplayAdapterServicePanel1().changeAllTimesButtonText(DisplayAdapterServicePanel.ALL_TIMES__STATE_TEXT);
        } else {
            getPDEDataContextPanel1().getdisplayAdapterServicePanel1().changeAllTimesButtonText(DisplayAdapterServicePanel.ALL_TIMES__APPROX_TEXT);
        }
        getPDEDataContextPanel1().setFunctionStatisticsRange(null);
    }
}
Also used : VolVariable(cbit.vcell.math.VolVariable) ReservedVariable(cbit.vcell.math.ReservedVariable) Variable(cbit.vcell.math.Variable) VCSimulationDataIdentifier(cbit.vcell.solver.VCSimulationDataIdentifier) LocalVCSimulationDataIdentifier(cbit.vcell.client.ClientSimManager.LocalVCSimulationDataIdentifier) ExternalDataIdentifier(org.vcell.util.document.ExternalDataIdentifier) VCDataIdentifier(org.vcell.util.document.VCDataIdentifier) DataIdentifier(cbit.vcell.simdata.DataIdentifier) VolVariable(cbit.vcell.math.VolVariable) ArrayList(java.util.ArrayList) Range(org.vcell.util.Range) Point(java.awt.Point) SinglePoint(cbit.vcell.geometry.SinglePoint) DataAccessException(org.vcell.util.DataAccessException) PropertyVetoException(java.beans.PropertyVetoException) ImageException(cbit.image.ImageException) UserCancelException(org.vcell.util.UserCancelException) MergedDataInfo(cbit.vcell.simdata.MergedDataInfo) AnnotatedFunction(cbit.vcell.solver.AnnotatedFunction) Function(cbit.vcell.math.Function) VarStatistics(cbit.vcell.util.FunctionRangeGenerator.VarStatistics) DataProcessingOutputInfo(cbit.vcell.simdata.DataOperationResults.DataProcessingOutputInfo) ExternalDataIdentifier(org.vcell.util.document.ExternalDataIdentifier) AnnotatedFunction(cbit.vcell.solver.AnnotatedFunction) FunctionStatistics(cbit.vcell.util.FunctionRangeGenerator.FunctionStatistics)

Example 23 with DataIdentifier

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

the class PDEDataViewer method createMultiTimePlotHelper.

// private static class MultiTimePointPropChangeListener implements PropertyChangeListener {
// @Override
// public void propertyChange(PropertyChangeEvent evt) {
// }
// }
private MultiTimePlotHelper createMultiTimePlotHelper(final ClientPDEDataContext copyThisPDEDatacontext, final User user, DataSymbolMetadataResolver argDataSymbolMetadataResolver) throws Exception {
    final ClientPDEDataContext[] copyHolder = new ClientPDEDataContext[1];
    if (PDEDataViewer.this.isPostProcess()) {
        copyHolder[0] = PDEDataViewerPostProcess.createPostProcessPDEDataContext(copyThisPDEDatacontext);
    } else {
        copyHolder[0] = (ClientPDEDataContext) ((PDEDataManager) copyThisPDEDatacontext.getDataManager()).createNewPDEDataManager(copyThisPDEDatacontext.getVCDataIdentifier(), null).getPDEDataContext();
    }
    copyHolder[0].setVariableAndTime(copyThisPDEDatacontext.getDataIdentifier(), copyThisPDEDatacontext.getTimePoint());
    return new PdeTimePlotMultipleVariablesPanel.MultiTimePlotHelper() {

        private DataSymbolMetadataResolver dataSymbolMetadataResolver = argDataSymbolMetadataResolver;

        private ArrayList<PropertyChangeListener> myPropertyChangeHolder = new ArrayList<>();

        private ClientPDEDataContext myPdeDataContext = copyHolder[0];

        private VariableType myVariableType = copyThisPDEDatacontext.getDataIdentifier().getVariableType();

        // catch events from 'this' PDEDataViewer and pass with new source
        private PropertyChangeListener myPropertyChangeListener;

        private User myUser = user;

        // List<AnnotatedFunction> myAnnots;
        // access to anonymous outer class
        private PdeTimePlotMultipleVariablesPanel.MultiTimePlotHelper multiTimePlotHelperThis = this;

        private PDEPlotControlPanel.IdentifierListCellRenderer myListCellRenderer;

        private AnnotatedFunction[] lastAnnotatedFunctions;

        private PDEPlotControlPanel.FunctionListProvider functionListProvider = new PDEPlotControlPanel.FunctionListProvider() {

            @Override
            public List<AnnotatedFunction> getAnnotatedFunctions() {
                if (myPdeDataContext.getDataManager().getOutputContext() != null && myPdeDataContext.getDataManager().getOutputContext().getOutputFunctions() != null && myPdeDataContext.getDataManager().getOutputContext().getOutputFunctions().length > 0) {
                    return new ArrayList<>(Arrays.asList(myPdeDataContext.getDataManager().getOutputContext().getOutputFunctions()));
                }
                return new ArrayList<>();
            }
        };

        private Comparator<AnnotatedFunction> nameComparator = new Comparator<AnnotatedFunction>() {

            @Override
            public int compare(AnnotatedFunction o1, AnnotatedFunction o2) {
                return o2.getName().compareToIgnoreCase(o1.getName());
            }
        };

        @Override
        public void removeDataJobListener(DataJobListener dataJobListener) {
            PDEDataViewer.this.removeDataJobListener(dataJobListener);
        }

        @Override
        public void addDataJobListener(DataJobListener dataJobListener) {
            PDEDataViewer.this.addDataJobListener(dataJobListener);
        }

        @Override
        public User getUser() {
            return myUser;
        }

        @Override
        public PDEDataContext getPdeDatacontext() {
            return myPdeDataContext;
        }

        @Override
        public DataIdentifier[] getCopyOfDisplayedDataIdentifiers() {
            DataIdentifier[] newData = PDEDataViewer.this.getPDEPlotControlPanel1().getDataIdentifierFilter().accept(DefaultDataIdentifierFilter.ALL, functionListProvider.getAnnotatedFunctions(), myPdeDataContext.getDataIdentifiers()).toArray(new DataIdentifier[0]);
            return DataIdentifier.collectSortedSimilarDataTypes(this.getVariableType(), newData);
        }

        @Override
        public PDEPlotControlPanel.IdentifierListCellRenderer getListCellRenderer() {
            if (myListCellRenderer == null) {
                myListCellRenderer = new PDEPlotControlPanel.IdentifierListCellRenderer(functionListProvider);
            }
            return myListCellRenderer;
        }

        @Override
        public Simulation getsimulation() {
            return PDEDataViewer.this.getSimulation();
        }

        private List<AnnotatedFunction> efficiencyFilter(List<AnnotatedFunction> funcs) {
            ArrayList<AnnotatedFunction> outputfunctions = new ArrayList<>();
            Iterator<AnnotatedFunction> iter = funcs.iterator();
            while (iter.hasNext()) {
                AnnotatedFunction theFunc = iter.next();
                if ((isPostProcess() && theFunc.getFunctionType().equals(VariableType.POSTPROCESSING)) || (!isPostProcess() && !theFunc.getFunctionType().equals(VariableType.POSTPROCESSING))) {
                    outputfunctions.add(theFunc);
                }
            }
            return outputfunctions;
        }

        @Override
        public void addPropertyChangeListener(PropertyChangeListener propertyChangeListener) {
            myPropertyChangeHolder.add(propertyChangeListener);
            if (myPropertyChangeListener == null) {
                myPropertyChangeListener = new PropertyChangeListener() {

                    @Override
                    public void propertyChange(PropertyChangeEvent evt) {
                        if (evt.getSource() == PDEDataViewer.this && evt.getPropertyName().equals(PDEDataContext.PROP_PDE_DATA_CONTEXT)) {
                            // List<AnnotatedFunction> currentOutputFunctions = functionListProvider.getAnnotatedFunctions();
                            // currentOutputFunctions = efficiencyFilter(currentOutputFunctions);
                            // currentOutputFunctions.sort(nameComparator);
                            List<AnnotatedFunction> newOutputFunctions0 = Arrays.asList(((ClientPDEDataContext) PDEDataViewer.this.getPdeDataContext()).getDataManager().getOutputContext().getOutputFunctions());
                            List<AnnotatedFunction> newOutputFunctions = efficiencyFilter(newOutputFunctions0);
                            newOutputFunctions.sort(nameComparator);
                            if (lastAnnotatedFunctions != null && Compare.isEqualOrNullStrict(lastAnnotatedFunctions, newOutputFunctions.toArray(new AnnotatedFunction[0]))) {
                                return;
                            }
                            lastAnnotatedFunctions = new AnnotatedFunction[newOutputFunctions.size()];
                            for (int i = 0; i < newOutputFunctions.size(); i++) {
                                lastAnnotatedFunctions[i] = new AnnotatedFunction(newOutputFunctions.get(i));
                            }
                            // lastAnnotatedFunctions = newOutputFunctions0.toArray(new AnnotatedFunction[0]);
                            myPdeDataContext.getDataManager().setOutputContext(new OutputContext(newOutputFunctions0.toArray(new AnnotatedFunction[0])));
                            myPdeDataContext.refreshIdentifiers();
                            for (int i = 0; i < myPropertyChangeHolder.size(); i++) {
                                myPropertyChangeHolder.get(i).propertyChange(new PropertyChangeEvent(multiTimePlotHelperThis, SimDataConstants.PROPERTY_NAME_DATAIDENTIFIERS, null, null));
                            }
                        }
                    }
                };
                PDEDataViewer.this.addPropertyChangeListener(myPropertyChangeListener);
            }
        }

        @Override
        public void removeallPropertyChangeListeners() {
            myPropertyChangeHolder.clear();
            if (myPropertyChangeListener != null) {
                PDEDataViewer.this.removePropertyChangeListener(myPropertyChangeListener);
            }
        }

        @Override
        public VariableType getVariableType() {
            return myVariableType;
        }

        // @Override
        // public void addExtraTasks(AsynchClientTask[] moreTasks) {
        // PDEDataViewer.this.addExtraTasks(moreTasks);
        // }
        @Override
        public DataSymbolMetadataResolver getDataSymbolMetadataResolver() {
            return dataSymbolMetadataResolver;
        }
    };
}
Also used : User(org.vcell.util.document.User) VCSimulationDataIdentifier(cbit.vcell.solver.VCSimulationDataIdentifier) LocalVCSimulationDataIdentifier(cbit.vcell.client.ClientSimManager.LocalVCSimulationDataIdentifier) ExternalDataIdentifier(org.vcell.util.document.ExternalDataIdentifier) VCDataIdentifier(org.vcell.util.document.VCDataIdentifier) DataIdentifier(cbit.vcell.simdata.DataIdentifier) PropertyChangeListener(java.beans.PropertyChangeListener) ArrayList(java.util.ArrayList) Comparator(java.util.Comparator) ArrayList(java.util.ArrayList) List(java.util.List) DataJobListener(cbit.rmi.event.DataJobListener) AnnotatedFunction(cbit.vcell.solver.AnnotatedFunction) MultiTimePlotHelper(cbit.vcell.simdata.gui.PdeTimePlotMultipleVariablesPanel.MultiTimePlotHelper) PropertyChangeEvent(java.beans.PropertyChangeEvent) DataSymbolMetadataResolver(cbit.vcell.solver.SimulationModelInfo.DataSymbolMetadataResolver) VariableType(cbit.vcell.math.VariableType) OutputContext(cbit.vcell.simdata.OutputContext) PDEPlotControlPanel(cbit.vcell.simdata.gui.PDEPlotControlPanel) ClientPDEDataContext(cbit.vcell.simdata.ClientPDEDataContext)

Example 24 with DataIdentifier

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

the class PDEExportDataPanel method startExport.

/**
 * Comment
 */
private void startExport() {
    if (getExportSettings1().getSelectedFormat() == ExportFormat.QUICKTIME && getJSlider1().getValue() == getJSlider2().getValue()) {
        DialogUtils.showWarningDialog(this, "User selected 'begin' and 'end' export times are the same.  'Movie' export format 'begin' and 'end' times must be different");
        return;
    }
    DisplayPreferences[] displayPreferences = null;
    @SuppressWarnings("deprecation") Object[] variableSelections = getJListVariables().getSelectedValues();
    boolean selectionHasVolumeVariables = false;
    boolean selectionHasMembraneVariables = false;
    switch(getExportSettings1().getSelectedFormat()) {
        case PLY:
        case QUICKTIME:
        case GIF:
        case FORMAT_JPEG:
        case ANIMATED_GIF:
            {
                displayPreferences = new DisplayPreferences[variableSelections.length];
                StringBuffer noScaleInfoNames = new StringBuffer();
                for (int i = 0; i < displayPreferences.length; i++) {
                    BitSet domainValid = null;
                    try {
                        if (dataInfoProvider != null) {
                            DataIdentifier varSelectionDataIdnetDataIdentifier = null;
                            for (int j = 0; j < dataInfoProvider.getPDEDataContext().getDataIdentifiers().length; j++) {
                                if (dataInfoProvider.getPDEDataContext().getDataIdentifiers()[j].getName().equals(variableSelections[i])) {
                                    varSelectionDataIdnetDataIdentifier = dataInfoProvider.getPDEDataContext().getDataIdentifiers()[j];
                                }
                            }
                            if (varSelectionDataIdnetDataIdentifier != null) {
                                selectionHasVolumeVariables = selectionHasVolumeVariables || varSelectionDataIdnetDataIdentifier.getVariableType().equals(VariableType.VOLUME) || varSelectionDataIdnetDataIdentifier.getVariableType().equals(VariableType.POSTPROCESSING) || varSelectionDataIdnetDataIdentifier.getVariableType().equals(VariableType.VOLUME_REGION);
                                selectionHasMembraneVariables = selectionHasMembraneVariables || varSelectionDataIdnetDataIdentifier.getVariableType().equals(VariableType.MEMBRANE) || varSelectionDataIdnetDataIdentifier.getVariableType().equals(VariableType.MEMBRANE_REGION);
                                CartesianMesh cartesianMesh = dataInfoProvider.getPDEDataContext().getCartesianMesh();
                                int dataLength = cartesianMesh.getDataLength(varSelectionDataIdnetDataIdentifier.getVariableType());
                                domainValid = new BitSet(dataLength);
                                domainValid.clear();
                                for (int j = 0; j < dataLength; j++) {
                                    if (dataInfoProvider.isDefined(varSelectionDataIdnetDataIdentifier, j)) {
                                        domainValid.set(j);
                                    }
                                }
                            } else {
                                throw new Exception("No DataIdentifer found for variable name '" + variableSelections[i] + "'");
                            }
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                        DialogUtils.showErrorDialog(this, "Error during domain evaluation:\n" + e.getMessage());
                        return;
                    }
                    displayPreferences[i] = new DisplayPreferences(getDisplayAdapterService().getDisplayPreferences((String) variableSelections[i]), domainValid);
                    if (!getDisplayAdapterService().hasStateID((String) variableSelections[i])) {
                        noScaleInfoNames.append("--- " + (String) variableSelections[i] + "\n");
                    }
                }
                break;
            }
        case CSV:
            {
                // check for membrane variables... warn for 3D geometry...
                // one gets the whole nine yards by index, not generally useful... except for a few people like Boris :)
                boolean mbVars = false;
                DataIdentifier[] dataIDs = getPdeDataContext().getDataIdentifiers();
                for (int i = 0; i < variableSelections.length; i++) {
                    String varName = (String) variableSelections[i];
                    for (int j = 0; j < dataIDs.length; j++) {
                        if (dataIDs[j].getName().equals(varName) && dataIDs[j].getVariableType().equals(VariableType.MEMBRANE)) {
                            mbVars = true;
                            break;
                        }
                    }
                }
                if (mbVars && getPdeDataContext().getCartesianMesh().getGeometryDimension() == 3 && getJRadioButtonSlice().isSelected()) {
                    String choice = PopupGenerator.showWarningDialog(this, getDataViewerManager().getUserPreferences(), UserMessage.warn_exportMembraneData3D, null);
                    if (choice.equals(UserMessage.OPTION_CANCEL)) {
                        // user canceled
                        return;
                    }
                }
                getExportSettings1().setSimulationSelector(createSimulationSelector());
                getExportSettings1().setIsCSVExport(true);
                break;
            }
        case NRRD:
        case IMAGEJ:
        case UCD:
        case VTK_IMAGE:
        case VTK_UNSTRUCT:
            break;
        default:
            break;
    }
    ;
    if (getJRadioButtonROI().isSelected() && getROISelections().getSelectedIndex() == -1) {
        PopupGenerator.showErrorDialog(this, "To export selections, you must select at least one item from the ROI selection list");
    }
    getExportSettings1().setTimeSpecs(new TimeSpecs(getJSlider1().getValue(), getJSlider2().getValue(), getPdeDataContext().getTimePoints(), ExportConstants.TIME_RANGE));
    getExportSettings1().setDisplayPreferences(displayPreferences, Arrays.asList(variableSelections).toArray(new String[0]), viewZoom);
    getExportSettings1().setSliceCount(FormatSpecificSpecs.getSliceCount(getJRadioButtonFull().isSelected(), getNormalAxis(), getPdeDataContext().getCartesianMesh()));
    getExportSettings1().setImageSizeCalculationInfo(getPdeDataContext().getCartesianMesh(), getNormalAxis());
    getExportSettings1().setIsSmoldyn(isSmoldyn);
    ExportFormat format = getSelectedFormat();
    if (format.equals(ExportFormat.PLY)) {
        getExportSettings1().setFormatSpecificSpecs(new PLYSpecs(true, displayPreferences));
    }
    if (format.requiresFollowOn()) {
        Frame theFrame = JOptionPane.getFrameForComponent(this);
        boolean okToExport = getExportSettings1().showFormatSpecificDialog(theFrame, selectionHasVolumeVariables, selectionHasMembraneVariables);
        if (!okToExport) {
            return;
        }
    }
    if (format.equals(ExportFormat.IMAGEJ)) {
        // export nrrd for imagej direct, the we'll send to imagej from vcell client
        getExportSettings1().setFormatSpecificSpecs(new RasterSpecs(ExportConstants.NRRD_SINGLE, false));
    }
    // determine of sim result is from local (quick) run or on server.
    final OutputContext outputContext = ((ClientPDEDataContext) getPdeDataContext()).getDataManager().getOutputContext();
    final ExportSpecs exportSpecs = getExportSpecs();
    boolean isLocalSimResult = false;
    VCDataIdentifier vcId = exportSpecs.getVCDataIdentifier();
    if (vcId instanceof LocalVCDataIdentifier) {
        isLocalSimResult = true;
    }
    // find out if smoldyn export choice is 'particle' - not available at this time
    boolean isParticle = false;
    if (getExportSettings1().getFormatSpecificSpecs() instanceof ImageSpecs) {
        isParticle = ((ImageSpecs) getExportSettings1().getFormatSpecificSpecs()).getParticleMode() == FormatSpecificSpecs.PARTICLE_SELECT;
    } else if (getExportSettings1().getFormatSpecificSpecs() instanceof MovieSpecs) {
        isParticle = ((MovieSpecs) getExportSettings1().getFormatSpecificSpecs()).getParticleMode() == FormatSpecificSpecs.PARTICLE_SELECT;
    }
    if (isLocalSimResult && isParticle) {
        DialogUtils.showErrorDialog(this, "Particle export for Smoldyn particles unavailable in local data at this time.");
        return;
    }
    // pass the export request down the line; non-blocking call
    if (!isLocalSimResult) {
        // for sims that ran on server, do as before.
        getDataViewerManager().startExport(this, outputContext, exportSpecs);
    } else {
        final String SOURCE_FILE_KEY = "SOURCE_FILE_KEY";
        final String DESTINATION_FILE_KEY = "DEESTINATION_FILE_KEY";
        AsynchClientTask localExportTast = new AsynchClientTask("Start Local Export", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {

            @Override
            public void run(Hashtable<String, Object> hashTable) throws Exception {
                try {
                    File primaryDir = ResourceUtil.getLocalRootDir();
                    User usr = User.tempUser;
                    File usrDir = new File(primaryDir.getAbsolutePath(), usr.getName());
                    System.setProperty(PropertyLoader.exportBaseDirInternalProperty, usrDir.getAbsolutePath() + File.separator);
                    System.setProperty(PropertyLoader.exportBaseURLProperty, usrDir.toURI().toURL().toString());
                    DataSetControllerImpl dataSetControllerImpl = new DataSetControllerImpl(null, primaryDir, null);
                    ExportServiceImpl localExportServiceImpl = new ExportServiceImpl();
                    DataServerImpl dataServerImpl = new DataServerImpl(dataSetControllerImpl, localExportServiceImpl);
                    ExportEvent localExportEvent = dataServerImpl.makeRemoteFile(outputContext, usr, exportSpecs);
                    File sourceFile = new File(usrDir, new File((new URL(localExportEvent.getLocation()).getPath())).getName());
                    hashTable.put(SOURCE_FILE_KEY, sourceFile);
                } catch (Exception e) {
                    throw new Exception("Unable to export local sim results data : " + e.getMessage(), e);
                }
            }
        };
        AsynchClientTask localSaveTask = new AsynchClientTask("Start Local Export", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {

            @Override
            public void run(Hashtable<String, Object> hashTable) throws Exception {
                File sourceFile = (File) hashTable.get(SOURCE_FILE_KEY);
                JFileChooser jFileChooser = new JFileChooser();
                jFileChooser.setSelectedFile(new File(sourceFile.getName()));
                if (jFileChooser.showSaveDialog(PDEExportDataPanel.this) == JFileChooser.APPROVE_OPTION) {
                    File destinationFile = jFileChooser.getSelectedFile();
                    if (destinationFile.exists()) {
                        final String OVERWRITE = "Overwrite";
                        final String CANCEL = "Cancel";
                        String response = DialogUtils.showWarningDialog(PDEExportDataPanel.this, "OK to Overwrite " + destinationFile.getAbsolutePath() + "?", new String[] { OVERWRITE, CANCEL }, OVERWRITE);
                        if (response == null || !response.equals(OVERWRITE)) {
                            return;
                        }
                    }
                    hashTable.put(DESTINATION_FILE_KEY, destinationFile);
                }
            }
        };
        AsynchClientTask localDeleteTempTask = new AsynchClientTask("Start Local Export", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING, false, false) {

            @Override
            public void run(Hashtable<String, Object> hashTable) throws Exception {
                File sourceFile = (File) hashTable.get(SOURCE_FILE_KEY);
                File destinationFile = (File) hashTable.get(DESTINATION_FILE_KEY);
                if (sourceFile != null && sourceFile.exists()) {
                    try {
                        if (destinationFile != null) {
                            copyFile(sourceFile, destinationFile);
                        }
                    } finally {
                        sourceFile.delete();
                    }
                }
            }
        };
        ClientTaskDispatcher.dispatch(this, new Hashtable<String, Object>(), new AsynchClientTask[] { localExportTast, localSaveTask, localDeleteTempTask }, false, true, null);
    }
}
Also used : DataServerImpl(cbit.vcell.simdata.DataServerImpl) JFrame(javax.swing.JFrame) Frame(java.awt.Frame) AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) LocalVCDataIdentifier(org.vcell.util.document.LocalVCDataIdentifier) VCDataIdentifier(org.vcell.util.document.VCDataIdentifier) DataIdentifier(cbit.vcell.simdata.DataIdentifier) User(org.vcell.util.document.User) RasterSpecs(cbit.vcell.export.server.RasterSpecs) ExportSpecs(cbit.vcell.export.server.ExportSpecs) ExportEvent(cbit.rmi.event.ExportEvent) URL(java.net.URL) DisplayPreferences(cbit.image.DisplayPreferences) ExportServiceImpl(cbit.vcell.export.server.ExportServiceImpl) TimeSpecs(cbit.vcell.export.server.TimeSpecs) Hashtable(java.util.Hashtable) PLYSpecs(cbit.vcell.export.server.PLYSpecs) BitSet(java.util.BitSet) ExportFormat(cbit.vcell.export.server.ExportFormat) LocalVCDataIdentifier(org.vcell.util.document.LocalVCDataIdentifier) IOException(java.io.IOException) UserCancelException(org.vcell.util.UserCancelException) OutputContext(cbit.vcell.simdata.OutputContext) CartesianMesh(cbit.vcell.solvers.CartesianMesh) MovieSpecs(cbit.vcell.export.server.MovieSpecs) JFileChooser(javax.swing.JFileChooser) ImageSpecs(cbit.vcell.export.server.ImageSpecs) DataSetControllerImpl(cbit.vcell.simdata.DataSetControllerImpl) LocalVCDataIdentifier(org.vcell.util.document.LocalVCDataIdentifier) VCDataIdentifier(org.vcell.util.document.VCDataIdentifier) File(java.io.File)

Example 25 with DataIdentifier

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

the class DefaultDataIdentifierFilter method accept.

public ArrayList<DataIdentifier> accept(String filterSetName, List<AnnotatedFunction> functionList, DataIdentifier[] filterTheseDataIdentifiers) {
    // 
    if (dataSymbolMetadataResolver != null) {
        ArrayList<String> allFilterNames = new ArrayList<String>();
        if (this.dataSymbolMetadataResolver != null) {
            ModelCategoryType[] uniqueCategories = dataSymbolMetadataResolver.getUniqueFilterCategories();
            for (ModelCategoryType catType : uniqueCategories) {
                allFilterNames.add(catType.getName());
            }
        }
        if (allFilterNames.contains(filterSetName)) {
            ArrayList<DataIdentifier> acceptedDataIdentifiers = new ArrayList<DataIdentifier>();
            for (DataIdentifier dataID : filterTheseDataIdentifiers) {
                DataSymbolMetadata metadata = dataSymbolMetadataResolver.getDataSymbolMetadata(dataID.getName());
                if (metadata != null && metadata.filterCategory.getName().equals(filterSetName)) {
                    String varName = dataID.getName();
                    if (varName.startsWith(MathFunctionDefinitions.Function_regionVolume_current.getFunctionName())) {
                        continue;
                    }
                    if (varName.startsWith(MathFunctionDefinitions.Function_regionArea_current.getFunctionName())) {
                        continue;
                    }
                    acceptedDataIdentifiers.add(dataID);
                }
            }
            return acceptedDataIdentifiers;
        }
    }
    ArrayList<DataIdentifier> acceptedDataIdentifiers = new ArrayList<DataIdentifier>();
    for (int i = 0; i < filterTheseDataIdentifiers.length; i++) {
        if (bPostProcessingMode && filterTheseDataIdentifiers[i].getVariableType().equals(VariableType.POSTPROCESSING)) {
            acceptedDataIdentifiers.add(filterTheseDataIdentifiers[i]);
            continue;
        }
        if (bPostProcessingMode && !filterTheseDataIdentifiers[i].getVariableType().equals(VariableType.POSTPROCESSING)) {
            continue;
        }
        if (!bPostProcessingMode && filterTheseDataIdentifiers[i].getVariableType().equals(VariableType.POSTPROCESSING)) {
            continue;
        }
        String varName = filterTheseDataIdentifiers[i].getName();
        if (varName.startsWith(MathFunctionDefinitions.Function_regionVolume_current.getFunctionName())) {
            continue;
        }
        if (varName.startsWith(MathFunctionDefinitions.Function_regionArea_current.getFunctionName())) {
            continue;
        }
        boolean bSizeVar = varName.startsWith(DiffEquMathMapping.PARAMETER_SIZE_FUNCTION_PREFIX);
        if (filterSetName.equals(REGION_SIZE_FILTER_SET) && bSizeVar) {
            acceptedDataIdentifiers.add(filterTheseDataIdentifiers[i]);
            continue;
        }
        if (!filterSetName.equals(REGION_SIZE_FILTER_SET) && bSizeVar) {
            continue;
        }
        if (filterSetName.equals(ALL)) {
            acceptedDataIdentifiers.add(filterTheseDataIdentifiers[i]);
        } else if (filterSetName.equals(VOLUME_FILTER_SET) && filterTheseDataIdentifiers[i].getVariableType().getVariableDomain().equals(VariableDomain.VARIABLEDOMAIN_VOLUME)) {
            acceptedDataIdentifiers.add(filterTheseDataIdentifiers[i]);
        } else if (filterSetName.equals(MEMBRANE_FILTER_SET) && filterTheseDataIdentifiers[i].getVariableType().getVariableDomain().equals(VariableDomain.VARIABLEDOMAIN_MEMBRANE)) {
            acceptedDataIdentifiers.add(filterTheseDataIdentifiers[i]);
        } else if (filterSetName.equals(USER_DEFINED_FILTER_SET)) {
            if (functionList != null) {
                for (AnnotatedFunction f : functionList) {
                    if (!f.isPredefined() && f.getName().equals(varName)) {
                        acceptedDataIdentifiers.add(filterTheseDataIdentifiers[i]);
                        break;
                    }
                }
            }
        }
    }
    if (acceptedDataIdentifiers.size() > 0) {
        return acceptedDataIdentifiers;
    }
    return null;
}
Also used : DataIdentifier(cbit.vcell.simdata.DataIdentifier) ModelCategoryType(cbit.vcell.solver.SimulationModelInfo.ModelCategoryType) ArrayList(java.util.ArrayList) DataSymbolMetadata(cbit.vcell.solver.DataSymbolMetadata) AnnotatedFunction(cbit.vcell.solver.AnnotatedFunction)

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