Brian Larsen
17 years ago
All,
I am using hist_nd.pro from J.D. Smith to find the indices that are in
each bin of a 2d mapping of data.
I have 3 arrays:
THEMIS> help, theta, lshell, pxxm
THETA DOUBLE = Array[282576]
LSHELL DOUBLE = Array[282576]
PXXM FLOAT = Array[282576]
I want the mean pxxm in each of the theta-lshell 2d space.
This is accomplished with:
nd = hist_nd(transpose([[theta],[lshell]]), $
[size_theta_bin, size_l_bin], $
min = [min(theta) > min_theta, min(lshell) > min_lshell],
$
max = [max(theta) < max_theta, max(lshell) < max_lshell],
$
reverse_indices = ri)
OK so here is the part where I want some cleverness. I have not
figured out how to do this without nested for loops and those are evil
(as we all know).
bins_mean = fltarr(size(nd, /dim))
nx = (size(nd, /dim))[0]
ny = (size(nd, /dim))[1]
FOR i = 0UL, nx-1 DO BEGIN
FOR j = 0UL, ny-1 DO BEGIN
ind_ri = [i+nx*j]
IF ri[ind_ri] EQ ri[ind_ri+1] THEN CONTINUE ; nothing to do in
this iteration
ri_sel = ri[ri[ind_ri]:ri[ind_ri+1]-1]
bins_mean[i, j] = mean(pxxm(ri_sel), /nan)
ENDFOR
ENDFOR
Is there some other/better way to do this? I am wondering if I am
missing a trick, or just thinking about this wrong, or I have it
right. The reverse indices is always cool and always a bit of voodoo
for me.
Thanks all,
Brian
--------------------------------------------------------------------------
Brian Larsen
Boston University
Center for Space Physics
http://people.bu.edu/balarsen/Home/IDL
I am using hist_nd.pro from J.D. Smith to find the indices that are in
each bin of a 2d mapping of data.
I have 3 arrays:
THEMIS> help, theta, lshell, pxxm
THETA DOUBLE = Array[282576]
LSHELL DOUBLE = Array[282576]
PXXM FLOAT = Array[282576]
I want the mean pxxm in each of the theta-lshell 2d space.
This is accomplished with:
nd = hist_nd(transpose([[theta],[lshell]]), $
[size_theta_bin, size_l_bin], $
min = [min(theta) > min_theta, min(lshell) > min_lshell],
$
max = [max(theta) < max_theta, max(lshell) < max_lshell],
$
reverse_indices = ri)
OK so here is the part where I want some cleverness. I have not
figured out how to do this without nested for loops and those are evil
(as we all know).
bins_mean = fltarr(size(nd, /dim))
nx = (size(nd, /dim))[0]
ny = (size(nd, /dim))[1]
FOR i = 0UL, nx-1 DO BEGIN
FOR j = 0UL, ny-1 DO BEGIN
ind_ri = [i+nx*j]
IF ri[ind_ri] EQ ri[ind_ri+1] THEN CONTINUE ; nothing to do in
this iteration
ri_sel = ri[ri[ind_ri]:ri[ind_ri+1]-1]
bins_mean[i, j] = mean(pxxm(ri_sel), /nan)
ENDFOR
ENDFOR
Is there some other/better way to do this? I am wondering if I am
missing a trick, or just thinking about this wrong, or I have it
right. The reverse indices is always cool and always a bit of voodoo
for me.
Thanks all,
Brian
--------------------------------------------------------------------------
Brian Larsen
Boston University
Center for Space Physics
http://people.bu.edu/balarsen/Home/IDL