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

301

302

303

304

305

306

307

308

309

310

311

312

313

314

315

316

317

318

319

320

321

322

323

324

325

326

327

328

329

330

331

332

333

334

335

336

337

338

339

340

341

342

343

344

345

346

347

348

349

350

351

352

353

354

355

356

357

358

359

360

361

362

363

364

365

366

367

368

369

370

371

372

373

374

375

376

377

378

379

380

381

382

383

384

385

386

387

388

389

390

391

392

393

394

395

396

397

398

399

400

401

402

403

404

405

406

407

408

409

410

411

412

413

414

415

416

417

418

419

420

421

422

423

424

425

426

427

428

429

430

431

432

433

434

435

436

437

438

439

440

441

442

443

444

445

446

447

448

449

450

451

452

453

454

455

456

457

458

459

460

461

462

463

464

465

466

467

468

469

470

471

472

473

474

475

476

477

478

479

480

481

482

483

484

485

486

487

488

489

490

491

492

493

494

495

496

497

498

499

500

501

502

503

504

505

506

507

508

509

510

511

512

513

514

515

516

517

518

519

520

521

522

523

524

525

526

527

528

529

530

531

532

533

534

535

536

537

538

539

540

541

542

543

544

545

546

547

548

549

550

551

552

553

554

555

556

557

558

559

560

561

562

563

564

565

566

567

568

569

570

571

572

573

574

575

576

577

578

579

580

581

582

583

584

585

586

587

588

589

590

591

592

593

594

595

596

597

598

599

600

601

602

603

604

605

606

607

608

609

610

611

612

613

614

615

616

617

618

619

620

621

622

623

624

625

626

627

628

629

630

631

632

633

634

635

636

637

638

639

640

641

642

643

644

645

646

647

648

649

650

651

652

653

654

655

656

657

658

659

660

661

662

663

664

665

666

667

668

669

670

671

672

673

674

675

676

677

678

679

680

681

682

683

684

685

686

687

688

689

690

691

692

693

694

695

696

697

698

699

700

701

702

703

704

705

706

707

708

709

710

711

712

713

714

715

716

717

718

719

720

721

722

723

724

725

726

727

728

729

730

731

732

733

734

735

736

737

738

739

740

741

742

743

744

745

746

747

748

749

750

751

752

753

754

755

756

757

758

759

760

761

762

763

764

765

766

767

768

769

770

771

772

773

774

775

776

777

778

779

780

781

782

783

784

785

786

787

788

789

790

791

792

793

794

795

796

797

798

799

800

801

802

803

804

805

806

807

808

809

810

811

812

813

814

815

816

817

818

819

820

821

822

823

824

825

826

827

828

829

830

831

832

833

834

835

836

837

838

839

840

841

842

843

844

845

846

847

848

849

850

851

852

853

854

855

856

857

858

859

860

861

862

863

864

865

866

867

868

869

870

871

872

873

874

875

876

877

878

879

880

881

882

883

884

885

886

887

888

889

890

891

892

893

894

895

896

897

898

899

900

901

902

903

904

905

906

907

908

909

910

911

912

913

914

915

916

917

918

919

920

921

922

923

924

925

926

927

928

929

930

931

932

933

934

935

936

937

938

939

940

941

942

943

944

945

946

947

948

949

950

951

952

953

954

955

956

957

958

959

960

961

962

963

964

965

966

967

968

969

970

971

972

973

974

975

976

977

978

979

980

981

982

983

984

985

986

987

988

989

990

991

992

993

994

995

996

997

998

999

1000

1001

1002

1003

1004

1005

1006

1007

1008

1009

1010

1011

1012

1013

1014

1015

1016

1017

1018

1019

1020

1021

1022

1023

1024

1025

1026

1027

1028

1029

1030

1031

1032

1033

1034

1035

1036

1037

1038

1039

1040

1041

1042

1043

1044

1045

1046

1047

1048

1049

1050

1051

1052

1053

1054

1055

1056

1057

1058

1059

1060

1061

1062

1063

1064

1065

1066

1067

1068

1069

1070

1071

1072

1073

1074

1075

1076

1077

1078

1079

1080

1081

1082

1083

1084

1085

1086

1087

1088

1089

1090

1091

1092

1093

1094

1095

1096

1097

1098

1099

1100

1101

1102

1103

1104

1105

1106

1107

1108

1109

1110

1111

1112

1113

1114

1115

1116

1117

1118

1119

1120

1121

1122

1123

1124

1125

1126

1127

1128

1129

1130

1131

1132

1133

1134

1135

1136

1137

1138

1139

1140

1141

1142

1143

1144

1145

1146

1147

1148

1149

1150

1151

1152

1153

1154

1155

1156

1157

1158

1159

1160

1161

1162

1163

1164

1165

1166

1167

1168

1169

1170

1171

1172

1173

1174

1175

1176

1177

1178

1179

1180

1181

1182

1183

1184

1185

1186

1187

1188

1189

1190

1191

1192

1193

1194

1195

1196

1197

1198

1199

1200

1201

1202

1203

1204

1205

1206

1207

1208

1209

1210

1211

1212

1213

1214

1215

1216

1217

1218

1219

1220

1221

1222

1223

1224

1225

1226

1227

1228

1229

1230

1231

1232

1233

1234

1235

1236

1237

1238

1239

1240

1241

1242

1243

1244

1245

1246

1247

1248

1249

1250

1251

1252

1253

1254

1255

1256

1257

1258

1259

1260

1261

1262

1263

1264

1265

1266

1267

1268

1269

1270

1271

1272

1273

1274

1275

1276

1277

1278

1279

1280

1281

1282

1283

1284

1285

1286

1287

1288

1289

1290

1291

1292

1293

1294

1295

1296

1297

1298

1299

1300

1301

1302

1303

1304

1305

1306

1307

1308

1309

1310

1311

1312

1313

1314

1315

1316

1317

1318

1319

1320

1321

1322

1323

1324

1325

1326

1327

1328

1329

1330

1331

1332

1333

1334

1335

1336

1337

1338

1339

1340

1341

1342

1343

1344

1345

1346

1347

1348

1349

1350

1351

1352

1353

1354

1355

1356

1357

1358

1359

1360

1361

1362

1363

1364

1365

1366

1367

1368

1369

1370

1371

1372

1373

1374

1375

1376

1377

1378

1379

1380

1381

1382

1383

1384

1385

1386

1387

1388

1389

1390

1391

1392

1393

1394

1395

1396

1397

1398

1399

1400

1401

1402

1403

1404

1405

1406

1407

1408

1409

1410

1411

1412

1413

1414

1415

1416

1417

1418

1419

1420

1421

1422

1423

1424

1425

1426

1427

1428

1429

1430

1431

1432

1433

1434

1435

1436

1437

1438

1439

1440

1441

1442

1443

1444

1445

1446

1447

1448

1449

1450

1451

1452

1453

1454

1455

1456

1457

1458

1459

1460

1461

1462

1463

1464

1465

1466

1467

1468

1469

1470

1471

1472

1473

1474

1475

1476

1477

1478

1479

1480

1481

1482

1483

1484

1485

1486

1487

1488

1489

1490

1491

1492

1493

1494

1495

1496

1497

1498

1499

1500

1501

1502

1503

#!/usr/bin/env python 

 

from __future__ import print_function, absolute_import 

 

import sys 

import os.path as op 

import logging 

from optparse import OptionParser, OptionValueError 

import grond 

from io import StringIO 

 

try: 

from pyrocko import util, marker 

except ImportError: 

print('Pyrocko is required for Grond!' 

'Go to https://pyrocko.org/ for installation instructions.') 

 

 

logger = logging.getLogger('grond.main') 

km = 1e3 

 

 

class Color: 

PURPLE = '\033[95m' 

CYAN = '\033[96m' 

DARKCYAN = '\033[36m' 

BLUE = '\033[94m' 

GREEN = '\033[92m' 

YELLOW = '\033[93m' 

RED = '\033[91m' 

BOLD = '\033[1m' 

UNDERLINE = '\033[4m' 

END = '\033[0m' 

 

 

def d2u(d): 

if isinstance(d, dict): 

return dict((k.replace('-', '_'), v) for (k, v) in d.items()) 

else: 

return d.replace('-', '_') 

 

 

subcommand_descriptions = { 

'init': 'initialise new project structure or print configuration', 

'scenario': 'create a forward-modelled scenario project', 

'events': 'print available event names for given configuration', 

'check': 'check data and configuration', 

'go': 'run Grond optimisation', 

'forward': 'run forward modelling', 

'harvest': 'manually run harvesting', 

'cluster': 'run cluster analysis on result ensemble', 

'plot': 'plot optimisation result', 

'movie': 'visualize optimiser evolution', 

'export': 'export results', 

'tag': 'add user-defined label to run directories', 

'report': 'create result report', 

'diff': 'compare two configs or other normalized Grond YAML files', 

'qc-polarization': 'check sensor orientations with polarization analysis', 

'upgrade-config': 'upgrade config file to the latest version of Grond', 

'version': 'print version number of Grond and its main dependencies', 

} 

 

subcommand_usages = { 

'init': ( 

'init list [options]', 

'init <example> [options]', 

'init <example> <projectdir> [options]'), 

'scenario': 'scenario [options] <projectdir>', 

'events': 'events <configfile>', 

'check': 'check <configfile> <eventnames> ... [options]', 

'go': 'go <configfile> <eventnames> ... [options]', 

'forward': ( 

'forward <rundir> [options]', 

'forward <configfile> <eventnames> ... [options]'), 

'harvest': 'harvest <rundir> [options]', 

'cluster': ( 

'cluster <method> <rundir> [options]', 

'cluster <clusteringconfigfile> <rundir> [options]'), 

'plot': ( 

'plot <plotnames> ( <rundir> | <configfile> <eventname> ) [options]', 

'plot all ( <rundir> | <configfile> <eventname> ) [options]', 

'plot <plotconfigfile> ( <rundir> | <configfile> <eventname> ) [options]', # noqa 

'plot list ( <rundir> | <configfile> <eventname> ) [options]', 

'plot config ( <rundir> | <configfile> <eventname> ) [options]'), 

'movie': 'movie <rundir> <xpar> <ypar> <filetemplate> [options]', 

'export': 'export (best|mean|ensemble|stats) <rundirs> ... [options]', 

'tag': ( 

'tag add <tag> <rundir>', 

'tag remove <tag> <rundir>', 

'tag list <rundir>'), 

'report': ( 

'report <rundir> ... [options]', 

'report <configfile> <eventnames> ...'), 

'diff': 'diff <left_path> <right_path>', 

'qc-polarization': 'qc-polarization <configfile> <eventname> ' 

'<target_group_path> [options]', 

'upgrade-config': 'upgrade-config <configfile>', 

'version': 'version', 

} 

 

subcommands = subcommand_descriptions.keys() 

 

program_name = 'grond' 

 

usage_tdata = d2u(subcommand_descriptions) 

usage_tdata['program_name'] = program_name 

usage_tdata['version_number'] = grond.__version__ 

 

 

usage = '''%(program_name)s <subcommand> [options] [--] <arguments> ... 

 

Grond is a probabilistic earthquake source inversion framework. 

 

This is Grond version %(version_number)s. 

 

Subcommands: 

 

scenario %(scenario)s 

init %(init)s 

events %(events)s 

check %(check)s 

go %(go)s 

forward %(forward)s 

harvest %(harvest)s 

cluster %(cluster)s 

plot %(plot)s 

movie %(movie)s 

export %(export)s 

tag %(tag)s 

report %(report)s 

diff %(diff)s 

qc-polarization %(qc_polarization)s 

upgrade-config %(upgrade_config)s 

version %(version)s 

 

To get further help and a list of available options for any subcommand run: 

 

%(program_name)s <subcommand> --help 

 

What do you want to bust today?! 

''' % usage_tdata 

 

 

class CLIHints(object): 

init = ''' 

We created a folder structure in {project_dir}. 

Check out the YAML configuration in {config} and start the optimisation by: 

 

grond go {config} 

''' 

scenario = ''' 

To start the scenario's optimisation, change to folder 

 

cd {project_dir} 

 

Check out the YAML configuration in {config} and start the optimisation by: 

 

grond go {config} 

''' 

report = ''' 

To open the report in your web browser, run 

 

grond report -s --open {config} 

''' 

check = ''' 

To start the optimisation, run 

 

grond go {config} 

''' 

go = ''' 

To look at the results, run 

 

grond report -so {rundir} 

''' 

 

def __new__(cls, command, **kwargs): 

return '{c.BOLD}Hint{c.END}\n'.format(c=Color) +\ 

getattr(cls, command).format(**kwargs) 

 

 

def main(args=None): 

if not args: 

args = sys.argv 

 

args = list(args) 

if len(args) < 2: 

sys.exit('Usage: %s' % usage) 

 

args.pop(0) 

command = args.pop(0) 

 

if command in subcommands: 

globals()['command_' + d2u(command)](args) 

 

elif command in ('--help', '-h', 'help'): 

if command == 'help' and args: 

acommand = args[0] 

if acommand in subcommands: 

globals()['command_' + acommand](['--help']) 

 

sys.exit('Usage: %s' % usage) 

 

else: 

die('No such subcommand: %s' % command) 

 

 

def add_common_options(parser): 

parser.add_option( 

'--loglevel', 

action='store', 

dest='loglevel', 

type='choice', 

choices=('critical', 'error', 'warning', 'info', 'debug'), 

default='info', 

help='set logger level to ' 

'"critical", "error", "warning", "info", or "debug". ' 

'Default is "%default".') 

 

parser.add_option( 

'--docs', 

dest='rst_docs', 

action='store_true') 

 

 

def print_docs(command, parser): 

 

from optparse import IndentedHelpFormatter 

 

class DocsFormatter(IndentedHelpFormatter): 

 

def format_heading(self, heading): 

return '%s\n%s\n\n' % (heading, '.'*len(heading)) 

 

def format_usage(self, usage): 

lines = usage.splitlines() 

return self.format_heading('Usage') + \ 

'.. code-block:: none\n\n%s' % '\n'.join( 

' '+line.strip() for line in lines) 

 

def format_option(self, option): 

if not option.help: 

return '' 

 

result = [] 

opts = self.option_strings[option] 

result.append('\n.. describe:: %s\n\n' % opts) 

 

help_text = self.expand_default(option) 

result.append(' %s\n\n' % help_text) 

 

return ''.join(result) 

 

parser.formatter = DocsFormatter() 

parser.formatter.set_parser(parser) 

 

def format_help(parser): 

formatter = parser.formatter 

result = [] 

 

result.append(parser.format_description(formatter) + "\n") 

 

if parser.usage: 

result.append(parser.get_usage() + "\n") 

 

result.append('\n') 

 

result.append(parser.format_option_help(formatter)) 

 

result.append('\n') 

 

result.append(parser.format_epilog(formatter)) 

return "".join(result) 

 

print(command) 

print('-' * len(command)) 

print() 

print('.. program:: %s' % program_name) 

print() 

print('.. option:: %s' % command) 

print() 

print(format_help(parser)) 

 

 

def process_common_options(command, parser, options): 

util.setup_logging(program_name, options.loglevel) 

if options.rst_docs: 

print_docs(command, parser) 

exit(0) 

 

 

def cl_parse(command, args, setup=None, details=None): 

usage = subcommand_usages[command] 

descr = subcommand_descriptions[command] 

 

if isinstance(usage, str): 

usage = [usage] 

 

susage = '%s %s' % (program_name, usage[0]) 

for s in usage[1:]: 

susage += '\n%s%s %s' % (' '*7, program_name, s) 

 

description = descr[0].upper() + descr[1:] + '.' 

 

if details: 

description = description + '\n\n%s' % details 

 

parser = OptionParser(usage=susage, description=description) 

 

if setup: 

setup(parser) 

 

add_common_options(parser) 

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

process_common_options(command, parser, options) 

return parser, options, args 

 

 

def die(message, err='', prelude=''): 

if prelude: 

prelude = prelude + '\n' 

 

if err: 

err = '\n' + err 

 

sys.exit('%s%s failed: %s%s' % (prelude, program_name, message, err)) 

 

 

def help_and_die(parser, message): 

sio = StringIO() 

parser.print_help(sio) 

die(message, prelude=sio.getvalue()) 

 

 

def multiple_choice(option, opt_str, value, parser, choices): 

options = value.split(',') 

for opt in options: 

if opt not in choices: 

raise OptionValueError('Invalid option %s - valid options are: %s' 

% (opt, ', '.join(choices))) 

setattr(parser.values, option.dest, options) 

 

 

def magnitude_range(option, opt_str, value, parser): 

mag_range = value.split('-') 

if len(mag_range) != 2: 

raise OptionValueError( 

'Invalid magnitude %s - valid range is e.g. 6-7.' % value) 

try: 

mag_range = tuple(map(float, mag_range)) 

except ValueError: 

raise OptionValueError('Magnitudes must be numbers.') 

 

if mag_range[0] > mag_range[1]: 

raise OptionValueError('Minimum magnitude must be larger than' 

' maximum magnitude.') 

setattr(parser.values, option.dest, mag_range) 

 

 

def command_scenario(args): 

 

STORE_STATIC = 'crust2_ib_static' 

STORE_WAVEFORMS = 'crust2_ib' 

 

def setup(parser): 

parser.add_option( 

'--targets', action='callback', dest='targets', type=str, 

callback=multiple_choice, callback_kwargs={ 

'choices': ('waveforms', 'gnss', 'insar') 

}, 

default='waveforms', 

help='forward modelling targets for the scenario. Select from:' 

' waveforms, gnss and insar. ' 

'(default: --targets=%default,' 

' multiple selection by --targets=waveforms,gnss,insar)') 

parser.add_option( 

'--problem', dest='problem', default='cmt', 

type='choice', choices=['cmt', 'rectangular'], 

help='problem to generate: \'dc\' (double couple)' 

' or \'rectangular\' (rectangular finite fault)' 

' (default: \'%default\')') 

parser.add_option( 

'--magnitude-range', dest='magnitude_range', type=str, 

action='callback', callback=magnitude_range, default=[6.0, 7.0], 

help='Magnitude range min_mag-max_mag (default: %default)') 

parser.add_option( 

'--nstations', dest='nstations', type=int, default=20, 

help='number of seismic stations to create (default: %default)') 

parser.add_option( 

'--gnss_nstations', dest='gnss_nstations', type=int, default=20, 

help='number of GNSS campaign stations to create' 

' (default: %default)') 

parser.add_option( 

'--nevents', dest='nevents', type=int, default=1, 

help='number of events to create (default: %default)') 

parser.add_option( 

'--lat', dest='lat', type=float, default=41.0, 

help='center latitude of the scenario (default: %default)') 

parser.add_option( 

'--lon', dest='lon', type=float, default=33.3, 

help='center latitude of the scenario (default: %default)') 

parser.add_option( 

'--radius', dest='radius', type=float, default=100., 

help='radius of the the scenario in [km] (default: %default)') 

parser.add_option( 

'--gf-waveforms', dest='store_waveforms', type=str, 

default=STORE_WAVEFORMS, 

help='Green\'s function store for waveform modelling, ' 

'(default: %default)') 

parser.add_option( 

'--gf-static', dest='store_statics', type=str, 

default=STORE_STATIC, 

help='Green\'s function store for static modelling, ' 

'(default: %default)') 

parser.add_option( 

'--force', dest='force', action='store_true', 

help='overwrite existing project folder.') 

parser.add_option( 

'--gf-store-superdirs', 

dest='gf_store_superdirs', 

help='Comma-separated list of directories containing GF stores') 

 

parser, options, args = cl_parse('scenario', args, setup) 

 

gf_store_superdirs = None 

if options.gf_store_superdirs: 

gf_store_superdirs = options.gf_store_superdirs.split(',') 

 

if len(args) == 1: 

project_dir = args[0] 

else: 

parser.print_help() 

sys.exit(1) 

 

from grond import scenario as grond_scenario 

try: 

scenario = grond_scenario.GrondScenario( 

project_dir, 

center_lat=options.lat, center_lon=options.lon, 

radius=options.radius*km) 

 

if 'waveforms' in options.targets: 

obs = grond_scenario.WaveformObservation( 

nstations=options.nstations, 

store_id=options.store_waveforms) 

scenario.add_observation(obs) 

 

if 'insar' in options.targets: 

obs = grond_scenario.InSARObservation( 

store_id=options.store_statics) 

scenario.add_observation(obs) 

 

if 'gnss' in options.targets: 

obs = grond_scenario.GNSSCampaignObservation( 

nstations=options.gnss_nstations, 

store_id=options.store_statics) 

scenario.add_observation(obs) 

 

if options.problem == 'cmt': 

problem = grond_scenario.DCSourceProblem( 

nevents=options.nevents, 

magnitude_min=options.magnitude_range[0], 

magnitude_max=options.magnitude_range[1]) 

elif options.problem == 'rectangular': 

problem = grond_scenario.RectangularSourceProblem( 

nevents=options.nevents) 

scenario.set_problem(problem) 

 

scenario.build( 

force=options.force, 

interactive=True, 

gf_store_superdirs=gf_store_superdirs) 

 

logger.info(CLIHints('scenario', 

config=scenario.get_grond_config_path(), 

project_dir=project_dir)) 

 

except grond.GrondError as e: 

die(str(e)) 

 

 

def command_init(args): 

 

from .cmd_init import GrondInit 

 

grond_init = GrondInit() 

 

def print_section(entries): 

if len(entries) == 0: 

return '\tNone available.' 

 

padding = max([len(n) for n in entries.keys()]) 

rstr = [] 

lcat = None 

for name, desc in entries.items(): 

 

cat = name.split('_')[0] 

if lcat is not None and lcat != cat: 

rstr.append('') 

lcat = cat 

 

rstr.append(' {c.BOLD}{name:<{padding}}{c.END} : {desc}'.format( 

name=name, desc=desc, padding=padding, c=Color)) 

return '\n'.join(rstr) 

 

help_text = '''Available configuration examples for Grond. 

 

{c.BOLD}Example Projects{c.END} 

 

Deploy a full project structure into a directory. 

 

usage: grond init <example> <projectdir> 

 

where <example> is any of the following: 

 

{examples_list} 

 

{c.BOLD}Config Sections{c.END} 

 

Print out configuration snippets for various components. 

 

usage: grond init <section> 

 

where <section> is any of the following: 

 

{sections_list} 

'''.format(c=Color, 

examples_list=print_section(grond_init.get_examples()), 

sections_list=print_section(grond_init.get_sections())) 

 

def setup(parser): 

parser.add_option( 

'--force', dest='force', action='store_true') 

 

parser, options, args = cl_parse( 

'init', args, setup, 

'Use grond init list to show available examples.') 

 

if len(args) not in (1, 2): 

help_and_die(parser, '1 or 2 arguments required') 

 

if args[0] == 'list': 

print(help_text) 

return 

 

if args[0].startswith('example_'): 

if len(args) == 1: 

config = grond_init.get_content_example(args[0]) 

if not config: 

help_and_die(parser, 'Unknown example: %s' % args[0]) 

 

sys.stdout.write(config+'\n\n') 

 

logger.info('Hint: To create a project, use: grond init <example> ' 

'<projectdir>') 

 

elif op.exists(op.abspath(args[1])) and not options.force: 

help_and_die( 

parser, 

'Directory "%s" already exists! Use --force to overwrite.' 

% args[1]) 

else: 

try: 

grond_init.init_example(args[0], args[1], force=options.force) 

except OSError as e: 

print(str(e)) 

 

else: 

sec = grond_init.get_content_snippet(args[0]) 

if not sec: 

help_and_die(parser, 'Unknown snippet: %s' % args[0]) 

 

sys.stdout.write(sec) 

 

 

def command_init_old(args): 

 

from . import cmd_init as init 

 

def setup(parser): 

parser.add_option( 

'--targets', action='callback', dest='targets', type=str, 

callback=multiple_choice, callback_kwargs={ 

'choices': ('waveforms', 'gnss', 'insar', 'all') 

}, 

default='waveforms', 

help='select from:' 

' waveforms, gnss and insar. ' 

'(default: --targets=%default,' 

' multiple selection by --targets=waveforms,gnss,insar)') 

parser.add_option( 

'--problem', dest='problem', 

type='choice', choices=['cmt', 'rectangular'], 

help='problem to generate: \'dc\' (double couple)' 

' or\'rectangular\' (rectangular finite fault)' 

' (default: \'%default\')') 

parser.add_option( 

'--force', dest='force', action='store_true', 

help='overwrite existing project folder') 

 

parser, options, args = cl_parse('init', args, setup) 

 

try: 

project = init.GrondProject() 

 

if 'all' in options.targets: 

targets = ['waveforms', 'gnss', 'insar'] 

else: 

targets = options.targets 

 

if not options.problem: 

if 'insar' in targets or 'gnss' in targets: 

problem = 'rectangular' 

else: 

problem = 'cmt' 

else: 

problem = options.problem 

 

if problem == 'rectangular': 

project.set_rectangular_source() 

elif problem == 'cmt': 

project.set_cmt_source() 

 

if 'waveforms' in targets: 

project.add_waveforms() 

 

if 'insar' in targets: 

project.add_insar() 

 

if 'gnss' in targets: 

project.add_gnss() 

 

if len(args) == 1: 

project_dir = args[0] 

project.build(project_dir, options.force) 

logger.info(CLIHints( 

'init', project_dir=project_dir, 

config=op.join(project_dir, 'config', 'config.gronf'))) 

else: 

sys.stdout.write(project.dump()) 

 

except grond.GrondError as e: 

die(str(e)) 

 

 

def command_events(args): 

def setup(parser): 

pass 

 

parser, options, args = cl_parse('events', args, setup) 

if len(args) != 1: 

help_and_die(parser, 'missing arguments') 

 

config_path = args[0] 

try: 

config = grond.read_config(config_path) 

 

for event_name in grond.get_event_names(config): 

print(event_name) 

 

except grond.GrondError as e: 

die(str(e)) 

 

 

def command_check(args): 

 

from grond.environment import Environment 

 

def setup(parser): 

parser.add_option( 

'--target-ids', dest='target_string_ids', metavar='TARGET_IDS', 

help='process only selected targets. TARGET_IDS is a ' 

'comma-separated list of target IDs. Target IDs have the ' 

'form SUPERGROUP.GROUP.NETWORK.STATION.LOCATION.CHANNEL.') 

 

parser.add_option( 

'--waveforms', dest='show_waveforms', action='store_true', 

help='show raw, restituted, projected, and processed waveforms') 

 

parser.add_option( 

'--nrandom', dest='n_random_synthetics', metavar='N', type=int, 

default=10, 

help='set number of random synthetics to forward model (default: ' 

'10). If set to zero, create synthetics for the reference ' 

'solution.') 

 

parser.add_option( 

'--save-stations-used', dest='stations_used_path', 

metavar='FILENAME', 

help='aggregate all stations used by the setup into a file') 

 

parser, options, args = cl_parse('check', args, setup) 

if len(args) < 1: 

help_and_die(parser, 'missing arguments') 

 

try: 

env = Environment(args) 

config = env.get_config() 

 

target_string_ids = None 

if options.target_string_ids: 

target_string_ids = options.target_string_ids.split(',') 

 

grond.check( 

config, 

event_names=env.get_selected_event_names(), 

target_string_ids=target_string_ids, 

show_waveforms=options.show_waveforms, 

n_random_synthetics=options.n_random_synthetics, 

stations_used_path=options.stations_used_path) 

 

logger.info(CLIHints('check', config=env.get_config_path())) 

 

except grond.GrondError as e: 

die(str(e)) 

 

 

def command_go(args): 

 

from grond.environment import Environment 

 

def setup(parser): 

parser.add_option( 

'--force', dest='force', action='store_true', 

help='overwrite existing run directory') 

parser.add_option( 

'--preserve', dest='preserve', action='store_true', 

help='preserve old rundir') 

parser.add_option( 

'--status', dest='status', default='state', 

type='choice', choices=['state', 'quiet'], 

help='status output selection (choices: state, quiet, default: ' 

'state)') 

parser.add_option( 

'--parallel', dest='nparallel', type=int, default=1, 

help='set number of events to process in parallel, ' 

'if set to more than one, --status=quiet is implied.') 

parser.add_option( 

'--threads', dest='nthreads', type=int, default=1, 

help='set number of threads per process (default: 1). ' 

'Set to 0 to use all available cores.') 

 

parser, options, args = cl_parse('go', args, setup) 

 

try: 

env = Environment(args) 

 

status = options.status 

if options.nparallel != 1: 

status = 'quiet' 

 

grond.go( 

env, 

force=options.force, 

preserve=options.preserve, 

status=status, 

nparallel=options.nparallel, 

nthreads=options.nthreads) 

if len(env.get_selected_event_names()) == 1: 

logger.info(CLIHints( 

'go', rundir=env.get_rundir_path())) 

 

except grond.GrondError as e: 

die(str(e)) 

 

 

def command_forward(args): 

 

from grond.environment import Environment 

 

def setup(parser): 

pass 

 

parser, options, args = cl_parse('forward', args, setup) 

if len(args) < 1: 

help_and_die(parser, 'missing arguments') 

 

try: 

env = Environment(args) 

grond.forward(env) 

except grond.GrondError as e: 

die(str(e)) 

 

 

def command_harvest(args): 

def setup(parser): 

parser.add_option( 

'--force', dest='force', action='store_true', 

help='overwrite existing harvest directory') 

parser.add_option( 

'--neach', dest='neach', type=int, default=10, 

help='take NEACH best samples from each chain (default: %default)') 

parser.add_option( 

'--weed', dest='weed', type=int, default=0, 

help='weed out bootstrap samples with bad global performance. ' 

'0: no weeding (default), ' 

'1: only bootstrap chains where all NEACH best samples ' 

'global misfit is less than the global average misfit of all ' 

'NEACH best in all chains plus one standard deviation are ' 

'included in the harvest ensemble, ' 

'2: same as 1 but additionally individual samples are ' 

'removed if their global misfit is greater than the global ' 

'average misfit of all NEACH best in all chains, ' 

'3: harvesting is done on the global chain only, bootstrap ' 

'chains are excluded') 

 

parser, options, args = cl_parse('harvest', args, setup) 

if len(args) != 1: 

help_and_die(parser, 'no rundir') 

 

run_path, = args 

grond.harvest( 

run_path, 

force=options.force, 

nbest=options.neach, 

weed=options.weed) 

 

 

def command_cluster(args): 

from grond import Clustering 

from grond.clustering import metrics, methods, read_config, write_config 

 

def setup(parser): 

parser.add_option( 

'--metric', dest='metric', metavar='METRIC', 

default='kagan_angle', 

choices=metrics.metrics, 

help='metric to measure model distances. Choices: [%s]. Default: ' 

'kagan_angle' % ', '.join(metrics.metrics)) 

 

parser.add_option( 

'--write-config', 

dest='write_config', 

metavar='FILE', 

help='write configuration (or default configuration) to FILE') 

 

method = args[0] if args else '' 

try: 

parser, options, args = cl_parse( 

'cluster', args[1:], setup=Clustering.cli_setup(method, setup), 

details='Available clustering methods: [%s]. Use ' 

'"grond cluster <method> --help" to get list of method ' 

'dependent options.' % ', '.join(methods)) 

 

if method not in Clustering.name_to_class and not op.exists(method): 

help_and_die( 

parser, 

'no such clustering method: %s' % method if method else 

'no clustering method specified') 

 

if op.exists(method): 

clustering = read_config(method) 

else: 

clustering = Clustering.cli_instantiate(method, options) 

 

if options.write_config: 

write_config(clustering, options.write_config) 

else: 

if len(args) != 1: 

help_and_die(parser, 'no rundir') 

run_path, = args 

 

grond.cluster(run_path, clustering, metric=options.metric) 

 

except grond.GrondError as e: 

die(str(e)) 

 

 

def command_plot(args): 

 

def setup(parser): 

parser.add_option( 

'--show', dest='show', action='store_true', 

help='show plot for interactive inspection') 

 

details = '' 

 

parser, options, args = cl_parse('plot', args, setup, details) 

 

if not options.show: 

import matplotlib 

matplotlib.use('Agg') 

 

from grond.environment import Environment 

 

if len(args) not in (1, 2, 3): 

help_and_die(parser, '1, 2 or 3 arguments required') 

 

if len(args) > 1: 

env = Environment(args[1:]) 

else: 

env = None 

 

from grond import plot 

if args[0] == 'list': 

 

def get_doc_title(doc): 

for ln in doc.split('\n'): 

ln = ln.strip() 

if ln != '': 

ln = ln.strip('.') 

return ln 

return 'Undocumented.' 

 

if env: 

plot_classes = env.get_plot_classes() 

else: 

plot_classes = plot.get_all_plot_classes() 

 

plot_names, plot_doc = zip(*[(pc.name, pc.__doc__) 

for pc in plot_classes]) 

 

plot_descs = [get_doc_title(doc) for doc in plot_doc] 

left_spaces = max([len(pn) for pn in plot_names]) 

 

for name, desc in zip(plot_names, plot_descs): 

print('{name:<{ls}} - {desc}'.format( 

ls=left_spaces, name=name, desc=desc)) 

 

elif args[0] == 'config': 

plot_config_collection = plot.get_plot_config_collection(env) 

print(plot_config_collection) 

 

elif args[0] == 'all': 

if env is None: 

help_and_die(parser, 'two or three arguments required') 

plot_names = plot.get_plot_names(env) 

plot.make_plots(env, plot_names=plot_names, show=options.show) 

 

elif op.exists(args[0]): 

if env is None: 

help_and_die(parser, 'two or three arguments required') 

plots = plot.PlotConfigCollection.load(args[0]) 

plot.make_plots(env, plots, show=options.show) 

 

else: 

if env is None: 

help_and_die(parser, 'two or three arguments required') 

plot_names = [name.strip() for name in args[0].split(',')] 

plot.make_plots(env, plot_names=plot_names, show=options.show) 

 

 

def command_movie(args): 

 

import matplotlib 

matplotlib.use('Agg') 

 

def setup(parser): 

pass 

 

parser, options, args = cl_parse('movie', args, setup) 

 

if len(args) != 4: 

help_and_die(parser, 'four arguments required') 

 

run_path, xpar_name, ypar_name, movie_filename_template = args 

 

from grond import plot 

 

movie_filename = movie_filename_template % { 

'xpar': xpar_name, 

'ypar': ypar_name} 

 

try: 

plot.make_movie(run_path, xpar_name, ypar_name, movie_filename) 

 

except grond.GrondError as e: 

die(str(e)) 

 

 

def command_export(args): 

 

def setup(parser): 

parser.add_option( 

'--type', dest='type', metavar='TYPE', 

choices=('event', 'event-yaml', 'source', 'vector'), 

help='select type of objects to be exported. Choices: ' 

'"event" (default), "event-yaml", "source", "vector".') 

 

parser.add_option( 

'--parameters', dest='parameters', metavar='PLIST', 

help='select parameters to be exported. PLIST is a ' 

'comma-separated list where each entry has the form ' 

'"<parameter>[.<measure>]". Available measures: "best", ' 

'"mean", "std", "minimum", "percentile16", "median", ' 

'"percentile84", "maximum".') 

 

parser.add_option( 

'--selection', dest='selection', metavar='EXPRESSION', 

help='only export data for runs which match EXPRESSION. ' 

'Example expression: "tags_contains:excellent,good"') 

 

parser.add_option( 

'--output', dest='filename', metavar='FILE', 

help='write output to FILE') 

 

parser, options, args = cl_parse('export', args, setup) 

if len(args) < 2: 

help_and_die(parser, 'arguments required') 

 

what = args[0] 

 

dirnames = args[1:] 

 

what_choices = ('best', 'mean', 'ensemble', 'stats') 

 

if what not in what_choices: 

help_and_die( 

parser, 

'invalid choice: %s (choose from %s)' % ( 

repr(what), ', '.join(repr(x) for x in what_choices))) 

 

if options.parameters: 

pnames = options.parameters.split(',') 

else: 

pnames = None 

 

try: 

grond.export( 

what, 

dirnames, 

filename=options.filename, 

type=options.type, 

pnames=pnames, 

selection=options.selection) 

 

except grond.GrondError as e: 

die(str(e)) 

 

 

def command_tag(args): 

 

def setup(parser): 

parser.add_option( 

'-d', '--dir-names', 

dest='show_dirnames', 

action='store_true', 

help='show directory names instead of run names') 

 

parser, options, args = cl_parse('tag', args, setup) 

if len(args) < 2: 

help_and_die(parser, 'two or more arguments required') 

 

action = args.pop(0) 

 

if action not in ('add', 'remove', 'list'): 

help_and_die(parser, 'invalid action: %s' % action) 

 

if action in ('add', 'remove'): 

if len(args) < 2: 

help_and_die(parser, 'three or more arguments required') 

 

tag = args.pop(0) 

 

rundirs = args 

 

if action == 'list': 

rundirs = args 

 

from grond.environment import Environment 

 

errors = False 

for rundir in rundirs: 

try: 

env = Environment([rundir]) 

if options.show_dirnames: 

name = rundir 

else: 

name = env.get_problem().name 

 

info = env.get_run_info() 

if action == 'add': 

info.add_tag(tag) 

env.set_run_info(info) 

elif action == 'remove': 

info.remove_tag(tag) 

env.set_run_info(info) 

elif action == 'list': 

print('%-60s : %s' % ( 

name, 

', '.join(info.tags))) 

 

except grond.GrondError as e: 

errors = True 

logger.error(e) 

 

if errors: 

die('Errors occurred, see log messages above.') 

 

 

def make_report(env_args, event_name, conf, update_without_plotting, nthreads): 

from grond.environment import Environment 

from grond.report import report 

try: 

env = Environment(env_args) 

if event_name: 

env.set_current_event_name(event_name) 

 

report( 

env, conf, 

update_without_plotting=update_without_plotting, 

make_index=False, 

make_archive=False, 

nthreads=nthreads) 

 

return True 

 

except grond.GrondError as e: 

logger.error(str(e)) 

return False 

 

 

def command_report(args): 

 

import matplotlib 

matplotlib.use('Agg') 

 

from pyrocko import parimap 

 

from grond.environment import Environment 

from grond.report import \ 

report_index, report_archive, serve_ip, serve_report, read_config, \ 

write_config, ReportConfig 

 

def setup(parser): 

parser.add_option( 

'--index-only', 

dest='index_only', 

action='store_true', 

help='create index only') 

parser.add_option( 

'--serve', '-s', 

dest='serve', 

action='store_true', 

help='start http service') 

parser.add_option( 

'--serve-external', '-S', 

dest='serve_external', 

action='store_true', 

help='shortcut for --serve --host=default --fixed-port') 

parser.add_option( 

'--host', 

dest='host', 

default='localhost', 

help='<ip> to start the http server on. Special values for ' 

'<ip>: "*" binds to all available interfaces, "default" ' 

'to default external interface, "localhost" to "127.0.0.1".') 

parser.add_option( 

'--port', 

dest='port', 

type=int, 

default=8383, 

help='set default http server port. Will count up if port is ' 

'already in use unless --fixed-port is given.') 

parser.add_option( 

'--fixed-port', 

dest='fixed_port', 

action='store_true', 

help='fail if port is already in use') 

parser.add_option( 

'--open', '-o', 

dest='open', 

action='store_true', 

help='open report in browser') 

parser.add_option( 

'--config', 

dest='config', 

metavar='FILE', 

help='report configuration file to use') 

parser.add_option( 

'--write-config', 

dest='write_config', 

metavar='FILE', 

help='write configuration (or default configuration) to FILE') 

parser.add_option( 

'--update-without-plotting', 

dest='update_without_plotting', 

action='store_true', 

help='quick-and-dirty update parameter files without plotting') 

parser.add_option( 

'--parallel', dest='nparallel', type=int, default=1, 

help='set number of runs to process in parallel, ' 

'If set to more than one, --status=quiet is implied.') 

parser.add_option( 

'--threads', dest='nthreads', type=int, default=1, 

help='set number of threads per process (default: 1).' 

'Set to 0 to use all available cores.') 

parser.add_option( 

'--no-archive', 

dest='no_archive', 

action='store_true', 

help='don\'t create archive file.') 

 

parser, options, args = cl_parse('report', args, setup) 

 

s_conf = '' 

if options.config: 

try: 

conf = read_config(options.config) 

except grond.GrondError as e: 

die(str(e)) 

 

s_conf = ' --config="%s"' % options.config 

else: 

from grond import plot 

conf = ReportConfig( 

plot_config_collection=plot.get_plot_config_collection()) 

conf.set_basepath('.') 

 

if options.write_config: 

try: 

write_config(conf, options.write_config) 

sys.exit(0) 

 

except grond.GrondError as e: 

die(str(e)) 

 

# commandline options that can override config values 

if options.no_archive: 

conf.make_archive = False 

 

if len(args) == 1 and op.exists(op.join(args[0], 'index.html')): 

conf.report_base_path = conf.rel_path(args[0]) 

s_conf = ' %s' % args[0] 

args = [] 

 

report_base_path = conf.expand_path(conf.report_base_path) 

 

if options.index_only: 

report_index(conf) 

report_archive(conf) 

args = [] 

 

entries_generated = False 

 

payload = [] 

if args and all(op.isdir(rundir) for rundir in args): 

rundirs = args 

all_failed = True 

for rundir in rundirs: 

payload.append(( 

[rundir], None, conf, options.update_without_plotting, 

options.nthreads)) 

 

elif args: 

try: 

env = Environment(args) 

for event_name in env.get_selected_event_names(): 

payload.append(( 

args, event_name, conf, options.update_without_plotting, 

options.nthreads)) 

 

except grond.GrondError as e: 

die(str(e)) 

 

if payload: 

entries_generated = [] 

for result in parimap.parimap( 

make_report, *zip(*payload), nprocs=options.nparallel): 

 

entries_generated.append(result) 

 

all_failed = not any(entries_generated) 

entries_generated = any(entries_generated) 

 

if all_failed: 

die('no report entries generated') 

 

report_index(conf) 

report_archive(conf) 

 

if options.serve or options.serve_external: 

if options.serve_external: 

host = 'default' 

else: 

host = options.host 

 

addr = serve_ip(host), options.port 

 

serve_report( 

addr, 

report_config=conf, 

fixed_port=options.fixed_port or options.serve_external, 

open=options.open) 

 

elif options.open: 

import webbrowser 

url = 'file://%s/index.html' % op.abspath(report_base_path) 

webbrowser.open(url) 

 

else: 

if not entries_generated and not options.index_only: 

logger.info('Nothing to do, see: grond report --help') 

 

if entries_generated and not (options.serve or options.serve_external): 

logger.info(CLIHints('report', config=s_conf)) 

 

 

def command_qc_polarization(args): 

 

def setup(parser): 

parser.add_option( 

'--time-factor-pre', dest='time_factor_pre', type=float, 

metavar='NUMBER', 

default=0.5, 

help='set duration to extract before synthetic P phase arrival, ' 

'relative to 1/fmin. fmin is taken from the selected target ' 

'group in the config file (default=%default)') 

parser.add_option( 

'--time-factor-post', dest='time_factor_post', type=float, 

metavar='NUMBER', 

default=0.5, 

help='set duration to extract after synthetic P phase arrival, ' 

'relative to 1/fmin. fmin is taken from the selected target ' 

'group in the config file (default=%default)') 

parser.add_option( 

'--distance-min', dest='distance_min', type=float, 

metavar='NUMBER', 

help='minimum event-station distance [m]') 

parser.add_option( 

'--distance-max', dest='distance_max', type=float, 

metavar='NUMBER', 

help='maximum event-station distance [m]') 

parser.add_option( 

'--depth-min', dest='depth_min', type=float, 

metavar='NUMBER', 

help='minimum station depth [m]') 

parser.add_option( 

'--depth-max', dest='depth_max', type=float, 

metavar='NUMBER', 

help='maximum station depth [m]') 

parser.add_option( 

'--picks', dest='picks_filename', 

metavar='FILENAME', 

help='add file with P picks in Snuffler marker format') 

parser.add_option( 

'--save', dest='output_filename', 

metavar='FILENAME.FORMAT', 

help='save output to file FILENAME.FORMAT') 

parser.add_option( 

'--dpi', dest='output_dpi', type=float, default=120., 

metavar='NUMBER', 

help='DPI setting for raster formats (default=120)') 

 

parser, options, args = cl_parse('qc-polarization', args, setup) 

if len(args) != 3: 

help_and_die(parser, 'missing arguments') 

 

if options.output_filename: 

import matplotlib 

matplotlib.use('Agg') 

 

import grond.qc 

 

config_path, event_name, target_group_path = args 

 

try: 

config = grond.read_config(config_path) 

except grond.GrondError as e: 

die(str(e)) 

 

ds = config.get_dataset(event_name) 

 

engine = config.engine_config.get_engine() 

 

nsl_to_time = None 

if options.picks_filename: 

markers = marker.load_markers(options.picks_filename) 

marker.associate_phases_to_events(markers) 

 

nsl_to_time = {} 

for m in markers: 

if isinstance(m, marker.PhaseMarker): 

ev = m.get_event() 

if ev is not None and ev.name == event_name: 

nsl_to_time[m.one_nslc()[:3]] = m.tmin 

 

if not nsl_to_time: 

help_and_die( 

parser, 

'no markers associated with event "%s" found in file "%s"' % ( 

event_name, options.picks_filename)) 

 

target_group_paths_avail = [] 

for target_group in config.target_groups: 

name = target_group.path 

if name == target_group_path: 

imc = target_group.misfit_config 

fmin = imc.fmin 

fmax = imc.fmax 

ffactor = imc.ffactor 

 

store = engine.get_store(target_group.store_id) 

timing = '{cake:P|cake:p|cake:P\\|cake:p\\}' 

 

grond.qc.polarization( 

ds, store, timing, fmin=fmin, fmax=fmax, ffactor=ffactor, 

time_factor_pre=options.time_factor_pre, 

time_factor_post=options.time_factor_post, 

distance_min=options.distance_min, 

distance_max=options.distance_max, 

depth_min=options.depth_min, 

depth_max=options.depth_max, 

nsl_to_time=nsl_to_time, 

output_filename=options.output_filename, 

output_dpi=options.output_dpi) 

 

return 

 

target_group_paths_avail.append(name) 

 

die('no target group with path "%s" found. Available: %s' % ( 

target_group_path, ', '.join(target_group_paths_avail))) 

 

 

def command_upgrade_config(args): 

def setup(parser): 

parser.add_option( 

'--diff', dest='diff', action='store_true', 

help='create diff between normalized old and new versions') 

 

parser, options, args = cl_parse('upgrade-config', args, setup) 

if len(args) != 1: 

help_and_die(parser, 'missing argument <configfile>') 

 

from grond import upgrade 

upgrade.upgrade_config_file(args[0], diff=options.diff) 

 

 

def command_diff(args): 

def setup(parser): 

pass 

 

parser, options, args = cl_parse('diff', args, setup) 

if len(args) != 2: 

help_and_die(parser, 'requires exactly two arguments') 

 

from grond.config import diff_configs 

diff_configs(*args) 

 

 

def command_version(args): 

def setup(parser): 

parser.add_option( 

'--short', dest='short', action='store_true', 

help='only print Grond\'s version number') 

parser.add_option( 

'--failsafe', dest='failsafe', action='store_true', 

help='do not get irritated when some dependencies are missing') 

 

parser, options, args = cl_parse('version', args, setup) 

 

if options.short: 

print(grond.__version__) 

return 

 

elif not options.failsafe: 

from grond import info 

print(info.version_info()) 

return 

 

print("grond: %s" % grond.__version__) 

 

try: 

import pyrocko 

print('pyrocko: %s' % pyrocko.long_version) 

except ImportError: 

print('pyrocko: N/A') 

 

try: 

import numpy 

print('numpy: %s' % numpy.__version__) 

except ImportError: 

print('numpy: N/A') 

 

try: 

import scipy 

print('scipy: %s' % scipy.__version__) 

except ImportError: 

print('scipy: N/A') 

 

try: 

import matplotlib 

print('matplotlib: %s' % matplotlib.__version__) 

except ImportError: 

print('matplotlib: N/A') 

 

try: 

from pyrocko.gui.qt_compat import Qt 

print('PyQt: %s' % Qt.PYQT_VERSION_STR) 

print('Qt: %s' % Qt.QT_VERSION_STR) 

except ImportError: 

print('PyQt: N/A') 

print('Qt: N/A') 

 

import sys 

print('python: %s.%s.%s' % sys.version_info[:3]) 

 

if not options.failsafe: 

die('fell back to failsafe version printing') 

 

 

if __name__ == '__main__': 

main()