3
# - requires both bad-value support and PGPLOT
9
use File::Basename qw(&basename &dirname);
11
# check for bad value support
13
my $bvalflag = $PDL::Config{WITH_BADVAL} || 0;
15
# This forces PL files to create target in same directory as PL file.
16
# This is so that make depend always knows where to find PL derivatives.
19
($file = basename($0)) =~ s/\.PL$//;
21
if ($Config{'osname'} eq 'VMS' or
22
$Config{'osname'} eq 'OS2'); # "case-forgiving"
23
open OUT,">$file" or die "Can't create $file: $!";
26
print "Extracting $file (WITH bad value support)\n";
28
print "Extracting $file (NO bad value support)\n";
32
print OUT <<'!NO!SUBS!';
34
# Created by BAD2_demo.pm.PL
35
# ** DO NOT EDIT THIS FILE **
37
package PDL::Demos::BAD2_demo;
40
use PDL::Graphics::PGPLOT;
44
PDL::Demos::Routines->import();
54
print OUT <<'!NO!SUBS!';
58
Your version of PDL has been compiled without support for bad
59
values, hence this demo doesn't do anything.
66
print OUT <<'!NO!SUBS!';
68
$ENV{PGPLOT_XW_WIDTH}=0.6;
69
$ENV{PGPLOT_DEV}=$^O =~ /MSWin32/ ? '/GW' : "/XSERVE";
71
# try and find m51.fits
72
$d = File::Spec->catdir( "PDL", "Demos" );
74
foreach my $path ( @INC ) {
75
my $check = File::Spec->catdir( $path, $d );
76
if ( -d $check ) { $m51path = $check; last; }
78
barf "Unable to find directory ${m51path} within the perl libraries.\n"
79
unless defined $m51path;
82
This demo is just a bit of eye-candy to show bad values in action,
83
and requires PGPLOT support in PDL. It makes use of the image of
84
m51 kindly provided by the IRAF group at the National Optical and
85
Astronomical Observatories.
87
It also serves to demonstrate that you often don't need to change
88
your code to handle bad values, as the routines may 'do it' for you.
94
# read in the image ($m51path has been set up by this demo to
95
# contain the location of the file)
96
$m51 = rfits "$m51path/m51.fits";
99
$just = { JUSTIFY => 1 };
106
# now, let's mask out the central 30 pixels and display it
107
$masked = $m51->setbadif( $m51->rvals({CENTRE=>[128,128]}) < 30 );
109
# since imag auto-scales the output, the bad values are not displayed
112
# compare the statistics of the images
113
# (as $PDL::verbose = 1, stats prints out the answers itself)
114
print "Original:\n"; $m51->stats;
115
print "Masked:\n"; $masked->stats;
121
# let's filter it a little bit
124
$filtered = med2d $masked, ones($nb,$nb), { Boundary => 'Truncate' };
126
# this is a model of the diffuse component of m51
127
imag $filtered, $just;
133
# unsharp masking, to bring out the small-scale detail
134
$unsharp = $masked - $filtered;
136
imag $unsharp, $just;
142
# add on some contours showing the large scale structure of the galaxy
143
imag $unsharp, $just;
154
print OUT <<'!NO!SUBS!';