File Coverage

blib/lib/PDL/Demos/Cartography_demo.pm
Criterion Covered Total %
statement 0 4 0.0
branch n/a
condition n/a
subroutine 0 4 0.0
pod n/a
total 0 8 0.0


line stmt bran cond sub pod time code
1             package PDL::Demos::Cartography_demo;
2              
3 0     0     sub init {'
4             use PDL::Transform::Cartography;
5             '}
6 0     0     sub done {'
7             undef $w;
8             '}
9              
10 0     0     sub info {('cartography','Cartographic projections (Req.: PDL::Graphics::Simple)')}
11              
12             my @demos = (
13             PDL->rpiccan('JPEG') ? () :
14             [comment => q|
15             This demo illustrates the PDL::Transform::Cartography module.
16              
17             It requires PDL::Graphics::Simple and also the ability to read/write
18             JPEG images.
19              
20             You don't seem to have that ability at the moment -- this is likely
21             because you do not have NetPBM installed. See the man page for PDL::IO::Pic.
22              
23             I'll continue with the demo anyway, but it will likely crash on the
24             earth_image('day') call on the next screen.
25              
26             |],
27              
28             [comment => q|
29              
30             This demo illustrates the PDL::Transform::Cartography module.
31             Also you must have PDL::Graphics::Simple installed to run it.
32              
33             PDL::Transform::Cartography includes a global earth vector coastline map
34             and night and day world image maps, as well as the infrastructure for
35             transforming them to different coordinate systems.
36             |],
37              
38             [act => q|
39             ### Load the necessary modules
40             use PDL::Graphics::Simple;
41             use PDL::Transform::Cartography;
42            
43             ### Get the vector coastline map (and a lon/lat grid), and load the Earth
44             ### RGB daytime image -- both of these are built-in to the module. The
45             ### coastline map is a set of (X,Y,Pen) vectors.
46             $coast = earth_coast()->glue( 1, scalar graticule(15,1) );
47             print "Coastline data are a collection of vectors: ",
48             join("x",$coast->dims),"\n";
49              
50             $map = earth_image('day');
51             print "Map data are RGB: ",join("x",$map->dims),"\n\n";
52             |],
53              
54             [act => q&
55             ### Map data are stored natively in Plate Carree format.
56             ### The image contains a FITS header that contains coordinate system info.
57             print "FITS HEADER INFORMATION:\n";
58             for $_(sort keys %{$map->hdr}){
59             next if(m/SIMPLE/ || m/HISTORY/ || m/COMMENT/);
60             printf (" %8s: %10s%s", $_, $map->hdr->{$_}, (++$i%3) ? " " : "\n");
61             }
62             print "\n";
63              
64             $w = pgswin();
65             $w->plot(with=>'fits', $map, {Title=>"NASA/MODIS Earth Map (Plate Carree)",J=>0});
66             &],
67              
68             [act => q&
69             ### The map data are co-aligned with the vector data, which can be drawn
70             ### on top of the window with the "with polylines" PDL::Graphics::Simple
71             ### plot type. The clean_lines method breaks lines that pass over
72             ### the map's singularity at the 180th parallel.
73            
74             $w->hold;
75             $w->plot(with=>'polylines', $coast->clean_lines);
76             $w->release;
77              
78             &],
79              
80             [act => q&
81             ### There are a large number of map projections -- to list them all,
82             ### say "??cartography" in the perldl shell. Here are four
83             ### of them:
84              
85             undef $w; # Close old window
86             $w = pgswin( size=>[8,6], multi=>[2,2] ) ;
87              
88             sub draw {
89             ($tx, $t, $px, @opt ) = @_;
90             $w->plot(with=>'fits', $map->map( $tx, $px, @opt ),
91             with=>'polylines', $coast->apply( $tx )->clean_lines(@opt),
92             {Title=>$t, J=>1});
93             }
94              
95             ## (The "or" option specifies the output range of the mapping)
96             draw( t_mercator, "Mercator Projection", [400,300] );
97             draw( t_aitoff, "Aitoff / Hammer", [400,300] );
98             draw( t_gnomonic, "Gnomonic", [400,300],{or=>[[-3,3],[-2,2]]} );
99             draw( t_lambert, "Lambert Conformal Conic",[400,300],{or=>[[-3,3],[-2,2]]} );
100             &],
101              
102             [act => q|
103             ### You can create oblique projections by feeding in a different origin.
104             ### Here, the origin is centered over North America.
105              
106             draw( t_mercator( o=>[-90,40] ), "Mercator Projection", [400,300] );
107             draw( t_aitoff ( o=>[-90,40] ), "Aitoff / Hammer", [400,300] );
108             draw( t_gnomonic( o=>[-90,40] ), "Gnomonic",[400,300],{or=>[[-3,3],[-2,2]]} );
109             draw( t_lambert( o=>[-90,40] ), "Lambert ",[400,300],{or=>[[-3,3],[-2,2]]} );
110              
111             |],
112              
113             [act => q|
114             ### There are three main perspective projections (in addition to special
115             ### cases like stereographic and gnomonic projection): orthographic,
116             ### vertical, and true perspective. The true perspective has options for
117             ### both downward-looking and aerial-view coordinate systems.
118              
119             draw( t_orthographic( o=>[-90,40] ),
120             "Orthographic", [400,300]);
121              
122             draw( t_vertical( r0=> (2 + 1), o=>[-90,40] ),
123             "Vertical (Altitude = 2 r_e)", [400,300]);
124              
125             draw( t_perspective( r0=> (2 + 1), o=>[-90,40] ),
126             "True Perspective (Altitude= 2 r_e)", [400,300]);
127              
128             # Observer is 0.1 earth-radii above surface, lon 117W, lat 31N (over Tijuana).
129             # view is 45 degrees below horizontal, azimuth -22 (338) degrees.
130             draw( t_perspective( r0=> 1.1, o=>[-117,31], cam=>[-22,-45,0] ),
131             "Aerial view of West Coast of USA", [400,300],
132             {or=>[[-60,60],[-45,45]], method=>'linear'});
133              
134             |],
135              
136             [comment => q|
137              
138             That concludes the basic cartography demo. Numerous other transforms
139             are available.
140              
141             Because PDL's cartographic transforms work within the Transform module
142             and are invertible, it's easy to use them both forwards and backwards.
143             In particular, the perspective transformation is useful for ingesting
144             scientific image data of the Earth or other planets, and converting to
145             a map of the imaged body.
146              
147             Similarly, scanned images of map data can easily be converted into
148             lat/lon coordinates or reprojected to make other projections.
149              
150             |],
151             );
152              
153 0     0     sub demo { @demos }
154              
155             1;