diff --git a/modules/amv/caliop_clavrx_amv.py b/modules/amv/caliop_clavrx_amv.py index 817958fb415f9f6879a7da3911337cfcdc5d7863..0d70be2ad39b786bc00d593499c4b0547f6d1065 100644 --- a/modules/amv/caliop_clavrx_amv.py +++ b/modules/amv/caliop_clavrx_amv.py @@ -7,6 +7,7 @@ from netCDF4 import Dataset from aeolus.datasource import get_datasource, CLAVRx_CALIPSO, get_parameters_caliop_clavrx from util.util import haversine_np from amv.intercompare import * +from util.util import pressure_to_altitude amv_file_duration = 60 # minutes half_width = 30 # search box centered on CALIOP profile (FGF coordinates) @@ -40,7 +41,7 @@ def get_search_box(cc, ll): return c_rng, l_rng -def match_calipso_clavrx_to_amvs(calipso_clavrx_ds, calipso_clavrx_file, amv_files, calipso_clavrx_params): +def match_calipso_clavrx_to_amvs(calipso_clavrx_ds, calipso_clavrx_file, amv_files, calipso_clavrx_params, gfs_ds): nav = amv_files.get_navigation() amv_params = amv_files.get_parameters() all_params = [amv_files.lon_name, amv_files.lat_name, amv_files.elem_name, amv_files.line_name] + amv_params @@ -55,6 +56,14 @@ def match_calipso_clavrx_to_amvs(calipso_clavrx_ds, calipso_clavrx_file, amv_fil if f_idx is None: return None + gfs_fname, _, _ = gfs_ds.get_file(nom_time) + if gfs_fname is None: + return None + gfs_xr = xr.open_dataset(gfs_fname) + gfs_press = gfs_xr['pressure levels'] + gfs_press = gfs_press.values + gfs_press = gfs_press[::-1] + match_dict[nom_time] = [] amvs_nd = get_amv_nd(amv_fname, delimiter=',') @@ -116,6 +125,19 @@ def match_calipso_clavrx_to_amvs(calipso_clavrx_ds, calipso_clavrx_file, amv_fil match_dict[nom_time].append((cc, ll, lon, lat, f_idx, data_da, amvs_da, dist_to_amvs)) + lons = amv_lons[in_box] + lats = amv_lats[in_box] + lons = lons[s_idxs] + lats = lats[s_idxs] + temp_prof = get_vert_profile_s(gfs_ds, ['temperature'], lons, lats, method='nearest') + temp_prof = temp_prof.values + temp_prof_s = temp_prof[0, :, :] + temp_prof_s = temp_prof_s[:, ::-1] + + for k in range(num_amvs): + alt = pressure_to_altitude(param_s[4, k], None, gfs_press, temp_prof_s[k, :]) + print(alt) + return match_dict @@ -282,7 +304,7 @@ def create_file(match_dct, output_path, target_filepath, caliop_clavrx_params, a rootgrp.close() -def run_caliop_clavrx_amv_match(output_path, path_to_caliop_clavrx, path_to_amvs, amv_source='OPS', band='14'): +def run_caliop_clavrx_amv_match(output_path, path_to_caliop_clavrx, path_to_amvs, path_to_gfs, amv_source='OPS', band='14'): caliop_clavrx_params = get_parameters_caliop_clavrx(filename=caliop_clvrx_exmpl_file) caliop_clavrx_ds = CLAVRx_CALIPSO(path_to_caliop_clavrx) @@ -291,8 +313,10 @@ def run_caliop_clavrx_amv_match(output_path, path_to_caliop_clavrx, path_to_amvs amv_params = amv_ds.get_parameters() amv_filenames = amv_ds.flist + gfs_ds = get_datasource(path_to_gfs, 'GFS') + for file in caliop_clavrx_ds.flist: - match_dict = match_calipso_clavrx_to_amvs(caliop_clavrx_ds, file, amv_ds, caliop_clavrx_params) + match_dict = match_calipso_clavrx_to_amvs(caliop_clavrx_ds, file, amv_ds, caliop_clavrx_params, gfs_ds) if match_dict is None: continue