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.
|