Analyze Z stack images and choose Z plane to image

Post your acquisition-related questions and macros here
CarlZeissMicroscopy3
Posts: 180
Joined: Wed May 20, 2020 10:10 am

Re: Analyze Z stack images and choose Z plane to image

Post by CarlZeissMicroscopy3 »

Hello Anand Ranjan,

happy to hear that your OAD macro works great.

File.Exists(path) is not an OAD command.

This is one of the strengths of OAD that you can import .Net DLLs e.g., from the .Net Framework, and use them!

You get class File by importing from System.IO at the beginning of your code.
In your case:
from System.IO import Path, File

Please be aware that the existence of a file does not necessarily mean that you can read it.
E.g. the file exists during the write process but you cannot read it at that time.
You might need some additional code like.

Code: Select all

fs = File.Open(filename + '_minVar.txt', FileMode.Open)      
canRead = fs.CanRead
canWrite = fs.CanWrite       
fs.Close()
fs.Dispose()
To get FileMode as well, the import looks like this:
from System.IO import Path, File, FileMode

I hope this helps to make your macro perfect.
Anand Ranjan
Posts: 14
Joined: Wed Dec 02, 2020 7:53 pm

Re: Analyze Z stack images and choose Z plane to image

Post by Anand Ranjan »

Thanks again for your reply. You correctly anticipated the problem that only checking for the existence of .txt file would not be enough and one has to check if the file can be read. We implemented that, but occasionally the file would show empty content. It seems Zen was reading the .txt file before the Fiji macro finished writing the result. This problem got fixed by a small change in Zen script to ensure the .txt file was not empty.

Here's the final script that works very well-
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------
fs=File.Open(filename + '_minVar.txt', FileMode.Open, FileAccess.Read, FileShare.ReadWrite)
canRead = fs.CanRead
reader = StreamReader(fs)
fileContent = reader.ReadLine()
while (String.IsNullOrEmpty(fileContent)):
fileContent = reader.ReadLine()
fs.Close()
fs.Dispose()

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
Many thanks for your patience and help.
Anand
CarlZeissMicroscopy3
Posts: 180
Joined: Wed May 20, 2020 10:10 am

Re: Analyze Z stack images and choose Z plane to image

Post by CarlZeissMicroscopy3 »

Hello Anand Ranjan,

thank you for posting your final solution!

Although the empty file might be a peculiarity of Fiji other people can profit from your experience.
Post Reply