Search in sources :

Example 21 with CartesianMesh

use of cbit.vcell.solvers.CartesianMesh in project vcell by virtualcell.

the class VFrapXmlHelper method LoadVFrapSpecialImages.

// // load and compute prebleach average and first postbleach images
// public void LoadVFrapSpecialImages(AnnotatedImageDataset annotatedImages, int startingIndexRecovery)
// {
// // unnormalized prebleach average
// prebleachAvg = new double[annotatedImages.getImageDataset().getImage(0, 0, startingIndexRecovery).getNumXYZ()];
// for(int j = 0; j < prebleachAvg.length; j++)
// {
// double pixelTotal = 0;
// for(int i = 0 ; i < startingIndexRecovery; i++)
// {
// pixelTotal = pixelTotal + (annotatedImages.getImageDataset().getImage(0, 0, i).getPixels()[j] & 0x0000FFFF);
// }
// prebleachAvg[j] = pixelTotal/startingIndexRecovery;
// }
// 
// // unnormalized first post bleach
// firstPostBleach = new double[annotatedImages.getImageDataset().getImage(0, 0, startingIndexRecovery).getNumXYZ()];
// short[] pixels = annotatedImages.getImageDataset().getImage(0, 0, startingIndexRecovery).getPixels();
// for(int i = 0; i< pixels.length; i++)
// {
// firstPostBleach[i] = pixels[i] & 0x0000FFFF;
// }
// }
// 
// Locate the special images within the vFrap files and load them in memory
// 
public static boolean LoadVFrapSpecialImages(Hashtable<String, Object> hashTable, Element vFrapRoot) throws IOException, DataAccessException, MathException, ImageException {
    // ------ parse the vfrap file and the log/zip files referred within -----
    // many channels of 1 timepoint each
    int NumTimePoints = 1;
    // the channels: prebleach, postbleach, roi1, roi2 ... roiN
    int NumChannels = tokenNames.length;
    String[] channelNames = new String[NumChannels];
    VariableType[] channelTypes = new VariableType[NumChannels];
    DataSymbolType[] channelVFrapImageType = new DataSymbolType[NumChannels];
    double[][][] pixData = new double[NumTimePoints][NumChannels][];
    // get the path of the file tagged with "ROIExternalDataInfoTag" and open it
    Element roiExternalDataInfoElement = vFrapRoot.getChild(MicroscopyXMLTags.ROIExternalDataInfoTag);
    if (roiExternalDataInfoElement == null) {
        // can't load FieldData for some reason, fall back to importing the biomodel only
        return false;
    }
    // <ROIExternalDataInfo Filename="c:\vFrap\VirtualMicroscopy\SimulationData\SimID_1282941232246_0_.log">
    // <ExternalDataIdentifier Name="timeData" KeyValue="1282941232246" OwnerName="SimulationData" OwnerKey="0" />
    // </ImageDatasetExternalDataInfo>
    // c:\VirtualMicroscopy\SimulationData\SimID_1284149203811_0_.log
    String filename = (roiExternalDataInfoElement).getAttributeValue("Filename");
    Element childElement = (roiExternalDataInfoElement).getChild("ExternalDataIdentifier");
    if (childElement == null) {
        // can't load FieldData for some reason, fall back to importing the biomodel only
        return false;
    }
    StringTokenizer tokens = new StringTokenizer(filename, "/\\.");
    final ArrayList<String> tokenArray = new ArrayList<String>();
    while (tokens.hasMoreElements()) {
        tokenArray.add(tokens.nextToken());
    }
    final String dataID = tokenArray.get(tokenArray.size() - 2);
    final String userName = tokenArray.get(tokenArray.size() - 3);
    VCDataIdentifier vcDataIdentifier = new VCDataIdentifier() {

        public String getID() {
            return dataID;
        }

        public KeyValue getDataKey() {
            return null;
        }

        public User getOwner() {
            return new User(userName, new KeyValue("123345432334"));
        }
    };
    // ------- recover simulation data for this user name, load the images in memory ------------
    // ex  c:\\VirtualMicroscopy\\SimulationData
    String userDirName = filename.substring(0, filename.indexOf(dataID) - 1);
    File userDir = new File(userDirName);
    SimulationData.SimDataAmplistorInfo simDataAmplistorInfo = AmplistorUtils.getSimDataAmplistorInfoFromPropertyLoader();
    SimulationData simData = new SimulationData(vcDataIdentifier, userDir, null, simDataAmplistorInfo);
    // build a valid mesh in 2 steps, what we have in simData is incomplete
    CartesianMesh incompleteMesh = simData.getMesh();
    Extent extent = incompleteMesh.getExtent();
    ISize isize = new ISize(incompleteMesh.getSizeX(), incompleteMesh.getSizeY(), incompleteMesh.getSizeZ());
    Origin origin = new Origin(0, 0, 0);
    CartesianMesh mesh = CartesianMesh.createSimpleCartesianMesh(origin, extent, isize, new RegionImage(new VCImageUncompressed(null, new byte[isize.getXYZ()], extent, isize.getX(), isize.getY(), isize.getZ()), 0, null, null, RegionImage.NO_SMOOTHING));
    DataIdentifier[] dataIdentifiers = simData.getVarAndFunctionDataIdentifiers(null);
    double[] times = simData.getDataTimes();
    for (int i = 0; i < dataIdentifiers.length; i++) {
        // ex: prebleach_avg, postbleach_first, postbleach_last, bleached_mask, cell_mask, ring1_mask,... ring8_mask
        System.out.println(dataIdentifiers[i].getName());
        for (double time : times) {
            // this loops only once, we have just 1 timepoint for each "special" image
            SimDataBlock simDataBlock = simData.getSimDataBlock(null, dataIdentifiers[i].getName(), time);
            channelNames[i] = dataIdentifiers[i].getName();
            channelTypes[i] = VariableType.VOLUME;
            channelVFrapImageType[i] = SymbolEquivalence.typeFromToken(dataIdentifiers[i].getName());
            pixData[0][i] = simDataBlock.getData();
            // var = prebleach_avg, time = 0.0, data = { 1.0832530361887216 1.0832530361887216 1.0832530361887216 1.0 .... }
            System.out.print("var = " + dataIdentifiers[i].getName() + ", time = " + time + ", data = { ");
            // show a few
            for (int j = 0; j < 5; j++) {
                System.out.print(pixData[0][i][j] + " ");
            }
            // show a few
            ;
            // show a few
            System.out.println(" ... ");
        }
    }
    hashTable.put("mesh", mesh);
    hashTable.put("pixData", pixData);
    hashTable.put("channelNames", channelNames);
    hashTable.put("channelTypes", channelTypes);
    hashTable.put("channelVFrapImageType", channelVFrapImageType);
    return true;
}
Also used : Origin(org.vcell.util.Origin) User(org.vcell.util.document.User) KeyValue(org.vcell.util.document.KeyValue) VCDataIdentifier(org.vcell.util.document.VCDataIdentifier) DataIdentifier(cbit.vcell.simdata.DataIdentifier) ExternalDataIdentifier(org.vcell.util.document.ExternalDataIdentifier) Extent(org.vcell.util.Extent) ISize(org.vcell.util.ISize) Element(org.jdom.Element) ArrayList(java.util.ArrayList) SimDataBlock(cbit.vcell.simdata.SimDataBlock) VariableType(cbit.vcell.math.VariableType) VCImageUncompressed(cbit.image.VCImageUncompressed) StringTokenizer(java.util.StringTokenizer) CartesianMesh(cbit.vcell.solvers.CartesianMesh) SimulationData(cbit.vcell.simdata.SimulationData) DataSymbolType(cbit.vcell.data.DataSymbol.DataSymbolType) RegionImage(cbit.vcell.geometry.RegionImage) VCDataIdentifier(org.vcell.util.document.VCDataIdentifier) File(java.io.File)

Example 22 with CartesianMesh

use of cbit.vcell.solvers.CartesianMesh in project vcell by virtualcell.

the class VFrapXmlHelper method SaveVFrapSpecialImagesAsFieldData.

// 
// save the special images in the database as field data
// 
public static ExternalDataIdentifier SaveVFrapSpecialImagesAsFieldData(Hashtable<String, Object> hashTable, DocumentManager documentManager) throws DataAccessException {
    CartesianMesh mesh = (CartesianMesh) hashTable.get("mesh");
    double[][][] pixData = (double[][][]) hashTable.get("pixData");
    String[] channelNames = (String[]) hashTable.get("channelNames");
    VariableType[] channelTypes = (VariableType[]) hashTable.get("channelTypes");
    // DataSymbolType[] channelVFrapImageType = (DataSymbolType[])hashTable.get("channelVFrapImageType");
    String mixedFieldDataName = (String) hashTable.get("mixedFieldDataName");
    FieldDataFileOperationSpec vfrapMiscFieldDataOpSpec = new FieldDataFileOperationSpec();
    vfrapMiscFieldDataOpSpec.opType = FieldDataFileOperationSpec.FDOS_ADD;
    vfrapMiscFieldDataOpSpec.cartesianMesh = mesh;
    vfrapMiscFieldDataOpSpec.doubleSpecData = pixData;
    vfrapMiscFieldDataOpSpec.specEDI = null;
    // item name as it comes from vFrap
    vfrapMiscFieldDataOpSpec.varNames = channelNames;
    vfrapMiscFieldDataOpSpec.owner = documentManager.getUser();
    vfrapMiscFieldDataOpSpec.times = new double[] { 0.0 };
    vfrapMiscFieldDataOpSpec.variableTypes = channelTypes;
    vfrapMiscFieldDataOpSpec.origin = new Origin(0, 0, 0);
    vfrapMiscFieldDataOpSpec.extent = mesh.getExtent();
    vfrapMiscFieldDataOpSpec.isize = new ISize(mesh.getSizeX(), mesh.getSizeY(), mesh.getSizeZ());
    ExternalDataIdentifier vfrapMisc = documentManager.saveFieldData(vfrapMiscFieldDataOpSpec, mixedFieldDataName);
    return vfrapMisc;
}
Also used : Origin(org.vcell.util.Origin) CartesianMesh(cbit.vcell.solvers.CartesianMesh) VariableType(cbit.vcell.math.VariableType) FieldDataFileOperationSpec(cbit.vcell.field.io.FieldDataFileOperationSpec) ISize(org.vcell.util.ISize) ExternalDataIdentifier(org.vcell.util.document.ExternalDataIdentifier)

Example 23 with CartesianMesh

use of cbit.vcell.solvers.CartesianMesh in project vcell by virtualcell.

the class PointSpreadFunctionManagement method importPointSpreadFunction.

public void importPointSpreadFunction() {
    AsynchClientTask[] taskArray = new AsynchClientTask[3];
    // select the desired PSF file
    taskArray[0] = new AsynchClientTask("Select a file", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {

        public void run(Hashtable<String, Object> hashTable) throws Exception {
            ChoosePSFFile(hashTable);
        }
    };
    // create and save the field data object
    taskArray[1] = new AsynchClientTask("Import objects", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {

        public void run(Hashtable<String, Object> hashTable) throws Exception {
            Component requesterComponent = parentWindow;
            DocumentWindow documentWindow = (DocumentWindow) BeanUtils.findTypeParentOfComponent(requesterComponent, DocumentWindow.class);
            DocumentManager documentManager = documentWindow.getTopLevelWindowManager().getRequestManager().getDocumentManager();
            if (documentManager == null) {
                throw new RuntimeException("Not connected to server.");
            }
            // the following line of code may modify initialFieldDataName
            // normal file name
            checkNameAvailability(hashTable, false, documentManager, requesterComponent);
            File filePSF = (File) hashTable.get("filePSF");
            String initialFieldDataName = (String) hashTable.get("initialFieldDataName");
            ImageDataset imageDataset = ImageDatasetReaderService.getInstance().getImageDatasetReader().readImageDataset(filePSF.getAbsolutePath(), null);
            Extent extent = imageDataset.getExtent();
            ISize isize = imageDataset.getISize();
            Origin origin = new Origin(0, 0, 0);
            CartesianMesh cartesianMesh = CartesianMesh.createSimpleCartesianMesh(origin, extent, isize, new RegionImage(new VCImageUncompressed(null, new byte[isize.getXYZ()], extent, isize.getX(), isize.getY(), isize.getZ()), 0, null, null, RegionImage.NO_SMOOTHING));
            // save field data
            int NumTimePoints = imageDataset.getImageTimeStamps().length;
            int NumChannels = 1;
            double[][][] pixData = new double[NumTimePoints][NumChannels][];
            for (int i = 0; i < NumTimePoints; i++) {
                // images according to zIndex at specific time points(tIndex)
                short[] originalData = imageDataset.getPixelsZ(0, i);
                double[] doubleData = new double[originalData.length];
                for (int j = 0; j < originalData.length; j++) {
                    doubleData[j] = 0x0000ffff & originalData[j];
                }
                pixData[i][NumChannels - 1] = doubleData;
            }
            FieldDataFileOperationSpec fdos = new FieldDataFileOperationSpec();
            // try {
            // fdos = ClientRequestManager.createFDOSFromImageFile(filePSF, false, null);
            // } catch (DataFormatException ex) {
            // throw new Exception("Cannot read image " + filePSF.getAbsolutePath()+"\n"+ex.getMessage());
            // }
            fdos.owner = documentManager.getUser();
            fdos.opType = FieldDataFileOperationSpec.FDOS_ADD;
            fdos.cartesianMesh = cartesianMesh;
            fdos.doubleSpecData = pixData;
            fdos.specEDI = null;
            fdos.varNames = new String[] { SimulationContext.FLUOR_DATA_NAME };
            fdos.times = imageDataset.getImageTimeStamps();
            fdos.variableTypes = new VariableType[] { VariableType.VOLUME };
            fdos.origin = origin;
            fdos.extent = extent;
            fdos.isize = isize;
            ExternalDataIdentifier pSFImageEDI = documentManager.saveFieldData(fdos, initialFieldDataName);
            hashTable.put("pSFImageEDI", pSFImageEDI);
        }
    };
    // create a data symbol for the PSF image saved above as field data
    taskArray[2] = new AsynchClientTask("Display Data Symbols", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {

        public void run(Hashtable<String, Object> hashTable) throws Exception {
            // --- create the data symbols associated with the time series
            String initialFieldDataName = (String) hashTable.get("initialFieldDataName");
            ExternalDataIdentifier pSFImageEDI = (ExternalDataIdentifier) hashTable.get("pSFImageEDI");
            String fluorName = "psf_" + initialFieldDataName;
            DataSymbol fluorDataSymbol = new FieldDataSymbol(fluorName, DataSymbolType.POINT_SPREAD_FUNCTION, simulationContext.getDataContext(), simulationContext.getModel().getUnitSystem().getInstance_TBD(), pSFImageEDI, SimulationContext.FLUOR_DATA_NAME, VariableType.VOLUME.getTypeName(), 0D);
            simulationContext.getDataContext().addDataSymbol(fluorDataSymbol);
        }
    };
    Hashtable<String, Object> hash = new Hashtable<String, Object>();
    ClientTaskDispatcher.dispatch(parentWindow, hash, taskArray, false, true, null);
}
Also used : Origin(org.vcell.util.Origin) AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) ImageDataset(cbit.vcell.VirtualMicroscopy.ImageDataset) VariableType(cbit.vcell.math.VariableType) Extent(org.vcell.util.Extent) ISize(org.vcell.util.ISize) FieldDataFileOperationSpec(cbit.vcell.field.io.FieldDataFileOperationSpec) Hashtable(java.util.Hashtable) DocumentManager(cbit.vcell.clientdb.DocumentManager) VCImageUncompressed(cbit.image.VCImageUncompressed) ImageException(cbit.image.ImageException) IOException(java.io.IOException) UserCancelException(org.vcell.util.UserCancelException) DocumentWindow(cbit.vcell.client.desktop.DocumentWindow) FieldDataSymbol(cbit.vcell.data.FieldDataSymbol) DataSymbol(cbit.vcell.data.DataSymbol) CartesianMesh(cbit.vcell.solvers.CartesianMesh) RegionImage(cbit.vcell.geometry.RegionImage) ExternalDataIdentifier(org.vcell.util.document.ExternalDataIdentifier) Component(java.awt.Component) ImageFile(cbit.image.ImageFile) File(java.io.File) FieldDataSymbol(cbit.vcell.data.FieldDataSymbol)

Example 24 with CartesianMesh

use of cbit.vcell.solvers.CartesianMesh in project vcell by virtualcell.

the class DataSymbolsPanel method addVFrapOriginalImages.

private void addVFrapOriginalImages() {
    // add dataset (normal images) from vFrap
    AsynchClientTask[] taskArray = new AsynchClientTask[5];
    // select the desired vfrap file
    taskArray[0] = ChooseVFrapFile();
    taskArray[1] = new AsynchClientTask("Import objects", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {

        public void run(Hashtable<String, Object> hashTable) throws Exception {
            File vFrapFile = (File) hashTable.get("vFrapFile");
            Component requesterComponent = DataSymbolsPanel.this;
            DocumentWindow documentWindow = (DocumentWindow) BeanUtils.findTypeParentOfComponent(requesterComponent, DocumentWindow.class);
            DocumentManager documentManager = documentWindow.getTopLevelWindowManager().getRequestManager().getDocumentManager();
            if (documentManager == null) {
                throw new RuntimeException("Not connected to server.");
            }
            // ex  ccc8.vfrap
            String vFrapFileNameExtended = vFrapFile.getName();
            {
                // we want to make sure to reload these strings from the hash later on
                String initialFieldDataName = vFrapFileNameExtended.substring(0, vFrapFileNameExtended.indexOf(".vfrap"));
                // we'll save here the "special" vFrap images (prebleach_avg, ...)
                String mixedFieldDataName = initialFieldDataName + "Mx";
                hashTable.put("initialFieldDataName", initialFieldDataName);
                hashTable.put("mixedFieldDataName", mixedFieldDataName);
            }
            if (vFrapFileNameExtended.indexOf(".vfrap") <= -1) {
                throw new RuntimeException("File extension must be .vfrap");
            }
            // normal images
            checkNameAvailability(hashTable, false, documentManager, requesterComponent);
            // ----- read needed info from Virtual FRAP xml file
            System.out.println("Loading " + vFrapFileNameExtended + " ...");
            String xmlString = XmlUtil.getXMLString(vFrapFile.getAbsolutePath());
            MicroscopyXmlReader xmlReader = new MicroscopyXmlReader(true);
            Element vFrapRoot = XmlUtil.stringToXML(xmlString, null).getRootElement();
            // loading frap images
            AnnotatedImageDataset annotatedImages = xmlReader.getAnnotatedImageDataset(vFrapRoot, null);
            hashTable.put("annotatedImages", annotatedImages);
            // loading ROIs for display purposes only (see next task)
            ROI[] rois = xmlReader.getPrimaryROIs(XmlUtil.stringToXML(xmlString, null).getRootElement(), null);
            LoadVFrapDisplayRoi(hashTable, annotatedImages, rois);
        // Calendar cal = Calendar.getInstance();
        // SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd_hhmmss");
        // DocumentWindow documentWindow = (DocumentWindow)BeanUtils.findTypeParentOfComponent(DataSymbolsPanel.this, DocumentWindow.class);
        // DocumentManager documentManager = documentWindow.getTopLevelWindowManager().getRequestManager().getDocumentManager();
        // VFrapXmlHelper vFrapXmlHelper = new VFrapXmlHelper();
        // if(vFrapXmlHelper.isAlreadyImported(vFrapFileName, documentManager)) {
        // throw new RuntimeException("FieldData name already in use.");
        // }
        // //				bioModel.setName(vFrapFileName + "-" + sdf.format(cal.getTime()));
        // bioModel.setName(vFrapFileName);
        // BioModel feedbackModel =  documentManager.save(bioModel, null);
        // BioModelChildSummary  childSummary = BioModelChildSummary.fromDatabaseSerialization(xmlString);
        // BioModelInfo biomodelInfo = new BioModelInfo(feedbackModel.getVersion(), feedbackModel.getVersion().getVersionKey(), childSummary );
        // documentWindow.getTopLevelWindowManager().getRequestManager().openDocument(biomodelInfo, documentWindow.getTopLevelWindowManager(), true);
        }
    };
    // show the images from the vfrap file in an OverlayEditorPanelJAI dialog
    taskArray[2] = new AsynchClientTask("Display images", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {

        public void run(Hashtable<String, Object> hashTable) throws Exception {
            String initialFieldDataName = (String) hashTable.get("initialFieldDataName");
            if (initialFieldDataName.equals("")) {
                JOptionPane.showMessageDialog(DataSymbolsPanel.this, "Field Data name " + initialFieldDataName + " already in use.");
                // prevents the rest of tasks below from running
                throw UserCancelException.CANCEL_GENERIC;
            }
            AnnotatedImageDataset annotatedImages = (AnnotatedImageDataset) hashTable.get("annotatedImages");
            BufferedImage[] displayROI = (BufferedImage[]) hashTable.get("displayROI");
            if (annotatedImages == null || displayROI == null) {
                return;
            }
            // display the images
            OverlayEditorPanelJAI overlayPanel = new OverlayEditorPanelJAI();
            overlayPanel.setAllowAddROI(false);
            ImageDataset imageDataset = annotatedImages.getImageDataset();
            overlayPanel.setImages(imageDataset, 1, 0, new OverlayEditorPanelJAI.AllPixelValuesRange(1, 200));
            overlayPanel.setAllROICompositeImage(displayROI, OverlayEditorPanelJAI.FRAP_DATA_INIT_PROPERTY);
            int choice = DialogUtils.showComponentOKCancelDialog(DataSymbolsPanel.this, overlayPanel, "vFrap Field Data");
            if (choice != JOptionPane.OK_OPTION) {
                throw UserCancelException.CANCEL_GENERIC;
            }
        }
    };
    // save the timepoints from memory to the database as field data
    taskArray[3] = new AsynchClientTask("Saving time series data", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {

        public void run(Hashtable<String, Object> hashTable) throws Exception {
            AnnotatedImageDataset annotatedImages = (AnnotatedImageDataset) hashTable.get("annotatedImages");
            String initialFieldDataName = (String) hashTable.get("initialFieldDataName");
            DocumentWindow documentWindow = (DocumentWindow) BeanUtils.findTypeParentOfComponent(DataSymbolsPanel.this, DocumentWindow.class);
            DocumentManager dm = documentWindow.getTopLevelWindowManager().getRequestManager().getDocumentManager();
            if (dm == null) {
                throw new RuntimeException("Not connected to server.");
            }
            User owner = null;
            Version version = simulationContext.getVersion();
            if (version == null) {
                // new document, so the owner is the user
                owner = dm.getUser();
            } else {
                owner = simulationContext.getVersion().getOwner();
            }
            // mesh
            ImageDataset imageDataset = annotatedImages.getImageDataset();
            Extent extent = imageDataset.getExtent();
            ISize isize = imageDataset.getISize();
            Origin origin = new Origin(0, 0, 0);
            CartesianMesh cartesianMesh = CartesianMesh.createSimpleCartesianMesh(origin, extent, isize, new RegionImage(new VCImageUncompressed(null, new byte[isize.getXYZ()], extent, isize.getX(), isize.getY(), isize.getZ()), 0, null, null, RegionImage.NO_SMOOTHING));
            // save field data
            int NumTimePoints = imageDataset.getImageTimeStamps().length;
            int NumChannels = 1;
            double[][][] pixData = new double[NumTimePoints][NumChannels][];
            for (int i = 0; i < NumTimePoints; i++) {
                // images according to zIndex at specific time points(tIndex)
                short[] originalData = imageDataset.getPixelsZ(0, i);
                double[] doubleData = new double[originalData.length];
                for (int j = 0; j < originalData.length; j++) {
                    doubleData[j] = 0x0000ffff & originalData[j];
                }
                pixData[i][NumChannels - 1] = doubleData;
            }
            FieldDataFileOperationSpec timeSeriesFieldDataOpSpec = new FieldDataFileOperationSpec();
            timeSeriesFieldDataOpSpec.opType = FieldDataFileOperationSpec.FDOS_ADD;
            timeSeriesFieldDataOpSpec.cartesianMesh = cartesianMesh;
            timeSeriesFieldDataOpSpec.doubleSpecData = pixData;
            timeSeriesFieldDataOpSpec.specEDI = null;
            timeSeriesFieldDataOpSpec.varNames = new String[] { SimulationContext.FLUOR_DATA_NAME };
            timeSeriesFieldDataOpSpec.owner = owner;
            timeSeriesFieldDataOpSpec.times = imageDataset.getImageTimeStamps();
            timeSeriesFieldDataOpSpec.variableTypes = new VariableType[] { VariableType.VOLUME };
            timeSeriesFieldDataOpSpec.origin = origin;
            timeSeriesFieldDataOpSpec.extent = extent;
            timeSeriesFieldDataOpSpec.isize = isize;
            // realignment for the case when first timepoint is not zero
            if (timeSeriesFieldDataOpSpec.times[0] != 0) {
                double shift = timeSeriesFieldDataOpSpec.times[0];
                for (int i = 0; i < NumTimePoints; i++) {
                    timeSeriesFieldDataOpSpec.times[i] -= shift;
                }
            }
            Calendar cal = Calendar.getInstance();
            SimpleDateFormat sdf = new SimpleDateFormat("yyMMMdd_hhmmss");
            String formattedDate = sdf.format(cal.getTime());
            hashTable.put("formattedDate", formattedDate);
            // ExternalDataIdentifier timeSeriesEDI = dm.saveFieldData(timeSeriesFieldDataOpSpec,
            // initialFieldDataName + "_" + formattedDate);
            ExternalDataIdentifier timeSeriesEDI = dm.saveFieldData(timeSeriesFieldDataOpSpec, initialFieldDataName);
            hashTable.put("imageDataset", imageDataset);
            hashTable.put("timeSeriesEDI", timeSeriesEDI);
        }
    };
    // create the data symbols for the images saved above and display them in the tree/table
    taskArray[4] = new AsynchClientTask("Display Data Symbols", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {

        public void run(Hashtable<String, Object> hashTable) throws Exception {
            // --- create the data symbols associated with the time series
            String initialFieldDataName = (String) hashTable.get("initialFieldDataName");
            ImageDataset imageDataset = (ImageDataset) hashTable.get("imageDataset");
            ExternalDataIdentifier timeSeriesEDI = (ExternalDataIdentifier) hashTable.get("timeSeriesEDI");
            for (double time : imageDataset.getImageTimeStamps()) {
                // String fluorName = TokenMangler.fixTokenStrict("fluor_"+time+"_");
                // while (simulationContext.getDataContext().getDataSymbol(fluorName)!=null){
                // fluorName = TokenMangler.getNextEnumeratedToken(fluorName);
                // }
                // max time interval we can display is about 11 days
                DecimalFormat df = new DecimalFormat("###000.00");
                // String fluorName = "fluor_" + df.format(time) + "_" + formattedDate;
                String fluorName = "fluor_" + df.format(time).substring(0, df.format(time).indexOf(".")) + "s" + df.format(time).substring(1 + df.format(time).indexOf(".")) + "_" + initialFieldDataName;
                // FieldFunctionArguments fluorFFArgs = new FieldFunctionArguments(timeSeriesEDI.getName(), fluorName, new Expression(time), VariableType.VOLUME);
                DataSymbol fluorDataSymbol = new FieldDataSymbol(fluorName, DataSymbolType.VFRAP_TIMEPOINT, simulationContext.getDataContext(), simulationContext.getModel().getUnitSystem().getInstance_TBD(), timeSeriesEDI, SimulationContext.FLUOR_DATA_NAME, VariableType.VOLUME.getTypeName(), time);
                simulationContext.getDataContext().addDataSymbol(fluorDataSymbol);
            }
        }
    };
    Hashtable<String, Object> hash = new Hashtable<String, Object>();
    ClientTaskDispatcher.dispatch(this, hash, taskArray, false, true, null);
// String name = null;
// try {
// getNewDataSymbolPanel().setSymbolName("");
// getNewDataSymbolPanel().setSymbolExpression("vcField(dataset1,var1,0.0,Volume)");
// int newSettings = org.vcell.util.gui.DialogUtils.showComponentOKCancelDialog(this, getNewDataSymbolPanel(), "New DataSymbol");
// if (newSettings == JOptionPane.OK_OPTION) {
// name = getNewDataSymbolPanel().getSymbolName();
// String expression = getNewDataSymbolPanel().getSymbolExpression();
// Expression exp = new Expression(expression);
// FunctionInvocation[] functionInvocations = exp.getFunctionInvocations(null);
// //			DataSymbol ds = new FieldDataSymbol(DataSymbolType.GENERIC_SYMBOL, name, "",
// //					simulationContext.getDataContext(), VCUnitDefinition.UNIT_TBD,
// //					new FieldFunctionArguments(functionInvocations[0]));
// DataSymbol ds = new FieldDataSymbol(name, DataSymbolType.GENERIC_SYMBOL,
// simulationContext.getDataContext(), VCUnitDefinition.UNIT_TBD);
// simulationContext.getDataContext().addDataSymbol(ds);
// }
// } catch (java.lang.Throwable ivjExc) {
// DialogUtils.showErrorDialog(this, "Data symbol " + name + " already exists");
// }
}
Also used : Origin(org.vcell.util.Origin) AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) User(org.vcell.util.document.User) AnnotatedImageDataset(cbit.vcell.VirtualMicroscopy.importer.AnnotatedImageDataset) ImageDataset(cbit.vcell.VirtualMicroscopy.ImageDataset) Extent(org.vcell.util.Extent) ISize(org.vcell.util.ISize) FieldDataFileOperationSpec(cbit.vcell.field.io.FieldDataFileOperationSpec) Element(org.jdom.Element) DecimalFormat(java.text.DecimalFormat) BufferedImage(java.awt.image.BufferedImage) Version(org.vcell.util.document.Version) ExternalDataIdentifier(org.vcell.util.document.ExternalDataIdentifier) Component(java.awt.Component) AnnotatedImageDataset(cbit.vcell.VirtualMicroscopy.importer.AnnotatedImageDataset) VariableType(cbit.vcell.math.VariableType) Hashtable(java.util.Hashtable) Calendar(java.util.Calendar) DocumentManager(cbit.vcell.clientdb.DocumentManager) VCImageUncompressed(cbit.image.VCImageUncompressed) UserCancelException(org.vcell.util.UserCancelException) DocumentWindow(cbit.vcell.client.desktop.DocumentWindow) MicroscopyXmlReader(cbit.vcell.VirtualMicroscopy.importer.MicroscopyXmlReader) FieldDataSymbol(cbit.vcell.data.FieldDataSymbol) DataSymbol(cbit.vcell.data.DataSymbol) CartesianMesh(cbit.vcell.solvers.CartesianMesh) RegionImage(cbit.vcell.geometry.RegionImage) File(java.io.File) OverlayEditorPanelJAI(cbit.vcell.geometry.gui.OverlayEditorPanelJAI) SimpleDateFormat(java.text.SimpleDateFormat) FieldDataSymbol(cbit.vcell.data.FieldDataSymbol)

Example 25 with CartesianMesh

use of cbit.vcell.solvers.CartesianMesh 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)

Aggregations

CartesianMesh (cbit.vcell.solvers.CartesianMesh)49 ISize (org.vcell.util.ISize)24 Extent (org.vcell.util.Extent)19 Origin (org.vcell.util.Origin)18 VariableType (cbit.vcell.math.VariableType)17 VCImageUncompressed (cbit.image.VCImageUncompressed)15 RegionImage (cbit.vcell.geometry.RegionImage)15 DataAccessException (org.vcell.util.DataAccessException)15 VCDataIdentifier (org.vcell.util.document.VCDataIdentifier)14 FieldDataFileOperationSpec (cbit.vcell.field.io.FieldDataFileOperationSpec)13 File (java.io.File)13 ExternalDataIdentifier (org.vcell.util.document.ExternalDataIdentifier)12 IOException (java.io.IOException)11 DataIdentifier (cbit.vcell.simdata.DataIdentifier)9 SimDataBlock (cbit.vcell.simdata.SimDataBlock)9 VCSimulationDataIdentifier (cbit.vcell.solver.VCSimulationDataIdentifier)9 VCImage (cbit.image.VCImage)8 UserCancelException (org.vcell.util.UserCancelException)8 Expression (cbit.vcell.parser.Expression)7 Vector (java.util.Vector)7