├── LICENSE ├── README.md ├── _config.yml ├── focal_mech ├── __init__.py ├── demo │ ├── 3146815_realizations.out │ ├── README.txt │ ├── example1-norev.inp │ ├── example1-noreverse.out │ ├── example1.inp │ ├── example1.out │ ├── images │ │ ├── WR1-2.png │ │ ├── ball_of_yarn.png │ │ ├── beachball.png │ │ ├── class_3145744_norev.png │ │ ├── class_3146815_dc.png │ │ ├── class_3146815_example.png │ │ ├── correlation.png │ │ ├── highlo.png │ │ ├── seismogram-wr1.png │ │ └── svm_schematic.png │ ├── no.reverse │ ├── test2.py │ ├── test3.py │ ├── test4.py │ ├── test5.py │ └── test6.py ├── io │ ├── __init__.py │ └── read_hash.py ├── lib │ ├── __init__.py │ ├── classify_mechanism.py │ ├── correlate.py │ └── sph_harm.py └── util │ ├── __init__.py │ └── hash_routines.py └── setup.py /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Ben Lasscock 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | FocalMechClassifier 2 | =================== 3 | 4 | For reproducibility, we demo the code using the dataset provide 5 | with the USGS HASH code, http://earthquake.usgs.gov/research/software/index.php. 6 | 7 | Download the hash.v1.2.tar.gz, unpack it and copy the north1.phase 8 | and scsn.reverse datafiles into the "demo" directory of this project. 9 | This will be the inputs to the demo test[2-6].py, run these from the 10 | demo directory. 11 | 12 | You'll also need to compile the hash_driver1 exe is you want to run 13 | it. You can use this to regenerate the example1.inp, example1-norev.inp 14 | data. Do, 15 | 16 | cat test1.out | sed -e s/*//" > example1.out 17 | 18 | this removes the extra column that messes up genfromtxt. 19 | 20 | We provide the input file example1.inp, example1-norev.inp input 21 | parameters. And also data derived from them, 3146815_realizations.out, 22 | example1.out and example1-noreverse.out. You can regenerate these using 23 | the inputs provided. 24 | 25 | If you get "LookupError: unknown encoding: " errors from ObsPy, set these environment variables: 26 | 27 | export LC_ALL=en_US.UTF-8 28 | 29 | export LANG=en_US.UTF-8 30 | 31 | This seemed to effect OSX: El Capitan. 32 | -------------------------------------------------------------------------------- /_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-slate -------------------------------------------------------------------------------- /focal_mech/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/blasscoc/FocalMechClassifier/8d54d5a19cea447c030ada596369e47e7f39d483/focal_mech/__init__.py -------------------------------------------------------------------------------- /focal_mech/demo/3146815_realizations.out: -------------------------------------------------------------------------------- 1 | 120.00 30.00 135.00 0.4330 0.2500 0.8660 -0.8839 0.3062 0.3536 2 | 130.65 60.00 150.00 0.6571 0.5641 0.5000 -0.7538 0.4943 0.4330 3 | 144.92 55.00 115.00 0.4708 0.6703 0.5736 -0.6446 -0.1825 0.7424 4 | 125.12 35.00 110.00 0.4691 0.3300 0.8192 -0.8264 -0.1631 0.5390 5 | 139.85 65.00 145.00 0.5844 0.6927 0.4226 -0.7824 0.3430 0.5198 6 | 118.80 20.00 130.00 0.2997 0.1648 0.9397 -0.9405 0.2165 0.2620 7 | 66.00 25.00 110.00 0.3861 -0.1719 0.9063 -0.6389 0.6588 0.3971 8 | 116.34 35.00 125.00 0.5140 0.2545 0.8192 -0.8558 0.2163 0.4698 9 | 104.12 45.00 120.00 0.6858 0.1725 0.7071 -0.7158 0.3355 0.6124 10 | 153.87 60.00 135.00 0.3814 0.7775 0.5000 -0.7905 -0.0060 0.6124 11 | 124.84 60.00 140.00 0.7108 0.4947 0.5000 -0.7014 0.4451 0.5567 12 | 157.12 55.00 160.00 0.3185 0.7547 0.5736 -0.9420 0.1846 0.2802 13 | 319.09 50.00 105.00 -0.5017 -0.5789 0.6428 0.6022 0.2997 0.7399 14 | 316.96 40.00 110.00 -0.4387 -0.4698 0.7660 0.7413 0.2926 0.6040 15 | 150.00 30.00 120.00 0.2500 0.4330 0.8660 -0.8080 -0.3995 0.4330 16 | 129.13 40.00 120.00 0.4986 0.4057 0.7660 -0.8302 -0.0308 0.5567 17 | 90.00 35.00 110.00 0.5736 0.0000 0.8192 -0.7698 0.3420 0.5390 18 | 151.46 35.00 165.00 0.2740 0.5039 0.8192 -0.9499 0.2752 0.1485 19 | 157.12 55.00 130.00 0.3185 0.7547 0.5736 -0.7631 -0.1549 0.6275 20 | 139.41 45.00 150.00 0.4601 0.5370 0.7071 -0.8877 0.2950 0.3536 21 | 156.46 65.00 120.00 0.3619 0.8309 0.4226 -0.6046 -0.1359 0.7849 22 | 319.09 50.00 115.00 -0.5017 -0.5789 0.6428 0.7009 0.1635 0.6943 23 | 301.30 40.00 105.00 -0.5492 -0.3340 0.7660 0.7667 0.1633 0.6209 24 | 160.59 45.00 155.00 0.2350 0.6669 0.7071 -0.9541 0.0194 0.2988 25 | 309.66 55.00 115.00 -0.6306 -0.5228 0.5736 0.6699 0.0064 0.7424 26 | 128.77 65.00 105.00 0.7066 0.5675 0.4226 -0.4803 -0.0538 0.8754 27 | 159.68 60.00 135.00 0.3008 0.8121 0.5000 -0.7859 -0.0860 0.6124 28 | 121.30 40.00 115.00 0.5492 0.3340 0.7660 -0.8128 0.0004 0.5826 29 | 105.65 40.00 115.00 0.6190 0.1734 0.7660 -0.7825 0.2196 0.5826 30 | 90.00 35.00 105.00 0.5736 0.0000 0.8192 -0.7912 0.2588 0.5540 31 | 148.91 50.00 120.00 0.3956 0.6560 0.6428 -0.7156 -0.2185 0.6634 32 | 126.00 25.00 140.00 0.3419 0.2484 0.9063 -0.9216 0.2773 0.2717 33 | 150.85 80.00 110.00 0.4798 0.8600 0.1736 -0.3782 0.0241 0.9254 34 | 142.26 60.00 160.00 0.5301 0.6848 0.5000 -0.8478 0.4400 0.2962 35 | 120.00 30.00 140.00 0.4330 0.2500 0.8660 -0.8651 0.3851 0.3214 36 | 170.00 30.00 165.00 0.0868 0.4924 0.8660 -0.9902 -0.0530 0.1294 37 | 153.53 45.00 155.00 0.3152 0.6330 0.7071 -0.9445 0.1365 0.2988 38 | 153.87 60.00 170.00 0.3814 0.7775 0.5000 -0.9224 0.3558 0.1504 39 | 133.90 35.00 100.00 0.4133 0.3977 0.8192 -0.7017 -0.4343 0.5649 40 | 160.59 45.00 175.00 0.2350 0.6669 0.7071 -0.9600 0.2730 0.0616 41 | 133.20 20.00 125.00 0.2493 0.2341 0.9397 -0.9538 -0.1088 0.2802 42 | 137.65 70.00 115.00 0.6331 0.6944 0.3420 -0.5211 0.0556 0.8517 43 | 90.00 30.00 110.00 0.5000 0.0000 0.8660 -0.8138 0.3420 0.4698 44 | 105.65 40.00 105.00 0.6190 0.1734 0.7660 -0.7823 0.0496 0.6209 45 | 122.73 50.00 150.00 0.6444 0.4142 0.6428 -0.7386 0.5548 0.3830 46 | 97.83 40.00 120.00 0.6368 0.0875 0.7660 -0.7253 0.4050 0.5567 47 | 142.68 35.00 160.00 0.3477 0.4562 0.8192 -0.9172 0.3469 0.1962 48 | 118.24 45.00 95.00 0.6230 0.3345 0.7071 -0.6618 -0.2565 0.7044 49 | 133.90 35.00 130.00 0.4133 0.3977 0.8192 -0.8979 0.0280 0.4394 50 | 137.65 70.00 120.00 0.6331 0.6944 0.3420 -0.5691 0.1180 0.8138 51 | 148.06 60.00 155.00 0.4581 0.7349 0.5000 -0.8809 0.3001 0.3660 52 | 132.71 55.00 155.00 0.6019 0.5556 0.5736 -0.7929 0.5015 0.3462 53 | 312.55 50.00 105.00 -0.5644 -0.5180 0.6428 0.6324 0.2291 0.7399 54 | 97.06 45.00 115.00 0.7017 0.0869 0.7071 -0.6879 0.3407 0.6409 55 | 306.00 65.00 105.00 -0.7332 -0.5327 0.4226 0.4824 0.0306 0.8754 56 | 125.12 35.00 130.00 0.4691 0.3300 0.8192 -0.8831 0.1647 0.4394 57 | 110.00 30.00 135.00 0.4698 0.1710 0.8660 -0.8173 0.4550 0.3536 58 | 159.68 60.00 145.00 0.3008 0.8121 0.5000 -0.8678 0.0156 0.4967 59 | 303.56 55.00 100.00 -0.6826 -0.4528 0.5736 0.5667 0.1676 0.8067 60 | 104.40 20.00 105.00 0.3313 0.0851 0.9397 -0.9435 0.0250 0.3304 61 | 136.45 60.00 100.00 0.5967 0.6277 0.5000 -0.4651 -0.2373 0.8529 62 | 162.00 65.00 140.00 0.2801 0.8619 0.4226 -0.8125 -0.0216 0.5826 63 | 151.02 55.00 150.00 0.3969 0.7166 0.5736 -0.8965 0.1688 0.4096 64 | 309.13 40.00 110.00 -0.4986 -0.4057 0.7660 0.7742 0.1890 0.6040 65 | 125.29 45.00 145.00 0.5771 0.4085 0.7071 -0.8043 0.4343 0.4056 66 | 142.68 35.00 155.00 0.3477 0.4562 0.8192 -0.9306 0.2741 0.2424 67 | 160.43 40.00 155.00 0.2153 0.6057 0.7660 -0.9624 -0.0015 0.2717 68 | 104.40 20.00 110.00 0.3313 0.0851 0.9397 -0.9403 0.1117 0.3214 69 | 328.15 65.00 110.00 -0.4782 -0.7699 0.4226 0.5001 0.1569 0.8517 70 | 159.68 60.00 175.00 0.3008 0.8121 0.5000 -0.9493 0.3051 0.0755 71 | 132.35 45.00 145.00 0.5226 0.4764 0.7071 -0.8516 0.3321 0.4056 72 | 130.65 60.00 140.00 0.6571 0.5641 0.5000 -0.7428 0.3719 0.5567 73 | 128.77 65.00 120.00 0.7066 0.5675 0.4226 -0.5985 0.1607 0.7849 74 | 150.92 65.00 100.00 0.4405 0.7921 0.4226 -0.3540 -0.2794 0.8925 75 | 120.00 30.00 95.00 0.4330 0.2500 0.8660 -0.7907 -0.3559 0.4981 76 | 301.30 40.00 95.00 -0.5492 -0.3340 0.7660 0.6973 0.3220 0.6403 77 | 148.24 70.00 110.00 0.4947 0.7989 0.3420 -0.4600 -0.0932 0.8830 78 | 104.12 45.00 110.00 0.6858 0.1725 0.7071 -0.7278 0.1696 0.6645 79 | 316.96 40.00 105.00 -0.4387 -0.4698 0.7660 0.6942 0.3641 0.6209 80 | 126.00 25.00 95.00 0.3419 0.2484 0.9063 -0.7817 -0.4602 0.4210 81 | 306.00 50.00 105.00 -0.6197 -0.4503 0.6428 0.6544 0.1556 0.7399 82 | 153.87 60.00 155.00 0.3814 0.7775 0.5000 -0.9067 0.2094 0.3660 83 | 134.31 65.00 110.00 0.6486 0.6331 0.4226 -0.5231 -0.0327 0.8517 84 | 129.27 50.00 145.00 0.5930 0.4849 0.6428 -0.8040 0.4008 0.4394 85 | 322.26 60.00 125.00 -0.5301 -0.6848 0.5000 0.7043 -0.0272 0.7094 86 | 144.92 55.00 150.00 0.4708 0.6703 0.5736 -0.8735 0.2631 0.4096 87 | 160.59 45.00 165.00 0.2350 0.6669 0.7071 -0.9718 0.1484 0.1830 88 | 316.96 40.00 100.00 -0.4387 -0.4698 0.7660 0.6418 0.4328 0.6330 89 | 316.96 40.00 120.00 -0.4387 -0.4698 0.7660 0.8182 0.1436 0.5567 90 | 121.30 40.00 120.00 0.5492 0.3340 0.7660 -0.8266 0.0825 0.5567 91 | 132.35 70.00 140.00 0.6944 0.6331 0.3420 -0.6785 0.4180 0.6040 92 | 132.71 55.00 95.00 0.6019 0.5556 0.5736 -0.4790 -0.3235 0.8160 93 | 136.45 60.00 120.00 0.5967 0.6277 0.5000 -0.6607 0.0306 0.7500 94 | 160.00 30.00 170.00 0.1710 0.4698 0.8660 -0.9769 0.1955 0.0868 95 | 153.87 60.00 150.00 0.3814 0.7775 0.5000 -0.8876 0.1569 0.4330 96 | 309.51 35.00 95.00 -0.4425 -0.3649 0.8192 0.6850 0.4520 0.5714 97 | 126.61 55.00 110.00 0.6575 0.4885 0.5736 -0.6366 -0.0469 0.7698 98 | 139.85 65.00 110.00 0.5844 0.6927 0.4226 -0.5175 -0.0830 0.8517 99 | 144.78 40.00 125.00 0.3707 0.5251 0.7660 -0.8305 -0.1819 0.5265 100 | 126.61 55.00 135.00 0.6575 0.4885 0.5736 -0.7473 0.3257 0.5792 101 | 120.00 30.00 120.00 0.4330 0.2500 0.8660 -0.8995 0.0580 0.4330 102 | 118.24 45.00 135.00 0.6230 0.3345 0.7071 -0.7750 0.3864 0.5000 103 | 130.00 30.00 140.00 0.3830 0.3214 0.8660 -0.9188 0.2290 0.3214 104 | 97.83 40.00 95.00 0.6368 0.0875 0.7660 -0.7679 -0.0176 0.6403 105 | 125.12 35.00 100.00 0.4691 0.3300 0.8192 -0.7597 -0.3221 0.5649 106 | 142.26 60.00 155.00 0.5301 0.6848 0.5000 -0.8460 0.3877 0.3660 107 | 114.00 25.00 95.00 0.3861 0.1719 0.9063 -0.8603 -0.2876 0.4210 108 | 315.88 45.00 120.00 -0.4922 -0.5076 0.7071 0.7852 0.0916 0.6124 109 | 164.12 70.00 140.00 0.2572 0.9038 0.3420 -0.7970 -0.0018 0.6040 110 | 160.24 35.00 160.00 0.1939 0.5398 0.8192 -0.9791 0.0540 0.1962 111 | 169.32 55.00 165.00 0.1518 0.8050 0.5736 -0.9767 0.0331 0.2120 112 | 138.00 25.00 155.00 0.2828 0.3141 0.9063 -0.9298 0.3218 0.1786 113 | 150.00 30.00 145.00 0.2500 0.4330 0.8660 -0.9578 -0.0206 0.2868 114 | 110.00 30.00 100.00 0.4698 0.1710 0.8660 -0.8608 -0.1285 0.4924 115 | 304.84 60.00 105.00 -0.7108 -0.4947 0.5000 0.5443 0.0635 0.8365 116 | 148.24 70.00 100.00 0.4947 0.7989 0.3420 -0.3250 -0.1950 0.9254 117 | 162.00 20.00 165.00 0.1057 0.3253 0.9397 -0.9938 0.0672 0.0885 118 | 102.00 25.00 110.00 0.4134 0.0879 0.9063 -0.9042 0.1575 0.3971 119 | 128.77 65.00 130.00 0.7066 0.5675 0.4226 -0.6549 0.2984 0.6943 120 | 140.00 30.00 155.00 0.3214 0.3830 0.8660 -0.9295 0.3022 0.2113 121 | 165.48 60.00 140.00 0.2171 0.8384 0.5000 -0.8221 -0.1191 0.5567 122 | 151.46 35.00 145.00 0.2740 0.5039 0.8192 -0.9441 -0.0214 0.3290 123 | 132.35 45.00 110.00 0.5226 0.4764 0.7071 -0.7215 -0.1949 0.6645 124 | 120.51 55.00 125.00 0.7057 0.4159 0.5736 -0.6960 0.2556 0.6710 125 | 151.02 55.00 145.00 0.3969 0.7166 0.5736 -0.8760 0.1091 0.4698 126 | 61.20 20.00 105.00 0.2997 -0.1648 0.9397 -0.6707 0.6641 0.3304 127 | 151.71 75.00 115.00 0.4577 0.8506 0.2588 -0.4833 -0.0063 0.8754 128 | 310.65 60.00 105.00 -0.6571 -0.5641 0.5000 0.5350 0.1182 0.8365 129 | 139.41 45.00 100.00 0.4601 0.5370 0.7071 -0.5849 -0.4158 0.6964 130 | 133.20 20.00 135.00 0.2493 0.2341 0.9397 -0.9684 0.0606 0.2418 131 | 90.00 30.00 100.00 0.5000 0.0000 0.8660 -0.8529 0.1736 0.4924 132 | 136.29 75.00 110.00 0.6675 0.6982 0.2588 -0.4153 0.0606 0.9077 133 | 150.92 65.00 165.00 0.4405 0.7921 0.4226 -0.8973 0.3738 0.2346 134 | 160.24 35.00 140.00 0.1939 0.5398 0.8192 -0.8989 -0.2366 0.3687 135 | 119.03 60.00 105.00 0.7572 0.4203 0.5000 -0.5479 -0.0081 0.8365 136 | 108.31 55.00 95.00 0.7777 0.2573 0.5736 -0.5699 -0.0967 0.8160 137 | 142.68 35.00 110.00 0.3477 0.4562 0.8192 -0.7386 -0.4048 0.5390 138 | 151.46 35.00 140.00 0.2740 0.5039 0.8192 -0.9245 -0.0966 0.3687 139 | 108.95 15.00 120.00 0.2448 0.0840 0.9659 -0.9535 0.2013 0.2241 140 | 167.65 45.00 150.00 0.1513 0.6907 0.7071 -0.9216 -0.1601 0.3536 141 | 139.41 45.00 120.00 0.4601 0.5370 0.7071 -0.7781 -0.1397 0.6124 142 | 142.94 70.00 130.00 0.5663 0.7499 0.3420 -0.6708 0.1783 0.7198 143 | 135.82 50.00 95.00 0.5339 0.5494 0.6428 -0.5088 -0.3985 0.7631 144 | 118.24 45.00 120.00 0.6230 0.3345 0.7071 -0.7761 0.1508 0.6124 145 | 145.38 65.00 145.00 0.5148 0.7459 0.4226 -0.8119 0.2658 0.5198 146 | 159.68 60.00 125.00 0.3008 0.8121 0.5000 -0.6801 -0.1849 0.7094 147 | 126.61 55.00 125.00 0.6575 0.4885 0.5736 -0.7192 0.1802 0.6710 148 | 160.43 40.00 150.00 0.2153 0.6057 0.7660 -0.9443 -0.0709 0.3214 149 | 132.71 55.00 110.00 0.6019 0.5556 0.5736 -0.6280 -0.1143 0.7698 150 | 151.02 55.00 155.00 0.3969 0.7166 0.5736 -0.9103 0.2271 0.3462 151 | 144.92 55.00 140.00 0.4708 0.6703 0.5736 -0.8388 0.1386 0.5265 152 | 97.83 40.00 110.00 0.6368 0.0875 0.7660 -0.7597 0.2408 0.6040 153 | 118.80 20.00 110.00 0.2997 0.1648 0.9397 -0.9386 -0.1257 0.3214 154 | 151.71 75.00 110.00 0.4577 0.8506 0.2588 -0.4164 -0.0521 0.9077 155 | 133.90 35.00 135.00 0.4133 0.3977 0.8192 -0.9077 0.1078 0.4056 156 | 168.55 50.00 140.00 0.1521 0.7508 0.6428 -0.8328 -0.2528 0.4924 157 | 118.24 45.00 115.00 0.6230 0.3345 0.7071 -0.7645 0.0691 0.6409 158 | 110.00 30.00 95.00 0.4698 0.1710 0.8660 -0.8405 -0.2132 0.4981 159 | 167.65 45.00 140.00 0.1513 0.6907 0.7071 -0.8455 -0.2801 0.4545 160 | 130.00 30.00 110.00 0.3830 0.3214 0.8660 -0.8433 -0.2611 0.4698 161 | 332.18 50.00 125.00 -0.3575 -0.6775 0.6428 0.7530 0.1980 0.6275 162 | 155.45 50.00 135.00 0.3182 0.6968 0.6428 -0.8320 -0.1197 0.5417 163 | 122.73 50.00 140.00 0.6444 0.4142 0.6428 -0.7617 0.4211 0.4924 164 | 162.00 25.00 155.00 0.1306 0.4019 0.9063 -0.9803 -0.0842 0.1786 165 | 136.96 40.00 150.00 0.4387 0.4698 0.7660 -0.8944 0.3112 0.3214 166 | 134.31 65.00 125.00 0.6486 0.6331 0.4226 -0.6484 0.1686 0.7424 167 | 328.15 65.00 120.00 -0.4782 -0.7699 0.4226 0.6178 0.0471 0.7849 168 | 128.77 65.00 155.00 0.7066 0.5675 0.4226 -0.7068 0.5948 0.3830 169 | 296.47 70.00 95.00 -0.8412 -0.4189 0.3420 0.3438 0.0739 0.9361 170 | 316.45 60.00 120.00 -0.5967 -0.6277 0.5000 0.6607 -0.0306 0.7500 171 | 165.48 60.00 160.00 0.2171 0.8384 0.5000 -0.9526 0.0700 0.2962 172 | 134.31 65.00 135.00 0.6486 0.6331 0.4226 -0.7078 0.2973 0.6409 173 | 167.65 45.00 145.00 0.1513 0.6907 0.7071 -0.8870 -0.2209 0.4056 174 | 144.92 55.00 155.00 0.4708 0.6703 0.5736 -0.8810 0.3226 0.3462 175 | 291.36 55.00 100.00 -0.7629 -0.2983 0.5736 0.5893 0.0440 0.8067 176 | 316.45 60.00 105.00 -0.5967 -0.6277 0.5000 0.5203 0.1717 0.8365 177 | 103.09 50.00 100.00 0.7461 0.1735 0.6428 -0.6559 0.0258 0.7544 178 | 125.12 35.00 155.00 0.4691 0.3300 0.8192 -0.8046 0.5421 0.2424 179 | 132.35 45.00 95.00 0.5226 0.4764 0.7071 -0.5793 -0.4102 0.7044 180 | 142.94 70.00 145.00 0.5663 0.7499 0.3420 -0.7719 0.3371 0.5390 181 | 322.94 45.00 105.00 -0.4261 -0.5643 0.7071 0.6181 0.3891 0.6830 182 | 118.24 45.00 105.00 0.6230 0.3345 0.7071 -0.7242 -0.0951 0.6830 183 | 142.36 50.00 150.00 0.4678 0.6066 0.6428 -0.8821 0.2743 0.3830 184 | 162.00 65.00 110.00 0.2801 0.8619 0.4226 -0.4480 -0.2720 0.8517 185 | 151.71 75.00 120.00 0.4577 0.8506 0.2588 -0.5465 0.0396 0.8365 186 | 130.00 30.00 115.00 0.3830 0.3214 0.8660 -0.8729 -0.1808 0.4532 187 | 308.82 45.00 95.00 -0.5509 -0.4433 0.7071 0.6034 0.3737 0.7044 188 | 169.32 55.00 135.00 0.1518 0.8050 0.5736 -0.7700 -0.2675 0.5792 189 | 121.30 40.00 135.00 0.5492 0.3340 0.7660 -0.8302 0.3227 0.4545 190 | 139.41 45.00 125.00 0.4601 0.5370 0.7071 -0.8124 -0.0667 0.5792 191 | 136.45 60.00 150.00 0.5967 0.6277 0.5000 -0.7999 0.4155 0.4330 192 | 136.96 40.00 120.00 0.4387 0.4698 0.7660 -0.8182 -0.1436 0.5567 193 | 116.34 35.00 95.00 0.5140 0.2545 0.8192 -0.7700 -0.2840 0.5714 194 | 310.65 60.00 100.00 -0.6571 -0.5641 0.5000 0.4867 0.1890 0.8529 195 | 113.48 40.00 100.00 0.5896 0.2561 0.7660 -0.7611 -0.1413 0.6330 196 | 119.03 60.00 100.00 0.7572 0.4203 0.5000 -0.5148 -0.0871 0.8529 197 | 139.41 45.00 130.00 0.4601 0.5370 0.7071 -0.8406 0.0069 0.5417 198 | 159.68 60.00 180.00 0.3008 0.8121 0.5000 -0.9378 0.3473 0.0000 199 | 124.84 60.00 125.00 0.7108 0.4947 0.5000 -0.6638 0.2368 0.7094 200 | 312.55 50.00 100.00 -0.5644 -0.5180 0.6428 0.5838 0.3001 0.7544 201 | 138.81 55.00 130.00 0.5394 0.6165 0.5736 -0.7731 0.0926 0.6275 202 | 165.48 60.00 155.00 0.2171 0.8384 0.5000 -0.9303 0.0226 0.3660 203 | 108.95 15.00 125.00 0.2448 0.0840 0.9659 -0.9346 0.2856 0.2120 204 | 138.81 55.00 160.00 0.5394 0.6165 0.5736 -0.8364 0.4712 0.2802 205 | 109.64 50.00 105.00 0.7215 0.2574 0.6428 -0.6718 0.0351 0.7399 206 | 129.27 50.00 155.00 0.5930 0.4849 0.6428 -0.7840 0.5297 0.3237 207 | 148.91 50.00 145.00 0.3956 0.6560 0.6428 -0.8919 0.1073 0.4394 208 | 152.61 40.00 170.00 0.2957 0.5707 0.7660 -0.9356 0.3350 0.1116 209 | 145.38 65.00 155.00 0.5148 0.7459 0.4226 -0.8473 0.3679 0.3830 210 | 125.29 45.00 115.00 0.5771 0.4085 0.7071 -0.7672 -0.0253 0.6409 211 | 139.85 65.00 160.00 0.5844 0.6927 0.4226 -0.8114 0.4955 0.3100 212 | 90.00 25.00 100.00 0.4226 0.0000 0.9063 -0.8925 0.1736 0.4162 213 | 308.82 45.00 105.00 -0.5509 -0.4433 0.7071 0.6944 0.2266 0.6830 214 | 148.06 60.00 145.00 0.4581 0.7349 0.5000 -0.8469 0.1899 0.4967 215 | 129.13 40.00 115.00 0.4986 0.4057 0.7660 -0.8053 -0.1103 0.5826 216 | 158.82 70.00 115.00 0.3395 0.8762 0.3420 -0.5061 -0.1364 0.8517 217 | 155.92 80.00 125.00 0.4019 0.8991 0.1736 -0.5817 0.1042 0.8067 218 | 136.45 60.00 140.00 0.5967 0.6277 0.5000 -0.7767 0.2948 0.5567 219 | 316.96 40.00 115.00 -0.4387 -0.4698 0.7660 0.7827 0.2189 0.5826 220 | 159.68 60.00 110.00 0.3008 0.8121 0.5000 -0.4839 -0.3218 0.8138 221 | 125.12 35.00 125.00 0.4691 0.3300 0.8192 -0.8788 0.0831 0.4698 222 | 120.51 55.00 115.00 0.7057 0.4159 0.5736 -0.6624 0.1002 0.7424 223 | 125.12 35.00 105.00 0.4691 0.3300 0.8192 -0.7961 -0.2435 0.5540 224 | 312.55 50.00 110.00 -0.5644 -0.5180 0.6428 0.6763 0.1564 0.7198 225 | 142.36 50.00 170.00 0.4678 0.6066 0.6428 -0.8480 0.5130 0.1330 226 | 136.45 60.00 105.00 0.5967 0.6277 0.5000 -0.5203 -0.1717 0.8365 227 | 156.86 75.00 125.00 0.3796 0.8882 0.2588 -0.6107 0.0305 0.7912 228 | 162.00 50.00 125.00 0.2367 0.7286 0.6428 -0.7082 -0.3235 0.6275 229 | 140.00 30.00 120.00 0.3214 0.3830 0.8660 -0.8651 -0.2531 0.4330 230 | 90.00 30.00 105.00 0.5000 0.0000 0.8660 -0.8365 0.2588 0.4830 231 | 142.36 50.00 110.00 0.4678 0.6066 0.6428 -0.6397 -0.2695 0.7198 232 | 300.73 35.00 105.00 -0.4930 -0.2931 0.8192 0.8124 0.1819 0.5540 233 | 306.00 50.00 110.00 -0.6197 -0.4503 0.6428 0.6897 0.0783 0.7198 234 | 160.43 40.00 135.00 0.2153 0.6057 0.7660 -0.8477 -0.2736 0.4545 235 | 163.22 55.00 155.00 0.2365 0.7843 0.5736 -0.9377 0.0296 0.3462 236 | 114.00 25.00 105.00 0.3861 0.1719 0.9063 -0.9050 -0.1196 0.4082 237 | 134.31 65.00 105.00 0.6486 0.6331 0.4226 -0.4729 -0.0999 0.8754 238 | 150.92 65.00 110.00 0.4405 0.7921 0.4226 -0.4919 -0.1809 0.8517 239 | 140.00 30.00 130.00 0.3214 0.3830 0.8660 -0.9188 -0.0950 0.3830 240 | 136.45 60.00 125.00 0.5967 0.6277 0.5000 -0.6979 0.0983 0.7094 241 | 151.02 55.00 105.00 0.3969 0.7166 0.5736 -0.4949 -0.3592 0.7912 242 | 139.41 45.00 165.00 0.4601 0.5370 0.7071 -0.8526 0.4895 0.1830 243 | 325.64 50.00 110.00 -0.4324 -0.6323 0.6428 0.6233 0.3056 0.7198 244 | 168.55 50.00 170.00 0.1521 0.7508 0.6428 -0.9874 0.0862 0.1330 245 | 129.27 50.00 140.00 0.5930 0.4849 0.6428 -0.8048 0.3315 0.4924 246 | 126.61 55.00 95.00 0.6575 0.4885 0.5736 -0.5106 -0.2708 0.8160 247 | 137.65 70.00 140.00 0.6331 0.6944 0.3420 -0.7142 0.3536 0.6040 248 | 126.61 55.00 100.00 0.6575 0.4885 0.5736 -0.5570 -0.1975 0.8067 249 | 90.00 40.00 95.00 0.6428 0.0000 0.7660 -0.7631 0.0872 0.6403 250 | 147.60 20.00 150.00 0.1833 0.2888 0.9397 -0.9830 0.0673 0.1710 251 | 132.71 55.00 130.00 0.6019 0.5556 0.5736 -0.7589 0.1743 0.6275 252 | 118.80 20.00 120.00 0.2997 0.1648 0.9397 -0.9540 0.0461 0.2962 253 | 98.78 35.00 125.00 0.5669 0.0876 0.8192 -0.7507 0.4644 0.4698 254 | 126.61 55.00 120.00 0.6575 0.4885 0.5736 -0.6969 0.1051 0.7094 255 | 153.53 45.00 165.00 0.3152 0.6330 0.7071 -0.9462 0.2667 0.1830 256 | 299.45 50.00 105.00 -0.6670 -0.3767 0.6428 0.6679 0.0799 0.7399 257 | 111.18 45.00 130.00 0.6594 0.2554 0.7071 -0.7373 0.4037 0.5417 258 | 138.00 25.00 125.00 0.2828 0.3141 0.9063 -0.9230 -0.1679 0.3462 259 | 325.64 50.00 125.00 -0.4324 -0.6323 0.6428 0.7707 0.1109 0.6275 260 | 146.47 45.00 140.00 0.3906 0.5894 0.7071 -0.8896 0.0442 0.4545 261 | 100.00 30.00 110.00 0.4924 0.0868 0.8660 -0.8608 0.1955 0.4698 262 | 152.61 40.00 125.00 0.2957 0.5707 0.7660 -0.7980 -0.2933 0.5265 263 | 169.32 55.00 160.00 0.1518 0.8050 0.5736 -0.9598 -0.0187 0.2802 264 | 279.82 50.00 95.00 -0.7548 -0.1306 0.6428 0.6458 0.0233 0.7631 265 | 150.92 65.00 135.00 0.4405 0.7921 0.4226 -0.7632 0.0825 0.6409 266 | 148.91 50.00 130.00 0.3956 0.6560 0.6428 -0.8047 -0.0897 0.5868 267 | 116.18 50.00 130.00 0.6874 0.3380 0.6428 -0.7255 0.3596 0.5868 268 | 100.00 30.00 115.00 0.4924 0.0868 0.8660 -0.8463 0.2799 0.4532 269 | 162.00 75.00 140.00 0.2985 0.9187 0.2588 -0.7800 0.0785 0.6209 270 | 162.00 50.00 160.00 0.2367 0.7286 0.6428 -0.9616 0.0813 0.2620 271 | 303.56 55.00 95.00 -0.6826 -0.4528 0.5736 0.5243 0.2432 0.8160 272 | 120.00 30.00 110.00 0.4330 0.2500 0.8660 -0.8758 -0.1107 0.4698 273 | 116.18 50.00 135.00 0.6874 0.3380 0.6428 -0.7199 0.4340 0.5417 274 | 102.00 25.00 115.00 0.4134 0.0879 0.9063 -0.8913 0.2426 0.3830 275 | 167.65 45.00 165.00 0.1513 0.6907 0.7071 -0.9827 0.0279 0.1830 276 | 127.06 70.00 110.00 0.7499 0.5663 0.3420 -0.4626 0.0793 0.8830 277 | 160.59 45.00 140.00 0.2350 0.6669 0.7071 -0.8736 -0.1741 0.4545 278 | 145.38 65.00 150.00 0.5148 0.7459 0.4226 -0.8328 0.3181 0.4532 279 | 150.85 80.00 120.00 0.4798 0.8600 0.1736 -0.5099 0.1123 0.8529 280 | 120.00 30.00 130.00 0.4330 0.2500 0.8660 -0.8959 0.2250 0.3830 281 | 116.34 35.00 110.00 0.5140 0.2545 0.8192 -0.8416 -0.0350 0.5390 282 | 157.12 55.00 170.00 0.3185 0.7547 0.5736 -0.9460 0.2912 0.1422 283 | 151.02 55.00 140.00 0.3969 0.7166 0.5736 -0.8488 0.0487 0.5265 284 | 136.29 75.00 115.00 0.6675 0.6982 0.2588 -0.4676 0.1225 0.8754 285 | 308.82 45.00 100.00 -0.5509 -0.4433 0.7071 0.6514 0.3013 0.6964 286 | 160.00 30.00 160.00 0.1710 0.4698 0.8660 -0.9843 0.0431 0.1710 287 | 130.00 30.00 105.00 0.3830 0.3214 0.8660 -0.8072 -0.3394 0.4830 288 | 121.30 40.00 110.00 0.5492 0.3340 0.7660 -0.7928 -0.0818 0.6040 289 | 136.29 75.00 125.00 0.6675 0.6982 0.2588 -0.5611 0.2431 0.7912 290 | 120.51 55.00 130.00 0.7057 0.4159 0.5736 -0.7049 0.3307 0.6275 291 | 139.85 65.00 125.00 0.5844 0.6927 0.4226 -0.6616 0.1053 0.7424 292 | 102.00 25.00 95.00 0.4134 0.0879 0.9063 -0.9013 -0.1025 0.4210 293 | 137.65 70.00 135.00 0.6331 0.6944 0.3420 -0.6855 0.2976 0.6645 294 | 153.53 70.00 130.00 0.4189 0.8412 0.3420 -0.6922 0.0520 0.7198 295 | 322.94 45.00 110.00 -0.4261 -0.5643 0.7071 0.6734 0.3241 0.6645 296 | 315.88 45.00 115.00 -0.4922 -0.5076 0.7071 0.7495 0.1659 0.6409 297 | 153.53 45.00 120.00 0.3152 0.6330 0.7071 -0.7205 -0.3253 0.6124 298 | 145.38 65.00 105.00 0.5148 0.7459 0.4226 -0.4449 -0.1889 0.8754 299 | 125.29 45.00 130.00 0.5771 0.4085 0.7071 -0.8135 0.2117 0.5417 300 | 142.26 60.00 105.00 0.5301 0.6848 0.5000 -0.5003 -0.2235 0.8365 301 | -------------------------------------------------------------------------------- /focal_mech/demo/README.txt: -------------------------------------------------------------------------------- 1 | For reproducibility, we demo the code using the dataset provide 2 | with the USGS HASH code, 3 | http://earthquake.usgs.gov/research/software/index.php. 4 | 5 | This code runs FPFIT which is a standard earthquake classifier, so we 6 | can compare the results. FPFIT is available to, but HASH was way 7 | easier to work with. 8 | 9 | Download the hash.v1.2.tar.gz, unpack it and copy the north1.phase 10 | and scsn.reverse datafiles into the "demo" directory of this project. 11 | This will be the inputs to the demo. 12 | 13 | 14 | You'll also need to compile the hash_driver1 exe is you want to run 15 | it. You can use this to regenerate the example1.inp, example1-norev.inp 16 | data. Do, 17 | 18 | cat test1.out | sed -e s/*//" > example1.out 19 | 20 | this removes the extra column that messes up genfromtxt. 21 | 22 | We provide the input file example1.inp, example1-norev.inp input 23 | parameters. And also data derived from them, 3146815_realizations.out, 24 | example1.out and example1-noreverse.out. You can regenerate these using 25 | the inputs provided. 26 | 27 | 28 | -------------------------------------------------------------------------------- /focal_mech/demo/example1-norev.inp: -------------------------------------------------------------------------------- 1 | scsn.reverse 2 | north1.phase 3 | test1.out 4 | test1.out2 5 | 8 6 | 90 7 | 60 8 | 5 9 | 300 10 | 300 11 | 0.1 12 | 120 13 | 45 14 | 0.25 15 | -------------------------------------------------------------------------------- /focal_mech/demo/example1-noreverse.out: -------------------------------------------------------------------------------- 1 | 3143312 1994 1 21 11 4 15.500 L 2.300 X 34.24250 -118.61767 18.130 X -9.000 0.070 0.100 -9.000 -18 -9 -9 155 59 143 40 50 30 22 D 31 67 2 | 3143312 1994 1 21 11 4 15.500 L 2.300 X 34.24250 -118.61767 18.130 X -9.000 0.070 0.100 -9.000 -18 -9 -9 13 73 -85 52 46 30 39 D 33 67 3 | 3145744 1994 1 25 10 5 22.020 L 2.400 X 34.24117 -118.62117 18.540 X -9.000 0.030 0.090 -9.000 -18 -9 -9 151 51 139 33 37 33 12 C 61 64 4 | 3146815 1994 1 28 7 44 46.320 L 3.400 X 34.23917 -118.62150 18.960 X -9.000 0.090 0.180 -9.000 -18 -9 -9 137 43 127 22 26 73 11 A 90 51 5 | 3146907 1994 1 28 15 47 20.680 L 2.000 X 34.23817 -118.61050 17.790 X -9.000 0.060 0.090 -9.000 -18 -9 -9 98 47 94 40 45 23 16 D 35 62 6 | 3147167 1994 1 29 7 52 21.520 L 2.600 X 34.23833 -118.62466 19.200 X -9.000 0.090 0.120 -9.000 -18 -9 -9 148 50 127 23 30 55 10 B 83 57 7 | 3148047 1994 1 31 7 13 16.730 L 2.200 X 34.24183 -118.61550 17.920 X -9.000 0.050 0.100 -9.000 -18 -9 -9 169 58 144 32 32 39 14 B 64 61 8 | 3149674 1994 2 5 7 11 45.110 L 2.400 X 34.24017 -118.61667 18.200 X -9.000 0.040 0.060 -9.000 -18 -9 -9 298 43 80 33 27 50 17 B 74 59 9 | 3150936 1994 2 10 4 19 26.080 L 2.500 X 34.24217 -118.62016 18.310 X -9.000 0.050 0.060 -9.000 -18 -9 -9 148 56 134 26 29 57 13 B 81 49 10 | 3150947 1994 2 10 4 46 40.730 L 2.300 X 34.24117 -118.62016 18.450 X -9.000 0.050 0.100 -9.000 -18 -9 -9 154 58 133 27 26 50 11 B 83 54 11 | 3151649 1994 2 13 9 4 56.640 L 2.100 X 34.23783 -118.61283 17.740 X -9.000 0.030 0.030 -9.000 -18 -9 -9 150 52 130 29 33 33 11 B 69 55 12 | 3152142 1994 2 14 13 19 47.650 L 2.300 X 34.24166 -118.61716 17.960 X -9.000 0.070 0.130 -9.000 -18 -9 -9 151 55 130 26 28 48 9 B 81 52 13 | 2148509 1994 2 15 1 59 47.430 L 2.500 X 34.24166 -118.61900 18.190 X -9.000 0.010 0.060 -9.000 -18 -9 -9 112 47 91 27 28 60 20 C 80 52 14 | 3152388 1994 2 15 4 10 52.050 L 2.000 X 34.23983 -118.62133 18.390 X -9.000 0.070 0.060 -9.000 -18 -9 -9 129 47 99 31 32 34 13 B 69 57 15 | 3152559 1994 2 15 21 13 54.090 L 2.300 X 34.23967 -118.61584 17.910 X -9.000 0.030 0.130 -9.000 -18 -9 -9 288 51 64 28 24 42 5 B 89 53 16 | 3153955 1994 2 20 19 35 21.170 L 1.900 X 34.23783 -118.61183 17.830 X -9.000 0.060 0.070 -9.000 -18 -9 -9 104 59 85 38 38 32 22 D 46 61 17 | 3158361 1994 3 14 10 2 19.320 L 2.200 X 34.23933 -118.61833 18.350 X -9.000 0.060 0.030 -9.000 -18 -9 -9 140 51 119 31 32 46 13 B 68 51 18 | 3159027 1994 3 18 8 27 27.080 L 2.200 X 34.24050 -118.61767 18.280 X -9.000 0.030 0.040 -9.000 -18 -9 -9 134 58 108 36 40 39 14 D 49 55 19 | 3159267 1994 3 20 0 11 12.920 L 2.500 X 34.24117 -118.61584 18.000 X -9.000 0.050 0.070 -9.000 -18 -9 -9 140 55 121 29 34 44 9 B 71 54 20 | 2155068 1994 3 22 13 7 33.690 L 2.300 X 34.23933 -118.61567 18.170 X -9.000 0.040 0.040 -9.000 -18 -9 -9 152 55 140 29 29 34 4 B 80 53 21 | 3160206 1994 3 24 11 23 51.600 L 1.700 X 34.24017 -118.61833 18.040 X -9.000 0.050 0.050 -9.000 -18 -9 -9 285 53 48 35 32 31 6 C 58 56 22 | 3160206 1994 3 24 11 23 51.600 L 1.700 X 34.24017 -118.61833 18.040 X -9.000 0.050 0.050 -9.000 -18 -9 -9 344 15 65 46 43 31 18 D 25 57 23 | 3177685 1994 7 26 2 58 20.640 L 2.600 X 34.23900 -118.61150 17.780 X -9.000 0.050 0.140 -9.000 -18 -9 -9 128 49 109 29 34 51 12 B 72 54 24 | 3148018 1994 1 31 4 53 39.250 L 2.100 X 34.23817 -118.61066 17.440 X -9.000 0.090 0.130 -9.000 -18 -9 -9 281 57 41 23 11 46 8 A 88 53 25 | 3150301 1994 2 7 5 23 49.910 L 1.800 X 34.23734 -118.61300 17.700 X -9.000 0.060 0.110 -9.000 -18 -9 -9 142 45 122 28 25 32 22 C 81 64 26 | 3150490 1994 2 8 2 7 8.790 L 2.600 X 34.23817 -118.60633 17.750 X -9.000 0.070 0.160 -9.000 -18 -9 -9 287 41 83 29 26 57 19 B 78 56 27 | -------------------------------------------------------------------------------- /focal_mech/demo/example1.inp: -------------------------------------------------------------------------------- 1 | scsn.reverse 2 | north1.phase 3 | test1.out 4 | test1.out2 5 | 8 6 | 90 7 | 60 8 | 5 9 | 300 10 | 300 11 | 0.1 12 | 120 13 | 45 14 | 0.25 15 | -------------------------------------------------------------------------------- /focal_mech/demo/example1.out: -------------------------------------------------------------------------------- 1 | 3143312 1994 1 21 11 4 15.500 L 2.300 X 34.24250 -118.61767 18.130 X -9.000 0.070 0.100 -9.000 -18 -9 -9 133 50 138 29 33 30 9 B 70 67 2 | 3145744 1994 1 25 10 5 22.020 L 2.400 X 34.24117 -118.62117 18.540 X -9.000 0.030 0.090 -9.000 -18 -9 -9 140 52 98 35 42 33 13 D 45 64 3 | 3145744 1994 1 25 10 5 22.020 L 2.400 X 34.24117 -118.62117 18.540 X -9.000 0.030 0.090 -9.000 -18 -9 -9 172 79 171 40 44 33 12 D 31 64 4 | 3146815 1994 1 28 7 44 46.320 L 3.400 X 34.23917 -118.62150 18.960 X -9.000 0.090 0.180 -9.000 -18 -9 -9 137 45 128 21 24 73 13 A 95 51 5 | 3146907 1994 1 28 15 47 20.680 L 2.000 X 34.23817 -118.61050 17.790 X -9.000 0.060 0.090 -9.000 -18 -9 -9 309 39 117 40 38 23 12 D 45 62 6 | 3146907 1994 1 28 15 47 20.680 L 2.000 X 34.23817 -118.61050 17.790 X -9.000 0.060 0.090 -9.000 -18 -9 -9 146 76 146 48 48 23 26 D 26 62 7 | 3147167 1994 1 29 7 52 21.520 L 2.600 X 34.23833 -118.62466 19.200 X -9.000 0.090 0.120 -9.000 -18 -9 -9 143 54 110 23 29 55 13 B 84 57 8 | 3148047 1994 1 31 7 13 16.730 L 2.200 X 34.24183 -118.61550 17.920 X -9.000 0.050 0.100 -9.000 -18 -9 -9 303 41 81 30 30 39 12 B 70 61 9 | 3149674 1994 2 5 7 11 45.110 L 2.400 X 34.24017 -118.61667 18.200 X -9.000 0.040 0.060 -9.000 -18 -9 -9 285 43 74 34 31 50 18 B 67 59 10 | 3150936 1994 2 10 4 19 26.080 L 2.500 X 34.24217 -118.62016 18.310 X -9.000 0.050 0.060 -9.000 -18 -9 -9 142 57 130 27 31 57 4 B 78 49 11 | 3150947 1994 2 10 4 46 40.730 L 2.300 X 34.24117 -118.62016 18.450 X -9.000 0.050 0.100 -9.000 -18 -9 -9 146 58 130 26 28 50 10 B 86 54 12 | 3151649 1994 2 13 9 4 56.640 L 2.100 X 34.23783 -118.61283 17.740 X -9.000 0.030 0.030 -9.000 -18 -9 -9 124 48 102 26 30 33 10 B 78 55 13 | 3152142 1994 2 14 13 19 47.650 L 2.300 X 34.24166 -118.61716 17.960 X -9.000 0.070 0.130 -9.000 -18 -9 -9 282 45 67 26 23 48 6 A 89 52 14 | 2148509 1994 2 15 1 59 47.430 L 2.500 X 34.24166 -118.61900 18.190 X -9.000 0.010 0.060 -9.000 -18 -9 -9 120 47 102 25 27 60 18 B 89 52 15 | 3152388 1994 2 15 4 10 52.050 L 2.000 X 34.23983 -118.62133 18.390 X -9.000 0.070 0.060 -9.000 -18 -9 -9 278 49 62 33 28 34 8 B 71 57 16 | 3152559 1994 2 15 21 13 54.090 L 2.300 X 34.23967 -118.61584 17.910 X -9.000 0.030 0.130 -9.000 -18 -9 -9 283 47 62 26 23 42 5 A 90 53 17 | 3153955 1994 2 20 19 35 21.170 L 1.900 X 34.23783 -118.61183 17.830 X -9.000 0.060 0.070 -9.000 -18 -9 -9 317 38 131 36 34 32 7 C 56 61 18 | 3158361 1994 3 14 10 2 19.320 L 2.200 X 34.23933 -118.61833 18.350 X -9.000 0.060 0.030 -9.000 -18 -9 -9 137 53 115 25 28 46 11 B 89 51 19 | 3159027 1994 3 18 8 27 27.080 L 2.200 X 34.24050 -118.61767 18.280 X -9.000 0.030 0.040 -9.000 -18 -9 -9 137 64 119 40 40 39 12 D 42 55 20 | 3159267 1994 3 20 0 11 12.920 L 2.500 X 34.24117 -118.61584 18.000 X -9.000 0.050 0.070 -9.000 -18 -9 -9 284 37 67 31 27 44 9 B 78 54 21 | 2155068 1994 3 22 13 7 33.690 L 2.300 X 34.23933 -118.61567 18.170 X -9.000 0.040 0.040 -9.000 -18 -9 -9 147 54 123 26 27 34 0 B 86 53 22 | 3160206 1994 3 24 11 23 51.600 L 1.700 X 34.24017 -118.61833 18.040 X -9.000 0.050 0.050 -9.000 -18 -9 -9 149 54 131 33 38 31 7 C 56 56 23 | 3177685 1994 7 26 2 58 20.640 L 2.600 X 34.23900 -118.61150 17.780 X -9.000 0.050 0.140 -9.000 -18 -9 -9 128 50 124 30 37 51 13 B 62 54 24 | 3148018 1994 1 31 4 53 39.250 L 2.100 X 34.23817 -118.61066 17.440 X -9.000 0.090 0.130 -9.000 -18 -9 -9 293 45 62 24 15 46 18 B 98 53 25 | 3150301 1994 2 7 5 23 49.910 L 1.800 X 34.23734 -118.61300 17.700 X -9.000 0.060 0.110 -9.000 -18 -9 -9 299 48 101 28 22 32 17 B 83 65 26 | 3150490 1994 2 8 2 7 8.790 L 2.600 X 34.23817 -118.60633 17.750 X -9.000 0.070 0.160 -9.000 -18 -9 -9 308 40 109 23 19 57 15 B 93 56 27 | -------------------------------------------------------------------------------- /focal_mech/demo/images/WR1-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/blasscoc/FocalMechClassifier/8d54d5a19cea447c030ada596369e47e7f39d483/focal_mech/demo/images/WR1-2.png -------------------------------------------------------------------------------- /focal_mech/demo/images/ball_of_yarn.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/blasscoc/FocalMechClassifier/8d54d5a19cea447c030ada596369e47e7f39d483/focal_mech/demo/images/ball_of_yarn.png -------------------------------------------------------------------------------- /focal_mech/demo/images/beachball.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/blasscoc/FocalMechClassifier/8d54d5a19cea447c030ada596369e47e7f39d483/focal_mech/demo/images/beachball.png -------------------------------------------------------------------------------- /focal_mech/demo/images/class_3145744_norev.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/blasscoc/FocalMechClassifier/8d54d5a19cea447c030ada596369e47e7f39d483/focal_mech/demo/images/class_3145744_norev.png -------------------------------------------------------------------------------- /focal_mech/demo/images/class_3146815_dc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/blasscoc/FocalMechClassifier/8d54d5a19cea447c030ada596369e47e7f39d483/focal_mech/demo/images/class_3146815_dc.png -------------------------------------------------------------------------------- /focal_mech/demo/images/class_3146815_example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/blasscoc/FocalMechClassifier/8d54d5a19cea447c030ada596369e47e7f39d483/focal_mech/demo/images/class_3146815_example.png -------------------------------------------------------------------------------- /focal_mech/demo/images/correlation.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/blasscoc/FocalMechClassifier/8d54d5a19cea447c030ada596369e47e7f39d483/focal_mech/demo/images/correlation.png -------------------------------------------------------------------------------- /focal_mech/demo/images/highlo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/blasscoc/FocalMechClassifier/8d54d5a19cea447c030ada596369e47e7f39d483/focal_mech/demo/images/highlo.png -------------------------------------------------------------------------------- /focal_mech/demo/images/seismogram-wr1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/blasscoc/FocalMechClassifier/8d54d5a19cea447c030ada596369e47e7f39d483/focal_mech/demo/images/seismogram-wr1.png -------------------------------------------------------------------------------- /focal_mech/demo/images/svm_schematic.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/blasscoc/FocalMechClassifier/8d54d5a19cea447c030ada596369e47e7f39d483/focal_mech/demo/images/svm_schematic.png -------------------------------------------------------------------------------- /focal_mech/demo/no.reverse: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/blasscoc/FocalMechClassifier/8d54d5a19cea447c030ada596369e47e7f39d483/focal_mech/demo/no.reverse -------------------------------------------------------------------------------- /focal_mech/demo/test2.py: -------------------------------------------------------------------------------- 1 | from numpy import array, rad2deg 2 | 3 | from matplotlib.pylab import contour 4 | import matplotlib.pyplot as plt 5 | import mplstereonet 6 | 7 | from obspy.imaging.beachball import aux_plane 8 | 9 | from focal_mech.lib.classify_mechanism import classify, translate_to_sphharm 10 | from focal_mech.io.read_hash import read_demo, read_hash_solutions 11 | 12 | from focal_mech.util.hash_routines import hash_to_classifier 13 | from focal_mech.lib.sph_harm import get_sph_harm 14 | from focal_mech.lib.correlate import corr_shear 15 | 16 | 17 | hash_solns = read_hash_solutions("example1.out") 18 | 19 | # we want solutions that are symetric 20 | polarity_data = read_demo("north1.phase", "scsn.reverse", reverse=True) 21 | inputs = hash_to_classifier(polarity_data, parity=1) 22 | 23 | event = 3146815 24 | 25 | result = classify(*inputs[event], kernel_degree=2) 26 | Alm = translate_to_sphharm(*result, kernel_degree=2) 27 | 28 | 29 | coeffs = array([Alm[0,0], 30 | Alm[1,-1], Alm[1,0], Alm[1,1], 31 | Alm[2,-2], Alm[2,-1], Alm[2,0], Alm[2,1], Alm[2,2]]) 32 | 33 | svm_soln, f = corr_shear(Alm) 34 | 35 | resolution = (200,400) 36 | longi, lati, Z = get_sph_harm(resolution=resolution) 37 | mech = coeffs.dot(Z).real 38 | 39 | longi.shape = resolution 40 | lati.shape = resolution 41 | mech.shape = resolution 42 | 43 | c = contour(longi, lati, mech, [0]) 44 | pth1 = c.collections[0].get_paths()[0].vertices 45 | pth1 = rad2deg(pth1) 46 | 47 | pth2 = c.collections[0].get_paths()[1].vertices 48 | pth2 = rad2deg(pth2) 49 | 50 | hash_focal = rad2deg(hash_solns[event]) 51 | 52 | fig = plt.figure(facecolor="white") 53 | ax = fig.add_subplot(111, projection='stereonet') 54 | 55 | indx = mech > 0 56 | # reflect the points in the lower half space 57 | #ax.pole(rad2deg(longi[indx]), rad2deg(lati[indx])) 58 | 59 | ax.rake(pth1[:,0], pth1[:,1] +90.0, 90.0, ':', color='red', linewidth=3) 60 | ax.rake(pth2[:,0], pth2[:,1] +90.0, 90.0, ':', color='red', linewidth=3) 61 | 62 | 63 | strike, dip, rake = svm_soln 64 | ax.plane(strike, dip, '-r', linewidth=2) 65 | 66 | strike, dip, rake = aux_plane(*svm_soln) 67 | ax.plane(strike, dip, '-r', linewidth=2) 68 | 69 | strike, dip, rake = hash_focal 70 | ax.plane(strike-90, dip, 'g-', linewidth=2) 71 | 72 | strike, dip, rake = aux_plane(*hash_focal) 73 | ax.plane(strike-90, dip,'g-', linewidth=2) 74 | 75 | azi = rad2deg(polarity_data[event][:,0]) 76 | toa = rad2deg(polarity_data[event][:,1]) 77 | 78 | # https://github.com/markcwill/hashpy/blob/master/hashpy/plotting/focalmechplotter.py # 79 | # Calculate strike azi from direct (dip-pointing) azi 80 | #azi = azi - 90. 81 | #--- HASH takeoffs are 0-180 from vertical UP!! 82 | #--- Stereonet angles 0-90 inward (dip) 83 | #--- Classic FM's are toa from center??? 84 | #indx = logical_and(toa >= 0, toa < 90) 85 | #toa[indx] = 90 - toa[indx] 86 | #indx = logical_and(toa >= 90, toa < 180) 87 | #toa[indx] = 270 - toa[indx] 88 | 89 | polarity = polarity_data[event][:,2] 90 | for a, t, p in zip(azi, toa, polarity): 91 | if p > 0: 92 | ax.pole(a, t,'o', markeredgecolor='red', markerfacecolor='red') 93 | else: 94 | ax.pole(a, t,'o', markeredgecolor='blue', markerfacecolor='white') 95 | 96 | fig.suptitle("Event %d" % event) 97 | ax.grid() 98 | 99 | plt.show() 100 | -------------------------------------------------------------------------------- /focal_mech/demo/test3.py: -------------------------------------------------------------------------------- 1 | from numpy import genfromtxt, rad2deg 2 | 3 | import matplotlib.pyplot as plt 4 | import mplstereonet 5 | 6 | from obspy.imaging.beachball import aux_plane 7 | 8 | from focal_mech.io.read_hash import read_demo, read_hash_solutions 9 | 10 | event = 3146815 11 | 12 | hash_solns = read_hash_solutions("example1.out") 13 | hash_focal = rad2deg(hash_solns[event]) 14 | 15 | mechs = genfromtxt("3146815_realizations.out")[:,:3] 16 | polarity_data = read_demo("north1.phase", "scsn.reverse", reverse=True) 17 | 18 | fig = plt.figure(facecolor="white") 19 | ax = fig.add_subplot(111, projection='stereonet') 20 | 21 | 22 | for mech in mechs[:10]: 23 | strike, dip, rake = mech 24 | ax.plane(strike-90, dip, '-r', linewidth=2) 25 | 26 | strike, dip, rake = aux_plane(*mech) 27 | ax.plane(strike-90, dip, '-r', linewidth=2) 28 | 29 | strike, dip, rake = hash_focal 30 | ax.plane(strike-90, dip, '-b', linewidth=2) 31 | 32 | strike, dip, rake = aux_plane(*hash_focal) 33 | ax.plane(strike-90, dip, '-b', linewidth=2) 34 | 35 | azi = rad2deg(polarity_data[event][:,0]) 36 | toa = rad2deg(polarity_data[event][:,1]) 37 | 38 | polarity = polarity_data[event][:,2] 39 | for a, t, p in zip(azi, toa, polarity): 40 | if p > 0: 41 | ax.pole(a, t,'o', markeredgecolor='red', markerfacecolor='red') 42 | else: 43 | ax.pole(a, t,'o', markeredgecolor='blue', markerfacecolor='white') 44 | 45 | fig.suptitle("Event %d" % event) 46 | ax.grid() 47 | 48 | plt.show() 49 | -------------------------------------------------------------------------------- /focal_mech/demo/test4.py: -------------------------------------------------------------------------------- 1 | from numpy import array, rad2deg, pi, mgrid, argmin 2 | 3 | import matplotlib.pyplot as plt 4 | import mplstereonet 5 | 6 | from obspy.imaging.beachball import aux_plane 7 | 8 | 9 | from focal_mech.lib.classify_mechanism import classify, translate_to_sphharm 10 | from focal_mech.io.read_hash import read_demo, read_hash_solutions 11 | 12 | from focal_mech.util.hash_routines import hash_to_classifier 13 | from focal_mech.lib.sph_harm import get_sph_harm 14 | from focal_mech.lib.correlate import corr_shear 15 | 16 | 17 | event = 3145744 18 | 19 | 20 | hash_solns = read_hash_solutions("example1.out") 21 | hash_solns_nr = read_hash_solutions("example1-noreverse.out") 22 | 23 | # we want solutions that are symetric 24 | polarity_data = read_demo("north1.phase", "scsn.reverse", reverse=True) 25 | polarity_data_nr = read_demo("north1.phase", "scsn.reverse", reverse=False) 26 | 27 | inputs = hash_to_classifier(polarity_data, parity=1) 28 | inputs_nr = hash_to_classifier(polarity_data_nr, parity=1) 29 | 30 | 31 | result = classify(*inputs[event], kernel_degree=2) 32 | Alm = translate_to_sphharm(*result, kernel_degree=2) 33 | 34 | coeffs = array([Alm[0,0], 35 | Alm[1,-1], Alm[1,0], Alm[1,1], 36 | Alm[2,-2], Alm[2,-1], Alm[2,0], Alm[2,1], Alm[2,2]]) 37 | 38 | result_nr = classify(*inputs_nr[event], kernel_degree=2) 39 | Alm_nr = translate_to_sphharm(*result_nr, kernel_degree=2) 40 | 41 | coeffs_nr = array([Alm_nr[0,0], 42 | Alm_nr[1,-1], Alm_nr[1,0], Alm_nr[1,1], 43 | Alm_nr[2,-2], Alm_nr[2,-1], Alm_nr[2,0], Alm_nr[2,1], Alm_nr[2,2]]) 44 | 45 | svm_soln, f = corr_shear(Alm) 46 | svm_soln_nr, f = corr_shear(Alm_nr) 47 | 48 | 49 | resolution = (200,400) 50 | longi, lati, Z = get_sph_harm(resolution=resolution) 51 | mech = coeffs.dot(Z).real 52 | 53 | longi.shape = resolution 54 | lati.shape = resolution 55 | mech.shape = resolution 56 | 57 | #c = contour(longi, lati, mech, [0]) 58 | #pth1 = c.collections[0].get_paths()[0].vertices 59 | #pth1 = rad2deg(pth1) 60 | 61 | #pth2 = c.collections[0].get_paths()[1].vertices 62 | #pth2 = rad2deg(pth2) 63 | 64 | hash_focal = rad2deg(hash_solns[event]) 65 | hash_focal_nr = rad2deg(hash_solns_nr[event]) 66 | 67 | fig = plt.figure(facecolor="white") 68 | ax = fig.add_subplot(111, projection='stereonet') 69 | 70 | indx = mech > 0 71 | # reflect the points in the lower half space 72 | #ax.pole(rad2deg(longi[indx]), rad2deg(lati[indx])) 73 | 74 | #ax.rake(pth1[:,0], pth1[:,1] +90.0, 90.0, '-', color='red', linewidth=3) 75 | #ax.rake(pth2[:,0], pth2[:,1] +90.0, 90.0, '-', color='red', linewidth=3) 76 | 77 | 78 | strike, dip, rake = svm_soln 79 | ax.plane(round(strike), dip, '-r', linewidth=2) 80 | 81 | strike, dip, rake = aux_plane(*svm_soln) 82 | ax.plane(strike, dip, '-r', linewidth=2) 83 | 84 | strike, dip, rake = svm_soln_nr 85 | ax.plane(round(strike), dip, '--r', linewidth=2) 86 | 87 | strike, dip, rake = aux_plane(*svm_soln_nr) 88 | ax.plane(strike, dip, '--r', linewidth=2) 89 | 90 | 91 | 92 | strike, dip, rake = hash_focal 93 | ax.plane(strike-90, dip, 'g-', linewidth=2) 94 | 95 | strike, dip, rake = aux_plane(*hash_focal) 96 | ax.plane(strike-90, dip,'g-', linewidth=2) 97 | 98 | 99 | strike, dip, rake = hash_focal_nr 100 | ax.plane(strike-90, dip, 'g--', linewidth=2) 101 | 102 | strike, dip, rake = aux_plane(*hash_focal_nr) 103 | ax.plane(strike-90, dip,'g--', linewidth=2) 104 | 105 | 106 | azi = rad2deg(polarity_data_nr[event][:,0]) 107 | toa = rad2deg(polarity_data_nr[event][:,1]) 108 | 109 | # https://github.com/markcwill/hashpy/blob/master/hashpy/plotting/focalmechplotter.py # 110 | # Calculate strike azi from direct (dip-pointing) azi 111 | #azi = azi - 90. 112 | #--- HASH takeoffs are 0-180 from vertical UP!! 113 | #--- Stereonet angles 0-90 inward (dip) 114 | #--- Classic FM's are toa from center??? 115 | #indx = logical_and(toa >= 0, toa < 90) 116 | #toa[indx] = 90 - toa[indx] 117 | #indx = logical_and(toa >= 90, toa < 180) 118 | #toa[indx] = 270 - toa[indx] 119 | 120 | 121 | polarity = polarity_data[event][:,2] 122 | for a, t, p in zip(azi, toa, polarity): 123 | if p > 0: 124 | ax.pole(a, t,'o', markeredgecolor='red', markerfacecolor='red') 125 | else: 126 | ax.pole(a, t,'o', markeredgecolor='blue', markerfacecolor='white') 127 | 128 | fig.suptitle("Event %d" % event) 129 | ax.grid() 130 | 131 | plt.show() 132 | -------------------------------------------------------------------------------- /focal_mech/demo/test5.py: -------------------------------------------------------------------------------- 1 | from numpy import array, argmin, arange, argmax, deg2rad, dot 2 | from scipy.linalg import norm 3 | 4 | import matplotlib.pyplot as plt 5 | import mplstereonet 6 | 7 | from focal_mech.lib.sph_harm import WignerD2 8 | from focal_mech.lib.classify_mechanism import classify, translate_to_sphharm 9 | from focal_mech.io.read_hash import read_demo, read_hash_solutions 10 | from focal_mech.util.hash_routines import hash_to_classifier 11 | 12 | 13 | hash_solns = read_hash_solutions("example1.out") 14 | 15 | # we want solutions that are symetric 16 | polarity_data = read_demo("north1.phase", "scsn.reverse", reverse=True) 17 | inputs = hash_to_classifier(polarity_data, parity=1) 18 | 19 | event = 3146815 20 | 21 | result = classify(*inputs[event], kernel_degree=2) 22 | Alm = translate_to_sphharm(*result, kernel_degree=2) 23 | 24 | alm = array([Alm[0,0], 25 | Alm[1,-1], Alm[1,0], Alm[1,1], 26 | Alm[2,-2], Alm[2,-1], Alm[2,0], Alm[2,1], Alm[2,2]]) 27 | 28 | corr = [] 29 | for event in polarity_data.keys(): 30 | 31 | if event == 3146815: 32 | continue 33 | 34 | result = classify(*inputs[event], kernel_degree=2) 35 | Blm = translate_to_sphharm(*result, kernel_degree=2) 36 | 37 | blm = array([Blm[0,0], 38 | Blm[1,-1], Blm[1,0], Blm[1,1], 39 | Blm[2,-2], Blm[2,-1], Blm[2,0], Blm[2,1], Blm[2,2]]) 40 | 41 | c = norm(alm.conjugate().dot(blm))/(norm(alm)*norm(blm)) 42 | 43 | print event, c 44 | corr.append(c) 45 | 46 | blm = array([Alm[0,0], 47 | Alm[1,-1], Alm[1,0], Alm[1,1], 48 | Alm[2,-2], Alm[2,-1], Alm[2,0], Alm[2,1], Alm[2,2]]) 49 | 50 | D = WignerD2(deg2rad(90), deg2rad(0), deg2rad(0) ) 51 | blm[4:] = dot(D, blm[4:]) 52 | 53 | # rotate event by 90-degreees 54 | corr.append(norm(alm.conjugate().dot(blm))/(norm(alm)*norm(blm))) 55 | 56 | # \alpha makes sense for sandstone or granite, 4\sqrt(5) is the other term 57 | blm = [4.7, 0,0,0, 0,0,9,0,0] 58 | 59 | corr.append(norm(alm.conjugate().dot(blm))/(norm(alm)*norm(blm))) 60 | 61 | events = [i for i in polarity_data.keys() if i != 3146815] 62 | 63 | events.append("90-degree") 64 | events.append("Tensile") 65 | 66 | N = len(events) 67 | 68 | fig = plt.figure(facecolor="white", figsize=(20,30)) 69 | ax = fig.add_subplot(111) 70 | rects1 = ax.bar([i+0.5 for i in range(N)], corr, 0.99, align = 'center') 71 | 72 | rects1[argmin(corr[:-2])].set_color('r') 73 | rects1[argmax(corr[:-2])].set_color('r') 74 | 75 | rects1[-1].set_color('c') 76 | rects1[-2].set_color('g') 77 | 78 | 79 | ax.set_yticks(arange(0,1,0.1)) 80 | ax.set_xticks(range(0,N)) 81 | ax.set_xticklabels(events, rotation=25, fontsize=18 ) 82 | ax.yaxis.grid(True) 83 | 84 | for tick in ax.yaxis.get_major_ticks(): 85 | tick.label.set_fontsize(18) 86 | 87 | plt.xlim([0,N]) 88 | 89 | plt.ylabel("Correlation Score", fontsize=24) 90 | 91 | plt.show() 92 | 93 | -------------------------------------------------------------------------------- /focal_mech/demo/test6.py: -------------------------------------------------------------------------------- 1 | from numpy import array, rad2deg, pi, mgrid, argmin 2 | 3 | from matplotlib.pylab import contour 4 | import matplotlib.pyplot as plt 5 | import mplstereonet 6 | 7 | from obspy.imaging.beachball import aux_plane 8 | 9 | from focal_mech.lib.classify_mechanism import classify, translate_to_sphharm 10 | from focal_mech.io.read_hash import read_demo, read_hash_solutions 11 | 12 | from focal_mech.util.hash_routines import hash_to_classifier 13 | from focal_mech.lib.sph_harm import get_sph_harm 14 | from focal_mech.lib.correlate import corr_shear 15 | 16 | hash_solns = read_hash_solutions("example1.out") 17 | 18 | # we want solutions that are symetric 19 | polarity_data = read_demo("north1.phase", "scsn.reverse", reverse=True) 20 | inputs = hash_to_classifier(polarity_data, parity=1) 21 | 22 | event = 3146815 23 | 24 | result = classify(*inputs[event], kernel_degree=2) 25 | Alm = translate_to_sphharm(*result, kernel_degree=2) 26 | 27 | coeffs = array([Alm[0,0], 28 | Alm[1,-1], Alm[1,0], Alm[1,1], 29 | Alm[2,-2], Alm[2,-1], Alm[2,0], Alm[2,1], Alm[2,2]]) 30 | 31 | 32 | svm_soln, f = corr_shear(Alm) 33 | 34 | resolution = (200,400) 35 | longi, lati, Z = get_sph_harm(resolution=resolution) 36 | mech = coeffs.dot(Z).real 37 | 38 | longi.shape = resolution 39 | lati.shape = resolution 40 | mech.shape = resolution 41 | 42 | c = contour(longi, lati, mech, [0]) 43 | pth1 = c.collections[0].get_paths()[0].vertices 44 | pth1 = rad2deg(pth1) 45 | 46 | pth2 = c.collections[0].get_paths()[1].vertices 47 | pth2 = rad2deg(pth2) 48 | 49 | hash_focal = rad2deg(hash_solns[event]) 50 | 51 | 52 | event2 = 3158361 53 | 54 | 55 | result = classify(*inputs[event2], kernel_degree=2) 56 | Alm = translate_to_sphharm(*result, kernel_degree=2) 57 | 58 | coeffs = array([Alm[0,0], 59 | Alm[1,-1], Alm[1,0], Alm[1,1], 60 | Alm[2,-2], Alm[2,-1], Alm[2,0], Alm[2,1], Alm[2,2]]) 61 | 62 | svm_soln2, f = corr_shear(Alm) 63 | 64 | resolution = (200,400) 65 | longi, lati, Z = get_sph_harm(resolution=resolution) 66 | mech = coeffs.dot(Z).real 67 | 68 | longi.shape = resolution 69 | lati.shape = resolution 70 | mech.shape = resolution 71 | 72 | c = contour(longi, lati, mech, [0]) 73 | pth3 = c.collections[0].get_paths()[0].vertices 74 | pth3 = rad2deg(pth3) 75 | 76 | pth4 = c.collections[0].get_paths()[1].vertices 77 | pth4 = rad2deg(pth4) 78 | 79 | hash_focal2 = rad2deg(hash_solns[event2]) 80 | 81 | 82 | event3 = 3153955 83 | 84 | 85 | result = classify(*inputs[event3], kernel_degree=2) 86 | Alm = translate_to_sphharm(*result, kernel_degree=2) 87 | 88 | coeffs = array([Alm[0,0], 89 | Alm[1,-1], Alm[1,0], Alm[1,1], 90 | Alm[2,-2], Alm[2,-1], Alm[2,0], Alm[2,1], Alm[2,2]]) 91 | 92 | svm_soln3, f = corr_shear(Alm) 93 | 94 | resolution = (200,400) 95 | longi, lati, Z = get_sph_harm(resolution=resolution) 96 | mech = coeffs.dot(Z).real 97 | 98 | longi.shape = resolution 99 | lati.shape = resolution 100 | mech.shape = resolution 101 | 102 | c = contour(longi, lati, mech, [0]) 103 | pth5 = c.collections[0].get_paths()[0].vertices 104 | pth5 = rad2deg(pth5) 105 | 106 | pth6 = c.collections[0].get_paths()[1].vertices 107 | pth6 = rad2deg(pth6) 108 | 109 | hash_focal3 = rad2deg(hash_solns[event3]) 110 | 111 | 112 | fig = plt.figure(facecolor="white", figsize=(10,20)) 113 | ax = fig.add_subplot(221, projection='stereonet') 114 | 115 | ax.rake(pth1[:,0], pth1[:,1] +90.0, 90.0, ':', color='red', linewidth=3) 116 | ax.rake(pth2[:,0], pth2[:,1] +90.0, 90.0, ':', color='red', linewidth=3) 117 | 118 | strike, dip, rake = svm_soln 119 | ax.plane(strike, dip, '-r', linewidth=2) 120 | 121 | strike, dip, rake = aux_plane(*svm_soln) 122 | ax.plane(strike, dip, '-r', linewidth=2) 123 | 124 | strike, dip, rake = hash_focal 125 | ax.plane(strike-90, dip, 'g-', linewidth=2) 126 | 127 | strike, dip, rake = aux_plane(*hash_focal) 128 | ax.plane(strike-90, dip,'g-', linewidth=2) 129 | 130 | azi = rad2deg(polarity_data[event][:,0]) 131 | toa = rad2deg(polarity_data[event][:,1]) 132 | 133 | polarity = polarity_data[event][:,2] 134 | for a, t, p in zip(azi, toa, polarity): 135 | if p > 0: 136 | ax.pole(a, t,'o', markeredgecolor='red', markerfacecolor='red') 137 | else: 138 | ax.pole(a, t,'o', markeredgecolor='blue', markerfacecolor='white') 139 | 140 | ax.grid() 141 | 142 | 143 | ax = fig.add_subplot(222, projection='stereonet') 144 | 145 | ax.rake(pth3[:,0], pth3[:,1] +90.0, 90.0, ':', color='red', linewidth=3) 146 | ax.rake(pth4[:,0], pth4[:,1] +90.0, 90.0, ':', color='red', linewidth=3) 147 | 148 | strike, dip, rake = svm_soln2 149 | ax.plane(strike, dip, '-r', linewidth=2) 150 | 151 | strike, dip, rake = aux_plane(*svm_soln2) 152 | ax.plane(strike, dip, '-r', linewidth=2) 153 | 154 | strike, dip, rake = hash_focal2 155 | ax.plane(strike-90, dip, 'g-', linewidth=2) 156 | 157 | strike, dip, rake = aux_plane(*hash_focal2) 158 | ax.plane(strike-90, dip,'g-', linewidth=2) 159 | 160 | azi = rad2deg(polarity_data[event2][:,0]) 161 | toa = rad2deg(polarity_data[event2][:,1]) 162 | 163 | polarity = polarity_data[event2][:,2] 164 | for a, t, p in zip(azi, toa, polarity): 165 | if p > 0: 166 | ax.pole(a, t,'o', markeredgecolor='red', markerfacecolor='red') 167 | else: 168 | ax.pole(a, t,'o', markeredgecolor='blue', markerfacecolor='white') 169 | 170 | ax.grid() 171 | 172 | 173 | ax = fig.add_subplot(224, projection='stereonet') 174 | 175 | ax.rake(pth5[:,0], pth5[:,1] +90.0, 90.0, ':', color='red', linewidth=3) 176 | ax.rake(pth6[:,0], pth6[:,1] +90.0, 90.0, ':', color='red', linewidth=3) 177 | 178 | strike, dip, rake = svm_soln3 179 | ax.plane(strike, dip, '-r', linewidth=2) 180 | 181 | strike, dip, rake = aux_plane(*svm_soln3) 182 | ax.plane(strike, dip, '-r', linewidth=2) 183 | 184 | strike, dip, rake = hash_focal3 185 | ax.plane(strike-90, dip, 'g-', linewidth=2) 186 | 187 | strike, dip, rake = aux_plane(*hash_focal3) 188 | ax.plane(strike-90, dip,'g-', linewidth=2) 189 | 190 | azi = rad2deg(polarity_data[event3][:,0]) 191 | toa = rad2deg(polarity_data[event3][:,1]) 192 | 193 | polarity = polarity_data[event3][:,2] 194 | for a, t, p in zip(azi, toa, polarity): 195 | if p > 0: 196 | ax.pole(a, t,'o', markeredgecolor='red', markerfacecolor='red') 197 | else: 198 | ax.pole(a, t,'o', markeredgecolor='blue', markerfacecolor='white') 199 | 200 | ax.grid() 201 | 202 | 203 | plt.tight_layout(pad=4.0, h_pad=20.0) 204 | 205 | plt.show() 206 | -------------------------------------------------------------------------------- /focal_mech/io/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/blasscoc/FocalMechClassifier/8d54d5a19cea447c030ada596369e47e7f39d483/focal_mech/io/__init__.py -------------------------------------------------------------------------------- /focal_mech/io/read_hash.py: -------------------------------------------------------------------------------- 1 | """ 2 | Read the demo data supplied by the HASH demo codes. 3 | """ 4 | import datetime 5 | from numpy import genfromtxt, int_, deg2rad, array 6 | 7 | def read_hash_solutions(filename): 8 | data = genfromtxt(filename) 9 | return dict(zip(int_(data[:,0]),deg2rad(data[:,21:24]))) 10 | 11 | def read_demo(phase_data, sta_reverse, reverse=True): 12 | """ 13 | Read the demo data in and grab the polarity and stations coords. 14 | """ 15 | 16 | polarity_data, event_time_map = parse_phase_file(phase_data) 17 | # Some of the stations were known to be recording the oppsite 18 | # polarity during certain periods: 19 | reverse_data = parse_reverse(sta_reverse) 20 | 21 | if reverse: 22 | reverse_polarity(reverse_data, polarity_data, event_time_map) 23 | 24 | demo_data = {} 25 | for event, val in polarity_data.items(): 26 | 27 | _, data = val 28 | 29 | pol = array([deg2rad(data[-1]), deg2rad(data[-2]), data[1]]) 30 | pol = pol.reshape([3,-1]).T 31 | 32 | demo_data[event] = pol 33 | 34 | return demo_data 35 | 36 | def _parse_phase_header(line_iter): 37 | """ 38 | 1-10 5i2 origin time, year, month, day, hour, minute 39 | 11-14 f4.2 origin time, seconds 40 | 15-16 i2 latitude, degrees 41 | 17 a1 latitude, 'S'=south 42 | 18-21 f4.2 latitude, minutes 43 | 22-24 i3 longitude, degrees 44 | 25 a1 longitude, 'E'=east 45 | 26-29 f4.2 longitude, minutes 46 | 30-34 f5.2 depth, km 47 | 35-36 f2.1 magnitude 48 | 81-88 2f4.2 horizontal and vertical uncertainty, km 49 | """ 50 | 51 | line = line_iter.next() 52 | 53 | cursor = 0 54 | 55 | year = int(line[cursor:cursor+2]); cursor += 2 56 | month = int(line[cursor:cursor+2]); cursor += 2 57 | day = int(line[cursor:cursor+2]); cursor += 2 58 | hour = int(line[cursor:cursor+2]); cursor += 2 59 | minute = int(line[cursor:cursor+2]); cursor += 2 60 | second = float(line[cursor:cursor+2]); cursor += 4 61 | 62 | event_id = int(line[122:138]) 63 | 64 | second /= 100 65 | microsecond = 1.0E+6 * (second - int(second)) 66 | 67 | # y2k bug: 68 | if year > 50: 69 | year = year + 1900 70 | else: 71 | year = year + 2000 72 | 73 | # seconds since epoch: 74 | t = (datetime.datetime(year, month, day, hour, minute, int(second), 75 | int(microsecond)) - 76 | datetime.datetime(1970,1,1)).total_seconds() 77 | 78 | return event_id, t 79 | 80 | def _parse_polarity_data(line_iter): 81 | """ 82 | 1-4 a4 station name 83 | 7 a1 polarity:U,u,+,D,d,or- 84 | 8 i1 quality: 0=good quality, 1=lower quality, etc 85 | 59-62 f4.1 source-station distance (km) 86 | 66-68 i3 takeoff angle 87 | 79-81 i3 azimuth 88 | 83-85 i3 takeoff angle uncertainty 89 | 87-89 i3 azimuth angle uncertainty 90 | """ 91 | 92 | station = [] 93 | polarity = [] 94 | quality = [] 95 | src_sta_dist = [] 96 | toa = [] 97 | azimuth = [] 98 | 99 | line = line_iter.next() 100 | while(line[0] != " "): 101 | cursor = 0 102 | 103 | 104 | # From HASH driver1.f: 105 | #30 continue 106 | # read (12,35) sname(k),pickpol(k),p_qual(k), 107 | # & qdist,ith,iaz,isthe,isazi 108 | #35 format (a4,2x,a1,i1,50x,f4.1,i3,10x,i3,1x,i3,1x,i3) 109 | # 110 | station.append(line[cursor:cursor+4]); cursor += 6 111 | 112 | pol = line[cursor:cursor+1]; cursor += 1 113 | if pol.lower() == 'd': 114 | polarity.append(-1) 115 | else: 116 | polarity.append(1) 117 | 118 | quality.append(int(line[cursor:cursor+1])); cursor += 51 119 | src_sta_dist.append(float(line[cursor:cursor+4])/10); cursor += 4 120 | 121 | toa.append(float(line[cursor:cursor+3])); cursor += 13 122 | azimuth.append(float(line[cursor:cursor+3])); cursor += 3 123 | 124 | line = line_iter.next() 125 | 126 | event_id = int(line) 127 | 128 | return event_id, [station, polarity, quality, src_sta_dist, toa, azimuth] 129 | 130 | 131 | def parse_phase_file(filename): 132 | """ 133 | files consist of header/data 134 | """ 135 | 136 | with open(filename,'r') as fp: 137 | lines = fp.readlines() 138 | 139 | polarity_data = {} 140 | event_time_map = {} 141 | line_iter = iter(lines) 142 | try: 143 | while(line_iter): 144 | ev_id, t = _parse_phase_header(line_iter) 145 | event_time_map[ev_id] = t 146 | ev_id, data = _parse_polarity_data(line_iter) 147 | polarity_data[ev_id] = (t, data) 148 | except: 149 | pass 150 | 151 | return polarity_data, event_time_map 152 | 153 | def parse_reverse(filename): 154 | data = genfromtxt(filename,dtype=[('station','S4'), 155 | ('start_t', 'S8'), 156 | ('end_t', 'S8')]) 157 | 158 | reverse = {} 159 | for dat in data: 160 | 161 | st = dat[1] 162 | 163 | if st != '0': 164 | year = int(st[:4]) 165 | month = int(st[4:6]) 166 | day = int(st[6:8]) 167 | else: 168 | year = 1900 169 | month = 1 170 | day = 1 171 | 172 | tstart = (datetime.datetime(year, month, day) - 173 | datetime.datetime(1970, 1, 1)).total_seconds() 174 | 175 | en = dat[2] 176 | 177 | if en != '0': 178 | year = int(en[:4]) 179 | month = int(en[4:6]) 180 | day = int(en[6:8]) 181 | else: 182 | year = 2100 183 | month = 1 184 | day = 1 185 | 186 | tend = (datetime.datetime(year, month, day) - 187 | datetime.datetime(1970, 1, 1)).total_seconds() 188 | 189 | reverse[dat[0]] = (tstart, tend) 190 | 191 | return reverse 192 | 193 | def reverse_polarity(reverse_data, polarity, event_time_map): 194 | 195 | for key, val in polarity.items(): 196 | t = event_time_map[key] 197 | 198 | t0 = val[0] 199 | stations = val[1][0] 200 | pol = val[1][1] 201 | 202 | updated_polarity = [] 203 | for sta, p in zip(stations,pol): 204 | 205 | if sta in reverse_data.keys(): 206 | 207 | if(t > reverse_data[sta][0] and 208 | t < reverse_data[sta][1]): 209 | #reverse the polarity: 210 | updated_polarity.append(p * -1) 211 | else: 212 | updated_polarity.append(p) 213 | 214 | else: 215 | updated_polarity.append(p) 216 | 217 | #update polarity 218 | polarity[key][1][1] = updated_polarity 219 | -------------------------------------------------------------------------------- /focal_mech/lib/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/blasscoc/FocalMechClassifier/8d54d5a19cea447c030ada596369e47e7f39d483/focal_mech/lib/__init__.py -------------------------------------------------------------------------------- /focal_mech/lib/classify_mechanism.py: -------------------------------------------------------------------------------- 1 | from numpy import (dot, array, sign, arccos, zeros, pi, c_, arctan2, 2 | sum, pi, sqrt, conjugate, logical_and, arcsin) 3 | from math import gamma 4 | 5 | from sklearn import svm 6 | 7 | from focal_mech.lib.sph_harm import sph_harm 8 | 9 | 10 | def kernel(x, y, degree=2, coeff=1): 11 | """ 12 | Evaluates the polynomial kernel used by sklearn, (x.dot(y) + coeff)^degree 13 | 14 | Parameters: 15 | ----------- 16 | :param x,y: cartesian coords. 17 | :param degree, coeff: the degree of the kernel, 2 and 1 respectively 18 | is adequate for iso, dc and clvd classification. 19 | """ 20 | return (dot(x,y) + coeff)**degree 21 | 22 | def classify(*args, **kwargs): 23 | """Parameters: 24 | ----------- 25 | :param args: (x, y, z, data) of each observation 26 | 27 | :param kwargs: kernel_degree and kernel_coeff parameterize the 28 | kernels, 2 and 1 respectively is adequate for iso, dc and clvd 29 | classification. 30 | 31 | Returns: 32 | -------- 33 | :rtype dual_coeff: dual coefficient 34 | :rtype theta: azimuth of the data point 35 | :rtype phi: polar angle of the data point 36 | 37 | Notes: 38 | ------ 39 | We're using the sklearn support vector machine to 40 | find a optimal seperating hyperplanes classifying the polarity of 41 | points on a sphere. Our particular choice of kernel can be shown 42 | to generate a expansion in terms of a basis spherical harmonics up 43 | to order equal to the kernel degree. 44 | 45 | Isotropic, double couple and clvd sources can be represented in 46 | this basis, which makes this a convenient expansion. 47 | 48 | """ 49 | 50 | if 'kernel_degree' in kwargs: 51 | kernel_degree = kwargs['kernel_degree'] 52 | else: 53 | kernel_degree = 2 54 | 55 | if 'kernel_coeff' in kwargs: 56 | kernel_coeff = kwargs['kernel_coeff'] 57 | else: 58 | kernel_coeff = 1 59 | 60 | x, y, z, data = args 61 | inputs = array([x.ravel(),y.ravel(),z.ravel()]).T 62 | classes = sign(data.ravel()) 63 | classes[classes<=0] = -1 64 | 65 | poly_svc = svm.SVC(kernel='poly', degree=kernel_degree, 66 | coef0=kernel_coeff, C=1.0).fit(inputs, classes) 67 | 68 | n_support = poly_svc.n_support_ 69 | if len(n_support) > 2: 70 | raise Exception("Not supported yet.") 71 | 72 | # \beta_0 73 | intercept = poly_svc.intercept_ 74 | 75 | # we only have classes : 1 or 0 (y_i ~ \pm 1) 76 | dual_coeff = poly_svc.dual_coef_[0,:] 77 | 78 | num_support = len(dual_coeff) 79 | 80 | #we need the angles of the support vectors: 81 | # measured from up - the colatitude 82 | theta = arccos(poly_svc.support_vectors_[:,2]) 83 | 84 | # the forward half, phi > 0 85 | phi = zeros(num_support) 86 | 87 | # phi the angle between [-pi,pi] measured as azimuth 88 | phi = arctan2(poly_svc.support_vectors_[:,1],poly_svc.support_vectors_[:,0]) 89 | 90 | in_sample = poly_svc.predict(c_[inputs]) 91 | 92 | return dual_coeff, phi, theta, intercept, in_sample 93 | 94 | def scholkopf_norm(elle,kernel_degree): 95 | # Scholkopf and Smola, page 113, eq 4.72 coefficient a_l,l > kernel_degree=0 96 | norm = ((2.0**(kernel_degree+1) * 97 | gamma(kernel_degree+1) * gamma(kernel_degree+1)) / 98 | (gamma(kernel_degree+2+elle) * gamma(kernel_degree+1-elle))) 99 | return norm 100 | 101 | def calc_00(intercept, kernel_degree=2): 102 | """ 103 | The hyper-plane is: 104 | f(x) = \sum( ... ) + \beta 105 | beta is the bias, which is the overlap with the 00 mode. 106 | """ 107 | norm = scholkopf_norm(0,kernel_degree) 108 | # from the addition theorem 109 | norm *= 4 * pi * 0.5 * sqrt(1.0/pi) 110 | 111 | return intercept / norm 112 | 113 | def calc_alm(dual_coeff, phi, theta, elle, emm, kernel_degree=2): 114 | """Computes the spectral content of the classifier function estimated by 115 | the support vector machine. 116 | 117 | Alm = 4\pi/(2l+1) * \sum_{i} \dual_coeff[i] a[elle] Y*_{elle,emm}(phi,theta) 118 | 119 | Parameters: 120 | ----------- 121 | 122 | :param dual_coeff : the lagrange multipliers * class (-1,1) output 123 | of the support vector machine. e.g. see sklearn.svm 124 | dual_coef_ 125 | 126 | :param phi: the azimuth of each observation 127 | :param theta: the polar angle of each observation 128 | 129 | :param elle: "l" as in (Y_lm), the degree degree of the spherical harmonic 130 | :param emm: "m" as in (Y_lm) the order of the spherical harmonic, -l<=m<= l 131 | 132 | :param kernel_degree: must be an integer, for the kernel used 133 | ( + 1)^d, use the default for focal mechanism 134 | classification. 135 | 136 | Returns: 137 | -------- 138 | :rtype Alm: A dict Alm[m,l] containing the spectrum in the sph_harm basis. 139 | 140 | Notes: 141 | ------ 142 | A kernel degree of 2 truncates the expansion l=2 and so is 143 | recommended for clvd, dc, iso classification. 144 | """ 145 | 146 | # l = elle, and the kernel degree is 2 147 | norm = scholkopf_norm(elle,kernel_degree) 148 | # from the addition theorem 149 | norm *= 4 * pi / (2.0 * elle + 1) 150 | 151 | # scipy does y_ml (with -l <= m <= l) 152 | # rather than y_lm (convention used in Jackson) 153 | return sum(conjugate(sph_harm(emm, elle, phi, theta) ) * dual_coeff) * norm 154 | 155 | def translate_to_sphharm(*args, **kwargs): 156 | """ 157 | 158 | Take the results of the classification (using kernels) and 159 | translate the result to a basis of spherical harmonics. 160 | 161 | :param args: pass the output of classify 162 | :rtype Alm: the spectrum of the classifier function. 163 | """ 164 | 165 | kernel_degree = kwargs.pop("kernel_degree",2) 166 | 167 | dual_coeff, phi, theta, intercept, _ = args 168 | 169 | # Scholkopf and Smola, page 113, eq 4.72 coefficient a_l, l>kernel_degree=0 170 | Alm = {} 171 | Alm[0,0] = calc_00(intercept) 172 | Alm[0,0] = Alm[0,0][0] 173 | for l in range(1,kernel_degree+1): 174 | for m in range(-l,l+1): 175 | Alm[(l,m)] = calc_alm(dual_coeff, phi, theta, l, m) 176 | 177 | return Alm 178 | 179 | -------------------------------------------------------------------------------- /focal_mech/lib/correlate.py: -------------------------------------------------------------------------------- 1 | 2 | from numpy import (pi, rad2deg, inner, array, zeros, mgrid, 3 | argmin) 4 | from scipy.linalg import norm 5 | from scipy.optimize import minimize 6 | 7 | from focal_mech.lib.sph_harm import WignerD2 8 | 9 | 10 | def _corr_shear(x, alm): 11 | """ 12 | Rotates the (13),(31) double couple source you can 13 | find in Ben-Menahem and Singh. Monopole, dipole 14 | terms for this source are zero. 15 | """ 16 | 17 | strike, dip, rake = x 18 | # Wigner is ZYZ Euler rotation, \gamma = -rake 19 | D = WignerD2(strike, dip, -rake).conjugate() 20 | # Template Spectrum : glm = (0, -1j, 0, -1j, 0) 21 | prop = (inner(D[:,3], alm) + inner(D[:,1], alm))*1j 22 | # Maximize, not minimize. 23 | return -norm(prop) 24 | 25 | def _scan_shear(alm): 26 | """ 27 | :param alm: Quadrupole components. 28 | 29 | Scans for the best starting point, the optimization 30 | can get stuck otherwise. 31 | """ 32 | 33 | # scan for a good starting point 34 | X, Y, Z = mgrid[0:2*pi:10j, 0:pi:10j, 0:2*pi:10j] 35 | x0s = zip(X.ravel(),Y.ravel(),Z.ravel()) 36 | res = [_corr_shear(x0, alm) for x0 in x0s] 37 | x0 = x0s[argmin(res)] 38 | 39 | print x0 40 | 41 | return x0 42 | 43 | def corr_shear(Alm): 44 | """ 45 | :param Alm: the spectrum of the classifier function. 46 | 47 | Scans for the best starting point, the optimization 48 | can get stuck otherwise. 49 | """ 50 | 51 | # correlation with iso, dipole is zero. 52 | alm = array([Alm[2,-2], Alm[2,-1], 53 | Alm[2,0], 54 | Alm[2,1],Alm[2,2]]) 55 | 56 | # pick a good starting point. 57 | x0 = _scan_shear(alm) 58 | 59 | f = lambda x : _corr_shear(x,alm) 60 | results = minimize(f, x0=x0, 61 | bounds=((0,2*pi), (0,pi), (0,2*pi))) 62 | 63 | return rad2deg(results.x), results.fun 64 | 65 | def corr_tensile(Alm): 66 | raise Exception("Method not implemented") 67 | -------------------------------------------------------------------------------- /focal_mech/lib/sph_harm.py: -------------------------------------------------------------------------------- 1 | from numpy import (pi, complex_, empty, mgrid, exp, sin, cos, zeros, 2 | sqrt, mod, amin, amax, where) 3 | from scipy.special import sph_harm as scipy_sph_harm 4 | 5 | 6 | def sph_harm(m, l, longi, colat): 7 | """ 8 | Adds the Cordon Shortly phase to the sph_harm. 9 | 10 | :parma m: order 11 | :param l: degree 12 | :param longi: longitude [0,2*pi] 13 | :param colat: colatitude [0,pi] 14 | """ 15 | cordon_shortley = (-1)**m 16 | return cordon_shortley * scipy_sph_harm(m, l, longi, colat) 17 | 18 | # removes amplitude from a radiation pattern 19 | def beachball(s): 20 | maxval= amax(amax(s)) 21 | minval= amin(amin(s)) 22 | return where(s>0,1,0) 23 | 24 | def get_sph_harm(resolution=(25,25)): 25 | """ Initialize a grid of template harmonic functions 26 | """ 27 | Nlong, Nlati = resolution 28 | 29 | longi, lati = mgrid[0:2*pi:(Nlati*1j), 0:pi:(Nlong*1j)] 30 | 31 | longi = longi.ravel() 32 | lati = lati.ravel() 33 | 34 | s_harm = empty(shape=(9,Nlong*Nlati), dtype=complex_) 35 | 36 | s_harm[0,:] = sph_harm(0, 0, longi, lati) 37 | 38 | s_harm[1,:] = sph_harm(-1, 1, longi, lati) 39 | s_harm[2,:] = sph_harm(0, 1, longi, lati) 40 | s_harm[3,:] = sph_harm(1, 1, longi, lati) 41 | 42 | s_harm[4,:] = sph_harm(-2, 2, longi, lati) 43 | s_harm[5,:] = sph_harm(-1, 2, longi, lati) 44 | s_harm[6,:] = sph_harm(0, 2, longi, lati) 45 | s_harm[7,:] = sph_harm(1, 2, longi, lati) 46 | s_harm[8,:] = sph_harm(2, 2, longi, lati) 47 | 48 | return longi, lati, s_harm 49 | 50 | def WignerD1(alpha, beta, gamma): 51 | """ 52 | Compute the Wigner-D matrix for l=1. 53 | 54 | Parameters - Euler angles 55 | :param alpha: strike 56 | :param beta: dip 57 | :param gamma: -rake 58 | 59 | Returns: 60 | -------- 61 | :rtype D: D^1_M'M(alpha,beta,gamma) : for -1 <= M <= 1 62 | """ 63 | 64 | D = zeros([3,3]) * complex(1,0) 65 | 66 | # exp(-i\alpha), exp(-i\gamma) 67 | neialp = exp(-complex(0,1)*alpha) 68 | neigam = exp(-complex(0,1)*gamma) 69 | # exp(i\alpha), exp(i\gamma) 70 | peialp = exp(complex(0,1)*alpha) 71 | peigam = exp(complex(0,1)*gamma) 72 | 73 | D[0,0] = neialp * 0.5 * (1.0 + cos(beta)) * neigam 74 | D[0,1] = -neialp * sin(beta) / sqrt(2.0) 75 | D[0,2] = neialp * 0.5 * (1.0 - cos(beta)) * peigam 76 | 77 | D[1,0] = sin(beta) * neigam / sqrt(2.0) 78 | D[1,1] = cos(beta) 79 | D[1,2] = -sin(beta) * peigam / sqrt(2.0) 80 | 81 | D[2,0] = peialp * 0.5 * (1.0 - cos(beta)) * neigam 82 | D[2,1] = peialp * sin(beta) / sqrt(2.0) 83 | D[2,2] = peialp * 0.5 * (1.0 + cos(beta)) * peigam 84 | 85 | return D 86 | 87 | def WignerD2(alpha, beta, gamma): 88 | """ 89 | Compute the wigner d matrix for l = 2. 90 | 91 | Parameters - Euler angles 92 | :param alpha: strike 93 | :param beta: dip 94 | :param gamma: -rake 95 | 96 | Returns: 97 | :rtype D: D^2_M'M(alpha,beta,gamma) : for -2<=M<= 2 98 | """ 99 | 100 | D = zeros([5,5]) * complex(1,0) 101 | 102 | # exp(-i\alpha), exp(-i\gamma) 103 | neialp2 = exp(-complex(0,2)*alpha) 104 | neigam2 = exp(-complex(0,2)*gamma) 105 | 106 | # exp(-i\alpha), exp(-i\gamma) 107 | neialp1 = exp(-complex(0,1)*alpha) 108 | neigam1 = exp(-complex(0,1)*gamma) 109 | 110 | # exp(-i\alpha), exp(-i\gamma) 111 | peialp1 = exp(complex(0,1)*alpha) 112 | peigam1 = exp(complex(0,1)*gamma) 113 | 114 | # exp(i\alpha), exp(i\gamma) 115 | peialp2 = exp(complex(0,2)*alpha) 116 | peigam2 = exp(complex(0,2)*gamma) 117 | 118 | D[0,0] = neialp2 * 0.25 * (1 + cos(beta)) * (1 + cos(beta)) * neigam2 119 | D[0,1] = -neialp2 * 0.5 * sin(beta) * (1 + cos(beta)) * neigam1 120 | D[0,2] = neialp2 * sqrt(3.0/8.0) * sin(beta) * sin(beta) 121 | D[0,3] = -neialp2 * 0.5 * sin(beta) * (1 - cos(beta)) * peigam1 122 | D[0,4] = neialp2 * 0.25 * (1 - cos(beta)) * (1 - cos(beta)) * peigam2 123 | 124 | D[1,0] = neialp1 * 0.5 * sin(beta) * (1 + cos(beta)) * neigam2 125 | D[1,1] = neialp1 * 0.5 * (2.0*cos(beta)**2 + cos(beta) - 1) * neigam1 126 | D[1,2] = -neialp1 * sqrt(3.0/2.0) * sin(beta) * cos(beta) 127 | D[1,3] = -neialp1 * 0.5 * (2.0*cos(beta)**2 - cos(beta) - 1) * peigam1 128 | D[1,4] = -neialp1 * 0.5 * sin(beta) * (1 - cos(beta)) * peigam2 129 | 130 | D[2,0] = sqrt(3.0/8.0) * sin(beta) * sin(beta) * neigam2 131 | D[2,1] = sqrt(3.0/2.0) * sin(beta) * cos(beta) * neigam1 132 | D[2,2] = 1.5 * cos(beta) * cos(beta) - 0.5 133 | D[2,3] = -sqrt(3.0/2.0) * sin(beta) * cos(beta) * peigam1 134 | D[2,4] = sqrt(3.0/8.0) * sin(beta) * sin(beta) * peigam2 135 | 136 | D[3,0] = peialp1 * 0.5 * sin(beta) * (1 - cos(beta)) * neigam2 137 | D[3,1] = -peialp1 * 0.5 * (2.0*cos(beta)**2 - cos(beta) - 1) * neigam1 138 | D[3,2] = peialp1 * sqrt(3.0/2.0) * sin(beta) * cos(beta) 139 | D[3,3] = peialp1 * 0.5 * (2.0*cos(beta)**2 + cos(beta) - 1) * peigam1 140 | D[3,4] = -peialp1 * 0.5 * sin(beta) * (1 + cos(beta)) * peigam2 141 | 142 | D[4,0] = peialp2 * 0.25 * (1 - cos(beta)) * (1 - cos(beta)) * neigam2 143 | D[4,1] = peialp2 * 0.5 * sin(beta) * (1 - cos(beta)) * neigam1 144 | D[4,2] = peialp2 * sqrt(3.0/8.0) * sin(beta) * sin(beta) 145 | D[4,3] = peialp2 * 0.5 * sin(beta) * (1 + cos(beta)) * peigam1 146 | D[4,4] = peialp2 * 0.25 * (1 + cos(beta)) * (1 + cos(beta)) * peigam2 147 | 148 | return D.conjugate() 149 | -------------------------------------------------------------------------------- /focal_mech/util/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/blasscoc/FocalMechClassifier/8d54d5a19cea447c030ada596369e47e7f39d483/focal_mech/util/__init__.py -------------------------------------------------------------------------------- /focal_mech/util/hash_routines.py: -------------------------------------------------------------------------------- 1 | from numpy import atleast_2d, sin, cos, hstack, sign, array, pi 2 | from focal_mech.io.read_hash import (parse_phase_file, parse_reverse, 3 | reverse_polarity) 4 | 5 | 6 | def hash_to_classifier(demo_data, parity=1): 7 | """ 8 | Convert the inputs taken from the HASH example datatsets 9 | and convert to something the classifier uses. 10 | 11 | Parameters 12 | 13 | :param demo_data: the output of read_demo. 14 | :param parity: Ensures the optimization will respect the 15 | symmetry of the solution. parity = 0, means 16 | there is no symmetry. For earthquakes use 17 | parity=1, to enforce conservation of 18 | momentum. 19 | """ 20 | 21 | inputs = {} 22 | for event, dat in demo_data.items(): 23 | # take off angles need to be "colatitude" measured from 24 | # Up 0-degrees, Down 180-degrees 25 | # The other angle needs to be azimuth 26 | x = atleast_2d(cos(dat[:,0])*sin(dat[:,1])) 27 | y = atleast_2d(sin(dat[:,0])*sin(dat[:,1])) 28 | z = atleast_2d(cos(dat[:,1])) 29 | 30 | classes = atleast_2d(dat[:,2]) 31 | if parity != 0: 32 | x = hstack((x,-x)) 33 | y = hstack((y,-y)) 34 | z = hstack((z,-z)) 35 | 36 | classes = hstack((classes, sign(parity)*classes)) 37 | 38 | inputs[event] = (x, y, z, classes) 39 | 40 | return inputs 41 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | from setuptools import setup, find_packages 2 | 3 | setup(name = "focal_mech", 4 | version = "0.1", 5 | author = "Ben Lasscock", 6 | author_email = "blasscoc@gmail.com", 7 | description = ("An Earthquake classifier."), 8 | packages=find_packages(), 9 | install_requires = ['numpy', 'scipy', 'matplotlib', 10 | 'mplstereonet', 11 | 'obspy']) 12 | 13 | 14 | --------------------------------------------------------------------------------