-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcut_fvcom_output.py
32 lines (22 loc) · 1022 Bytes
/
cut_fvcom_output.py
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
# %%
# Cut by latitude and longitude coordinates a FVCOM model output
from PyFVCOM.read import FileReader
import numpy as np
# %%
# %% file load
def cut_fvcom(min_lon, max_lon, min_lat, max_lat, file_name, variables):
fvcom_data = FileReader(file_name, variables=['latc', 'lonc'])
if (fvcom_data.data.lonc > 180).any():
indices = np.argwhere((fvcom_data.data.latc >= min_lat) & (fvcom_data.data.latc <= max_lat) &
(fvcom_data.data.lonc <= (max_lon+360)) & (fvcom_data.data.lonc >= (min_lon+360)))
else:
indices = np.argwhere((fvcom_data.data.latc >= min_lat) & (fvcom_data.data.latc <= max_lat) &
(fvcom_data.data.lonc <= (max_lon)) & (fvcom_data.data.lonc >= (min_lon)))
indices_list = indices.tolist()
indices_sq = np.squeeze(indices_list)
#%% read
fvcom_data = FileReader(file_name,
dims={'nele': indices_sq},
variables=variables)
return fvcom_data
# %%