Is there an easy way to fill channel values for missing data


Recommended Posts

I am collecting channel data at 6 minute HISTORY intervals.

Channel timing ranges from 10 sec with Average so history is at 6 minute interval.

I am logging and exporting at 6 minute, 1 hour, and 24 hour intervals.

Is there a QUICK or Easy way to.

At DFexpress loading of the *.ctl file

Check time of last data collection, i.e, basetime=channelx.Time[0]

Based on that value AND current system time

Fill ALL channel's histories with nAn values upto the current time mod 360.

i.e., from channelx.time[0] to current time at 360 sec increments

Some of the hourly files do mean, max, min. The 24 hour file dumps a days worth of data.

The only way I can think of doing it is do a loop FOR EACH channel,

channelx.addvalue(????) nAn

Then do channelx.TIME[0] =channelx.TIME[1] +360

and loop til completed

Which leads to question, will nAn, be correctly recognized by mean, max, min????

Link to comment
Share on other sites

That's the right approach, but use execute() inside your loop so you don't have to type out every channel name. This assumes that your channels are numbered in order. Execute might read something like this:

for (private x = 0, x < 10, x++)
   execute("channel" + doubletostr(x) + ".AddValue(y)")
endfor

Now, you can't do channelx.time, but addvalue will use the time of whatever you pass, so create another variable, say y in my case and set it to NaN then set its time:

y = Nan()
y.time = channelx.time[0] + 360

Link to comment
Share on other sites

I found Channel.ListALL() function

ListAll([group]): returns an array of strings containing the names of all the channels. If group is provided, only those channels in the given group are returned: Channel.ListAll("Main"). Used in conjunction with Execute() or Evaluate() you could easily apply things across groups of channels.

Since this returns a csv string, I'm evidently missing the easily part. :>)

Note: I didn't find this in DF help, but it works V.channel.listall()

Link to comment
Share on other sites

My script does set the value to NaN() and the time to 6 minutes more then channelx.time[0].

Yes, mean/sum, etc ignore nan values.

Channel.ListAll() returns an array of strings, not a csv string. You can just loop through them:

private string chanlist = channel.listall()
for (private x = 0, x < numrows(chanlist), x++)
   execute(chanlist[x] + ".AddValue(y)")
endfor

Link to comment
Share on other sites

  • 5 weeks later...

Got it working BUT

Export sets that output the NaN data to a *.csv file with ff expression(s)

Format("%4.2f",(max(v.S_kw_hrs[0,9]))) output is 100000000000000000000 "didn't count all the 0's"

same but min() ditto

same but mean() output is 1.#J

was told that the NaN values would be ignored by above functions, max, min, mean

If I output just channel[0] get inf

Cannot find what "inf" is, but possibly stands for infinite???????

Link to comment
Share on other sites

I think perhaps you are using an older version of DAQFactory that did not properly ignore nans. Try going to the command prompt and typing this:

global x = {1,2,3}

? mean(x)

should display 2

x[2] = nan()

? mean(x)

should display 1.5

My version, 5.79a, does this. If you get anything else you should go and get the latest release.

Link to comment
Share on other sites

well that certainly makes sense. If there is nothing but NaN's, there's nothing left to do mean/min/max on. Format displays a weird value because internally, nan is actually 1e300, which is usually easier to deal with for reasons I won't go into. Here's what you can do:

iif(mychan[0] == NaN(),"NaN",Format("%.3f",mychan[0]))

This will display NaN if its NaN, and a formatted value otherwise.

Link to comment
Share on other sites

  • 2 weeks later...

iif(mychan[0] == NaN(),"NaN",Format("%.3f",mychan[0]))

This will display NaN if its NaN, and a formatted value otherwise.

I'm using the output in an export sets with of the form of max(mychan[0,9]) so is it safe to assume that

the line would be:

iff(max(mychan[0,9]) ==NaN(), "NaN", format("%.3f", max(mychan[0,9])))

+ or - a parentheses or two.

will work????

Link to comment
Share on other sites

  • 1 year later...

Sorry to bump another old thread, but this is the only thread I've found with info on "NaN" values...

I have a few values that depend on a counter to be running using the 2 counters on my LJ U3...

I also have the counters counts per/min value in a while(1) loop because the counters turn on and off frequently...

I would like to know if there is an easy way to replace "NaN" values with just a plain 'ole "0" or "1" just to keep my calced values displaying a number instead of "NaN".

I tried a few iif() statements, but I don't think I quite understand yet...

Any pointers would be great! :)

Link to comment
Share on other sites

This is what I've ended up with -

if(Strokes[0] < 10) && (Strokes2[0] < 10)
   PumpsOff[0] = 1
   Variable1[0] = 0
   Variable2[0] = 0
   Variable3[0] = 0
   Variable4[0] = 0
   Variable5[0] = 0
   Variable6[0] = 0
   //ect...
else
   PumpsOff[0] = 0
endif

Seems to be a "cheater" way of doing it, but atleast I have zeros instead of NaN... :)

Link to comment
Share on other sites

Its usually better to adjust the display, as having 0 or 1 in your data might get confused for actual data. You can take it out of your display using iif. For example:

iif(variable1[0] == Nan(), "---", variable1[0])

Of course you can put calcs in too.

Link to comment
Share on other sites

Ahh, that's where I was going wrong...

I thought NaN was a string, so I was trying to figure out how to use it...I thought it was like this -

iif(variable1[0] == "NaN"

:P

Thanks again, very much appreciated. :)

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.