Channels ▼
RSS

PDL: The Perl Data Language


DDJ, Software Careers Fall 97: PDL: Table

PDL: The Perl Data Language:
Tables and Examples

Software Careers Fall 1997 Dr. Dobb's Journal

by Karl Glazebrook and Frossie Economou


Jump to Table 1

Examples:

  perldl> $b = 2
  perldl> p $b/2
  1
  perldl> p $b/3
  0.666666666666667
  perldl>
<pre>
<tr><td bgcolor="#cccccc"><b>Example 1:</b> Assigning values to variables, then printing them.
</table>

</td>
<td align=center>

<table width=275 cellpadding=4 cellspacing=0 border=1>
<tr><td><pre>
  perldl> $a = pdl [5,3,4, [6,4,3];
  perldl> print $a;
  [
    [5,3,4]
    [6,4,3]
  ]
  perldl> $b = $a * $a;
  perldl> print $b;
  [
    [25,9,16]
    [36,16,9]
  ]
Example 2: Creating a 2X3 Matrix and multiplying it by itself.

<b>(a)</b>
perldl> $a = rfits "PDL1.11/m51.fits";
IO loaded
BITPIX = 16 size =65536 pixels
Reading 131072 bytes
BSCALE = 1.0000000000E0 && BZERO
       = 0.0000000000E0
perldl>

<b>(b)</b>
perldl> p dims $a
256 256
perldl>

<b>(c)</b>
perldl> p stats $a
104.193572998047 67.4254211880158
perldl>

<b>(d)</b>
perldl> p sec ($a,0,3,252,255)
[
  [50 51 54 53]
  [50 50 53 54]
  [51 52 53 52]
  [54 53 54 51]
]
perldl>

Example 3: (a)Reading in and plotting an image; (b) determining the dimensions of data by using the dims() function; (c) determining the mean and standard deviation of a piddle using the stats() function; (d) printing a portion of the piddle, using sec() function.

<b>(a)</b>
perldl> imag $a
Loaded PGPLOT
Displaying 256 x 256 image from
  24 to 500 ...

<b>(b)</b>
perldl> imag sin(0.05*$a)
Displaying image 256 x 256 from
  -0.999990224838257 to
  0.999992072582245 ...
Example 4: (a) imag() displayign the piddle $a; (b) results of humiliation.

<b>(a)</b>
perldl> $r = rvals zeroes 20,20

<b>(b)</b>
perldl> $g = exp(-($r/6)**2)/108.08
perldl> imag $g

<b>(c)</b>
perldl> $b = convolve $a.$g
perldl> imag $b

<b>(d)</b>
perldl> imag $a-$b
Example 5: . (a) Chaining PDL functions; (b) using the exp() function to generate a two-dimensional Gaussian; (c) convolving Messier 51 using the newly created Gaussian filter; (d) creating an unsharp masked image.


Tables

<B>(a)</b>                                
<hr>
+ - * / > < >=                   Array operators/functions 
<= << >> &                         (same as Perl and C 
| ^ == != +=                       but they act element by 
-= *= /= %=                        element)
**= <<= >>= 
&= |= ^= <=> 
** % ! ++ - 
"" atan2* sqrt* 
sin* cos* log* 
exp* abs*

X                                Matrix multiplication
~                                Matrix transpose

byte short                       Type conversions
ushort long 
float double 
convert

pdl                              Create/copy a piddle
topdl                            Coerce to piddle if scalar
howbig                           Size of piddle datatype in bytes
nelem                            Number of elements
dims                             Return list of dimensions
inplace                          Perform operation in place
list                             Convert piddle to list, e.g.
                                   for (list $x) { }
listindices                      Return list of index values (1D)
log10*                           Take log base 10
min max sum                      Min/max/sum of piddle
zeroes ones                      Create zero/one-filled piddle
sequence                         Create sequence-filled piddle
reshape                          Reshape the dimensions of a piddle
sec                              Subsection of a piddle
int* set                         Insertion/Setting
at                               Return pixel value at (x, y, z, ...)

axisvals*                        Fill piddle with axis values
xvals*
yvals* 
zvals*

rvals                            Fill piddle with distance from its
                                   center
callext                          Call external C code in dynamically
                                   loadable object
convolve                         Convolve image with kernel (real space)
hist                             Histogram of data
stats                            Return mean and standard deviation
transpose                        Matrix transpose
qsort*                           Quick sort piddle
median                           Median of piddle
oddmedian                        Lower odd median of piddle


<B>(b)</B>
<hr>
fibonacci*                       Compute Fibonacci series (simple 1D example)
cc8compt*                        Connected 8-component labelling (2D example)


<B>(c)</B>
<hr>
rfits                            Read a FITS format file
wfits                            Write  a FITS format file
rcols                            Read columns in a text file into piddles
rgrep                            Read <I>regexp</I> matches into piddles
rdsa                             Read a DSA format file (Starlink systems only)


<B>(d)</B>
<hr>
imag                             Display an image
ctab                             Load an image color table
line                             Plot vector as connected points
points                           Plot vector as points
errb                             Plot error bars
cont                             Display image as contour map
bin                              Plot vector as histogram (<I>bin hist $data</I>,
                                   for instance)
hi2d                             Plot image as 2D histogram
poly                             Draw a polygon
vect                             Display two images as a vector field
hold                             Hold current plot window range;
                                   for example, for overlays 
release                          Autoscale new plot window for each command
rel                              Synonym for "release"
env                              Define a plot window, put on "hold"
dev                              Explicitly set a new PGPLOT graphics device


<B>(e)</B>
<hr>
iis                              Display image
iiscur                           Return a cursor position
iiscirc                          Draw circles on image display
saoimage                         Start SAOimage
ximtool                          Start Ximtool


<B>(f)</B>
<hr>
flush                            Update C cache from piddle Perl
                                   data structure
copy                             Copy a piddle
new                              Create a piddle
Table 1: PDL 1.11 functions. Starred items (log10*, for instance) act as mutators: When you say log10(inplace($a)), every element of $a is replaced with its logarithm base 10. (a) Defined in PDL::Core; (b) defined in PDL::Examples; (c) defined in PDL::Io; (d) defined in PDL::Graphics::PG (PGPLOT graphics); (e) defined in PDL::Graphics::IIS (talk to IIS protocol image display widget); (f) PDL methods.


DDJ

Return to Article


Related Reading


More Insights






Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

 
Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.
 

Video