-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_subset_hycom_nc.py
53 lines (41 loc) · 2.25 KB
/
run_subset_hycom_nc.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
import os
from tool_scripts import *
import yaml
from hycom_dataset import *
from datasets import *
if __name__ == "__main__":
subsetdir = 'netcdf_files/subset'
os.system('mkdir -p %s' % (subsetdir))
dataset_to_process = {
'dataset_url_2013a': DATASET_URL_2013a,
'dataset_url_2013b': DATASET_URL_2013b,
'dataset_url_2014a': DATASET_URL_2014a,
'dataset_url_2014b': DATASET_URL_2014b,
'dataset_url_2015': DATASET_URL_2015,
'dataset_url_2016': DATASET_URL_2016
}
for dataset in dataset_to_process:
splitted_url = dataset_to_process[dataset].split("__var__")
dimensions = ['u', 'v']
print '\n\n'
print 'Processing dataset %s' % (dataset.split('_')[-1])
print '\n\n'
for dimension in dimensions:
# import pdb; pdb.set_trace()
netcdf_file = 'netcdf_files/%svel_%s.nc' % (dimension, dataset.split('_')[-1])
netcdf_output = '%s/%svel_%s_nodepth.nc' % (subsetdir, dimension, dataset.split('_')[-1])
os.system('ncwa -O -a Depth %s %s' % (netcdf_file, netcdf_output))
os.system('ncks -O -C -x -v Depth %s %s' % (netcdf_output, netcdf_output))
# import pdb; pdb.set_trace()
os.system('ncrename -O -v Latitude,latitude %s' % (netcdf_output))
os.system('ncrename -O -v Longitude,longitude %s' % (netcdf_output))
os.system('ncrename -O -v %s,%scur %s' % (dimension, dimension, netcdf_output))
os.system('ncrename -d X,longitude %s' % (netcdf_output))
os.system('ncrename -d Y,latitude %s' % (netcdf_output))
os.system('ncrename -O -d MT,time %s' % (netcdf_output))
os.system('ncrename -O -v MT,time %s' % (netcdf_output))
u_netcdf_output = '%s/%svel_%s_nodepth.nc' % (subsetdir, 'u', dataset.split('_')[-1])
v_netcdf_output = '%s/%svel_%s_nodepth.nc' % (subsetdir, 'v', dataset.split('_')[-1])
vel_netcdf_output = '%s/vel_%s_process.nc' % (subsetdir, dataset.split('_')[-1])
os.system('cp %s %s' % (v_netcdf_output, vel_netcdf_output))
os.system('ncks -A %s %s' % (u_netcdf_output, vel_netcdf_output))