Earthquakes 0.0 Earthquake calculations api. Compares 2 earthquakes (comparing a list tbd)
"""Earthquakes api Simple earthquake calculations. """ __version__="0.0" MN="Earthquake V"+__version__+":" crid=MN+"\n© 2024 SteveG1CMZ" from math import * abt="Earthquake calculations are estimates and can be calculated differently. No liability is accepted." EPSILON=10*(-308) #0 LIMIT FOR LOGS #units "" Nm="Nm" RigidityTypical=3.0*10**10 #N/m2 vPtypical = 6 # km/s OR 1.7*vS vStypical = 3 # km/s def about(): print(crid) print(abt) def MSGBOX(ST): print(ST) #and wait tbd def string(st): return "" #ST tbd def alog10(n): return 10**n def M0Nm( Aream2,Slipm, RigidityNm2=RigidityTypical): #Calculate SeismicMoment in Nm^2 #=rigidity x area x slip #The rigidity of rock is a constant number based on the rock type. It has units of pressure. Typical assumptions are on the order of 3 x 10^10 N/m2. #Slip is a length and it is on the order of centimeters (meters for a great earthquake). #Area is in units of length2 and is often on the order of km2. #The units for seismic moment are then Nm # Typical value if none supplied Rigidity=RigidityNm2 Area=Aream2 Slip=Slipm return Rigidity*Area*Slip def MW(M0): #Calculate Mw = (2/3)*logM0 - 6.05 M00=max(M0,EPSILON) #GUARD M0≤0 MM=(2/3)*log10(M00)-6.05 if min(M0,M0)<=0: #min superfluous MSGBOX(MN+":MW:\n"+"LOG≤0: "+string(M0)) return MM def Magnitude(Aream2,Slipm, RigidityNm2=RigidityTypical): return MW(M0Nm(Aream2,Slipm,RigidityNm2)) #These magnitudes are approximations to Richter scale but not same def Magnitude_(M0): return MW(M0) def EnergyJ(Magnitud): #"Magnitude" is a reserved word or function # Calculate E, where Log10(E) = 5.24 + 1.44M #Empirical good for M>5 #This estimates damaging energy return round(alog10(5.24+1.44*Magnitud),0) #J def Energyt(Magnitud): TNT=4.184*10**9 #J PER TONNE return EnergyJ(Magnitud)/TNT def EnergyH(Magnitud): HIROSHIMA=7.4*10**12 #J return EnergyJ(Magnitud)/HIROSHIMA # time functions def Centred(tdelta, vP=vPtypical,vS=vStypical): #Distance to centre-Local usable up To 100-250km. #Simple formula for constant velocity #dist tdelta vp vs units to match #eg km s or m s #tdelta=(TimeS-TimeP) dist=(tdelta)*(vP*vS)/(vP-vS) return round(dist,0) def Delay(distance, vP=vPtypical,vS=vStypical): #DISTANCE ≤250 km #GIVEN DISTANCE,HOW LONG AFTER P WILL S ARRIVE #DISTANCE Delay:UNITS MATCH vP vS return (distance/vP)-(distance/vS) # Comparing 2 Quakes (unused) def RelAmplitude(MagA,MagB): #Compare relative amplitude, any order BIGGER = 10**abs(MagA-MagB); return BIGGER #unitless def RelEnergy(MagA,MagB): #Compare relative energy (damage), any order BIGGER = RelAmplitude(MagA,MagB) STRONGER = 10**(abs(MagA-MagB)/2)*BIGGER return STRONGER #unitless #examples (= signifies expected) def exMo(): #As an example, the 2004 26 December Sumatra-Andaman earthquake had the following dimensions as reported by Lay et al. (2005): Its slip averaged about 5 m, its rupture length was about 1300 km and the fault width was between 160 - 240 km. Assuming a rigidity of 3 x 10^10 N/m2 gives us a seismic moment of 4.4 x 10^22Nm. exr=3.0*10**10 #typical exalo=1300*10**3 * 160*10**3 #m*m exahi=1300*10**3 * 240*10**3 #m*m exs=5.0 #m exmo=[M0Nm(exalo,exs), M0Nm(exahi,exs), M0Nm((exahi+exalo)/2,exs)] print("Seismic Moment:") print(exmo,Nm,float(4.4*10**22)) #ex def exMW(): print (MW(4.4*10**22)," Magnitude =9.05") def AnEarthquake(Magnitud): #Describe an Earthquake #print() print(Magnitud," Magnitude"); #print(" "); print((EnergyJ(Magnitud))," J"); print((Energyt(Magnitud))," t(TNT)"); print((EnergyH(Magnitud))," Hiroshima") def exRel(): print(RelAmplitude(7.1,6.4),"=5") print(RelEnergy(7.1,6.4),"=11.2") #print(Amplitudes({7.1,6.4},1),"=5") #print(Energies({7.1,6.4},1),"=11.2") def exEnergy(): #PRINT({EnergyJ({5.0,6.0,7.0}),"=2.8ᴇ12 =7.8ᴇ13?? =2.1ᴇ15"}+" J "); #PRINT({EnergyH(5.0),EnergyH(6.0),EnergyH(7.0)," "}+" Hiroshima "); #PRINT({EnergyJ(9.05),"=1.84ᴇ18"}+" J "); #PRINT({Energyt(5.0)}+" tTNT "); AnEarthquake(7.1) #examples main def examples(): print("Examples:") exMo() exMW() exEnergy() exRel() print(crid) showme=True #False if showme or __name__=="__main__": about() if True: examples()