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

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

194

195

196

197

198

199

200

201

202

203

204

205

206

207

208

209

210

211

212

213

214

215

216

217

218

219

220

221

222

223

224

225

226

227

228

229

230

231

232

233

234

235

236

237

238

239

240

241

242

243

244

245

246

247

248

249

250

251

252

253

254

255

256

257

258

259

260

261

262

263

264

265

266

267

268

269

270

271

272

273

274

275

276

277

278

279

280

281

282

283

284

285

286

287

288

289

290

291

292

293

294

295

296

297

298

299

300

#!/usr/bin/env python 

# http://pyrocko.org - GPLv3 

# 

# The Pyrocko Developers, 21st Century 

# ---|P------/S----------~Lg---------- 

 

import sys 

import logging 

import numpy as num 

from pyrocko import util, model, orthodrome as od, gmtpy 

from pyrocko import moment_tensor as pmt 

from pyrocko.plot import automap 

 

from optparse import OptionParser 

 

km = 1000. 

logger = logging.getLogger('pyrocko.apps.automap') 

 

program_name = 'automap' 

 

usage = ''' 

usage: %s [options] [--] <lat> <lon> <radius_km> <output.(pdf|png)> 

%s [--download-etopo1] [--download-srtmgl3] 

'''.strip() % (program_name, program_name) 

 

description = '''Create a simple map with topography.''' 

 

 

def latlon_arrays(locs): 

return num.array( 

[(x.effective_lat, x.effective_lon) for x in locs]).T 

 

 

def main(args=None): 

if args is None: 

args = sys.argv[1:] 

 

parser = OptionParser( 

usage=usage, 

description=description) 

 

parser.add_option( 

'--width', 

dest='width', 

type='float', 

default=20.0, 

metavar='FLOAT', 

help='set width of output image [cm] (%default)') 

 

parser.add_option( 

'--height', 

dest='height', 

type='float', 

default=15.0, 

metavar='FLOAT', 

help='set height of output image [cm] (%default)') 

 

parser.add_option( 

'--topo-resolution-min', 

dest='topo_resolution_min', 

type='float', 

default=40.0, 

metavar='FLOAT', 

help='minimum resolution of topography [dpi] (%default)') 

 

parser.add_option( 

'--topo-resolution-max', 

dest='topo_resolution_max', 

type='float', 

default=200.0, 

metavar='FLOAT', 

help='maximum resolution of topography [dpi] (%default)') 

 

parser.add_option( 

'--no-grid', 

dest='show_grid', 

default=True, 

action='store_false', 

help='don\'t show grid lines') 

 

parser.add_option( 

'--no-topo', 

dest='show_topo', 

default=True, 

action='store_false', 

help='don\'t show topography') 

 

parser.add_option( 

'--no-cities', 

dest='show_cities', 

default=True, 

action='store_false', 

help='don\'t show cities') 

 

parser.add_option( 

'--no-illuminate', 

dest='illuminate', 

default=True, 

action='store_false', 

help='deactivate artificial illumination of topography') 

 

parser.add_option( 

'--illuminate-factor-land', 

dest='illuminate_factor_land', 

type='float', 

metavar='FLOAT', 

help='set factor for artificial illumination of land (0.5)') 

 

parser.add_option( 

'--illuminate-factor-ocean', 

dest='illuminate_factor_ocean', 

type='float', 

metavar='FLOAT', 

help='set factor for artificial illumination of ocean (0.25)') 

 

parser.add_option( 

'--theme', 

choices=['topo', 'soft'], 

default='topo', 

help='select color theme, available: topo, soft (topo)"') 

 

parser.add_option( 

'--download-etopo1', 

dest='download_etopo1', 

action='store_true', 

help='download full ETOPO1 topography dataset') 

 

parser.add_option( 

'--download-srtmgl3', 

dest='download_srtmgl3', 

action='store_true', 

help='download full SRTMGL3 topography dataset') 

 

parser.add_option( 

'--make-decimated-topo', 

dest='make_decimated', 

action='store_true', 

help='pre-make all decimated topography datasets') 

 

parser.add_option( 

'--stations', 

dest='stations_fn', 

metavar='FILENAME', 

help='load station coordinates from FILENAME') 

 

parser.add_option( 

'--events', 

dest='events_fn', 

metavar='FILENAME', 

help='load event coordinates from FILENAME') 

 

parser.add_option( 

'--debug', 

dest='debug', 

action='store_true', 

default=False, 

help='print debugging information to stderr') 

 

(options, args) = parser.parse_args(args) 

 

if options.debug: 

util.setup_logging(program_name, 'debug') 

else: 

util.setup_logging(program_name, 'info') 

 

if options.download_etopo1: 

import pyrocko.datasets.topo.etopo1 

pyrocko.datasets.topo.etopo1.download() 

 

if options.download_srtmgl3: 

import pyrocko.datasets.topo.srtmgl3 

pyrocko.datasets.topo.srtmgl3.download() 

 

if options.make_decimated: 

import pyrocko.datasets.topo 

pyrocko.datasets.topo.make_all_missing_decimated() 

 

if (options.download_etopo1 or options.download_srtmgl3 or 

options.make_decimated) and len(args) == 0: 

 

sys.exit(0) 

 

if options.theme == 'soft': 

color_kwargs = { 

'illuminate_factor_land': options.illuminate_factor_land or 0.2, 

'illuminate_factor_ocean': options.illuminate_factor_ocean or 0.15, 

'color_wet': (216, 242, 254), 

'color_dry': (238, 236, 230), 

'topo_cpt_wet': 'light_sea_uniform', 

'topo_cpt_dry': 'light_land_uniform'} 

elif options.theme == 'topo': 

color_kwargs = { 

'illuminate_factor_land': options.illuminate_factor_land or 0.5, 

'illuminate_factor_ocean': options.illuminate_factor_ocean or 0.25} 

 

events = [] 

if options.events_fn: 

events = model.load_events(options.events_fn) 

 

stations = [] 

 

if options.stations_fn: 

stations = model.load_stations(options.stations_fn) 

 

if not (len(args) == 4 or ( 

len(args) == 1 and (events or stations))): 

 

parser.print_help() 

sys.exit(1) 

 

if len(args) == 4: 

try: 

lat = float(args[0]) 

lon = float(args[1]) 

radius = float(args[2])*km 

except Exception: 

parser.print_help() 

sys.exit(1) 

else: 

lats, lons = latlon_arrays(stations+events) 

lat, lon = map(float, od.geographic_midpoint(lats, lons)) 

radius = float( 

num.max(od.distance_accurate50m_numpy(lat, lon, lats, lons))) 

radius *= 1.1 

 

m = automap.Map( 

width=options.width, 

height=options.height, 

lat=lat, 

lon=lon, 

radius=radius, 

topo_resolution_max=options.topo_resolution_max, 

topo_resolution_min=options.topo_resolution_min, 

show_topo=options.show_topo, 

show_grid=options.show_grid, 

illuminate=options.illuminate, 

**color_kwargs) 

 

logger.debug('map configuration:\n%s' % str(m)) 

 

if options.show_cities: 

m.draw_cities() 

 

if stations: 

lats = [s.lat for s in stations] 

lons = [s.lon for s in stations] 

 

m.gmt.psxy( 

in_columns=(lons, lats), 

S='t8p', 

G='black', 

*m.jxyr) 

 

for s in stations: 

m.add_label(s.lat, s.lon, '%s' % '.'.join( 

x for x in s.nsl() if x)) 

 

if events: 

beachball_symbol = 'mt' 

beachball_size = 20.0 

for ev in events: 

if ev.moment_tensor is None: 

m.gmt.psxy( 

in_rows=[[ev.lon, ev.lat]], 

S='c12p', 

G=gmtpy.color('scarletred2'), 

W='1p,black', 

*m.jxyr) 

 

else: 

devi = ev.moment_tensor.deviatoric() 

mt = devi.m_up_south_east() 

mt = mt / ev.moment_tensor.scalar_moment() \ 

* pmt.magnitude_to_moment(5.0) 

m6 = pmt.to6(mt) 

data = (ev.lon, ev.lat, 10) + tuple(m6) + (1, 0, 0) 

 

if m.gmt.is_gmt5(): 

kwargs = dict( 

M=True, 

S='%s%g' % ( 

beachball_symbol[0], beachball_size / gmtpy.cm)) 

else: 

kwargs = dict( 

S='%s%g' % ( 

beachball_symbol[0], beachball_size*2 / gmtpy.cm)) 

 

m.gmt.psmeca( 

in_rows=[data], 

G=gmtpy.color('chocolate1'), 

E='white', 

W='1p,%s' % gmtpy.color('chocolate3'), 

*m.jxyr, 

**kwargs) 

 

m.save(args[-1]) 

 

 

if __name__ == '__main__': 

main(sys.argv[1:])