-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsam.py
More file actions
79 lines (64 loc) · 2.03 KB
/
sam.py
File metadata and controls
79 lines (64 loc) · 2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
from mpi4py import MPI
from netCDF4 import Dataset
from itertools import islice
import geopandas as gpd
import numpy as np
import omp
import time
def alert(wavemeters, lons, lats, lm, hs, dir, t0m1, depth):
cumulativeEffectClass = omp.alert(wavemeters.to_numpy(), lons, lats, lm, hs, dir, t0m1, depth)
return cumulativeEffectClass
comm = MPI.COMM_WORLD
size = comm.Get_size()
rank = comm.Get_rank()
if rank == 0:
start_time = time.time()
#df = gpd.read_file("data/wavemeter.geojson").iloc[:1]
df = gpd.read_file("data/wavemeter.geojson")
totalSize = len(df)
print(totalSize)
wavemeters = [None] * size
spare = totalSize % size
data_part = [int(x) for x in np.linspace(spare, len(df), size+1)]
for i in range(size):
if i == 0:
wavemeters[i] = df.iloc[data_part[i]-spare:data_part[i+1]]
else:
wavemeters[i] = df.iloc[data_part[i]:data_part[i+1]]
ww3 = Dataset("data/regridded_ww33_d03_20221224Z2000.nc")
lm = ww3["lm"][0][:]
hs = ww3["hs"][0][:]
dir = ww3["dir"][0][:]
t0m1 = ww3["t0m1"][0][:]
dtm = Dataset("data/DTM.nc")
depth = dtm["height"][:]
lons = dtm["longitude"][:]
lats = dtm["latitude"][:]
else:
totalSize = None
wavemeters = None
lm = None
hs = None
dir = None
t0m1 = None
depth = None
lons = None
lats = None
wavemeters = comm.scatter(wavemeters, root = 0)
lm = comm.bcast(lm, root=0)
hs = comm.bcast(hs, root=0)
dir = comm.bcast(dir, root=0)
t0m1 = comm.bcast(t0m1, root=0)
depth = comm.bcast(depth, root=0)
lons = comm.bcast(lons, root=0)
lats = comm.bcast(lats, root=0)
totalSize = comm.bcast(totalSize, root=0)
classVarPartition = alert(wavemeters, lons, lats, lm, hs, dir, t0m1, depth)
classVar = None
if rank == 0:
classVar = np.zeros(len(wavemeters)*size, dtype = int)
comm.Gather(classVarPartition, classVar, root=0)
if rank == 0:
end_time = time.time() - start_time
print("Exectution time: ", end_time)
print('Rank: ',rank, ', recvbuf received: ', classVar[:totalSize])