-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_glorys12_nbdy.py
executable file
·126 lines (97 loc) · 3.43 KB
/
get_glorys12_nbdy.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
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/bin/python
# Python script for geting data from the Mercator opendap
# revised version of the example provided by Mercator.
# This script can be used for Initial condition and for BDY condition
# However, note that this is just an extraction of GLORY12v1, with 50 vertical levels.
# Extracted data will be processed ahead for producing suitable BDY/Initial conditions
import os
import xarray as xr
import calendar
# define general path
url="http://tds.mercator-ocean.fr/thredds/dodsC/"
src_set="glorys12v1-daily"
# define zoom ( take care of index starting from 0 ! )
tgt_name="eNBDY12-v1"
# 2758 3514 2561 2646
imin=2758-1
imax=3514
jmin=2561-1
jmax=2646
t1=4411 #### 01/01/2004
for year in range(2004,2016) :
for month in range(1,13) :
ndays=calendar.monthrange(year,month)[1]
print ("y%4dm%02d : %02d " % ( year,month, ndays))
s='{0:02d}'.format(month)
tag="y"+str(year)+"m"+s+".1d"
t2=t1+ndays
# GRID 2D
typset="grid2D"
dtaset=src_set+"-"+typset
fileout=tgt_name+"_"+tag+"_"+typset+".nc"
t2=t1+ndays
if not os.path.isfile(fileout):
data = xr.open_dataset(url+dtaset,decode_cf=True)
print "open "+url+dtaset
ext_ind = data.isel(x=slice(imin,imax),y=slice(jmin,jmax),time_counter=slice(t1,t2)).sossheig
print "selected area: ", imin, imax, jmin, jmax
ext_ind.to_netcdf(fileout)
print fileout+" done"
# GRID T
typset="gridT"
var="votemper"
dtaset=src_set+"-"+typset
fileout=tgt_name+"_"+tag+"_"+var+".nc"
tt1=t1-1
t2=tt1+ndays
if not os.path.isfile(fileout):
data = xr.open_dataset(url+dtaset,decode_cf=True)
ext_ind = data.isel(x=slice(imin,imax),y=slice(jmin,jmax),time_counter=slice(tt1,t2)).votemper
ext_ind.to_netcdf(fileout)
print fileout+" done"
# GRID S
typset="gridS"
var="vosaline"
dtaset=src_set+"-"+typset
fileout=tgt_name+"_"+tag+"_"+var+".nc"
t2=t1+ndays
if not os.path.isfile(fileout):
data = xr.open_dataset(url+dtaset,decode_cf=True)
ext_ind = data.isel(x=slice(imin,imax),y=slice(jmin,jmax),time_counter=slice(t1,t2)).vosaline
ext_ind.to_netcdf(fileout)
print fileout+" done"
# GRID U
typset="gridU"
var="vozocrtx"
dtaset=src_set+"-"+typset
fileout=tgt_name+"_"+tag+"_"+var+".nc"
tt1=t1-1
t2=tt1+ndays
if not os.path.isfile(fileout):
data = xr.open_dataset(url+dtaset,decode_cf=True)
ext_ind = data.isel(x=slice(imin,imax),y=slice(jmin,jmax),time_counter=slice(tt1,t2)).vozocrtx
ext_ind.to_netcdf(fileout)
print fileout+" done"
# GRID V
typset="gridV"
var="vomecrty"
dtaset=src_set+"-"+typset
fileout=tgt_name+"_"+tag+"_"+var+".nc"
t2=t1+ndays
if not os.path.isfile(fileout):
data = xr.open_dataset(url+dtaset,decode_cf=True)
ext_ind = data.isel(x=slice(imin,imax),y=slice(jmin,jmax),time_counter=slice(t1,t2)).vomecrty
ext_ind.to_netcdf(fileout)
print fileout+" done"
# ICEMOD
typset="icemod"
dtaset=src_set+"-"+typset
fileout=tgt_name+"_"+tag+"_"+typset+".nc"
tt1=t1-1
t2=tt1+ndays
if not os.path.isfile(fileout):
data = xr.open_dataset(url+dtaset,decode_cf=True)
ext_ind = data.isel(x=slice(imin,imax),y=slice(jmin,jmax),time_counter=slice(tt1,t2))
ext_ind.to_netcdf(fileout)
print fileout+" done"
t1=t1+ndays