0

I would like to incorporate the use of loops within my Python coding equation. I am looking to find the value for the radius (distance) for multiple earthquakes and their corresponding intensity values. I am getting the magnitude and depth data from the USGS Excel Spreadsheet file. At the moment my code looks like this (see attached) but I would like to remove the Input MMI Intensity Value code and use a loop that runs intensity values from 0 to 12, in 0.5 intervals, into the equation.

ml = float(input("Enter Magnitude Value: "))
h = float(input("Enter Depth Value: "))
Iso = float(input("Enter Intensity MMI Value: "))
import math

Io = 1.5 * (ml - math.log(h) + 1.4)
a = (Io - Iso) / (1.8)
d = (10 / 8) * (a)

d = d - 1
if d <= 0:
    print("Distance is zero")
else:
    d = math.sqrt(h * h + d * d)
    print("Radius (km): ", d)

Once I have the distance for each individual intensity value, I would like to input these distances into QGIS, along with other Earthquake data, to create an earthquake hazard map that has radii rings of varying intensity around an earthquake point.

0

1 Answer 1

1

Use range. As far as I know you cant use decimal numbers as step (with this range function) so divide by ten:

for Iso in [i/10 for i in range(0,125,5)]:
    print(Iso)

0.0
0.5
1.0
1.5
2.0
2.5
3.0
3.5
...
12.0

In your code:

ml = float(input("Enter Magnitude Value: "))
h = float(input("Enter Depth Value: "))
#Iso = float(input("Enter Intensity MMI Value: "))
import math

Io = 1.5 * (ml - math.log(h) + 1.4)

for Iso in [i/10 for i in range(0,125,5)]:
    a = (Io - Iso) / (1.8)
    d = (10 / 8) * (a)
    d = d - 1
    if d <= 0:
        print("Distance is zero")
    else:
        d = math.sqrt(h * h + d * d)
        print("Radius (km): ", d)
Enter Magnitude Value: 3.7

Enter Depth Value: 6.1
Radius (km):  6.565774088572565
Radius (km):  6.445404583784344
Radius (km):  6.341783476150495
Radius (km):  6.25574309025655
Radius (km):  6.188016815379507
Radius (km):  6.139210791849095
Radius (km):  6.109778451736456
Distance is zero
Distance is zero
...
7
  • Which section would I include this bit of code in? At the moment, I have replaced it with the "Enter Intensity MMI Value" code but all I get printed out is values for 0 to 12 in the dialogue, rather than individual distance (d) values for each intensity ranging from 0.5 to 12.
    – LiamHems
    Nov 3, 2020 at 11:35
  • You say input in QGIS, you want to create a csv file and add that to QGIS?
    – BERA
    Nov 3, 2020 at 11:46
  • Either a csv file or another file option that would allow me to create rings of intensity around an earthquake point (like a shakemap).
    – LiamHems
    Nov 3, 2020 at 11:50
  • There is to much information missing in your question. For example what your table is looking like.
    – BERA
    Nov 3, 2020 at 11:56
  • I agree there is quite a lot of missing information. To simplify it, not worrying about QGIS etc, I can input the depth and magnitude values myself in PyCharm. But, is there any way I can use that equation to get a value for d for varying intensity values (ISO), using a loop? Hope this makes sense and sorry for the confusion.
    – LiamHems
    Nov 3, 2020 at 12:03

Not the answer you're looking for? Browse other questions tagged or ask your own question.