def loadRetPerAllYears(ncDir='/ClimateRun4/multi-hazard/eva', rlVarName='rl', retPer=100,
        flpattern='projection_dis_{scen}_{mdl}_wuConst_statistics.nc', nmodels=-1, excludedModels=[]):
  
  wlyR8 = getWarmingLevels('rcp85', 2.0)
  models = wlyR8.keys()
  if nmodels > -1:
    models = models[:nmodels]
  for mdl in excludedModels:
    if mdl in models:
      models.remove(mdl)

  dsuparea = netCDF4.Dataset('upArea.nc')
  upArea = dsuparea.variables['upArea'][:].transpose()
  dsuparea.close()

  tamask, _, _ = getAfricaAndTurkeyMask()
  tamask = tamask.transpose()
  
  vlsR8 = []
  vlsR4 = []  
  for mdl, imdl in zip(models, range(len(models))):
    print('model ' + mdl)

    flr8 = flpattern.format(scen='rcp85', mdl=mdl)
    flr8pth = os.path.join(ncDir, flr8)
    ds = netCDF4.Dataset(flr8pth)
    yr = ds.variables['year'][:]
    upAreaMtx = np.tile(upArea, [yr.shape[0], 1, 1])
    tamaskMtx = np.tile(tamask, [yr.shape[0], 1, 1])
    retper_ = ds.variables['return_period'][:]
    rpIndx = np.where(retper_==retPer)[0][0]
    vl = ds.variables[rlVarName][rpIndx, :, :, :]
    vl[upAreaMtx < 1e9] = np.nan
    vl[~tamaskMtx] = np.nan
    vlsR8.append(vl)
    ds.close()

    flr4 = flpattern.format(scen='rcp45', mdl=mdl)
    flr4pth = os.path.join(ncDir, flr4)
    ds = netCDF4.Dataset(flr4pth)
    vl = ds.variables[rlVarName][rpIndx, :, :, :]
    vl[upAreaMtx < 1e9] = np.nan
    vl[~tamaskMtx] = np.nan
    vlsR4.append(vl)
    ds.close()

  vlsR8 = np.array(vlsR8)
  vlsR4 = np.array(vlsR4)

  return yr, vlsR8, vlsR4, models
Beispiel #2
0
def loadWlVsScenChange(
        ncDir='/ClimateRun4/multi-hazard/eva',
        bslnYear=1995,
        warmingLev=2,
        retPer=100,
        threshold=0,
        rlVarName='rl',
        flpattern='projection_dis_{scen}_{mdl}_wuConst_statistics.nc',
        nmodels=-1,
        shapeParamNcVarName='',
        minNumModels=8):
    # computes the mean relative change

    wlyR8 = getWarmingLevels('rcp85', warmingLev)
    wlyR4 = getWarmingLevels('rcp45', warmingLev)

    dsuparea = netCDF4.Dataset('upArea.nc')
    upArea = dsuparea.variables['upArea'][:].transpose()
    dsuparea.close()

    maskInvalidShapeParamPts = shapeParamNcVarName != ''

    models = wlyR8.keys()
    if nmodels > -1:
        models = models[:nmodels]
    # menta

#models = [models[0], models[1]]
    tamask, _, _ = getAfricaAndTurkeyMask()
    tamask = tamask.transpose()

    if minNumModels > nmodels:
        minNumModels = nmodels

    rl_r4 = []
    rl_r8 = []
    mdlCountR4 = np.zeros(upArea.shape)
    mdlCountR8 = np.zeros(upArea.shape)
    for mdl, imdl in zip(models, range(len(models))):
        print('model ' + mdl)
        flr8 = flpattern.format(scen='rcp85', mdl=mdl)
        flr8pth = os.path.join(ncDir, flr8)
        flr4 = flpattern.format(scen='rcp45', mdl=mdl)
        flr4pth = os.path.join(ncDir, flr4)

        r8year = wlyR8[mdl]
        r8yearInf = int(np.floor(r8year / float(5)) * 5)
        print('  rcp85 w.l. year: ' + str(r8year))
        r4year = wlyR4[mdl]
        r4yearInf = int(np.floor(r4year / float(5)) * 5)
        print('  rcp45 w.l. year: ' + str(r4year))

        print('  loading file ' + flr8pth)
        ds = netCDF4.Dataset(flr8pth)
        retper_ = ds.variables['return_period'][:]
        rpIndx = np.where(retper_ == retPer)[0][0]
        year_ = ds.variables['year'][:]
        yIndxBsln = np.where(year_ == bslnYear)[0][0]
        rlBslnR8 = ds.variables[rlVarName][rpIndx, yIndxBsln, :, :]
        yIndx = np.where(year_ == r8yearInf)[0][0]
        rlR8_ = ds.variables[rlVarName][rpIndx, yIndx:yIndx + 2, :, :]
        rlR8 = interp1d(year_[yIndx:yIndx + 2], rlR8_, axis=0)(r8year)
        if maskInvalidShapeParamPts:
            shapeParam = ds.variables[shapeParamNcVarName][:]
            cnd = shapeParam <= -.4
            rlBslnR8[cnd] = np.nan
            rlR8[cnd] = np.nan
        ds.close()
        r8RelChng = (rlR8 - rlBslnR8) / rlBslnR8
        if threshold > 0:
            cnd = rlBslnR8 < threshold
            r8RelChng[cnd] = np.nan
        #r8RelChng[r8RelChng < -.15] = np.nan

        print('  loading file ' + flr4pth)
        ds = netCDF4.Dataset(flr4pth)
        rlBslnR4 = ds.variables[rlVarName][rpIndx, yIndxBsln, :, :]
        #rlBslnR4 = rlBslnR8
        yIndx = np.where(year_ == r4yearInf)[0][0]
        rlR4_ = ds.variables[rlVarName][rpIndx, yIndx:yIndx + 2, :, :]
        rlR4 = interp1d(year_[yIndx:yIndx + 2], rlR4_, axis=0)(r4year)
        if maskInvalidShapeParamPts:
            shapeParam = ds.variables[shapeParamNcVarName][:]
            cnd = shapeParam <= -.4
            rlBslnR4[cnd] = np.nan
            rlR4[cnd] = np.nan
        ds.close()
        r4RelChng = (rlR4 - rlBslnR4) / rlBslnR4
        if threshold > 0:
            cnd = rlBslnR4 < threshold
            r4RelChng[cnd] = np.nan
        #r4RelChng[r4RelChng < -.15] = np.nan

        r8RelChng[upArea < 1e9] = np.nan
        r4RelChng[upArea < 1e9] = np.nan

        r8RelChng[~tamask] = np.nan
        r4RelChng[~tamask] = np.nan

        rl_r8.append(r8RelChng)
        rl_r4.append(r4RelChng)

        mdlCountR8 += ~np.isnan(r8RelChng)
        mdlCountR4 += ~np.isnan(r4RelChng)

    rl_r8 = np.array(rl_r8)
    rl_r4 = np.array(rl_r4)

    mdlCountMskR8 = mdlCountR8 >= minNumModels
    mdlCountMskR4 = mdlCountR4 >= minNumModels
    mskR8 = np.tile(mdlCountMskR8, [rl_r8.shape[0], 1, 1])
    mskR4 = np.tile(mdlCountMskR4, [rl_r8.shape[0], 1, 1])

    rl_r8[mskR8 != 1] = np.nan
    rl_r4[mskR4 != 1] = np.nan

    relChngDiff = np.nanmean(rl_r8 - rl_r4, 0)
    relChngDiff[~tamask] = np.nan

    return relChngDiff, np.nanmean(rl_r8, 0), np.nanmean(rl_r4,
                                                         0), rl_r8, rl_r4
Beispiel #3
0
def loadMeanPrecipitationChangesAtWl(
        ncRootDir='/DATA/ClimateData/cordexEurope/yearlymeans/',
        bslnYear=1995,
        warmingLev=2,
        threshold=0,
        flname='pr.nc',
        nmodels=-1,
        timeWindowHalfSize=15):
    # computes the mean relative change

    wlyR8 = getWarmingLevels('rcp85', warmingLev)
    wlyR4 = getWarmingLevels('rcp45', warmingLev)

    models = wlyR8.keys()
    if nmodels > -1:
        models = models[:nmodels]

    tamask, _, _ = getAfricaAndTurkeyMask()
    tamask = tamask

    rlVarName1 = 'pr'
    rlVarname2 = 'prAdjust'

    rl_r4 = []
    rl_r8 = []
    for mdl, imdl in zip(models, range(len(models))):
        print('model ' + mdl)
        flhistpth = os.path.join(ncRootDir, mdl, 'historical', flname)
        flr8pth = os.path.join(ncRootDir, mdl, 'rcp85', flname)
        flr4pth = os.path.join(ncRootDir, mdl, 'rcp45', flname)

        r8year = wlyR8[mdl]
        r4year = wlyR4[mdl]

        print('  loading file ' + flhistpth)
        ds = netCDF4.Dataset(flhistpth)
        rlVarName = 'pr' if 'pr' in ds.variables else 'prAdjust'
        tmnc = ds.variables['time']
        tm = netCDF4.num2date(tmnc[:], tmnc.units, tmnc.calendar)
        yearHist = np.array([t.year for t in tm])
        yIndxBsln = np.where(yearHist == bslnYear)[0][0]
        minIndx = np.max([yIndxBsln - timeWindowHalfSize, 0])
        maxIndx = np.min([yIndxBsln + timeWindowHalfSize, len(yearHist)])
        rlBsln = np.nanmean(ds.variables[rlVarName][minIndx:maxIndx, :, :], 0)
        ds.close()

        print('  loading file ' + flr8pth)
        ds = netCDF4.Dataset(flr8pth)
        rlVarName = 'pr' if 'pr' in ds.variables else 'prAdjust'
        tmnc = ds.variables['time']
        tm = netCDF4.num2date(tmnc[:], tmnc.units, tmnc.calendar)
        yearR = np.array([t.year for t in tm])
        yIndx = np.where(yearR == r8year)[0][0]
        minIndx = np.max([yIndx - timeWindowHalfSize, 0])
        maxIndx = np.min([yIndx + timeWindowHalfSize, len(yearR)])
        rlR8 = np.nanmean(ds.variables[rlVarName][minIndx:maxIndx, :, :], 0)
        r8RelChng = (rlR8 - rlBsln) / rlBsln
        if threshold > 0:
            cnd = rlBslnR8 < threshold
            r8RelChng[cnd] = np.nan
        #r8RelChng[r8RelChng < -.15] = np.nan
        ds.close()

        print('  loading file ' + flr4pth)
        ds = netCDF4.Dataset(flr4pth)
        rlVarName = 'pr' if 'pr' in ds.variables else 'prAdjust'
        tmnc = ds.variables['time']
        tm = netCDF4.num2date(tmnc[:], tmnc.units, tmnc.calendar)
        yearR = np.array([t.year for t in tm])
        yIndx = np.where(yearR == r4year)[0][0]
        minIndx = np.max([yIndx - timeWindowHalfSize, 0])
        maxIndx = np.min([yIndx + timeWindowHalfSize, len(yearR)])
        rlR4 = np.nanmean(ds.variables[rlVarName][minIndx:maxIndx, :, :], 0)
        r4RelChng = (rlR4 - rlBsln) / rlBsln
        if threshold > 0:
            cnd = rlBslnR4 < threshold
            r4RelChng[cnd] = np.nan
        #r4RelChng[r4RelChng < -.15] = np.nan
        ds.close()

        #r8RelChng[upArea < 1e9] = np.nan
        #r4RelChng[upArea < 1e9] = np.nan

        r8RelChng[~tamask] = np.nan
        r4RelChng[~tamask] = np.nan

        rl_r8.append(r8RelChng)
        rl_r4.append(r4RelChng)

    rl_r8 = np.array(rl_r8)
    rl_r4 = np.array(rl_r4)

    relChngDiff = np.nanmean(rl_r8 - rl_r4, 0)
    relChngDiff[~tamask] = np.nan

    return relChngDiff, np.nanmean(rl_r8, 0), np.nanmean(rl_r4,
                                                         0), rl_r8, rl_r4
Beispiel #4
0
def loadWlVsScenChangeYMax(
        ncDir='/ClimateRun4/multi-hazard/eva',
        bslnYear=1995,
        warmingLev=2,
        retPer=100,
        threshold=0,
        rlVarName='year_max',
        windowHalfSize=10,
        flpattern='projection_dis_{scen}_{mdl}_wuConst_statistics.nc'):
    # computes the mean relative change

    wlyR8 = getWarmingLevels('rcp85', warmingLev)
    wlyR4 = getWarmingLevels('rcp45', warmingLev)

    dsuparea = netCDF4.Dataset('upArea.nc')
    upArea = dsuparea.variables['upArea'][:].transpose()
    dsuparea.close()

    models = wlyR8.keys()
    # menta
    #models = [models[0], models[1]]
    tamask, _, _ = getAfricaAndTurkeyMask()
    tamask = tamask.transpose()

    rl_r4 = []
    rl_r8 = []
    for mdl, imdl in zip(models, range(len(models))):
        print('model ' + mdl)
        flr8 = flpattern.format(scen='rcp85', mdl=mdl)
        flr8pth = os.path.join(ncDir, flr8)
        flr4 = flpattern.format(scen='rcp45', mdl=mdl)
        flr4pth = os.path.join(ncDir, flr4)

        r8year = wlyR8[mdl]
        print('  rcp85 w.l. year: ' + str(r8year))
        r4year = wlyR4[mdl]
        print('  rcp45 w.l. year: ' + str(r4year))

        hsz = windowHalfSize

        print('  loading file ' + flr8pth)
        ds = netCDF4.Dataset(flr8pth)
        year_ = ds.variables['year_all'][:]
        yIndxBsln = np.where(year_ == bslnYear)[0][0]
        rlBslnR8 = np.nanmean(
            ds.variables[rlVarName][yIndxBsln - hsz:yIndxBsln + hsz, :, :], 0)
        yIndx = np.where(year_ == r8year)[0][0]
        rlR8 = np.nanmean(
            ds.variables[rlVarName][yIndx - hsz:yIndx + hsz, :, :], 0)
        ds.close()
        r8RelChng = (rlR8 - rlBslnR8) / rlBslnR8
        if threshold > 0:
            cnd = rlBslnR8 < threshold
            r8RelChng[cnd] = np.nan
        #r8RelChng[r8RelChng < -.15] = np.nan

        print('  loading file ' + flr4pth)
        ds = netCDF4.Dataset(flr4pth)
        #rlBslnR4 = ds.variables[rlVarName][rpIndx, yIndxBsln, :, :]
        rlBslnR4 = rlBslnR8
        yIndx = np.where(year_ == r4year)[0][0]
        rlR4 = np.nanmean(
            ds.variables[rlVarName][yIndx - hsz:yIndx + hsz, :, :], 0)
        ds.close()
        r4RelChng = (rlR4 - rlBslnR4) / rlBslnR4
        if threshold > 0:
            cnd = rlBslnR4 < threshold
            r4RelChng[cnd] = np.nan
        #r4RelChng[r4RelChng < -.15] = np.nan

        r8RelChng[upArea < 1e9] = np.nan
        r4RelChng[upArea < 1e9] = np.nan

        r8RelChng[~tamask] = np.nan
        r4RelChng[~tamask] = np.nan

        rl_r8.append(r8RelChng)
        rl_r4.append(r4RelChng)

    rl_r8 = np.array(rl_r8)
    rl_r4 = np.array(rl_r4)

    relChngDiff = np.nanmean(rl_r8 - rl_r4, 0)
    relChngDiff[~tamask] = np.nan

    return relChngDiff, np.nanmean(rl_r8, 0), np.nanmean(rl_r4,
                                                         0), rl_r8, rl_r4
Beispiel #5
0
def getGrossEnsembleAtYear(ryear,
                           ncDir='/ClimateRun4/multi-hazard/eva',
                           bslnYear=1995,
                           retPer=100,
                           threshold=200):
    flpattern = 'projection_dis_{scen}_{mdl}_wuConst_statistics.nc'

    wlyR8 = getWarmingLevels('rcp85', 2.0)
    #wlyR4 = getWarmingLevels('rcp45', warmingLev)

    models = wlyR8.keys()
    tamask, _, _ = getAfricaAndTurkeyMask()
    tamask = tamask.transpose()

    rl_all = []
    for mdl, imdl in zip(models, range(len(models))):
        print('model ' + mdl)
        flr8 = flpattern.format(scen='rcp85', mdl=mdl)
        flr8pth = os.path.join(ncDir, flr8)
        flr4 = flpattern.format(scen='rcp45', mdl=mdl)
        flr4pth = os.path.join(ncDir, flr4)

        #r8year = wlyR8[mdl] + wlOffset
        #r8yearInf = int(np.floor(r8year/float(5))*5)
        #print('  rcp85 w.l. year: ' + str(r8year))
        #r4year = wlyR4[mdl] + wlOffset
        #r4yearInf = int(np.floor(r4year/float(5))*5)
        #print('  rcp45 w.l. year: ' + str(r4year))

        ryearInf = int(np.floor(ryear / float(5)) * 5)

        print('  loading file ' + flr8pth)
        ds = netCDF4.Dataset(flr8pth)
        retper_ = ds.variables['return_period'][:]
        rpIndx = np.where(retper_ == retPer)[0][0]
        year_ = ds.variables['year'][:]
        yIndxBsln = np.where(year_ == bslnYear)[0][0]
        rlBslnR8 = ds.variables['rl'][rpIndx, yIndxBsln, :, :]
        #yIndx = np.where(year_==r8yearInf)[0][0]
        yIndx = np.where(year_ == ryearInf)[0][0]
        rlR8_ = ds.variables['rl'][rpIndx, yIndx:yIndx + 2, :, :]
        ds.close()
        #rlR8 = interp1d(year_[yIndx:yIndx+2], rlR8_, axis=0)(r8year)
        rlR8 = interp1d(year_[yIndx:yIndx + 2], rlR8_, axis=0)(ryear)
        r8RelChng = (rlR8 - rlBslnR8) / rlBslnR8
        if threshold > 0:
            cnd = rlBslnR8 < threshold
            r8RelChng[cnd] = np.nan

        print('  loading file ' + flr4pth)
        ds = netCDF4.Dataset(flr4pth)
        rlBslnR4 = ds.variables['rl'][rpIndx, yIndxBsln, :, :]
        #yIndx = np.where(year_==r4yearInf)[0][0]
        yIndx = np.where(year_ == ryearInf)[0][0]
        rlR4_ = ds.variables['rl'][rpIndx, yIndx:yIndx + 2, :, :]
        ds.close()
        #rlR4 = interp1d(year_[yIndx:yIndx+2], rlR4_, axis=0)(r4year)
        rlR4 = interp1d(year_[yIndx:yIndx + 2], rlR4_, axis=0)(ryear)
        r4RelChng = (rlR4 - rlBslnR4) / rlBslnR4
        if threshold > 0:
            cnd = rlBslnR4 < threshold
            r4RelChng[cnd] = np.nan

        r8RelChng[~tamask] = np.nan
        r4RelChng[~tamask] = np.nan

        rl_all.append(r8RelChng)
        rl_all.append(r4RelChng)

    rl_all = np.array(rl_all)

    ensembleRelChngAll = np.nanmean(rl_all, 0)

    return ensembleRelChngAll
Beispiel #6
0
def loadWlVsScenChange2(ncDir='/ClimateRun4/multi-hazard/eva',
                        bslnYear=1995,
                        warmingLev=2,
                        retPer=100,
                        threshold=0,
                        rlVarName='rl'):
    # computes the relative change of the ensemble
    flpattern = 'projection_dis_{scen}_{mdl}_wuConst_statistics.nc'

    wlyR8 = getWarmingLevels('rcp85', warmingLev)
    wlyR4 = getWarmingLevels('rcp45', warmingLev)

    dsuparea = netCDF4.Dataset('upArea.nc')
    upArea = dsuparea.variables['upArea'][:].transpose()
    dsuparea.close()

    models = wlyR8.keys()
    # menta
    #models = [models[0], models[1]]
    tamask, _, _ = getAfricaAndTurkeyMask()
    tamask = tamask.transpose()

    rl_bsln = []
    rl_r4 = []
    rl_r8 = []
    for mdl, imdl in zip(models, range(len(models))):
        print('model ' + mdl)
        flr8 = flpattern.format(scen='rcp85', mdl=mdl)
        flr8pth = os.path.join(ncDir, flr8)
        flr4 = flpattern.format(scen='rcp45', mdl=mdl)
        flr4pth = os.path.join(ncDir, flr4)

        r8year = wlyR8[mdl]
        r8yearInf = int(np.floor(r8year / float(5)) * 5)
        print('  rcp85 w.l. year: ' + str(r8year))
        r4year = wlyR4[mdl]
        r4yearInf = int(np.floor(r4year / float(5)) * 5)
        print('  rcp45 w.l. year: ' + str(r4year))

        print('  loading file ' + flr8pth)
        ds = netCDF4.Dataset(flr8pth)
        retper_ = ds.variables['return_period'][:]
        rpIndx = np.where(retper_ == retPer)[0][0]
        year_ = ds.variables['year'][:]
        yIndxBsln = np.where(year_ == bslnYear)[0][0]
        rlBslnR8 = ds.variables[rlVarName][rpIndx, yIndxBsln, :, :]
        yIndx = np.where(year_ == r8yearInf)[0][0]
        rlR8_ = ds.variables[rlVarName][rpIndx, yIndx:yIndx + 2, :, :]
        ds.close()
        rlR8 = interp1d(year_[yIndx:yIndx + 2], rlR8_, axis=0)(r8year)

        print('  loading file ' + flr4pth)
        ds = netCDF4.Dataset(flr4pth)
        yIndx = np.where(year_ == r4yearInf)[0][0]
        rlR4_ = ds.variables[rlVarName][rpIndx, yIndx:yIndx + 2, :, :]
        ds.close()
        rlR4 = interp1d(year_[yIndx:yIndx + 2], rlR4_, axis=0)(r4year)

        rlR8[upArea < 1e9] = np.nan
        rlR4[upArea < 1e9] = np.nan

        rlR8[~tamask] = np.nan
        rlR4[~tamask] = np.nan

        rl_r8.append(rlR8)
        rl_r4.append(rlR4)
        rl_bsln.append(rlBslnR8)

    rl_r8 = np.array(rl_r8)
    rl_r4 = np.array(rl_r4)
    rl_bsln = np.array(rl_bsln)

    mnbsln = np.nanmean(rl_bsln, 0)
    mnbsln[mnbsln < threshold] = np.nan
    rc_r8 = (np.nanmean(rl_r8, 0) - mnbsln) / mnbsln
    rc_r4 = (np.nanmean(rl_r4, 0) - mnbsln) / mnbsln

    relChngDiff = rc_r8 - rc_r4
    relChngDiff[~tamask] = np.nan

    nmdl = rl_bsln.shape[0]
    std_r8 = np.std(rl_r8 - rl_bsln, 0) / np.sqrt(
        np.sum(rl_bsln**2., 0) / nmdl)
    std_r4 = np.std(rl_r4 - rl_bsln, 0) / np.sqrt(
        np.sum(rl_bsln**2., 0) / nmdl)
    std_diff = np.std(rl_r8 - rl_r4, 0) / np.sqrt(
        np.sum(rl_bsln**2., 0) / nmdl)

    _, pval_r8 = stats.ttest_ind(rl_r8, rl_bsln, 0)
    _, pval_r4 = stats.ttest_ind(rl_r4, rl_bsln, 0)
    _, pval_diff = stats.ttest_ind(rl_r8, rl_r4, 0)

    return relChngDiff, rc_r8, rc_r4, std_r8, std_r4, std_diff, pval_r8, pval_r4, pval_diff
def loadMeanChangesAtWl_nYearsAroundWLYear(ncDir='/ClimateRun4/multi-hazard/eva', bslnYear=1995, warmingLev=2, 
    threshold=0, rlVarName='year_mean',
    flpattern='projection_dis_{scen}_{mdl}_wuConst_statistics.nc',
    nmodels=-1, timeWindowHalfSize=15, excludedModels=[]):
  # computes the mean relative change

  wlyR8 = getWarmingLevels('rcp85', warmingLev)
  wlyR4 = getWarmingLevels('rcp45', warmingLev)

  dsuparea = netCDF4.Dataset('upArea.nc')
  upArea = dsuparea.variables['upArea'][:].transpose()
  dsuparea.close()

  models = wlyR8.keys()
  if nmodels > -1:
    models = models[:nmodels]
  for mdl in excludedModels:
    if mdl in models:
      models.remove(mdl)
  tamask, _, _ = getAfricaAndTurkeyMask()
  tamask = tamask.transpose()

  rl_r4 = []
  rl_r8 = [] 
  for mdl, imdl in zip(models, range(len(models))):
    print('model ' + mdl)

    flr8 = flpattern.format(scen='rcp85', mdl=mdl)
    flr8pth = os.path.join(ncDir, flr8)
    flr4 = flpattern.format(scen='rcp45', mdl=mdl)
    flr4pth = os.path.join(ncDir, flr4)

    r8year = wlyR8[mdl]
    r4year = wlyR4[mdl]

    print('  loading file ' + flr8pth)
    ds = netCDF4.Dataset(flr8pth)
    year_ = ds.variables['year_all'][:]
    yIndxBsln = np.where(year_ == bslnYear)[0][0]
    minIndx = np.max([yIndxBsln-timeWindowHalfSize, 0])
    maxIndx = np.min([yIndxBsln+timeWindowHalfSize+1, len(year_)])
    rlBslnR8 = np.nanmean(ds.variables[rlVarName][minIndx:maxIndx, :, :], 0)
    yIndx = np.where(year_==r8year)[0][0]
    minIndx = np.max([yIndx-timeWindowHalfSize*2, 0])
    maxIndx = np.min([yIndx+timeWindowHalfSize*2, len(year_)])
    rlR8All = ds.variables[rlVarName][minIndx:maxIndx, :, :]
    convFnct = np.ones([timeWindowHalfSize*2])/(timeWindowHalfSize*2)
    rlR8RunningMean = convolve1d(rlR8All, convFnct, 0)
    minIndx, maxIndx = timeWindowHalfSize, timeWindowHalfSize*3+1
    rlR8RunningMean = rlR8RunningMean[minIndx:maxIndx, :, :]
    indx = np.arange(0,31,5)
    rlR8RunningMean = rlR8RunningMean[indx, :, :]
    rlBslnR8Mtx = np.tile(rlBslnR8, [rlR8RunningMean.shape[0], 1, 1])
    r8RelChng = (rlR8RunningMean-rlBslnR8Mtx)/rlBslnR8Mtx
    if threshold > 0:
      cnd = rlBslnR8 < threshold
      r8RelChng[cnd] = np.nan
     #r8RelChng[r8RelChng < -.15] = np.nan

    print('  loading file ' + flr4pth)
    ds = netCDF4.Dataset(flr4pth)
    rlBslnR4 = rlBslnR8
    yIndx = np.where(year_==r4year)[0][0]
    minIndx = np.max([yIndx-timeWindowHalfSize*2, 0])
    maxIndx = np.min([yIndx+timeWindowHalfSize*2, len(year_)])
    rlR4All = ds.variables[rlVarName][minIndx:maxIndx, :, :]
    convFnct = np.ones([timeWindowHalfSize*2])/(timeWindowHalfSize*2)
    rlR4RunningMean = convolve1d(rlR4All, convFnct, 0)
    minIndx, maxIndx = timeWindowHalfSize, timeWindowHalfSize*3+1
    rlR4RunningMean = rlR4RunningMean[minIndx:maxIndx, :, :]
    indx = np.arange(0,31,5)
    rlR4RunningMean = rlR4RunningMean[indx, :, :]
    rlBslnR4Mtx = np.tile(rlBslnR4, [rlR4RunningMean.shape[0], 1, 1])
    r4RelChng = (rlR4RunningMean-rlBslnR4Mtx)/rlBslnR4Mtx

    upAreaMtx = np.tile(upArea, [r8RelChng.shape[0], 1, 1])
    r8RelChng[upAreaMtx < 1e9] = np.nan
    r4RelChng[upAreaMtx < 1e9] = np.nan

    tamaskMtx = np.tile(tamask, [r8RelChng.shape[0], 1, 1])
    r8RelChng[~tamaskMtx] = np.nan
    r4RelChng[~tamaskMtx] = np.nan

    rl_r8.append(r8RelChng)
    rl_r4.append(r4RelChng)

  rl_r8 = np.array(rl_r8)
  rl_r4 = np.array(rl_r4)

  relChngDiff = np.nanmean(rl_r8-rl_r4, 0)

  return relChngDiff, np.nanmean(rl_r8, 0), np.nanmean(rl_r4, 0), rl_r8, rl_r4