Skip to content
Snippets Groups Projects
Commit 374bdaed authored by tomrink's avatar tomrink
Browse files

minor

parent 8a1fb206
No related branches found
No related tags found
No related merge requests found
...@@ -1922,6 +1922,113 @@ def create_file(filename, aeolus_to_amv_dct, aeolus_dct, amv_files, cld_lyr=Fals ...@@ -1922,6 +1922,113 @@ def create_file(filename, aeolus_to_amv_dct, aeolus_dct, amv_files, cld_lyr=Fals
rootgrp.close() rootgrp.close()
def create_file_new(match_dct, filename, amv_params):
grd_x_len = 9
grd_y_len = 9
num_aparams = 7
num_aprofs = len(match_dct)
max_num_alevels = 0
alons = []
alats = []
atimes = []
elems = []
lines = []
# scan to get max num levels
keys = list(match_dct.keys())
for key in keys:
tup = match_dct.get(key)
prof = tup[4]
lat = prof[0, 0]
lon = prof[0, 1]
alons.append(lon)
alats.append(lat)
atimes.append(tup[0])
elems.append(tup[1])
lines.append(tup[2])
nlevs = prof.shape[0]
if nlevs > max_num_alevels:
max_num_alevels = nlevs
alons = np.array(alons)
alats = np.array(alats)
atimes = np.array(atimes)
elems = np.array(elems)
lines = np.array(lines)
# Sample file to retrieve and copy variable attributes
rg_exmpl = Dataset('/home/rink/data/clavrx/clavrx_OR_ABI-L1b-RadF-M6C01_G16_s20192930000343.level2.nc', 'r')
# the top level group for the output file
rootgrp = Dataset(filename, 'w', format='NETCDF4')
dim_amvs = rootgrp.createDimension('num_aeolus_params', size=num_aparams)
dim_alevs = rootgrp.createDimension('max_num_aeolus_levels', size=max_num_alevels)
dim_num_aeolus_prof = rootgrp.createDimension('num_aeolus_profs', size=num_aprofs)
dim_grd_x = rootgrp.createDimension('grd_x_len', size=grd_x_len)
dim_grd_y = rootgrp.createDimension('grd_y_len', size=grd_y_len)
prf_time = rootgrp.createVariable('time', 'f4', ['num_aeolus_profs'])
# ---- Profile variables ---------------
prf_lon = rootgrp.createVariable('prof_longitude', 'f4', ['num_aeolus_profs'])
prf_lon.units = 'degrees east'
prf_lat = rootgrp.createVariable('prof_latitude', 'f4', ['num_aeolus_profs'])
prf_lat.units = 'degrees north'
prf_time.units = 'seconds since 1970-01-1 00:00:00'
prf_elem = rootgrp.createVariable('FD_elem', 'f4', ['num_aeolus_profs'])
prf_line = rootgrp.createVariable('FD_line', 'f4', ['num_aeolus_profs'])
prf_azm = rootgrp.createVariable('prof_azm', 'f4', ['num_aeolus_profs', 'max_num_aeolus_levels'])
prf_azm.units = 'degree'
prf_spd = rootgrp.createVariable('prof_spd', 'f4', ['num_aeolus_profs', 'max_num_aeolus_levels'])
prf_spd.units = 'm s-1'
prf_hht = rootgrp.createVariable('prof_hht', 'f4', ['num_aeolus_profs', 'max_num_aeolus_levels'])
prf_hht.units = 'meter'
prf_hhb = rootgrp.createVariable('prof_hhb', 'f4', ['num_aeolus_profs', 'max_num_aeolus_levels'])
prf_hhb.units = 'meter'
# ----- Product variables ----------------
nc4_vars = []
var_s = rg_exmpl.variables
for pidx, param in enumerate(amv_params):
v = var_s[param]
attr_s = v.ncattrs()
if '_FillValue' in attr_s:
var = rootgrp.createVariable(param, v.dtype, ['num_aeolus_profs', 'grd_y_len', 'grd_x_len'], fill_value=v.getncattr('_FillValue'))
else:
var = rootgrp.createVariable(param, v.dtype, ['num_aeolus_profs', 'grd_y_len', 'grd_x_len'])
# copy attributes from example to new output variable of the same name
for attr in attr_s:
if attr != '_FillValue':
var.setncattr(attr, v.getncattr(attr))
nc4_vars.append(var)
# Write data to file ---------------------
prf_lon[:] = alons
prf_lat[:] = alats
prf_elem[:] = elems
prf_line[:] = lines
prf_time[:] = atimes
for idx, key in enumerate(keys):
tup = match_dct.get(key)
prof = tup[4]
param_nd = tup[5]
nlevs = prof.shape[0]
for k in range(nlevs):
prf_spd[idx,k] = prof[k,6]
prf_azm[idx,k] = prof[k,5]
prf_hht[idx,k] = prof[k,3]
prf_hhb[idx,k] = prof[k,4]
for pidx, param in enumerate(clvrx_params):
nc4_vars[pidx][idx, :, :] = param_nd[pidx, :, :]
rg_exmpl.close()
rootgrp.close()
# aeolus_files_dir: S4 NOAA txt output files # aeolus_files_dir: S4 NOAA txt output files
# amv_files_dir: G16/17 AMV product files # amv_files_dir: G16/17 AMV product files
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment