-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrib_to_netcdf_call.py
executable file
·46 lines (27 loc) · 1.14 KB
/
grib_to_netcdf_call.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
#!/usr/local/apps/python/2.7.12-01/bin/python
import os
import subprocess
import sys
def submit_list(grib_file_list, stream):
if 'era5t' in stream:
dest_folder = '/scratch/ms/gb/ukc/era5t_processed/%s'% stream
elif 'era51' in stream:
dest_folder = '/scratch/ms/gb/ukc/era51_processed/%s'% stream
else:
dest_folder = '/scratch/ms/gb/ukc/era5_processed/%s'% stream
for grib_file in grib_file_list:
grib_file = grib_file.strip()
name_bit = os.path.basename(grib_file)[:-3] + 'nc'
netcdf_file = os.path.join(dest_folder, name_bit)
pro = subprocess.call(['grib_to_netcdf', grib_file, '-o' , netcdf_file, '-k', '4', '-d', '1'])
if os.path.exists(netcdf_file):
os.remove(grib_file)
if __name__== "__main__":
args = sys.argv
temp_file = args[1]
stream = args[2]
if os.path.exists(temp_file):
with file(temp_file,'r') as grib_list_file:
grib_file_list = grib_list_file.readlines()
submit_list(grib_file_list, stream)
os.remove(temp_file)