-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmaking_data_rough.py
More file actions
64 lines (49 loc) · 1.89 KB
/
Copy pathmaking_data_rough.py
File metadata and controls
64 lines (49 loc) · 1.89 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
import xarray as xr
import pandas as pd
import os
import matplotlib.pyplot as plt
import numpy as np
from scipy.ndimage.filters import uniform_filter as unif2D
def largest_sum(a, n):
idx = unif2D(a.astype(float),size=n, mode='constant').argmax()
return np.unravel_index(idx, a.shape)
## change n below to have different "search areas"
## load hurricane
hurricane = 'bob01'
wind = xr.open_dataset(hurricane + '/' + 'fg.nc')
wind = wind['wind_speed_of_gust']
all_winds = []
centre_winds = []
centre_winds_cut = []
t_wind = []
p_wind = []
centres_cols = []
centres_rows = []
valid = []
size = 257
side = int((size-1)/2)
for wind_time in wind.forecast_reference_time:
for wind_period in wind.forecast_period:
single_wind = wind.loc[dict(forecast_reference_time=wind_time, forecast_period = wind_period)]
single_wind = single_wind.values
(r, c) = largest_sum(single_wind, n = 50)
t_wind.append(wind_time.values)
p_wind.append(wind_period.values)
centres_cols.append(c)
centres_rows.append(r)
winds_centre = single_wind[r-side:r+side, c-side:c+side]
centre_winds.append(winds_centre.copy())
single_wind[single_wind < 3*np.mean(single_wind)] = 'NaN'
back = np.zeros_like(single_wind)
back[:] = np.nan
back[r-side:r+side, c-side:c+side] = single_wind[r-side:r+side, c-side:c+side]
# remove noise
all_winds.append(back.copy())
if np.count_nonzero(~np.isnan(single_wind)) < 3000:
valid.append(False)
else:
valid.append(True)
winds_centre = single_wind[r-side:r+side, c-side:c+side]
back[r-side:r+side, c-side:c+side] = winds_centre
centre_winds_cut.append(winds_centre)
## save here the results