Skip to content

Instantly share code, notes, and snippets.

@lacan
Created January 25, 2023 09:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lacan/93eac945ee83a33cf61dc337e975ccfe to your computer and use it in GitHub Desktop.
Save lacan/93eac945ee83a33cf61dc337e975ccfe to your computer and use it in GitHub Desktop.
[Quickly Assess Bleaching] Quick tool for assessing bleaching in Fiji from a copied XY data table from ZEN or LAS-X #Fiji #Macro #Bleaching #ZEN #LASX
macro "Assess Bleaching [F2]" {
// Measure Half time and relate it to number of frames
run("Close All");
// Get the contents of the clipboard as text
text = String.paste;
// Split the lines and then the rows so as to get the X and Y coordinates
line = split(text, "\n");
n = line.length;
// Lines to skip to avoid the headers
skip = 1;
// Create the arrays for x (time) and y (values).
time = newArray( n-skip );
values = newArray( n-skip );
frames = Array.getSequence( n-skip );
for( i=0; i<n-skip; i++ ) { // skip first row
cols = split(line[i+skip], "\t");
time[i] = cols[0];
values[i] = cols[1];
}
// Do curve fitting to get it with time (not so useful but valid)
Fit.doFit("Exponential", time, values);
// get the half time in seconds
b_s = Fit.p(1);
tau_s = -1 * log(2) / b_s;
// do curve fitting to get the result in number of frames
Fit.doFit("Exponential", frames, values);
Fit.plot();
rename("Exponential Fit (frames)");
// get teh half time in frames
b_f = Fit.p(1);
tau_f = -1 * log(2) / b_f; // See https://en.wikipedia.org/wiki/Exponential_decay
// Save the results as a table
if( isOpen("Bleach Assessment") ) { selectWindow("Bleach Assessment"); } else {Table.create("Bleach Assessment"); }
n = Table.size;
// Keep the date for one of the columns, in case the user wants to run it multiple times to compare different values
getDateAndTime(year, month, dayOfWeek, dayOfMonth, hour, minute, second, msec);
dateString = ""+year+"-"+month+"-"+dayOfMonth+" "+hour+":"+minute+":"+second;
Table.set("Date", n, dateString);
Table.set("Half Intensity Reached In (s)", n, d2s(tau_s,1));
Table.set("Half Intensity Reached In (frames)", n, d2s(tau_f,0));
Table.update;
// Show a message to the user
showMessage("You have "+d2s(tau_f,0)+" frames before you lose 50% of your overall intensity");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment