Search in sources :

Example 31 with VCDataIdentifier

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

the class FRAPStudyPanel method refreshPDEDisplay.

protected void refreshPDEDisplay(DisplayChoice choice) throws Exception {
    Simulation sim = null;
    FRAPStudy fStudy = getFrapWorkspace().getWorkingFrapStudy();
    if (fStudy == null || fStudy.getBioModel() == null || fStudy.getBioModel().getSimulations() == null || fStudy.getBioModel().getSimulations().length < 1) {
        return;
    }
    sim = fStudy.getBioModel().getSimulations()[0];
    FieldFunctionArguments[] fieldFunctionArgs = FieldUtilities.getFieldFunctionArguments(sim.getMathDescription());
    FieldDataIdentifierSpec[] fieldDataIdentifierSpecs = new FieldDataIdentifierSpec[fieldFunctionArgs.length];
    for (int i = 0; i < fieldDataIdentifierSpecs.length; i++) {
        fieldDataIdentifierSpecs[i] = new FieldDataIdentifierSpec(fieldFunctionArgs[i], fStudy.getFrapDataExternalDataInfo().getExternalDataIdentifier());
    }
    PDEDataViewer flourViewer = getFlourDataViewer();
    PDEDataManager dataManager = null;
    if (choice == DisplayChoice.EXTTIMEDATA) {
        flourViewer.setSimulation(null);
        flourViewer.setPdeDataContext(null);
        flourViewer.setDataIdentifierFilter(new DataIdentifierFilter() {

            private String ALL_DATAIDENTIFIERS = "All";

            private String EXP_NORM_FLUOR = "Exp. Norm. Fluor";

            private String SIM_NORM_FLUOR = "Sim. Norm. Fluor";

            private String DEFAULT_VIEW = "Default View (more...)";

            private String[] filterSetNames = new String[] { ALL_DATAIDENTIFIERS, EXP_NORM_FLUOR, SIM_NORM_FLUOR, DEFAULT_VIEW };

            public boolean accept(String filterSetName, List<AnnotatedFunction> myFunctionList, DataIdentifier dataidentifier) {
                if (filterSetName.equals(ALL_DATAIDENTIFIERS)) {
                    return true;
                } else if (filterSetName.equals(EXP_NORM_FLUOR)) {
                    return dataidentifier.getName().indexOf(NORM_FLUOR_VAR) != -1;
                } else if (filterSetName.equals(SIM_NORM_FLUOR)) {
                    boolean a = (dataidentifier.getName().indexOf(REACTION_RATE_PREFIX) == -1) && ((dataidentifier.getName().indexOf(FRAPStudy.SPECIES_NAME_PREFIX_COMBINED) != -1) || (dataidentifier.getName().indexOf(FRAPStudy.SPECIES_NAME_PREFIX_IMMOBILE) != -1) || (dataidentifier.getName().indexOf(FRAPStudy.SPECIES_NAME_PREFIX_MOBILE) != -1) || (dataidentifier.getName().indexOf(FRAPStudy.SPECIES_NAME_PREFIX_SLOW_MOBILE) != -1));
                    return a;
                } else if (filterSetName.equals(DEFAULT_VIEW)) {
                    boolean a = (dataidentifier.getName().indexOf(REACTION_RATE_PREFIX) == -1) && ((dataidentifier.getName().indexOf(NORM_FLUOR_VAR) != -1) || (dataidentifier.getName().indexOf(NORM_SIM_VAR) != -1));
                    return a;
                }
                throw new IllegalArgumentException("DataIdentifierFilter: Unknown filterSetName " + filterSetName);
            }

            public String getDefaultFilterName() {
                return DEFAULT_VIEW;
            }

            public String[] getFilterSetNames() {
                return filterSetNames;
            }

            public boolean isAcceptAll(String filterSetName) {
                return filterSetName.equals(ALL_DATAIDENTIFIERS);
            }

            @Override
            public void setPostProcessingMode(boolean bPostProcessingMode) {
            // TODO Auto-generated method stub
            }

            @Override
            public boolean isPostProcessingMode() {
                // TODO Auto-generated method stub
                return false;
            }

            @Override
            public ArrayList<DataIdentifier> accept(String filterSetName, List<AnnotatedFunction> myFunctionList, DataIdentifier[] dataidentifiers) {
                if (filterSetName.equals(DEFAULT_VIEW)) {
                    ArrayList<DataIdentifier> dataIds = new ArrayList<>();
                    if (dataidentifiers != null) {
                        for (int i = 0; i < dataidentifiers.length; i++) {
                            dataIds.add(dataidentifiers[i]);
                        }
                    }
                    return dataIds;
                }
                throw new RuntimeException("Not Implemented for FRAP");
            }
        });
        ExternalDataIdentifier timeSeriesExtDataID = fStudy.getFrapDataExternalDataInfo().getExternalDataIdentifier();
        ExternalDataIdentifier maskExtDataID = fStudy.getRoiExternalDataInfo().getExternalDataIdentifier();
        // add sim
        int jobIndex = 0;
        SimulationJob simJob = new SimulationJob(sim, jobIndex, fieldDataIdentifierSpecs);
        // add function to display normalized fluorence data
        Norm_Exp_Fluor = new Expression(Norm_Exp_Fluor_Str);
        SimulationSymbolTable simSymbolTable = simJob.getSimulationSymbolTable();
        if (// one diffusing component
        simSymbolTable.getVariable(FRAPStudy.SPECIES_NAME_PREFIX_SLOW_MOBILE) == null) {
            Norm_Sim = new Expression(Norm_Sim_One_Diff_Str);
        } else // two diffusing components
        {
            Norm_Sim = new Expression(Norm_Sim_Two_Diff_Str);
        }
        AnnotatedFunction[] func = { new AnnotatedFunction(NORM_FLUOR_VAR, Norm_Exp_Fluor, null, null, VariableType.VOLUME, FunctionCategory.OLDUSERDEFINED), new AnnotatedFunction(NORM_SIM_VAR, Norm_Sim, null, null, VariableType.VOLUME, FunctionCategory.OLDUSERDEFINED) };
        VCDataIdentifier[] dataIDs = new VCDataIdentifier[] { timeSeriesExtDataID, maskExtDataID, simJob.getVCDataIdentifier() };
        VCDataIdentifier vcDataId = new MergedDataInfo(LocalWorkspace.getDefaultOwner(), dataIDs, FRAPStudy.VFRAP_DS_PREFIX);
        outputContext = new OutputContext(func);
        dataManager = new PDEDataManager(outputContext, getLocalWorkspace().getVCDataManager(), vcDataId);
        ClientPDEDataContext pdeDataContext = new ClientPDEDataContext(dataManager);
        pdeDataContext.refreshIdentifiers();
        flourViewer.setSimulation(sim);
        flourViewer.setPdeDataContext(pdeDataContext);
        SimulationModelInfo simModelInfo = new SimulationWorkspaceModelInfo(fStudy.getBioModel().getSimulationContext(sim), sim.getName());
        flourViewer.setSimulationModelInfo(simModelInfo);
        getLocalWorkspace().getDataSetControllerImpl().addDataJobListener(flourViewer);
        ((VirtualFrapWindowManager) flourViewer.getDataViewerManager()).setLocalWorkSpace(getLocalWorkspace());
        // do now show post data processing for VFRAP
        flourViewer.setPostProcessingPanelVisible(false);
        flourViewer.repaint();
    }
}
Also used : ExternalDataIdentifier(org.vcell.util.document.ExternalDataIdentifier) VCDataIdentifier(org.vcell.util.document.VCDataIdentifier) DataIdentifier(cbit.vcell.simdata.DataIdentifier) ArrayList(java.util.ArrayList) MergedDataInfo(cbit.vcell.simdata.MergedDataInfo) ExternalDataIdentifier(org.vcell.util.document.ExternalDataIdentifier) FRAPStudy(cbit.vcell.microscopy.FRAPStudy) SimulationWorkspaceModelInfo(cbit.vcell.client.data.SimulationWorkspaceModelInfo) SimulationJob(cbit.vcell.solver.SimulationJob) AnnotatedFunction(cbit.vcell.solver.AnnotatedFunction) DataIdentifierFilter(cbit.vcell.client.data.DataIdentifierFilter) SimulationModelInfo(cbit.vcell.solver.SimulationModelInfo) FieldFunctionArguments(cbit.vcell.field.FieldFunctionArguments) SimulationSymbolTable(cbit.vcell.solver.SimulationSymbolTable) Point(java.awt.Point) OutputContext(cbit.vcell.simdata.OutputContext) Simulation(cbit.vcell.solver.Simulation) PDEDataManager(cbit.vcell.simdata.PDEDataManager) Expression(cbit.vcell.parser.Expression) FieldDataIdentifierSpec(cbit.vcell.field.FieldDataIdentifierSpec) ClientPDEDataContext(cbit.vcell.simdata.ClientPDEDataContext) VCDataIdentifier(org.vcell.util.document.VCDataIdentifier) PDEDataViewer(cbit.vcell.client.data.PDEDataViewer)

Example 32 with VCDataIdentifier

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

the class FRAPStudyPanel method showMovie.

private void showMovie() {
    AsynchClientTask createMovieTask = new AsynchClientTask("Buffering movie data...", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {

        public void run(Hashtable<String, Object> hashTable) throws Exception {
            FRAPStudy fStudy = getFrapWorkspace().getWorkingFrapStudy();
            if (fStudy == null) {
                return;
            }
            if (fStudy.getMovieURLString() != null && fStudy.getMovieFileString() != null) {
                hashTable.put("FrapStudy", fStudy);
                return;
            }
            // create export specs
            Simulation sim = null;
            if (fStudy.getBioModel() == null || fStudy.getBioModel().getSimulations() == null || fStudy.getBioModel().getSimulations().length < 1) {
                return;
            } else {
                sim = fStudy.getBioModel().getSimulations()[0];
            }
            FieldFunctionArguments[] fieldFunctionArgs = FieldUtilities.getFieldFunctionArguments(sim.getMathDescription());
            FieldDataIdentifierSpec[] fieldDataIdentifierSpecs = new FieldDataIdentifierSpec[fieldFunctionArgs.length];
            for (int i = 0; i < fieldDataIdentifierSpecs.length; i++) {
                fieldDataIdentifierSpecs[i] = new FieldDataIdentifierSpec(fieldFunctionArgs[i], fStudy.getFrapDataExternalDataInfo().getExternalDataIdentifier());
            }
            ExternalDataIdentifier timeSeriesExtDataID = fStudy.getFrapDataExternalDataInfo().getExternalDataIdentifier();
            ExternalDataIdentifier maskExtDataID = fStudy.getRoiExternalDataInfo().getExternalDataIdentifier();
            // add sim
            int jobIndex = 0;
            SimulationJob simJob = new SimulationJob(sim, jobIndex, fieldDataIdentifierSpecs);
            VCDataIdentifier[] dataIDs = new VCDataIdentifier[] { timeSeriesExtDataID, maskExtDataID, simJob.getVCDataIdentifier() };
            VCDataIdentifier vcDataId = new MergedDataInfo(LocalWorkspace.getDefaultOwner(), dataIDs, FRAPStudy.VFRAP_DS_PREFIX);
            PDEDataManager dataManager = new PDEDataManager(null, getLocalWorkspace().getVCDataManager(), vcDataId);
            PDEDataContext pdeDataContext = new ClientPDEDataContext(dataManager);
            ExportFormat format = ExportFormat.QUICKTIME;
            String[] variableNames = new String[] { NORM_FLUOR_VAR, NORM_SIM_VAR };
            VariableSpecs variableSpecs = new VariableSpecs(variableNames, ExportConstants.VARIABLE_MULTI);
            // int endTimeIndex = (int)Math.round(sim.getSolverTaskDescription().getTimeBounds().getEndingTime()/((UniformOutputTimeSpec)sim.getSolverTaskDescription().getOutputTimeSpec()).getOutputTimeStep());
            int endTimeIndex = getFRAPSimDataViewerPanel().getOriginalDataViewer().getPdeDataContext().getTimePoints().length - 1;
            TimeSpecs timeSpecs = new TimeSpecs(0, endTimeIndex, pdeDataContext.getTimePoints(), ExportConstants.TIME_RANGE);
            int geoMode = ExportConstants.GEOMETRY_SLICE;
            GeometrySpecs geometrySpecs = new GeometrySpecs(null, Coordinate.Z_AXIS, 0, geoMode);
            // 10s
            double duration = 10000;
            DisplayPreferences pref1 = new DisplayPreferences("BlueRed", new Range(0.01, 1.1), DisplayAdapterService.createBlueRedSpecialColors());
            DisplayPreferences pref2 = new DisplayPreferences("BlueRed", new Range(0.01, 1.1), DisplayAdapterService.createBlueRedSpecialColors());
            DisplayPreferences[] displayPref = new DisplayPreferences[] { pref1, pref2 };
            int imageScale = 1;
            int membraneScale = 1;
            int scaleMode = ImagePaneModel.MESH_MODE;
            // the default setting in MediaSettingsPanel.
            int volVarMemOutlineThickness = 1;
            MovieSpecs mSpec = new MovieSpecs(duration, true, displayPref, ExportFormat.QUICKTIME, ExportConstants.NO_MIRRORING, volVarMemOutlineThickness, imageScale, membraneScale, scaleMode, FormatSpecificSpecs.CODEC_JPEG, 1.0f, /*lossless*/
            false, FormatSpecificSpecs.PARTICLE_NONE);
            // mSpec.setViewZoom(1);
            ExportSpecs exSpecs = new ExportSpecs(vcDataId, format, variableSpecs, timeSpecs, geometrySpecs, mSpec, fStudy.getName(), null);
            // pass the request
            ExportEvent exportEvt = ((VirtualFrapWindowManager) getFlourDataViewer().getDataViewerManager()).startExportMovie(exSpecs, outputContext, this.getClientTaskStatusSupport());
            hashTable.put("ExportEvt", exportEvt);
            hashTable.put("FrapStudy", fStudy);
        }
    };
    AsynchClientTask showMovieTask = new AsynchClientTask("Showing movie ...", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {

        public void run(Hashtable<String, Object> hashTable) throws Exception {
            ExportEvent exportEvt = (ExportEvent) hashTable.get("ExportEvt");
            FRAPStudy fStudy = (FRAPStudy) hashTable.get("FrapStudy");
            // show movie if successfully exported
            if (exportEvt != null) {
                final String fileURLString = System.getProperty(PropertyLoader.exportBaseURLProperty) + exportEvt.getJobID() + ".mov";
                final String fileString = System.getProperty(PropertyLoader.exportBaseDirInternalProperty) + exportEvt.getJobID() + ".mov";
                fStudy.setMovieURLString(fileURLString);
                fStudy.setMovieFileString(fileString);
            }
            showMovieInDialog(fStudy.getMovieURLString(), fStudy.getMovieFileString());
        }
    };
    ClientTaskDispatcher.dispatch(this, new Hashtable<String, Object>(), new AsynchClientTask[] { createMovieTask, showMovieTask }, true, true, null, true);
}
Also used : ClientPDEDataContext(cbit.vcell.simdata.ClientPDEDataContext) PDEDataContext(cbit.vcell.simdata.PDEDataContext) AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) ExportSpecs(cbit.vcell.export.server.ExportSpecs) ExportEvent(cbit.rmi.event.ExportEvent) GeometrySpecs(cbit.vcell.export.server.GeometrySpecs) MergedDataInfo(cbit.vcell.simdata.MergedDataInfo) DisplayPreferences(cbit.image.DisplayPreferences) ExternalDataIdentifier(org.vcell.util.document.ExternalDataIdentifier) FRAPStudy(cbit.vcell.microscopy.FRAPStudy) TimeSpecs(cbit.vcell.export.server.TimeSpecs) SimulationJob(cbit.vcell.solver.SimulationJob) FieldFunctionArguments(cbit.vcell.field.FieldFunctionArguments) Hashtable(java.util.Hashtable) ExportFormat(cbit.vcell.export.server.ExportFormat) Range(org.vcell.util.Range) Point(java.awt.Point) VariableSpecs(cbit.vcell.export.server.VariableSpecs) MovieSpecs(cbit.vcell.export.server.MovieSpecs) Simulation(cbit.vcell.solver.Simulation) PDEDataManager(cbit.vcell.simdata.PDEDataManager) FieldDataIdentifierSpec(cbit.vcell.field.FieldDataIdentifierSpec) ClientPDEDataContext(cbit.vcell.simdata.ClientPDEDataContext) VCDataIdentifier(org.vcell.util.document.VCDataIdentifier)

Example 33 with VCDataIdentifier

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

the class ASCIIExporter method sofyaFormat.

private ExportOutput sofyaFormat(OutputContext outputContext, long jobID, User user, DataServerImpl dataServerImpl, final VCDataIdentifier orig_vcdID, VariableSpecs variableSpecs, TimeSpecs timeSpecs, GeometrySpecs geometrySpecs, ASCIISpecs asciiSpecs, String contextName, FileDataContainerManager fileDataContainerManager) throws DataAccessException, IOException {
    ExportSpecs.SimNameSimDataID[] simNameSimDataIDs = asciiSpecs.getSimNameSimDataIDs();
    // use mesh to calulate indexes
    CartesianMesh mesh = dataServerImpl.getMesh(user, orig_vcdID);
    final int SIM_COUNT = simNameSimDataIDs.length;
    final int PARAMSCAN_COUNT = (asciiSpecs.getExportMultipleParamScans() != null ? asciiSpecs.getExportMultipleParamScans().length : 1);
    final int TIME_COUNT = timeSpecs.getEndTimeIndex() - timeSpecs.getBeginTimeIndex() + 1;
    if (PARAMSCAN_COUNT > 1 || geometrySpecs.getModeID() != GEOMETRY_SELECTIONS) /* || geometrySpecs.getCurves().length != 0*/
    {
        throw new DataAccessException("Alternate csv format cannot have parameter scans and must be 'point selection' type");
    }
    // millisecodns
    final long MESSAGE_LIMIT = 5000;
    final long MAX_DATA = 10000000;
    long totalPoints = SIM_COUNT * TIME_COUNT * variableSpecs.getVariableNames().length * geometrySpecs.getPointCount();
    if (totalPoints > MAX_DATA) {
        throw new DataAccessException("Too much data, select fewer (sims or times or variables or samplepoints).  Exceeded limit by " + NumberUtils.formatNumber(100 * (((double) totalPoints / (double) MAX_DATA) - 1.0), 6) + "%");
    }
    ExportOutput exportOutput1 = new ExportOutput(true, ".csv", SIM_COUNT + "_multisims_", variableSpecs.getVariableNames().length + "_Vars_" + TIME_COUNT + "_times", fileDataContainerManager);
    fileDataContainerManager.append(exportOutput1.getFileDataContainerID(), "\"Model:'" + contextName + "'\"\n\n");
    int[] sampleIndexes = getallSampleIndexes(geometrySpecs, mesh);
    int[][] indexes = new int[variableSpecs.getVariableNames().length][];
    HashMap<Integer, TSJobResultsNoStats> simData = new HashMap<>();
    long lastTime = 0;
    double progressCounter = 0;
    for (int t = 0; t < TIME_COUNT; t++) {
        fileDataContainerManager.append(exportOutput1.getFileDataContainerID(), "Time," + timeSpecs.getAllTimes()[timeSpecs.getBeginTimeIndex() + t] + "\n");
        for (int simIndex = 0; simIndex < SIM_COUNT; simIndex++) {
            progressCounter++;
            if ((System.currentTimeMillis() - lastTime) > MESSAGE_LIMIT) {
                lastTime = System.currentTimeMillis();
                exportServiceImpl.fireExportProgress(jobID, orig_vcdID, "multisim-point", progressCounter / (SIM_COUNT * TIME_COUNT));
            }
            int simJobIndex = simNameSimDataIDs[simIndex].getDefaultJobIndex();
            VCDataIdentifier vcdID = simNameSimDataIDs[simIndex].getVCDataIdentifier(simJobIndex);
            if (SIM_COUNT > 1) {
                // check times are the same
                double[] currentTimes = dataServerImpl.getDataSetTimes(user, vcdID);
                if (currentTimes.length != timeSpecs.getAllTimes().length) {
                    throw new DataAccessException("time sets are different length");
                }
                for (int i = 0; i < currentTimes.length; i++) {
                    if (timeSpecs.getAllTimes()[i] != currentTimes[i]) {
                        throw new DataAccessException("time sets have different values");
                    }
                }
            }
            SpatialSelection[] spatialSelections = geometrySpecs.getSelections();
            mesh = dataServerImpl.getMesh(user, vcdID);
            for (int i = 0; i < spatialSelections.length; i++) {
                if (spatialSelections[i].getMesh() == null) {
                    spatialSelections[i].setMesh(mesh);
                } else if (!spatialSelections[i].getMesh().getISize().compareEqual(mesh.getISize()) || spatialSelections[i].getMesh().getNumMembraneElements() != mesh.getNumMembraneElements()) {
                    // check just sizes not areas,normals,etc...
                    // This will throw fail message
                    spatialSelections[i].setMesh(mesh);
                }
            }
            if (simIndex == 0) {
                fileDataContainerManager.append(exportOutput1.getFileDataContainerID(), "Variables-->,");
                for (int v = 0; v < variableSpecs.getVariableNames().length; v++) {
                    fileDataContainerManager.append(exportOutput1.getFileDataContainerID(), "\"" + variableSpecs.getVariableNames()[v] + "\"");
                    for (int p = 0; p < sampleIndexes.length; p++) {
                        fileDataContainerManager.append(exportOutput1.getFileDataContainerID(), ",");
                    }
                }
                fileDataContainerManager.append(exportOutput1.getFileDataContainerID(), "\n\"Simulation Name : (point/line)Index-->\",");
                for (int v = 0; v < variableSpecs.getVariableNames().length; v++) {
                    indexes[v] = sampleIndexes;
                    for (int p = 0; p < sampleIndexes.length; p++) {
                        fileDataContainerManager.append(exportOutput1.getFileDataContainerID(), sampleIndexes[p] + ",");
                    }
                }
                fileDataContainerManager.append(exportOutput1.getFileDataContainerID(), "\n");
            }
            fileDataContainerManager.append(exportOutput1.getFileDataContainerID(), "\"" + simNameSimDataIDs[simIndex].getSimulationName() + "\"");
            TSJobResultsNoStats timeSeriesJobResults = simData.get(simIndex);
            if (timeSeriesJobResults == null) {
                TimeSeriesJobSpec timeSeriesJobSpec = new TimeSeriesJobSpec(variableSpecs.getVariableNames(), indexes, null, timeSpecs.getAllTimes()[timeSpecs.getBeginTimeIndex()], 1, timeSpecs.getAllTimes()[timeSpecs.getEndTimeIndex()], VCDataJobID.createVCDataJobID(user, false));
                timeSeriesJobResults = (TSJobResultsNoStats) dataServerImpl.getTimeSeriesValues(outputContext, user, vcdID, timeSeriesJobSpec);
                simData.put(simIndex, timeSeriesJobResults);
            }
            // the length of variableValues[n] is allTimes.length
            for (int v = 0; v < variableSpecs.getVariableNames().length; v++) {
                final double[][] variableValues = timeSeriesJobResults.getTimesAndValuesForVariable(variableSpecs.getVariableNames()[v]);
                for (int p = 0; p < sampleIndexes.length; p++) {
                    fileDataContainerManager.append(exportOutput1.getFileDataContainerID(), "," + variableValues[p + 1][t]);
                }
            }
            fileDataContainerManager.append(exportOutput1.getFileDataContainerID(), "\n");
        }
        fileDataContainerManager.append(exportOutput1.getFileDataContainerID(), "\n");
    }
    return exportOutput1;
}
Also used : TimeSeriesJobSpec(org.vcell.util.document.TimeSeriesJobSpec) HashMap(java.util.HashMap) SinglePoint(cbit.vcell.geometry.SinglePoint) CartesianMesh(cbit.vcell.solvers.CartesianMesh) SpatialSelection(cbit.vcell.simdata.SpatialSelection) VCDataIdentifier(org.vcell.util.document.VCDataIdentifier) DataAccessException(org.vcell.util.DataAccessException) TSJobResultsNoStats(org.vcell.util.document.TSJobResultsNoStats)

Example 34 with VCDataIdentifier

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

the class ASCIIExporter method exportPDEData.

/**
 * This method was created in VisualAge.
 * @throws IOException
 */
private List<ExportOutput> exportPDEData(OutputContext outputContext, long jobID, User user, DataServerImpl dataServerImpl, final VCDataIdentifier orig_vcdID, VariableSpecs variableSpecs, TimeSpecs timeSpecs, GeometrySpecs geometrySpecs, ASCIISpecs asciiSpecs, String contextName, FileDataContainerManager fileDataContainerManager) throws DataAccessException, IOException {
    ExportSpecs.SimNameSimDataID[] simNameSimDataIDs = asciiSpecs.getSimNameSimDataIDs();
    Vector<ExportOutput[]> exportOutputV = new Vector<ExportOutput[]>();
    double progressCounter = 0;
    final int SIM_COUNT = simNameSimDataIDs.length;
    final int PARAMSCAN_COUNT = (asciiSpecs.getExportMultipleParamScans() != null ? asciiSpecs.getExportMultipleParamScans().length : 1);
    final int endTimeIndex = timeSpecs.getEndTimeIndex();
    final int beginTimeIndex = timeSpecs.getBeginTimeIndex();
    final int TIME_COUNT = endTimeIndex - beginTimeIndex + 1;
    double TOTAL_EXPORTS_OPS = 0;
    switch(geometrySpecs.getModeID()) {
        case GEOMETRY_SELECTIONS:
            TOTAL_EXPORTS_OPS = SIM_COUNT * PARAMSCAN_COUNT * variableSpecs.getVariableNames().length * (geometrySpecs.getCurves().length + (geometrySpecs.getPointCount() > 0 ? 1 : 0));
            break;
        case GEOMETRY_SLICE:
            TOTAL_EXPORTS_OPS = SIM_COUNT * PARAMSCAN_COUNT * variableSpecs.getVariableNames().length * TIME_COUNT;
            break;
    }
    if (asciiSpecs.getCSVRoiLayout() == ASCIISpecs.csvRoiLayout.time_sim_var) {
        exportOutputV.add(new ExportOutput[] { sofyaFormat(outputContext, jobID, user, dataServerImpl, orig_vcdID, variableSpecs, timeSpecs, geometrySpecs, asciiSpecs, contextName, fileDataContainerManager) });
    } else {
        for (int v = 0; v < SIM_COUNT; v++) {
            int simJobIndex = simNameSimDataIDs[v].getDefaultJobIndex();
            VCDataIdentifier vcdID = simNameSimDataIDs[v].getVCDataIdentifier(simJobIndex);
            // 3. simNameSimDataIDs[v].getExportParamScanInfo() != null and asciiSpecs.getExportMultipleParamScans() != null, parameter scan use simNameSimDataIDs[v].getExportParamScanInfo().getParamScanJobIndexes() loop through
            for (int ps = 0; ps < PARAMSCAN_COUNT; ps++) {
                if (asciiSpecs.getExportMultipleParamScans() != null) {
                    simJobIndex = simNameSimDataIDs[v].getExportParamScanInfo().getParamScanJobIndexes()[asciiSpecs.getExportMultipleParamScans()[ps]];
                    vcdID = simNameSimDataIDs[v].getVCDataIdentifier(simJobIndex);
                }
                // Get times for each sim{paramscan} because they may be different
                final double[] allTimes = dataServerImpl.getDataSetTimes(user, vcdID);
                if (allTimes.length <= beginTimeIndex || allTimes.length <= endTimeIndex) {
                    throw new DataAccessException("Sim '" + simNameSimDataIDs[v].getSimulationName() + "' id=" + vcdID.getID() + " simJob=" + simJobIndex + ", time array length=" + allTimes.length + " has no endTimeIndex=" + endTimeIndex);
                }
                String paramScanInfo = "";
                if (simNameSimDataIDs[v].getExportParamScanInfo() != null) {
                    for (int i = 0; i < simNameSimDataIDs[v].getExportParamScanInfo().getParamScanConstantNames().length; i++) {
                        String psName = simNameSimDataIDs[v].getExportParamScanInfo().getParamScanConstantNames()[i];
                        paramScanInfo = paramScanInfo + " '" + psName + "'=" + simNameSimDataIDs[v].getExportParamScanInfo().getParamScanConstantValues()[simJobIndex][i];
                    }
                }
                String simID = vcdID.getID();
                String dataType = ".csv";
                FileDataContainerID fileDataContainerID_header = fileDataContainerManager.getNewFileDataContainerID();
                SimulationDescription simulationDescription = new SimulationDescription(outputContext, user, dataServerImpl, vcdID, false, null);
                fileDataContainerManager.append(fileDataContainerID_header, "\"" + "Model: '" + contextName + "'\"\n\"Simulation: '" + simNameSimDataIDs[v].getSimulationName() + "' (" + paramScanInfo + ")\"\n" + simulationDescription.getHeader(dataType));
                switch(geometrySpecs.getModeID()) {
                    case GEOMETRY_SELECTIONS:
                        {
                            // Set mesh on SpatialSelection because mesh is transient field because it's too big for messaging
                            SpatialSelection[] spatialSelections = geometrySpecs.getSelections();
                            CartesianMesh mesh = dataServerImpl.getMesh(user, vcdID);
                            for (int i = 0; i < spatialSelections.length; i++) {
                                if (spatialSelections[i].getMesh() == null) {
                                    spatialSelections[i].setMesh(mesh);
                                } else if (!spatialSelections[i].getMesh().getISize().compareEqual(mesh.getISize()) || spatialSelections[i].getMesh().getNumMembraneElements() != mesh.getNumMembraneElements()) {
                                    // check just sizes not areas,normals,etc...
                                    // This will throw fail message
                                    spatialSelections[i].setMesh(mesh);
                                }
                            }
                            Vector<ExportOutput> outputV = new Vector<ExportOutput>();
                            if (geometrySpecs.getPointCount() > 0) {
                                // assemble single point data together (uses more compact formatting)
                                String dataID = "_Points_vars(" + geometrySpecs.getPointCount() + ")_times(" + (endTimeIndex - beginTimeIndex + 1) + ")";
                                // StringBuilder data1 = new StringBuilder(data.toString());
                                ExportOutput exportOutput1 = new ExportOutput(true, dataType, simID, dataID, /* + variableSpecs.getVariableNames()[i]*/
                                fileDataContainerManager);
                                fileDataContainerManager.append(exportOutput1.getFileDataContainerID(), fileDataContainerID_header);
                                for (int i = 0; i < variableSpecs.getVariableNames().length; i++) {
                                    fileDataContainerManager.append(exportOutput1.getFileDataContainerID(), getPointsTimeSeries(outputContext, user, dataServerImpl, vcdID, variableSpecs.getVariableNames()[i], geometrySpecs, allTimes, beginTimeIndex, endTimeIndex, asciiSpecs.getSwitchRowsColumns(), fileDataContainerManager));
                                    fileDataContainerManager.append(exportOutput1.getFileDataContainerID(), "\n");
                                    progressCounter++;
                                    exportServiceImpl.fireExportProgress(jobID, orig_vcdID, "CSV", progressCounter / TOTAL_EXPORTS_OPS);
                                }
                                outputV.add(exportOutput1);
                            }
                            if (geometrySpecs.getCurves().length != 0) {
                                // assemble curve (non-single point) data together
                                String dataID = "_Curves_vars(" + (geometrySpecs.getCurves().length) + ")_times(" + (endTimeIndex - beginTimeIndex + 1) + ")";
                                // StringBuilder data1 = new StringBuilder(data.toString());
                                ExportOutput exportOutput1 = new ExportOutput(true, dataType, simID, dataID, /* + variableSpecs.getVariableNames()[i]*/
                                fileDataContainerManager);
                                fileDataContainerManager.append(exportOutput1.getFileDataContainerID(), fileDataContainerID_header);
                                for (int i = 0; i < variableSpecs.getVariableNames().length; i++) {
                                    for (int s = 0; s < geometrySpecs.getCurves().length; s++) {
                                        if (!GeometrySpecs.isSinglePoint(geometrySpecs.getCurves()[s])) {
                                            fileDataContainerManager.append(exportOutput1.getFileDataContainerID(), getCurveTimeSeries(outputContext, user, dataServerImpl, vcdID, variableSpecs.getVariableNames()[i], geometrySpecs.getCurves()[s], allTimes, beginTimeIndex, endTimeIndex, asciiSpecs.getSwitchRowsColumns(), fileDataContainerManager));
                                            fileDataContainerManager.append(exportOutput1.getFileDataContainerID(), "\n");
                                            progressCounter++;
                                            exportServiceImpl.fireExportProgress(jobID, orig_vcdID, "CSV", progressCounter / TOTAL_EXPORTS_OPS);
                                        }
                                    }
                                }
                                outputV.add(exportOutput1);
                            }
                            exportOutputV.add(outputV.toArray(new ExportOutput[0]));
                            break;
                        }
                    case GEOMETRY_SLICE:
                        {
                            String dataID = "_Slice_" + Coordinate.getNormalAxisPlaneName(geometrySpecs.getAxis()) + "_" + geometrySpecs.getSliceNumber() + "_";
                            ExportOutput[] output = new ExportOutput[variableSpecs.getVariableNames().length * TIME_COUNT];
                            for (int j = 0; j < variableSpecs.getVariableNames().length; j++) {
                                for (int i = 0; i < TIME_COUNT; i++) {
                                    StringBuilder inset = new StringBuilder(Integer.toString(i + beginTimeIndex));
                                    inset.reverse();
                                    inset.append("000");
                                    inset.setLength(4);
                                    inset.reverse();
                                    String dataID1 = dataID + variableSpecs.getVariableNames()[j] + "_" + inset.toString();
                                    ExportOutput exportOutput1 = new ExportOutput(true, dataType, simID, dataID1, /* + variableSpecs.getVariableNames()[i]*/
                                    fileDataContainerManager);
                                    fileDataContainerManager.append(exportOutput1.getFileDataContainerID(), fileDataContainerID_header);
                                    fileDataContainerManager.append(exportOutput1.getFileDataContainerID(), getSlice(outputContext, user, dataServerImpl, vcdID, variableSpecs.getVariableNames()[j], i + beginTimeIndex, Coordinate.getNormalAxisPlaneName(geometrySpecs.getAxis()), geometrySpecs.getSliceNumber(), asciiSpecs.getSwitchRowsColumns(), fileDataContainerManager));
                                    output[j * TIME_COUNT + i] = exportOutput1;
                                    progressCounter++;
                                    exportServiceImpl.fireExportProgress(jobID, orig_vcdID, "CSV", progressCounter / TOTAL_EXPORTS_OPS);
                                // data1.cleanup();
                                // data2.cleanup();
                                }
                            }
                            exportOutputV.add(output);
                            break;
                        }
                    default:
                        {
                            throw new DataAccessException("Unexpected geometry modeID");
                        }
                }
            }
        }
    }
    if (exportOutputV.size() == 1) {
        // geometry_slice
        return Arrays.asList(exportOutputV.elementAt(0));
    }
    // geometry_selections (all are same length as first element)
    ArrayList<ExportOutput> combinedExportOutput = new ArrayList<>();
    for (int i = 0; i < exportOutputV.elementAt(0).length; i++) {
        String DATATYPE = exportOutputV.elementAt(0)[i].getDataType();
        String DATAID = exportOutputV.elementAt(0)[i].getDataID();
        ExportOutput eo = new ExportOutput(true, DATATYPE, "MultiSimulation", DATAID, fileDataContainerManager);
        // FileDataContainer container = fileDataContainerManager.getFileDataContainer(combinedExportOutput[i].getFileDataContainerID());
        for (int j = 0; j < exportOutputV.size(); j++) {
            fileDataContainerManager.append(eo.getFileDataContainerID(), exportOutputV.elementAt(j)[i].getFileDataContainerID());
            fileDataContainerManager.append(eo.getFileDataContainerID(), "\n");
        }
        combinedExportOutput.add(eo);
    }
    return combinedExportOutput;
}
Also used : ArrayList(java.util.ArrayList) SinglePoint(cbit.vcell.geometry.SinglePoint) CartesianMesh(cbit.vcell.solvers.CartesianMesh) FileDataContainerID(cbit.vcell.export.server.FileDataContainerManager.FileDataContainerID) Vector(java.util.Vector) VCDataIdentifier(org.vcell.util.document.VCDataIdentifier) DataAccessException(org.vcell.util.DataAccessException)

Example 35 with VCDataIdentifier

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

the class IMGExporter method getParticleFiles.

private File[] getParticleFiles(ExportSpecs exportSpecs, User user, DataServerImpl dataServerImpl) throws Exception {
    // int particleMode = FormatSpecificSpecs.PARTICLE_NONE;
    // if(exportSpecs.getFormatSpecificSpecs() instanceof ImageSpecs){
    // particleMode = ((ImageSpecs)exportSpecs.getFormatSpecificSpecs()).getParticleMode();
    // }else if (exportSpecs.getFormatSpecificSpecs() instanceof MovieSpecs){
    // particleMode = ((MovieSpecs)exportSpecs.getFormatSpecificSpecs()).getParticleMode();
    // }
    // if(particleMode == FormatSpecificSpecs.PARTICLE_NONE){
    // return null;
    // }
    final VCDataIdentifier vcdID = exportSpecs.getVCDataIdentifier();
    SimulationData.SimDataAmplistorInfo simDataAmplistorInfo = AmplistorUtils.getSimDataAmplistorInfoFromPropertyLoader();
    SimulationData simData = new SimulationData(vcdID, new File(PropertyLoader.getRequiredProperty(PropertyLoader.primarySimDataDirInternalProperty), vcdID.getOwner().getName()), new File(PropertyLoader.getProperty(PropertyLoader.primarySimDataDirInternalProperty, null), vcdID.getOwner().getName()), simDataAmplistorInfo);
    File logFile = simData.getLogFile();
    if (!logFile.exists()) {
        throw new Exception("ImgExport particle, Couldn't find Log file " + logFile.getAbsolutePath());
    }
    ArrayList<File> smoldynPointFiles = new ArrayList<>();
    // smoldyn always begins at timeindex 1
    int timeIndex = 1;
    while (true) {
        File smoldynOutFile = simData.getSmoldynOutputFile(timeIndex);
        if (!smoldynOutFile.exists()) {
            // get smoldynOutput files
            break;
        } else {
            smoldynPointFiles.add(smoldynOutFile);
        }
        timeIndex++;
    }
    if (smoldynPointFiles.size() == 0) {
        return null;
    }
    return smoldynPointFiles.toArray(new File[0]);
}
Also used : SimulationData(cbit.vcell.simdata.SimulationData) ArrayList(java.util.ArrayList) VCDataIdentifier(org.vcell.util.document.VCDataIdentifier) File(java.io.File) GIFFormatException(GIFUtils.GIFFormatException) RemoteException(java.rmi.RemoteException) DataFormatException(java.util.zip.DataFormatException) IOException(java.io.IOException) DataAccessException(org.vcell.util.DataAccessException) UserCancelException(org.vcell.util.UserCancelException)

Aggregations

VCDataIdentifier (org.vcell.util.document.VCDataIdentifier)49 VCSimulationDataIdentifier (cbit.vcell.solver.VCSimulationDataIdentifier)20 CartesianMesh (cbit.vcell.solvers.CartesianMesh)17 DataAccessException (org.vcell.util.DataAccessException)15 Vector (java.util.Vector)12 IOException (java.io.IOException)11 User (org.vcell.util.document.User)11 File (java.io.File)10 ArrayList (java.util.ArrayList)10 ExternalDataIdentifier (org.vcell.util.document.ExternalDataIdentifier)10 SimDataBlock (cbit.vcell.simdata.SimDataBlock)9 KeyValue (org.vcell.util.document.KeyValue)9 MathException (cbit.vcell.math.MathException)8 DataIdentifier (cbit.vcell.simdata.DataIdentifier)8 PDEDataManager (cbit.vcell.simdata.PDEDataManager)8 AnnotatedFunction (cbit.vcell.solver.AnnotatedFunction)8 ObjectNotFoundException (org.vcell.util.ObjectNotFoundException)8 ExportSpecs (cbit.vcell.export.server.ExportSpecs)7 VariableType (cbit.vcell.math.VariableType)7 OutputContext (cbit.vcell.simdata.OutputContext)7