use of gdsc.smlm.tsf.TaggedSpotFile.ROI in project GDSC-SMLM by aherbert.
the class TSFPeakResultsReader method createResults.
private MemoryPeakResults createResults() {
// Limit the capacity since we may not need all the spots
int capacity = 1000;
if (spotList.hasNrSpots())
capacity = (int) Math.min(100000, spotList.getNrSpots());
MemoryPeakResults results = new MemoryPeakResults(capacity);
// Generic reconstruction
String name;
if (spotList.hasName()) {
name = spotList.getName();
} else {
name = new File(filename).getName();
}
// Append these if not using the defaults
if (channel != 1 || slice != 0 || position != 0 || fluorophoreType != 1) {
name = String.format("%s c=%d, s=%d, p=%d, ft=%d", name, channel, slice, position, fluorophoreType);
}
results.setName(name);
// if (spotList.hasNrPixelsX() && spotList.hasNrPixelsY())
// {
// // Do not do this. The size of the camera may not map to the data bounds due
// // to the support for position offsets.
// results.setBounds(new Rectangle(0, 0, spotList.getNrPixelsX(), spotList.getNrPixelsY()));
// }
Calibration cal = new Calibration();
results.setCalibration(cal);
if (spotList.hasPixelSize()) {
cal.setNmPerPixel(spotList.getPixelSize());
}
if (spotList.getEcfCount() >= channel) {
// ECF is per channel
double ecf = spotList.getEcf(channel - 1);
// QE is per fluorophore type
double qe = (spotList.getQeCount() >= fluorophoreType) ? spotList.getQe(fluorophoreType - 1) : 1;
cal.setGain(ecf * qe);
cal.setAmplification(ecf);
}
if (isGDSC) {
if (spotList.hasSource()) {
// Deserialise
results.setSource(ImageSource.fromXML(spotList.getSource()));
}
if (spotList.hasRoi()) {
ROI roi = spotList.getRoi();
if (roi.hasX() && roi.hasY() && roi.hasXWidth() && roi.hasYWidth())
results.setBounds(new Rectangle(roi.getX(), roi.getY(), roi.getXWidth(), roi.getYWidth()));
}
if (spotList.hasGain())
cal.setGain(spotList.getGain());
if (spotList.hasExposureTime())
cal.setExposureTime(spotList.getExposureTime());
if (spotList.hasReadNoise())
cal.setReadNoise(spotList.getReadNoise());
if (spotList.hasBias())
cal.setBias(spotList.getBias());
if (spotList.hasEmCCD())
cal.setEmCCD(spotList.getEmCCD());
if (spotList.hasAmplification())
cal.setAmplification(spotList.getAmplification());
if (spotList.hasConfiguration()) {
results.setConfiguration(spotList.getConfiguration());
}
}
if (spotList.getLocationUnits() != LocationUnits.PIXELS) {
if (!cal.hasNmPerPixel())
System.err.println("TSF location units are not pixels and no calibration is available. The dataset will be constructed in the native units: " + spotList.getLocationUnits());
}
if (spotList.getIntensityUnits() != IntensityUnits.COUNTS) {
if (!cal.hasGain())
System.err.println("TSF intensity units are not counts and no calibration is available. The dataset will be constructed in the native units: " + spotList.getIntensityUnits());
}
return results;
}