Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Christoph Heim
dyamond_mistral
Commits
539f3f3f
Commit
539f3f3f
authored
Sep 09, 2019
by
Christoph Heim
Browse files
Updated cosmo script.
parent
b70926ab
Changes
1
Hide whitespace changes
Inline
Side-by-side
10_cosmo.py
View file @
539f3f3f
...
...
@@ -24,7 +24,7 @@ from functions import paste_dir_names
def
sellatlon_COSMO
(
inp_file
,
out_file
,
dt
,
box
,
options
,
var_name
,
res
):
TM
=
Timer
()
file_code
=
'{}km_{}_{:%Y%m%d%H}'
.
format
(
res
,
var_name
,
dt
)
file_code
=
'{}km_{}_{:%Y%m%d%H
%M
}'
.
format
(
res
,
var_name
,
dt
)
if
os
.
path
.
exists
(
out_file
)
and
not
options
[
'recompute'
]:
TM
.
start
(
'cdo'
)
...
...
@@ -36,37 +36,57 @@ def sellatlon_COSMO(inp_file, out_file, dt, box, options, var_name, res):
split
=
os
.
path
.
split
(
out_file
)
nco_file
=
os
.
path
.
join
(
split
[
0
],
'nco_'
+
split
[
1
])
#print(nco_file)
## nco
#if not os.path.exists(nco_file):
# TM.start('nco')
# bash_command = 'ncrcat -O -v {} {} {}'.format(
# var_dict[var_name]['key'], inp_file,
# nco_file)
# process = subprocess.Popen(bash_command.split(),
# stdout=subprocess.PIPE)
# output, error = process.communicate()
# TM.stop('nco')
#else:
# TM.start('nco')
# TM.stop('nco')
# nco
if
not
os
.
path
.
exists
(
nco_file
):
TM
.
start
(
'nco'
)
if
var_dict
[
var_name
][
'dim'
]
==
'3D'
:
bash_command
=
'ncrcat -O -v {} {} {}'
.
format
(
var_dict
[
var_name
][
'key'
],
inp_file
,
nco_file
)
process
=
subprocess
.
Popen
(
bash_command
.
split
(),
stdout
=
subprocess
.
PIPE
)
output
,
error
=
process
.
communicate
()
TM
.
stop
(
'nco'
)
else
:
TM
.
start
(
'nco'
)
TM
.
stop
(
'nco'
)
if
var_dict
[
var_name
][
'dim'
]
==
'3D'
:
ofile
=
cdo
.
sellonlatbox
(
box
[
'lon'
].
start
,
box
[
'lon'
].
stop
,
box
[
'lat'
].
start
,
box
[
'lat'
].
stop
,
input
=
(
' -sellevidx,'
+
str
(
box
[
'vert0'
])
+
'/'
+
str
(
box
[
'vert1'
])
+
' -selname,'
+
var_dict
[
var_name
][
'key'
]
+
' '
+
inp
_file
),
#
' -selname,'+var_dict[var_name]['key'] +
' '
+
nco
_file
),
output
=
out_file
)
# delete tmp file
bash_command
=
'rm {}'
.
format
(
nco_file
)
process
=
subprocess
.
Popen
(
bash_command
.
split
(),
stdout
=
subprocess
.
PIPE
)
elif
var_dict
[
var_name
][
'dim'
]
==
'2D'
:
ofile
=
cdo
.
sellonlatbox
(
box
[
'lon'
].
start
,
box
[
'lon'
].
stop
,
box
[
'lat'
].
start
,
box
[
'lat'
].
stop
,
input
=
(
' -selname,'
+
var_dict
[
var_name
][
'key'
]
+
' '
+
inp_file
),
output
=
out_file
)
bash_command
=
'ncrcat -O -v {} {} {}'
.
format
(
var_dict
[
var_name
][
'key'
],
inp_file
,
out_file
)
process
=
subprocess
.
Popen
(
bash_command
.
split
(),
stdout
=
subprocess
.
PIPE
)
output
,
error
=
process
.
communicate
()
# ofile = cdo.sellonlatbox(
# box['lon'].start, box['lon'].stop,
# box['lat'].start, box['lat'].stop,
# input=(nco_file),
# #input=(' -selname,'+var_dict[var_name]['key'] +
# # ' '+inp_file),
# output=out_file)
TM
.
stop
(
'cdo'
)
return
(
TM
)
...
...
@@ -82,7 +102,8 @@ if __name__ == '__main__':
# box to subselect
box
=
domain
box
.
update
({
'vert0'
:
40
,
'vert1'
:
60
})
#box.update({'vert0':40,'vert1':60}) # 3km top
box
.
update
({
'vert0'
:
32
,
'vert1'
:
60
})
# 6km top
box
[
'lon'
]
=
slice
(
box
[
'lon'
].
start
-
padding
,
box
[
'lon'
].
stop
+
padding
)
box
[
'lat'
]
=
slice
(
box
[
'lat'
].
start
-
padding
,
box
[
'lat'
].
stop
+
padding
)
...
...
@@ -92,21 +113,16 @@ if __name__ == '__main__':
# variables to extract
var_names
=
[
'QV'
,
'QC'
,
'T'
,
'W'
,
'U10M'
,
'V10M'
,
'T2M'
,
'LWUTOA'
,
'SWDSFC'
,
'SLHFLX'
,
'SSHFLX'
,
'TQC'
]
var_names
=
[
'QV'
,
'QC'
,
'T'
,
'W'
]
#var_names = ['U10M', 'V10M', 'T2M', 'LWUTOA', 'SWDSFC',
# 'SLHFLX', 'SSHFLX', 'TQC']
#var_names = ['V10M', 'T2M', 'LWUTOA']
var_names
=
[
'TQC'
]
'SLHFLX'
,
'SSHFLX'
,
'TQC'
,
'PP'
]
var_names
=
[
'SWDSFC'
]
# model resolutions [km] of simulations
ress
=
[
12
,
4.4
]
ress
=
[
4.4
]
ress
=
[
12
]
# date range
first_date
=
datetime
(
2016
,
8
,
1
1
)
last_date
=
datetime
(
2016
,
8
,
2
0
)
first_date
=
datetime
(
2016
,
8
,
1
)
last_date
=
datetime
(
2016
,
8
,
2
)
# options for computation
options
=
{}
...
...
@@ -117,7 +133,6 @@ if __name__ == '__main__':
# COSMO SPECIFIC SETTINGS
###########################################################################
sim_tag
=
'SE_Atl'
var_dict
=
{
'QV'
:{
'key'
:
'QV'
,
'folder'
:
'3h_3D'
,
'dim'
:
'3D'
},
'QC'
:{
'key'
:
'QC'
,
'folder'
:
'3h_3D'
,
'dim'
:
'3D'
},
...
...
@@ -134,7 +149,14 @@ if __name__ == '__main__':
'TQC'
:{
'key'
:
'TQC'
,
'folder'
:
'15min_water'
,
'dim'
:
'2D'
},
'PP'
:{
'key'
:
'TOT_PREC'
,
'folder'
:
'15min_water'
,
'dim'
:
'2D'
},
}
inc_min
=
{
'3D'
:
180
,
'2D'
:
60
}
inc_min
=
{
'3h_3D'
:
180
,
'1h_2D'
:
60
,
'15min_water'
:
15
}
model_dict
=
{
12
:
'c'
,
4.4
:
'f'
,
}
sim_tag
=
'SA_12_4'
###########################################################################
## PREPARING STEPS
...
...
@@ -151,14 +173,15 @@ if __name__ == '__main__':
for
var_name
in
var_names
:
print
(
'############## var '
+
var_name
+
' ##################'
)
dt_range
=
np
.
arange
(
first_date
,
last_date
+
timedelta
(
days
=
1
)
,
dt_range
=
np
.
arange
(
first_date
,
last_date
,
timedelta
(
minutes
=
inc_min
[
var_dict
[
var_name
][
'dim'
]])).
tolist
()
var_dict
[
var_name
][
'folder'
]])).
tolist
()
for
res
in
ress
:
print
(
'############## res '
+
str
(
res
)
+
' ##################'
)
#res = 4
sim_name
=
'lm_'
+
str
(
res
)
sim_name
=
'lm_'
+
model_dict
[
res
]
inp_dir
=
os
.
path
.
join
(
raw_data_dir
,
sim_tag
,
sim_name
,
var_dict
[
var_name
][
'folder'
],
str
(
dt_range
[
0
].
year
))
...
...
@@ -179,9 +202,9 @@ if __name__ == '__main__':
args
=
[]
for
dt
in
dt_range
:
inp_file
=
glob
.
glob
(
os
.
path
.
join
(
inp_dir
,
'lffd{:%Y%m%d%H}.nc'
.
format
(
dt
)))[
0
]
'lffd{:%Y%m%d%H
%M%S
}.nc'
.
format
(
dt
)))[
0
]
out_file
=
os
.
path
.
join
(
out_tmp_dir
,
var_name
+
'_{:%Y%m%d%H}'
.
format
(
dt
)
+
'.nc'
)
var_name
+
'_{:%Y%m%d%H
%M
}'
.
format
(
dt
)
+
'.nc'
)
args
.
append
(
(
inp_file
,
out_file
,
dt
,
box
,
options
,
var_name
,
res
)
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment