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

Hopefully last updates from mistral.

parent 6209befb
......@@ -4,7 +4,7 @@
description: Extract lat-lon box of data from model NICAM.
author: Christoph Heim
date created: 27.06.2019
date changed: 27.02.2020
date changed: 06.04.2020
usage: arguments:
1st: n jobs for multiprocessing pool
"""
......@@ -15,13 +15,13 @@ from datetime import datetime, timedelta
from multiprocessing import Pool
from pathlib import Path
from cdo import Cdo
from package.utilities import Timer, cdo_mergetime
from package.utilities import Timer, cdo_mergetime, write_grid_file
from namelist import domain, padding
from functions import paste_dir_names
###############################################################################
def sellatlon_NICAM(inp_file, out_file, dt, box, options, var_dict,
var_name, res):
var_name, res, target_grid):
TM = Timer()
......@@ -38,15 +38,28 @@ def sellatlon_NICAM(inp_file, out_file, dt, box, options, var_dict,
if var_dict['dim'] == '3D':
input = ('-sellevidx,'+str(box['vert0'])+'/'+
str(box['vert1'])+' '+inp_file)
str(box['vert1'])+
' -settaxis,{:%Y-%m-%d,%H:%M:%S},3h'.format(dt)+
' '+inp_file)
elif var_dict['dim'] == '2D':
input=inp_file
input = ('-settaxis,{:%Y-%m-%d,%H:%M:%S},15min'.format(dt)+
' '+inp_file)
tmp_file = '{}.tmp'.format(out_file)
ofile = cdo.sellonlatbox(
box['lon'].start,box['lon'].stop,
box['lat'].start,box['lat'].stop,
input=input,
output=out_file)
output=tmp_file)
# Have to remap because of inconsistencies in NICAM_3.5 model output.
ofile = cdo.remapbil(target_grid,
input=tmp_file, output=out_file,
options='-f nc4')
# remove temporary file
os.remove(tmp_file)
TM.stop('cdo')
......@@ -75,14 +88,18 @@ if __name__ == '__main__':
# variables to extract
var_names = ['QV', 'QC', 'T', 'W', 'U', 'V', 'P',
'MSLP', 'U10M', 'V10M', 'T2M',
'LWUTOA', 'SWDSFC', 'SWUTOA',
'LWUTOA', 'SWUTOA',
'SST', 'SLHFLX', 'SSHFLX',
'TQC', 'TQI',
'PP']
# missing: TQV, CLCL, CLCT, and in NICAM-3.5 also SST
# missing: PS
var_names = ['TQI']
var_names = ['QV', 'QC', 'T', 'W', 'U', 'V', 'P',
'MSLP', 'U10M', 'V10M', 'T2M',
'LWUTOA', 'SWUTOA',
'SLHFLX', 'SSHFLX',
'TQC', 'TQI',
'PP']
"""
parallel tasks:
......@@ -97,13 +114,14 @@ if __name__ == '__main__':
# model resolutions [km] of simulations
ress = [7, 3.5]
ress = [7]
#ress = [3.5]
ress = [3.5]
# date range
first_date = datetime(2016,8,1)
last_date = datetime(2016,9,9)
#last_date = datetime(2016,8,1)
exceptions = ['7_QC_20160801', '7_QC_20160802', '7_QC_20160803', '7_QC_20160804',
'7_T_20160815', '7_T_20160831', '7_T_20160901', '7_T_20160902',
'7_T_20160903', '7_T_20160904', '7_T_20160905', '7_T_20160906',
......@@ -116,7 +134,8 @@ if __name__ == '__main__':
'7_V_20160907', '7_V_20160908', '7_V_20160909',
'7_P_20160815', '7_P_20160831', '7_P_20160901', '7_P_20160902',
'7_P_20160903', '7_P_20160904', '7_P_20160905', '7_P_20160906',
'7_P_20160907', '7_P_20160908', '7_P_20160909']
'7_P_20160907', '7_P_20160908', '7_P_20160909',
]
# options for computation
options = {}
......@@ -177,6 +196,10 @@ if __name__ == '__main__':
print('############## var ' + var_name + ' ##################')
for res in ress:
print('############## res ' + str(res) + ' ##################')
target_grid = os.path.join('grids','latlon_{}km_dom_{}'.format(
res, domain['code']))
write_grid_file(box, target_grid, res)
# data input directory
sim_name = model_name + '-' + str(res) + 'km'
......@@ -206,7 +229,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,
var_dict[var_name], var_name, res) )
var_dict[var_name], var_name, res,
target_grid) )
# run function serial or parallel
if n_tasks > 1:
......
......@@ -142,7 +142,7 @@ if __name__ == '__main__':
'2D':['TQV'],
'3D':['U', 'P', 'V'],
'3D':['P'],
'3D':['T'],
#'3D':['U'],
#'3D':['V'],
#'3D':['U', 'V'],
......@@ -168,7 +168,7 @@ if __name__ == '__main__':
#ress = [7.5]
ress = [3.75]
i_bash_output = 0
i_bash_output = 1
# date range
# 7.5
......@@ -177,8 +177,8 @@ if __name__ == '__main__':
######################
## done U, V, P
#first_date = datetime(2016,8,1)
#last_date = datetime(2016,8,10)
first_date = datetime(2016,9,4)
last_date = datetime(2016,9,5)
## done U, V, P
#first_date = datetime(2016,8,11)
......
......@@ -4,7 +4,7 @@
description: Extract lat-lon box of data from model GEOS.
author: Christoph Heim
date created: 09.07.2019
date changed: 01.04.2020
date changed: 02.04.2020
usage: arguments:
1st: n jobs for multiprocessing pool
"""
......@@ -44,6 +44,8 @@ def sellatlon_GEOS(inp_file, out_file, dt, box, options, var_name, var_dict,
str(box['vert1'])+
' -selname,'+var_dict[var_name]['key']+
' '+inp_file),
#input=(' -selname,'+var_dict[var_name]['key']+
# ' '+inp_file),
output=tmp_file)
ofile = cdo.remapbil(target_grid, input=tmp_file, output=out_file)
......@@ -66,8 +68,8 @@ if __name__ == '__main__':
# box to subselect
box = domain
#box.update({'vert0':1,'vert1':13}) # top 3km
box.update({'vert0':1,'vert1':18}) # top 6km
#box.update({'vert0':1,'vert1':18}) # top 6km
box.update({'vert0':95,'vert1':132}) # top 6km
box['lon'] = slice(box['lon'].start - padding, box['lon'].stop + padding)
box['lat'] = slice(box['lat'].start - padding, box['lat'].stop + padding)
......@@ -82,7 +84,8 @@ if __name__ == '__main__':
'TQC', 'TQI', 'TQV',
'PP']
# missing: SST CLCL CLCT
#var_names = ['V']
var_names = ['H', 'T', 'QV', 'QC', 'W', 'U', 'V', 'P']
#var_names = ['W']
"""
parallel tasks:
......@@ -114,6 +117,21 @@ if __name__ == '__main__':
#first_date = datetime(2016,9,2)
#last_date = datetime(2016,9,9)
first_date = datetime(2016,8,17)
last_date = datetime(2016,8,20)
first_date = datetime(2016,8,21)
last_date = datetime(2016,8,25)
first_date = datetime(2016,8,26)
last_date = datetime(2016,8,30)
first_date = datetime(2016,8,31)
last_date = datetime(2016,9,4)
first_date = datetime(2016,9,5)
last_date = datetime(2016,9,9)
# options for computation
options = {}
options['recompute'] = 0
......
......@@ -256,7 +256,7 @@ if __name__ == '__main__':
# missing: SST
#'3D':['U', 'V'],
#'3D':['U'],
#'2D':['PS', 'TQV', 'CLCL', 'CLCT'],
'2D':['PS'],
#'2D':['LWUTOA', 'T2M'],
}
......
gridtype = lonlat
xsize = 2002
ysize = 1525
xname = lon
xlongname = "longitude"
xunits = "degrees_east"
yname = lat
ylongname = "latitude"
yunits = "degrees_north"
xfirst = -45
xinc = 0.031
yfirst = -30
yinc = 0.031
gridtype = lonlat
xsize = 1001
ysize = 763
xname = lon
xlongname = "longitude"
xunits = "degrees_east"
yname = lat
ylongname = "latitude"
yunits = "degrees_north"
xfirst = -45
xinc = 0.063
yfirst = -30
yinc = 0.063
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