How to use aggregate functions on Arrays

Basic question, just getting started.

So I have a tag that represents an array of INT’s. I’d like to display the value of the average of that array. When I generate a custom property for the linear scale object that will display it, I bind the property to the expression

mean({path/arraytag},0)

And the scale is then greyed out, with a blue tag with a red ‘x’ in the top corner. The online manual only gives an example for the mean function using a 2-dimensional database, so I’m not sure what I could be doing wrong here. I’m used to working with Python, datatypes are handled intelligently by the compiler, but I don’t believe the expression window runs on Python. Do I need to convert my INT’s to floats first?

Edit:

Having found the same blue tag-red x error indication in another linkage, I realized that I was including the base ‘Tags’ Folder in my path. Omitting ‘Tags’ from the path in that particular scale solves the problem. As that scale shows the difference between nearest neighbor values from the same array, I have not involved any of the built in math functions. Simply subtracting one array value from another seems to work fine, suggesting the issue for my other scale is in the call to the mean function.

However, now when I attempt to implement the script, I get:
“Type mismatch: Argument 0 for function ‘mean(dataset, column OR number, number…)’ needs to be a number”

Argument zero is my dataset path, correct?

My path extended as far as the top-level name of the array, though it has a sub-property ‘Value’ which has 24 indices. If I change my path name to include ‘Value’, I get the same blue tag, red-x warning that seems to indicate an invalid path.

Ignition’s array tags are only arrays of bits at this point – do you mean you have a dataset of INTs? And yes, expression bindings are not python at all. See the expression functions reference in the manual for what you can use.

As I said, I have checked the manual. As someone who speaks python (specifically numpy), I don’t consider 1-d Arrays and 2-d Datasets to be different species, but again, I don’t speak Ignition yet. Since the manual does not cover my use case, I can’t be sure if it was neglected as a redundant generalization or because it is impossible within Ignition.

When I generate the OPC tag, the Datatype I select is Integer Array. Since it’s a selection preloaded in the dropdown menu, I’d imagine that it is precisely what it says it is, an array of integer values. I’d hope that, having a 1-d array of values, that I would be able to use combinations of permutations of them the same way I would several individual INT tags.

Am I mistaken?

I suppose I can always just write 1/n*{path/array[0]}+1/n*{path/array[1]}+… 1/n*{path/array[n]}

But that seems a bit verbose.

In the context of the aggregate functions, they can only accept an object that implements the Ignition DataSet interface even though the underlying storage mechanism is likely a 2-d array.

If you set the memory tag up as the DataSet type, and just configure the value like a 1-d array then it’ll work out of the box. In “real life” that might not be as simple depending on what is writing to the tag, but if it is just for testing it’ll get you the info you want.

The other option would be using the runScript expression with a one-liner or helper function that converts an array to a dataset.

The Integer Array tag type is poorly named. It is a bit array produced from the given-sized integer data source. I understand this is being reworked for v8.0.

Thanks Phillip!

I’ll give that a shot.

Quick question, Memory Tag vs. OPC tag. The tag array I’m working with is an OPC tag array. That is, I’m reading these values directly from our PLC memory (where they are stored as an array) and deriving values from there.

Should I be using Memory tags, rather than OPC tags for this work?

OOOooof. Thanks. I would have never figured that out.

How then are the integers converted into bits? Zero or nonzero?

Bitwise. Least-significant bit of the integer is placed in subscript zero of the bit array.

Oh, so one integer is 32 bits or so. So the 24 element array I’d thought was storing 24 INT was only holding most of the first element.

I could have banged my head against that one forever without getting it.

8.0 needs to get here quick.

I figured it out when I fed some real data to one. I haven't used it since. /-:

So. Problem solved. To compress for anyone who might need this later:

DO NOT use Integer Arrays as arrays of integers (as of 7.9).

Type your tags, instead, as datasets. The expression functions that pertain to aggregated data will then operate correctly.

Also, your tag paths should begin with the first level down BELOW the ‘Tags’ folder.

Thanks, all