Dear PDL'ers,

I am stuck with an apparently simple problem and hoped that someone in
this list might have a clue.

I have approx. 130000 pairs of data, z and r,  which represent
observations of some function r  at some coordinate z.
A sample of the data looks like this:

z      r

 3311  311.817
 3346  249.333
 3238  353.368
 3279  367.020
 3347  324.405
 3448  274.632
 3161  310.469
 3204  358.739
...... ......

These observations come from a three dimensional space, and therefore
there exists more than one r value for each value of the coordinate z.
What I want to do is to estimate a gross distribution of r values
versus z. Simple as it seems I am having troubles to set up a PDL code
to compute it.

My thought is: first compute bins (hist) of the z variable and then
find all r observations that fit within intervals (z - delta_z; z
+delta_z), over the whole range of z. Finally find the average,
maximum and distribution of r values over that interval.

The idea was to create a 2D piddle where the rows are values of r and
the columns are the values of z bins. Then, by some suitable
transposing, obtain the r values using which and index. As I could not
make this work, I tried with the less fancy approach of doing a loop
with 1D piddles.  My (still not working) version of the solution is:


use PDL;
use PDL::NiceSlice;
use PDL::Graphics::PGPLOT;

# read data into two piddles
my ($z,$r) = rcols ('data');

# calculates bins of size 10 from $z values between minimum and maximum
my ($zv,$zfs) = hist($z, int (min $z), int (max $z), 10);

# defines auxiliary variables
# lower limit of bin
my $zvl = $zv - 5;
# upper limit of bin
my $zvu = $zv + 5;

# an empty piddle to allocate the aggregated observations
# its dimensions are those of the binned z values
my $ri = zeroes(nelem($zv));

# a temporary piddle
# its dimensions are those of the original data
my $tmp = zeroes(nelem($z));

# sets an index variable to 0
my $i = 0;

# starts the loop
while ($i < nelem($zv)) {

# finds the indexes of z elements that fit within the interval,
# captures the r values at the same locations and stores that in the temp piddle
$tmp .= $r->index(which($z > $zvl($i)  |  $z < $zvu($i) ));

# calculates some statistics
$ri($i) .= average ($tmp);

$i++;
}

# plots ...
points zv,$ri;


This doesn't work though and neither did its many sibling versions. I
am stuck and perplexed.

Any hint will be appreciated!


Thanks!



Hernán




-- 

Hernán De Angelis
Linux user # 397217

_______________________________________________
Perldl mailing list
[email protected]
http://mailman.jach.hawaii.edu/mailman/listinfo/perldl

Reply via email to