Creating and consuming collections and arrays

Is there any way I can mix and match collection cells (i.e. […], such as those created by the List or Set aggregation functions) with Double[] cells (i.e. [D], such as those created by the ImageJ2 integration when using double[] as an output @Parameter)?

I tried the following code in an ImageJ2/SciJava Command:

@Plugin(type = Command.class, headless = true,
	menuPath = "FMI>Testing>Input Double Collection")
public class InputDoubleCollection implements Command {

	@Parameter(label = "Some doubles")
	private Collection<Double>[] m;

	@Parameter
	private LogService log;

	@Override
	public void run() {
		log.error("Double Array input running...");
	}
}

… and while it does auto-generate a node, I get the following error when trying to add it to a workflow:

ERROR Input Double Collection 2:3        Error while creating node dialog for 'Input Double Collection': Can not set [Ljava.util.Collection; field ch.fmi.test.InputDoubleCollection.m to org.scijava.Context

If it doesn’t work this way, is there maybe a way to create the [D] column type using a Java Snippet node?

My specific use case: I’d like to dynamically generate the input to one of my plugins (e.g. TrackMateCollectionTracker) from an arbitrary number of rows in a KNIME table at runtime (without knowing the number of rows beforehand, of course).

Would you have any helpful advice for me (@christian.dietz, @stelfrich, @gab1one) ? :slight_smile:

Hi @imagejan,

The ImageJ2 integration works on a row-by-row basis. There is currently no way for a generated node to consume several rows at once. I guess you are aggregating the rows you want work on in a collection to then pass them to the node? This is currently not working, as there are no converters for collection cells to raw java types. You can see the implemented adapters here: https://github.com/knime-ip/knip-imagej2/tree/master/org.knime.knip.imagej2.core/src/org/knime/knip/imagej2/core/adapter/impl

best,
Gabriel

Yes, hence my approach to create a collection cell before feeding it to an ImageJ2 plugin.

That’s really unfortunate. Is there a way to create a double array cell with the Java snippet then?

There are no converters from KNIME collection cells to raw java types for the ImageJ2 integration. So if you have such a cell, you can currently not consume it with the ImageJ2 integration.

You can create Collection cells containing double[][] arrays using the Create Collection Column node, see the attached workflow for an example.
create double-array.knwf (9.7 KB)

best,
Gabriel

Thanks @gab1one for the explanations.

Yes, that’s what I was trying, but as the type of the cells is still just a “Collection” (as indicated by the […] column header) and not a Double[] (which shows up as [D] column header), there’s no way to use this in the ImageJ2 integration at all, right?

The other thing I was trying was adding a column of type Double and selecting the Is array option in the Java Snippet node:

image

… but this also just generates a […] collection cell instead of the [D] that I’d have expected.

The column type with the header [D] is a Double Vector (Collection Of Number (double)), which is only used by the Wide Data Extension. The […] collection cell are core KNIME.

best,
Gabriel

… and by the KNIME Image Processing extension. When I define an output as such:

	@Parameter(type = ItemIO.OUTPUT)
	private double[] matrix;

… I get a [D] column type.

Thanks for pointing me to the Wide Data Extension. I noticed they provide an Expand Vector node (that essentially does the same as the Split Collection Column node, no?), but what I’d require here is rather the opposite: a “combine/merge columns into vector” node.


Here’s a small workflow (making use of nodes from the FMI KNIME Plugins update site) that illustrates what I was trying to achieve:

image

Thanks to your hint to the Wide Data Extension, I was able to find a workaround by saving my values to a temporary CSV file and reading them with the CSV Array Reader node provided by that extension, but it’s a bit complicated:

image

Here’s the example workflow file: Double Vector and Collections.knwf (76.1 KB)

If you have any suggestions on how to improve this, I’d be happy to learn :slight_smile:

1 Like

I am as surprised as you, that there is no Columns to Vector node, seems like an oversight
I found a much better workaround:
Selection_020

You need to convert the columns to a string, to then use the line chopper to convert them to an array :roll_eyes:, but it works :+1:

Double array fun.knwf (8.2 KB)

1 Like

Thanks, I hadn’t looked at the Line Chopper yet, that’s indeed much better!

I think it would be useful if the Wide Data Extension (or any other component) provided a new aggregation function Vector similar to the currently available List (in the GroupBy and Pivoting nodes) that would create vector columns instead of collections.

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.