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

1504

1505

1506

1507

1508

1509

1510

1511

1512

1513

1514

1515

1516

1517

1518

1519

1520

1521

1522

1523

1524

1525

1526

1527

1528

1529

1530

1531

1532

1533

1534

1535

1536

1537

1538

1539

1540

1541

1542

1543

1544

1545

1546

1547

1548

1549

1550

1551

1552

1553

1554

1555

1556

1557

1558

1559

1560

1561

1562

1563

1564

1565

1566

1567

1568

1569

1570

1571

1572

1573

1574

1575

1576

1577

1578

1579

1580

1581

1582

1583

1584

1585

1586

1587

1588

1589

1590

1591

1592

1593

1594

1595

1596

1597

1598

1599

1600

1601

1602

1603

1604

1605

1606

1607

1608

1609

1610

1611

1612

1613

1614

1615

1616

1617

1618

1619

1620

1621

1622

1623

1624

1625

1626

1627

1628

1629

1630

1631

1632

1633

1634

1635

1636

1637

1638

1639

1640

1641

1642

1643

1644

1645

1646

1647

1648

1649

1650

1651

1652

1653

1654

1655

1656

1657

1658

1659

1660

1661

1662

1663

1664

1665

1666

1667

1668

1669

1670

1671

1672

1673

1674

1675

1676

1677

1678

1679

1680

1681

1682

1683

1684

1685

1686

1687

1688

1689

1690

1691

1692

1693

1694

1695

1696

1697

1698

1699

1700

1701

1702

1703

1704

1705

1706

1707

1708

1709

1710

1711

1712

1713

1714

1715

1716

1717

1718

1719

1720

1721

1722

1723

1724

1725

1726

1727

1728

1729

1730

1731

1732

1733

1734

1735

1736

1737

1738

1739

1740

1741

1742

1743

1744

1745

1746

1747

1748

1749

1750

1751

1752

1753

1754

1755

1756

1757

1758

1759

1760

1761

1762

1763

1764

1765

1766

1767

1768

1769

1770

1771

1772

1773

1774

1775

1776

1777

1778

1779

1780

1781

1782

1783

1784

1785

1786

1787

1788

1789

1790

1791

1792

1793

1794

1795

1796

1797

1798

1799

1800

1801

1802

1803

1804

1805

1806

1807

1808

1809

1810

1811

1812

1813

1814

1815

1816

1817

1818

1819

1820

1821

1822

1823

1824

1825

1826

1827

1828

1829

1830

1831

1832

1833

1834

1835

1836

1837

1838

1839

1840

1841

1842

1843

1844

1845

1846

1847

1848

1849

1850

1851

1852

1853

1854

1855

1856

1857

1858

1859

1860

1861

1862

1863

1864

1865

1866

1867

1868

1869

1870

1871

1872

1873

1874

1875

1876

1877

1878

1879

1880

1881

1882

1883

1884

1885

1886

1887

1888

1889

1890

1891

1892

1893

1894

1895

1896

1897

1898

1899

1900

1901

1902

1903

1904

1905

1906

1907

1908

1909

1910

1911

1912

1913

1914

1915

1916

1917

1918

1919

1920

1921

1922

1923

1924

1925

1926

1927

1928

1929

1930

1931

1932

1933

1934

1935

1936

1937

1938

1939

1940

1941

1942

1943

1944

1945

1946

1947

1948

1949

1950

1951

1952

1953

1954

1955

1956

1957

1958

1959

1960

1961

1962

1963

1964

1965

1966

1967

1968

1969

1970

1971

1972

1973

1974

1975

1976

1977

1978

1979

1980

1981

1982

1983

1984

1985

1986

1987

1988

1989

1990

1991

1992

1993

1994

1995

1996

1997

1998

1999

2000

2001

2002

2003

2004

2005

2006

2007

2008

2009

2010

2011

2012

2013

2014

2015

2016

2017

2018

2019

2020

2021

2022

2023

2024

2025

2026

2027

2028

2029

2030

2031

2032

2033

2034

2035

2036

2037

2038

2039

2040

2041

2042

2043

2044

2045

2046

2047

2048

2049

2050

2051

2052

2053

2054

2055

2056

2057

2058

2059

2060

2061

2062

2063

2064

2065

2066

2067

2068

2069

2070

2071

2072

2073

2074

2075

2076

2077

2078

2079

2080

2081

2082

2083

2084

2085

2086

2087

2088

2089

2090

2091

2092

2093

2094

2095

2096

2097

2098

2099

2100

2101

2102

2103

2104

2105

2106

2107

2108

2109

2110

2111

2112

2113

2114

2115

2116

2117

2118

2119

2120

2121

2122

2123

2124

2125

2126

2127

2128

2129

2130

2131

2132

2133

2134

2135

2136

2137

2138

2139

2140

2141

2142

2143

2144

2145

2146

2147

2148

2149

2150

2151

2152

2153

2154

2155

2156

2157

2158

2159

2160

2161

2162

2163

2164

2165

2166

2167

2168

2169

2170

2171

2172

2173

2174

2175

2176

2177

2178

2179

2180

2181

2182

2183

2184

2185

2186

2187

2188

2189

2190

2191

2192

2193

2194

2195

2196

2197

2198

2199

2200

2201

2202

2203

2204

2205

2206

2207

2208

2209

2210

2211

2212

2213

2214

2215

2216

2217

2218

2219

2220

2221

2222

2223

2224

2225

2226

2227

2228

2229

2230

2231

2232

2233

2234

2235

2236

2237

2238

2239

2240

2241

2242

2243

2244

2245

2246

2247

2248

2249

2250

2251

2252

2253

2254

2255

2256

2257

2258

2259

2260

2261

2262

2263

2264

2265

2266

2267

2268

2269

2270

2271

2272

2273

2274

2275

2276

2277

2278

2279

2280

2281

2282

2283

2284

2285

2286

2287

2288

2289

2290

2291

2292

2293

2294

2295

2296

2297

2298

2299

2300

2301

2302

2303

2304

2305

2306

2307

2308

2309

2310

2311

2312

2313

2314

2315

2316

2317

2318

2319

2320

2321

2322

2323

2324

2325

2326

2327

2328

2329

2330

2331

2332

2333

2334

2335

2336

2337

2338

2339

2340

2341

2342

2343

2344

2345

2346

2347

2348

2349

2350

2351

2352

2353

2354

2355

2356

2357

2358

2359

2360

2361

2362

2363

2364

2365

2366

2367

2368

2369

2370

2371

2372

2373

2374

2375

2376

2377

2378

2379

2380

2381

2382

2383

2384

2385

2386

2387

2388

2389

2390

2391

2392

2393

2394

2395

2396

2397

2398

2399

2400

2401

2402

2403

2404

2405

2406

2407

2408

2409

2410

2411

2412

2413

2414

2415

2416

2417

2418

2419

2420

2421

2422

2423

2424

2425

2426

2427

2428

2429

2430

2431

2432

2433

2434

2435

2436

2437

2438

2439

2440

2441

2442

2443

2444

2445

2446

2447

2448

2449

2450

2451

2452

2453

2454

2455

2456

2457

2458

2459

2460

2461

2462

2463

2464

2465

2466

2467

2468

2469

2470

2471

2472

2473

2474

2475

2476

2477

2478

2479

2480

2481

2482

2483

2484

2485

2486

2487

2488

2489

2490

2491

2492

2493

2494

2495

2496

2497

2498

2499

2500

2501

2502

2503

2504

2505

2506

2507

2508

2509

2510

2511

2512

2513

2514

2515

2516

2517

2518

2519

2520

2521

2522

2523

2524

2525

2526

2527

2528

2529

2530

2531

2532

2533

2534

2535

2536

2537

2538

2539

2540

2541

2542

2543

2544

2545

2546

2547

2548

2549

2550

2551

2552

2553

2554

2555

2556

2557

2558

2559

2560

2561

2562

2563

2564

2565

2566

2567

2568

2569

2570

2571

2572

2573

2574

2575

2576

2577

2578

2579

2580

2581

2582

2583

2584

2585

2586

2587

2588

2589

2590

2591

2592

2593

2594

2595

2596

2597

2598

2599

2600

2601

2602

2603

2604

2605

2606

2607

2608

2609

2610

2611

2612

2613

2614

2615

2616

2617

2618

2619

2620

2621

2622

2623

2624

2625

2626

2627

2628

2629

2630

2631

2632

2633

2634

2635

2636

2637

2638

2639

2640

2641

2642

2643

2644

2645

2646

2647

2648

2649

2650

2651

2652

2653

2654

2655

2656

2657

2658

2659

2660

2661

2662

2663

2664

2665

2666

2667

2668

2669

2670

2671

2672

2673

2674

2675

2676

2677

2678

2679

2680

2681

2682

2683

2684

2685

2686

2687

2688

2689

2690

2691

2692

2693

2694

2695

2696

2697

2698

2699

2700

2701

2702

2703

2704

2705

2706

2707

2708

2709

2710

2711

2712

2713

2714

2715

2716

2717

2718

2719

2720

2721

2722

2723

2724

2725

2726

2727

2728

2729

2730

2731

2732

2733

2734

2735

2736

2737

2738

2739

2740

2741

2742

2743

2744

2745

2746

2747

2748

2749

2750

2751

2752

2753

2754

2755

2756

2757

2758

2759

2760

2761

2762

2763

2764

2765

2766

2767

2768

2769

2770

2771

2772

2773

2774

2775

2776

2777

2778

2779

2780

2781

2782

2783

2784

2785

2786

2787

2788

2789

2790

2791

2792

2793

2794

2795

2796

2797

2798

2799

2800

2801

2802

2803

2804

2805

2806

2807

2808

2809

2810

2811

2812

2813

2814

2815

2816

2817

2818

2819

2820

2821

2822

2823

2824

2825

2826

2827

2828

2829

2830

2831

2832

2833

2834

2835

2836

2837

2838

2839

2840

2841

2842

2843

2844

2845

2846

2847

2848

2849

2850

2851

2852

2853

2854

2855

2856

2857

2858

2859

2860

2861

2862

2863

2864

2865

2866

2867

2868

2869

2870

2871

2872

2873

2874

2875

2876

2877

2878

2879

2880

2881

2882

2883

2884

2885

2886

2887

2888

2889

2890

2891

2892

2893

2894

2895

2896

2897

2898

2899

2900

2901

2902

2903

2904

2905

2906

2907

2908

2909

2910

2911

2912

2913

2914

2915

2916

2917

2918

2919

2920

2921

2922

2923

2924

2925

2926

2927

2928

2929

2930

2931

2932

2933

2934

2935

2936

2937

2938

2939

2940

2941

2942

2943

2944

2945

2946

2947

2948

2949

2950

2951

2952

2953

2954

2955

2956

2957

2958

2959

2960

2961

2962

2963

2964

2965

2966

2967

2968

2969

2970

2971

2972

2973

2974

2975

2976

2977

2978

2979

2980

2981

2982

2983

2984

2985

2986

2987

2988

2989

2990

2991

2992

2993

2994

2995

2996

2997

2998

2999

3000

3001

3002

3003

3004

3005

3006

3007

3008

3009

3010

3011

3012

3013

3014

3015

3016

3017

3018

3019

3020

3021

3022

3023

3024

3025

3026

3027

3028

3029

3030

3031

3032

3033

3034

3035

3036

3037

3038

3039

3040

3041

3042

3043

3044

3045

3046

3047

3048

3049

3050

3051

3052

3053

3054

3055

3056

3057

3058

3059

3060

3061

3062

3063

3064

3065

3066

3067

3068

3069

3070

3071

3072

3073

3074

3075

3076

3077

3078

3079

3080

3081

3082

3083

3084

3085

3086

3087

# http://pyrocko.org - GPLv3 

# 

# The Pyrocko Developers, 21st Century 

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

from __future__ import absolute_import, division 

 

import math 

import re 

import fnmatch 

import logging 

 

import numpy as num 

from scipy.interpolate import interp1d 

 

from pyrocko.guts import (Object, SObject, String, StringChoice, 

StringPattern, Unicode, Float, Bool, Int, TBase, 

List, ValidationError, Timestamp, Tuple, Dict) 

from pyrocko.guts import dump, load # noqa 

from pyrocko.guts_array import literal, Array 

from pyrocko.model import Location, gnss 

 

from pyrocko import cake, orthodrome, spit, moment_tensor, trace 

from pyrocko.util import num_full 

 

from .error import StoreError 

 

try: 

new_str = unicode 

except NameError: 

new_str = str 

 

guts_prefix = 'pf' 

 

d2r = math.pi / 180. 

r2d = 1.0 / d2r 

km = 1000. 

vicinity_eps = 1e-5 

 

logger = logging.getLogger('pyrocko.gf.meta') 

 

 

def fmt_choices(cls): 

return 'choices: %s' % ', '.join( 

"``'%s'``" % choice for choice in cls.choices) 

 

 

class InterpolationMethod(StringChoice): 

choices = ['nearest_neighbor', 'multilinear'] 

 

 

class SeismosizerTrace(Object): 

 

codes = Tuple.T( 

4, String.T(), 

default=('', 'STA', '', 'Z'), 

help='network, station, location and channel codes') 

 

data = Array.T( 

shape=(None,), 

dtype=num.float32, 

serialize_as='base64', 

serialize_dtype=num.dtype('<f4'), 

help='numpy array with data samples') 

 

deltat = Float.T( 

default=1.0, 

help='sampling interval [s]') 

 

tmin = Timestamp.T( 

default=0.0, 

help='time of first sample as a system timestamp [s]') 

 

def pyrocko_trace(self): 

c = self.codes 

return trace.Trace(c[0], c[1], c[2], c[3], 

ydata=self.data, 

deltat=self.deltat, 

tmin=self.tmin) 

 

@classmethod 

def from_pyrocko_trace(cls, tr, **kwargs): 

d = dict( 

codes=tr.nslc_id, 

tmin=tr.tmin, 

deltat=tr.deltat, 

data=num.asarray(tr.get_ydata(), dtype=num.float32)) 

d.update(kwargs) 

return cls(**d) 

 

 

class SeismosizerResult(Object): 

n_records_stacked = Int.T(optional=True, default=1) 

t_stack = Float.T(optional=True, default=0.) 

 

 

class Result(SeismosizerResult): 

trace = SeismosizerTrace.T(optional=True) 

n_shared_stacking = Int.T(optional=True, default=1) 

t_optimize = Float.T(optional=True, default=0.) 

 

 

class StaticResult(SeismosizerResult): 

result = Dict.T( 

String.T(), 

Array.T(shape=(None,), dtype=num.float, serialize_as='base64')) 

 

 

class GNSSCampaignResult(StaticResult): 

campaign = gnss.GNSSCampaign.T( 

optional=True) 

 

 

class SatelliteResult(StaticResult): 

 

theta = Array.T( 

optional=True, 

shape=(None,), dtype=num.float, serialize_as='base64') 

 

phi = Array.T( 

optional=True, 

shape=(None,), dtype=num.float, serialize_as='base64') 

 

 

class KiteSceneResult(SatelliteResult): 

 

shape = Tuple.T() 

 

def get_scene(self, component='displacement.los'): 

try: 

from kite import Scene 

except ImportError: 

raise ImportError('Kite not installed') 

 

def reshape(arr): 

return arr.reshape(self.shape) 

 

displacement = self.result[component] 

 

displacement, theta, phi = map( 

reshape, (displacement, self.theta, self.phi)) 

 

sc = Scene( 

displacement=displacement, 

theta=theta, phi=phi, 

config=self.config) 

 

return sc 

 

 

class ComponentSchemeDescription(Object): 

name = String.T() 

source_terms = List.T(String.T()) 

ncomponents = Int.T() 

default_stored_quantity = String.T(optional=True) 

provided_components = List.T(String.T()) 

 

 

component_scheme_descriptions = [ 

ComponentSchemeDescription( 

name='elastic2', 

source_terms=['m0'], 

ncomponents=2, 

default_stored_quantity='displacement', 

provided_components=[ 

'n', 'e', 'd']), 

ComponentSchemeDescription( 

name='elastic8', 

source_terms=['mnn', 'mee', 'mdd', 'mne', 'mnd', 'med'], 

ncomponents=8, 

default_stored_quantity='displacement', 

provided_components=[ 

'n', 'e', 'd']), 

ComponentSchemeDescription( 

name='elastic10', 

source_terms=['mnn', 'mee', 'mdd', 'mne', 'mnd', 'med'], 

ncomponents=10, 

default_stored_quantity='displacement', 

provided_components=[ 

'n', 'e', 'd']), 

ComponentSchemeDescription( 

name='elastic18', 

source_terms=['mnn', 'mee', 'mdd', 'mne', 'mnd', 'med'], 

ncomponents=18, 

default_stored_quantity='displacement', 

provided_components=[ 

'n', 'e', 'd']), 

ComponentSchemeDescription( 

name='elastic5', 

source_terms=['fn', 'fe', 'fd'], 

ncomponents=5, 

default_stored_quantity='displacement', 

provided_components=[ 

'n', 'e', 'd']), 

ComponentSchemeDescription( 

name='poroelastic10', 

source_terms=['pore_pressure'], 

ncomponents=10, 

default_stored_quantity=None, 

provided_components=[ 

'displacement.n', 'displacement.e', 'displacement.d', 

'vertical_tilt.n', 'vertical_tilt.e', 

'pore_pressure', 

'darcy_velocity.n', 'darcy_velocity.e', 'darcy_velocity.d'])] 

 

 

# new names? 

# 'mt_to_displacement_1d' 

# 'mt_to_displacement_1d_ff_only' 

# 'mt_to_gravity_1d' 

# 'mt_to_stress_1d' 

# 'explosion_to_displacement_1d' 

# 'sf_to_displacement_1d' 

# 'mt_to_displacement_3d' 

# 'mt_to_gravity_3d' 

# 'mt_to_stress_3d' 

# 'pore_pressure_to_displacement_1d' 

# 'pore_pressure_to_vertical_tilt_1d' 

# 'pore_pressure_to_pore_pressure_1d' 

# 'pore_pressure_to_darcy_velocity_1d' 

 

 

component_schemes = [c.name for c in component_scheme_descriptions] 

component_scheme_to_description = dict( 

(c.name, c) for c in component_scheme_descriptions) 

 

 

class ComponentScheme(StringChoice): 

''' 

Different Green's Function component schemes are available: 

 

================= ========================================================= 

Name Description 

================= ========================================================= 

``elastic10`` Elastodynamic for 

:py:class:`~pyrocko.gf.meta.ConfigTypeA` and 

:py:class:`~pyrocko.gf.meta.ConfigTypeB` stores, MT 

sources only 

``elastic8`` Elastodynamic for far-field only 

:py:class:`~pyrocko.gf.meta.ConfigTypeA` and 

:py:class:`~pyrocko.gf.meta.ConfigTypeB` stores, 

MT sources only 

``elastic2`` Elastodynamic for 

:py:class:`~pyrocko.gf.meta.ConfigTypeA` and 

:py:class:`~pyrocko.gf.meta.ConfigTypeB` stores, purely 

isotropic sources only 

``elastic5`` Elastodynamic for 

:py:class:`~pyrocko.gf.meta.ConfigTypeA` 

and :py:class:`~pyrocko.gf.meta.ConfigTypeB` stores, SF 

sources only 

``elastic18`` Elastodynamic for 

:py:class:`~pyrocko.gf.meta.ConfigTypeC` stores, MT 

sources only 

``poroelastic10`` Poroelastic for :py:class:`~pyrocko.gf.meta.ConfigTypeA` 

and :py:class:`~pyrocko.gf.meta.ConfigTypeB` stores 

================= ========================================================= 

''' 

 

choices = component_schemes 

 

 

class Earthmodel1D(Object): 

dummy_for = cake.LayeredModel 

 

class __T(TBase): 

def regularize_extra(self, val): 

if isinstance(val, str): 

val = cake.LayeredModel.from_scanlines( 

cake.read_nd_model_str(val)) 

 

return val 

 

def to_save(self, val): 

return literal(cake.write_nd_model_str(val)) 

 

 

class StringID(StringPattern): 

pattern = r'^[A-Za-z][A-Za-z0-9._]{0,64}$' 

 

 

class ScopeType(StringChoice): 

choices = [ 

'global', 

'regional', 

'local', 

] 

 

 

class WaveType(StringChoice): 

choices = [ 

'full waveform', 

'bodywave', 

'P wave', 

'S wave', 

'surface wave', 

] 

 

 

class NearfieldTermsType(StringChoice): 

choices = [ 

'complete', 

'incomplete', 

'missing', 

] 

 

 

class QuantityType(StringChoice): 

choices = [ 

'displacement', 

'rotation', 

'velocity', 

'acceleration', 

'pressure', 

'tilt', 

'pore_pressure', 

'darcy_velocity', 

'vertical_tilt'] 

 

 

class Reference(Object): 

id = StringID.T() 

type = String.T() 

title = Unicode.T() 

journal = Unicode.T(optional=True) 

volume = Unicode.T(optional=True) 

number = Unicode.T(optional=True) 

pages = Unicode.T(optional=True) 

year = String.T() 

note = Unicode.T(optional=True) 

issn = String.T(optional=True) 

doi = String.T(optional=True) 

url = String.T(optional=True) 

eprint = String.T(optional=True) 

authors = List.T(Unicode.T()) 

publisher = Unicode.T(optional=True) 

keywords = Unicode.T(optional=True) 

note = Unicode.T(optional=True) 

abstract = Unicode.T(optional=True) 

 

@classmethod 

def from_bibtex(cls, filename=None, stream=None): 

 

from pybtex.database.input import bibtex 

 

parser = bibtex.Parser() 

 

if filename is not None: 

bib_data = parser.parse_file(filename) 

elif stream is not None: 

bib_data = parser.parse_stream(stream) 

 

references = [] 

 

for id_, entry in bib_data.entries.items(): 

d = {} 

avail = entry.fields.keys() 

for prop in cls.T.properties: 

if prop.name == 'authors' or prop.name not in avail: 

continue 

 

d[prop.name] = entry.fields[prop.name] 

 

if 'author' in entry.persons: 

d['authors'] = [] 

for person in entry.persons['author']: 

d['authors'].append(new_str(person)) 

 

c = Reference(id=id_, type=entry.type, **d) 

references.append(c) 

 

return references 

 

 

_fpat = r'[+-]?(\d+(\.\d*)?|\.\d+)([eE][-+]?\d+)?' 

_spat = StringID.pattern[1:-1] 

_cake_pat = cake.PhaseDef.allowed_characters_pattern 

_iaspei_pat = cake.PhaseDef.allowed_characters_pattern_classic 

 

_ppat = r'(' \ 

r'cake:' + _cake_pat + \ 

r'|iaspei:' + _iaspei_pat + \ 

r'|vel_surface:' + _fpat + \ 

r'|vel:' + _fpat + \ 

r'|stored:' + _spat + \ 

r')' 

 

 

timing_regex_old = re.compile( 

r'^((first|last)?\((' + _spat + r'(\|' + _spat + r')*)\)|(' + 

_spat + r'))?(' + _fpat + ')?$') 

 

 

timing_regex = re.compile( 

r'^((first|last)?\{(' + _ppat + r'(\|' + _ppat + r')*)\}|(' + 

_ppat + r'))?(' + _fpat + '(S|%)?)?$') 

 

 

class PhaseSelect(StringChoice): 

choices = ['', 'first', 'last'] 

 

 

class InvalidTimingSpecification(ValidationError): 

pass 

 

 

class Timing(SObject): 

''' 

Definition of a time instant relative to one or more named phase arrivals 

 

Instances of this class can be used e.g. in cutting and tapering 

operations. They can hold an absolute time or an offset to a named phase 

arrival or group of such arrivals. 

 

Timings can be instantiated from a simple string defintion i.e. with 

``Timing(str)`` where ``str`` is something like 

``'SELECT{PHASE_DEFS}[+-]OFFSET[S|%]'`` where ``'SELECT'`` is ``'first'``, 

``'last'`` or empty, ``'PHASE_DEFS'`` is a ``'|'``-separated list of phase 

definitions, and ``'OFFSET'`` is the time offset in seconds. If a ``'%'`` 

is appended, it is interpreted as percent. If the an ``'S'`` is appended 

to ``'OFFSET'``, it is interpreted as a surface slowness in [s/km]. 

 

Phase definitions can be specified in either of the following ways: 

 

* ``'stored:PHASE_ID'`` - retrieves value from stored travel time table 

* ``'cake:CAKE_PHASE_DEF'`` - evaluates first arrival of phase with cake 

(see :py:class:`pyrocko.cake.PhaseDef`) 

* ``'vel_surface:VELOCITY'`` - arrival according to surface distance / 

velocity [km/s] 

* ``'vel:VELOCITY'`` - arrival according to 3D-distance / velocity [km/s] 

 

**Examples:** 

 

* ``'100'`` : absolute time; 100 s 

* ``'{stored:P}-100'`` : 100 s before arrival of P phase according to 

stored travel time table named ``'P'`` 

* ``'{stored:P}-5.1S'`` : 10% before arrival of P phase according to 

stored travel time table named ``'P'`` 

* ``'{stored:P}-10%'`` : 10% before arrival of P phase according to 

stored travel time table named ``'P'`` 

* ``'{stored:A|stored:B}'`` : time instant of phase arrival A, or B if A is 

undefined for a given geometry 

* ``'first{stored:A|stored:B}'`` : as above, but the earlier arrival of A 

and B is chosen, if both phases are defined for a given geometry 

* ``'last{stored:A|stored:B}'`` : as above but the later arrival is chosen 

* ``'first{stored:A|stored:B|stored:C}-100'`` : 100 s before first out of 

arrivals A, B, and C 

''' 

 

def __init__(self, s=None, **kwargs): 

 

if s is not None: 

offset_is = None 

s = re.sub(r'\s+', '', s) 

try: 

offset = float(s.rstrip('S')) 

 

if s.endswith('S'): 

offset_is = 'slowness' 

 

phase_defs = [] 

select = '' 

 

except ValueError: 

matched = False 

m = timing_regex.match(s) 

if m: 

if m.group(3): 

phase_defs = m.group(3).split('|') 

elif m.group(19): 

phase_defs = [m.group(19)] 

else: 

phase_defs = [] 

 

select = m.group(2) or '' 

 

offset = 0.0 

soff = m.group(27) 

if soff: 

offset = float(soff.rstrip('S%')) 

if soff.endswith('S'): 

offset_is = 'slowness' 

elif soff.endswith('%'): 

offset_is = 'percent' 

 

matched = True 

 

else: 

m = timing_regex_old.match(s) 

if m: 

if m.group(3): 

phase_defs = m.group(3).split('|') 

elif m.group(5): 

phase_defs = [m.group(5)] 

else: 

phase_defs = [] 

 

select = m.group(2) or '' 

 

offset = 0.0 

if m.group(6): 

offset = float(m.group(6)) 

 

phase_defs = [ 

'stored:' + phase_def for phase_def in phase_defs] 

 

matched = True 

 

if not matched: 

raise InvalidTimingSpecification(s) 

 

kwargs = dict( 

phase_defs=phase_defs, 

select=select, 

offset=offset, 

offset_is=offset_is) 

 

SObject.__init__(self, **kwargs) 

 

def __str__(self): 

s = [] 

if self.phase_defs: 

sphases = '|'.join(self.phase_defs) 

# if len(self.phase_defs) > 1 or self.select: 

sphases = '{%s}' % sphases 

 

if self.select: 

sphases = self.select + sphases 

 

s.append(sphases) 

 

if self.offset != 0.0 or not self.phase_defs: 

s.append('%+g' % self.offset) 

if self.offset_is == 'slowness': 

s.append('S') 

elif self.offset_is == 'percent': 

s.append('%') 

 

return ''.join(s) 

 

def evaluate(self, get_phase, args): 

try: 

if self.offset_is == 'slowness' and self.offset != 0.0: 

phase_offset = get_phase( 

'vel_surface:%g' % (1.0/self.offset)) 

offset = phase_offset(args) 

else: 

offset = self.offset 

 

if self.phase_defs: 

phases = [ 

get_phase(phase_def) for phase_def in self.phase_defs] 

times = [phase(args) for phase in phases] 

if self.offset_is == 'percent': 

times = [t*(1.+offset/100.) 

for t in times if t is not None] 

else: 

times = [t+offset for t in times if t is not None] 

 

if not times: 

return None 

elif self.select == 'first': 

return min(times) 

elif self.select == 'last': 

return max(times) 

else: 

return times[0] 

else: 

return offset 

 

except spit.OutOfBounds: 

raise OutOfBounds(args) 

 

phase_defs = List.T(String.T()) 

offset = Float.T(default=0.0) 

offset_is = String.T(optional=True) 

select = PhaseSelect.T( 

default='', 

help=('Can be either ``\'%s\'``, ``\'%s\'``, or ``\'%s\'``. ' % 

tuple(PhaseSelect.choices))) 

 

 

def mkdefs(s): 

defs = [] 

for x in s.split(','): 

try: 

defs.append(float(x)) 

except ValueError: 

if x.startswith('!'): 

defs.extend(cake.PhaseDef.classic(x[1:])) 

else: 

defs.append(cake.PhaseDef(x)) 

 

return defs 

 

 

class TPDef(Object): 

''' 

Maps an arrival phase identifier to an arrival phase definition. 

''' 

 

id = StringID.T( 

help='name used to identify the phase') 

definition = String.T( 

help='definition of the phase in either cake syntax as defined in ' 

':py:class:`pyrocko.cake.PhaseDef`, or, if prepended with an ' 

'``!``, as a *classic phase name*, or, if it is a simple ' 

'number, as a constant horizontal velocity.') 

 

@property 

def phases(self): 

return [x for x in mkdefs(self.definition) 

if isinstance(x, cake.PhaseDef)] 

 

@property 

def horizontal_velocities(self): 

return [x for x in mkdefs(self.definition) if isinstance(x, float)] 

 

 

class OutOfBounds(Exception): 

def __init__(self, values=None, reason=None): 

Exception.__init__(self) 

self.values = values 

self.reason = reason 

self.context = None 

 

def __str__(self): 

scontext = '' 

if self.context: 

scontext = '\n%s' % str(self.context) 

 

if self.reason: 

scontext += '\n%s' % self.reason 

 

if self.values: 

return 'out of bounds: (%s)%s' % ( 

','.join('%g' % x for x in self.values), scontext) 

else: 

return 'out of bounds%s' % scontext 

 

 

class MultiLocation(Object): 

 

lats = Array.T( 

optional=True, shape=(None,), dtype=num.float, 

help='Latitudes of targets.') 

lons = Array.T( 

optional=True, shape=(None,), dtype=num.float, 

help='Longitude of targets.') 

north_shifts = Array.T( 

optional=True, shape=(None,), dtype=num.float, 

help='North shifts of targets.') 

east_shifts = Array.T( 

optional=True, shape=(None,), dtype=num.float, 

help='East shifts of targets.') 

elevation = Array.T( 

optional=True, shape=(None,), dtype=num.float, 

help='Elevations of targets.') 

 

def __init__(self, *args, **kwargs): 

self._coords5 = None 

Object.__init__(self, *args, **kwargs) 

 

@property 

def coords5(self): 

if self._coords5 is not None: 

return self._coords5 

props = [self.lats, self.lons, self.north_shifts, self.east_shifts, 

self.elevation] 

sizes = [p.size for p in props if p is not None] 

if not sizes: 

raise AttributeError('Empty StaticTarget') 

if num.unique(sizes).size != 1: 

raise AttributeError('Inconsistent coordinate sizes.') 

 

self._coords5 = num.zeros((sizes[0], 5)) 

for idx, p in enumerate(props): 

if p is not None: 

self._coords5[:, idx] = p.flatten() 

 

return self._coords5 

 

@property 

def ncoords(self): 

if self.coords5.shape[0] is None: 

return 0 

return int(self.coords5.shape[0]) 

 

def get_latlon(self): 

''' Get all coordinates as lat lon 

:returns: Coordinates in Latitude, Longitude 

:rtype: :class:`numpy.ndarray`, (N, 2) 

''' 

latlons = num.empty((self.ncoords, 2)) 

for i in range(self.ncoords): 

latlons[i, :] = orthodrome.ne_to_latlon(*self.coords5[i, :4]) 

return latlons 

 

def get_corner_coords(self): 

'''Returns the corner coordinates of the multi location object 

 

:returns: In LatLon: lower left, upper left, upper right, lower right 

:rtype: tuple 

''' 

latlon = self.get_latlon() 

ll = (latlon[:, 0].min(), latlon[:, 1].min()) 

ur = (latlon[:, 0].max(), latlon[:, 1].max()) 

return (ll, (ll[0], ur[1]), ur, (ur[0], ll[1])) 

 

 

class Receiver(Location): 

codes = Tuple.T( 

3, String.T(), 

optional=True, 

help='network, station, and location codes') 

 

def pyrocko_station(self): 

from pyrocko import model 

 

lat, lon = self.effective_latlon 

 

return model.Station( 

network=self.codes[0], 

station=self.codes[1], 

location=self.codes[2], 

lat=lat, 

lon=lon, 

depth=self.depth) 

 

 

def g(x, d): 

if x is None: 

return d 

else: 

return x 

 

 

class UnavailableScheme(Exception): 

pass 

 

 

class InvalidNComponents(Exception): 

pass 

 

 

class DiscretizedSource(Object): 

'''Base class for discretized sources. 

 

To compute synthetic seismograms, the parameterized source models (see of 

:py:class:`~pyrocko.gf.seismosizer.Source` derived classes) are first 

discretized into a number of point sources. These spacio-temporal point 

source distributions are represented by subclasses of the 

:py:class:`DiscretizedSource`. For elastodynamic problems there is the 

:py:class:`DiscretizedMTSource` for moment tensor point source 

distributions and the :py:class:`DiscretizedExplosionSource` for pure 

explosion/implosion type source distributions. The geometry calculations 

are implemented in the base class. How Green's function components have to 

be weighted and sumed is defined in the derived classes. 

 

Like in the :py:class:`Location` class, the positions of the point sources 

contained in the discretized source are defined by a common reference point 

(:py:attr:`lat`, :py:attr:`lon`) and cartesian offsets to this 

(:py:attr:`north_shifts`, :py:attr:`east_shifts`, :py:attr:`depths`). 

Alternatively latitude and longitude of each contained point source can be 

specified directly (:py:attr:`lats`, :py:attr:`lons`). 

''' 

 

times = Array.T(shape=(None,), dtype=num.float) 

lats = Array.T(shape=(None,), dtype=num.float, optional=True) 

lons = Array.T(shape=(None,), dtype=num.float, optional=True) 

lat = Float.T(optional=True) 

lon = Float.T(optional=True) 

north_shifts = Array.T(shape=(None,), dtype=num.float, optional=True) 

east_shifts = Array.T(shape=(None,), dtype=num.float, optional=True) 

depths = Array.T(shape=(None,), dtype=num.float) 

dl = Float.T(optional=True) 

dw = Float.T(optional=True) 

nl = Float.T(optional=True) 

nw = Float.T(optional=True) 

 

@classmethod 

def check_scheme(cls, scheme): 

''' 

Check if given GF component scheme is supported by the class. 

 

Raises :py:class:`UnavailableScheme` if the given scheme is not 

supported by this discretized source class. 

''' 

 

if scheme not in cls.provided_schemes: 

raise UnavailableScheme( 

'source type "%s" does not support GF component scheme "%s"' % 

(cls.__name__, scheme)) 

 

def __init__(self, **kwargs): 

Object.__init__(self, **kwargs) 

self._latlons = None 

 

def __setattr__(self, name, value): 

if name in ('lat', 'lon', 'north_shifts', 'east_shifts', 

'lats', 'lons'): 

self.__dict__['_latlons'] = None 

 

Object.__setattr__(self, name, value) 

 

def get_source_terms(self, scheme): 

raise NotImplementedError() 

 

def make_weights(self, receiver, scheme): 

raise NotImplementedError() 

 

@property 

def effective_latlons(self): 

''' 

Property holding the offest-corrected lats and lons of all points. 

''' 

 

if self._latlons is None: 

if self.lats is not None and self.lons is not None: 

if (self.north_shifts is not None and 

self.east_shifts is not None): 

self._latlons = orthodrome.ne_to_latlon( 

self.lats, self.lons, 

self.north_shifts, self.east_shifts) 

else: 

self._latlons = self.lats, self.lons 

else: 

lat = g(self.lat, 0.0) 

lon = g(self.lon, 0.0) 

self._latlons = orthodrome.ne_to_latlon( 

lat, lon, self.north_shifts, self.east_shifts) 

 

return self._latlons 

 

@property 

def effective_north_shifts(self): 

if self.north_shifts is not None: 

return self.north_shifts 

else: 

return num.zeros(self.times.size) 

 

@property 

def effective_east_shifts(self): 

if self.east_shifts is not None: 

return self.east_shifts 

else: 

return num.zeros(self.times.size) 

 

def same_origin(self, receiver): 

''' 

Check if receiver has same reference point. 

''' 

 

return (g(self.lat, 0.0) == receiver.lat and 

g(self.lon, 0.0) == receiver.lon and 

self.lats is None and self.lons is None) 

 

def azibazis_to(self, receiver): 

''' 

Compute azimuths and backaziumuths to/from receiver, for all contained 

points. 

''' 

 

if self.same_origin(receiver): 

azis = r2d * num.arctan2(receiver.east_shift - self.east_shifts, 

receiver.north_shift - self.north_shifts) 

bazis = azis + 180. 

else: 

slats, slons = self.effective_latlons 

rlat, rlon = receiver.effective_latlon 

azis = orthodrome.azimuth_numpy(slats, slons, rlat, rlon) 

bazis = orthodrome.azimuth_numpy(rlat, rlon, slats, slons) 

 

return azis, bazis 

 

def distances_to(self, receiver): 

''' 

Compute distances to receiver for all contained points. 

''' 

if self.same_origin(receiver): 

return num.sqrt((self.north_shifts - receiver.north_shift)**2 + 

(self.east_shifts - receiver.east_shift)**2) 

 

else: 

slats, slons = self.effective_latlons 

rlat, rlon = receiver.effective_latlon 

return orthodrome.distance_accurate50m_numpy(slats, slons, 

rlat, rlon) 

 

def element_coords(self, i): 

if self.lats is not None and self.lons is not None: 

lat = float(self.lats[i]) 

lon = float(self.lons[i]) 

else: 

lat = self.lat 

lon = self.lon 

 

if self.north_shifts is not None and self.east_shifts is not None: 

north_shift = float(self.north_shifts[i]) 

east_shift = float(self.east_shifts[i]) 

 

else: 

north_shift = east_shift = 0.0 

 

return lat, lon, north_shift, east_shift 

 

def coords5(self): 

xs = num.zeros((self.nelements, 5)) 

 

if self.lats is not None and self.lons is not None: 

xs[:, 0] = self.lats 

xs[:, 1] = self.lons 

else: 

xs[:, 0] = g(self.lat, 0.0) 

xs[:, 1] = g(self.lon, 0.0) 

 

if self.north_shifts is not None and self.east_shifts is not None: 

xs[:, 2] = self.north_shifts 

xs[:, 3] = self.east_shifts 

 

xs[:, 4] = self.depths 

 

return xs 

 

@property 

def nelements(self): 

return self.times.size 

 

@classmethod 

def combine(cls, sources, **kwargs): 

''' 

Combine several discretized source models. 

 

Concatenenates all point sources in the given discretized ``sources``. 

Care must be taken when using this function that the external amplitude 

factors and reference times of the parameterized (undiscretized) 

sources match or are accounted for. 

''' 

 

first = sources[0] 

 

if not all(type(s) == type(first) for s in sources): 

raise Exception('DiscretizedSource.combine must be called with ' 

'sources of same type.') 

 

latlons = [] 

for s in sources: 

latlons.append(s.effective_latlons) 

 

lats, lons = num.hstack(latlons) 

 

if all((s.lats is None and s.lons is None) for s in sources): 

rlats = num.array([s.lat for s in sources], dtype=num.float) 

rlons = num.array([s.lon for s in sources], dtype=num.float) 

same_ref = num.all( 

rlats == rlats[0]) and num.all(rlons == rlons[0]) 

else: 

same_ref = False 

 

cat = num.concatenate 

times = cat([s.times for s in sources]) 

depths = cat([s.depths for s in sources]) 

 

if same_ref: 

lat = first.lat 

lon = first.lon 

north_shifts = cat([s.effective_north_shifts for s in sources]) 

east_shifts = cat([s.effective_east_shifts for s in sources]) 

lats = None 

lons = None 

else: 

lat = None 

lon = None 

north_shifts = None 

east_shifts = None 

 

return cls( 

times=times, lat=lat, lon=lon, lats=lats, lons=lons, 

north_shifts=north_shifts, east_shifts=east_shifts, 

depths=depths, **kwargs) 

 

def centroid_position(self): 

moments = self.moments() 

norm = num.sum(moments) 

if norm != 0.0: 

w = moments / num.sum(moments) 

else: 

w = num.ones(moments.size) 

 

if self.lats is not None and self.lons is not None: 

lats, lons = self.effective_latlons 

rlat, rlon = num.mean(lats), num.mean(lons) 

n, e = orthodrome.latlon_to_ne_numpy(rlat, rlon, lats, lons) 

else: 

rlat, rlon = g(self.lat, 0.0), g(self.lon, 0.0) 

n, e = self.north_shifts, self.east_shifts 

 

cn = num.sum(n*w) 

ce = num.sum(e*w) 

clat, clon = orthodrome.ne_to_latlon(rlat, rlon, cn, ce) 

 

if self.lats is not None and self.lons is not None: 

lat = clat 

lon = clon 

north_shift = 0. 

east_shift = 0. 

else: 

lat = g(self.lat, 0.0) 

lon = g(self.lon, 0.0) 

north_shift = cn 

east_shift = ce 

 

depth = num.sum(self.depths*w) 

time = num.sum(self.times*w) 

return tuple(float(x) for x in 

(time, lat, lon, north_shift, east_shift, depth)) 

 

 

class DiscretizedExplosionSource(DiscretizedSource): 

m0s = Array.T(shape=(None,), dtype=num.float) 

 

provided_schemes = ( 

'elastic2', 

'elastic8', 

'elastic10', 

) 

 

def get_source_terms(self, scheme): 

self.check_scheme(scheme) 

 

if scheme == 'elastic2': 

return self.m0s[:, num.newaxis].copy() 

 

elif scheme in ('elastic8', 'elastic10'): 

m6s = num.zeros((self.m0s.size, 6)) 

m6s[:, 0:3] = self.m0s[:, num.newaxis] 

return m6s 

else: 

assert False 

 

def make_weights(self, receiver, scheme): 

self.check_scheme(scheme) 

 

azis, bazis = self.azibazis_to(receiver) 

 

sb = num.sin(bazis*d2r-num.pi) 

cb = num.cos(bazis*d2r-num.pi) 

 

m0s = self.m0s 

n = azis.size 

 

cat = num.concatenate 

rep = num.repeat 

 

if scheme == 'elastic2': 

w_n = cb*m0s 

g_n = filledi(0, n) 

w_e = sb*m0s 

g_e = filledi(0, n) 

w_d = m0s 

g_d = filledi(1, n) 

 

elif scheme == 'elastic8': 

w_n = cat((cb*m0s, cb*m0s)) 

g_n = rep((0, 2), n) 

w_e = cat((sb*m0s, sb*m0s)) 

g_e = rep((0, 2), n) 

w_d = cat((m0s, m0s)) 

g_d = rep((5, 7), n) 

 

elif scheme == 'elastic10': 

w_n = cat((cb*m0s, cb*m0s, cb*m0s)) 

g_n = rep((0, 2, 8), n) 

w_e = cat((sb*m0s, sb*m0s, sb*m0s)) 

g_e = rep((0, 2, 8), n) 

w_d = cat((m0s, m0s, m0s)) 

g_d = rep((5, 7, 9), n) 

 

else: 

assert False 

 

return ( 

('displacement.n', w_n, g_n), 

('displacement.e', w_e, g_e), 

('displacement.d', w_d, g_d), 

) 

 

def split(self): 

from pyrocko.gf.seismosizer import ExplosionSource 

sources = [] 

for i in range(self.nelements): 

lat, lon, north_shift, east_shift = self.element_coords(i) 

sources.append(ExplosionSource( 

time=float(self.times[i]), 

lat=lat, 

lon=lon, 

north_shift=north_shift, 

east_shift=east_shift, 

depth=float(self.depths[i]), 

moment=float(self.m0s[i]))) 

 

return sources 

 

def moments(self): 

return self.m0s 

 

def centroid(self): 

from pyrocko.gf.seismosizer import ExplosionSource 

time, lat, lon, north_shift, east_shift, depth = \ 

self.centroid_position() 

 

return ExplosionSource( 

time=time, 

lat=lat, 

lon=lon, 

north_shift=north_shift, 

east_shift=east_shift, 

depth=depth, 

moment=float(num.sum(self.m0s))) 

 

@classmethod 

def combine(cls, sources, **kwargs): 

''' 

Combine several discretized source models. 

 

Concatenenates all point sources in the given discretized ``sources``. 

Care must be taken when using this function that the external amplitude 

factors and reference times of the parameterized (undiscretized) 

sources match or are accounted for. 

''' 

 

if 'm0s' not in kwargs: 

kwargs['m0s'] = num.concatenate([s.m0s for s in sources]) 

 

return super(DiscretizedExplosionSource, cls).combine(sources, 

**kwargs) 

 

 

class DiscretizedSFSource(DiscretizedSource): 

forces = Array.T(shape=(None, 3), dtype=num.float) 

 

provided_schemes = ( 

'elastic5', 

) 

 

def get_source_terms(self, scheme): 

self.check_scheme(scheme) 

 

return self.forces 

 

def make_weights(self, receiver, scheme): 

self.check_scheme(scheme) 

 

azis, bazis = self.azibazis_to(receiver) 

 

sa = num.sin(azis*d2r) 

ca = num.cos(azis*d2r) 

sb = num.sin(bazis*d2r-num.pi) 

cb = num.cos(bazis*d2r-num.pi) 

 

forces = self.forces 

fn = forces[:, 0] 

fe = forces[:, 1] 

fd = forces[:, 2] 

 

f0 = fd 

f1 = ca * fn + sa * fe 

f2 = ca * fe - sa * fn 

 

n = azis.size 

 

if scheme == 'elastic5': 

ioff = 0 

 

cat = num.concatenate 

rep = num.repeat 

 

w_n = cat((cb*f0, cb*f1, -sb*f2)) 

g_n = ioff + rep((0, 1, 2), n) 

w_e = cat((sb*f0, sb*f1, cb*f2)) 

g_e = ioff + rep((0, 1, 2), n) 

w_d = cat((f0, f1)) 

g_d = ioff + rep((3, 4), n) 

 

return ( 

('displacement.n', w_n, g_n), 

('displacement.e', w_e, g_e), 

('displacement.d', w_d, g_d), 

) 

 

@classmethod 

def combine(cls, sources, **kwargs): 

''' 

Combine several discretized source models. 

 

Concatenenates all point sources in the given discretized ``sources``. 

Care must be taken when using this function that the external amplitude 

factors and reference times of the parameterized (undiscretized) 

sources match or are accounted for. 

''' 

 

if 'forces' not in kwargs: 

kwargs['forces'] = num.vstack([s.forces for s in sources]) 

 

return super(DiscretizedSFSource, cls).combine(sources, **kwargs) 

 

def moments(self): 

return num.sum(self.forces**2, axis=1) 

 

def centroid(self): 

from pyrocko.gf.seismosizer import SFSource 

time, lat, lon, north_shift, east_shift, depth = \ 

self.centroid_position() 

 

fn, fe, fd = map(float, num.sum(self.forces, axis=0)) 

return SFSource( 

time=time, 

lat=lat, 

lon=lon, 

north_shift=north_shift, 

east_shift=east_shift, 

depth=depth, 

fn=fn, 

fe=fe, 

fd=fd) 

 

 

class DiscretizedMTSource(DiscretizedSource): 

m6s = Array.T( 

shape=(None, 6), dtype=num.float, 

help='rows with (m_nn, m_ee, m_dd, m_ne, m_nd, m_ed)') 

 

provided_schemes = ( 

'elastic8', 

'elastic10', 

'elastic18', 

) 

 

def get_source_terms(self, scheme): 

self.check_scheme(scheme) 

return self.m6s 

 

def make_weights(self, receiver, scheme): 

self.check_scheme(scheme) 

 

m6s = self.m6s 

n = m6s.shape[0] 

rep = num.repeat 

 

if scheme == 'elastic18': 

w_n = m6s.flatten() 

g_n = num.tile(num.arange(0, 6), n) 

w_e = m6s.flatten() 

g_e = num.tile(num.arange(6, 12), n) 

w_d = m6s.flatten() 

g_d = num.tile(num.arange(12, 18), n) 

 

else: 

azis, bazis = self.azibazis_to(receiver) 

 

sa = num.sin(azis*d2r) 

ca = num.cos(azis*d2r) 

s2a = num.sin(2.*azis*d2r) 

c2a = num.cos(2.*azis*d2r) 

sb = num.sin(bazis*d2r-num.pi) 

cb = num.cos(bazis*d2r-num.pi) 

 

f0 = m6s[:, 0]*ca**2 + m6s[:, 1]*sa**2 + m6s[:, 3]*s2a 

f1 = m6s[:, 4]*ca + m6s[:, 5]*sa 

f2 = m6s[:, 2] 

f3 = 0.5*(m6s[:, 1]-m6s[:, 0])*s2a + m6s[:, 3]*c2a 

f4 = m6s[:, 5]*ca - m6s[:, 4]*sa 

f5 = m6s[:, 0]*sa**2 + m6s[:, 1]*ca**2 - m6s[:, 3]*s2a 

 

cat = num.concatenate 

 

if scheme == 'elastic8': 

w_n = cat((cb*f0, cb*f1, cb*f2, -sb*f3, -sb*f4)) 

g_n = rep((0, 1, 2, 3, 4), n) 

w_e = cat((sb*f0, sb*f1, sb*f2, cb*f3, cb*f4)) 

g_e = rep((0, 1, 2, 3, 4), n) 

w_d = cat((f0, f1, f2)) 

g_d = rep((5, 6, 7), n) 

 

elif scheme == 'elastic10': 

w_n = cat((cb*f0, cb*f1, cb*f2, cb*f5, -sb*f3, -sb*f4)) 

g_n = rep((0, 1, 2, 8, 3, 4), n) 

w_e = cat((sb*f0, sb*f1, sb*f2, sb*f5, cb*f3, cb*f4)) 

g_e = rep((0, 1, 2, 8, 3, 4), n) 

w_d = cat((f0, f1, f2, f5)) 

g_d = rep((5, 6, 7, 9), n) 

 

else: 

assert False 

 

return ( 

('displacement.n', w_n, g_n), 

('displacement.e', w_e, g_e), 

('displacement.d', w_d, g_d), 

) 

 

def split(self): 

from pyrocko.gf.seismosizer import MTSource 

sources = [] 

for i in range(self.nelements): 

lat, lon, north_shift, east_shift = self.element_coords(i) 

sources.append(MTSource( 

time=float(self.times[i]), 

lat=lat, 

lon=lon, 

north_shift=north_shift, 

east_shift=east_shift, 

depth=float(self.depths[i]), 

m6=self.m6s[i])) 

 

return sources 

 

def moments(self): 

moments = num.array( 

[num.linalg.eigvalsh(moment_tensor.symmat6(*m6)) 

for m6 in self.m6s]) 

return num.linalg.norm(moments, axis=1) / num.sqrt(2.) 

 

def get_moment_rate(self, deltat=None): 

moments = self.moments() 

times = self.times 

times -= times.min() 

 

t_max = times.max() 

mom_times = num.arange(0, t_max + 2 * deltat, deltat) - deltat 

mom_times[mom_times > t_max] = t_max 

 

# Right open histrogram bins 

mom, _ = num.histogram( 

times, 

bins=mom_times, 

weights=moments) 

 

deltat = num.diff(mom_times) 

mom_rate = mom / deltat 

 

return mom_rate, mom_times[1:] 

 

def centroid(self): 

from pyrocko.gf.seismosizer import MTSource 

time, lat, lon, north_shift, east_shift, depth = \ 

self.centroid_position() 

 

return MTSource( 

time=time, 

lat=lat, 

lon=lon, 

north_shift=north_shift, 

east_shift=east_shift, 

depth=depth, 

m6=num.sum(self.m6s, axis=0)) 

 

@classmethod 

def combine(cls, sources, **kwargs): 

''' 

Combine several discretized source models. 

 

Concatenenates all point sources in the given discretized ``sources``. 

Care must be taken when using this function that the external amplitude 

factors and reference times of the parameterized (undiscretized) 

sources match or are accounted for. 

''' 

 

if 'm6s' not in kwargs: 

kwargs['m6s'] = num.vstack([s.m6s for s in sources]) 

 

return super(DiscretizedMTSource, cls).combine(sources, **kwargs) 

 

 

class DiscretizedPorePressureSource(DiscretizedSource): 

pp = Array.T(shape=(None,), dtype=num.float) 

 

provided_schemes = ( 

'poroelastic10', 

) 

 

def get_source_terms(self, scheme): 

self.check_scheme(scheme) 

return self.pp[:, num.newaxis].copy() 

 

def make_weights(self, receiver, scheme): 

self.check_scheme(scheme) 

 

azis, bazis = self.azibazis_to(receiver) 

 

sb = num.sin(bazis*d2r-num.pi) 

cb = num.cos(bazis*d2r-num.pi) 

 

pp = self.pp 

n = bazis.size 

 

w_un = cb*pp 

g_un = filledi(1, n) 

w_ue = sb*pp 

g_ue = filledi(1, n) 

w_ud = pp 

g_ud = filledi(0, n) 

 

w_tn = cb*pp 

g_tn = filledi(6, n) 

w_te = sb*pp 

g_te = filledi(6, n) 

 

w_pp = pp 

g_pp = filledi(7, n) 

 

w_dvn = cb*pp 

g_dvn = filledi(9, n) 

w_dve = sb*pp 

g_dve = filledi(9, n) 

w_dvd = pp 

g_dvd = filledi(8, n) 

 

return ( 

('displacement.n', w_un, g_un), 

('displacement.e', w_ue, g_ue), 

('displacement.d', w_ud, g_ud), 

('vertical_tilt.n', w_tn, g_tn), 

('vertical_tilt.e', w_te, g_te), 

('pore_pressure', w_pp, g_pp), 

('darcy_velocity.n', w_dvn, g_dvn), 

('darcy_velocity.e', w_dve, g_dve), 

('darcy_velocity.d', w_dvd, g_dvd), 

) 

 

def moments(self): 

return self.pp 

 

def centroid(self): 

from pyrocko.gf.seismosizer import PorePressurePointSource 

time, lat, lon, north_shift, east_shift, depth = \ 

self.centroid_position() 

 

return PorePressurePointSource( 

time=time, 

lat=lat, 

lon=lon, 

north_shift=north_shift, 

east_shift=east_shift, 

depth=depth, 

pp=float(num.sum(self.pp))) 

 

@classmethod 

def combine(cls, sources, **kwargs): 

''' 

Combine several discretized source models. 

 

Concatenenates all point sources in the given discretized ``sources``. 

Care must be taken when using this function that the external amplitude 

factors and reference times of the parameterized (undiscretized) 

sources match or are accounted for. 

''' 

 

if 'pp' not in kwargs: 

kwargs['pp'] = num.concatenate([s.pp for s in sources]) 

 

return super(DiscretizedPorePressureSource, cls).combine(sources, 

**kwargs) 

 

 

class Region(Object): 

name = String.T(optional=True) 

 

 

class RectangularRegion(Region): 

lat_min = Float.T() 

lat_max = Float.T() 

lon_min = Float.T() 

lon_max = Float.T() 

 

 

class CircularRegion(Region): 

lat = Float.T() 

lon = Float.T() 

radius = Float.T() 

 

 

class Config(Object): 

''' 

Green's function store meta information. 

 

Currently implemented :py:class:`~pyrocko.gf.store.Store` 

configuration types are: 

 

* :py:class:`~pyrocko.gf.meta.ConfigTypeA` - cylindrical or 

spherical symmetry, 1D earth model, single receiver depth 

 

* Problem is invariant to horizontal translations and rotations around 

vertical axis. 

* All receivers must be at the same depth (e.g. at the surface) 

* High level index variables: ``(source_depth, receiver_distance, 

component)`` 

 

* :py:class:`~pyrocko.gf.meta.ConfigTypeB` - cylindrical or 

spherical symmetry, 1D earth model, variable receiver depth 

 

* Symmetries like in Type A but has additional index for receiver depth 

* High level index variables: ``(source_depth, receiver_distance, 

receiver_depth, component)`` 

 

* :py:class:`~pyrocko.gf.meta.ConfigTypeC` - no symmetrical 

constraints but fixed receiver positions 

 

* Cartesian source volume around a reference point 

* High level index variables: ``(ireceiver, source_depth, 

source_east_shift, source_north_shift, component)`` 

''' 

 

id = StringID.T( 

help='Name of the store. May consist of upper and lower-case letters, ' 

'digits, dots and underscores. The name must start with a ' 

'letter.') 

 

derived_from_id = StringID.T( 

optional=True, 

help='Name of the original store, if this store has been derived from ' 

'another one (e.g. extracted subset).') 

 

version = String.T( 

default='1.0', 

optional=True, 

help='User-defined version string. Use <major>.<minor> format.') 

 

modelling_code_id = StringID.T( 

optional=True, 

help='Identifier of the backend used to compute the store.') 

 

author = Unicode.T( 

optional=True, 

help='Comma-separated list of author names.') 

 

author_email = String.T( 

optional=True, 

help="Author's contact email address.") 

 

created_time = Timestamp.T( 

optional=True, 

help='Time of creation of the store.') 

 

regions = List.T( 

Region.T(), 

help='Geographical regions for which the store is representative.') 

 

scope_type = ScopeType.T( 

optional=True, 

help='Distance range scope of the store ' 

'(%s).' % fmt_choices(ScopeType)) 

 

waveform_type = WaveType.T( 

optional=True, 

help='Wave type stored (%s).' % fmt_choices(WaveType)) 

 

nearfield_terms = NearfieldTermsType.T( 

optional=True, 

help='Information about the inclusion of near-field terms in the ' 

'modelling (%s).' % fmt_choices(NearfieldTermsType)) 

 

description = String.T( 

optional=True, 

help='Free form textual description of the GF store.') 

 

references = List.T( 

Reference.T(), 

help='Reference list to cite the modelling code, earth model or ' 

'related work.') 

 

earthmodel_1d = Earthmodel1D.T( 

optional=True, 

help='Layered earth model in ND (named discontinuity) format.') 

 

earthmodel_receiver_1d = Earthmodel1D.T( 

optional=True, 

help='Receiver-side layered earth model in ND format.') 

 

can_interpolate_source = Bool.T( 

optional=True, 

help='Hint to indicate if the spatial sampling of the store is dense ' 

'enough for multi-linear interpolation at the source.') 

 

can_interpolate_receiver = Bool.T( 

optional=True, 

help='Hint to indicate if the spatial sampling of the store is dense ' 

'enough for multi-linear interpolation at the receiver.') 

 

frequency_min = Float.T( 

optional=True, 

help='Hint to indicate the lower bound of valid frequencies [Hz].') 

 

frequency_max = Float.T( 

optional=True, 

help='Hint to indicate the upper bound of valid frequencies [Hz].') 

 

sample_rate = Float.T( 

optional=True, 

help='Sample rate of the GF store [Hz].') 

 

factor = Float.T( 

default=1.0, 

help='Gain value, factored out of the stored GF samples. ' 

'(may not work properly, keep at 1.0).', 

optional=True) 

 

component_scheme = ComponentScheme.T( 

default='elastic10', 

help='GF component scheme (%s).' % fmt_choices(ComponentScheme)) 

 

stored_quantity = QuantityType.T( 

optional=True, 

help='Physical quantity of stored values (%s). If not given, a ' 

'default is used based on the GF component scheme. The default ' 

'for the ``"elastic*"`` family of component schemes is ' 

'``"displacement"``.' % fmt_choices(QuantityType)) 

 

tabulated_phases = List.T( 

TPDef.T(), 

help='Mapping of phase names to phase definitions, for which travel ' 

'time tables are available in the GF store.') 

 

ncomponents = Int.T( 

optional=True, 

help='Number of GF components. Use :gattr:`component_scheme` instead.') 

 

uuid = String.T( 

optional=True, 

help='Heuristic hash value which can be used to uniquely identify the ' 

'GF store for practical purposes.') 

 

reference = String.T( 

optional=True, 

help='Store reference name composed of the store\'s :gattr:`id` and ' 

'the first six letters of its :gattr:`uuid`.') 

 

def __init__(self, **kwargs): 

self._do_auto_updates = False 

Object.__init__(self, **kwargs) 

self._index_function = None 

self._indices_function = None 

self._vicinity_function = None 

self.validate(regularize=True, depth=1) 

self._do_auto_updates = True 

self.update() 

 

def check_ncomponents(self): 

ncomponents = component_scheme_to_description[ 

self.component_scheme].ncomponents 

 

if self.ncomponents is None: 

self.ncomponents = ncomponents 

elif ncomponents != self.ncomponents: 

raise InvalidNComponents( 

'ncomponents=%i incompatible with component_scheme="%s"' % ( 

self.ncomponents, self.component_scheme)) 

 

def __setattr__(self, name, value): 

Object.__setattr__(self, name, value) 

try: 

self.T.get_property(name) 

if self._do_auto_updates: 

self.update() 

 

except ValueError: 

pass 

 

def update(self): 

self.check_ncomponents() 

self._update() 

self._make_index_functions() 

 

def irecord(self, *args): 

return self._index_function(*args) 

 

def irecords(self, *args): 

return self._indices_function(*args) 

 

def vicinity(self, *args): 

return self._vicinity_function(*args) 

 

def vicinities(self, *args): 

return self._vicinities_function(*args) 

 

def grid_interpolation_coefficients(self, *args): 

return self._grid_interpolation_coefficients(*args) 

 

def nodes(self, level=None, minlevel=None): 

return nodes(self.coords[minlevel:level]) 

 

def iter_nodes(self, level=None, minlevel=None): 

return nditer_outer(self.coords[minlevel:level]) 

 

def iter_extraction(self, gdef, level=None): 

i = 0 

arrs = [] 

ntotal = 1 

for mi, ma, inc in zip(self.mins, self.effective_maxs, self.deltas): 

if gdef and len(gdef) > i: 

sssn = gdef[i] 

else: 

sssn = (None,)*4 

 

arr = num.linspace(*start_stop_num(*(sssn + (mi, ma, inc)))) 

ntotal *= len(arr) 

 

arrs.append(arr) 

i += 1 

 

arrs.append(self.coords[-1]) 

return nditer_outer(arrs[:level]) 

 

def make_sum_params(self, source, receiver, implementation='c', 

nthreads=0): 

assert implementation in ['c', 'python'] 

 

out = [] 

delays = source.times 

for comp, weights, icomponents in source.make_weights( 

receiver, 

self.component_scheme): 

 

weights *= self.factor 

 

args = self.make_indexing_args(source, receiver, icomponents) 

delays_expanded = num.tile(delays, icomponents.size//delays.size) 

out.append((comp, args, delays_expanded, weights)) 

 

return out 

 

def short_info(self): 

raise NotImplementedError('should be implemented in subclass') 

 

def get_shear_moduli(self, lat, lon, points, 

interpolation=None): 

''' 

Get shear moduli at given points from contained velocity model. 

 

:param lat: surface origin for coordinate system of ``points`` 

:param points: NumPy array of shape ``(N, 3)``, where each row is 

a point ``(north, east, depth)``, relative to origin at 

``(lat, lon)`` 

:param interpolation: interpolation method. Choose from 

``('nearest_neighbor', 'multilinear')`` 

:returns: NumPy array of length N with extracted shear moduli at each 

point 

 

The default implementation retrieves and interpolates the shear moduli 

from the contained 1D velocity profile. 

''' 

return self.get_material_property(lat, lon, points, 

parameter='shear_moduli', 

interpolation=interpolation) 

 

def get_lambda_moduli(self, lat, lon, points, 

interpolation=None): 

''' 

Get lambda moduli at given points from contained velocity model. 

 

:param lat: surface origin for coordinate system of ``points`` 

:param points: NumPy array of shape ``(N, 3)``, where each row is 

a point ``(north, east, depth)``, relative to origin at 

``(lat, lon)`` 

:param interpolation: interpolation method. Choose from 

``('nearest_neighbor', 'multilinear')`` 

:returns: NumPy array of length N with extracted shear moduli at each 

point 

 

The default implementation retrieves and interpolates the lambda moduli 

from the contained 1D velocity profile. 

''' 

return self.get_material_property(lat, lon, points, 

parameter='lambda_moduli', 

interpolation=interpolation) 

 

def get_bulk_moduli(self, lat, lon, points, 

interpolation=None): 

''' 

Get bulk moduli at given points from contained velocity model. 

 

:param lat: surface origin for coordinate system of ``points`` 

:param points: NumPy array of shape ``(N, 3)``, where each row is 

a point ``(north, east, depth)``, relative to origin at 

``(lat, lon)`` 

:param interpolation: interpolation method. Choose from 

``('nearest_neighbor', 'multilinear')`` 

:returns: NumPy array of length N with extracted shear moduli at each 

point 

 

The default implementation retrieves and interpolates the lambda moduli 

from the contained 1D velocity profile. 

''' 

lambda_moduli = self.get_material_property( 

lat, lon, points, parameter='lambda_moduli', 

interpolation=interpolation) 

shear_moduli = self.get_material_property( 

lat, lon, points, parameter='shear_moduli', 

interpolation=interpolation) 

return lambda_moduli + (2 / 3) * shear_moduli 

 

def get_vs(self, lat, lon, points, interpolation=None): 

''' 

Get Vs at given points from contained velocity model. 

 

:param lat: surface origin for coordinate system of ``points`` 

:param points: NumPy array of shape ``(N, 3)``, where each row is 

a point ``(north, east, depth)``, relative to origin at 

``(lat, lon)`` 

:param interpolation: interpolation method. Choose from 

``('nearest_neighbor', 'multilinear')`` 

:returns: NumPy array of length N with extracted shear moduli at each 

point 

 

The default implementation retrieves and interpolates Vs 

from the contained 1D velocity profile. 

''' 

return self.get_material_property(lat, lon, points, 

parameter='vs', 

interpolation=interpolation) 

 

def get_vp(self, lat, lon, points, interpolation=None): 

''' 

Get Vp at given points from contained velocity model. 

 

:param lat: surface origin for coordinate system of ``points`` 

:param points: NumPy array of shape ``(N, 3)``, where each row is 

a point ``(north, east, depth)``, relative to origin at 

``(lat, lon)`` 

:param interpolation: interpolation method. Choose from 

``('nearest_neighbor', 'multilinear')`` 

:returns: NumPy array of length N with extracted shear moduli at each 

point 

 

The default implementation retrieves and interpolates Vp 

from the contained 1D velocity profile. 

''' 

return self.get_material_property(lat, lon, points, 

parameter='vp', 

interpolation=interpolation) 

 

def get_rho(self, lat, lon, points, interpolation=None): 

''' 

Get rho at given points from contained velocity model. 

 

:param lat: surface origin for coordinate system of ``points`` 

:param points: NumPy array of shape ``(N, 3)``, where each row is 

a point ``(north, east, depth)``, relative to origin at 

``(lat, lon)`` 

:param interpolation: interpolation method. Choose from 

``('nearest_neighbor', 'multilinear')`` 

:returns: NumPy array of length N with extracted shear moduli at each 

point 

 

The default implementation retrieves and interpolates rho 

from the contained 1D velocity profile. 

''' 

return self.get_material_property(lat, lon, points, 

parameter='rho', 

interpolation=interpolation) 

 

def get_material_property(self, lat, lon, points, parameter='vs', 

interpolation=None): 

 

if interpolation is None: 

raise TypeError('Interpolation method not defined! available: ' 

"multilinear", "nearest_neighbor") 

 

earthmod = self.earthmodel_1d 

store_depth_profile = self.get_source_depths() 

z_profile = earthmod.profile('z') 

 

if parameter == 'vs': 

vs_profile = earthmod.profile('vs') 

profile = num.interp( 

store_depth_profile, z_profile, vs_profile) 

 

elif parameter == 'vp': 

vp_profile = earthmod.profile('vp') 

profile = num.interp( 

store_depth_profile, z_profile, vp_profile) 

 

elif parameter == 'rho': 

rho_profile = earthmod.profile('rho') 

 

profile = num.interp( 

store_depth_profile, z_profile, rho_profile) 

 

elif parameter == 'shear_moduli': 

vs_profile = earthmod.profile('vs') 

rho_profile = earthmod.profile('rho') 

 

store_vs_profile = num.interp( 

store_depth_profile, z_profile, vs_profile) 

store_rho_profile = num.interp( 

store_depth_profile, z_profile, rho_profile) 

 

profile = num.power(store_vs_profile, 2) * store_rho_profile 

 

elif parameter == 'lambda_moduli': 

vs_profile = earthmod.profile('vs') 

vp_profile = earthmod.profile('vp') 

rho_profile = earthmod.profile('rho') 

 

store_vs_profile = num.interp( 

store_depth_profile, z_profile, vs_profile) 

store_vp_profile = num.interp( 

store_depth_profile, z_profile, vp_profile) 

store_rho_profile = num.interp( 

store_depth_profile, z_profile, rho_profile) 

 

profile = store_rho_profile * ( 

num.power(store_vp_profile, 2) - 

num.power(store_vs_profile, 2) * 2) 

else: 

raise TypeError( 

'parameter %s not available' % parameter) 

 

if interpolation == 'multilinear': 

kind = 'linear' 

elif interpolation == 'nearest_neighbor': 

kind = 'nearest' 

else: 

raise TypeError( 

'Interpolation method %s not available' % interpolation) 

 

interpolator = interp1d(store_depth_profile, profile, kind=kind) 

 

try: 

return interpolator(points[:, 2]) 

except ValueError: 

raise OutOfBounds() 

 

def is_static(self): 

for code in ('psgrn_pscmp', 'poel'): 

if self.modelling_code_id.startswith(code): 

return True 

return False 

 

def is_dynamic(self): 

return not self.is_static() 

 

def get_source_depths(self): 

raise NotImplementedError('must be implemented in subclass') 

 

def get_tabulated_phase(self, phase_id): 

''' 

Get tabulated phase definition. 

''' 

 

for pdef in self.tabulated_phases: 

if pdef.id == phase_id: 

return pdef 

 

raise StoreError('No such phase: %s' % phase_id) 

 

def fix_ttt_holes(self, sptree, mode): 

raise StoreError( 

'Cannot fix travel time table holes in GF stores of type %s.' 

% self.short_type) 

 

 

class ConfigTypeA(Config): 

''' 

Cylindrical symmetry, 1D earth model, single receiver depth 

 

* Problem is invariant to horizontal translations and rotations around 

vertical axis. 

 

* All receivers must be at the same depth (e.g. at the surface) 

High level index variables: ``(source_depth, distance, 

component)`` 

 

* The ``distance`` is the surface distance between source and receiver 

points. 

''' 

 

receiver_depth = Float.T( 

default=0.0, 

help='Fixed receiver depth [m].') 

 

source_depth_min = Float.T( 

help='Minimum source depth [m].') 

 

source_depth_max = Float.T( 

help='Maximum source depth [m].') 

 

source_depth_delta = Float.T( 

help='Grid spacing of source depths [m]') 

 

distance_min = Float.T( 

help='Minimum source-receiver surface distance [m].') 

 

distance_max = Float.T( 

help='Maximum source-receiver surface distance [m].') 

 

distance_delta = Float.T( 

help='Grid spacing of source-receiver surface distance [m].') 

 

short_type = 'A' 

 

provided_schemes = [ 

'elastic2', 'elastic5', 'elastic8', 'elastic10', 'poroelastic10'] 

 

def get_surface_distance(self, args): 

return args[1] 

 

def get_distance(self, args): 

return math.sqrt(args[0]**2 + args[1]**2) 

 

def get_source_depth(self, args): 

return args[0] 

 

def get_source_depths(self): 

return self.coords[0] 

 

def get_receiver_depth(self, args): 

return self.receiver_depth 

 

def _update(self): 

self.mins = num.array( 

[self.source_depth_min, self.distance_min], dtype=num.float) 

self.maxs = num.array( 

[self.source_depth_max, self.distance_max], dtype=num.float) 

self.deltas = num.array( 

[self.source_depth_delta, self.distance_delta], 

dtype=num.float) 

self.ns = num.floor((self.maxs - self.mins) / self.deltas + 

vicinity_eps).astype(num.int) + 1 

self.effective_maxs = self.mins + self.deltas * (self.ns - 1) 

self.deltat = 1.0/self.sample_rate 

self.nrecords = num.product(self.ns) * self.ncomponents 

self.coords = tuple(num.linspace(mi, ma, n) for 

(mi, ma, n) in 

zip(self.mins, self.effective_maxs, self.ns)) + \ 

(num.arange(self.ncomponents),) 

 

self.nsource_depths, self.ndistances = self.ns 

 

def _make_index_functions(self): 

 

amin, bmin = self.mins 

da, db = self.deltas 

na, nb = self.ns 

 

ng = self.ncomponents 

 

def index_function(a, b, ig): 

ia = int(round((a - amin) / da)) 

ib = int(round((b - bmin) / db)) 

try: 

return num.ravel_multi_index((ia, ib, ig), (na, nb, ng)) 

except ValueError: 

raise OutOfBounds() 

 

def indices_function(a, b, ig): 

ia = num.round((a - amin) / da).astype(int) 

ib = num.round((b - bmin) / db).astype(int) 

try: 

return num.ravel_multi_index((ia, ib, ig), (na, nb, ng)) 

except ValueError: 

for ia_, ib_, ig_ in zip(ia, ib, ig): 

try: 

num.ravel_multi_index((ia_, ib_, ig_), (na, nb, ng)) 

except ValueError: 

raise OutOfBounds() 

 

def grid_interpolation_coefficients(a, b): 

ias = indi12((a - amin) / da, na) 

ibs = indi12((b - bmin) / db, nb) 

return ias, ibs 

 

def vicinity_function(a, b, ig): 

ias, ibs = grid_interpolation_coefficients(a, b) 

 

if not (0 <= ig < ng): 

raise OutOfBounds() 

 

indis = [] 

weights = [] 

for ia, va in ias: 

iia = ia*nb*ng 

for ib, vb in ibs: 

indis.append(iia + ib*ng + ig) 

weights.append(va*vb) 

 

return num.array(indis), num.array(weights) 

 

def vicinities_function(a, b, ig): 

 

xa = (a - amin) / da 

xb = (b - bmin) / db 

 

xa_fl = num.floor(xa) 

xa_ce = num.ceil(xa) 

xb_fl = num.floor(xb) 

xb_ce = num.ceil(xb) 

va_fl = 1.0 - (xa - xa_fl) 

va_ce = (1.0 - (xa_ce - xa)) * (xa_ce - xa_fl) 

vb_fl = 1.0 - (xb - xb_fl) 

vb_ce = (1.0 - (xb_ce - xb)) * (xb_ce - xb_fl) 

 

ia_fl = xa_fl.astype(num.int) 

ia_ce = xa_ce.astype(num.int) 

ib_fl = xb_fl.astype(num.int) 

ib_ce = xb_ce.astype(num.int) 

 

if num.any(ia_fl < 0) or num.any(ia_fl >= na): 

raise OutOfBounds() 

 

if num.any(ia_ce < 0) or num.any(ia_ce >= na): 

raise OutOfBounds() 

 

if num.any(ib_fl < 0) or num.any(ib_fl >= nb): 

raise OutOfBounds() 

 

if num.any(ib_ce < 0) or num.any(ib_ce >= nb): 

raise OutOfBounds() 

 

irecords = num.empty(a.size*4, dtype=num.int) 

irecords[0::4] = ia_fl*nb*ng + ib_fl*ng + ig 

irecords[1::4] = ia_ce*nb*ng + ib_fl*ng + ig 

irecords[2::4] = ia_fl*nb*ng + ib_ce*ng + ig 

irecords[3::4] = ia_ce*nb*ng + ib_ce*ng + ig 

 

weights = num.empty(a.size*4, dtype=num.float) 

weights[0::4] = va_fl * vb_fl 

weights[1::4] = va_ce * vb_fl 

weights[2::4] = va_fl * vb_ce 

weights[3::4] = va_ce * vb_ce 

 

return irecords, weights 

 

self._index_function = index_function 

self._indices_function = indices_function 

self._grid_interpolation_coefficients = grid_interpolation_coefficients 

self._vicinity_function = vicinity_function 

self._vicinities_function = vicinities_function 

 

def make_indexing_args(self, source, receiver, icomponents): 

nc = icomponents.size 

dists = source.distances_to(receiver) 

n = dists.size 

return (num.tile(source.depths, nc//n), 

num.tile(dists, nc//n), 

icomponents) 

 

def make_indexing_args1(self, source, receiver): 

return (source.depth, source.distance_to(receiver)) 

 

@property 

def short_extent(self): 

return '%g:%g:%g x %g:%g:%g' % ( 

self.source_depth_min/km, 

self.source_depth_max/km, 

self.source_depth_delta/km, 

self.distance_min/km, 

self.distance_max/km, 

self.distance_delta/km) 

 

def fix_ttt_holes(self, sptree, mode): 

from pyrocko import eikonal_ext, spit 

 

nodes = self.nodes(level=-1) 

 

delta = self.deltas[-1] 

assert num.all(delta == self.deltas) 

 

nsources, ndistances = self.ns 

 

points = num.zeros((nodes.shape[0], 3)) 

points[:, 0] = nodes[:, 1] 

points[:, 2] = nodes[:, 0] 

 

speeds = self.get_material_property( 

0., 0., points, 

parameter='vp' if mode == cake.P else 'vs', 

interpolation='multilinear') 

 

speeds = speeds.reshape((nsources, ndistances)) 

 

times = sptree.interpolate_many(nodes) 

 

times[num.isnan(times)] = -1. 

times = times.reshape(speeds.shape) 

 

try: 

eikonal_ext.eikonal_solver_fmm_cartesian( 

speeds, times, delta) 

except eikonal_ext.EikonalExtError as e: 

if str(e).endswith('please check results'): 

logger.debug( 

'Got a warning from eikonal solver ' 

'- may be ok...') 

else: 

raise 

 

def func(x): 

ibs, ics = \ 

self.grid_interpolation_coefficients(*x) 

 

t = 0 

for ib, vb in ibs: 

for ic, vc in ics: 

t += times[ib, ic] * vb * vc 

 

return t 

 

return spit.SPTree( 

f=func, 

ftol=sptree.ftol, 

xbounds=sptree.xbounds, 

xtols=sptree.xtols) 

 

 

class ConfigTypeB(Config): 

''' 

Cylindrical symmetry, 1D earth model, variable receiver depth 

 

* Symmetries like in :py:class:`ConfigTypeA` but has additional index for 

receiver depth 

 

* High level index variables: ``(source_depth, receiver_distance, 

receiver_depth, component)`` 

''' 

 

receiver_depth_min = Float.T( 

help='Minimum receiver depth [m].') 

 

receiver_depth_max = Float.T( 

help='Maximum receiver depth [m].') 

 

receiver_depth_delta = Float.T( 

help='Grid spacing of receiver depths [m]') 

 

source_depth_min = Float.T( 

help='Minimum source depth [m].') 

 

source_depth_max = Float.T( 

help='Maximum source depth [m].') 

 

source_depth_delta = Float.T( 

help='Grid spacing of source depths [m]') 

 

distance_min = Float.T( 

help='Minimum source-receiver surface distance [m].') 

 

distance_max = Float.T( 

help='Maximum source-receiver surface distance [m].') 

 

distance_delta = Float.T( 

help='Grid spacing of source-receiver surface distances [m].') 

 

short_type = 'B' 

 

provided_schemes = [ 

'elastic2', 'elastic5', 'elastic8', 'elastic10', 'poroelastic10'] 

 

def get_distance(self, args): 

return math.sqrt((args[1] - args[0])**2 + args[2]**2) 

 

def get_surface_distance(self, args): 

return args[2] 

 

def get_source_depth(self, args): 

return args[1] 

 

def get_receiver_depth(self, args): 

return args[0] 

 

def get_source_depths(self): 

return self.coords[1] 

 

def _update(self): 

self.mins = num.array([ 

self.receiver_depth_min, 

self.source_depth_min, 

self.distance_min], 

dtype=num.float) 

 

self.maxs = num.array([ 

self.receiver_depth_max, 

self.source_depth_max, 

self.distance_max], 

dtype=num.float) 

 

self.deltas = num.array([ 

self.receiver_depth_delta, 

self.source_depth_delta, 

self.distance_delta], 

dtype=num.float) 

 

self.ns = num.floor((self.maxs - self.mins) / self.deltas + 

vicinity_eps).astype(num.int) + 1 

self.effective_maxs = self.mins + self.deltas * (self.ns - 1) 

self.deltat = 1.0/self.sample_rate 

self.nrecords = num.product(self.ns) * self.ncomponents 

self.coords = tuple(num.linspace(mi, ma, n) for 

(mi, ma, n) in 

zip(self.mins, self.effective_maxs, self.ns)) + \ 

(num.arange(self.ncomponents),) 

self.nreceiver_depths, self.nsource_depths, self.ndistances = self.ns 

 

def _make_index_functions(self): 

 

amin, bmin, cmin = self.mins 

da, db, dc = self.deltas 

na, nb, nc = self.ns 

ng = self.ncomponents 

 

def index_function(a, b, c, ig): 

ia = int(round((a - amin) / da)) 

ib = int(round((b - bmin) / db)) 

ic = int(round((c - cmin) / dc)) 

try: 

return num.ravel_multi_index((ia, ib, ic, ig), 

(na, nb, nc, ng)) 

except ValueError: 

raise OutOfBounds() 

 

def indices_function(a, b, c, ig): 

ia = num.round((a - amin) / da).astype(int) 

ib = num.round((b - bmin) / db).astype(int) 

ic = num.round((c - cmin) / dc).astype(int) 

try: 

return num.ravel_multi_index((ia, ib, ic, ig), 

(na, nb, nc, ng)) 

except ValueError: 

raise OutOfBounds() 

 

def grid_interpolation_coefficients(a, b, c): 

ias = indi12((a - amin) / da, na) 

ibs = indi12((b - bmin) / db, nb) 

ics = indi12((c - cmin) / dc, nc) 

return ias, ibs, ics 

 

def vicinity_function(a, b, c, ig): 

ias, ibs, ics = grid_interpolation_coefficients(a, b, c) 

 

if not (0 <= ig < ng): 

raise OutOfBounds() 

 

indis = [] 

weights = [] 

for ia, va in ias: 

iia = ia*nb*nc*ng 

for ib, vb in ibs: 

iib = ib*nc*ng 

for ic, vc in ics: 

indis.append(iia + iib + ic*ng + ig) 

weights.append(va*vb*vc) 

 

return num.array(indis), num.array(weights) 

 

def vicinities_function(a, b, c, ig): 

 

xa = (a - amin) / da 

xb = (b - bmin) / db 

xc = (c - cmin) / dc 

 

xa_fl = num.floor(xa) 

xa_ce = num.ceil(xa) 

xb_fl = num.floor(xb) 

xb_ce = num.ceil(xb) 

xc_fl = num.floor(xc) 

xc_ce = num.ceil(xc) 

va_fl = 1.0 - (xa - xa_fl) 

va_ce = (1.0 - (xa_ce - xa)) * (xa_ce - xa_fl) 

vb_fl = 1.0 - (xb - xb_fl) 

vb_ce = (1.0 - (xb_ce - xb)) * (xb_ce - xb_fl) 

vc_fl = 1.0 - (xc - xc_fl) 

vc_ce = (1.0 - (xc_ce - xc)) * (xc_ce - xc_fl) 

 

ia_fl = xa_fl.astype(num.int) 

ia_ce = xa_ce.astype(num.int) 

ib_fl = xb_fl.astype(num.int) 

ib_ce = xb_ce.astype(num.int) 

ic_fl = xc_fl.astype(num.int) 

ic_ce = xc_ce.astype(num.int) 

 

if num.any(ia_fl < 0) or num.any(ia_fl >= na): 

raise OutOfBounds() 

 

if num.any(ia_ce < 0) or num.any(ia_ce >= na): 

raise OutOfBounds() 

 

if num.any(ib_fl < 0) or num.any(ib_fl >= nb): 

raise OutOfBounds() 

 

if num.any(ib_ce < 0) or num.any(ib_ce >= nb): 

raise OutOfBounds() 

 

if num.any(ic_fl < 0) or num.any(ic_fl >= nc): 

raise OutOfBounds() 

 

if num.any(ic_ce < 0) or num.any(ic_ce >= nc): 

raise OutOfBounds() 

 

irecords = num.empty(a.size*8, dtype=num.int) 

irecords[0::8] = ia_fl*nb*nc*ng + ib_fl*nc*ng + ic_fl*ng + ig 

irecords[1::8] = ia_ce*nb*nc*ng + ib_fl*nc*ng + ic_fl*ng + ig 

irecords[2::8] = ia_fl*nb*nc*ng + ib_ce*nc*ng + ic_fl*ng + ig 

irecords[3::8] = ia_ce*nb*nc*ng + ib_ce*nc*ng + ic_fl*ng + ig 

irecords[4::8] = ia_fl*nb*nc*ng + ib_fl*nc*ng + ic_ce*ng + ig 

irecords[5::8] = ia_ce*nb*nc*ng + ib_fl*nc*ng + ic_ce*ng + ig 

irecords[6::8] = ia_fl*nb*nc*ng + ib_ce*nc*ng + ic_ce*ng + ig 

irecords[7::8] = ia_ce*nb*nc*ng + ib_ce*nc*ng + ic_ce*ng + ig 

 

weights = num.empty(a.size*8, dtype=num.float) 

weights[0::8] = va_fl * vb_fl * vc_fl 

weights[1::8] = va_ce * vb_fl * vc_fl 

weights[2::8] = va_fl * vb_ce * vc_fl 

weights[3::8] = va_ce * vb_ce * vc_fl 

weights[4::8] = va_fl * vb_fl * vc_ce 

weights[5::8] = va_ce * vb_fl * vc_ce 

weights[6::8] = va_fl * vb_ce * vc_ce 

weights[7::8] = va_ce * vb_ce * vc_ce 

 

return irecords, weights 

 

self._index_function = index_function 

self._indices_function = indices_function 

self._grid_interpolation_coefficients = grid_interpolation_coefficients 

self._vicinity_function = vicinity_function 

self._vicinities_function = vicinities_function 

 

def make_indexing_args(self, source, receiver, icomponents): 

nc = icomponents.size 

dists = source.distances_to(receiver) 

n = dists.size 

receiver_depths = num.empty(nc) 

receiver_depths.fill(receiver.depth) 

return (receiver_depths, 

num.tile(source.depths, nc//n), 

num.tile(dists, nc//n), 

icomponents) 

 

def make_indexing_args1(self, source, receiver): 

return (receiver.depth, 

source.depth, 

source.distance_to(receiver)) 

 

@property 

def short_extent(self): 

return '%g:%g:%g x %g:%g:%g x %g:%g:%g' % ( 

self.receiver_depth_min/km, 

self.receiver_depth_max/km, 

self.receiver_depth_delta/km, 

self.source_depth_min/km, 

self.source_depth_max/km, 

self.source_depth_delta/km, 

self.distance_min/km, 

self.distance_max/km, 

self.distance_delta/km) 

 

def fix_ttt_holes(self, sptree, mode): 

from pyrocko import eikonal_ext, spit 

 

nodes_sr = self.nodes(minlevel=1, level=-1) 

 

delta = self.deltas[-1] 

assert num.all(delta == self.deltas[1:]) 

 

nreceivers, nsources, ndistances = self.ns 

 

points = num.zeros((nodes_sr.shape[0], 3)) 

points[:, 0] = nodes_sr[:, 1] 

points[:, 2] = nodes_sr[:, 0] 

 

speeds = self.get_material_property( 

0., 0., points, 

parameter='vp' if mode == cake.P else 'vs', 

interpolation='multilinear') 

 

speeds = speeds.reshape((nsources, ndistances)) 

 

receiver_times = [] 

for ireceiver in range(nreceivers): 

nodes = num.hstack([ 

num_full( 

(nodes_sr.shape[0], 1), 

self.coords[0][ireceiver]), 

nodes_sr]) 

 

times = sptree.interpolate_many(nodes) 

 

times[num.isnan(times)] = -1. 

 

times = times.reshape(speeds.shape) 

 

try: 

eikonal_ext.eikonal_solver_fmm_cartesian( 

speeds, times, delta) 

except eikonal_ext.EikonalExtError as e: 

if str(e).endswith('please check results'): 

logger.debug( 

'Got a warning from eikonal solver ' 

'- may be ok...') 

else: 

raise 

 

receiver_times.append(times) 

 

def func(x): 

ias, ibs, ics = \ 

self.grid_interpolation_coefficients(*x) 

 

t = 0 

for ia, va in ias: 

times = receiver_times[ia] 

for ib, vb in ibs: 

for ic, vc in ics: 

t += times[ib, ic] * va * vb * vc 

 

return t 

 

return spit.SPTree( 

f=func, 

ftol=sptree.ftol, 

xbounds=sptree.xbounds, 

xtols=sptree.xtols) 

 

 

class ConfigTypeC(Config): 

''' 

No symmetrical constraints but fixed receiver positions. 

 

* Cartesian 3D source volume around a reference point 

 

* High level index variables: ``(ireceiver, source_depth, 

source_east_shift, source_north_shift, component)`` 

''' 

 

receivers = List.T( 

Receiver.T(), 

help='List of fixed receivers.') 

 

source_origin = Location.T( 

help='Origin of the source volume grid.') 

 

source_depth_min = Float.T( 

help='Minimum source depth [m].') 

 

source_depth_max = Float.T( 

help='Maximum source depth [m].') 

 

source_depth_delta = Float.T( 

help='Source depth grid spacing [m].') 

 

source_east_shift_min = Float.T( 

help='Minimum easting of source grid [m].') 

 

source_east_shift_max = Float.T( 

help='Maximum easting of source grid [m].') 

 

source_east_shift_delta = Float.T( 

help='Source volume grid spacing in east direction [m].') 

 

source_north_shift_min = Float.T( 

help='Minimum northing of source grid [m].') 

 

source_north_shift_max = Float.T( 

help='Maximum northing of source grid [m].') 

 

source_north_shift_delta = Float.T( 

help='Source volume grid spacing in north direction [m].') 

 

short_type = 'C' 

 

provided_schemes = ['elastic18'] 

 

def get_surface_distance(self, args): 

ireceiver, _, source_east_shift, source_north_shift, _ = args 

sorig = self.source_origin 

sloc = Location( 

lat=sorig.lat, 

lon=sorig.lon, 

north_shift=sorig.north_shift + source_north_shift, 

east_shift=sorig.east_shift + source_east_shift) 

 

return self.receivers[args[0]].distance_to(sloc) 

 

def get_distance(self, args): 

# to be improved... 

ireceiver, sdepth, source_east_shift, source_north_shift, _ = args 

sorig = self.source_origin 

sloc = Location( 

lat=sorig.lat, 

lon=sorig.lon, 

north_shift=sorig.north_shift + source_north_shift, 

east_shift=sorig.east_shift + source_east_shift) 

 

return math.sqrt( 

self.receivers[args[0]].distance_to(sloc)**2 + sdepth**2) 

 

def get_source_depth(self, args): 

return args[1] 

 

def get_receiver_depth(self, args): 

return self.receivers[args[0]].depth 

 

def get_source_depths(self): 

return self.coords[0] 

 

def _update(self): 

self.mins = num.array([ 

self.source_depth_min, 

self.source_east_shift_min, 

self.source_north_shift_min], 

dtype=num.float) 

 

self.maxs = num.array([ 

self.source_depth_max, 

self.source_east_shift_max, 

self.source_north_shift_max], 

dtype=num.float) 

 

self.deltas = num.array([ 

self.source_depth_delta, 

self.source_east_shift_delta, 

self.source_north_shift_delta], 

dtype=num.float) 

 

self.ns = num.floor((self.maxs - self.mins) / self.deltas + 

vicinity_eps).astype(num.int) + 1 

self.effective_maxs = self.mins + self.deltas * (self.ns - 1) 

self.deltat = 1.0/self.sample_rate 

self.nreceivers = len(self.receivers) 

self.nrecords = \ 

self.nreceivers * num.product(self.ns) * self.ncomponents 

 

self.coords = (num.arange(self.nreceivers),) + \ 

tuple(num.linspace(mi, ma, n) for (mi, ma, n) in 

zip(self.mins, self.effective_maxs, self.ns)) + \ 

(num.arange(self.ncomponents),) 

self.nreceiver_depths, self.nsource_depths, self.ndistances = self.ns 

 

self._distances_cache = {} 

 

def _make_index_functions(self): 

 

amin, bmin, cmin = self.mins 

da, db, dc = self.deltas 

na, nb, nc = self.ns 

ng = self.ncomponents 

nr = self.nreceivers 

 

def index_function(ir, a, b, c, ig): 

ia = int(round((a - amin) / da)) 

ib = int(round((b - bmin) / db)) 

ic = int(round((c - cmin) / dc)) 

try: 

return num.ravel_multi_index((ir, ia, ib, ic, ig), 

(nr, na, nb, nc, ng)) 

except ValueError: 

raise OutOfBounds() 

 

def indices_function(ir, a, b, c, ig): 

ia = num.round((a - amin) / da).astype(int) 

ib = num.round((b - bmin) / db).astype(int) 

ic = num.round((c - cmin) / dc).astype(int) 

 

try: 

return num.ravel_multi_index((ir, ia, ib, ic, ig), 

(nr, na, nb, nc, ng)) 

except ValueError: 

raise OutOfBounds() 

 

def vicinity_function(ir, a, b, c, ig): 

ias = indi12((a - amin) / da, na) 

ibs = indi12((b - bmin) / db, nb) 

ics = indi12((c - cmin) / dc, nc) 

 

if not (0 <= ir < nr): 

raise OutOfBounds() 

 

if not (0 <= ig < ng): 

raise OutOfBounds() 

 

indis = [] 

weights = [] 

iir = ir*na*nb*nc*ng 

for ia, va in ias: 

iia = ia*nb*nc*ng 

for ib, vb in ibs: 

iib = ib*nc*ng 

for ic, vc in ics: 

indis.append(iir + iia + iib + ic*ng + ig) 

weights.append(va*vb*vc) 

 

return num.array(indis), num.array(weights) 

 

def vicinities_function(ir, a, b, c, ig): 

 

xa = (a-amin) / da 

xb = (b-bmin) / db 

xc = (c-cmin) / dc 

 

xa_fl = num.floor(xa) 

xa_ce = num.ceil(xa) 

xb_fl = num.floor(xb) 

xb_ce = num.ceil(xb) 

xc_fl = num.floor(xc) 

xc_ce = num.ceil(xc) 

va_fl = 1.0 - (xa - xa_fl) 

va_ce = (1.0 - (xa_ce - xa)) * (xa_ce - xa_fl) 

vb_fl = 1.0 - (xb - xb_fl) 

vb_ce = (1.0 - (xb_ce - xb)) * (xb_ce - xb_fl) 

vc_fl = 1.0 - (xc - xc_fl) 

vc_ce = (1.0 - (xc_ce - xc)) * (xc_ce - xc_fl) 

 

ia_fl = xa_fl.astype(num.int) 

ia_ce = xa_ce.astype(num.int) 

ib_fl = xb_fl.astype(num.int) 

ib_ce = xb_ce.astype(num.int) 

ic_fl = xc_fl.astype(num.int) 

ic_ce = xc_ce.astype(num.int) 

 

if num.any(ia_fl < 0) or num.any(ia_fl >= na): 

raise OutOfBounds() 

 

if num.any(ia_ce < 0) or num.any(ia_ce >= na): 

raise OutOfBounds() 

 

if num.any(ib_fl < 0) or num.any(ib_fl >= nb): 

raise OutOfBounds() 

 

if num.any(ib_ce < 0) or num.any(ib_ce >= nb): 

raise OutOfBounds() 

 

if num.any(ic_fl < 0) or num.any(ic_fl >= nc): 

raise OutOfBounds() 

 

if num.any(ic_ce < 0) or num.any(ic_ce >= nc): 

raise OutOfBounds() 

 

irig = ir*na*nb*nc*ng + ig 

 

irecords = num.empty(a.size*8, dtype=num.int) 

irecords[0::8] = ia_fl*nb*nc*ng + ib_fl*nc*ng + ic_fl*ng + irig 

irecords[1::8] = ia_ce*nb*nc*ng + ib_fl*nc*ng + ic_fl*ng + irig 

irecords[2::8] = ia_fl*nb*nc*ng + ib_ce*nc*ng + ic_fl*ng + irig 

irecords[3::8] = ia_ce*nb*nc*ng + ib_ce*nc*ng + ic_fl*ng + irig 

irecords[4::8] = ia_fl*nb*nc*ng + ib_fl*nc*ng + ic_ce*ng + irig 

irecords[5::8] = ia_ce*nb*nc*ng + ib_fl*nc*ng + ic_ce*ng + irig 

irecords[6::8] = ia_fl*nb*nc*ng + ib_ce*nc*ng + ic_ce*ng + irig 

irecords[7::8] = ia_ce*nb*nc*ng + ib_ce*nc*ng + ic_ce*ng + irig 

 

weights = num.empty(a.size*8, dtype=num.float) 

weights[0::8] = va_fl * vb_fl * vc_fl 

weights[1::8] = va_ce * vb_fl * vc_fl 

weights[2::8] = va_fl * vb_ce * vc_fl 

weights[3::8] = va_ce * vb_ce * vc_fl 

weights[4::8] = va_fl * vb_fl * vc_ce 

weights[5::8] = va_ce * vb_fl * vc_ce 

weights[6::8] = va_fl * vb_ce * vc_ce 

weights[7::8] = va_ce * vb_ce * vc_ce 

 

return irecords, weights 

 

self._index_function = index_function 

self._indices_function = indices_function 

self._vicinity_function = vicinity_function 

self._vicinities_function = vicinities_function 

 

def lookup_ireceiver(self, receiver): 

k = (receiver.lat, receiver.lon, 

receiver.north_shift, receiver.east_shift) 

dh = min(self.source_north_shift_delta, self.source_east_shift_delta) 

dv = self.source_depth_delta 

 

for irec, rec in enumerate(self.receivers): 

if (k, irec) not in self._distances_cache: 

self._distances_cache[k, irec] = math.sqrt( 

(receiver.distance_to(rec)/dh)**2 + 

((rec.depth - receiver.depth)/dv)**2) 

 

if self._distances_cache[k, irec] < 0.1: 

return irec 

 

raise OutOfBounds( 

reason='No GFs available for receiver at (%g, %g).' % 

receiver.effective_latlon) 

 

def make_indexing_args(self, source, receiver, icomponents): 

nc = icomponents.size 

 

dists = source.distances_to(self.source_origin) 

azis, _ = source.azibazis_to(self.source_origin) 

 

source_north_shifts = - num.cos(d2r*azis) * dists 

source_east_shifts = - num.sin(d2r*azis) * dists 

source_depths = source.depths - self.source_origin.depth 

 

n = dists.size 

ireceivers = num.empty(nc, dtype=num.int) 

ireceivers.fill(self.lookup_ireceiver(receiver)) 

 

return (ireceivers, 

num.tile(source_depths, nc//n), 

num.tile(source_east_shifts, nc//n), 

num.tile(source_north_shifts, nc//n), 

icomponents) 

 

def make_indexing_args1(self, source, receiver): 

dist = source.distance_to(self.source_origin) 

azi, _ = source.azibazi_to(self.source_origin) 

 

source_north_shift = - num.cos(d2r*azi) * dist 

source_east_shift = - num.sin(d2r*azi) * dist 

source_depth = source.depth - self.source_origin.depth 

 

return (self.lookup_ireceiver(receiver), 

source_depth, 

source_east_shift, 

source_north_shift) 

 

@property 

def short_extent(self): 

return '%g:%g:%g x %g:%g:%g x %g:%g:%g' % ( 

self.source_depth_min/km, 

self.source_depth_max/km, 

self.source_depth_delta/km, 

self.source_east_shift_min/km, 

self.source_east_shift_max/km, 

self.source_east_shift_delta/km, 

self.source_north_shift_min/km, 

self.source_north_shift_max/km, 

self.source_north_shift_delta/km) 

 

 

class Weighting(Object): 

factor = Float.T(default=1.0) 

 

 

class Taper(Object): 

tmin = Timing.T() 

tmax = Timing.T() 

tfade = Float.T(default=0.0) 

shape = StringChoice.T( 

choices=['cos', 'linear'], 

default='cos', 

optional=True) 

 

 

class SimplePattern(SObject): 

 

_pool = {} 

 

def __init__(self, pattern): 

self._pattern = pattern 

SObject.__init__(self) 

 

def __str__(self): 

return self._pattern 

 

@property 

def regex(self): 

pool = SimplePattern._pool 

if self.pattern not in pool: 

rpat = '|'.join(fnmatch.translate(x) for 

x in self.pattern.split('|')) 

pool[self.pattern] = re.compile(rpat, re.I) 

 

return pool[self.pattern] 

 

def match(self, s): 

return self.regex.match(s) 

 

 

class WaveformType(StringChoice): 

choices = ['dis', 'vel', 'acc', 

'amp_spec_dis', 'amp_spec_vel', 'amp_spec_acc', 

'envelope_dis', 'envelope_vel', 'envelope_acc'] 

 

 

class ChannelSelection(Object): 

pattern = SimplePattern.T(optional=True) 

min_sample_rate = Float.T(optional=True) 

max_sample_rate = Float.T(optional=True) 

 

 

class StationSelection(Object): 

includes = SimplePattern.T() 

excludes = SimplePattern.T() 

distance_min = Float.T(optional=True) 

distance_max = Float.T(optional=True) 

azimuth_min = Float.T(optional=True) 

azimuth_max = Float.T(optional=True) 

 

 

class WaveformSelection(Object): 

channel_selection = ChannelSelection.T(optional=True) 

station_selection = StationSelection.T(optional=True) 

taper = Taper.T() 

# filter = FrequencyResponse.T() 

waveform_type = WaveformType.T(default='dis') 

weighting = Weighting.T(optional=True) 

sample_rate = Float.T(optional=True) 

gf_store_id = StringID.T(optional=True) 

 

 

def indi12(x, n): 

''' 

Get linear interpolation index and weight. 

''' 

 

r = round(x) 

if abs(r - x) < vicinity_eps: 

i = int(r) 

if not (0 <= i < n): 

raise OutOfBounds() 

 

return ((int(r), 1.),) 

else: 

f = math.floor(x) 

i = int(f) 

if not (0 <= i < n-1): 

raise OutOfBounds() 

 

v = x-f 

return ((i, 1.-v), (i + 1, v)) 

 

 

def float_or_none(s): 

units = { 

'k': 1e3, 

'M': 1e6, 

} 

 

factor = 1.0 

if s and s[-1] in units: 

factor = units[s[-1]] 

s = s[:-1] 

if not s: 

raise ValueError('unit without a number: \'%s\'' % s) 

 

if s: 

return float(s) * factor 

else: 

return None 

 

 

class GridSpecError(Exception): 

def __init__(self, s): 

Exception.__init__(self, 'invalid grid specification: %s' % s) 

 

 

def parse_grid_spec(spec): 

try: 

result = [] 

for dspec in spec.split(','): 

t = dspec.split('@') 

num = start = stop = step = None 

if len(t) == 2: 

num = int(t[1]) 

if num <= 0: 

raise GridSpecError(spec) 

 

elif len(t) > 2: 

raise GridSpecError(spec) 

 

s = t[0] 

v = [float_or_none(x) for x in s.split(':')] 

if len(v) == 1: 

start = stop = v[0] 

if len(v) >= 2: 

start, stop = v[0:2] 

if len(v) == 3: 

step = v[2] 

 

if len(v) > 3 or (len(v) > 2 and num is not None): 

raise GridSpecError(spec) 

 

if step == 0.0: 

raise GridSpecError(spec) 

 

result.append((start, stop, step, num)) 

 

except ValueError: 

raise GridSpecError(spec) 

 

return result 

 

 

def start_stop_num(start, stop, step, num, mi, ma, inc, eps=1e-5): 

swap = step is not None and step < 0. 

if start is None: 

start = [mi, ma][swap] 

if stop is None: 

stop = [ma, mi][swap] 

if step is None: 

step = [inc, -inc][ma < mi] 

if num is None: 

if (step < 0) != (stop-start < 0): 

raise GridSpecError() 

 

num = int(round((stop-start)/step))+1 

stop2 = start + (num-1)*step 

if abs(stop-stop2) > eps: 

num = int(math.floor((stop-start)/step))+1 

stop = start + (num-1)*step 

else: 

stop = stop2 

 

if start == stop: 

num = 1 

 

return start, stop, num 

 

 

def nditer_outer(x): 

return num.nditer( 

x, op_axes=(num.identity(len(x), dtype=num.int)-1).tolist()) 

 

 

def nodes(xs): 

ns = [x.size for x in xs] 

nnodes = num.prod(ns) 

ndim = len(xs) 

nodes = num.empty((nnodes, ndim), dtype=xs[0].dtype) 

for idim in range(ndim-1, -1, -1): 

x = xs[idim] 

nrepeat = num.prod(ns[idim+1:], dtype=num.int) 

ntile = num.prod(ns[:idim], dtype=num.int) 

nodes[:, idim] = num.repeat(num.tile(x, ntile), nrepeat) 

 

return nodes 

 

 

def filledi(x, n): 

a = num.empty(n, dtype=num.int) 

a.fill(x) 

return a 

 

 

config_type_classes = [ConfigTypeA, ConfigTypeB, ConfigTypeC] 

 

discretized_source_classes = [ 

DiscretizedExplosionSource, 

DiscretizedSFSource, 

DiscretizedMTSource, 

DiscretizedPorePressureSource] 

 

 

__all__ = ''' 

Earthmodel1D 

StringID 

ScopeType 

WaveformType 

QuantityType 

NearfieldTermsType 

Reference 

Region 

CircularRegion 

RectangularRegion 

PhaseSelect 

InvalidTimingSpecification 

Timing 

TPDef 

OutOfBounds 

Location 

Receiver 

'''.split() + [ 

S.__name__ for S in discretized_source_classes + config_type_classes] + ''' 

ComponentScheme 

component_scheme_to_description 

component_schemes 

Config 

GridSpecError 

Weighting 

Taper 

SimplePattern 

WaveformType 

ChannelSelection 

StationSelection 

WaveformSelection 

nditer_outer 

dump 

load 

discretized_source_classes 

config_type_classes 

UnavailableScheme 

InterpolationMethod 

SeismosizerTrace 

SeismosizerResult 

Result 

StaticResult 

'''.split()