I have the following workflow (console output is shown as > ...) --

    my $pdl = readflex("$file");

    # Print basic info for the piddle
    print "Info: " . $pdl->info . "\n";
    > Info: PDL: Float D [271116,99]

    # Set the bad value for the piddle
    my $bad = -9999;
    print "Setting BAD to $bad... ";
    $pdl->badvalue($bad);
    print "and turning on the bad flag\n";
    $pdl->badflag(1);
    > Setting BAD to -9999... and turning on the bad flag

    # Print the dims of the piddle
    my @dims = $pdl->dims;
    print "Num of cells: " . $dims[0] . ", Num of years: " . $dims[1] . "\n";
    Num of cells: 271116, Num of years: 99

    for my $year (0 .. 2) {

        # Get a ref to one year's worth of data
        my $ypdl = $pdl->slice(":,$year");
        print "Info for year $year: " . $ypdl->info . "\n";
        > Info for year 0: PDL: Float D [271116,1]

        # Exchange the piddle dims to calculate the averages
        print "Average for year $year: " . avg($ypdl) . "\n";
        > Average for year 0: BAD

        # Print the sum of the piddle
        print "Sum for year $year: " . sum($ypdl) . "\n";
        > Sum for year 0: BAD
    }
}

I have the following questions --

1. I actually have 100 years in the second dimension. I understood the
$pdl->dims method to return the size of the dim. So, shouldn't it have
returned 100 instead of 99. My understanding is that 99 is the highest
value, but the number of values is 100. Did I understand wrong, or
should I go back and check my data?

2. Is my approach correct? I am looping over the second dimension, but
is there a PDL-ish way for doing that?

3. The docs for avg say that it averages over the 1st dim. I actually
want to avg over the second dim. Should I be doing something like

    my $yave = average $ypdl->xchg(0, 1);

Also, the same question applies for sum.

4. The docs for avg (and for sum) say that the routines do handle BAD
values. I understood that to mean that they would discard the BAD
values in their calculation, not return a BAD value.

5. I really don't understand the difference between sum and sumover.

Many thanks for putting up with these really basic steps.

My subsequent tasks would be to plot charts of the averages and sums
by year, and create images of all the cells for every year. Again, I
am hoping to discard the BAD values in doing so. What I really should
be doing is creating piddles of the averages and sums, and then using
PLplot to plot the charts. Suggestions?

-- 
Puneet Kishor

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

Reply via email to