├── FMC_manual.pdf ├── jap_select.dat ├── functionsFMC.py ├── plotFMC.py ├── LICENSE └── FMC.py /FMC_manual.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jose-Alvarez/FMC/HEAD/FMC_manual.pdf -------------------------------------------------------------------------------- /jap_select.dat: -------------------------------------------------------------------------------- 1 | 149.27 44.12 28 1.01 -0.47 -0.54 1.68 1.85 -0.48 27 X Y 032378C 2 | 138.87 40.44 13 3.96 -0.85 -3.11 -1.01 -2.50 -0.81 27 X Y 052683A 3 | 143.08 39.95 24 0.61 -0.07 -0.55 0.56 1.10 -0.11 27 X Y 110189E 4 | 139.28 42.71 16 4.52 -0.29 -4.23 0.04 -1.58 0.02 27 X Y 071293B 5 | 142.99 40.56 28 1.73 0.13 -1.87 1.78 4.16 -0.43 27 X Y 122894C 6 | 150.17 44.82 26 3.11 -1.39 -1.72 4.87 5.79 -1.87 27 X Y 120395E 7 | 143.84 42.21 28 0.78 -0.41 -0.37 1.32 2.59 -0.66 28 X Y 092503C 8 | 137.00 32.94 16 0.67 -0.83 0.16 0.20 0.06 0.01 27 X Y 090504A 9 | 137.22 33.13 12 1.11 -1.77 0.66 -0.01 0.11 0.04 27 X Y 090504D 10 | 154.33 46.71 14 1.74 -0.56 -1.18 1.64 2.58 -0.77 28 X Y 200611151114A 11 | 154.80 46.17 12 -1.38 1.33 0.05 -0.27 -0.78 0.80 28 X Y 200701130423A 12 | 142.78 38.56 14 0.49 -0.02 -0.47 0.42 1.05 -0.13 27 X Y 201103090245A 13 | 143.05 37.52 20 1.73 -0.28 -1.45 2.12 4.55 -0.66 29 X Y 201103110546A 14 | 141.38 35.92 29 4.39 -0.31 -4.07 3.17 6.34 -1.97 27 X Y 201103110615A 15 | 144.63 38.27 21 -3.03 0.03 3.00 -0.41 -0.34 0.47 27 X Y 201103110625A 16 | 143.83 37.77 20 -0.65 -0.12 0.76 0.04 0.12 0.31 27 X Y 201212070818B 17 | -------------------------------------------------------------------------------- /functionsFMC.py: -------------------------------------------------------------------------------- 1 | # Defining functions for FMC 2 | # 3 | # FMC, Focal Mechanisms Classification 4 | # Copyright (C) 2015 Jose A. Alvarez-Gomez 5 | # 6 | # This program is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program. If not, see . 18 | # 19 | # 20 | # Some of this functions are python adaptations from the 21 | # Gasperini and Vannucci (2003) FORTRAN subroutines: 22 | # Gasperini P. and Vannucci G., FPSPACK: a package of simple Fortran subroutines 23 | # to manage earthquake focal mechanism data, Computers & Geosciences (2003) 24 | # 25 | # Version 1.01 26 | # Version 1.1 27 | # Including Hierarchical clustering 28 | # Version 1.2 29 | # Including slip sense and inmersion 30 | # Version 1.6 31 | # including functions for Hudson source type diamond diagram 32 | # Version 1.7 33 | # include functions to work with P, T orientations as input 34 | # Version 1.8 35 | # Include isotropic component ratio 36 | from numpy import diff, zeros, asarray, sin, cos, sqrt, dot, deg2rad, rad2deg, arccos, arcsin, arctan2, mod, where, linalg, trace, divide 37 | import scipy.cluster.hierarchy as hac 38 | 39 | 40 | def norm(wax, way, waz): 41 | """This function Computes Euclidean norm and normalized components of a vector.""" 42 | a = asarray((wax, way, waz)) 43 | anorm = sqrt(dot(a, a.conj())) 44 | if anorm == 0: 45 | ax = 0 46 | ay = 0 47 | az = 0 48 | else: 49 | ax = wax / anorm 50 | ay = way / anorm 51 | az = waz / anorm 52 | return ax, ay, az 53 | 54 | 55 | def ca2ax(wax, way, waz): 56 | """This function translates cartesian components to orientation""" 57 | 58 | (ax, ay, az) = norm(wax, way, waz) 59 | if az < 0: 60 | ax = -ax 61 | ay = -ay 62 | az = -az 63 | if ay != 0 or ax != 0: 64 | trend = rad2deg(arctan2(ay, ax)) 65 | else: 66 | trend = 0 67 | trend = mod(trend + 360, 360) 68 | plunge = rad2deg(arcsin(az)) 69 | return trend, plunge 70 | 71 | def ax2ca(trend, plunge): 72 | """This function translates orientation to cartesian components""" 73 | 74 | ax = cos(deg2rad(plunge))*cos(deg2rad(trend)) 75 | ay = cos(deg2rad(plunge))*sin(deg2rad(trend)) 76 | az = sin(deg2rad(plunge)) 77 | 78 | return ax, ay, az 79 | 80 | 81 | def nd2pl(wanx, wany, wanz, wdx, wdy, wdz): 82 | """This function computes plane orientation from outward normal and slip vectors""" 83 | (anX, anY, anZ) = norm(wanx, wany, wanz) 84 | (dx, dy, dz) = norm(wdx, wdy, wdz) 85 | 86 | if anZ > 0: 87 | anX = -anX 88 | anY = -anY 89 | anZ = -anZ 90 | dx = -dx 91 | dy = -dy 92 | dz = -dz 93 | if anZ == -1: 94 | wdelta = 0 95 | wphi = 0 96 | walam = arctan2(-dy, dx) 97 | else: 98 | wdelta = arccos(-anZ) 99 | wphi = arctan2(-anX, anY) 100 | walam = arctan2(-dz / sin(wdelta), dx * cos(wphi) + dy * sin(wphi)) 101 | 102 | phi = rad2deg(wphi) 103 | delta = rad2deg(wdelta) 104 | alam = rad2deg(walam) 105 | phi = mod(phi + 360, 360) 106 | dipdir = phi + 90 107 | dipdir = mod(dipdir + 360, 360) 108 | return phi, delta, alam, dipdir 109 | 110 | 111 | def pl2nd(strike, dip, rake): 112 | """ compute Cartesian components of outward normal and slip vectors from strike, dip and rake 113 | strike strike angle in degrees (INPUT) 114 | dip dip angle in degrees (INPUT) 115 | rake rake angle in degrees (INPUT) 116 | anx,any,anz components of fault plane outward normal vector in the 117 | Aki-Richards Cartesian coordinate system (OUTPUT) 118 | dx,dy,dz components of slip versor in the Aki-Richards 119 | Cartesian coordinate system (OUTPUT)""" 120 | 121 | wstrik = deg2rad(strike) 122 | wdip = deg2rad(dip) 123 | wrake = deg2rad(rake) 124 | 125 | anX = -sin(wdip) * sin(wstrik) 126 | anY = sin(wdip) * cos(wstrik) 127 | anZ = -cos(wdip) 128 | dx = cos(wrake) * cos(wstrik) + cos(wdip) * sin(wrake) * sin(wstrik) 129 | dy = cos(wrake) * sin(wstrik) - cos(wdip) * sin(wrake) * cos(wstrik) 130 | dz = -sin(wdip) * sin(wrake) 131 | 132 | return anX, anY, anZ, dx, dy, dz 133 | 134 | 135 | def pl2pl(strika, dipa, rakea): 136 | """Compute one nodal plane from the other.""" 137 | 138 | anX, anY, anZ, dx, dy, dz = pl2nd(strika, dipa, rakea) 139 | strikb, dipb, rakeb, dipdirb = nd2pl(dx, dy, dz, anX, anY, anZ) 140 | 141 | return strikb, dipb, rakeb, dipdirb 142 | 143 | 144 | def nd2pt(wanx, wany, wanz, wdx, wdy, wdz): 145 | """compute Cartesian component of P, T and B axes from outward normal and slip vectors.""" 146 | (anX, anY, anZ) = norm(wanx, wany, wanz) 147 | (dx, dy, dz) = norm(wdx, wdy, wdz) 148 | px = anX - dx 149 | py = anY - dy 150 | pz = anZ - dz 151 | (px, py, pz) = norm(px, py, pz) 152 | if pz < 0: 153 | px = -px 154 | py = -py 155 | pz = -pz 156 | tx = anX + dx 157 | ty = anY + dy 158 | tz = anZ + dz 159 | (tx, ty, tz) = norm(tx, ty, tz) 160 | if tz < 0: 161 | tx = -tx 162 | ty = -ty 163 | tz = -tz 164 | bx = py * tz - pz * ty 165 | by = pz * tx - px * tz 166 | bz = px * ty - py * tx 167 | if bz < 0: 168 | bx = -bx 169 | by = -by 170 | bz = -bz 171 | 172 | return px, py, pz, tx, ty, tz, bx, by, bz 173 | 174 | def pt2nd(wpx, wpy, wpz, wtx, wty, wtz): 175 | """compute outward normal and slip vectors from cartesian component of P and T axes.""" 176 | 177 | (px, py, pz) = norm(wpx, wpy, wpz) 178 | if pz < 0: 179 | px = -px 180 | py = -py 181 | pz = -pz 182 | 183 | (tx, ty, tz) = norm(wtx, wty, wtz) 184 | if tz < 0: 185 | tx = -tx 186 | ty = -ty 187 | tz = -tz 188 | 189 | anX = tx + px 190 | anY = ty + py 191 | anZ = tz + pz 192 | 193 | (anX, anY, anZ) = norm(anX, anY, anZ) 194 | 195 | dx = tx - px 196 | dy = ty - py 197 | dz = tz - pz 198 | (dx, dy, dz) = norm(dx, dy, dz) 199 | 200 | if anZ < 0: 201 | anX = -anX 202 | anY = -anY 203 | anZ = -anZ 204 | dx = -dx 205 | dy = -dy 206 | dz = -dz 207 | 208 | return anX, anY, anZ, dx, dy, dz 209 | 210 | def pt2pl(trendp, plungp, trendt, plungt): 211 | """compute strike dip and rake (and dip direction) of two nodal planes from trend and plung of P and T axes""" 212 | 213 | (px, py, pz) = ax2ca(trendp,plungp) 214 | (tx, ty, tz) = ax2ca(trendt,plungt) 215 | 216 | (anX, anY, anZ, dx, dy, dz) = pt2nd(px, py, pz, tx, ty, tz) 217 | (strika, dipa, rakea, dipdira) = nd2pl(anX, anY, anZ, dx, dy, dz) 218 | (strikb, dipb, rakeb, dipdirb) = nd2pl(dx, dy, dz, anX, anY, anZ) 219 | 220 | return strika, dipa, rakea, dipdira, strikb, dipb, rakeb, dipdirb 221 | 222 | def nd2ar(anX, anY, anZ, dx, dy, dz, am0): 223 | """Compute tensor components from outward normal and slip vectors.""" 224 | 225 | wanx, wany, wanz = norm(anX, anY, anZ) 226 | wdx, wdy, wdz = norm(dx, dy, dz) 227 | 228 | if am0 == 0: 229 | aam0 = 1.0 230 | else: 231 | aam0 = am0 232 | 233 | am = zeros((3, 3)) 234 | am[0][0] = aam0 * 2.0 * wdx * wanx 235 | am[0][1] = aam0 * (wdx * wany + wdy * wanx) 236 | am[1][0] = am[0][1] 237 | am[0][2] = aam0 * (wdx * wanz + wdz * wanx) 238 | am[2][0] = am[0][2] 239 | am[1][1] = aam0 * 2.0 * wdy * wany 240 | am[1][2] = aam0 * (wdy * wanz + wdz * wany) 241 | am[2][1] = am[1][2] 242 | am[2][2] = aam0 * 2.0 * wdz * wanz 243 | 244 | return am 245 | 246 | 247 | def ar2ha(am): 248 | """Translates tensor components between cartesian and Harvard convention.""" 249 | 250 | amo = zeros((3, 3)) 251 | amo[0][0] = am[0][0] 252 | amo[0][1] = -am[0][1] 253 | amo[0][2] = am[0][2] 254 | amo[1][0] = -am[1][0] 255 | amo[1][1] = am[1][1] 256 | amo[1][2] = -am[1][2] 257 | amo[2][0] = am[2][0] 258 | amo[2][1] = -am[2][1] 259 | amo[2][2] = am[2][2] 260 | 261 | return amo 262 | 263 | 264 | def slipinm(strike, dip, rake): 265 | """Computes slip vector orientation from a plane orientation.""" 266 | 267 | a = cos(deg2rad(rake)) * cos(deg2rad(strike)) + \ 268 | sin(deg2rad(rake)) * cos(deg2rad(dip)) * sin(deg2rad(strike)) 269 | b = -cos(deg2rad(rake)) * sin(deg2rad(strike)) + \ 270 | sin(deg2rad(rake)) * cos(deg2rad(dip)) * cos(deg2rad(strike)) 271 | slip = rad2deg(arctan2(-b, a)) 272 | slip = mod((slip) + 360, 360) 273 | inmer = rad2deg(arcsin(sin(deg2rad(rake)) * sin(deg2rad(dip)))) 274 | 275 | return slip, inmer 276 | 277 | 278 | def kave(plungt, plungb, plungp): 279 | """Computes x and y for the Kaverina diagram""" 280 | 281 | zt = sin(deg2rad(plungt)) 282 | zb = sin(deg2rad(plungb)) 283 | zp = sin(deg2rad(plungp)) 284 | L = 2 * sin(0.5 * arccos((zt + zb + zp) / sqrt(3))) 285 | N = sqrt(2 * ((zb - zp)**2 + (zb - zt)**2 + (zt - zp)**2)) 286 | x = sqrt(3) * (L / N) * (zt - zp) 287 | y = (L / N) * (2 * zb - zp - zt) 288 | return x, y 289 | 290 | 291 | def mecclass(plungt, plungb, plungp): 292 | """Classify the rupture as function of the axes plunges.""" 293 | 294 | 295 | plunges = asarray((plungp, plungb, plungt)) 296 | P = plunges[0] 297 | B = plunges[1] 298 | T = plunges[2] 299 | maxplung, axis = plunges.max(0), plunges.argmax(0) 300 | if maxplung >= 67.5: 301 | if axis == 0: # P max 302 | clase = 'N' # normal faulting 303 | elif axis == 1: # B max 304 | clase = 'SS' # strike-slip faulting 305 | elif axis == 2: # T max 306 | clase = 'R' # reverse faulting 307 | else: 308 | if axis == 0: # P max 309 | if B > T: 310 | clase = 'N-SS' # normal - strike-slip faulting 311 | else: 312 | clase = 'N' # normal faulting 313 | if axis == 1: # B max 314 | if P > T: 315 | clase = 'SS-N' # strike-slip - normal faulting 316 | else: 317 | clase = 'SS-R' # strike-slip - reverse faulting 318 | if axis == 2: # T max 319 | if B > P: 320 | clase = 'R-SS' # reverse - strike-slip faulting 321 | else: 322 | clase = 'R' # reverse faulting 323 | return clase 324 | 325 | 326 | def moment(am): 327 | """Computes scalar seismic moment, fclvd, deviatoric components, iso component and ratio, eigenvectors, and position on the Hudson diagram""" 328 | 329 | # To avoid problems with cosines 330 | ceros = where(am == 0) 331 | am[ceros] = 0.000001 332 | 333 | # Eigenvalues and Eigenvectors 334 | val, vect = linalg.eig(am) 335 | # Ordering of eigenvalues and eigenvectors (increasing eigenvalues) 336 | idx = val.argsort() 337 | val = val[idx] 338 | vect = vect[:, idx] 339 | 340 | # Tensor isotropic component 341 | e = trace(am) / 3 342 | dval = val - e 343 | iso = e 344 | 345 | # fclvd, seismic moment and Mw 346 | fclvd = (abs(val[1] / (max((abs(val[0])), (abs(val[2])))))) # from Frohlich and Apperson, 1992 347 | # am0 = (abs(val[0]) + abs(val[2])) / 2 # From Dziewonski et al., 1981 348 | am0 = sqrt((val[0]**2 + val[1]**2 + val[2]**2) / 2) # From Silver and Jordan, 1982 349 | fiso = iso/am0 350 | 351 | # u & v position in Hudson et al. (1989) skewed diamond from Vavrycuk (2014) 352 | maxiM = max(abs(val[0]),abs(val[1]),abs(val[2])) 353 | Ms = divide(val,maxiM) 354 | u = (-(2/3))*(Ms[2]+Ms[0]-2*Ms[1]) 355 | v = (1/3)*(Ms[0]+Ms[1]+Ms[2]) 356 | 357 | return am0, fclvd, dval, vect, iso, u, v, fiso 358 | 359 | 360 | def HC(data, meth, metr, num_clust): 361 | """# Mahalanobis Hierarchycal Clustering 362 | # data: the set of variables used to perform the clustering analysis 363 | # method: method to perform the HCA [single(default), complete, average, weighted, average, centroid, median, ward] 364 | # metric: the metric to perform the HCA [euclidean(default), mahalanobis] 365 | # num_clust: predefined number of clusters, if not present then it is 366 | # automatically computed with "diff".""" 367 | 368 | li = hac.linkage(data, method=meth, metric=metr) 369 | if num_clust == 0: 370 | knee = diff(li[::-1, 2], 2) 371 | num_clust = knee.argmax() + 2 372 | clustID = hac.fcluster(li, num_clust, 'maxclust') 373 | else: 374 | clustID = hac.fcluster(li, num_clust, 'maxclust') 375 | return clustID 376 | -------------------------------------------------------------------------------- /plotFMC.py: -------------------------------------------------------------------------------- 1 | # Plotting functions for FMC 2 | # 3 | # FMC, Focal Mechanisms Classification 4 | # Copyright (C) 2013 Jose A. Alvarez-Gomez 5 | # 6 | # This program is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program. If not, see . 18 | # 19 | # version 1.6 20 | # Diamond source-type diagram included 21 | # Some plot adjustments were done 22 | # version 1.9 23 | # The scale of the symbols now is adjusted to the magnitude range of the input data 24 | 25 | import matplotlib.pyplot as plt 26 | from numpy import zeros, sqrt, arcsin, pi, sin, squeeze, round 27 | from functionsFMC import kave 28 | 29 | plt.rc('pdf', fonttype=3) 30 | 31 | def baseplot(spacing, plotname): 32 | # border 33 | fig = plt.figure() 34 | plt.axes().set_aspect('equal') 35 | 36 | X = zeros((1, 101)) 37 | Y = zeros((1, 101)) 38 | for a in range(0, 101): 39 | P = arcsin(sqrt(a / 100.0)) / (pi / 180) 40 | B = 0.0 41 | T = arcsin(sqrt(1 - (a / 100.0))) / (pi / 180) 42 | X[0][a], Y[0][a] = kave(T, B, P) 43 | 44 | tickx, ticky = kave(range(90, -1, -10), zeros((1, 10)), range(0, 91, 10)) 45 | plt.plot(X[0], Y[0], color='black', linewidth=2) 46 | plt.scatter(tickx, ticky, marker=3, c='black', linewidth=2) 47 | for i in range(0, 10): 48 | plt.text( 49 | tickx[0][i], 50 | ticky[0][i] - 0.04, 51 | i * 10, 52 | fontsize=8, 53 | verticalalignment='top') 54 | plt.text( 55 | 0, 56 | -0.76, 57 | 'P axis plunge', 58 | fontsize=9, 59 | horizontalalignment='center') 60 | 61 | X = zeros((1, 101)) 62 | Y = zeros((1, 101)) 63 | for a in range(0, 101): 64 | B = arcsin(sqrt(a / 100.0)) / (pi / 180) 65 | P = 0.0 66 | T = arcsin(sqrt(1 - (a / 100.0))) / (pi / 180) 67 | X[0][a], Y[0][a] = kave(T, B, P) 68 | 69 | tickx, ticky = kave(zeros((1, 10)), range(0, 91, 10), range(90, -1, -10)) 70 | plt.plot(X[0], Y[0], color='black', linewidth=2) 71 | plt.scatter(tickx, ticky, marker=0, c='black', linewidth=2) 72 | for i in range(0, 10): 73 | plt.text( 74 | tickx[0][i] - 0.04, 75 | ticky[0][i], 76 | i * 10, 77 | fontsize=8, 78 | horizontalalignment='right') 79 | plt.text( 80 | -0.7, 81 | 0.2, 82 | 'B axis plunge', 83 | fontsize=9, 84 | horizontalalignment='center', 85 | rotation=60) 86 | 87 | X = zeros((1, 101)) 88 | Y = zeros((1, 101)) 89 | for a in range(0, 101): 90 | T = arcsin(sqrt(a / 100.0)) / (pi / 180) 91 | B = 0.0 92 | P = arcsin(sqrt(1 - (a / 100.0))) / (pi / 180) 93 | X[0][a], Y[0][a] = kave(T, B, P) 94 | 95 | tickx, ticky = kave(range(0, 91, 10), range(90, -1, -10), zeros((1, 10))) 96 | plt.plot(X[0], Y[0], color='black', linewidth=2) 97 | plt.scatter(tickx + 0.025, ticky, marker=0, c='black', linewidth=2) 98 | for i in range(0, 10): 99 | plt.text( 100 | tickx[0][i] + 0.04, 101 | ticky[0][i], 102 | i * 10, 103 | fontsize=8, 104 | horizontalalignment='left') 105 | plt.text( 106 | 0.7, 107 | 0.2, 108 | 'T axis plunge', 109 | fontsize=9, 110 | horizontalalignment='center', 111 | rotation=-60) 112 | 113 | X = zeros((1, 101)) 114 | Y = zeros((1, 101)) 115 | for a in range(0, 101): 116 | P = arcsin(sqrt(a / 100.0)) / (pi / 180) 117 | T = 0.0 118 | B = arcsin(sqrt(1 - (a / 100.0))) / (pi / 180) 119 | X[0][a], Y[0][a] = kave(T, B, P) 120 | 121 | plt.plot(X[0], Y[0], color='black', linewidth=2) 122 | 123 | # inner lines 124 | # class fields 125 | X = zeros((1, 51)) 126 | Y = zeros((1, 51)) 127 | for a in range(0, 51): 128 | B = arcsin(sqrt((a / 50.0) * 0.14645)) / (pi / 180) 129 | T = 67.5 130 | P = arcsin(sqrt((1 - (a / 50.0)) * 0.14645)) / (pi / 180) 131 | X[0][a], Y[0][a] = kave(T, B, P) 132 | 133 | xf = X[0][25] 134 | yf = Y[0][25] 135 | plt.plot([0, xf], [0, yf], color='grey', linewidth=1) 136 | plt.plot(X[0][25:51], Y[0][25:51], color='grey', linewidth=1) 137 | 138 | X = zeros((1, 51)) 139 | Y = zeros((1, 51)) 140 | for a in range(0, 51): 141 | B = arcsin(sqrt((a / 50.0) * 0.14645)) / (pi / 180) 142 | P = 67.5 143 | T = arcsin(sqrt((1 - (a / 50.0)) * 0.14645)) / (pi / 180) 144 | X[0][a], Y[0][a] = kave(T, B, P) 145 | 146 | xf = X[0][25] 147 | yf = Y[0][25] 148 | plt.plot([0, xf], [0, yf], color='grey', linewidth=1) 149 | plt.plot(X[0][25:51], Y[0][25:51], color='grey', linewidth=1) 150 | 151 | X = zeros((1, 51)) 152 | Y = zeros((1, 51)) 153 | for a in range(0, 51): 154 | T = arcsin(sqrt((a / 50.0) * 0.14645)) / (pi / 180) 155 | B = 67.5 156 | P = arcsin(sqrt((1 - (a / 50.0)) * 0.14645)) / (pi / 180) 157 | X[0][a], Y[0][a] = kave(T, B, P) 158 | 159 | plt.plot(X[0], Y[0], color='grey', linewidth=1) 160 | 161 | plt.plot([0, 0], [0.555221438, -0.605810893], color='grey', linewidth=1) 162 | plt.plot([0, 0.52481139], [0, 0.303], color='grey', linewidth=1) 163 | plt.plot([0, -0.52481139], [0, 0.303], color='grey', linewidth=1) 164 | # Labels 165 | plt.text(0, -0.9, plotname, horizontalalignment='center', fontsize=16) 166 | plt.text(-0.9, -0.5, 'Normal', horizontalalignment='right', fontsize=14) 167 | plt.text(0.9, -0.5, 'Reverse', horizontalalignment='left', fontsize=14) 168 | plt.text(0, 1, 'Strike-slip', horizontalalignment='center', fontsize=14) 169 | 170 | plt.axis('off') 171 | if spacing != 0: 172 | fig = grids(spacing, plotname) 173 | 174 | return fig 175 | 176 | 177 | def circles(X, Y, size, color, plotname, label, spacing): 178 | # working on it 179 | # computes min and max size to provide adecuate symbol scaling 180 | minval = min(size) 181 | maxval = max(size) 182 | minscale=20 183 | maxscale=140 184 | symb_size = [(minscale + (valor - minval) * (maxscale - minscale) / (maxval - minval)) for valor in size] 185 | 186 | fig = baseplot(spacing, plotname) 187 | if str(color) == 'white': 188 | sc = plt.scatter(X, Y, s=symb_size, c=color, alpha=0.7, linewidth=0.5, edgecolors='black') 189 | else: 190 | sc = plt.scatter( 191 | X, 192 | Y, 193 | s=symb_size, 194 | c=color, # AQUI HAY UN PROBLEMA AL UTILIZAR NUMEROS EN ID PARA COLOREAR PROBLEMA EN LA FUNCION COLOR DE matplotlib 3 195 | alpha=0.7, 196 | linewidth=0.5, 197 | edgecolors='black', 198 | cmap='plasma_r') 199 | cbar = plt.colorbar(sc, shrink=0.5) 200 | cbar.set_label(label) 201 | # legend 202 | plt.scatter(0.4, 0.9, s=20, c='white', linewidth=0.5, edgecolors='black') 203 | plt.scatter(0.5, 0.9, s=50, c='white', linewidth=0.5, edgecolors='black') 204 | plt.scatter(0.6, 0.9, s=80, c='white', linewidth=0.5, edgecolors='black') 205 | plt.scatter(0.7, 0.9, s=110, c='white', linewidth=0.5, edgecolors='black') 206 | plt.scatter(0.8, 0.9, s=140, c='white', linewidth=0.5, edgecolors='black') 207 | plt.text(0.4, .95, str(round(minval,1)).strip("'[]'"), fontsize=9, ha='center') 208 | plt.text(0.8, .95, str(round(maxval,1)).strip("'[]'"), fontsize=9, ha='center') 209 | plt.text(0.9, .95, 'Mw', fontsize=9) 210 | return fig 211 | 212 | 213 | def annot(X, Y, size, color, plotname, label, annots, lab_param, spacing): 214 | 215 | fig = circles(X, Y, size, color, plotname, label, spacing) 216 | for i, txt in enumerate(annots): 217 | plt.annotate( 218 | str(txt).strip(".'[]'"), 219 | (X[i] + 0.01, 220 | Y[i] + 0.01), 221 | horizontalalignment='left', 222 | verticalalignment='bottom', 223 | rotation=30, 224 | size='x-small') 225 | plt.text( 226 | 1.05, 227 | -0.75, 228 | 'Text label:\n' + str( 229 | lab_param).strip( 230 | "'[]'").replace( 231 | "_", 232 | " "), 233 | fontsize=10, 234 | horizontalalignment='center', 235 | verticalalignment='top') 236 | 237 | return fig 238 | 239 | 240 | def grids(spacing, plotname): 241 | for sp in range(0, 91, spacing): 242 | # B plunge gridlines 243 | compl = (sin((90 - sp) * (pi / 180)))**2 244 | X = zeros((1, 51)) 245 | Y = zeros((1, 51)) 246 | for a in range(0, 51): 247 | P = arcsin(sqrt((a / 50.0) * compl)) / (pi / 180) 248 | B = sp 249 | T = arcsin(sqrt((1 - (a / 50.0)) * compl)) / (pi / 180) 250 | X[0][a], Y[0][a] = kave(T, B, P) 251 | plt.plot(X[0], Y[0], color='gray', linewidth=0.5, linestyle='--') 252 | # P plunge gridlines 253 | compl = (sin((90 - sp) * (pi / 180)))**2 254 | X = zeros((1, 51)) 255 | Y = zeros((1, 51)) 256 | for a in range(0, 51): 257 | B = arcsin(sqrt((a / 50.0) * compl)) / (pi / 180) 258 | P = sp 259 | T = arcsin(sqrt((1 - (a / 50.0)) * compl)) / (pi / 180) 260 | X[0][a], Y[0][a] = kave(T, B, P) 261 | plt.plot(X[0], Y[0], color='gray', linewidth=0.5, linestyle='--') 262 | # T plunge gridlines 263 | compl = (sin((90 - sp) * (pi / 180)))**2 264 | X = zeros((1, 51)) 265 | Y = zeros((1, 51)) 266 | for a in range(0, 51): 267 | B = arcsin(sqrt((a / 50.0) * compl)) / (pi / 180) 268 | T = sp 269 | P = arcsin(sqrt((1 - (a / 50.0)) * compl)) / (pi / 180) 270 | X[0][a], Y[0][a] = kave(T, B, P) 271 | plt.plot(X[0], Y[0], color='gray', linewidth=0.5, linestyle='--') 272 | 273 | # Source type diagram, diamond skeewed from Hudson et al. (1989) 274 | def diamond_base(plotname): 275 | fig = plt.figure() 276 | plt.axes().set_aspect('equal') 277 | 278 | plt.plot([0,1.3333,0,-1.3333,0],[1,0.3333,-1,-0.3333,1],linewidth=2,color='black') # diagram limits 279 | plt.plot([-1,1],[0,0],linewidth=1,color='black') # horizontal line 280 | plt.plot([0,0],[-1,1],linewidth=1,color='black') # vertical line 281 | plt.plot([-1.3333,1.3333],[-0.3333,0.3333],linewidth=1,color='black',linestyle='--') # diagonal line 282 | 283 | plt.text(0, -1.4, plotname, horizontalalignment='center', fontsize=16) # figure title 284 | # Labels 285 | plt.text(0,-1.1,'Implosion', horizontalalignment='center', fontsize=10) 286 | plt.text(0,1.05,'Explosion', horizontalalignment='center', fontsize=10) 287 | plt.text(1.05,0,'CLVD (-)', horizontalalignment='left', verticalalignment='center', fontsize=10) 288 | plt.text(-1.05,0,'CLVD', horizontalalignment='right', verticalalignment='center', fontsize=10) 289 | 290 | plt.axis('off') 291 | 292 | return fig 293 | 294 | def diamond_circles(u, v, size, color, plotname, label): 295 | # computes min and max size to provide adecuate symbol scaling 296 | minval = min(size) 297 | maxval = max(size) 298 | minscale=20 299 | maxscale=100 300 | symb_size = [(minscale + (valor - minval) * (maxscale - minscale) / (maxval - minval)) for valor in size] 301 | 302 | fig = diamond_base(plotname) 303 | if str(color) == 'white': 304 | sc = plt.scatter(u, v, s=symb_size, c=color, alpha=0.7, linewidth=0.5, edgecolors='black') 305 | else: 306 | sc = plt.scatter( 307 | u, 308 | v, 309 | s=symb_size, 310 | c=color, # AQUI HAY UN PROBLEMA AL UTILIZAR NUMEROS EN ID PARA COLOREAR PROBLEMA EN LA FUNCION COLOR DE matplotlib 3 311 | alpha=0.7, 312 | linewidth=0.5, 313 | edgecolors='black', 314 | cmap='plasma_r') 315 | cbar = plt.colorbar(sc, shrink=0.5) 316 | cbar.set_label(label) 317 | 318 | # legend 319 | plt.scatter(0.4, 0.9, s=20, c='white', linewidth=0.5, edgecolors='black') 320 | plt.scatter(0.5, 0.9, s=40, c='white', linewidth=0.5, edgecolors='black') 321 | plt.scatter(0.6, 0.9, s=60, c='white', linewidth=0.5, edgecolors='black') 322 | plt.scatter(0.7, 0.9, s=80, c='white', linewidth=0.5, edgecolors='black') 323 | plt.scatter(0.8, 0.9, s=100, c='white', linewidth=0.5, edgecolors='black') 324 | plt.text(0.4, .97, str(round(minval,1)).strip("'[]'"), fontsize=9, ha='center') 325 | plt.text(0.8, .97, str(round(maxval,1)).strip("'[]'"), fontsize=9, ha='center') 326 | plt.text(0.9, .97, 'Mw', fontsize=9) 327 | return fig 328 | 329 | def diamond_annot(X, Y, size, color, plotname, label, annots, lab_param): 330 | 331 | fig = diamond_circles(X, Y, size, color, plotname, label) 332 | for i, txt in enumerate(annots): 333 | plt.annotate( 334 | str(txt).strip(".'[]'"), 335 | (X[i] + 0.01, 336 | Y[i] + 0.01), 337 | horizontalalignment='left', 338 | verticalalignment='bottom', 339 | rotation=30, 340 | size='x-small') 341 | plt.text( 342 | 1.7, 343 | -1.25, 344 | 'Text label:\n' + str( 345 | lab_param).strip( 346 | "'[]'").replace( 347 | "_", 348 | " "), 349 | fontsize=10, 350 | horizontalalignment='center', 351 | verticalalignment='top') 352 | 353 | return fig 354 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /FMC.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | # FMC, Focal Mechanisms Classification 4 | # Copyright (C) 2015 Jose A. Alvarez-Gomez 5 | # 6 | # 7 | # This program is free software: you can redistribute it and/or modify 8 | # it under the terms of the GNU General Public License as published by 9 | # the Free Software Foundation, either version 3 of the License, or 10 | # (at your option) any later version. 11 | # 12 | # This program is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | # GNU General Public License for more details. 16 | # 17 | # You should have received a copy of the GNU General Public License 18 | # along with this program. If not, see . 19 | # 20 | # Version 1.1 21 | # Including: 22 | # new output parsing 23 | # symbol coloring 24 | # Hierarchical clustering with several methods 25 | # 26 | # Version 1.2 27 | # Including: 28 | # Slip sense and inmersion optional output 29 | # 30 | # Version 1.3 31 | # Including: 32 | # Adapted to python 3 33 | # new plot options: labels, colors, grid 34 | # 35 | # Version 1.4 36 | # Including: 37 | # Bug correction 38 | # custom title 39 | # Isotropic component output 40 | # 41 | # Version 1.5 42 | # Including: 43 | # Bug correction 44 | # Warning for symbol filling 45 | # 46 | # Version 1.51 47 | # Including: 48 | # Correction on genfromtext 49 | # Adjustment of T and B axes labels 50 | # 51 | # Version 1.6 52 | # Including: 53 | # Hudson et al. (1989) source-type diagram with plotting options -pd 54 | # 55 | # Version 1.7 56 | # Including: 57 | # Input of P and T axes from strain tensors obtained with fault slip analysis 58 | # 59 | # Version 1.8 60 | # Including: 61 | # Isotropic component ratio output 62 | # 63 | # Version 1.9 64 | # Including: 65 | # Small code adaptation to define symbol plot sizes according to the data input magnitude range 66 | 67 | 68 | import sys 69 | import argparse 70 | from argparse import RawTextHelpFormatter, ArgumentParser 71 | from numpy import c_, vstack, array, zeros, asarray, genfromtxt, atleast_2d, shape, log10, array2string, isnan 72 | from functionsFMC import * 73 | from plotFMC import * 74 | 75 | # All the command line parser thing. 76 | parser = ArgumentParser(description='Focal mechanism process\ 77 | and classification.\nVersion 1.3', formatter_class=RawTextHelpFormatter) 78 | parser.add_argument('infile', nargs='?') 79 | parser.add_argument('-i', nargs=1, default=['CMT'], choices=['CMT', 'AR', 'P', 'PT'], 80 | help='Input file format.\n\ 81 | Choose between:\n\ 82 | [CMT]: Global CMT for psmeca (GMT) [default]\n\ 83 | [AR]: Aki and Richards for psmeca (GMT)\n\ 84 | [P]: Old Harvard CMT with both planes for psmeca (GMT)\n\ 85 | [PT]: Tensor P and T axes\n') 86 | parser.add_argument( 87 | '-o', nargs=1, default=['CMT'], choices=['CMT', 'P', 'AR', 'K', 'ALL', 'CUSTOM'], 88 | help='Output file format.\n\ 89 | Choose between:\n\ 90 | [CMT]: Global CMT for psmeca (GMT) [default]\n\ 91 | [P]: Old Harvard CMT with both planes for psmeca (GMT)\n\ 92 | [AR]: Aki and Richards for psmeca (GMT)\n\ 93 | [K]: X, Y positions for the Kaverina diagram with Mw, depth, ID and class\n\ 94 | [ALL]: A complete format file that outputs all the parameters computed\n\ 95 | [CUSTOM]: The outputs fields are given with the option -of [fields].\n\ 96 | Type "FMC.py -helpFields" to obtain information on the data fields \n\ 97 | that can be used and parsed as comma separated names.\n\ 98 | (see details on manual)\n ') 99 | parser.add_argument('-of', nargs='?', 100 | help='If present together with -o \'CUSTOM\' FMC will use the fields given as output.\n ') 101 | parser.add_argument('-p', metavar='[PlotFileName.pdf]', nargs='?', 102 | help='If present FMC will generate a plot with the DC classification diagram\n\ 103 | with the file format specified in the plot file name.\n ') 104 | parser.add_argument('-pd', metavar='[PlotFileName.pdf]', nargs='?', 105 | help='If present FMC will generate a plot with the source type classification diagram\n\ 106 | with the file format specified in the plot file name.\n ') 107 | parser.add_argument('-pc', nargs='?', 108 | help='If present FMC will use the specified parameter to fill the plotted\n\ 109 | circles with color in the classification diagram.\n\ 110 | Type "FMC.py -helpFields" to obtain information on the data fields\n\ 111 | that can be used.\n\ 112 | By default FMC uses white circles or, for the clustering, the cluster number.\n ') 113 | parser.add_argument('-pa', nargs='?', 114 | help='If present the program will plot labels with the selected parameter on the diagram plot.\n\ 115 | Type "FMC.py -helpFields" to obtain information on the data fields that can be used. \n ') 116 | parser.add_argument('-pg', nargs='?', 117 | help='If present the program will plot gridlines with the specified angular spacing on the diagram plot. [10 by default] \n ') 118 | parser.add_argument('-pt', nargs='?', 119 | help='If present the program will plot a title with the specified text on the diagram plot.\n\ 120 | If no text is given, or "-pt" is not set, then the output plot file name (without extension) is used by default.\n\ 121 | To omit the title just use the space character as text string -pt " ".\n ') 122 | parser.add_argument( 123 | '-cm', nargs='?', choices=['single', 'complete', 'average', 'weighted', 'centroid', 'median', 'ward'], 124 | help='If present FMC will perform a hierarchical clustering analysis\n\ 125 | of the focal mechanisms distribution on the Kaverina diagram\n\ 126 | with the method specified:\n\ 127 | [single]: single/min/nearest\n\ 128 | [complete]: complete/max/farthest point\n\ 129 | [average]: average/UPGMA\n\ 130 | [weighted]: weighted/WPGMA\n\ 131 | [centroid]: centroid/UPGMC [default]\n\ 132 | [median]: median/WPGMC\n\ 133 | [ward]: Ward\'s\n\n\ 134 | Methods centroid, median and ward are correctly defined only if "euclidean" metric is used.\n ') 135 | parser.add_argument( 136 | '-ce', nargs='?', choices=['braycurtis', 'canberra', 'chebyshev', 'cityblock', 'correlation', 'cosine', 137 | 'euclidean', 'hamming', 'jaccard', 'mahalanobis', 'minkowski', 'seuclidean', 'sqeuclidean'], 138 | help='If present FMC will perform a hierarchical clustering analysis of the focal\n\ 139 | mechanisms distribution on the Kaverina diagram with the metric specified.\n\ 140 | The algorithm uses the metrics available in the scipy.spatial.distance.pdist\n\ 141 | function which are listed below. By default FMC uses euclidean. \n\n\ 142 | The distance function can be braycurtis, canberra, chebyshev, cityblock, correlation,\n\ 143 | cosine, euclidean, hamming, jaccard, mahalanobis, minkowski, seuclidean, sqeuclidean.\n\n\ 144 | Please check the adequacy of your choice.\n\ 145 | As a rule of thumb if the parameters used to perform the clustering are all in\n\ 146 | the same units and equivalent magnitudes "euclidean" is a good choice.\n\ 147 | If you are using parameters in different units and magnitudes "mahalanobis" should work.\n ') 148 | parser.add_argument('-cn', nargs='?', 149 | help='If present FMC will perform a hierarchical clustering analysis\n\ 150 | of the focal mechanisms distribution on the Kaverina diagram\n\ 151 | with the number of clusters specified.\n\ 152 | if 0 [default] the minimum number of clusters is computed automatically.\n ') 153 | parser.add_argument('-ci', nargs='?', 154 | help='If present FMC will use the data given to perform the \n\ 155 | hierarchical clustering analysis of the focal mechanisms \n\ 156 | instead of the position on the Kaverina diagram, \n\ 157 | e.g. "-ci lon,lat" in order to perform a spatial clustering. \n\ 158 | Type "FMC.py -helpFields" to obtain information on the data fields \n\ 159 | that can be used and parsed as comma separated names.\n ') 160 | parser.add_argument('-v', action='count', 161 | help='If present the program will show additional processing information.\n ') 162 | parser.add_argument('-helpFields', action='count', 163 | help='If present the program will show information on the different\n\ 164 | parameters used or generated by FMC and will exit.\n ') 165 | 166 | args = parser.parse_args() 167 | args.outfile = sys.stdout 168 | 169 | if args.helpFields is not None: 170 | sys.stderr.write("Parameters used or generated by FMC: \n\n\ 171 | lon = longitude \n\ 172 | lat = latitude \n\ 173 | dep = depth \n\ 174 | mrr = mrr centroid moment tensor component \n\ 175 | mtt = mtt centroid moment tensor component \n\ 176 | mff = mff centroid moment tensor component \n\ 177 | mrt = mrt centroid moment tensor component \n\ 178 | mrf = mrf centroid moment tensor component \n\ 179 | mtf = mtf centroid moment tensor component \n\ 180 | mant = mantissa of the seismic moment tensor \n\ 181 | expo = exponent of the seismic moment tensor \n\ 182 | Mo = Scalar seismic moment \n\ 183 | Mw = Moment (or Kanamori) magnitude \n\ 184 | strA = Strike of nodal plane A \n\ 185 | dipA = Dip of nodal plane A \n\ 186 | rakeA = Rake of nodal plane A \n\ 187 | strB = Strike of nodal plane B \n\ 188 | dipB = Dip of nodal plane B \n\ 189 | rakeB = Rake of nodal plane B \n\ 190 | slipA = Slip trend of plane A \n\ 191 | plungA = Plunge of slip vector of plane A \n\ 192 | slipB = Slip trend of plane B \n\ 193 | plungB = Plunge of slip vector of plane B \n\ 194 | trendp = Trend of P axis \n\ 195 | plungp = Plunge of P axis \n\ 196 | trendb = Trend of B axis \n\ 197 | plungb = Plunge of B axis \n\ 198 | trendt = Trend of T axis \n\ 199 | plungt = Plunge of T axis \n\ 200 | fclvd = Compensated linear vector dipole ratio \n\ 201 | iso = Isotropic component of the Moment Tensor \n\ 202 | fiso = Isotropic component ratio \n\ 203 | u_Hudson = u position on the Hudson diagram \n\ 204 | v_Hudson = v position on the Hudson diagram \n\ 205 | x_kav = x position on the Kaverina diagram \n\ 206 | y_kav = y position on the Kaverina diagram \n\ 207 | ID = ID of the event \n\ 208 | clas = focal mechanism rupture type \n\ 209 | posX = X plotting position for GMT psmeca \n\ 210 | posY = Y plotting position for GMT psmeca \n\ 211 | clustID = ID number of cluster \n\ 212 | data1 = variable to represent any quantity to use with PT axes input \n\n") 213 | sys.exit(1) 214 | 215 | if args.infile: 216 | if args.v is not None: 217 | sys.stderr.write( 218 | ''.join( 219 | 'Working on input file ' + 220 | args.infile + 221 | '\n')) 222 | 223 | open(args.infile).read() 224 | elif not sys.stdin.isatty(): 225 | if args.v: 226 | sys.stderr.write('Working on standard input.\n') 227 | 228 | parser.add_argument( 229 | 'infile', 230 | nargs='*', 231 | type=argparse.FileType('r'), 232 | default=sys.stdin) 233 | args = parser.parse_args() 234 | args.outfile = sys.stdout 235 | 236 | else: 237 | parser.print_help() 238 | sys.exit(1) 239 | 240 | # check the python version to different genfromtext syntax 241 | 242 | if sys.version_info[0] == 2: 243 | data = genfromtxt(args.infile, dtype=None) 244 | 245 | elif sys.version_info[0] == 3: 246 | data = genfromtxt(args.infile, dtype=None, encoding=None) 247 | 248 | n_events = data.size 249 | if n_events == 1: 250 | data = atleast_2d(data)[0] 251 | fields = shape(data.dtype.names)[0] 252 | 253 | # Output data array generation 254 | lon_all = zeros((n_events, 1)) 255 | lat_all = zeros((n_events, 1)) 256 | dep_all = zeros((n_events, 1)) 257 | mrr_all = zeros((n_events, 1)) 258 | mtt_all = zeros((n_events, 1)) 259 | mff_all = zeros((n_events, 1)) 260 | mrt_all = zeros((n_events, 1)) 261 | mrf_all = zeros((n_events, 1)) 262 | mtf_all = zeros((n_events, 1)) 263 | mant_all = zeros((n_events, 1)) 264 | expo_all = zeros((n_events, 1)) 265 | Mo_all = zeros((n_events, 1)) 266 | Mw_all = zeros((n_events, 1)) 267 | strA_all = zeros((n_events, 1)) 268 | dipA_all = zeros((n_events, 1)) 269 | rakeA_all = zeros((n_events, 1)) 270 | strB_all = zeros((n_events, 1)) 271 | dipB_all = zeros((n_events, 1)) 272 | rakeB_all = zeros((n_events, 1)) 273 | slipA_all = zeros((n_events, 1)) 274 | plungA_all = zeros((n_events, 1)) 275 | slipB_all = zeros((n_events, 1)) 276 | plungB_all = zeros((n_events, 1)) 277 | trendp_all = zeros((n_events, 1)) 278 | plungp_all = zeros((n_events, 1)) 279 | trendb_all = zeros((n_events, 1)) 280 | plungb_all = zeros((n_events, 1)) 281 | trendt_all = zeros((n_events, 1)) 282 | plungt_all = zeros((n_events, 1)) 283 | fclvd_all = zeros((n_events, 1)) 284 | iso_all = zeros((n_events, 1)) 285 | fiso_all = zeros((n_events, 1)) 286 | u_Hudson_all = zeros((n_events, 1)) 287 | v_Hudson_all = zeros((n_events, 1)) 288 | x_kav_all = zeros((n_events, 1)) 289 | y_kav_all = zeros((n_events, 1)) 290 | ID_all = [None] * n_events 291 | #ID_all = zeros((n_events, 1),dtype="int8") 292 | clas_all = [None] * n_events 293 | posX_all = [None] * n_events 294 | posY_all = [None] * n_events 295 | clustID_all = [None] * n_events 296 | data1_all = zeros((n_events, 1)) 297 | 298 | # false clustID to initialize the variable 299 | clustID = 0 300 | 301 | for row in range(n_events): 302 | if args.i[0] == 'CMT': 303 | if fields != 13: 304 | sys.stderr.write( 305 | "ERROR - Incorrect number of columns (should be 13). - Program aborted") 306 | sys.exit(1) 307 | else: 308 | if args.v is not None: 309 | sys.stderr.write( 310 | ''.join( 311 | '\rProcessing ' + str( 312 | row + 1) + '/' + str( 313 | n_events) + ' focal mechanisms.')) 314 | 315 | lon = data[row][0] 316 | lat = data[row][1] 317 | dep = data[row][2] 318 | posX = data[row][10] 319 | posY = data[row][11] 320 | ID = data[row][12] 321 | 322 | # tensor matrix building 323 | expo = (data[row][9] * 1.0) 324 | mrr = data[row][3] * 10**expo 325 | mtt = data[row][4] * 10**expo 326 | mff = data[row][5] * 10**expo 327 | mrt = data[row][6] * 10**expo 328 | mrf = data[row][7] * 10**expo 329 | mtf = data[row][8] * 10**expo 330 | am = asarray(([mtt, -mtf, mrt], [-mtf, mff, -mrf], [mrt, -mrf, mrr])) 331 | 332 | # scalar moment and fclvd 333 | Mo, fclvd, val, vect, iso, u_Hudson, v_Hudson, fiso = moment(am) 334 | Mw = ((2.0 / 3.0) * log10(Mo)) - 10.733333 335 | mant_exp = ("%e" % Mo).split('e') 336 | mant = mant_exp[0] 337 | expo = mant_exp[1].strip('+') 338 | 339 | # Axis vectors 340 | px = vect[0, 0] 341 | py = vect[1, 0] 342 | pz = vect[2, 0] 343 | tx = vect[0, 2] 344 | ty = vect[1, 2] 345 | tz = vect[2, 2] 346 | bx = vect[0, 1] 347 | by = vect[1, 1] 348 | bz = vect[2, 1] 349 | 350 | # Axis trend and plunge 351 | trendp, plungp = ca2ax(px, py, pz) 352 | trendt, plungt = ca2ax(tx, ty, tz) 353 | trendb, plungb = ca2ax(bx, by, bz) 354 | 355 | # transforming axis reference 356 | px, py, pz = norm(px, py, pz) 357 | if pz < 0: 358 | px = -px 359 | py = -py 360 | pz = -pz 361 | tx, ty, tz = norm(tx, ty, tz) 362 | if tz < 0: 363 | tx = -tx 364 | ty = -ty 365 | tz = -tz 366 | anX = tx + px 367 | anY = ty + py 368 | anZ = tz + pz 369 | anX, anY, anZ = norm(anX, anY, anZ) 370 | dx = tx - px 371 | dy = ty - py 372 | dz = tz - pz 373 | dx, dy, dz = norm(dx, dy, dz) 374 | if anZ > 0: 375 | anX = -anX 376 | anY = -anY 377 | anZ = -anZ 378 | dx = -dx 379 | dy = -dy 380 | dz = -dz 381 | 382 | # Obtaining geometry of planes 383 | strA, dipA, rakeA, dipdir1 = nd2pl(anX, anY, anZ, dx, dy, dz) 384 | strB, dipB, rakeB, dipdir2 = nd2pl(dx, dy, dz, anX, anY, anZ) 385 | 386 | # Obtaining slip vectors 387 | slipA, plungA = slipinm(strA, dipA, rakeA) 388 | slipB, plungB = slipinm(strB, dipB, rakeB) 389 | 390 | # x, y Kaverina diagram 391 | x_kav, y_kav = kave(plungt, plungb, plungp) 392 | 393 | # Focal mechanism classification Alvarez-Gomez, 2009. 394 | clas = mecclass(plungt, plungb, plungp) 395 | 396 | data1=0 397 | 398 | elif args.i[0] == 'AR': 399 | if fields != 10: 400 | sys.stderr.write( 401 | "ERROR - Incorrect number of columns (should be 10). - Program aborted") 402 | sys.exit(1) 403 | else: 404 | if args.v is not None: 405 | sys.stderr.write( 406 | ''.join( 407 | '\rProcessing ' + str( 408 | row + 1) + '/' + str( 409 | n_events) + ' focal mechanisms.')) 410 | 411 | lon = data[row][0] 412 | lat = data[row][1] 413 | dep = data[row][2] 414 | posX = data[row][7] 415 | posY = data[row][8] 416 | ID = data[row][9] 417 | 418 | strA = (data[row][3]) 419 | dipA = (data[row][4]) 420 | rakeA = (data[row][5]) 421 | Mw = (data[row][6]) 422 | Mo = 10**(1.5 * (Mw + 10.7333333)) 423 | mant_exp = ("%e" % Mo).split('e') 424 | mant = mant_exp[0] 425 | expo = mant_exp[1].strip('+') 426 | 427 | anX, anY, anZ, dx, dy, dz = pl2nd(strA, dipA, rakeA) 428 | px, py, pz, tx, ty, tz, bx, by, bz = nd2pt(anX, anY, anZ, dx, dy, dz) 429 | strB, dipB, rakeB, dipdir2 = pl2pl(strA, dipA, rakeA) 430 | 431 | slipA, plungA = slipinm(strA, dipA, rakeA) 432 | slipB, plungB = slipinm(strB, dipB, rakeB) 433 | 434 | trendp, plungp = ca2ax(px, py, pz) 435 | trendt, plungt = ca2ax(tx, ty, tz) 436 | trendb, plungb = ca2ax(bx, by, bz) 437 | 438 | # moment tensor from P and T 439 | am = nd2ar(anX, anY, anZ, dx, dy, dz, Mo) 440 | am = ar2ha(am) 441 | mrr = am[2][2] 442 | mff = am[1][1] 443 | mtt = am[0][0] 444 | mrf = am[1][2] 445 | mrt = am[0][2] 446 | mtf = am[0][1] 447 | 448 | # scalar moment and fclvd 449 | Mo, fclvd, val, vect, iso, u_Hudson, v_Hudson, fiso = moment(am) 450 | 451 | # x, y Kaverina diagram 452 | x_kav, y_kav = kave(plungt, plungb, plungp) 453 | 454 | # Focal mechanism classification Alvarez-Gomez, 2009. 455 | clas = mecclass(plungt, plungb, plungp) 456 | data1=0 457 | 458 | elif args.i[0] == 'P': 459 | if fields != 14: 460 | sys.stderr.write( 461 | "ERROR - Incorrect number of columns (should be 14). - Program aborted") 462 | sys.exit(1) 463 | else: 464 | if args.v is not None: 465 | sys.stderr.write( 466 | ''.join( 467 | '\rProcessing ' + str( 468 | row + 1) + '/' + str( 469 | n_events) + ' focal mechanisms.')) 470 | 471 | lon = data[row][0] 472 | lat = data[row][1] 473 | dep = data[row][2] 474 | posX = data[row][11] 475 | posY = data[row][12] 476 | ID = data[row][13] 477 | 478 | strA = (data[row][3]) 479 | dipA = (data[row][4]) 480 | rakeA = (data[row][5]) 481 | strB = (data[row][6]) 482 | dipB = (data[row][7]) 483 | rakeB = (data[row][8]) 484 | 485 | mant = (data[row][9] * 1.0) 486 | expo = (data[row][10] * 1.0) 487 | Mo = mant * 10**expo 488 | Mw = ((2.0 / 3.0) * log10(Mo)) - 10.733333 489 | 490 | anX, anY, anZ, dx, dy, dz = pl2nd(strA, dipA, rakeA) 491 | px, py, pz, tx, ty, tz, bx, by, bz = nd2pt(anX, anY, anZ, dx, dy, dz) 492 | 493 | slipA, plungA = slipinm(strA, dipA, rakeA) 494 | slipB, plungB = slipinm(strB, dipB, rakeB) 495 | 496 | trendp, plungp = ca2ax(px, py, pz) 497 | trendt, plungt = ca2ax(tx, ty, tz) 498 | trendb, plungb = ca2ax(bx, by, bz) 499 | 500 | # moment tensor from P and T 501 | am = nd2ar(anX, anY, anZ, dx, dy, dz, Mo) 502 | am = ar2ha(am) 503 | mrr = am[2][2] 504 | mff = am[1][1] 505 | mtt = am[0][0] 506 | mrf = am[1][2] 507 | mrt = am[0][2] 508 | mtf = am[0][1] 509 | 510 | # scalar moment and fclvd 511 | Mo, fclvd, val, vect, iso, u_Hudson, v_Hudson, fiso = moment(am) 512 | 513 | # x, y Kaverina diagram 514 | x_kav, y_kav = kave(plungt, plungb, plungp) 515 | 516 | # Focal mechanism classification Alvarez-Gomez, 2009. 517 | clas = mecclass(plungt, plungb, plungp) 518 | data1=0 519 | 520 | elif args.i[0] == 'PT': # to work with tensors obtained from fault slip analysis 521 | if fields != 10: 522 | sys.stderr.write( 523 | "ERROR - Incorrect number of columns (should be 10). - Program aborted") 524 | sys.exit(1) 525 | else: 526 | if args.v is not None: 527 | sys.stderr.write( 528 | ''.join( 529 | '\rProcessing ' + str( 530 | row + 1) + '/' + str( 531 | n_events) + ' focal mechanisms.')) 532 | lon = data[row][0] 533 | lat = data[row][1] 534 | trendp = data[row][2] 535 | plungp = data[row][3] 536 | trendt = data[row][4] 537 | plungt = data[row][5] 538 | data1 = data[row][6] 539 | posX = data[row][7] 540 | posY = data[row][8] 541 | ID = data[row][9] 542 | 543 | strA, dipA, rakeA, dipdirA, strB, dipB, rakeB, dipdirB = pt2pl(trendp, plungp, trendt, plungt) 544 | 545 | anX, anY, anZ, dx, dy, dz = pl2nd(strA, dipA, rakeA) 546 | px, py, pz, tx, ty, tz, bx, by, bz = nd2pt(anX, anY, anZ, dx, dy, dz) 547 | 548 | slipA, plungA = slipinm(strA, dipA, rakeA) 549 | slipB, plungB = slipinm(strB, dipB, rakeB) 550 | 551 | trendb, plungb = ca2ax(bx, by, bz) 552 | 553 | # moment tensor from P and T 554 | Mo = 1E20 # fake scalar moment 555 | expo = 20 # fake exponent 556 | mant = 1 # fake mantissa 557 | Mw = 8 # fake Mw 558 | dep = 0 # fake depth 559 | 560 | am = nd2ar(anX, anY, anZ, dx, dy, dz, Mo) 561 | am = ar2ha(am) 562 | mrr = am[2][2] 563 | mff = am[1][1] 564 | mtt = am[0][0] 565 | mrf = am[1][2] 566 | mrt = am[0][2] 567 | mtf = am[0][1] 568 | 569 | # scalar moment and fclvd 570 | Mo, fclvd, val, vect, iso, u_Hudson, v_Hudson, fiso = moment(am) 571 | 572 | # x, y Kaverina diagram 573 | x_kav, y_kav = kave(plungt, plungb, plungp) 574 | 575 | # Focal mechanism classification Alvarez-Gomez, 2009. 576 | clas = mecclass(plungt, plungb, plungp) 577 | 578 | else: 579 | sys.stderr.write('Error, input file format should be G or P.') 580 | sys.exit(1) 581 | 582 | # storing data for the plot 583 | lon_all[row] = "%g" % (lon) 584 | lat_all[row] = "%g" % (lat) 585 | dep_all[row] = dep 586 | mrr_all[row] = "%g" % (mrr / (10**(int(expo)))) 587 | mtt_all[row] = "%g" % (mtt / (10**(int(expo)))) 588 | mff_all[row] = "%g" % (mff / (10**(int(expo)))) 589 | mrt_all[row] = "%g" % (mrt / (10**(int(expo)))) 590 | mrf_all[row] = "%g" % (mrf / (10**(int(expo)))) 591 | mtf_all[row] = "%g" % (mtf / (10**(int(expo)))) 592 | mant_all[row] = mant 593 | expo_all[row] = expo 594 | Mo_all[row] = "%g" % (Mo) 595 | Mw_all[row] = "%.1f" % (Mw) 596 | strA_all[row] = "%g" % (strA) 597 | dipA_all[row] = "%g" % (dipA) 598 | rakeA_all[row] = "%g" % (rakeA) 599 | strB_all[row] = "%g" % (strB) 600 | dipB_all[row] = "%g" % (dipB) 601 | rakeB_all[row] = "%g" % (rakeB) 602 | slipA_all[row] = "%g" % (slipA) 603 | plungA_all[row] = "%g" % (plungA) 604 | slipB_all[row] = "%g" % (slipB) 605 | plungB_all[row] = "%g" % (plungB) 606 | trendp_all[row] = "%g" % (trendp) 607 | plungp_all[row] = "%g" % (plungp) 608 | trendb_all[row] = "%g" % (trendb) 609 | plungb_all[row] = "%g" % (plungb) 610 | trendt_all[row] = "%g" % (trendt) 611 | plungt_all[row] = "%g" % (plungt) 612 | fclvd_all[row] = "%g" % (fclvd) 613 | iso_all[row] = "%g" % (iso) 614 | fiso_all[row] = "%g" % (fiso) 615 | u_Hudson_all[row] = "%g" % (u_Hudson) 616 | v_Hudson_all[row] = "%g" % (v_Hudson) 617 | x_kav_all[row] = "%g" % (x_kav) 618 | y_kav_all[row] = "%g" % (y_kav) 619 | ID_all[row] = ID 620 | # ID_all[row] = "%g" % (ID) 621 | clas_all[row] = clas 622 | posX_all[row] = posX 623 | posY_all[row] = posY 624 | clustID_all[row] = clustID 625 | data1_all[row] = data1 626 | 627 | 628 | r = row + 1 629 | 630 | lonH = vstack(((['Longitude']), (array(lon_all, dtype=object)))) 631 | latH = vstack(((['Latitude']), (array(lat_all, dtype=object)))) 632 | depH = vstack(((['Depth_(km)']), (array(dep_all, dtype=object)))) 633 | mrrH = vstack(((['mrr']), (array(mrr_all, dtype=object)))) 634 | mttH = vstack(((['mtt']), (array(mtt_all, dtype=object)))) 635 | mffH = vstack(((['mff']), (array(mff_all, dtype=object)))) 636 | mrtH = vstack(((['mrt']), (array(mrt_all, dtype=object)))) 637 | mrfH = vstack(((['mrf']), (array(mrf_all, dtype=object)))) 638 | mtfH = vstack(((['mtf']), (array(mtf_all, dtype=object)))) 639 | mantH = vstack( 640 | ((['Seismic_moment_mantissa']), (array(mant_all, dtype=object)))) 641 | expoH = vstack(((['Exponent_(dyn-cm)']), (array(expo_all, dtype=object)))) 642 | MoH = vstack(((['Seismic_moment_Mo']), (array(Mo_all, dtype=object)))) 643 | MwH = vstack(((['Magnitude_Mw']), (array(Mw_all, dtype=object)))) 644 | strAH = vstack(((['Strike_A']), (array(strA_all, dtype=object)))) 645 | dipAH = vstack(((['Dip_A']), (array(dipA_all, dtype=object)))) 646 | rakeAH = vstack(((['Rake_A']), (array(rakeA_all, dtype=object)))) 647 | strBH = vstack(((['Strike_B']), (array(strB_all, dtype=object)))) 648 | dipBH = vstack(((['Dip_B']), (array(dipB_all, dtype=object)))) 649 | rakeBH = vstack(((['Rake_B']), (array(rakeB_all, dtype=object)))) 650 | slipAH = vstack(((['Slip_trend_A']), (array(slipA_all, dtype=object)))) 651 | plungAH = vstack(((['Slip_plunge_A']), (array(plungA_all, dtype=object)))) 652 | slipBH = vstack(((['Slip_trend_B']), (array(slipB_all, dtype=object)))) 653 | plungBH = vstack(((['Slip_plunge_B']), (array(plungB_all, dtype=object)))) 654 | trendpH = vstack(((['Trend_P']), (array(trendp_all, dtype=object)))) 655 | plungpH = vstack(((['Plunge_P']), (array(plungp_all, dtype=object)))) 656 | trendbH = vstack(((['Trend_B']), (array(trendb_all, dtype=object)))) 657 | plungbH = vstack(((['Plunge_B']), (array(plungb_all, dtype=object)))) 658 | trendtH = vstack(((['Trend_T']), (array(trendt_all, dtype=object)))) 659 | plungtH = vstack(((['Plunge_T']), (array(plungt_all, dtype=object)))) 660 | fclvdH = vstack(((['fclvd']), (array(fclvd_all, dtype=object)))) 661 | isoH = vstack(((['Isotropic']), (array(iso_all, dtype=object)))) 662 | fisoH = vstack(((['Iso_ratio']), (array(fiso_all, dtype=object)))) 663 | u_HudsonH = vstack(((['u_Hudson']), (array(u_Hudson_all, dtype=object)))) 664 | v_HudsonH = vstack(((['v_Hudson']), (array(v_Hudson_all, dtype=object)))) 665 | x_kavH = vstack(((['X_Kaverina']), (array(x_kav_all, dtype=object)))) 666 | y_kavH = vstack(((['Y_Kaverina']), (array(y_kav_all, dtype=object)))) 667 | IDH = vstack(((['ID']), (array(ID_all).reshape((n_events, 1))))) 668 | clasH = vstack(((['rupture_type']), (array(clas_all).reshape((n_events, 1))))) 669 | posXH = vstack( 670 | ((['X_position(GMT)']), (array(posX_all).reshape((n_events, 1))))) 671 | posYH = vstack( 672 | ((['Y_position(GMT)']), (array(posY_all).reshape((n_events, 1))))) 673 | clustIDH = vstack(((['clustID']), (array(clustID_all).reshape((n_events, 1))))) 674 | data1H = vstack(((['data1']), (array(data1_all).reshape((n_events, 1))))) 675 | 676 | dict_all = { 677 | 'lon': lon_all, 678 | 'lat': lat_all, 679 | 'dep': dep_all, 680 | 'mrr': mrr_all, 681 | 'mtt': mtt_all, 682 | 'mff': mff_all, 683 | 'mrt': mrt_all, 684 | 'mrf': mrf_all, 685 | 'mtf': mtf_all, 686 | 'mant': mant_all, 687 | 'expo': expo_all, 688 | 'Mo': Mo_all, 689 | 'Mw': Mw_all, 690 | 'strA': strA_all, 691 | 'dipA': dipA_all, 692 | 'rakeA': rakeA_all, 693 | 'strB': strB_all, 694 | 'dipB': dipB_all, 695 | 'rakeB': rakeB_all, 696 | 'slipA': slipA_all, 697 | 'plungA': plungA_all, 698 | 'slipB': slipB_all, 699 | 'plungB': plungB_all, 700 | 'trendp': trendp_all, 701 | 'plungp': plungp_all, 702 | 'trendb': trendb_all, 703 | 'plungb': plungb_all, 704 | 'trendt': trendt_all, 705 | 'plungt': plungt_all, 706 | 'fclvd': fclvd_all, 707 | 'iso': iso_all, 708 | 'fiso': fiso_all, 709 | 'u_Hudson': u_Hudson_all, 710 | 'v_Hudson': v_Hudson_all, 711 | 'x_kav': x_kav_all, 712 | 'y_kav': y_kav_all, 713 | 'ID': ID_all, 714 | 'clas': clas_all, 715 | 'posX': posX_all, 716 | 'posY': posY_all, 717 | 'clustID': clustID_all, 718 | 'data1': data1_all} 719 | 720 | if args.v is not None: 721 | sys.stderr.write('\n') 722 | 723 | if args.cn is None and args.cm is None and args.ce is None and args.ci is None: 724 | clustering = 'FALSE' 725 | else: 726 | if args.cm is None: 727 | method = 'centroid' 728 | else: 729 | method = args.cm 730 | 731 | if args.ce is None: 732 | metric = 'euclidean' 733 | else: 734 | metric = args.ce 735 | 736 | if args.cn is None: 737 | num_clust = 0 738 | else: 739 | num_clust = int(args.cn) 740 | 741 | if args.ci: 742 | if "," in args.ci: 743 | labels = ('%s' % args.ci).split(",") 744 | nl = len(labels) - 1 745 | for l in labels: 746 | if 'cl_input' in locals(): 747 | cl_input = c_[cl_input, dict_all[l]] 748 | else: 749 | cl_input = dict_all[l] 750 | else: 751 | cl_input = dict_all[args.ci] 752 | else: 753 | cl_input = c_[x_kav_all, y_kav_all] 754 | 755 | clustID = HC(cl_input, method, metric, num_clust) 756 | clustID = (array(clustID).reshape((n_events, 1))) 757 | clustIDH = vstack( 758 | ((['Cluster_ID']), (clustID))) 759 | clustering = 'TRUE' 760 | 761 | dict_H = { 762 | 'lon': lonH, 763 | 'lat': latH, 764 | 'dep': depH, 765 | 'mrr': mrrH, 766 | 'mtt': mttH, 767 | 'mff': mffH, 768 | 'mrt': mrtH, 769 | 'mrf': mrfH, 770 | 'mtf': mtfH, 771 | 'mant': mantH, 772 | 'expo': expoH, 773 | 'Mo': MoH, 774 | 'Mw': MwH, 775 | 'strA': strAH, 776 | 'dipA': dipAH, 777 | 'rakeA': rakeAH, 778 | 'strB': strBH, 779 | 'dipB': dipBH, 780 | 'rakeB': rakeBH, 781 | 'slipA': slipAH, 782 | 'plungA': plungAH, 783 | 'slipB': slipBH, 784 | 'plungB': plungBH, 785 | 'trendp': trendpH, 786 | 'plungp': plungpH, 787 | 'trendb': trendbH, 788 | 'plungb': plungbH, 789 | 'trendt': trendtH, 790 | 'plungt': plungtH, 791 | 'fclvd': fclvdH, 792 | 'iso': isoH, 793 | 'fiso': fisoH, 794 | 'u_Hudson': u_HudsonH, 795 | 'v_Hudson': v_HudsonH, 796 | 'x_kav': x_kavH, 797 | 'y_kav': y_kavH, 798 | 'ID': IDH, 799 | 'clas': clasH, 800 | 'posX': posXH, 801 | 'posY': posYH, 802 | 'clustID': clustIDH, 803 | 'data1': data1H} 804 | 805 | #~ output 806 | if args.o[0] == 'CMT': 807 | outdata = c_[ 808 | lonH, 809 | latH, 810 | depH, 811 | mrrH, 812 | mttH, 813 | mffH, 814 | mrtH, 815 | mrfH, 816 | mtfH, 817 | expoH, 818 | posXH, 819 | posYH, 820 | IDH, 821 | clasH] 822 | if clustering == 'TRUE': 823 | outdata = c_[outdata, clustIDH] 824 | 825 | elif args.o[0] == 'P': 826 | outdata = c_[ 827 | lonH, 828 | latH, 829 | depH, 830 | strAH, 831 | dipAH, 832 | rakeAH, 833 | strBH, 834 | dipBH, 835 | rakeBH, 836 | mantH, 837 | expoH, 838 | posXH, 839 | posYH, 840 | IDH, 841 | clasH] 842 | if clustering == 'TRUE': 843 | outdata = c_[outdata, clustIDH] 844 | 845 | elif args.o[0] == 'AR': 846 | outdata = c_[ 847 | lonH, 848 | latH, 849 | depH, 850 | strAH, 851 | dipAH, 852 | rakeAH, 853 | MwH, 854 | posXH, 855 | posYH, 856 | IDH, 857 | clasH] 858 | if clustering == 'TRUE': 859 | outdata = c_[outdata, clustIDH] 860 | 861 | elif args.o[0] == 'K': 862 | outdata = c_[x_kavH, y_kavH, MwH, depH, IDH, clasH] 863 | if clustering == 'TRUE': 864 | outdata = c_[outdata, clustIDH] 865 | 866 | elif args.o[0] == 'ALL': 867 | outdata = c_[ 868 | lonH, 869 | latH, 870 | depH, 871 | mrrH, 872 | mttH, 873 | mffH, 874 | mrtH, 875 | mrfH, 876 | mtfH, 877 | expoH, 878 | MoH, 879 | MwH, 880 | strAH, 881 | dipAH, 882 | rakeAH, 883 | strBH, 884 | dipBH, 885 | rakeBH, 886 | slipAH, 887 | plungAH, 888 | slipBH, 889 | plungBH, 890 | trendpH, 891 | plungpH, 892 | trendbH, 893 | plungbH, 894 | trendtH, 895 | plungtH, 896 | fclvdH, 897 | isoH, 898 | fisoH, 899 | u_HudsonH, 900 | v_HudsonH, 901 | x_kavH, 902 | y_kavH, 903 | IDH, 904 | clasH] 905 | if clustering == 'TRUE': 906 | outdata = c_[outdata, clustIDH] 907 | 908 | elif args.o[0] == 'CUSTOM': 909 | if "," in args.of: 910 | labels = ('%s' % args.of).split(",") 911 | nl = len(labels) - 1 912 | for l in labels: 913 | if 'outdata' in locals(): 914 | outdata = c_[outdata, dict_H[l]] 915 | else: 916 | outdata = dict_H[l] 917 | else: 918 | outdata = dict_H[args.of] 919 | 920 | outdata[0][0] = "#" + outdata[0][0] 921 | args.outfile.write( 922 | '\n'.join(str(e).strip("[]").replace("'", '').replace('\n', '') for e in outdata)) 923 | print ("") 924 | 925 | # diagram FMC plot 926 | 927 | if args.p: 928 | if args.pc: 929 | # if args.pc == 'ID' or args.pc == 'posX' or args.pc == 'posY' or args.pc == 'clas': 930 | if args.pc == 'posX' or args.pc == 'posY' or args.pc == 'clas': 931 | sys.stderr.write('\nWarning, to fill the symbols a numeric value is needed.\n') 932 | color = 'white' 933 | label = 'nada' 934 | else: 935 | color = dict_all[args.pc] 936 | label = str(dict_H[args.pc][0]).strip( 937 | "[]").replace("'", '').replace("_", " ") 938 | else: 939 | if clustering == 'TRUE': 940 | color = clustID 941 | # color = (dict_all['clustID']) # tratando de solventar el problema de colorear con los ID de cluster en python3 942 | label = 'Clust ID' 943 | else: 944 | color = 'white' 945 | label = 'nada' 946 | 947 | if args.pg: 948 | gridspacing = int(args.pg) 949 | else: 950 | gridspacing = 0 951 | 952 | if args.pt: 953 | plotname = args.pt 954 | else: 955 | plotname = args.p.split('.')[0] 956 | 957 | # ---------------------------------- 958 | 959 | if args.pa: 960 | dotlabel = dict_all[args.pa] 961 | lab_param = dict_H[args.pa][0] 962 | fig = annot( 963 | x_kav_all, 964 | y_kav_all, 965 | Mw_all, 966 | color, 967 | plotname, 968 | label, 969 | dotlabel, 970 | lab_param, 971 | gridspacing) 972 | else: 973 | fig = circles( 974 | x_kav_all, 975 | y_kav_all, 976 | Mw_all, 977 | color, 978 | plotname, 979 | label, 980 | gridspacing) 981 | 982 | plt.savefig(args.p, dpi=300) 983 | plt.close() 984 | 985 | # source type diagram plot 986 | if args.pd: 987 | if args.pc: 988 | # if args.pc == 'ID' or args.pc == 'posX' or args.pc == 'posY' or args.pc == 'clas': 989 | if args.pc == 'posX' or args.pc == 'posY' or args.pc == 'clas': 990 | sys.stderr.write('\nWarning, to fill the symbols a numeric value is needed.\n') 991 | color = 'white' 992 | label = 'nada' 993 | else: 994 | color = dict_all[args.pc] 995 | label = str(dict_H[args.pc][0]).strip( 996 | "[]").replace("'", '').replace("_", " ") 997 | else: 998 | if clustering == 'TRUE': 999 | color = clustID 1000 | label = 'Clust ID' 1001 | else: 1002 | color = 'white' 1003 | label = 'nada' 1004 | if args.pt: 1005 | plotname = args.pt 1006 | else: 1007 | plotname = args.pd.split('.')[0] 1008 | if args.pa: 1009 | dotlabel = dict_all[args.pa] 1010 | lab_param = dict_H[args.pa][0] 1011 | fig = diamond_annot( 1012 | u_Hudson_all, 1013 | v_Hudson_all, 1014 | Mw_all, 1015 | color, 1016 | plotname, 1017 | label, 1018 | dotlabel, 1019 | lab_param) 1020 | # gridspacing) 1021 | else: 1022 | fig = diamond_circles( 1023 | u_Hudson_all, 1024 | v_Hudson_all, 1025 | Mw_all, 1026 | color, 1027 | plotname, 1028 | label) 1029 | # gridspacing) 1030 | 1031 | plt.savefig(args.pd, dpi=300) 1032 | plt.close() 1033 | --------------------------------------------------------------------------------