-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmuk_basic_plot.py
74 lines (55 loc) · 2.23 KB
/
muk_basic_plot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
"""
=============================================
Basic Trajectory Plotting and Using MapDesign
=============================================
How to quickly initialize a matplotlib Basemap with the ``MapDesign``
class and plot ``Trajectory`` paths.
For this example we'll initialize only the January trajectories created in
``bulk_trajgen_example.py``.
"""
import matplotlib.pyplot as plt
import pysplit
trajgroup = pysplit.make_trajectorygroup(r'H:/pysplit/traj_dir/*spring*')
"""
Basemaps and MapDesign
----------------------
PySPLIT's ``MapDesign`` class uses the matplotlib Basemap toolkit to quickly
set up attractive maps. The user is not restricted to using maps
produced from ``MapDesign``, however- any Basemap will serve in the section
below entitled 'Plotting ``Trajectory`` Paths.
Creating a basic cylindrical map using ``MapDesign`` only requires
``mapcorners``, a list of the lower-left longitude, lower-left latitude,
upper-right longitude, and upper-right latitude values.
The ``standard_pm``, a list of standard parallels and meridians,
may be passed as ``None``.
"""
#mapcorners = [-150, 15, -50, 65]
mapcorners = [30, 5, 130, 60]
standard_pm = None
bmap_params = pysplit.MapDesign(mapcorners, standard_pm)
"""
Once the ``MapDesign`` is initialized it can be used to draw a map:
"""
bmap = bmap_params.make_basemap()
"""
Plotting ``Trajectory`` Paths
-----------------------------
For this example, we will color-code by initialization (t=0) altitude,
(500, 1000, or 1500 m), which can be accessed via ``Trajectory.data.geometry``,
a ``GeoSeries`` of Shapely ``Point`` objects.
We can store the trajectory color in ``Trajectory.trajcolor`` for convenience.
"""
color_dict = {100.0 : 'blue',
500.0 : 'orange',
1000.0 : 'black'}
for traj in trajgroup:
altitude0 = traj.data.geometry.apply(lambda p: p.z)[0]
traj.trajcolor = color_dict[altitude0]
"""
For display purposes, let's plot only every fifth ``Trajectory``. The lats,
lons are obtained by unpacking the ``Trajectory.Path``
(Shapely ``LineString``) xy coordinates.
"""
for traj in trajgroup[::5]:
bmap.plot(*traj.path.xy, c=traj.trajcolor, latlon=True, zorder=20)
plt.show()