From b1ed5fa9a517ccd9e7f9af6ecad7ffcef762839a Mon Sep 17 00:00:00 2001 From: David Jean du Preez Date: Wed, 3 Aug 2022 08:49:56 +0200 Subject: [PATCH] fix profile func --- configurations/mbees_les_test_10.conf | 6 +++--- dynamic/palm_dynamic.py | 25 +++++++++++++------------ dynamic/palm_dynamic_aerosol.py | 6 +++--- dynamic/palm_dynamic_output.py | 2 +- dynamic/palm_wrf_utils.py | 22 +++++++++++----------- 5 files changed, 31 insertions(+), 30 deletions(-) diff --git a/configurations/mbees_les_test_10.conf b/configurations/mbees_les_test_10.conf index 2918b51..d85f0e2 100644 --- a/configurations/mbees_les_test_10.conf +++ b/configurations/mbees_les_test_10.conf @@ -8,7 +8,7 @@ scenario = 'les_test' nested_domain = False # Dynamic driver output directory and filename -dynamic_driver_file = "/cfs/home/d/u/dupreeda/MBEES/PALM/palm_model_system-v21.10/JOBS/augs3_1_3/INPUT/augs3_1_dynamic_12hr" +dynamic_driver_file = "/cfs/home/d/u/dupreeda/MBEES/PALM/palm_model_system-v21.10/JOBS/augs3_1_3/INPUT/augs3_1_dynamic_2dy" # Import grid parameters for dynamic driver from static driver grid_from_static = True @@ -28,12 +28,12 @@ dz_stretch_factor = 1.00 dz_max = 10.0 # Time origin and extent of the simulation (format YYYY-MM-DD hh:mm:ss) -origin_time = "2022-03-16 06:00:00" +origin_time = "2022-03-16 23:00:00" simulation_hours = 3 # Directory for wrf_chem input data and mask wrf_dir_name = '/cfs/home/d/u/dupreeda/MBEES/PALM/wrf_chem_data' -wrf_file_mask = "wrfout_d01_2022*" +wrf_file_mask = "wrfout_d01_2022-03*" wrf_hybrid_levs = False vinterp_terrain_smoothing = None # Directory for interpolated files diff --git a/dynamic/palm_dynamic.py b/dynamic/palm_dynamic.py index 079f9d1..17f4836 100644 --- a/dynamic/palm_dynamic.py +++ b/dynamic/palm_dynamic.py @@ -84,6 +84,7 @@ print('WRF-CHEM file path:', wrf_dir_name) print('WRF-CHEM: dynamics file mask:', wrf_file_mask) print('Simulation start time:', origin_time) print('Simulation hours:', simulation_hours) + if aerosol_wrfchem: print('\nNumber of aerosol size bins in subranges (nbin): ', nbin) print('Aerosol diameter limits of subrnages (reglim): ', reglim) @@ -243,9 +244,9 @@ ztop = z_levels[-1] + dzs / 2. # get complete list of wrf files wrf_file_list = glob.glob(os.path.join(wrf_dir_name, wrf_file_mask)) # get simulation origin and final time as datetime -start_time = datetime.strptime(origin_time, '%Y-%m-%d %H:%M:%S') -end_time = start_time + timedelta(hours=simulation_hours) -end_time_rad = end_time +start_time = datetime.strptime(origin_time, '%Y-%m-%d %H:%M:%S') +end_time = start_time + timedelta(hours=simulation_hours) +end_time_rad = end_time print('\nPALM simulation extent', start_time, end_time, simulation_hours) if nested_domain: print('Nested domain - process only initialization.') @@ -253,13 +254,13 @@ if nested_domain: end_time = start_time # get wrf times and sort wrf files by time -#print('\nAnalyse WRF files dates:') +#print('\nWRF files in directory:') file_times = [] for wrf_file in wrf_file_list: nc_wrf = netCDF4.Dataset(wrf_file, "r", format="NETCDF4") - ta = nc_wrf.variables['Times'][:] - t = ta.tobytes().decode("utf-8") - td = datetime.strptime(t, '%Y-%m-%d_%H:%M:%S') + ta = nc_wrf.variables['Times'][:] + t = ta.tobytes().decode("utf-8") + td = datetime.strptime(t, '%Y-%m-%d_%H:%M:%S') #print(os.path.basename(wrf_file), ': ', td) file_times.append((td,wrf_file)) nc_wrf.close() @@ -272,7 +273,7 @@ for tf in file_times: times.append(tf[0]) wrf_files.append(tf[1]) -print('PALM output times:', ', '.join('{}'.format(t) for t in times)) +print('WRF input file times:', ', '.join('{}'.format(t) for t in times)) if not times.__contains__(start_time): print('WRF files does not contain PALM origin_time timestep - cannot process!') @@ -319,10 +320,10 @@ interp_files = [] regridder = None for wrf_file in wrf_files_proc: print ("Input wrf file: ", wrf_file) - pth,fnam = os.path.split(wrf_file) - hinterp_file = (os.path.join(interp_dir_name, fnam))+"_"+simul_id+'.hinterp' - hinterp_log = (os.path.join(interp_dir_name, fnam))+"_"+simul_id+'.hinterp.log' - vinterp_file = (os.path.join(interp_dir_name, fnam))+"_"+simul_id+'.interp' + pth,fnam = os.path.split(wrf_file) + hinterp_file = (os.path.join(interp_dir_name, fnam)) +"_"+ simul_id +'.hinterp' + hinterp_log = (os.path.join(interp_dir_name, fnam)) +"_"+ simul_id +'.hinterp.log' + vinterp_file = (os.path.join(interp_dir_name, fnam)) +"_"+ simul_id +'.interp' interp_files.append(vinterp_file) if wrf_interpolation: diff --git a/dynamic/palm_dynamic_aerosol.py b/dynamic/palm_dynamic_aerosol.py index 79ccf72..2039b22 100644 --- a/dynamic/palm_dynamic_aerosol.py +++ b/dynamic/palm_dynamic_aerosol.py @@ -36,14 +36,14 @@ def upwind_location(zlev, u, v): prf_x = round(wnd_dir.shape[1]/2) elif 45 < wnd_avg <= 135: prf_y = round(wnd_dir.shape[0]/2) - prf_x = round(wnd_dir.shape[1]) + prf_x = round(wnd_dir.shape[1]-1) elif 135 < wnd_avg <= 225: - prf_y = wnd_dir.shape[0] + prf_y = wnd_dir.shape[0]-1 prf_x = round(wnd_dir.shape[1]/2) else: prf_y = round(wnd_dir.shape[0]/2) prf_x = 0 - + return prf_x, prf_y diff --git a/dynamic/palm_dynamic_output.py b/dynamic/palm_dynamic_output.py index fcc63bc..e96b284 100644 --- a/dynamic/palm_dynamic_output.py +++ b/dynamic/palm_dynamic_output.py @@ -270,7 +270,7 @@ def palm_dynamic_output(wrf_files, interp_files, dynamic_driver_file, times_sec, # read interpolated files and write values for dynamical & chemical variables def add_interpValues(dynam_chem_variables): - print('\tCreating initialisation variablesin dynamic driver') + print('\tCreating initialisation variables in dynamic driver') infile = netCDF4.Dataset(interp_files[0], "r", format="NETCDF4") outfile = netCDF4.Dataset(dynamic_driver_file, "r+", format="NETCDF4") # initialization variables diff --git a/dynamic/palm_wrf_utils.py b/dynamic/palm_wrf_utils.py index 7443ca8..d38f081 100644 --- a/dynamic/palm_wrf_utils.py +++ b/dynamic/palm_wrf_utils.py @@ -221,10 +221,10 @@ def calc_gp(f, ph): def palm_wrf_vertical_interp(infile, outfile, wrffile, z_levels, z_levels_stag, z_soil_levels, origin_z, terrain, wrf_hybrid_levs, vinterp_terrain_smoothing,nz,ny,nx): - zdim = len(z_levels) - zwdim = len(z_levels_stag) - zsoildim = len(z_soil_levels) - dimnames = ['z', 'zw', 'zsoil'] # dimnames of palm vertical dims + zdim = len(z_levels) + zwdim = len(z_levels_stag) + zsoildim = len(z_soil_levels) + dimnames = ['z', 'zw', 'zsoil'] # dimnames of palm vertical dims dimensions = [zdim , zwdim, zsoildim] try: @@ -257,28 +257,28 @@ def palm_wrf_vertical_interp(infile, outfile, wrffile, z_levels, z_levels_stag, wrfterr.min(), wrfterr.max(), target_terrain.min(), target_terrain.max())) # Load original dry air column pressure - mu = nc_infile.variables['MUB'][0,:,:] + nc_infile.variables['MU'][0,:,:] + mu = nc_infile.variables['MUB'][0,:,:] + nc_infile.variables['MU'][0,:,:] pht = nc_wrf.variables['P_TOP'][0] # Shift column pressure so that it matches PALM terrain - t = wrf_t(nc_infile) + t = wrf_t(nc_infile) mu2 = barom_pres(mu+pht, target_terrain*g, gpf[0,:,:], t[0,:,:])-pht # Calculate original and shifted 3D dry air pressure if wrf_hybrid_levs: - phf, phh = calc_ph_hybrid(nc_wrf, mu) + phf, phh = calc_ph_hybrid(nc_wrf, mu) phf2, phh2 = calc_ph_hybrid(nc_wrf, mu2) else: - phf, phh = calc_ph_sigma(nc_wrf, mu) + phf, phh = calc_ph_sigma(nc_wrf, mu) phf2, phh2 = calc_ph_sigma(nc_wrf, mu2) # Shift 3D geopotential according to delta dry air pressure - tf = np.concatenate((t, t[-1:,:,:]), axis=0) # repeat highest layer + tf = np.concatenate((t, t[-1:,:,:]), axis=0) # repeat highest layer gpf2 = barom_gp(gpf, phf2, phf, tf) # For half-levs, originate from gp full levs rather than less accurate gp halving gph2 = barom_gp(gpf[:-1,:,:], phh2, phf[:-1,:,:], t) - zf = gpf2 * (1./g) - origin_z - zh = gph2 * (1./g) - origin_z + zf = gpf2 * (1./g) - origin_z + zh = gph2 * (1./g) - origin_z # Report gpdelta = gpf2 - gpf -- GitLab