diff --git a/modules/aeolus/aeolus_amv.py b/modules/aeolus/aeolus_amv.py index 27370b7ecda54705ff74ae550d7c27d22ec5ed23..4616cfdd95716dd301caf79215300a78f0d11621 100644 --- a/modules/aeolus/aeolus_amv.py +++ b/modules/aeolus/aeolus_amv.py @@ -1468,6 +1468,106 @@ def match_aeolus_to_clavrx(aeolus_dict, clvrx_files): return match_dict +def create_file_2(match_dct, filename, clvrx_params=['cld_height_acha', 'cld_press_acha', 'cld_temp_acha']): + grd_x_len = 7 + grd_y_len = 7 + 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) + + # 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' + prof_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 = [] + #out_params = amv_files.get_out_parameters() + #meta_dict = amv_files.get_meta_dict() + for pidx, param in enumerate(clvrx_params): + #u, t = meta_dict.get(param) + u = None + t = 'f4' + var = rootgrp.createVariable(param, t, ['num_aeolus_profs', 'grd_y_len', 'grd_x_len']) + if u is not None: + var.units = u + nc4_vars.append(var) + + # Write data to file... + for idx, key in enumerate(keys): + tup = match_dct.get(key) + prof = tup[4] + param_nd = tup[5] + + for pidx, param in enumerate(clvrx_params): + nc4_vars[pidx][idx, :, :] = param_nd[pidx, :, :] + + prf_spd[idx,:] = prof[:,6] + prf_azm[idx,:] = prof[:,5] + prf_hht[idx,:] = prof[:,3] + prf_hhb[idx,:] = prof[:,4] + + prf_lon[:] = alons + prf_lat[:] = alats + prf_elem[:] = elems + prf_line[:] = lines + prf_time[:] = atimes + + rootgrp.close() + + def get_search_box(nav, lon, lat): cc, ll = nav.earth_to_lc(lon, lat) if cc is None: