even more bizarre... On Tue, Aug 31, 2010 at 1:14 PM, P Kishor <[email protected]> wrote: > On Tue, Aug 31, 2010 at 11:59 AM, P Kishor <[email protected]> wrote: >> On Tue, Aug 31, 2010 at 11:54 AM, Chris Marshall <[email protected]> wrote: >>>> I would love to learn that I am doing something stupid, >>>> but I am fairly convinced that there is either a bug or >>>> an untrapped error in the PDL code. >>> >>> Actually the error is being trapped which is what >>> you have reported. The problem is that you have >>> bad values in the image data that you are trying >>> to save. >>> >>> If there is a problem with the current PDL >>> code, it may be that an error is *not* being given >>> for the non-LUT wpic() case. >>> >>> At any rate, the fix is to save image data *without* >>> bad values in them. I suggest using setbadtoval() >>> and then make that value in your color map special >>> (e.g., bright red so you can see the erroneous pixels). >>> >> >> I don't even know which value is bad? If I can't see it, if I don't >> know which one it is, if I can't even list it out, how do I know which >> one to setbadtoval()? >> >> I already have set -9999 to bad, as those are pixels with no data. I >> used to have NaNs, and I have gotten rid of those. Now, as far as I >> can tell, I have either -9999, or I have a valid number. >> >> When I write the entire piddle to a b&w image, it writes fine. When I >> try to use a LUT, all hell breaks loose. >> >> as you say, I should use "setbadtoval() and then make that value in >> your color map special." What is "that value"? That is what I am >> trying to determine. >> >> > > > Assuming that something might be wrong with the BAD values in my > piddles, I did the following -- > > # Set the bad value for the piddle and turn on the badflag > $pdl->badvalue(-9999.0); > $pdl->badflag(1); > > # Multiply each value by 10 > $pdl = $pdl * 10; > pdl_info('pdl', $pdl); > > # Get the min max > my ($min, $max) = $pdl->minmax; > my $div = int(($max - $min) / 10) + 1; > > # Grab a piddle for one year, and flip the piddle to correct "video coords" > my $ypdl = $pdl->slice(":,:,0")->squeeze()->slice(':,-1:0:-1'); > > # Place each element of the pdl into a corresponding bin and convert to > byte > $ypdl = byte(floor ($ypdl / $div)); > pdl_info('ypdl', $ypdl); > > # Create a lookup table ######## > my $lut = get_lut(); > pdl_info('lut', $lut); > > # Replicate ImageRGB.pm code > my $foo = byte($lut->xchg(0,1)); > pdl_info('foo', $foo); > > my $bar = $ypdl->dummy(0); > pdl_info('bar', $bar); > > my $res = index($foo, $bar); > pdl_info('res', $res); > > print bigstring($res,"%3g") . "\n"; > > > sub pdl_info { > my ($name, $pdl) = @_; > > print "\n"; > print "State of bad flag in piddle $name: " . > $pdl->check_badflag . "\n"; > print "The bad value for piddle $name is: " . $pdl->badvalue() . "\n"; > print " Info for piddle $name: " . $pdl->info . "\n"; > print "-" x 50 . "\n"; > } > > sub get_lut { > my $lut = byte(zeroes 3, 256); > > # Increment red from 0 to 255 > my $r = $lut->slice('0,:'); > $r .= $r + $r->yvals; > > # Set green to 255 > my $g = $lut->slice('1,:'); > $g .= $g + 255; > > return $lut; > } > > sub bigstring { > my($pdl, $fmt, $lev) = @_; > > $fmt = "%g" unless($fmt); > my $s=" "x$lev; > > if($pdl->ndims > 1) { > $s .= join("\n", "[", (map { bigstring($_,$fmt,$lev+1) > } dog $pdl), $s."]"); > } > elsif ($pdl->ndims) { > $s .= "[ " . join(" ",map { sprintf($fmt,$_) } > $pdl->list) . " ]"; > } > else { > $s = sprintf($fmt,$pdl->at(0)); > } > > return $s; > } > > This is what printed out > > punk...@hardangervidda ~/Data/carbonmodel/cnnf$perl testindex.pl > > State of bad flag in piddle pdl: 1 > The bad value for piddle pdl is: -9999 > Info for piddle pdl: PDL: Float D [252,189,100] > -------------------------------------------------- > > State of bad flag in piddle ypdl: 1 > The bad value for piddle ypdl is: 255 > Info for piddle ypdl: PDL: Byte D [252,189] > -------------------------------------------------- > > State of bad flag in piddle lut: 0 > The bad value for piddle lut is: 255 > Info for piddle lut: PDL: Byte D [3,256] > -------------------------------------------------- > > State of bad flag in piddle foo: 0 > The bad value for piddle foo is: 255 > Info for piddle foo: PDL: Byte D [256,3] > -------------------------------------------------- > > State of bad flag in piddle bar: 1 > The bad value for piddle bar is: 255 > Info for piddle bar: PDL: Byte D [1,252,189] > -------------------------------------------------- > > PDL::index: invalid index -2147483648 (valid range 0..255) at > /usr/local/lib/perl5/site_perl/5.12.1/darwin-2level/PDL/Bad.pm line > 493. > >
I printed out the $foo and $bar piddles in my code above using Craig's bigstring (it barfed on $res, as expected). I saved the output to a file. Then I opened that output file and reworked the output of $foo and $bar back into piddles. Basically, the output looked like so Info for piddle foo: PDL: Byte D [256,3] #255 entries in each line ---- [ [ 0 1 2 3 .. 255] [ 255 255 255 255 .. 255] [ 0 0 0 0 .. 0] ] Info for piddle bar: PDL: Byte D [1,252,189] ---- [ [ [ 0 ] [ 0 ] .. [ 0 ] ] [ [ 0 ] [ 0 ] .. [ 0 ] ] .. ] I added the appropriate commas to the above, and read them into $foo and $bar. Then I did $res = index($foo, $bar) and voila! That worked fine! So, there is something going on when I do the same in my code, but the output from my code re-read back into the code works fine. I will get to the bottom of this, if that is the last thing I do with PDL. -- Puneet Kishor http://www.punkish.org Carbon Model http://carbonmodel.org Charter Member, Open Source Geospatial Foundation http://www.osgeo.org Science Commons Fellow, http://sciencecommons.org/about/whoweare/kishor Nelson Institute, UW-Madison http://www.nelson.wisc.edu ----------------------------------------------------------------------- Assertions are politics; backing up assertions with evidence is science ======================================================================= _______________________________________________ Perldl mailing list [email protected] http://mailman.jach.hawaii.edu/mailman/listinfo/perldl
