Skip to content
Snippets Groups Projects
Commit 2d8b2212 authored by brunner's avatar brunner
Browse files

No commit message

No commit message
parent 34b5094e
No related branches found
No related tags found
No related merge requests found
...@@ -2,116 +2,132 @@ import sys ...@@ -2,116 +2,132 @@ import sys
import numpy as np import numpy as np
from netCDF4 import Dataset from netCDF4 import Dataset
idir = '/store/empa/em05/parsenov/cosmo_input/icbc/'
odir = '/store/empa/em05/parsenov/cosmo_input/icbc/processed/ensemble/'
half_a=(0,7.367743,210.39389,855.361755,2063.779785,3850.91333,6144.314941,8802.356445,11632.75879,14411.12402,16899.46875,18864.75,20097.40234,20429.86328,19755.10938,18045.18359,15379.80566,12077.44629,8765.053711,6018.019531,3960.291504,1680.640259,713.218079,298.495789,95.636963,0) half_a=(0,7.367743,210.39389,855.361755,2063.779785,3850.91333,6144.314941,8802.356445,11632.75879,14411.12402,16899.46875,18864.75,20097.40234,20429.86328,19755.10938,18045.18359,15379.80566,12077.44629,8765.053711,6018.019531,3960.291504,1680.640259,713.218079,298.495789,95.636963,0)
half_b=(1,0.99401945,0.97966272,0.95182151,0.90788388,0.84737492,0.77159661,0.68326861,0.58616841,0.48477158,0.38389215,0.28832296,0.2024759,0.13002251,0.07353383,0.03412116,0.01114291,0.00181516,0.00007582,0,0,0,0,0,0,0) half_b=(1,0.99401945,0.97966272,0.95182151,0.90788388,0.84737492,0.77159661,0.68326861,0.58616841,0.48477158,0.38389215,0.28832296,0.2024759,0.13002251,0.07353383,0.03412116,0.01114291,0.00181516,0.00007582,0,0,0,0,0,0,0)
date=str(sys.argv[1]) def ct(date, co2_bg):
ifile = Dataset('CT2016.molefrac_glb3x2_'+date[:4]+'-'+date[4:6]+'-'+date[6:8]+'.nc', mode='r') date = str(date)
levs = ifile.variables['level'][:] co2_bg = np.array(co2_bg)
lats = ifile.variables['latitude'][:] ifile = Dataset(idir+'3d_molefractions_1x1_'+date+'.nc', mode='r')
lons = ifile.variables['longitude'][:] levs = ifile.variables['levels'][:]
lats = ifile.variables['latitude'][:]
co2 = np.squeeze(ifile.variables['co2'][:]) lons = ifile.variables['longitude'][:]
p_bound = np.squeeze(ifile.variables['pressure'][:])
ifile.close() co2 = np.squeeze(ifile.variables['co2'][:])*(0.04401/0.02896)
p_bound = np.squeeze(ifile.variables['pressure'][:])
lats_tf=(lats<=63.)&(lats>=35.) ifile.close()
lons_tf=(lons<=34.5)&(lons>=-10.5)
lats=lats[np.logical_and(lats>=35.,lats<=63.)] lats_tf=(lats<=66.5)&(lats>=33.5)
lons=lons[np.logical_and(lons>=-10.5,lons<=34.5)] lons_tf=(lons<=39.5)&(lons>=-13.5)
lats=lats[np.logical_and(lats>=33.5,lats<=66.5)]
co2=co2[:,:,lats_tf,:][:,:,:,lons_tf]*0.04401/0.02896 # * mmCO2/mmAir lons=lons[np.logical_and(lons>=-13.5,lons<=39.5)]
p_bound=p_bound[:,:,lats_tf,:][:,:,:,lons_tf]
p=np.empty(shape=(8,25,15,16)) #lats_tf=(lats<=63.)&(lats>=35.)
for i in range(0,24): #lons_tf=(lons<=34.5)&(lons>=-10.5)
p[:,i,:,:]=(p_bound[:,i,:,:]+p_bound[:,i+1,:,:])/2. #lats=lats[np.logical_and(lats>=35.,lats<=63.)]
sp=np.squeeze(p[:,0,:,:]) #lons=lons[np.logical_and(lons>=-10.5,lons<=34.5)]
hyam=np.empty(25) p_bound=p_bound[:,:,lats_tf,:][:,:,:,lons_tf]
hybm=np.empty(25) p=np.empty(shape=(8,25,34,54))
for i in range(0,25): # p=np.empty(shape=(8,25,15,16)) # was like this before
hyam[i]=(half_a[i]+half_a[i+1])/2. for i in range(0,24):
hybm[i]=(half_b[i]+half_b[i+1])/2. p[:,i,:,:]=(p_bound[:,i,:,:]+p_bound[:,i+1,:,:])/2.
sp=np.squeeze(p[:,0,:,:])
ttt=("00","03","06","09","12","15","18","21") co2=co2[:,:,lats_tf,:][:,:,:,lons_tf]
co2_ens = np.empty(shape=(co2_bg.size,8,25,34,54))
for ti,tt in enumerate(ttt): for i in range(0, co2_bg.size):
co2_ens[i,:,:,:,:] = co2[:,:,:,:]*co2_bg[i]
ofile = Dataset(sys.argv[2]+'/ct_'+date[:4]+date[4:6]+date[6:8]+tt+'.nc', mode='w')
olev = ofile.createDimension('level', len(levs)) hyam=np.empty(25)
olat = ofile.createDimension('lat', len(lats)) hybm=np.empty(25)
olon = ofile.createDimension('lon', len(lons)) for i in range(0,25):
odate = ofile.createDimension('date', 1) hyam[i]=(half_a[i]+half_a[i+1])/2.
hybm[i]=(half_b[i]+half_b[i+1])/2.
olat = ofile.createVariable('lat', np.float64, ('lat',))
olon = ofile.createVariable('lon', np.float64, ('lon',)) ttt=("00","03","06","09","12","15","18","21")
olev = ofile.createVariable('level', np.float64, ('level',))
otime = ofile.createVariable('time', np.float64, ('date',)) for ti,tt in enumerate(ttt):
odate = ofile.createVariable('date', np.float64, ('date',)) ofile = Dataset(odir+'ct_'+date+tt+'.nc', mode='w')
ohyam = ofile.createVariable('hyam', np.float32, ('level',)) olev = ofile.createDimension('level', len(levs))
ohybm = ofile.createVariable('hybm', np.float32, ('level',)) olat = ofile.createDimension('lat', len(lats))
olon = ofile.createDimension('lon', len(lons))
oco2 = ofile.createVariable('CO2_BG', np.float32, ('date','level','lat','lon'),fill_value=-999.99) odate = ofile.createDimension('date', 1)
op = ofile.createVariable('pressure', np.float32, ('date','level','lat','lon'),fill_value=-999.99)
osp = ofile.createVariable('PSURF', np.float32, ('date','lat','lon'),fill_value=-999.99) olat = ofile.createVariable('lat', np.float64, ('lat',))
op0 = ofile.createVariable('P0', np.float32, ('date'),fill_value=-999.99) olon = ofile.createVariable('lon', np.float64, ('lon',))
olev = ofile.createVariable('level', np.float64, ('level',))
odate.comment = 'time-interval average, centered on times in the date axis' otime = ofile.createVariable('time', np.float64, ('date',))
odate.long_name = 'UTC dates and times' odate = ofile.createVariable('date', np.float64, ('date',))
odate.units = 'days since '+date[:4]+'-'+date[4:6]+'-'+date[6:8]+' 00:00:00'
# otime.dtype = 'double' ohyam = ofile.createVariable('hyam', np.float32, ('level',))
ohybm = ofile.createVariable('hybm', np.float32, ('level',))
otime.units = 'seconds since '+date[:4]+'-'+date[4:6]+'-'+date[6:8]+' 00:00:00'
otime.calendar = 'proleptic_gregorian' op = ofile.createVariable('pressure', np.float32, ('date','level','lat','lon'),fill_value=-999.99)
osp = ofile.createVariable('PSURF', np.float32, ('date','lat','lon'),fill_value=-999.99)
olat.standard_name = 'latitude' op0 = ofile.createVariable('P0', np.float32, ('date'),fill_value=-999.99)
olat.long_name = 'latitude'
olat.units = 'degree_north' odate.comment = 'time-interval average, centered on times in the date axis'
olat.axis = 'Y' odate.long_name = 'UTC dates and times'
odate.units = 'days since '+date[:4]+'-'+date[4:6]+'-'+date[6:8]+' 00:00:00'
olon.standard_name = 'longitude' # otime.dtype = 'double'
olon.long_name = 'longitude'
olon.units = 'degree_east' otime.units = 'seconds since '+date[:4]+'-'+date[4:6]+'-'+date[6:8]+' 00:00:00'
olon.axis = 'X' otime.calendar = 'proleptic_gregorian'
ohyam.long_name = 'hybrid A coefficient at layer midpoints' olat.standard_name = 'latitude'
ohyam.units = 'Pa' olat.long_name = 'latitude'
olat.units = 'degree_north'
ohybm.long_name = 'hybrid B coefficient at layer midpoints' olat.axis = 'Y'
ohybm.units = '1'
olon.standard_name = 'longitude'
olev.positive = 'up' olon.long_name = 'longitude'
olev.units = 'levels' olon.units = 'degree_east'
olon.axis = 'X'
oco2.standard_name = 'mass_fraction_of_carbon_dioxide_in_air'
oco2.long_name = 'mass mixing ratio of CO2 from outside Europe' ohyam.long_name = 'hybrid A coefficient at layer midpoints'
oco2.units = 'kg kg-1' ohyam.units = 'Pa'
op.long_name = 'pressure_at_center_levels' ohybm.long_name = 'hybrid B coefficient at layer midpoints'
op.units = 'Pa' ohybm.units = '1'
op.standard_name = 'air pressure'
olev.positive = 'up'
op0.units = 'Pa' olev.units = 'levels'
osp.cell_methods = 'level:mean' op.long_name = 'pressure_at_center_levels'
osp.units = 'Pa' op.units = 'Pa'
osp.long_name = 'surface pressure' op.standard_name = 'air pressure'
osp.table = '128'
osp.lev = '1' op0.units = 'Pa'
olat[:] = lats osp.cell_methods = 'level:mean'
olon[:] = lons osp.units = 'Pa'
olev[:] = levs osp.long_name = 'surface pressure'
odate[:] = 3.*ti/24. osp.table = '128'
otime[:] = ti*3*3600 osp.lev = '1'
oco2[:] = co2[ti,:] olat[:] = lats
osp[:] = sp[ti,:] olon[:] = lons
op[:] = p[ti,:] olev[:] = levs
op0[:] = 1. odate[:] = 3.*ti/24.
ohyam[:] = hyam otime[:] = ti*3*3600
ohybm[:] = hybm
osp[:] = sp[ti,:]
op[:] = p[ti,:]
op0[:] = 1.
ohyam[:] = hyam
ohybm[:] = hybm
for e in range(0, co2_bg.size):
ens = str(e).zfill(3)
oco2 = ofile.createVariable('BG_'+ens, np.float64, ('date','level','lat','lon'),fill_value=-999.99)
oco2.standard_name = 'mass_fraction_of_carbon_dioxide_in_air'
oco2.long_name = 'mass mixing ratio of CO2 from outside Europe'
oco2.units = 'kg kg-1'
oco2[:] = co2_ens[e,ti,:,:,:]
ofile.close() ofile.close()
...@@ -127,17 +127,19 @@ class ObservationOperator(object): ...@@ -127,17 +127,19 @@ class ObservationOperator(object):
logging.info('Multiplying emissions with parameters for lag %d, date %s' % (lag, dt.strftime('%Y%m%d%H'))) logging.info('Multiplying emissions with parameters for lag %d, date %s' % (lag, dt.strftime('%Y%m%d%H')))
for ens in range(0,self.forecast_nmembers): for ens in range(0,self.forecast_nmembers):
dthh = dt.strftime('%H') dthh = dt.strftime('%H')
co2_bg=str((members[ens].param_values[-1]))
ens = str(ens).zfill(3) ens = str(ens).zfill(3)
cdo.setunit("'kg m-2 s-1' -expr,GPP_"+ens+"_F=CO2_GPP_F*parametermap -merge "+os.path.join(dacycle['da.bio.input'], 'gpp_%s.nc' % dt.strftime('%Y%m%d%H')), input = os.path.join(dacycle['restartmap.dir'],"parameters_gpp_lag"+str(lag)+"."+ens+".nc"), output = os.path.join(dacycle['da.bio.input'], 'ensemble', "gpp_"+ens+"_%s.nc" % dt.strftime('%Y%m%d%H'))) cdo.setunit("'kg m-2 s-1' -expr,GPP_"+ens+"_F=CO2_GPP_F*parametermap -merge "+os.path.join(dacycle['da.bio.input'], 'gpp_%s.nc' % dt.strftime('%Y%m%d%H')), input = os.path.join(dacycle['restartmap.dir'],"parameters_gpp_lag"+str(lag)+"."+ens+".nc"), output = os.path.join(dacycle['da.bio.input'], 'ensemble', "gpp_"+ens+"_%s.nc" % dt.strftime('%Y%m%d%H')))
cdo.setunit("'kg m-2 s-1' -expr,RESP_"+ens+"_F=CO2_RESP_F*parametermap -merge "+os.path.join(dacycle['da.bio.input'], 'ra_%s.nc' % dt.strftime('%Y%m%d%H')), input = os.path.join(dacycle['restartmap.dir'],"parameters_resp_lag"+str(lag)+"."+ens+".nc"), output = os.path.join(dacycle['da.bio.input'], 'ensemble', "ra_"+ens+"_%s.nc" % dt.strftime('%Y%m%d%H'))) cdo.setunit("'kg m-2 s-1' -expr,RESP_"+ens+"_F=CO2_RESP_F*parametermap -merge "+os.path.join(dacycle['da.bio.input'], 'ra_%s.nc' % dt.strftime('%Y%m%d%H')), input = os.path.join(dacycle['restartmap.dir'],"parameters_resp_lag"+str(lag)+"."+ens+".nc"), output = os.path.join(dacycle['da.bio.input'], 'ensemble', "ra_"+ens+"_%s.nc" % dt.strftime('%Y%m%d%H')))
if dthh=='00' or dthh=='03' or dthh=='06' or dthh=='09' or dthh=='12' or dthh=='15' or dthh=='18' or dthh=='21': # co2_bg=str((members[ens].param_values[-1]))
cdo.setunit("'kg m-2 s-1' -expr,BG_"+ens+"=CO2_BG*"+co2_bg+" -merge "+os.path.join(dacycle['da.bg.input'], 'ct_%s.nc' % dt.strftime('%Y%m%d%H')), output = os.path.join(dacycle['da.bg.input'], 'ensemble', "ct_"+ens+"_%s.nc" % dt.strftime('%Y%m%d%H'))) co2_bg=str((members[:].param_values[-1]))
if dthh=='00':
icbc4ctdas(dt.strftime('%Y%m%d'), co2_bg)
#cdo.setunit("'kg m-2 s-1' -expr,BG_"+ens+"=CO2_BG*"+co2_bg+" -merge "+os.path.join(dacycle['da.bg.input'], 'ct_%s.nc' % dt.strftime('%Y%m%d%H')), output = os.path.join(dacycle['da.bg.input'], 'ensemble', "ct_"+ens+"_%s.nc" % dt.strftime('%Y%m%d%H')))
cdo.merge(input = os.path.join(dacycle['da.bio.input'], 'ensemble', "gpp_???_%s.nc" % dt.strftime('%Y%m%d%H')), output = os.path.join(dacycle['da.bio.input'], 'ensemble', "gpp_%s.nc" % dt.strftime('%Y%m%d%H'))) cdo.merge(input = os.path.join(dacycle['da.bio.input'], 'ensemble', "gpp_???_%s.nc" % dt.strftime('%Y%m%d%H')), output = os.path.join(dacycle['da.bio.input'], 'ensemble', "gpp_%s.nc" % dt.strftime('%Y%m%d%H')))
cdo.merge(input = os.path.join(dacycle['da.bio.input'], 'ensemble', "ra_???_%s.nc" % dt.strftime('%Y%m%d%H')), output = os.path.join(dacycle['da.bio.input'], 'ensemble', "ra_%s.nc" % dt.strftime('%Y%m%d%H'))) cdo.merge(input = os.path.join(dacycle['da.bio.input'], 'ensemble', "ra_???_%s.nc" % dt.strftime('%Y%m%d%H')), output = os.path.join(dacycle['da.bio.input'], 'ensemble', "ra_%s.nc" % dt.strftime('%Y%m%d%H')))
if dthh=='00' or dthh=='03' or dthh=='06' or dthh=='09' or dthh=='12' or dthh=='15' or dthh=='18' or dthh=='21': # if dthh=='00' or dthh=='03' or dthh=='06' or dthh=='09' or dthh=='12' or dthh=='15' or dthh=='18' or dthh=='21':
cdo.merge(input = os.path.join(dacycle['da.bg.input'], 'ensemble', "ct_???_%s.nc" % dt.strftime('%Y%m%d%H')), output = os.path.join(dacycle['da.bg.input'], 'ensemble', "ct_%s.nc" % dt.strftime('%Y%m%d%H'))) # cdo.merge(input = os.path.join(dacycle['da.bg.input'], 'ensemble', "ct_???_%s.nc" % dt.strftime('%Y%m%d%H')), output = os.path.join(dacycle['da.bg.input'], 'ensemble', "ct_%s.nc" % dt.strftime('%Y%m%d%H')))
os.chdir(dacycle['da.obsoperator.home']) os.chdir(dacycle['da.obsoperator.home'])
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment