private Tgm getModel(GtaModelReference gtaModelReference) { TgmDataObject tgmDO = null; Tgm model = null; String path = project.getProjectDirectory() + File.separator + gtaModelReference.getPath(); try { File datasetF = new File(path); FileObject datasetFO = FileUtil.createData(datasetF); DataObject datasetDO = DataObject.find(datasetFO); if (datasetDO != null) { tgmDO = (TgmDataObject) datasetDO; model = tgmDO.getTgm(); } } catch (DataObjectExistsException ex) { Exceptions.printStackTrace(ex); } catch (IOException ex) { Exceptions.printStackTrace(ex); } return model; }
private DatasetTimp[] getDatasets(GtaDatasetContainer gtaDatasetContainer) { TimpDatasetDataObject timpDatasetDO = null; int numberOfDatasets = gtaDatasetContainer.getDatasets().size(); datasets = new DatasetTimp[numberOfDatasets]; for (int i = 0; i < numberOfDatasets; i++) { GtaDataset gtaDataset = gtaDatasetContainer.getDatasets().get(i); String path = project.getProjectDirectory() + File.separator + gtaDataset.getPath(); try { File datasetF = new File(path); FileObject datasetFO = FileUtil.createData(datasetF); DataObject datasetDO = DataObject.find(datasetFO); if (datasetDO != null) { timpDatasetDO = (TimpDatasetDataObject) datasetDO; datasets[i] = timpDatasetDO.getDatasetTimp(); } } catch (DataObjectExistsException ex) { Exceptions.printStackTrace(ex); } catch (IOException ex) { Exceptions.printStackTrace(ex); } } return datasets; }
private Tgm getModel(String filename, String relativeFilePath) { TgmDataObject tgmDO; Tgm model = null; String newPath = project.getProjectDirectory() + File.separator + relativeFilePath + File.separator + filename; try { File datasetF = new File(newPath); FileObject datasetFO = FileUtil.createData(datasetF); DataObject datasetDO = DataObject.find(datasetFO); if (datasetDO != null) { tgmDO = (TgmDataObject) datasetDO; model = tgmDO.getTgm(); } } catch (DataObjectExistsException ex) { Exceptions.printStackTrace(ex); } catch (IOException ex) { Exceptions.printStackTrace(ex); } return model; }
private void writeResults( TimpResultDataset[] results, GtaModelReference modelReference, String[] nlsprogressResult) { Tgm model = getModel(modelReference); GtaResult newResultsObject = new GtaResult(); String freeResultsFilename = FileUtil.findFreeFileName(resultsfolder, resultsfolder.getName(), "summary"); try { writeSummary(resultsfolder, freeResultsFilename); } catch (IOException ex) { Exceptions.printStackTrace(ex); } if (nlsprogressResult != null) { for (int i = 0; i < nlsprogressResult.length; i++) { NlsProgress progress = new NlsProgress(); progress.setRss(nlsprogressResult[i]); newResultsObject.getNlsprogress().add(progress); } } for (int i = 0; i < results.length; i++) { TimpResultDataset timpResultDataset = results[i]; timpResultDataset.setType(datasets[i].getType()); newResultsObject.getDatasets().add(new Dataset()); newResultsObject.getDatasets().get(i).setDatasetFile(new OutputFile()); newResultsObject .getDatasets() .get(i) .getDatasetFile() .setFilename(datasetContainer.getDatasets().get(i).getFilename()); newResultsObject .getDatasets() .get(i) .getDatasetFile() .setPath(datasetContainer.getDatasets().get(i).getPath()); newResultsObject.getDatasets().get(i).getDatasetFile().setFiletype(datasets[i].getType()); newResultsObject.getDatasets().get(i).setId(String.valueOf(i + 1)); if (model.getDat().getIrfparPanel().getLamda() != null) { timpResultDataset.setLamdac(model.getDat().getIrfparPanel().getLamda()); } if (datasets[i].getType().equalsIgnoreCase("flim")) { timpResultDataset.setOrheigh(datasets[i].getOriginalHeight()); timpResultDataset.setOrwidth(datasets[i].getOriginalWidth()); timpResultDataset.setIntenceIm(datasets[i].getIntenceIm().clone()); timpResultDataset.setMaxInt(datasets[i].getMaxInt()); timpResultDataset.setMinInt(datasets[i].getMinInt()); timpResultDataset.setX(datasets[i].getX().clone()); timpResultDataset.setX2(datasets[i].getX2().clone()); } try { String freeFilename = FileUtil.findFreeFileName( resultsfolder, resultsfolder.getName() + "_d" + (i + 1) + "_" + timpResultDataset.getDatasetName(), "timpres"); timpResultDataset.setDatasetName(freeFilename); writeTo = resultsfolder.createData(freeFilename, "timpres"); ObjectOutputStream stream = new ObjectOutputStream(writeTo.getOutputStream()); stream.writeObject(timpResultDataset); stream.close(); newResultsObject.getDatasets().get(i).setResultFile(new OutputFile()); newResultsObject.getDatasets().get(i).getResultFile().setFilename(freeFilename); newResultsObject .getDatasets() .get(i) .getResultFile() .setPath(FileUtil.getRelativePath(project.getProjectDirectory(), resultsfolder)); } catch (IOException ex) { Exceptions.printStackTrace(ex); } } try { writeResultsXml(newResultsObject); } catch (IOException ex) { Exceptions.printStackTrace(ex); } }
private void doAnalysis() { if (project != null) { if (output.getIterations() != null) { if (!output.getIterations().isEmpty()) { numIterations = Integer.parseInt(output.getIterations()); } } else { numIterations = NO_OF_ITERATIONS; } if (output.getOutputPath() != null) { String[] nlsprogressResult = null; String outputPath = project.getResultsFolder(true) + File.separator + output.getOutputPath(); File outputFolder = new File(outputPath); if (outputFolder.exists()) { resultsfolder = FileUtil.toFileObject(outputFolder); if (resultsfolder.getChildren().length > 0) { try { resultsfolder = FileUtil.createFolder( resultsfolder.getParent(), FileUtil.findFreeFolderName( resultsfolder.getParent(), resultsfolder.getName())); } catch (IOException ex) { Exceptions.printStackTrace(ex); } } } else { try { FileUtil.createFolder(outputFolder); resultsfolder = outputFolder.exists() ? FileUtil.toFileObject(outputFolder) : null; } catch (IOException ex) { Exceptions.printStackTrace(ex); } } datasets = getDatasets(datasetContainer); modelCalls.add(getModelCall(modelReference, 0)); fitModelCall = getFitModelCall(datasets, modelCalls, modelDifferences, output, numIterations); if (isValidAnalysis(datasets, modelReference)) { timpcontroller = Lookup.getDefault().lookup(TimpControllerInterface.class); if (timpcontroller != null) { results = timpcontroller.runAnalysis(datasets, modelCalls, fitModelCall); nlsprogressResult = timpcontroller.getStringArray( TimpControllerInterface.NAME_OF_RESULT_OBJECT + "$nlsprogress"); } } else { // TODO: CoreErrorMessages warning return; } if (results != null) { writeResults(results, modelReference, nlsprogressResult); } else { try { writeSummary( resultsfolder, FileUtil.findFreeFileName( resultsfolder, resultsfolder.getName() + "_errorlog", "summary")); } catch (IOException ex) { Exceptions.printStackTrace(ex); } } timpcontroller.cleanup(); } } }