use of java.util.InputMismatchException in project GDSC-SMLM by aherbert.
the class PeakResultsReader method createNSTORMResult.
// So that the fields can be named
@SuppressWarnings("unused")
private PeakResult createNSTORMResult(String line) {
// data then Zc= Z.
try {
Scanner scanner = new Scanner(line);
scanner.useDelimiter(tabPattern);
scanner.useLocale(Locale.US);
String channelName = scanner.next();
float x = scanner.nextFloat();
float y = scanner.nextFloat();
float xc = scanner.nextFloat();
float yc = scanner.nextFloat();
float height = scanner.nextFloat();
float area = scanner.nextFloat();
float width = scanner.nextFloat();
float phi = scanner.nextFloat();
float ax = scanner.nextFloat();
float bg = scanner.nextFloat();
float i = scanner.nextFloat();
int frame = scanner.nextInt();
int length = scanner.nextInt();
// These are not needed
//float link = scanner.nextFloat();
//float valid = scanner.nextFloat();
//float z = scanner.nextFloat();
//float zc = scanner.nextFloat();
scanner.close();
// The coordinates are in nm
// The values are in ADUs. The area value is the signal.
// The following relationship holds when length == 1:
// Area = Height * 2 * pi * (Width / (pixel_pitch*2) )^2
// => Pixel_pitch = 0.5 * Width / sqrt(Area / (Height * 2 * pi))
float[] params = new float[7];
params[Gaussian2DFunction.BACKGROUND] = bg;
//params[Gaussian2DFunction.ANGLE] = ax;
params[Gaussian2DFunction.SIGNAL] = height;
params[Gaussian2DFunction.X_POSITION] = xc;
params[Gaussian2DFunction.Y_POSITION] = yc;
params[Gaussian2DFunction.X_SD] = width;
params[Gaussian2DFunction.Y_SD] = width;
// Store the signal as the original value
return new ExtendedPeakResult(frame, (int) xc, (int) yc, area, 0.0, 0.0f, params, null, frame + length - 1, 0);
} catch (InputMismatchException e) {
// Ignore
} catch (NoSuchElementException e) {
// Ignore
}
return null;
}
use of java.util.InputMismatchException in project GDSC-SMLM by aherbert.
the class PeakResultsReader method createRapidSTORMResult.
private PeakResult createRapidSTORMResult(String line) {
// *Note that the RapidSTORM Amplitude is the signal. To get the Amplitude we must divide by the 2*pi*sx*sy
try {
Scanner scanner = new Scanner(line);
scanner.useDelimiter(spacePattern);
scanner.useLocale(Locale.US);
float x = scanner.nextFloat();
float y = scanner.nextFloat();
final int peak = scanner.nextInt();
final float signal = scanner.nextFloat();
final float sx2 = scanner.nextFloat();
final float sy2 = scanner.nextFloat();
@SuppressWarnings("unused") final float kernelImprovement = scanner.nextFloat();
final double chiSquared = scanner.nextDouble();
scanner.close();
// Convert from pm^2 to nm
float sx = (float) (Math.sqrt(sx2) * 1000);
float sy = (float) (Math.sqrt(sy2) * 1000);
// If calibration was found convert to pixels
if (calibration != null) {
x /= calibration.getNmPerPixel();
y /= calibration.getNmPerPixel();
sx /= calibration.getNmPerPixel();
sy /= calibration.getNmPerPixel();
}
float[] params = new float[7];
params[Gaussian2DFunction.SIGNAL] = signal;
params[Gaussian2DFunction.X_POSITION] = x;
params[Gaussian2DFunction.Y_POSITION] = y;
params[Gaussian2DFunction.X_SD] = sx;
params[Gaussian2DFunction.Y_SD] = sy;
// Store the signal as the original value
return new PeakResult(peak, (int) x, (int) y, signal, chiSquared, 0.0f, params, null);
} catch (InputMismatchException e) {
} catch (NoSuchElementException e) {
}
return null;
}
use of java.util.InputMismatchException in project GDSC-SMLM by aherbert.
the class DriftCalculator method readDriftFile.
/**
* Read the drift file storing the T,X,Y into the class level calculatedTimepoints, lastdx and lastdy
* arrays. Ignore any records where T is outside the limits.
*
* @param limits
* @return The number of records read
*/
private int readDriftFile(int[] limits) {
int ok = 0;
BufferedReader input = null;
try {
FileInputStream fis = new FileInputStream(driftFilename);
input = new BufferedReader(new UnicodeReader(fis, null));
String line;
Pattern pattern = Pattern.compile("[\t, ]+");
while ((line = input.readLine()) != null) {
if (line.length() == 0)
continue;
if (Character.isDigit(line.charAt(0))) {
try {
Scanner scanner = new Scanner(line);
scanner.useDelimiter(pattern);
scanner.useLocale(Locale.US);
final int t = scanner.nextInt();
if (t < limits[0] || t > limits[1])
continue;
final double x = scanner.nextDouble();
final double y = scanner.nextDouble();
calculatedTimepoints[t] = ++ok;
lastdx[t] = x;
lastdy[t] = y;
scanner.close();
} catch (InputMismatchException e) {
} catch (NoSuchElementException e) {
}
}
}
} catch (IOException e) {
// ignore
} finally {
try {
if (input != null)
input.close();
} catch (IOException e) {
// Ignore
}
}
return ok;
}
use of java.util.InputMismatchException in project GDSC-SMLM by aherbert.
the class PCPALMClusters method loadHistogram.
/**
* Load the histogram from the file. Assumes the histogram is [int, float] format and creates a contiguous histogram
* from zero
*
* @param filename
* @return
*/
private HistogramData loadHistogram(String filename) {
BufferedReader input = null;
try {
int f = 0;
double a = 0;
String u = "";
FileInputStream fis = new FileInputStream(filename);
input = new BufferedReader(new UnicodeReader(fis, null));
String line;
int count = 0;
ArrayList<float[]> data = new ArrayList<float[]>();
// Read the header and store the calibration if present
while ((line = input.readLine()) != null) {
count++;
if (line.length() == 0)
continue;
if (Character.isDigit(line.charAt(0)))
// This is the first record
break;
String[] fields = line.split("[\t, ]+");
if (fields[0].equalsIgnoreCase("frames"))
f = Integer.parseInt(fields[1]);
if (fields[0].equalsIgnoreCase("area"))
a = Double.parseDouble(fields[1]);
if (fields[0].equalsIgnoreCase("units"))
u = fields[1];
}
final Pattern pattern = Pattern.compile("[\t, ]+");
while (line != null) {
if (line.length() == 0)
continue;
if (!Character.isDigit(line.charAt(0)))
continue;
// Extract the first 2 fields
Scanner scanner = new Scanner(line);
scanner.useLocale(Locale.US);
scanner.useDelimiter(pattern);
try {
int molecules = scanner.nextInt();
float frequency = scanner.nextFloat();
// Check for duplicates
for (float[] d : data) {
if (d[0] == molecules) {
error("Duplicate molecules field on line " + count);
return null;
}
}
data.add(new float[] { molecules, frequency });
} catch (InputMismatchException e) {
error("Incorrect fields on line " + count);
return null;
} catch (NoSuchElementException e) {
error("Incorrect fields on line " + count);
return null;
} finally {
scanner.close();
}
// Get the next line
line = input.readLine();
count++;
}
if (data.isEmpty()) {
error("No data in file " + filename);
return null;
}
// Create a contiguous histogram from zero
int maxN = 0;
for (float[] d : data) {
if (maxN < d[0])
maxN = (int) d[0];
}
float[][] hist = new float[2][maxN + 1];
for (int n = 0; n <= maxN; n++) {
hist[0][n] = n;
for (float[] d : data) {
if (n == d[0])
hist[1][n] = d[1];
}
}
HistogramData histogramData = new HistogramData(hist, f, a, u);
histogramData.filename = filename;
return histogramData;
} catch (IOException e) {
IJ.error(TITLE, "Unable to read from file " + filename);
} finally {
try {
if (input != null)
input.close();
} catch (IOException e) {
// Ignore
}
}
return null;
}
use of java.util.InputMismatchException in project Neuronizer by djuelg.
the class EditHeaderInteractorImpl method run.
@Override
public void run() {
final Optional<TodoListHeader> outDatedItem = repository.todoList().getHeaderById(uuid);
if (!outDatedItem.isPresent()) {
throw new InputMismatchException("Item not existing!");
}
final TodoListHeader updatedItem = outDatedItem.get().update(title, position, expanded);
repository.todoList().update(updatedItem);
final Optional<TodoList> todoList = repository.todoList().getTodoListById(updatedItem.getParentTodoListUuid());
final TodoListHeader itemFromUI = new TodoListHeader(uuid, title, outDatedItem.get().getCreatedAt(), outDatedItem.get().getChangedAt(), position, expanded, outDatedItem.get().getParentTodoListUuid());
if (todoList.isPresent() && !outDatedItem.get().equals(itemFromUI))
repository.todoList().update(todoList.get().updateLastChange());
mMainThread.post(new Runnable() {
@Override
public void run() {
callback.onHeaderUpdated(updatedItem);
}
});
}
Aggregations