TrakEM2 scripting questions

Hello all,

I am attempting to use TrakEm2 to measure the minimal distance between a ball and a profile. I then want to edit this code to find the minimal distance between two or more area_lists. It is section 4.1 of this webpage. I have been able to get the first script to run no problem in the script editor of Fiji. However, the second script is not working for me. It gives the error “TypeError: findbyId(): expected 2 args; got 1”. I am not sure how to work around this. In a Lifeline version of Fiji running Java 6 in the Jython Interpreter on Windows, this same code works without a hitch. My goal is to modify and run the second script from the aforementioned web manual in the latest version of Fiji to return distance measurements.

Thank you for any and all help.

Maybe @albertcardona the author could help with that ? :stuck_out_tongue:

Hi @Chapin_Zerner,
That error would happen when invoking a non-static method (just its usual arguments, here just 1) as a static method. The “self” or “this” pointer to the object instance wouldn’t be present when invoking as a static method.
In other words: did you type Project.findById instead of project.findById by accident? Project is the class name, project is a particular instance of the class, in that script.

Hey @albertcardona thanks so much for your quick response!

I am a high school student working in a university setting for the summer, so your guidance is certainly greatly appreciated. I have been experimenting with this script for quite some time now, and I see what you are referring to with the capitalization of Project.findById.

I apologize if I am missing something, but do I require the use of a self pointer in this instance through the use of a class? I have tried using something along the lines of def init(self, getProjects, findById): to no avail. I have attached what I currently believe to be the code that is closest to working.

To have this work in the latest version of the Fiji script editor with selected language as Python is my goal at first. Then, I would love to be able to measure the distance between area_list profiles without the use of a ball as shown in the scripts in section 4.1.

Thank you once again for your speedy assistance!

Fiji.txt (903 Bytes)

Hi @Chapin_Zerner,

Perhaps it would be a good idea to do a tutorial on python first. Fiji uses python 2.7, so I’d start here: , particularly where it says “tutorial”.

On the script that you sent: there is no need to wrap it in a class. The “self” of the class you are declaring has nothing to do with the “self” in the “project” instance.

The tutorial on python classes and object-oriented programming is here:

1 Like

Hello @albertcardona,

I have looked over the documentation you listed, and I am sorry to say that I am still a bit confused.

I have removed the class from the code, as you said that there is no need to wrap the code in a class.

However, I am still getting an error that reads the following: AttributeError: ‘NoneType’ object has no attribute ‘generateTriangles’. The same error occurs for ‘asWorldPoints’.

Is there any way to resolve this issue?

Additionally, is there is any way to measure minimum distance between an area_list and another area_list?

Thank you for all your help.


Please first put some effort to learn python. Then you’ll realize that what you want to do is not hard.

If what you want is for some else to write the entire python script that your analysis needs, then note there are consultants available.

1 Like

Hi Chapin,
Well for a high school student it seems hard enough to me !
You could open a dedicated post rather than extending on this topic “jython coding advice”.

This error means that the variables vesicles and synapticSurface are actually None meaning that the project.findId(vesiclesID) worked but returned None.

It could simply be that the ID that are used (1541 and 1543 at the top of the script) are too large for your case. You might have less of them. Try a smaller value eventually