X
PrevPrev Go to previous topic
NextNext Go to next topic
Last Post 13 Feb 2013 11:46 AM by  anon
Save Indices of Non-Missing Values of 2D Arrays the IDL Way
 1 Replies
Sort:
You are not authorized to post a reply.
Author Messages

anon



New Member


Posts:
New Member


--
13 Feb 2013 11:46 AM
    Hi everyone, I am pretty new to IDL, have only been using it for a few months, and am now very stuck when manipulating 2D arrays. I am trying to save the indices of non-missing values of tpw and m9 so I can exclude the missing values. Missing values in these datasets are denoted as -999.000. The dimensions of these two variables are Float[3601,1860]. To exclude the missing values, I need to preserve the dimensions of the variables as I will need to map these. The existing IDL mapping routines that have been developed here require 2D inputs of the m9 and tpw variables. Here is the code I have written to try and do this. It saves the i and j indices for non-missing tpw and m9 values in an idx and idy variable. It keeps on appending the current i and j values that it finds as it goes through the loop (that is what the “IF c EQ 0 THEN BEGIN” loop is there for). Needless to say, it does not work. It doesn’t give me an error or anything. It just seems to get stuck and does absolutely nothing, probably due to all the loops that I have in there: c=0 n=size(tpw) nx=n[1]-1 ny=n[2]-1 FOR i=0,nx DO BEGIN FOR j=0,ny DO BEGIN IF tpw[i,j] NE -999.000 OR m9[i,j] NE -999.000 THEN BEGIN IF c EQ 0 THEN BEGIN ; if c eq 0, save current i and j value idx=i idy=j c=1 ENDIF ELSE BEGIN; append current i and j values to existing idx, idy idx=[idx,i] idy=[idy,j] ENDELSE ENDIF ENDFOR ENDFOR I think I am going the overly complicated way about this and assume that there is a much easier way to do this. The only way that I have semi-managed to get around this is by making all the missing values NaNs as follows: i = WHERE(tpw EQ -999.000 OR m9 EQ -999.000, count) IF (count GT 0)THEN BEGIN tpw[i] = !VALUES.F_NAN m9[i]=!VALUES.F_NAN ENDIF However, life would be much easier if I could just exclude the missing values and not have to deal with NaNs in my dataset. Any suggestions would be greatly appreciated. Thanks! Note: I just made a few changes in there that I had forgotten to make. The code is now updated. Regardless, it still doesn't work.

    Deleted User



    New Member


    Posts:
    New Member


    --
    15 Feb 2013 08:29 AM
    Hi First of all, try to avoid for loops, they are not very efficient in IDL. Secondly, the first and second version of your solution don't give the same result. In the first, if either tpw or m9 has a good value, you count it as a good index. In the second example, if either tpw or m9 has a missing value, you count it as a missing index. But anyway, I would do it as you did in the second example, just the other way around: goodindices = WHERE((tpw NE -999.000) AND (m9 NE -999.000), count) Now, goodindices contains all the valid data points, it will be a 1d-array, but this doesn't matter, since n-dimensional arrays are internally 1-dimensional arrays anyway. The second row is behind the first one, the third behind the second and so on. Hoper that helps
    You are not authorized to post a reply.