Last active
December 21, 2022 15:23
-
-
Save flowernert/25008c65c2872f9a646a91a3b6f50101 to your computer and use it in GitHub Desktop.
ImageJ/FiJi check microscope acquisition parameters consistency
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Intensity and exposure labels | |
var labelChName = "Information|Image|Channel|Name #"; //ok | |
var labelChLaser = "Information|Image|Channel|Intensity #"; //ok most of the times | |
var labelChExposure = "Information|Image|Channel|ExposureTime #"; //ok but needs to be divided | |
//var labelCh1Name = "Experiment|AcquisitionBlock|MultiTrackSetup|Track|Channel|Name #1"; | |
//var labelChLaser = "Experiment|HardwareSettingsPool|HardwareSetting|ParameterCollection|Intensity #1"; | |
//var labelCh1exposure = "Experiment|AcquisitionBlock|MultiTrackSetup|Track|Channel|DataGrabberSetup|CameraFrameSetup|ExposureTime #1"; | |
var options = "color_mode=Default rois_import=[ROI manager] stack_order=Default"; | |
macro "Check metadata" { | |
//CZI dir selection | |
dir = getDir("Choose a directory"); | |
filelist = getFileList(dir); | |
//find 1st file intensity and exposuretime | |
reffile = ""; | |
for (i = 0; i < lengthOf(filelist) ; i++) { | |
if (endsWith(filelist[i], ".czi")) { | |
reffile = filelist[i]; | |
run("Bio-Formats Importer","open=[" + dir + reffile + "] " + options); | |
break; | |
} | |
} | |
nbCh = Property.getNumber("SizeC"); | |
// Dialog creation, fills values based on 1st CZI file values | |
Dialog.create("Enter power and exposure to check"); | |
Dialog.addMessage(nbCh + " channels"); | |
Dialog.addMessage("Exposure time in ms"); | |
for (i = 1 ; i <= nbCh ; i++) { | |
Dialog.addNumber(Property.get(labelChName + i), Property.getNumber(labelChExposure+i)*1e-6); | |
} | |
Dialog.addMessage("Laser power in %"); | |
for (i = 1 ; i <= nbCh ; i++) { | |
tmp = split(Property.get(labelChLaser+i), "%"); | |
Dialog.addNumber(Property.get(labelChName + i), parseFloat(tmp[0])); | |
} | |
Dialog.addSlider("Tolerance in percent", 0.0, 10.0, 2.0); | |
Dialog.addCheckbox("Export to CSV", true); | |
Dialog.show(); | |
// getting info back from dialog | |
refExpTime = newArray(nbCh); | |
refPower = newArray(nbCh); | |
for (i = 0; i < nbCh; i++) { | |
refExpTime[i] = Dialog.getNumber(); | |
} | |
for (i = 0; i < nbCh; i++) { | |
refPower[i] = Dialog.getNumber(); | |
} | |
tolerance = Dialog.getNumber()/100; | |
export = Dialog.getCheckbox(); | |
// Doing the verification for each file | |
filelist = getFileList(dir) ; | |
//results storage | |
foundExpTimes = newArray(lengthOf(filelist) * nbCh); | |
foundPowers = newArray(lengthOf(filelist) * nbCh); | |
for (i = 0; i < lengthOf(filelist); i++) { | |
if (endsWith(filelist[i], ".czi")) { | |
print(dir + filelist[i]); | |
run("Bio-Formats Importer","open=[" + dir + filelist[i] + "] " + options); | |
for (j = 0; j < nbCh; j++) { | |
foundExpTime = Property.getNumber(labelChExposure+j+1) *1e-6; | |
foundExpTimes[i+j*lengthOf(filelist)] = foundExpTime; | |
if (foundExpTime < refExpTime[j] - refExpTime[j]*tolerance || | |
foundExpTime > refExpTime[j] + refExpTime[j]*tolerance || | |
isNaN(foundExpTime)) { | |
print("\t " + "Exposure mismatch, " + foundExpTime + " found against " + refExpTime[j] + " on channel " + j); | |
} | |
foundPower = Property.get(labelChLaser+j+1); | |
if (lengthOf(foundPower) > 0) { | |
tmp = split(foundPower, "%"); | |
foundPower = parseFloat(tmp[0]); | |
foundPowers[i+j*lengthOf(filelist)] = foundPower; | |
if (foundPower < refPower[j] - refPower[j]*tolerance || | |
foundPower > refPower[j] + refPower[j]*tolerance || | |
isNaN(foundPower)) { | |
print("\t Laser power mismatch, " + foundPower + " found against " + refPower[j] + " on channel " + j); | |
} | |
} | |
else { | |
print("\t no laser power can be found for channel " + j); | |
} | |
} | |
close("*"); | |
} | |
} | |
Table.create("Acquisition parameters"); | |
Table.setColumn("File", filelist); | |
for (i = 0; i < lengthOf(filelist) ; i++) { | |
for (j = 0 ; j < nbCh ; j++) { | |
Table.set("Exposure C" + parseInt(j), i, foundExpTimes[i+j*lengthOf(filelist)]); | |
} | |
for (j = 0 ; j < nbCh ; j++) { | |
Table.set("Power C" + parseInt(j), i, foundPowers[i+j*lengthOf(filelist)]); | |
} | |
} | |
if (export) { | |
Table.save(dir + "Acquisition parameters.csv"); | |
} | |
} |
Full update and simplification after discovering the Property.get API
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The script now automatically fills the acquisition parameters in the Dialog box based on the first .czi image parameters, you still can change it manually before to launch the verification.
You can now export the acquisition parameters to a CSV file
Next feature I'll develop will be to be compatible with nd2 files for Nikon microscopes acquisitions