Repository navigation
Expand file tree
/
Copy pathgenerate_netcdf_for_OPT_tracers.py
More file actions
99 lines (82 loc) · 2.62 KB
/
Copy pathgenerate_netcdf_for_OPT_tracers.py
File metadata and controls
99 lines (82 loc) · 2.62 KB
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
import os
import sys
import iris
import numpy as np
import definitions_STASH_for_OPT as def_STASH
from stash_list_for_OPT_ap4 import lst_ap4
from stash_list_for_OPT_pm import lst
# Only use for files with more than one timestep as iris does not output that dimension if only one step in it.
def ret_stash_string(i):
isec=i//1000
sec="{:02d}".format(isec)
it="{:03d}".format(i-(1000*isec))
return 'm01s'+sec+'i'+it
jobids=["u-bz750","u-bz751","u-bz752","u-bz753"]
# jobid='u-cb159'
for jobid in jobids:
disk='/work/scratch-pw2/ptg21/'
print(jobid)
outputdir=disk+jobid+'/netcdf_OPT/'
inputdir= disk+jobid+'/pp_files_for_OPT_archive_pm/'
if not os.path.exists(outputdir):
os.makedirs(outputdir)
#### PM stream
name = []
stash_list = []
for i in lst:
name.append(i[0])
stash_list.append(i[1])
print ('\n'+jobid+'\npm')
# prepare STASH codes
path_to_files=inputdir+'/'+jobid+'a.pm'
for z in range(0,len(stash_list)):
for decade in np.arange(209,210):
decade = str(decade)
stash=[]
field_constr=[]
for i in stash_list[z]:
stashdir = inputdir+'/'
stash.append(ret_stash_string(i))
field_constr.append(iris.AttributeConstraint(STASH=ret_stash_string(i)))
print ('stash : ')
print (stashdir)
# load pp files and output netCDF
outfile=outputdir+'BASE_'+decade+'0'+name[z]+'.nc'
print(outfile)
field=iris.load(stashdir+'*'+decade+'*.pp',field_constr,callback=def_STASH.UKCA_callback)
print (field)
iris.save(field, outfile)
jobids=["u-bz754"]
for jobid in jobids:
disk='/work/scratch-pw2/ptg21/'
print(jobid)
outputdir=disk+jobid+'/netcdf_OPT/'
inputdir= disk+jobid+'/pp_files_for_OPT_archive_pm/'
if not os.path.exists(outputdir):
os.makedirs(outputdir)
#### PM stream
name = []
stash_list = []
for i in lst:
name.append(i[0])
stash_list.append(i[1])
print ('\n'+jobid+'\npm')
# prepare STASH codes
path_to_files=inputdir+'/'+jobid+'a.pm'
for z in range(0,len(stash_list)):
for decade in np.arange(185,186):
decade = str(decade)
stash=[]
field_constr=[]
for i in stash_list[z]:
stashdir = inputdir+'/'
stash.append(ret_stash_string(i))
field_constr.append(iris.AttributeConstraint(STASH=ret_stash_string(i)))
print ('stash : ')
print (stashdir)
# load pp files and output netCDF
outfile=outputdir+'BASE_'+decade+'0'+name[z]+'.nc'
print(outfile)
field=iris.load(stashdir+'*'+decade+'*.pp',field_constr,callback=def_STASH.UKCA_callback)
print (field)
iris.save(field, outfile)