blib/lib/PDL/Demos/Cartography_demo.pm

filter: Statementstmt 0.0% 0 / 4 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 4 Podpod n/a totaltotal 0.0% 0 / 8 CC 1 SCAR 6.9
CC
1
Cov
0%
init
2.0
done
2.0
info
2.0
CRAP 2.0
« blib/lib/PDL/Config.pm ↑ Summary blib/lib/PDL/NiceSlice/ModuleCompile.pm »
1 package PDL::Demos::Cartography_demo;
2  
3 0 ▶sub init {'
Subroutine init: not called CC=1 SCAR=6.9
4 use PDL::Transform::Cartography;
5 '}
6 0 ▶sub done {'
Subroutine done: not called CC=1 SCAR=6.9
7 undef $w;
8 '}
9  
10 0 ▶sub info {('cartography','Cartographic projections (Req.: PDL::Graphics::Simple)')}
Subroutine info: not called CC=1 SCAR=6.9
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 [act => q|
137 ### Speaking of stereographic and other projections, here are some.
138  
139 draw( t_sinusoidal(),
140 "Sinusoidal", [400,300]);
141  
142 draw( t_sin_lat(),
143 "Sinusoidal except preserving longitude", [400,300]);
144  
145 draw( t_stereographic(),
146 "Stereographic", [400,300]);
147  
148 draw( t_stereographic(o=>[0,90]),
149 "Stereographic about North Pole", [400,300]);
150  
151 |],
152  
153 [act => q|
154 ### More projections.
155  
156 draw( t_az_eqa(),
157 "Azimuthal equal-area", [400,300]);
158  
159 draw( t_az_eqd(),
160 "Azimuthal equal-distance", [400,300]);
161  
162 draw( t_conic(),
163 "Simple conic", [400,300]);
164  
165 draw( t_vertical(),
166 "Vertical perspective", [400,300]);
167  
168 |],
169  
170 [comment => q|
171  
172 That concludes the basic cartography demo. Numerous other transforms
173 are available.
174  
175 Because PDL's cartographic transforms work within the Transform module
176 and are invertible, it's easy to use them both forwards and backwards.
177 In particular, the perspective transformation is useful for ingesting
178 scientific image data of the Earth or other planets, and converting to
179 a map of the imaged body.
180  
181 Similarly, scanned images of map data can easily be converted into
182 lat/lon coordinates or reprojected to make other projections.
183  
184 |],
185 );
186  
187 0 ▶sub demo { @demos }
Subroutine demo: not called CC=1 SCAR=6.9
188  
189 1;
« blib/lib/PDL/Config.pm ↑ Summary blib/lib/PDL/NiceSlice/ModuleCompile.pm »