def save_Anomaly_as_npz(fy, ly, var, product_n = 3): a = subroutine.read_meta_data('var') formal_name = subroutine.celldata(a, 'var', var, 'formal_name') dim = subroutine.celldata(a, 'var', var, 'dim') _,title_name,_=subroutine.product_n_to_name(product_n) tmpyear = 2000 for month in range(1,13): _,strmonth=subroutine.strym(2000,month) Clim=subroutine.load_npz('Ave_of_' + formal_name + '_m'+strmonth+'_' + str(fy) + '-' + str(ly) + '_'+title_name) print 'month = ', month start = time.time() for year in range(fy,ly+1): stryear,strmonth=subroutine.strym(year,month) j=year-fy if dim == '3D': data=subroutine.get_data(year,month,var,0,title_name) elif dim == '2D': data=subroutine.get_data(year,month,var,1,title_name) else: raise Exception('your dim is not valid!') Anomaly=data-Clim DIR = subroutine.get_DIR(year, month, formal_name, product_n) subroutine.check_and_make_DIR(DIR) subroutine.save_npz(Anomaly,DIR+'Anomaly_from_Mean_Annual_Cycle_Year'+str(fy)+'-'+str(ly),data_dir_flg='NO') print 'elapsed time:', time.time() - start
def load_Ave_or_Std_of_Data_of_npz(self, month, fy, ly, product_n, Ave_or_Std = 'Ave'): import D import subroutine title_name = D.Data[product_n].title_name year = 2000 stryear, strmonth = subroutine.strym(year, month) DIR = subroutine.NAS_dir() + 'DATA/' + title_name + '/npz/' + self.dir_name + '/' _, strmonth = subroutine.strym(year, month) AvSt_of_Data = subroutine.load_npz(DIR + Ave_or_Std + '_of_' + self.fname + '_Year' + \ str(fy) + '-' + str(ly) + \ '_Month' + strmonth + '_' + title_name, \ data_dir_flg = 'NO') return AvSt_of_Data
def load_Data_of_Climatology_of_npz(self, month, fy, ly, product_n): import D import subroutine title_name = D.Data[product_n].title_name year = 2000 stryear, strmonth = subroutine.strym(year, month) DIR = subroutine.NAS_dir() + 'DATA/' + title_name + '/npz/' + self.dir_name + '/' _, strmonth = subroutine.strym(year, month) Data_of_Clim = subroutine.load_npz(DIR + self.fname + '_of_Climatology_Year' + \ str(fy) + '-' + str(ly) + \ '_Month' + strmonth + '_' + title_name, \ data_dir_flg = 'NO') return Data_of_Clim
def save_Data_of_Climatology_as_npz(self, Data_of_Clim, fy, ly, product_n): """ Data_of_Climの作成は、以下のような感じで。 Data_of_Clim = np.zeros((ygrid.size, xgrid.size, 12)) for month in range(1, 13): # SGT of Ave t = CI.load_climatology_or_interannual_variation_as_npz(fy, ly, month, 't', 'Ave', product_n = product_n) s = CI.load_climatology_or_interannual_variation_as_npz(fy, ly, month, 's', 'Ave', product_n = product_n) Data_of_Clim[:, :, month - 1] = make_density_product_from_ts(t, s, product_n = product_n, data_type = 1) """ import D import subroutine title_name = D.Data[product_n].title_name year = 2000 DIR = subroutine.NAS_dir() + 'DATA/' + title_name + '/npz/' + self.dir_name + '/' subroutine.check_and_make_DIR(DIR) for month in range(1, 13): _, strmonth = subroutine.strym(year, month) fname = self.fname + '_of_Climatology_Year' + \ str(fy) + '-' + str(ly) + \ '_Month' + strmonth + '_' + title_name if self.dimension == 2: subroutine.save_npz(Data_of_Clim[:, :, month - 1], DIR + fname, data_dir_flg = 'NO') elif self.dimension == 3: subroutine.save_npz(Data_of_Clim[:, :, :, month - 1], DIR + fname, data_dir_flg = 'NO') else: raise ValueError('your dimension is not valid!')
def minus_MG_and_argopoint(year,month,var,cb_min,cb_max,area_num,depth): # area_num=0でインド洋全域 import subroutine import MOAA_GPV import WOA01 import AQC import numpy as np import matplotlib.pyplot as plt stryear,strmonth=subroutine.strym(year,month) strym=stryear+strmonth save_dir=subroutine.save_dir() my_color=0 # 青白赤 dataWOA=WOA01.nc_read(month,var,depth+1) # WOAはz=0があるので、1足してMGと一致 dataWOA=subroutine.data_trimming_IO(dataWOA,4) dataMG=MOAA_GPV.nc_read(year,month,var,depth) dataMG=subroutine.data_trimming_IO(dataMG,1) data=dataMG-dataWOA xgrid,ygrid=subroutine.IO_gridvalue() m=subroutine.IO_map(area_num,1,1) x, y = np.meshgrid(xgrid, ygrid) X, Y = m(x, y) title='' plt.title(title,fontsize=25) temp,salt,pres,lon,lat=AQC.get_data(year,month) interval_of_cf=subroutine.cl_res(cb_min,cb_max) data,cmap,cb_interval,plt=subroutine.color(data,my_color,interval_of_cf,plt) CF=m.contourf(X, Y, data,interval_of_cf, cmap=cmap, latlon=True,extend='both') cb=m.colorbar(CF, ticks=cb_interval) SC=plt.scatter(lon,lat,s=45,c='maroon') fnameF = save_dir+strym+var+'_MG-WOA.jpg' plt.savefig(fnameF) plt.clf()
def load_climatology_or_interannual_variation_as_npz(fy, ly, month, var, Ave_or_Std, product_n = 3): vid = Var.var_to_id(var) formal_name = Var.VAR[vid].Get_formal_name() title_name = D.Data[product_n].title_name _, strmonth = subroutine.strym(2000, month) data =subroutine.load_npz(Ave_or_Std + '_of_' + \ formal_name + '_m' + strmonth + '_' + str(fy) + '-' + str(ly) + \ '_' + title_name) return data
def save_climatology_or_interannual_variation_as_npz(data_allmonth, fy, ly, var, Ave_or_Std, product_n = 3): a=subroutine.read_meta_data('var') formal_name = subroutine.celldata(a, 'var', var, 'formal_name') _, title_name, _ = subroutine.product_n_to_name(product_n) for month in range(1, 13): _, strmonth = subroutine.strym(2000, month) subroutine.save_npz(data_allmonth[:, :, :, month - 1], Ave_or_Std + '_of_' + \ formal_name + '_m' + strmonth + '_' + str(fy) + '-' + str(ly) + \ '_' + title_name)
def get_grid_value(var): import netCDF4 import subroutine import numpy as np stryear,strmonth=subroutine.strym(2012,1) ncfile=subroutine.dat_dir()+'Aquarius/NetCDF/sss'+stryear+strmonth+'.v4.0cap.nc' nc=netCDF4.Dataset(ncfile,'r') xgrid=nc.variables['lon'][:] ygrid=nc.variables['lat'][:] nc.close() return [xgrid,ygrid,np.array([0])]
def nc_read(year,month): import netCDF4 import subroutine import scipy as sp import numpy as np Threshold=-998.0 stryear,strmonth=subroutine.strym(year,month) ncfile=subroutine.dat_dir()+'ERSST/ersst.'+stryear+strmonth+'.nc' nc=netCDF4.Dataset(ncfile,'r') the_sst=nc.variables['sst'][0,0,:,:] the_sst[np.where(the_sst<=Threshold)]=sp.nan # 欠損値のところはnanに。 nc.close() return the_sst
def get_data(year,month): import subroutine import netCDF4 dir=subroutine.dat_dir()+'AQC/NetCDF/' stryear,strmonth=subroutine.strym(year,month) ncfile=dir+'AQC_Profile_Data_'+stryear+strmonth+'.nc' nc=netCDF4.Dataset(ncfile,'r') time=nc.variables['TIME'][:,:] N_PROF=time.shape[0] STRING16=time.shape[1] pres=nc.variables['PRES'][:,:] N_LEVELS=pres.shape[1] temp=nc.variables['TEMP'][:] salt=nc.variables['PSAL'][:] lon=nc.variables['LONGITUDE'][:] lat=nc.variables['LATITUDE'][:] return temp,salt,pres,lon,lat
def draw_line_with_data_map(self, plt, year, month, var, depth, cb_min, cb_max, product_n = 3, xlim = [40, 110], ylim = [ - 20, 30], \ fsizex = 10, fsizey = 6, div = 20.0, interval = 10, color = 'red', linetype = '--'): import D import Var import quick import subroutine xgrid, ygrid, zgrid = D.get_grid_value(var, product_n) data = D.get_data(year, month, var, depth, product_n) stryear, strmonth = subroutine.strym(year, month) vid = Var.var_to_id(var) formal_name = Var.VAR[vid].Get_formal_name() title_name = D.Data[product_n].title_name clabel = stryear + '/' + strmonth + ' ' + formal_name + ' ' + ' at ' + str(zgrid[depth - 1]) + 'm '+ title_name plta = quick.draw_with_axis_and_map(data, ygrid, xgrid, cb_min, cb_max, xlim = xlim, ylim = ylim, \ interval = interval, clabel = clabel, fsizex = fsizex, fsizey = fsizey) plta = self.draw_line(plta, xlim, ylim, interval = interval, color = color, linetype = linetype) return plta
def get_data(year,month): import subroutine import netCDF4 import numpy as np import scipy as sp # ファイル名を指定 stryear,strmonth=subroutine.strym(year,month) ncfile=subroutine.dat_dir()+'Aquarius/NetCDF/sss'+stryear+strmonth+'.v4.0cap.nc' print ncfile # ファイル名を指定 nc=netCDF4.Dataset(ncfile,'r') lon=nc.variables['lon'][:] lon=nc.variables['lon'][:] data=nc.variables['sss_cap'][:,:] data[np.where(data<=-999)]=sp.nan # 欠損値のところはnanに。 return data
def save_Ave_or_Std_of_Data_as_npz(self, AvSt_of_Data, fy, ly, product_n, Ave_or_Std = 'Ave'): import D import subroutine title_name = D.Data[product_n].title_name year = 2000 DIR = subroutine.NAS_dir() + 'DATA/' + title_name + '/npz/' + self.dir_name + '/' subroutine.check_and_make_DIR(DIR) for month in range(1, 13): _, strmonth = subroutine.strym(year, month) fname = self.fname + '_of_Climatology_Year' + \ str(fy) + '-' + str(ly) + \ '_Month' + strmonth + '_' + title_name if self.dimension == 2: subroutine.save_npz(AvSt_of_Data[:, :, month - 1], DIR + fname, data_dir_flg = 'NO') elif self.dimension == 3: subroutine.save_npz(AvSt_of_Data[:, :, :, month - 1], DIR + fname, data_dir_flg = 'NO') else: raise ValueError('your dimension is not valid!')
def masuda_data_read(year,month,var,depth): Mt=60*60*24*30 # 1ヶ月の秒数 Threshold=-1e+30 # Threshold of Missing value data_dir=subroutine.dat_dir()+'ESTOCver03/binary/each_data/' ID = Var.var_to_id(var) dt=np.dtype([("data","<"+str(nx*ny)+"f")]) stryear,strmonth=subroutine.strym(year,month) fd=open(data_dir+"/"+stryear+strmonth+"/"+var+".out","r") dim = Var.VAR[ID].Get_dim() if dim == '3D': count=ik else: count=1 if count == 1 and depth != 1: raise ValueError('if you choose 2D data, depth must be 1!') chunk=np.fromfile(fd,dtype=dt,count=count) if depth != 0: data=chunk[depth-1]['data'] data=np.reshape(data,(ny,nx)) else: data=np.ones((ny,nx,ik)) for k in range(0,ik): data[:,:,k]=np.reshape(chunk[k]['data'],(ny,nx)) data[np.where(data<=Threshold)]=np.nan # 欠損値のところはnanに。 # 単位に関してはすでに修正済み。 # taux,tauy:N/m^2 # u,v,w,sff:m/s # q:cal/(m^2 s) if var=='sff':# 単位をm/Monthに data=data*Mt elif var=='ustar' or var=='vstar' or var=='wstar': data=data / 100.0 # 単位をm/sに elif var=='eq': # 淡水フラックスと同じ次元で扱えるように data=data*-Mt*0.01 return data
def nc_read(year,month,var,depth): import numpy as np import scipy as sp import netCDF4 import subroutine a=subroutine.read_meta_data('var') vn=subroutine.celldata(a,'var',var,'MOAA_GPV_vn') stryear,strmonth=subroutine.strym(year,month) ncfile=subroutine.dat_dir()+'MOAA_GPV/NetCDF/TS_'+stryear+strmonth+'_GLB.nc' nc=netCDF4.Dataset(ncfile,'r') if depth != 0: data=nc.variables[vn][depth-1,:,:] else: data=np.ones((ny,nx,nz)) for k in range(0,nz): data[:,:,k]=nc.variables[vn][k,:,:] nc.close() data[np.where(data>=10000)]=sp.nan # 欠損値のところはnanに。 return data
def draw_12month_cycle(cb_min, cb_max, depthn1 = 1, depthn2 = 4, product_n = 3, interval = 15): _,title_name,_=subroutine.product_n_to_name(product_n) xgrid, ygrid, zgrid = subroutine.product_grid_info('u', 'data', product_n) xlim = [40, 110] ylim = [-20, 30] fy = 1990 ly = 2011 Data = np.zeros((12, ygrid.size, xgrid.size)) for i in range(0, 12): month = i + 1 # データの取得 _, strmonth = subroutine.strym(2000, month) u = CI.load_climatology_or_interannual_variation_as_npz(fy, ly, month, 'u', 'Ave', product_n = product_n) v = CI.load_climatology_or_interannual_variation_as_npz(fy, ly, month, 'v', 'Ave', product_n = product_n) data1 = cal_Length_of_Current_Vector(u[:, :, depthn1 - 1], v[:, :, depthn1 - 1]) data2 = cal_Length_of_Current_Vector(u[:, :, depthn2 - 1], v[:, :, depthn2 - 1]) Data[i, :, :] = data1 - data2 plta = quick.draw_12month_cycle_with_map(Data, ygrid, xgrid, cb_min, cb_max, xlim = xlim, ylim = ylim, \ clabel = "Vertical Shear of Current(m/s) " + str(zgrid[depthn1 - 1]) + 'm - ' + str(zgrid[depthn2 - 1]) + 'm',\ interval = interval, my_color = 0)