use of gdsc.smlm.ij.settings.BatchSettings in project GDSC-SMLM by aherbert.
the class BatchPeakFit method loadSettings.
private BatchSettings loadSettings(String configurationFilename) {
BatchSettings settings = null;
FileInputStream fs = null;
try {
fs = new FileInputStream(configurationFilename);
settings = (BatchSettings) xs.fromXML(fs);
} catch (ClassCastException ex) {
//ex.printStackTrace();
} catch (FileNotFoundException ex) {
ex.printStackTrace();
} catch (XStreamException ex) {
ex.printStackTrace();
} finally {
if (fs != null) {
try {
fs.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return settings;
}
use of gdsc.smlm.ij.settings.BatchSettings in project GDSC-SMLM by aherbert.
the class BatchPeakFit method itemStateChanged.
/*
* (non-Javadoc)
*
* @see java.awt.event.ItemListener#itemStateChanged(java.awt.event.ItemEvent)
*/
public void itemStateChanged(ItemEvent e) {
// When the checkbox is clicked, create a default configuration file and update the
// GenericDialog with the file location.
Checkbox cb = (Checkbox) e.getSource();
if (cb.getState()) {
cb.setState(false);
Document doc = getDefaultSettingsXmlDocument();
if (doc == null)
return;
try {
// Look for nodes that are part of the fit configuration
XPathFactory factory = XPathFactory.newInstance();
XPath xpath = factory.newXPath();
XPathExpression expr = xpath.compile("//gdsc.smlm.engine.FitEngineConfiguration//*");
// For each node, add the name and value to the BatchParameters
BatchSettings batchSettings = new BatchSettings();
batchSettings.resultsDirectory = System.getProperty("java.io.tmpdir");
batchSettings.images.add("/path/to/image.tif");
Object result = expr.evaluate(doc, XPathConstants.NODESET);
NodeList nodes = (NodeList) result;
for (int i = 0; i < nodes.getLength(); i++) {
Node node = nodes.item(i);
if (// Only nodes with a single text entry
node.getChildNodes().getLength() == 1) {
batchSettings.parameters.add(new ParameterSettings(node.getNodeName(), node.getTextContent()));
}
}
// Save the settings file
String[] path = Utils.decodePath(configFilenameText.getText());
OpenDialog chooser = new OpenDialog("Settings_file", path[0], path[1]);
if (chooser.getFileName() != null) {
String newFilename = chooser.getDirectory() + chooser.getFileName();
if (!newFilename.endsWith(".xml"))
newFilename += ".xml";
FileOutputStream fs = null;
try {
fs = new FileOutputStream(newFilename);
xs.toXML(batchSettings, fs);
} finally {
if (fs != null) {
fs.close();
}
}
// Update dialog filename
configFilenameText.setText(newFilename);
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
use of gdsc.smlm.ij.settings.BatchSettings in project GDSC-SMLM by aherbert.
the class BatchPeakFit method runBatch.
/**
* Reads the batch configuration file. For each parameter variation, create a fitting configuration. Then run the
* fit engine on each input image using each configuration.
*
* @param configurationFilename
*/
private void runBatch(String configurationFilename) {
BatchSettings settings = loadSettings(configurationFilename);
if (settings == null || settings.parameters.isEmpty()) {
IJ.log("No settings for the fitting engine");
return;
}
if (!new File(settings.resultsDirectory).exists()) {
if (!new File(settings.resultsDirectory).mkdirs()) {
IJ.log("Unable to create the results directory: " + settings.resultsDirectory);
return;
}
}
Document doc = getDefaultSettingsXmlDocument();
if (doc == null)
return;
// Create XML for each variation
ArrayList<String> xmlSettings = new ArrayList<String>();
setParameters(settings.parameters, 0, doc, xmlSettings);
// Run all the variants on the input images
for (String imageFilename : settings.images) {
ImagePlus imp = IJ.openImage(imageFilename);
if (imp == null) {
IJ.log("Unable to load image: " + imageFilename);
continue;
}
processImage(settings, imp, xmlSettings);
}
}
Aggregations