Ejemplo n.º 1
0
def get_SUMsalinity(year, month, product_n = 3):
	# 全球での塩分の総和を求める。
	# 単位はkg。
	rho0 = 1024.0					# 海水の密度はこれで統一。
	_, title_name, _ = product_n_to_name(product_n)
	s = get_data(year, month, 's', 0, title_name)
	xgrid, ygrid, zgrid = product_grid_info('w', 'data', product_n)
	xn = xgrid.size
	yn = ygrid.size
	zn = zgrid.size
	ew_dist = zeros([yn, xn])
	ns_dist = zeros([yn, xn])
	S = zeros([yn, xn])

	for i in range(0, xn):
		for j in range(0, yn):
			ew_dist[j, i] = dist_on_sphere([0, ygrid[j]], [1, ygrid[j]])
			ns_dist[j, i] = dist_on_sphere([0, ygrid[j] - 0.5], [0, ygrid[j] + 0.5])
			if isnan(s[j, i, 0]) == True:
				S[j, i] = 0.0
			else:
				for k in range(0, zn):
					if k == 0:
						dH = zgrid[k]
					else:
						dH = zgrid[k] - zgrid[k - 1]

					if isnan(s[j, i, k]) == False:
						S[j, i] = S[j, i] + dH * ew_dist[j, i] * ns_dist[j, i] * rho0 * (s[j, i, k]/1000)
					else:
						break


	return sum(S)
def get_average_of_some_month(year, fm, lm, var, depth, product_n):
	import numpy as np
	if fm <= 0 or fm >= 13 or lm <= 0 or lm >= 0:
		raise Exception('your month value is not valid!')

	if lm < fm:
		raise Exception('lm must be greater equal than fm!')

	xgrid, ygrid, zgrid = subroutine.product_grid_info(var, 'data', product_n)
	xn, yn, zn = xgrid.size, ygrid.size, zgrid.size
	pro_name, title_name, bin_dirname = subroutine.product_n_to_name(product_n)
	nmonth = lm - fm + 1
	if depth == 0:
		each_data = np.zeros((nmonth, yn, xn, zn))
	else:
		each_data = np.zeros((nmonth, yn, xn))

	for month in range(fm, lm + 1):
		i = month - fm
		if depth == 0:
			each_data[i, :, :, :] = subroutine.get_data(year, month, var, depth, title_name)
		else:
			each_data[i, :, :] = subroutine.get_data(year, month, var, depth, title_name)

	average_data = np.average(each_data, axis = 0)

	return average_data
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 make_data_from_ts(t, s, product_n = 3, dt = 0.2):
	_,title_name,_=subroutine.product_n_to_name(product_n)
	xgrid,ygrid,zgrid=subroutine.product_grid_info('t','data',product_n)

	# MOAA_GPVだけ、格納されているのが(ポテンシャル水温でなく)通常の水温なので、まずポテンシャル水温への変換が必要
	if title_name=='MOAA_GPV':
		theta=np.zeros((t.shape[0],t.shape[1],t.shape[2]))
		for m in range(0,zgrid.size):
			theta[:,:,m]=density.poT(t[:,:,m],s[:,:,m],zgrid[m])

		t=theta
		t[np.where(abs(t)== inf)]=nan

	rho=density.rho(t,s,0)
	rho[np.where(abs(rho)== inf)]=nan
	xn=xgrid.size
	yn=ygrid.size
	ILD=np.zeros([yn,xn])
	MLD=np.zeros([yn,xn])
	BLT=np.zeros([yn,xn])
	for i in range(0,xn):
		for j in range(0,yn):
			if np.isnan(t[j,i,0]) == False:
				tpro=t[j,i,:]
				rhopro=rho[j,i,:]
				spro = s[j, i, :]
				ILD[j, i], MLD[j, i], BLT[j, i] = make_data_from_profile(tpro, spro, rhopro, zgrid, dt)
			else:
				ILD[j,i]=nan
				MLD[j,i]=nan
				BLT[j, i] = nan


	return ILD,MLD,BLT
def make_climatology_or_interannual_variation_of_a_month(fy, ly, month, var, depth, Ave_or_Std, product_n = 3):

	if ly < fy:
		raise Exception('ly must be greater equal than fy!')

	xgrid, ygrid, zgrid = subroutine.product_grid_info(var, 'data', product_n)
	xn, yn, zn = xgrid.size, ygrid.size, zgrid.size
	pro_name, title_name, bin_dirname = subroutine.product_n_to_name(product_n)
	nyear = ly - fy + 1
	if depth == 0:
		each_data = np.zeros((nyear, yn, xn, zn))
	else:
		each_data = np.zeros((nyear, yn, xn))

	for year in range(fy, ly + 1):
		i = year - fy
		if depth == 0:
			each_data[i, :, :, :] = subroutine.get_data(year, month, var, depth, title_name)
		else:
			each_data[i, :, :] = subroutine.get_data(year, month, var, depth, title_name)

	if Ave_or_Std == 'Ave':
		climatology = np.average(each_data, axis = 0)
		return climatology
	elif Ave_or_Std == 'Std':
		Interannual_variation = np.std(each_data, axis = 0)
		return Interannual_variation
	else:
		raise Exception('your Ave_or_Std argument is not valid!')
def make_data(year,month,product_n=3,dt=0.2):
	# ESTOC、ORAS4などで、層厚の計算を行うための関数。
	# MOAA_GPVだけ、格納されているのが(ポテンシャル水温でなく)通常の水温なので、まずポテンシャル水温への変換が必要
	_,title_name,_=subroutine.product_n_to_name(product_n)
	t=subroutine.get_data(year,month,'t',0,title_name)
	s=subroutine.get_data(year,month,'s',0,title_name)
	ILD, MLD, BLT = make_data_from_ts(t, s, product_n, dt)
	return ILD, MLD, BLT
def make_data_of_24sigma_t_depth(year, month, var, product_n = 3):
	_,title_name,_=subroutine.product_n_to_name(product_n)
	sgmt_d = make_24sigma_t_depth(year, month, product_n)
	data = subroutine.get_data(year, month, var, 0, title_name)
	if var == 'u' or var == 'v':
		data = convert.convert_UVgrid_value_to_Sgrid_value_3D(data)

	data_of_sgm_t = make_data_of_24sigma_t_depth_from_data(sgmt_d, data, product_n = product_n)
	return data_of_sgm_t
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 make_rho_from_ts(t,s, product_n = 3):
	xgrid,ygrid,zgrid=subroutine.product_grid_info('t','data',product_n)
	_, title_name, _ = subroutine.product_n_to_name(product_n)
	# MOAA_GPVだけ、格納されているのが(ポテンシャル水温でなく)通常の水温なので、まずポテンシャル水温への変換が必要
	if title_name=='MOAA_GPV':
		theta=zeros((t.shape[0],t.shape[1],t.shape[2]))
		for m in range(0,zgrid.size):
			theta[:,:,m]=density.poT(t[:,:,m],s[:,:,m],zgrid[m])

		t=theta
		t[where(abs(t)== inf)]=nan

	rho = density.rho(t, s, 0)
	rho[np.where(np.abs(rho) == sp.inf)] = np.nan
	return rho
Ejemplo n.º 10
0
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
Ejemplo n.º 11
0
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)
Ejemplo n.º 12
0
def cal_ew_ns_dist(year,month,product_n=3):
	_,title_name,_=product_n_to_name(product_n)
	xgrid,ygrid,zgrid=product_grid_info('u','data',product_n)
	u=get_data(year,month,'u',0,title_name)
	v=get_data(year,month,'v',0,title_name)
	xn=xgrid.size
	yn=ygrid.size
	zn=zgrid.size
	ew_dist=zeros([yn-1,xn])
	ns_dist=zeros([yn-1,xn])
	xgrid_for_manual_w=zeros(xn)
	ygrid_for_manual_w=zeros(yn-1)
	zgrid_for_manual_w=zeros(zn)

	for i in range(0,xn):
		x0=i
		lon0=xgrid[x0]
		if i==xn-1:
			x1=0
			lon1=xgrid[x1]
			xgrid_for_manual_w[i]=average([lon0,lon1+360])
		else:
			x1=i+1
			lon1=xgrid[x1]
			xgrid_for_manual_w[i]=average([lon0,lon1])

		for j in range(0,yn-1):

			y0=j
			y1=j+1
			lat0=ygrid[y0]
			lat1=ygrid[y1]
			ygrid_for_manual_w[j]=average([lat0,lat1])
			ew_dist[j,i]=dist_on_sphere([lon0,ygrid_for_manual_w[j]],[lon1,ygrid_for_manual_w[j]])
			ns_dist[j,i]=dist_on_sphere([xgrid_for_manual_w[i],lat0],[xgrid_for_manual_w[i],lat1])


	return ew_dist,ns_dist
Ejemplo n.º 13
0
def get_SUMsff(year, month, product_n = 3):
	# 全球での淡水フラックスの総和を求める
	# 単位はm^3/month。
	_, title_name, _ = product_n_to_name(product_n)
	sff = get_data(year, month, 'sff', 1, title_name)
	xgrid, ygrid, _ = product_grid_info('t', 'data', product_n)
	xn = xgrid.size
	yn = ygrid.size
	ew_dist = zeros([yn, xn])
	ns_dist = zeros([yn, xn])
	SFF = zeros([yn, xn])

	for i in range(0, xn):
		for j in range(0, yn):
			ew_dist[j, i] = dist_on_sphere([0, ygrid[j]], [1, ygrid[j]])
			ns_dist[j, i] = dist_on_sphere([0, ygrid[j] - 0.5], [0, ygrid[j] + 0.5])
			if isnan(sff[j, i]) == True:
				SFF[j, i] = 0.0
			else:
				SFF[j, i] = sff[j, i] * ew_dist[j, i] * ns_dist[j, i]


	return sum(SFF)
Ejemplo n.º 14
0
def get_water_mass(product_n = 3):
	_, title_name, _ = product_n_to_name(product_n)
	s = get_data(2001, 1, 's', 0, title_name)
	xgrid, ygrid, zgrid = product_grid_info('w', 'data', product_n)
	xn = xgrid.size
	yn = ygrid.size
	zn = zgrid.size
	ew_dist = zeros([yn, xn])
	ns_dist = zeros([yn, xn])
	Mass = zeros([yn, xn])

	for i in range(0, xn):
		for j in range(0, yn):
			ew_dist[j, i] = dist_on_sphere([0, ygrid[j]], [1, ygrid[j]])
			ns_dist[j, i] = dist_on_sphere([0, ygrid[j] - 0.5], [0, ygrid[j] + 0.5])
			if isnan(s[j, i, 0]) == True:
				Mass[j, i] = 0.0
			else:
				L = max(where(isnan(s[j, i, :]) == False)[0])
				Mass[j, i] = zgrid[L] * ew_dist[j, i] * ns_dist[j, i]


	return sum(Mass)
def make_20degree_depth(year, month, product_n = 3):
	_, title_name, _ = subroutine.product_n_to_name(product_n)
	t = subroutine.get_data(year, month, 't', 0, title_name)
	data = make_20degree_depth_from_t(t, product_n)
	return data
Ejemplo n.º 16
0
def cal_manual_w(year,month,product_n=3, GM = 'N'):
	_,title_name,_=product_n_to_name(product_n)
	if GM == 'N':
		u=get_data(year,month,'u',0,title_name)
		v=get_data(year,month,'v',0,title_name)
	elif GM == 'Y':
		u = get_data(year, month, 'ustar', 0, title_name)
		v = get_data(year, month, 'vstar', 0, title_name)
	else:
		raise Exception('your GM argument is not valid!')

	xgrid,ygrid,zgrid=product_grid_info('u','data',product_n)
	xn=xgrid.size
	yn=ygrid.size
	zn=zgrid.size
	manual_w=zeros([yn,xn,zn])
	xgrid_for_manual_w=zeros(xn)
	ygrid_for_manual_w=zeros(yn)
	zgrid_for_manual_w=zeros(zn)
	dH=zeros(zn)
	for k in range(0,zn):
		if k==0:
			zgrid_for_manual_w[k]=2*zgrid[k]
			dH[k]=zgrid_for_manual_w[k]
		else:
			zgrid_for_manual_w[k]=2*zgrid[k]-zgrid_for_manual_w[k-1]
			dH[k]=zgrid_for_manual_w[k]-zgrid_for_manual_w[k-1]


	for i in range(0,xn):
		x0=i
		lon0=xgrid[x0]
		if i==xn-1:
			x1=0
			lon1=xgrid[x1]
			xgrid_for_manual_w[i]=average([lon0,lon1+360])
		else:
			x1=i+1
			lon1=xgrid[x1]
			xgrid_for_manual_w[i]=average([lon0,lon1])

		for j in range(0,yn):
			if j == yn - 1:
				manual_w[j,i,:]=nan
				ygrid_for_manual_w[j]=average([ygrid[yn - 1],ygrid[yn - 1] + 1])
			else:
				y0=j
				y1=j + 1
				lat0=ygrid[y0]
				lat1=ygrid[y1]
				ygrid_for_manual_w[j]=average([lat0,lat1])
				ew_dist=dist_on_sphere([lon0,ygrid_for_manual_w[j]],[lon1,ygrid_for_manual_w[j]])
				ns_dist=dist_on_sphere([xgrid_for_manual_w[i],lat0],[xgrid_for_manual_w[i],lat1])

				for k in range(0,zn):
					if k==0:
						manual_w0=0.0
					else:
						manual_w0=manual_w[j,i,k-1]

					u00=u[y0,x0,k]
					v00=v[y0,x0,k]
					u01=u[y1,x0,k]
					v01=v[y1,x0,k]
					u10=u[y0,x1,k]
					v10=v[y0,x1,k]
					u11=u[y1,x1,k]
					v11=v[y1,x1,k]
					if any(isnan(u00, u01, u10, u11)) == False:
						manual_w[j,i,k]=dH[k]*(((v01+v11)/2.0-(v00+v10)/2.0)/ns_dist
										  +((u10+u11)/2.0-(u00+u01)/2.0)/ew_dist)+manual_w0
					else:
						manual_w[j,i,k]=nan

	return manual_w,xgrid_for_manual_w,ygrid_for_manual_w,zgrid_for_manual_w
Ejemplo n.º 17
0
def make_rho(year, month, product_n = 3):
	_, title_name, _ = subroutine.product_n_to_name(product_n)
	t = subroutine.get_data(year, month, 't', 0, title_name)
	s = subroutine.get_data(year, month, 's', 0, title_name)
	rho = make_rho_from_ts(t, s, product_n)
	return rho
Ejemplo n.º 18
0
def get_Length_of_Current_Vector(year, month, depthn = 1, product_n = 3):
	_,title_name,_=subroutine.product_n_to_name(product_n)
	u = subroutine.get_data(year, month, 'u', depthn, title_name)
	v = subroutine.get_data(year, month, 'v', depthn, title_name)
	L = cal_Length_of_Current_Vector(u, v)
	return L