def main(year, month, alg=0, poleStr='A', outputGrid=0): m = Basemap(projection='npstere', boundinglat=65, lon_0=0, resolution='l') #datapath='/Users/aapetty/GitRepos/GitHub/SeaIcePrediction/Data/' #dataoutpath='/Users/aapetty/GitRepos/GitHub/SeaIcePrediction/DataOutput/IceConcA/' #figpath='/Users/aapetty/GitRepos/GitHub/SeaIcePrediction/Figures/Arctic/IceConc/' datapath = '../../Data' dataoutpath = '../../DataOutput/IceConcA/' figpath = '../../Figures/Arctic/IceConc' dx_res = 100000. nx = int((m.xmax - m.xmin) / dx_res) + 1 ny = int((m.ymax - m.ymin) / dx_res) + 1 grid_str = str(int(dx_res / 1000)) + 'km' lonsG, latsG, xptsG, yptsG = m.makegrid(nx, ny, returnxy=True) if (outputGrid == 1): xptsG.dump(dataoutpath + 'xpts' + grid_str + poleStr) yptsG.dump(dataoutpath + 'ypts' + grid_str + poleStr) lats, lons = ff.get_psnlatslons(datapath) xpts, ypts = m(lons, lats) f = Dataset(datapath + '/OTHER/NIC_valid_ice_mask.N25km.01.1972-2007.nc', 'r') ice_flag = f.variables['valid_ice_flag'][:] region_mask = ff.get_region_mask_sect(datapath, m, xypts_return=0) if (year > 2015): ice_conc = ff.get_month_concSN_NRT(datapath, year, month, alg=alg, pole=poleStr, lowerConc=1, maxConc=1, mask=1, monthMean=1) #ice_conc=ma.masked_where(ice_conc<=0.15, ice_conc) else: ice_conc = ff.get_month_concSN(datapath, year, month, alg=alg, pole=poleStr, lowerConc=1, maxConc=1, mask=1) #ice_conc = ice_conc.filled(0) #ice_conc = ma.masked_where(ice_conc>1., ice_conc) #ice_conc = ma.where(ice_conc>1.,0, ice_conc) #ice_conc = ma.where(ice_conc<0.15,0, ice_conc) ice_conc = ma.where((ice_flag >= 1.5), 0, ice_conc) # get mean conc around the pole hole (time varying) pmask = ff.get_pmask(year, month) concHole = ma.mean(ice_conc[(lats > pmask - 0.5) & (lats < pmask)]) ice_conc = where((lats >= pmask - 0.5), concHole, ice_conc) #ice_conc[where(region_mask>18)]=0 ice_concG = griddata((xpts.flatten(), ypts.flatten()), ice_conc.flatten(), (xptsG, yptsG), method='linear') ice_conc_ma = ma.masked_where(np.isnan(ice_concG), ice_concG) plot_conc(figpath, m, xptsG, yptsG, ice_conc_ma, year, month, grid_str, poleStr='A') ice_conc_ma.dump(dataoutpath + 'ice_conc' + grid_str + str(month) + str(year) + poleStr)
dx_res = 100000. # 100 km nx = int((m.xmax-m.xmin)/dx_res)+1; ny = int((m.ymax-m.ymin)/dx_res)+1 grid_str=str(int(dx_res/1000))+'km' lonsG, latsG, xptsG, yptsG = m.makegrid(nx, ny, returnxy=True) # Get lon/lats pf the ice concentration data on polar sterographic grid lats, lons = ff.get_psnlatslons(datapath) xpts, ypts =m(lons, lats) f = Dataset(datapath+'/OTHER/NIC_valid_ice_mask.N25km.01.1972-2007.nc', 'r') ice_flag = f.variables['valid_ice_flag'][:] if (year>2015): ice_conc = ff.get_month_concSN_NRT(datapath, year, month, alg=alg, pole=poleStr, monthMean=1) # Mask values below 0.15 ice_conc=ma.masked_where(ice_conc<=0.15, ice_conc) else: ice_conc = ff.get_month_concSN(datapath, year, month, alg=alg, pole=poleStr) # fill ice concentration data with zeroes ice_conc = ice_conc.filled(0) ice_conc = where((ice_flag >=1.5), 0, ice_conc) # Note the pole hole due to the incomplete satellite orbit if (year<1987): pmask=84. elif((year==1987)&(month<=5)): pmask=84.
end_year=2017 month = 9 # 9 = Sept alg=0 #0=NASA TEAM, 1=BOOTSTRAP ice_ext_mean=[] ice_area_mean=[] regions=[12, 13] print ('Month:', month) for year in range(start_year, end_year+1): print (year) if (year>2016): ice_conc = ff.get_month_concSN_NRT(dataPath, year, month-1, alg=alg, pole='A', lowerConc=1, maxConc=1, mask=1, monthMean=1) #ice_conc=ma.masked_where(ice_conc<=0.15, ice_conc) else: ice_conc = ff.get_month_concSN(dataPath, year, month-1, alg=alg, pole='A', lowerConc=1, maxConc=1, mask=1) ice_conc = ice_conc.filled(0) #if (year>2015): # Subtract 1 to get month index starting from zero. # ice_conc = ff.get_month_concSN_NRT(dataPath, year, month-1, alg=alg, pole='A') #else: # ice_conc = ff.get_month_concSN(dataPath, year, month-1, alg=alg, pole='A') #ice_conc = ice_conc.filled(0)
def get_conc_grid(month, year, resolution): """ Purpose: Retrieve the concentration grids using given month, year, and resolution """ poleStr='A'# 'A: Arctic, AA: Antarctic alg=0 #0=Nasa team # File paths datapath = '../../../Data' # Get map projection and create regularly spaced grid from this projection m = Basemap(projection='npstere',boundinglat=65,lon_0=0, resolution='l') dx_res = resolution * 1000 nx = int((m.xmax-m.xmin)/dx_res)+1; ny = int((m.ymax-m.ymin)/dx_res)+1 lonsG, latsG, xptsG, yptsG = m.makegrid(nx, ny, returnxy=True) # Get lon/lats pf the ice concentration data on polar sterographic grid lats, lons = ff.get_psnlatslons(datapath) xpts, ypts =m(lons, lats) f = Dataset(datapath+'/OTHER/NIC_valid_ice_mask.N25km.01.1972-2007.nc', 'r') ice_flag = f.variables['valid_ice_flag'][:] if (year>2015): ice_conc = ff.get_month_concSN_NRT(datapath, year, month, alg=alg, pole=poleStr, monthMean=1) # Mask values below 0.15 ice_conc=ma.masked_where(ice_conc<=0.15, ice_conc) #I don't get this... else: ice_conc = ff.get_month_concSN(datapath, year, month, alg=alg, pole=poleStr) # fill ice concentration data with zeroes ice_conc = ice_conc.filled(0) ice_conc = where((ice_flag >=1.5), 0, ice_conc) # Note the pole hole due to the incomplete satellite orbit if (year<1987): pmask=84. elif((year==1987)&(month<=5)): pmask=84. elif ((year==1987)&(month>5)): pmask=86.5 elif ((year>1987)&(year<2008)): pmask=86.5 else: pmask=88.5 # Grid data ice_concG = griddata((xpts.flatten(), ypts.flatten()),ice_conc.flatten(), (xptsG, yptsG), method='linear') ice_conc_ma=ma.masked_where(np.isnan(ice_concG), ice_concG) #ice_conc_ma=ma.masked_where((latsG>pmask), ice_conc_ma) test = np.where(latsG>pmask) gridData = ice_conc_ma.data gridData[ice_conc_ma.mask == True] = 0 #WARNING: Super ghetto solution to not just set the hole to 1 arr1 = np.arange(np.min(test[0]), np.max(test[0])) arr2 = np.ones((1, np.size(arr1)), dtype=np.int ) * (np.min(test[0])-1) tup = (arr1, arr2) gridMean = sum(gridData[tup])/np.size(arr1) gridData[test] = gridMean #fix return gridData