# Untitled

unknown
python
10 days ago
1.9 kB
6
Indexable
Never
```import openpyxl
import math

# Laster inn arbeidsboken og henter aktivt ark
wb = openpyxl.load_workbook('table 4.xlsx')
sheet = wb.active

# Lister over alle middelvindhastigheter, nedbør og vindretninger
Mean_Wind_speeds = []
Precipitation = []
Wind_Directions = []

# Går gjennom kolonne D (middelvindhastighet), kolonne E (nedbør) og kolonne F (vindretning)
for row in sheet.iter_rows(min_col=4, max_col=6, values_only=True):
wind_speed = row[0]  # Value from coulumn 4
precipitation = row[1]  # Value from coulumn 5
wind_direction = row[2]  # Value from coulumn 6

#  retrieve the values from the lists
if isinstance(wind_speed, (int, float)):
Mean_Wind_speeds.append(wind_speed)

if isinstance(precipitation, (int, float)):
Precipitation.append(precipitation)

if isinstance(wind_direction, (int, float)):
Wind_Directions.append(wind_direction)

# Making a function to use the formula for driving rain with
def calculate_result(theta, wind_speeds, precipitations, wind_directions):
result_sum = 0
for wind_speed, precipitation, wind_direction in zip(wind_speeds, precipitations, wind_directions):
if precipitation > 0:  # If it is precipitation do the formula
cos_term = math.cos(math.radians(wind_direction - theta))
result_sum += wind_speed * precipitation * cos_term * 0.206
return result_sum

# Calculationg for theta = 135
theta1 = 135
result_theta1 = calculate_result(theta1, Mean_Wind_speeds, Precipitation, Wind_Directions)

# Calculationg for theta = 225
theta2 = 225
result_theta2 = calculate_result(theta2, Mean_Wind_speeds, Precipitation, Wind_Directions)

# Skriv ut resultatene
print(f"Driving rain total for south-east = : {result_theta1}")
print(f"Driving rain total for south-west = : {result_theta2}")

```