def DMI(fy, ly, product_n): # 時系列データを得る練習として、DMIを計算してみる。 npz_dir = subroutine.get_npz_dir(product_n) fname = npz_dir + 'DMI-' + str(fy) + str(ly) + '.npz' print fname if os.path.exists(fname) == False: etseries = np.ones([ly - fy + 1, 12]) wtseries = np.ones([ly - fy + 1, 12]) for iye in range(fy, ly + 1): for itime in range(1, 13): etseries[iye - fy, itime - 1] = get_area_mean_data(0, iye, itime, 't', 1, 'hoge', 'eDMI', product_n) wtseries[iye - fy, itime - 1] = get_area_mean_data(0, iye, itime, 't', 1, 'hoge', 'wDMI', product_n) ano_et = subroutine.array_avestd(etseries, 'ano') ano_et = to_oneline(ano_et) ano_et = running_mean(ano_et, 5) ano_wt = subroutine.array_avestd(wtseries, 'ano') ano_wt = to_oneline(ano_wt) ano_wt = running_mean(ano_wt, 5) dmi = ano_wt - ano_et # dmi_oneline=to_oneline(dmi) ym = ts.ym_timeseries02(fy, ly) np.savez(fname, ym = ym, dmi = dmi) else: pass npload = np.load(fname) ym = npload['ym'] dmi = npload['dmi'] return dmi, ym
def call_productDMI(product_n): # fortranで作成したDMIを呼び出す pro_name, title_name, bin_dirname = subroutine.product_n_to_name(product_n) dtd = subroutine.dat_dir() f = open(dtd + '/' + pro_name + '/' + bin_dirname + '/DMI/fy.dat', 'r') fy = int(f.read()) f.close() f = open(dtd + '/' + pro_name + '/' + bin_dirname + '/DMI/ly.dat', 'r') ly = int(f.read()) f.close() fd = open(dtd + '/' + pro_name + '/' + bin_dirname + '/DMI/dmi.monthly_ESTOC.out', 'r') chunk = np.fromfile(fd, dtype = np.dtype([("data", "<" + str((ly - fy + 1)*12) + "f")]), count = 4) ym_convert = chunk[0]['data'] fy = ym_convert[0] ly = int(ym_convert[ym_convert.size - 1]) ym = ts.ym_timeseries02(fy, ly) data = chunk[1]['data'] data_rm = chunk[2]['data'] data_rm_tr = chunk[3]['data'] return ym, data, data_rm, data_rm_tr
def get_data(var,lon,lat,time_res): import subroutine import timeseries as ts import netCDF4 import numpy as np import scipy as sp dir=subroutine.dat_dir()+'RAMA/NetCDF/' # ファイル名を指定 if lat>=0.0: strlat=str(lat)+'n' else: strlat=str(-lat)+'s' strlon=str(lon)+'e' if var=='t': filevar='t' floatvar='T_20' elif var=='s': filevar='s' floatvar='S_41' elif var=='u': filevar='adcp' floatvar='u_1205' elif var=='v': filevar='adcp' floatvar='v_1206' elif var=='ssu': filevar='cur' floatvar='U_320' elif var=='ssv': filevar='cur' floatvar='V_321' else: raise Exception('your var is not valid!') if time_res=='D': # Dailyのデータ f_name_tr='dy' elif time_res=="M": # Monthlyのデータ f_name_tr='mon' else: raise Exception('your time_res in not valid!') ncfile=dir+filevar+strlat+strlon+'_'+f_name_tr+'.cdf' print ncfile # ファイル名を指定 nc=netCDF4.Dataset(ncfile,'r') time=nc.variables['time'][:] units=nc.variables['time'].units dtime=netCDF4.num2date(time,units=units) lon=nc.variables['lon'][:] lat=nc.variables['lat'][:] depth=nc.variables['depth'][:] data=nc.variables[floatvar][:,:,0,0] data[np.where(data>=10000)]=sp.nan # 欠損値のところはnanに。 if time_res=="M": # 期間を2001年1月から2016年12月まで fy=2001 ly=2016 all_data=np.zeros([(ly-fy+1)*12,depth.size]) all_dtime=ts.ym_timeseries02(fy,ly) nmin=max(max(np.where(all_dtime==dtime[0]))) # データの開始する番号 nmax=max(max(np.where(all_dtime==dtime[dtime.size-1]))) # データが終了する番号 all_data[nmin:nmax+1,:]=data[:,:] all_data[:nmin,:]=sp.nan all_data[nmax+1:,:]=sp.nan dtime=all_dtime data=all_data if var=='u' or var=='v' or var=='ssu' or var=='ssv':data=data*0.01 # 単位をm/sに return dtime,depth,data