def global_wa_hyp(M, lat_hyp, lon_hyp, depth_hyp, lat_sta, lon_sta): """ Computed intensity prediction equation according to Wald & Allan, 2012 Parameters: M magnitude lat_hyp, lon_hyp, depth_hyp: coordinates of the hypocenter (latitude, longitude, depth, respectively) lat_sta, lon_sta: coordinates of the station (latitude and longitude, respectively) Returns: a number """ #defining constants: c0 = 2.085 c1 = 1.428 c2 = -1.402 c4 = 0.078 m1 = -0.209 m2 = 2.042 R_hyp = _threed_dist(lat_hyp, lon_hyp, depth_hyp, lat_sta, lon_sta, 0) R_M = m1 + m2 * exp(M - 5) I = c0 + c1 * M + c2 * log(sqrt(R_hyp**2 + R_M**2)) if R_hyp > 50: I = I + c4 * log(R_hyp / 50) return I
def calculate(self, distance): xEP1, xEP2, xEP3, xEP4, xEP5 = self.__constants M = self.m #magnitude depth = self.depth return xEP1 * M + xEP2 * log10(depth) + xEP3 - xEP4 * 0.5 * log10( (distance / depth)**2 + 1) - xEP5 * (sqrt(distance**2 + depth**2) - depth)
def global_wa_hyp(M, lat_hyp, lon_hyp, depth_hyp, lat_sta, lon_sta): """ Computed intensity prediction equation according to Wald & Allan, 2012 Parameters: M magnitude lat_hyp, lon_hyp, depth_hyp: coordinates of the hypocenter (latitude, longitude, depth, respectively) lat_sta, lon_sta: coordinates of the station (latitude and longitude, respectively) Returns: a number """ #defining constants: c0 = 2.085 c1 = 1.428 c2 = -1.402 c4 = 0.078 m1 = -0.209 m2 = 2.042 R_hyp = _threed_dist(lat_hyp, lon_hyp, depth_hyp, lat_sta, lon_sta, 0) R_M = m1 + m2 * exp(M-5) I = c0 + c1 * M + c2 * log(sqrt(R_hyp ** 2 + R_M ** 2)); if R_hyp > 50: I = I + c4 * log(R_hyp/50) return I
def calculate(self, distance): c0, c1, c2, c4, m1, m2 = self.__constants M = self.m #magnitude R_M = m1 + m2 * exp(M - 5) I = c0 + c1 * M + c2 * log(sqrt(distance**2 + R_M**2)) if distance > 50: I = I + c4 * log(distance / 50) return I
def disthyp(lat_hyp, lon_hyp, depth_hyp, lat, lon): """ Returns the distance, in km, from the hypocenter whose latitude, longitude and depth are lat_hyp, lon_hyp and depth_hyp, respectively, and a generic location whose latitude and longitude are lat and lon, respectively. All arguments are assumed in degrees except for depth, in km """ chord = chorddistance(lat_hyp, lon_hyp, lat, lon) return sqrt(depth_hyp**2 + chord**2)
def test_two_bar_truss_analysis(): """Example of two-bar truss stress/deflection analysis""" H = N(30, 5 / 3.0, tag="H") B = N(60, 0.5 / 3.0, tag="B") d = N(3, 0.1 / 3, tag="d") t = N(0.15, 0.01 / 3, tag="t") E = N(30000, 1500 / 3.0, tag="E") rho = N(0.3, 0.01 / 3.0, tag="rho") P = N(66, 3 / 3.0, tag="P") pi = np.pi wght = 2 * pi * rho * d * t * umath.sqrt((B / 2) ** 2 + H ** 2) strs = (P * umath.sqrt((B / 2) ** 2 + H ** 2)) / (2 * pi * d * t * H) buck = (pi ** 2 * E * (d ** 2 + t ** 2)) / (8 * ((B / 2) ** 2 + H ** 2)) defl = (P * ((B / 2) ** 2 + H ** 2) ** (1.5)) / (2 * pi * d * t * H ** 2 * E) print(wght.describe("wght")) print(strs.describe("strs")) print(buck.describe("buck")) print(defl.describe("defl"))
def __call__(self, lat, lon): #TO BE IMPLEMENTED #getting constants: c0, c1 , c2 , c4, m1, m2 = self.__constants #R_hyp = _threed_dist(self.lat, self.lon, self.depth, lat, lon, 0) chord = chorddistance(self.lat, self.lon, lat, lon) R_hyp = sqrt(self.depth**2 + chord**2) M = self.m #magnitude R_M = m1 + m2 * exp(M-5) I = c0 + c1 * M + c2 * log(sqrt(R_hyp ** 2 + R_M ** 2)); if R_hyp > 50: I = I + c4 * log(R_hyp/50) return I
def __call__(self, lat, lon): if not hasattr(self, "_rld"): self._rld, self._rw = rld_rw(self.sof)(self.m) c0, c1, c2, c3 = self.__constants r_rup = rup_distance(lat, lon, self.lat, self.lon, self.depth, self.strike, self.dip, self._rld, self._rw) return c0 + c1 * self.m + c2 * log (sqrt( r_rup ** 2 + (1 + c3 * exp(self.m -5)) **2 ))
def test_volumetric_gas_flow(): """Example of volumetric gas flow through orifice meter""" H = N(64, 0.5) M = N(16, 0.1) P = N(361, 2) t = N(165, 0.5) C = 38.4 Q = C * umath.sqrt((520 * H * P) / (M * (t + 460))) Q.describe()
def _centralasia_emca_1( M, depth, dist_epi_sta ): #h=Depth, dist_epi_sta=distanza in R2 tra epicentro e stazione. DISTANCES IN KM!!!! """ Computed intensity prediction equation for central asia given a Magnitude M, the hypocenter depth and the distance between epicenter and station """ #computed intensity for Central Asia #Epicentral and EXtended distances; #Input: mag,depth,distance values #distance can be a vector xEP1 = 1.0074538 xEP2 = -2.0045088 xEP3 = 3.2980663 xEP4 = 2.6920855 xEP5 = 4.2344195e-04 return xEP1 * M + xEP2 * log10(depth) + xEP3 - xEP4 * 0.5 * log10( (dist_epi_sta / depth)**2 + 1) - xEP5 * (sqrt(dist_epi_sta**2 + depth**2) - depth)
def calculate(self, distance): c0, c1, c2, c3 = self.__constants I = c0 + c1 * self.m + c2 * log( sqrt(distance**2 + (1 + c3 * exp(self.m - 5))**2)) return I
def _threed_dist(lat1, lon1, depth1, lat2, lon2, depth2): """ Returns the 3D distance from point1 to point2 """ return sqrt((lat1 - lat2)**2 + (lon1 - lon2)**2 + (depth1 - depth2)**2)
def _threed_dist(lat1, lon1, depth1, lat2, lon2, depth2): """ Returns the 3D distance from point1 to point2 """ return sqrt( (lat1-lat2)**2 + (lon1-lon2)**2 + (depth1-depth2)**2 )
def __call__(self, lat, lon): #TO BE IMPLEMENTED #getting constants: xEP1, xEP2, xEP3, xEP4, xEP5 = self.__constants dist_epi_sta = deg2km(greatarc_dist(self.lat, self.lon, lat, lon)) M = self.m #magnitude depth = self.depth return xEP1*M + xEP2*log10(depth) + xEP3 - xEP4*0.5*log10((dist_epi_sta/depth)**2 + 1) - xEP5*(sqrt(dist_epi_sta**2 + depth**2)-depth)
from mcerp import * # N, U, Gamma, Beta, correlate, etc. import mcerp.umath as umath import numpy as np sp = 2 # deviation standard pour le rayon # une deviation standard de 2 m en rayon sur chaque coin correspond a une deviation standard en x ou y de stv/sqrt(2) sp = sp / umath.sqrt(2) x1 = N(0, sp) y1 = N(0, sp) x2 = N(100, sp) y2 = N(0, sp) x3 = N(0, sp) y3 = N(50, sp) x4 = N(100, sp) y4 = N(50, sp) # calcul des surfaces '''# approximatif surface = umath.sqrt((x2-x1)**2+(y2-y1)**2)*umath.sqrt((x3-x1)**2+(y3-y1)**2)/2+umath.sqrt((x4-x2)**2+(y4-y2)**2)*umath.sqrt((x4-x3)**2+(y4-y3)**2)/2 ''' # exact v12 = [x2 - x1, y2 - y1] v13 = [x3 - x1, y3 - y1] v14 = [x4 - x1, y4 - y1] surface = np.cross(v12, v14) / 2 + np.cross(v14, v13) / 2 surface.describe() print('surface.mean : ', surface.mean, ' stv : ', np.sqrt(surface.var)) ''' surface.mean : 4999.957807386318 stv : 157.22298079
print('*' * 80) print('Example of a three part assembly') x1 = N(24, 1) x2 = N(37, 4) x3 = Exp(2) # Exp(mu=0.5) is the same Z = (x1 * x2**2) / (15 * (1.5 + x3)) Z.describe() print('*' * 80) print('Example of volumetric gas flow through orifice meter') H = N(64, 0.5) M = N(16, 0.1) P = N(361, 2) t = N(165, 0.5) C = 38.4 Q = C * umath.sqrt((520 * H * P) / (M * (t + 460))) Q.describe() print('*' * 80) print('Example of manufacturing tolerance stackup') # for a gamma distribution we need the following conversions: # shape = mean**2/var # scale = var/mean mn = 1.5 vr = 0.25 k = mn**2 / vr theta = vr / mn x = Gamma(k, theta) y = Gamma(k, theta) z = Gamma(k, theta) w = x + y + z
def _centralasia_emca_1(M, depth, dist_epi_sta): #h=Depth, dist_epi_sta=distanza in R2 tra epicentro e stazione. DISTANCES IN KM!!!! """ Computed intensity prediction equation for central asia given a Magnitude M, the hypocenter depth and the distance between epicenter and station """ #computed intensity for Central Asia #Epicentral and EXtended distances; #Input: mag,depth,distance values #distance can be a vector xEP1 =1.0074538 xEP2 = -2.0045088 xEP3 = 3.2980663 xEP4 = 2.6920855 xEP5 = 4.2344195e-04 return xEP1*M + xEP2*log10(depth) + xEP3 - xEP4*0.5*log10((dist_epi_sta/depth)**2 + 1) - xEP5*(sqrt(dist_epi_sta**2 + depth**2)-depth)