-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_glorys12.py
executable file
·110 lines (84 loc) · 2.88 KB
/
get_glorys12.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
#!/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
# define general path
url="http://tds.mercator-ocean.fr/thredds/dodsC/"
src_set="glorys12v1-monthly"
# define zoom ( take care of index starting from 0 ! )
tgt_name="eNATLYS12-v1"
imin=2266-1
imax=3979
jmin=1320-1
jmax=2745
time=145
tag="y2004m01.1m"
# isel method is use to select data by index
# GRID 2D
# 1 - open dataset
typset="grid2D"
dtaset=src_set+"-"+typset
fileout=tgt_name+"_"+tag+"_"+typset+".nc"
if not os.path.isfile(fileout):
data = xr.open_dataset(url+dtaset,decode_cf=True)
print "open "+url+dtaset
# 2 - Select area - time
ext_ind = data.isel(x=slice(imin,imax),y=slice(jmin,jmax),time_counter=slice(time,time+1)).sossheig
print "selected area: ", imin, imax, jmin, jmax
# 3 - Write on disk
ext_ind.to_netcdf(fileout)
print fileout+" done"
# WIP
# GRID T
typset="gridT"
var="votemper"
dtaset=src_set+"-"+typset
fileout=tgt_name+"_"+tag+"_"+var+".nc"
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(time,time+1)).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"
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(time,time+1)).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"
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(time,time+1)).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"
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(time,time+1)).vomecrty
ext_ind.to_netcdf(fileout)
print fileout+" done"
# ICEMOD
typset="icemod"
dtaset=src_set+"-"+typset
fileout=tgt_name+"_"+tag+"_"+typset+".nc"
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(time,time+1))
ext_ind.to_netcdf(fileout)
print fileout+" done"