Commit 65ed954f authored by Christoph Heim's avatar Christoph Heim
Browse files

ARPEGE now more or less working.

parent d1919418
......@@ -94,7 +94,8 @@ def sellatlon_MPAS(inp_file, out_file, dt, box, options, var_dict,
# output=out_file, options='-f nc')
input = "-sellonlatbox,{},{},{},{} -sellevidx,{}/{} -setgrid,mpas:{} {}".format(
input = ("-sellonlatbox,{},{},{},{} -sellevidx,{}/{}"+
" -setgrid,mpas:{} {}").format(
box['lon'].start, box['lon'].stop,
box['lat'].start, box['lat'].stop,
box['vert0'], box['vert1'],
......@@ -126,6 +127,8 @@ if __name__ == '__main__':
# box to subselect
box = domain
box.update({'vert0':1,'vert1':22})
#TODO
#box.update({'vert0':1,'vert1':1})
# name of model
model_name = 'MPAS'
......
......@@ -16,11 +16,12 @@ from datetime import datetime, timedelta
from multiprocessing import Pool
from pathlib import Path
from cdo import Cdo
from package.utilities import Timer, cdo_mergetime, write_grid_file
from package.utilities import Timer, cdo_mergetime, write_grid_file, cd
from namelist import domain
from functions import paste_dir_names
###############################################################################
def get_splf(split_files, var_dict):
"""
Get glob search pattern for grib var split file.
......@@ -73,12 +74,23 @@ def sellatlon_ARPEGE(inp_file, out_file, dt, box, options, var_name, var_dicts,
split_files = os.path.join(tmp_dir,'split')
# run gribsplit if not already done
#print(get_splf(split_files, var_dicts[var_name]))
search = glob.glob(get_splf(split_files, var_dicts[var_name]))
#print(search)
#quit()
if len(search) == 0:
# Split original grib files
command = './gribsplit'
subprocess.call([command, inp_file, split_files],
stdout=subprocess.DEVNULL)
subprocess.call(['cp', 'gribsplit', tmp_dir])
# change context to local directory because gribsplit
# produces _tmpfile in directory where it is called.
# Changing directory allows to run in parallel by preventing
# _tmpfiles from being overwritten by parallel processes.
with cd(tmp_dir):
subprocess.call([command, inp_file,
os.path.split(split_files)[1]],
stdout=subprocess.DEVNULL)
# remove all split variables that are irrelevant
keep_files = []
......@@ -87,7 +99,8 @@ def sellatlon_ARPEGE(inp_file, out_file, dt, box, options, var_name, var_dicts,
if var_dict['vdim'] == '3D':
# Remove unnecessary levels
levels = ['l{}00'.format(lev) for lev in range(box['vert0'],box['vert1']+1)]
levels = ['l{}00'.format(lev) for lev in range(box['vert0'],
box['vert1']+1)]
remove = []
for file in search:
match = False
......@@ -100,10 +113,14 @@ def sellatlon_ARPEGE(inp_file, out_file, dt, box, options, var_name, var_dicts,
search.remove(file)
keep_files.extend(search)
search = glob.glob('{}/*'.format(tmp_dir))
search = glob.glob('{}/*.gp'.format(tmp_dir))
for file in search:
if file not in keep_files:
os.remove(file)
search = glob.glob('{}/*.spectral'.format(tmp_dir))
for file in search:
if file not in keep_files:
#print('remove ',file)
os.remove(file)
tmp_files = glob.glob(get_splf(split_files, var_dicts[var_name]))
......@@ -121,7 +138,7 @@ def sellatlon_ARPEGE(inp_file, out_file, dt, box, options, var_name, var_dicts,
TM.start('cdo')
merge_files = []
for tmp_file in tmp_files:
print(tmp_file)
#print(tmp_file)
input = ("-sellonlatbox,{},{},{},{} -setgrid,{}"+
" -setgridtype,regular {}").format(
box['lon'].start, box['lon'].stop,
......@@ -153,9 +170,8 @@ def sellatlon_ARPEGE(inp_file, out_file, dt, box, options, var_name, var_dicts,
var_dicts[var_name]['vdim'] == '3D'):
for file in merge_fies:
os.remove(file)
TM.stop('cdo')
#quit()
return(TM)
......@@ -182,15 +198,13 @@ if __name__ == '__main__':
'SLHFLX', 'SSHFLX', 'TQC']
#var_names = ['QC']
#var_names = ['W']
var_names = ['U10M', 'V10M', 'T2M', 'LWUTOA', 'SWDSFC',
'SLHFLX', 'SSHFLX', 'TQC']
# model resolutions [km] of simulations
ress = [2.5]
# date range
first_date = datetime(2016,8,10)
last_date = datetime(2016,8,10)
last_date = datetime(2016,8,19)
# options for computation
options = {}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment