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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
|
#!/usr/bin/env python3
# Use the proper idiom in the main module ...
# NOTE: See https://docs.python.org/3.12/library/multiprocessing.html#the-spawn-and-forkserver-start-methods
if __name__ == "__main__":
# Import standard modules ...
import os
import shutil
# Import special modules ...
try:
import cartopy
cartopy.config.update(
{
"cache_dir" : os.path.expanduser("~/.local/share/cartopy_cache"),
}
)
except:
raise Exception("\"cartopy\" is not installed; run \"pip install --user Cartopy\"") from None
try:
import matplotlib
matplotlib.rcParams.update(
{
"backend" : "Agg", # NOTE: See https://matplotlib.org/stable/gallery/user_interfaces/canvasagg.html
"figure.dpi" : 300,
"figure.figsize" : (9.6, 7.2), # NOTE: See https://github.com/Guymer/misc/blob/main/README.md#matplotlib-figure-sizes
"font.size" : 8,
}
)
import matplotlib.pyplot
except:
raise Exception("\"matplotlib\" is not installed; run \"pip install --user matplotlib\"") from None
# Import my modules ...
try:
import pyguymer3
import pyguymer3.geo
import pyguymer3.image
import pyguymer3.media
except:
raise Exception("\"pyguymer3\" is not installed; you need to have the Python module from https://github.com/Guymer/PyGuymer3 located somewhere in your $PYTHONPATH") from None
# **************************************************************************
# Make sure that the output folder exists ...
if not os.path.exists("png"):
os.mkdir("png")
# Initialize list ...
frames = []
# Loop over longitudes ...
for ilon in range(-180, 180):
# Deduce longitude ...
lon = float(ilon) # [°]
# Deduce filename, append it to list and skip this longitude if it
# already exists ...
frame = f"png/addMapUnderlay_animation_lon={lon:+08.3f}.png"
frames.append(frame)
if os.path.exists(frame):
continue
print(f"Making \"{frame}\" ...")
# Create figure ...
fg = matplotlib.pyplot.figure(figsize = (7.2, 7.2))
# Create axis ...
ax = pyguymer3.geo.add_axis(
fg,
add_coastlines = False,
lat = 51.5,
lon = lon,
)
# Configure axis ...
pyguymer3.geo.add_NE_map_underlay(ax, cultural = False, linewidth = 0.0, resolution = "50m")
# Configure figure ...
fg.tight_layout()
# Save figure ...
fg.savefig(frame)
matplotlib.pyplot.close(fg)
# Optimize PNG ...
pyguymer3.image.optimize_image(frame, strip = True)
# **************************************************************************
print("Making \"addMapUnderlay_animation.mp4\" ...")
# Save 25fps MP4 ...
vname = pyguymer3.media.images2mp4(
frames,
)
shutil.move(vname, "addMapUnderlay_animation.mp4")
# **************************************************************************
print("Making \"addMapUnderlay_animation.webp\" ...")
# Save 25fps WEBP ...
pyguymer3.media.images2webp(
frames,
"addMapUnderlay_animation.webp",
)
# **************************************************************************
# Set maximum sizes ...
# NOTE: By inspection, the PNG frames are 2,160 px tall/wide.
maxSizes = [512, 1024, 2048] # [px]
# Loop over maximum sizes ...
for maxSize in maxSizes:
print(f"Making \"addMapUnderlay_animation{maxSize:04d}px.mp4\" ...")
# Save 25fps MP4 ...
vname = pyguymer3.media.images2mp4(
frames,
screenWidth = maxSize,
screenHeight = maxSize,
)
shutil.move(vname, f"addMapUnderlay_animation{maxSize:04d}px.mp4")
# **********************************************************************
print(f"Making \"addMapUnderlay_animation{maxSize:04d}px.webp\" ...")
# Save 25fps WEBP ...
pyguymer3.media.images2webp(
frames,
f"addMapUnderlay_animation{maxSize:04d}px.webp",
screenWidth = maxSize,
screenHeight = maxSize,
)
|