Commit d1783115 authored by Christoph Heim's avatar Christoph Heim
Browse files

Adding new variables. Done for NICAM and SAM.

parent 52110b46
......@@ -4,7 +4,7 @@
description: Extract lat-lon box of data from model NICAM.
author: Christoph Heim
date created: 27.06.2019
date changed: 09.07.2019
date changed: 10.07.2019
usage: arguments:
1st: n jobs for multiprocessing pool
python: 3.5.2
......@@ -19,7 +19,7 @@ from cdo import Cdo
from utilities import Timer, mergetime
###############################################################################
def sellatlon_NICAM(inp_file, out_file, dt, box, options):
def sellatlon_NICAM(inp_file, out_file, dt, box, options, var_dict):
TM = Timer()
TM.start('total')
......@@ -33,12 +33,19 @@ def sellatlon_NICAM(inp_file, out_file, dt, box, options):
# cdo
TM.start('cdo')
#print('\t{:%Y%m%d%H} cdo'.format(dt))
ofile = cdo.sellonlatbox(
box['lon0'],box['lon1'],
box['lat0'],box['lat1'],
input=('-sellevidx,'+str(box['vert0'])+'/'+
str(box['vert1'])+' '+inp_file),
output=out_file)
if var_dict['dim'] == '3D':
ofile = cdo.sellonlatbox(
box['lon0'],box['lon1'],
box['lat0'],box['lat1'],
input=('-sellevidx,'+str(box['vert0'])+'/'+
str(box['vert1'])+' '+inp_file),
output=out_file)
elif var_dict['dim'] == '2D':
ofile = cdo.sellonlatbox(
box['lon0'],box['lon1'],
box['lat0'],box['lat1'],
input=(inp_file),
output=out_file)
print('\t\t{:%Y%m%d%H} completed'.format(dt))
TM.stop('cdo')
......@@ -65,11 +72,12 @@ if __name__ == '__main__':
model_name = 'NICAM'
# variables to extract
var_names = ['QC', 'T']
#var_names = ['QC']
var_names = ['QV', 'QC', 'T', 'W',
'U10M', 'V10M', 'T2M', 'LWUTOA', 'SWDSFC',
'SLHFLX', 'SSHFLX']
# model resolutions [km] of simulations
ress = [3.5, 7]
ress = [7, 3.5]
#ress = [7]
# date range
......@@ -85,8 +93,18 @@ if __name__ == '__main__':
# NICAM SPECIFIC SETTINGS
###########################################################################
var_dict = {
'QC':{'file':'ms_qc',},
'T':{'file':'ms_tem',},
'QV' :{'file':'ms_qv', 'dim':'3D', },
'QC' :{'file':'ms_qc', 'dim':'3D', },
'T' :{'file':'ms_tem', 'dim':'3D', },
'W' :{'file':'ms_w', 'dim':'3D', },
'U10M' :{'file':'ss_u10m', 'dim':'2D', },
'V10M' :{'file':'ss_v10m', 'dim':'2D', },
'T2M' :{'file':'ss_t2m', 'dim':'2D', },
'LWUTOA':{'file':'sa_lwu_toa', 'dim':'2D', },
'SWDSFC':{'file':'ss_swd_sfc', 'dim':'2D', },
'SLHFLX':{'file':'ss_lh_sfc', 'dim':'2D', },
'SSHFLX':{'file':'ss_sh_sfc', 'dim':'2D', },
}
###########################################################################
......@@ -135,7 +153,8 @@ if __name__ == '__main__':
out_file = os.path.join(out_tmp_dir,
var_name+'_{:%Y%m%d}'.format(dt)+'.nc')
args.append( (inp_file, out_file, dt, box, options) )
args.append( (inp_file, out_file, dt, box, options,
var_dict[var_name]) )
# run function serial or parallel
if n_tasks > 1:
......
......@@ -4,7 +4,7 @@
description: Extract lat-lon box of data from model SAM.
author: Christoph Heim
date created: 20.06.2019
date changed: 09.07.2019
date changed: 10.07.2019
usage: arguments:
1st: n jobs for multiprocessing pool
python: 3.5.2
......@@ -31,6 +31,7 @@ def sellatlon_SAM(inp_file, out_file, dt, box, options):
TM.start('cdo')
TM.stop('cdo')
else:
print('\t\t{:%Y%m%d%H}'.format(dt))
split = os.path.split(out_file)
......@@ -63,7 +64,6 @@ def sellatlon_SAM(inp_file, out_file, dt, box, options):
' '+nco_file),
output=out_file)
print('\t\t{:%Y%m%d%H} completed'.format(dt))
TM.stop('cdo')
# delete tmp_file
......@@ -93,7 +93,10 @@ if __name__ == '__main__':
# variables to extract
var_names = ['QC', 'T']
#var_names = ['QC']
var_names = ['QV', 'QC', 'T', 'W',
'U10M', 'V10M', 'T2M', 'LWUTOA', 'SWDSFC',
'SLHFLX', 'SSHFLX']
#var_names = ['T2M']
# model resolutions [km] of simulations
ress = [4]
......@@ -104,20 +107,41 @@ if __name__ == '__main__':
# options for computation
options = {}
options['recompute'] = 0
options['rm_tmp_files'] = 0
options['recompute'] = 0
options['rm_tmp_files'] = 1
#options['redo_mergetime'] = 1
###########################################################################
# SAM SPECIFIC SETTINGS
###########################################################################
var_dict = {
'QC':{'file':'QC',
'loc':'OUT_3D','fntime':(-16,-6),},
'T':{'file':'TABS',
'loc':'OUT_3D','fntime':(-18,-8),},
'QV' :{'file':'QV',
'loc':'OUT_3D','fntime':(-16,-6),},
'QC' :{'file':'QC',
'loc':'OUT_3D','fntime':(-16,-6),},
'T' :{'file':'TABS',
'loc':'OUT_3D','fntime':(-18,-8),},
'W' :{'file':'W',
'loc':'OUT_3D','fntime':(-15,-5),},
'U10M' :{'file':'U10m',
'loc':'OUT_2D','fntime':(-21,-11),},
'V10M' :{'file':'V10m',
'loc':'OUT_2D','fntime':(-21,-11),},
'T2M' :{'file':'T2mm',
'loc':'OUT_2D','fntime':(-21,-11),},
'LWUTOA':{'file':'LWNTA',
'loc':'OUT_2D','fntime':(-22,-12),},
'SWDSFC':{'file':'SWDSA',
'loc':'OUT_2D','fntime':(-22,-12),},
'SLHFLX':{'file':'LHF',
'loc':'OUT_2D','fntime':(-20,-10),},
'SSHFLX':{'file':'SHF',
'loc':'OUT_2D','fntime':(-20,-10),},
}
dt = 7.5
base_time = datetime(2016,8,1)
###########################################################################
......@@ -154,12 +178,18 @@ if __name__ == '__main__':
Path(out_tmp_dir).mkdir(parents=True, exist_ok=True)
# find times and files that should be extracted
inp_files_glob = glob.glob(os.path.join(inp_dir,
'*_'+var_dict[var_name]['file']+'.nc'))
if var_dict[var_name]['loc'] == 'OUT_3D':
inp_files_glob = glob.glob(os.path.join(inp_dir,
'*_'+var_dict[var_name]['file']+'.nc'))
elif var_dict[var_name]['loc'] == 'OUT_2D':
inp_files_glob = glob.glob(os.path.join(inp_dir,
'*'+var_dict[var_name]['file']+'*.nc'))
times = [base_time + timedelta(seconds=dt*int(
f[var_dict[var_name]['fntime'][0]:
var_dict[var_name]['fntime'][1]]))
for f in inp_files_glob]
use_times = [dt for dt in times if dt >= first_date and
dt < last_date+timedelta(days=1)]
use_files = [inp_files_glob[i]
......
......@@ -4,7 +4,7 @@
description: Extract lat-lon box of data from model ICON.
author: Christoph Heim
date created: 27.06.2019
date changed: 09.07.2019
date changed: 10.07.2019
usage: arguments:
1st: n jobs for multiprocessing pool
python: 3.5.2
......@@ -35,7 +35,7 @@ def comp_weights_file(target_grid, weights_file, inp_file, grid_def_file,
def sellatlon_ICON(inp_file, out_file, grid_def_file, weights_file,
target_grid, dt, box, options):
target_grid, dt, box, options, var_dict):
"""
"""
......@@ -50,13 +50,21 @@ def sellatlon_ICON(inp_file, out_file, grid_def_file, weights_file,
# cdo
TM.start('cdo')
ofile = cdo.remap(target_grid, weights_file,
input=(
' -sellevidx,'+
str(box['vert0'])+'/'+str(box['vert1'])+
' -setgrid,'+grid_def_file+
' '+inp_file),
output=out_file, options='-P 1 -f nc')
if var_dict['dim'] == '3d':
ofile = cdo.remap(target_grid, weights_file,
input=(
' -sellevidx,'+
str(box['vert0'])+'/'+str(box['vert1'])+
' -setgrid,'+grid_def_file+
' '+inp_file),
output=out_file, options='-P 1 -f nc')
elif var_dict['dim'] == '2d':
ofile = cdo.remap(target_grid, weights_file,
input=(
' -setgrid,'+grid_def_file+
#' -selname,'+var_dict['key']+
' '+inp_file),
output=out_file, options='-P 1 -f nc')
print('\t\t{:%Y%m%d%H} completed'.format(dt))
TM.stop('cdo')
......@@ -84,17 +92,24 @@ if __name__ == '__main__':
# variables to extract
var_names = ['QC', 'T']
#var_names = ['QC']
var_names = ['QV', 'QC', 'T', 'W',
'U10M', 'V10M', 'T2M', 'LWUTOA', 'SWTSFC', 'SWDIFFUSFC',
'SLHFLX', 'SSHFLX']
var_names = ['SLHFLX']
#var_names = ['T']
# model resolutions [km] of simulations
ress = [10,5,2.5]
ress = [10,2.5]
#ress = [5]
#ress = [10]
ress = [10]
#ress = [2.5]
# date range
first_date = datetime(2016,8,10)
last_date = datetime(2016,8,19)
last_date = datetime(2016,8,10)
# options for computation
options = {}
......@@ -106,8 +121,19 @@ if __name__ == '__main__':
###########################################################################
grid_def_base_dir = os.path.join('/work','bk1040','experiments', 'input')
var_dict = {
'QC':{'file':'tot_qc_dia',},
'T':{'file':'t',},
'QV' :{'file':'qv', 'dim':'3d', },
'QC' :{'file':'tot_qc_dia', 'dim':'3d', },
'T' :{'file':'t', 'dim':'3d', },
'W' :{'file':'w', 'dim':'3d', },
'U10M' :{'file':'atm3_2d_ml', 'dim':'2d', 'key':'10u'},
'V10M' :{'file':'atm3_2d_ml', 'dim':'2d', 'key':'10v'},
'T2M' :{'file':'atm3_2d_ml', 'dim':'2d', 'key':'2t'},
'LWUTOA' :{'file':'atm_2d_avg_ml', 'dim':'2d', 'key':'nlwrf_2'},
'SWTSFC' :{'file':'atm_2d_avg_ml', 'dim':'2d', 'key':'nswrf'},
'SWDIFFUSFC':{'file':'atm_2d_avg_ml', 'dim':'2d', 'key':'uswrf_2'},
'SLHFLX' :{'file':'atm2_2d_ml', 'dim':'2d', 'key':'SHFL_S'},
'SSHFLX' :{'file':'atm2_2d_ml', 'dim':'2d', 'key':'LHFL_S'},
}
grid_dict = {
10: {'grid_def_file':os.path.join(grid_def_base_dir,
......@@ -179,12 +205,14 @@ if __name__ == '__main__':
'*_{}_*{:%Y%m%d}*'.format(
var_dict[var_name]['file'], dt)))
inp_file = os.path.join(inp_files_glob[0])
#print(inp_file)
#quit()
out_file = os.path.join(out_tmp_dir,
var_name+'_{:%Y%m%d}'.format(dt)+'.nc')
args.append( (inp_file, out_file, grid_def_file,
weights_file, target_grid,
dt, box, options) )
dt, box, options, var_dict[var_name]) )
if ((not os.path.exists(weights_file)) or
(not os.path.exists(target_grid))):
......
......@@ -113,7 +113,7 @@ if __name__ == '__main__':
#var_names = ['QC']
# model resolutions [km] of simulations
ress = [7.5, 3.75]
#ress = [7.5, 3.75]
#ress = [3.75]
ress = [7.5]
......
......@@ -134,8 +134,8 @@ if __name__ == '__main__':
'*'+var_dict[var_name]['vdim']+'*'))
#times = [datetime.strptime(file[-12:], '%Y%m%d%H%M') for file in inp_files]
#times = [file[-12:] for file in inp_files]
print(inp_files[0][-12:])
print(datetime.strptime(inp_files[0][-12:]))
print(datetime.strptime(inp_files[0][-12:-2], '%Y%m%d%H'))
#print(datetime.strptime(str(inp_files[0][-12:-2].split(' ')[0]), '%Y%m%d%H%M'))
#print(times)
quit()
out_file = os.path.join(out_tmp_dir,
......
......@@ -96,7 +96,8 @@ if __name__ == '__main__':
def mergetime(inp_folder, out_folder, var_name):
inp_files = glob.glob(os.path.join(inp_folder,var_name+'*'))
inp_files = glob.glob(os.path.join(inp_folder,var_name+'_*'))
inp_files.sort()
out_file = os.path.join(out_folder,var_name+'.nc')
cdo.mergetime(input=inp_files, output=out_file, options='-O')
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