def combine_kernels(parameters):
    DDEG_RASTER = float(parameters['DDEG_RASTER'])
    LMAX = int(parameters['LMAX'])
    ddir = os.path.expanduser(parameters['DIRECTORY'])
    RAD = int(parameters['RAD'])
    OCN = ('_OCN' if (parameters['MASCON_OCEAN'] in ['Y', 'y']) else '')
    mascon_nums = np.array(parameters['MSCN_NUMS'].split(','), dtype=int)
    mascon_name = parameters['MSCN_NAME']
    out_lbl = '{0}_{1}'.format(mascon_name, parameters['MSCN_NUMS'].replace(',', '+'))
    kerns = {}
    for i in mascon_nums:
        kern_file = os.path.join(ddir, 'MASCON_{0:d}_YLMS_{1:.2f}DEG_SKERNEL{2}_L{3:02d}_r{4:d}km.nc'.format(i, DDEG_RASTER, OCN, LMAX, RAD))
        kerns[i] = ncdf_read(kern_file, DATE=False)
    kern_sum = kerns[mascon_nums[0]]['data']
    for i in mascon_nums[1:]:
        kern_sum += kerns[i]['data']
    glat = kerns[mascon_nums[0]]['lat']
    glon = kerns[mascon_nums[0]]['lon']
    outfile = os.path.join(ddir, 'MASCON_{0}_YLMS_{1:.2f}DEG_SKERNEL_OCN_L{2:02d}_r{3:d}km.nc'.format(out_lbl, DDEG_RASTER, LMAX, RAD))
    ncdf_write(kern_sum, glon, glat, 0, FILENAME=outfile, DATE=False, UNITS='unitless', LONGNAME='Sensitivity_Kernel')
    world = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))
    (fig, ax) = plt.subplots(1, figsize=(10, 6), dpi=100)
    klim = (np.max(np.abs(kern_sum)) * 0.95)
    c = ax.contourf(glon, glat, kern_sum, cmap='bwr', levels=np.linspace((- klim), klim, 16))
    drx = make_axes_locatable(ax)
    cax = drx.append_axes('right', size='5%', pad=0.1)
    cbar = fig.colorbar(c, cax=cax)
    cbar.set_label('Sensitivity Kernel (min:{0:.1f}, max:{1:.1f})'.format(np.min(kern_sum), np.max(kern_sum)))
    world.plot(ax=ax, alpha=0.3, fc='none', ec='k', linewidth=1.2, rasterized=True)
    plt.tight_layout()
    plt.savefig(outfile.replace('.nc', '.png'), format='PNG')
    plt.close(fig=fig)
def combine_kernels(parameters):
    DDEG_RASTER = float(parameters['DDEG_RASTER'])
    LMAX = int(parameters['LMAX'])
    ddir = os.path.expanduser(parameters['DIRECTORY'])
    RAD = int(parameters['RAD'])
    OCN = ('_OCN' if (parameters['MASCON_OCEAN'] in ['Y', 'y']) else )
    mascon_nums = np.array(parameters['MSCN_NUMS'].split(','), dtype=int)
    mascon_name = parameters['MSCN_NAME']
    out_lbl = '{0}_{1}'.format(mascon_name, parameters['MSCN_NUMS'].replace(',', '+'))
    kerns = {}
    for i in mascon_nums:
        kern_file = os.path.join(ddir, 'MASCON_{0:d}_YLMS_{1:.2f}DEG_SKERNEL{2}_L{3:02d}_r{4:d}km.nc'.format(i, DDEG_RASTER, OCN, LMAX, RAD))
        kerns[i] = ncdf_read(kern_file, DATE=False)
    kern_sum = kerns[mascon_nums[0]]['data']
    for i in mascon_nums[1:]:
        kern_sum += kerns[i]['data']
    glat = kerns[mascon_nums[0]]['lat']
    glon = kerns[mascon_nums[0]]['lon']
    outfile = os.path.join(ddir, 'MASCON_{0}_YLMS_{1:.2f}DEG_SKERNEL_OCN_L{2:02d}_r{3:d}km.nc'.format(out_lbl, DDEG_RASTER, LMAX, RAD))
    ncdf_write(kern_sum, glon, glat, 0, FILENAME=outfile, DATE=False, UNITS='unitless', LONGNAME='Sensitivity_Kernel')
    world = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))
    (fig, ax) = plt.subplots(1, figsize=(10, 6), dpi=100)
    klim = (np.max(np.abs(kern_sum)) * 0.95)
    c = ax.contourf(glon, glat, kern_sum, cmap='bwr', levels=np.linspace((- klim), klim, 16))
    drx = make_axes_locatable(ax)
    cax = drx.append_axes('right', size='5%', pad=0.1)
    cbar = fig.colorbar(c, cax=cax)
    cbar.set_label('Sensitivity Kernel (min:{0:.1f}, max:{1:.1f})'.format(np.min(kern_sum), np.max(kern_sum)))
    world.plot(ax=ax, alpha=0.3, fc='none', ec='k', linewidth=1.2, rasterized=True)
    plt.tight_layout()
    plt.savefig(outfile.replace('.nc', '.png'), format='PNG')
    plt.close(fig=fig)