comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » newbie wants to enforce "array conservation"
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
newbie wants to enforce "array conservation" [message #61619] Mon, 21 July 2008 17:51
Tom Roche is currently offline  Tom Roche
Messages: 11
Registered: July 2008
Junior Member
How to check that two arrays have the same totals, to some tolerance?
and to throw an error if they don't? Especially if they are not the
same size? (Apologies if these are FAQs, but I've googled and searched
the online help and I'm not seeing it.) 3 more detailed questions
below:

I'm massaging netCDF files containing data on emissions over space and
time. (Sometimes space is 2D, others 3D.) I want to ensure that I'm
not corrupting the emissions, e.g. by conserving mass. I'm guessing a
straightforward way to verify conservation is to check that, after
each step in the overall process, the sum of emissions in the
pre-massage file matches the sum of emissions in the post-massage
file. I remember just enough of my undergraduate scientific-computing
course to know that I want to match subject to some tolerance. I don't
know IDL very well, but I can see

http://idlastro.gsfc.nasa.gov/idl_html_help/ARRAY_EQUAL.html

That should work for massages that don't change the size of the data:
unfortunately I must also do regridding, which changes the size. For
size-invariant massage I'm thinking I should do something like this:

; time is the first dimension in all these arrays
timeIndex=1
; read pre-massage data into array "before"
; read post-massage data into array "after"
; total before
before_total=TOTAL(before,timeIndex,/NAN)
badval=WHERE(before_total eq 0, ct)
IF ct ne 0 THEN before_total[badval]=0
; total after
after_total=TOTAL(after,timeIndex,/NAN)
badval=WHERE(after_total eq 0, ct)
IF ct ne 0 THEN after_total[badval]=0
; check match including size
IF not ARRAY_EQUAL(before_total, after_total, /NO_TYPECONV) THEN
<throw error/>

Does that look right? If so,

1 How does one typically throw a (non-GUI) error in IDL?

2 How does ARRAY_EQUAL handle tolerance? I was somewhat surprised that
there was not, e.g., a keyword. Am I missing something?

If not, how should size-invariant array matching be done?

For size-variant massage (i.e. SIZE(input) ne SIZE(output)) one cannot
use ARRAY_EQUAL, because it checks that array sizes match. (Or am I
missing something?) So I'm thinking I should verify size-variant
massages by just matching the scalar sums, e.g.

; read pre-massage data into array "before"
; read post-massage data into array "after"
; scalar total before
before_total=TOTAL(before,/NAN)
; scalar total after
after_total=TOTAL(after,/NAN)
; check match ignoring size
diff=ABS(before_total-after_total)
tolerance=<some small float/>
IF diff gt tolerance THEN <throw error/>

Does that look right? If so,

3 How does one determine a good tolerance value?

If not, how should size-variant array matching be done?

TIA, Tom Roche <Tom_Roche@pobox.com>
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: *really* online help for IDL?
Next Topic: union or overlap of two plots

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 19:48:14 PDT 2025

Total time taken to generate the page: 0.00504 seconds