""" reduce resolution of bS by averaging 100-m layer
        centered at p3 altitude """
    bot = 25    
    top = 26
    for z in p3z[:16]:    
        center_idx = np.where(bSz==z*1000.)[0]
        if not center_idx:
            bSulist.append(np.nan)
            bSvlist.append(np.nan)
        else:
            c = center_idx[0]
            bSulist.append(bSu[c-bot:c+top].mean())    
            bSvlist.append(bSv[c-bot:c+top].mean())    

const = True
res_u = linear_reg(bSulist, p3ulist, const=const)
res_v = linear_reg(bSvlist, p3vlist, const=const)

out_u = res_u.params[0],res_u.params[1], res_u.rsquared, res_u.nobs
out_v = res_v.params[0],res_v.params[1], res_v.rsquared, res_v.nobs
inter_u, slope_u, rsquared_u, nobs_u = out_u
inter_v, slope_v, rsquared_v, nobs_v = out_v

stat = 'Slope:{:2.2f}\nIntercep:{:2.2f}\nR-sqr:{:2.2f}\nN:{:2.0f}'
stat_u = stat.format(slope_u, inter_u, rsquared_u, nobs_u)
stat_v = stat.format(slope_v, inter_v, rsquared_v, nobs_v)

x0u,y0u = np.arange(-15,16), np.arange(-15,16)
x0v,y0v = np.arange(0,41), np.arange(0,41)

    sy_u = np.append(sy_u, out['sy']['u'])
    sy_v = np.append(sy_v, out['sy']['v'])

good_u=[np.where(~np.isnan(sy_u))]
good_v=[np.where(~np.isnan(sy_v))]

Xu,Yu = np.squeeze(fl_u[good_u]),np.squeeze(sy_u[good_u])
Xv,Yv = np.squeeze(fl_v[good_v]),np.squeeze(sy_v[good_v])
x0u,y0u = np.arange(-20,21), np.arange(-20,21)
x0v,y0v = np.arange(0,31), np.arange(0,31)

add_const=True

if add_const is True:

    res_u = linear_reg(Xu,Yu,const=True)
    res_v = linear_reg(Xv,Yv,const=True)
    
    inter_u, slope_u, rsquared_u, nobs_u = [res_u.params[0],
                                            res_u.params[1],
                                            res_u.rsquared,
                                            res_u.nobs]
                                            
                                            
    inter_v, slope_v, rsquared_v, nobs_v = [res_v.params[0],
                                            res_v.params[1],
                                            res_v.rsquared,
                                            res_v.nobs]
    
    stats = 'Slope: {:2.2f}\nIntercep: {:2.2f}\nR-sqr: {:2.2f}\
                \nN: {:2.0f}'