示例#1
0
def get_depth_of_minimum_of_vertical_gradient_from_data(data, var, product_n = 3):
	xgrid, ygrid, zgrid = D.get_grid_value(var, product_n)
	xn = xgrid.size
	yn = ygrid.size
	zn = zgrid.size

	Grad = np.zeros((yn, xn, zn))
	for k in range(1, zn - 1):
		dz = 0.5 * (zgrid[k + 1] - zgrid[k - 1])
		Grad[:, :, k] = (data[:, :, k + 1] - data[:, :, k - 1]) / dz

	Grad[np.where(np.isnan(Grad) == True)] = np.inf
	GradMin = np.min(Grad, axis = 2)

	Depth_of_GradMin = np.zeros((yn, xn))
	for j in range(0, yn):
		for i in range(0, xn):
			if GradMin[j, i] == 0.0:
				Depth_of_GradMin[j, i] = np.nan
			else:
				K1 = np.where(Grad[j, i, :] == GradMin[j, i])[0][0]
				Depth_of_GradMin[j, i] = zgrid[K1]

	Depth_of_GradMin[np.where(np.abs(Depth_of_GradMin) == np.inf)] = np.nan
	Depth_of_GradMin[np.where(Depth_of_GradMin == 0.0)] = np.nan

	return Depth_of_GradMin
示例#2
0
def get_depth_of_maximum_of_vertical_gradient_from_profile(profile, product_n = 3):
	_, _, zgrid = D.get_grid_value('s', product_n)
	zn = zgrid.size
	Grad = np.zeros(zn)
	for k in range(1, zn - 1):
		dz = 0.5 * (zgrid[k + 1] - zgrid[k - 1])
		Grad[k] = (profile[k + 1] - profile[k - 1]) / dz

	Grad[np.where(np.isnan(Grad) == True)] = -np.inf
	GradMax = np.max(Grad)
	Grad[np.where(Grad == -np.inf)] = np.inf
	GradMin = np.min(Grad)

	if GradMax == 0.0 and GradMin == 0.0:
		Depth_of_GradMax = np.nan
	else:
		K1 = np.where(Grad == GradMax)[0][0]
		K2 = np.where(Grad == GradMin)[0][0]
		if GradMax >= abs(GradMin):
			Depth_of_GradMax = zgrid[K1]
		else:
			Depth_of_GradMax = zgrid[K2]


	return Depth_of_GradMax
示例#3
0
	def Get_VerticalSection_from_data(self, data, var, product_n):
		import D
		import numpy as np
		import convert
		xgrid, ygrid, zgrid = D.get_grid_value('t', product_n)
		if var == 'u' or var == 'v':
			data = convert.convert_UVgrid_value_to_Sgrid_value_3D(data)

		Ln = self.Pn
		if self.direction == 'EW':
			Data = np.zeros((self.band, Ln, zgrid.size))
			for i in range(0, Ln):
				xn = np.where(xgrid == self.hgrid[i])[0][0]
				for j in range(0, self.band):
					yn = np.where(ygrid == self.latp[i] + j)[0][0]
					Data[j, i, :] = data[yn, xn, :]

		elif self.direction == 'NS':
			Data = np.zeros((Ln, self.band, zgrid.size))
			for j in range(0, Ln):
				yn = np.where(ygrid == self.hgrid[j])[0][0]
				for i in range(0, self.band):
					xn = np.where(xgrid == self.lonp[j] + i)[0][0]
					Data[j, i, :] = data[yn, xn, :]

		else:
			raise ValueError("your direction is not valid!")

		return np.average(Data, axis = self.average_axis), self.hgrid, zgrid
示例#4
0
	def Get_Current_of_VerticalSection_from_UV(self, u, v, product_n):
		import D
		import numpy as np
		xgrid, ygrid, zgrid = D.get_grid_value('u', product_n)
		Ln = self.Pn
		if self.direction == 'EW':
			Data = np.zeros((self.band - 1, Ln - 1, zgrid.size))
			for i in range(0, Ln - 1):
				xn = np.where(xgrid == self.hgrid[i] + 0.5)[0][0]
				x = self.lonp[i + 1] - self.lonp[i]
				y = self.latp[i + 1] - self.latp[i]
				cos_alpha = x / np.sqrt(x ** 2 + y ** 2)
				sin_alpha = y / np.sqrt(x ** 2 + y ** 2)
				for j in range(0, self.band - 1):
					yn = np.where(ygrid == self.latp[i] + j + 0.5)[0][0]
					Data[j, i, :] = cos_alpha * u[yn, xn, :] + sin_alpha * v[yn, xn, :]

		elif self.direction == 'NS':
			Data = np.zeros((Ln - 1, self.band - 1, zgrid.size))
			for j in range(0, Ln - 1):
				yn = np.where(ygrid == self.hgrid[j] + 0.5)[0][0]
				x = self.lonp[j + 1] - self.lonp[j]
				y = self.latp[j + 1] - self.latp[j]
				cos_alpha = x / np.sqrt(x ** 2 + y ** 2)
				sin_alpha = y / np.sqrt(x ** 2 + y ** 2)
				for i in range(0, self.band - 1):
					xn = np.where(xgrid == self.lonp[j] + i + 0.5)[0][0]
					Data[j, i, :] = cos_alpha * u[yn, xn, :] + sin_alpha * v[yn, xn, :]

		else:
			raise ValueError("your direction is not valid!")

		return np.average(Data, axis = self.average_axis), self.hgrid[:self.Pn - 1] + 0.5, zgrid
示例#5
0
	def Get_VerticalSection_from_2Ddata(self, data, var, product_n):
		import D
		import numpy as np
		xgrid, ygrid, zgrid = D.get_grid_value(var, product_n)
		Ln = self.Pn
		if self.direction == 'EW':
			Data = np.zeros((self.band, Ln))
			for i in range(0, Ln):
				xn = np.where(xgrid == self.hgrid[i])[0][0]
				for j in range(0, self.band):
					yn = np.where(ygrid == self.latp[i] + j)[0][0]
					Data[j, i] = data[yn, xn]

		elif self.direction == 'NS':
			Data = np.zeros((Ln, self.band))
			for j in range(0, Ln):
				yn = np.where(ygrid == self.hgrid[j])[0][0]
				for i in range(0, self.band):
					xn = np.where(xgrid == self.lonp[j] + i)[0][0]
					Data[j, i] = data[yn, xn]

		else:
			raise ValueError("your direction is not valid!")

		return np.average(Data, axis = self.average_axis), self.hgrid
示例#6
0
def get_Gradient_of_variable_from_data(data, var, product_n = 3):
	xgrid, ygrid, zgrid = D.get_grid_value(var, product_n)
	xn = xgrid.size
	yn = ygrid.size
	zn = zgrid.size

	Data_ns = np.zeros((yn, xn, zn))
	Data_ew = np.zeros((yn, xn, zn))
	ns_dist = subroutine.dist_on_sphere([0.0, - 0.5], [0.0, 0.5])

	for j in range(0, yn):
		if j == 0 or j == yn - 1:
			Data_ns[j, :, :] = np.nan
			Data_ew[j, :, :] = np.nan
		else:
			y0 = j - 1
			y1 = j
			y2 = j + 1
			lat1 = ygrid[y1]
			ew_dist = subroutine.dist_on_sphere([0.0, lat1], [1.0, lat1])

			for i in range(0, xn):
				x1 = i
				lon1 = xgrid[x1]
				if i == 0:
					x0 = xn - 1
					x2 = i + 1
				elif i == xn - 1:
					x0 = i - 1
					x2 = xn - 1
				else:
					x0 = i - 1
					x2 = i + 1

				data01 = data[y1, x0, :]
				data10 = data[y0, x1, :]
				data11 = data[y1, x1, :]
				data21 = data[y1, x2, :]
				data12 = data[y2, x1, :]

				if np.isnan(data01[0]) == True and np.isnan(data21[0]) == False:
					Data_ew[j, i, :] = (data21 - data11) / ew_dist
				elif np.isnan(data21[0]) == True and np.isnan(data01[0]) == False:
					Data_ew[j, i, :] = (data11 - data01) / ew_dist
				else:
					Data_ew[j, i, :] = (data21 - data01) / (2.0 * ew_dist)

				if np.isnan(data10[0]) == True and np.isnan(data12[0]) == False:
					Data_ns[j, i, :] = (data12 - data11) / ns_dist
				elif np.isnan(data12[0]) == True and np.isnan(data10[0]) == False:
					Data_ns[j, i, :] = (data11 - data10) / ns_dist
				else:
					Data_ns[j, i, :] = (data12 - data10) / (2.0 * ns_dist)

	return Data_ew, Data_ns
示例#7
0
	def save_data_as_npz(self, Timeseries, fy, ly, var, depth = 1, product_n = 3):
		import D
		import Var
		import subroutine
		vid = Var.var_to_id(var)
		formal_name = Var.VAR[vid].Get_formal_name()
		title_name = D.Data[product_n].title_name
		xgrid, ygrid, zgrid = D.get_grid_value(var, product_n)
		subroutine.save_npz(Timeseries, self.AreaName + '_Area-Averaged-' + \
							formal_name + '_at_' + str(zgrid[depth - 1]) + \
							'm_Year' + str(fy) + '-' + str(ly) + '_' + title_name)
def product_grid_info(var, data_or_size, product_n = 3):		# グリッドに関するデータを獲得する
	import D
	if type(product_n) != int:								# product_nが整数でない時はエラーを吐き出す。
		raise Exception('product_n is not integer!')

	xgrid, ygrid, zgrid = D.get_grid_value(var, product_n)
	if data_or_size == 'data':
		return xgrid, ygrid, zgrid
	elif data_or_size == 'size':
		return xgrid.size, ygrid.size, zgrid.size
	else:
		raise Exception('error! your character is not valid!')
def cal_GeostrophicCurrent_from_SSH(ssh, product_n = 3):
	ns_dist = subroutine.dist_on_sphere([0.0, - 0.5], [0.0, 0.5])
	xgrid, ygrid, zgrid = D.get_grid_value('ht', product_n)
	yn = ygrid.size
	xn = xgrid.size
	Ug = np.zeros((yn, xn))
	Vg = np.zeros((yn, xn))
	xgrid_new = np.zeros(xn)
	ygrid_new = np.zeros(yn)

	for j in range(0, yn):
		if j == yn - 1:
			ygrid_new[j] = 0.5 * (ygrid[j] + ygrid[j] + 1)
			Ug[j, :] = np.nan
			Vg[j, :] = np.nan
		else:
			y0 = j
			y1 = j + 1
			ygrid_new[j] = 0.5 * (ygrid[y0] + ygrid[y1])

			if abs(ygrid_new[j]) <= 2.0: # 赤道付近においては地衡流は計算しない
				Ug[j, :] = np.nan
				Vg[j, :] = np.nan
			else:
				ew_dist = subroutine.dist_on_sphere([0.0, ygrid_new[j]], [1.0, ygrid_new[j]])
				f = subroutine.f0(ygrid_new[j])

				for i in range(0, xn):
					x0 = i
					if i == xn - 1:
						x1 = 0
						lon = 0.5 * (xgrid[i] + xgrid[i] + 1.0)
					else:
						x1 = i + 1
						lon = 0.5 * (xgrid[x0] + xgrid[x1])

					if j == 1:
						xgrid_new[i] = lon

					ssh00 = ssh[y0, x0]
					ssh01 = ssh[y1, x0]
					ssh10 = ssh[y0, x1]
					ssh11 = ssh[y1, x1]
					a = Using_jit.average_of_2data(ssh01, ssh11)
					b = Using_jit.average_of_2data(ssh00, ssh10)
					c = Using_jit.average_of_2data(ssh10, ssh11)
					d = Using_jit.average_of_2data(ssh00, ssh01)

					Ug[j, i] = -g / f * (a - b) / ns_dist
					Vg[j, i] = g / f * (c - d) / ew_dist


	return Ug, Vg, xgrid_new, ygrid_new
示例#10
0
def cal_curl(year, month, product_n = 3):
	taux = D.get_data(year, month, 'taux', 1, product_n)
	tauy = D.get_data(year, month, 'tauy', 1, product_n)
	xgrid, ygrid, zgrid = D.get_grid_value('taux', product_n)
	xn = xgrid.size
	yn = ygrid.size
	curl = np.zeros([yn, xn])
	ns_dist = subroutine.dist_on_sphere([0.0, - 0.5], [0.0, 0.5])

	for j in range(0, yn):
		if j == yn - 1:
			curl[j, :] = np.nan
		else:
			y0 = j
			y1 = j + 1
			lat0 = ygrid[y0]
			lat1 = ygrid[y1]
			tmpdist = np.average(np.array([lat0, lat1]))
			ew_dist = subroutine.dist_on_sphere([0.0, tmpdist], [1.0, tmpdist])

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

				taux00 = taux[y0, x0]
				tauy00 = tauy[y0, x0]
				taux01 = taux[y1, x0]
				tauy01 = tauy[y1, x0]
				taux10 = taux[y0, x1]
				tauy10 = tauy[y0, x1]
				taux11 = taux[y1, x1]
				tauy11 = tauy[y1, x1]
				a = Using_jit.average_of_2data(tauy10, tauy11)
				b = Using_jit.average_of_2data(tauy00, tauy01)
				c = Using_jit.average_of_2data(taux01, taux11)
				d = Using_jit.average_of_2data(taux00, taux10)
				if np.isnan(a - b) == False and np.isnan(c - d) == False:
					curl[j, i] = (a - b) / ew_dist - (c - d) / ns_dist
				elif np.isnan(a - b) == False:
					curl[j, i] = (a - b) / ew_dist
				elif np.isnan(c - d) == False:
					curl[j, i] = - (c - d) / ns_dist
				else:
					curl[j, i] = np.nan

	return curl
示例#11
0
	def load_data_of_npz(self, fy, ly, var, depth = 1, product_n = 3):
		import D
		import Var
		import subroutine
		vid = Var.var_to_id(var)
		formal_name = Var.VAR[vid].Get_formal_name()
		title_name = D.Data[product_n].title_name
		xgrid, ygrid, zgrid = D.get_grid_value(var, product_n)
		Timeseries = subroutine.load_npz(self.AreaName + '_Area-Averaged-' + \
										 formal_name + '_at_' + str(zgrid[depth - 1]) + \
										 'm_Year' + str(fy) + '-' + str(ly) + '_' + title_name)
		months, label = subroutine.get_months_and_label(fy, ly)
		return Timeseries, months, label
示例#12
0
def cal_Ue_or_Ve(year, month, product_n, Ue_or_Ve, nu):
	taux = D.get_data(year, month, 'taux', 1, product_n)
	tauy = D.get_data(year, month, 'tauy', 1, product_n)
	xgrid, ygrid, zgrid = D.get_grid_value('taux', product_n)

	if Ue_or_Ve == 'Ue':
		Ue, _ = cal_EkmanCurrent_from_tau(taux, tauy, ygrid, nu)
	elif Ue_or_Ve == 'Ve':
		_, Ue = cal_EkmanCurrent_from_tau(taux, tauy, ygrid, nu)
	else:
		raise ValueError('your Ue_or_Ve argument is not valid!')

	Ue = convert.convert_Sgrid_value_to_UVgrid_value_3D(Ue)
	a = np.zeros((ygrid.size, xgrid.size, zgrid.size - M)) * np.nan # 鉛直にuやvと同じだけ層を作ってやる
	Ue = np.c_[Ue, a]
	return Ue
示例#13
0
	def cal_Salinity_Transport_Budget(self, year, month, depth = 10, product_n = 3):
		# その領域における塩分輸送量収支を計算する。
		# 注意! x,y,z軸方向のグリッドの大きさはすべて等しいと仮定して計算しております。
		# さらに、領域は南北に長くなく、EWdistで南北両側面の断面積を計算していいこととしております。
		import D
		import D2
		import Using_jit
		import numpy as np
		import Budget_at_Global_Ocean
		rho0 = 1024.0
		dS = Budget_at_Global_Ocean.cal_dSdt(year, month, product_n)[:, :, :depth]
		sff = D.get_data(year, month, 'sff', 1, product_n)
		s = D.get_data(year, month, 's', 0, product_n)[:, :, :depth]
		u = D.get_data(year, month, 'u', 0, product_n)[:, :, :depth]
		v = D.get_data(year, month, 'v', 0, product_n)[:, :, :depth]
		ssh = D2.D2Data[33].load_data_of_npz(year, month, product_n)
		ssh_Sec = self.Get_data_of_AreaSection_from_data(ssh, 'ht', product_n)
		ssh_Area, _, _ = self.Get_data_of_area(ssh, 'ht', product_n)
		s_bottom = s[:, :, depth - 1]
		s_surface = s[:, :, 0]
		w = D.get_data(year, month, 'w', depth, product_n)
		_, _, zgrid = D.get_grid_value('w', product_n)

		ZonTsp = Using_jit.cal_Salt_Transport(s, u, 0, product_n)
		MerTsp = Using_jit.cal_Salt_Transport(s, v, 1, product_n)
		ZonTsp = self.Get_data_of_AreaSection_from_data(ZonTsp, 's', product_n)
		MerTsp = self.Get_data_of_AreaSection_from_data(MerTsp, 's', product_n)

		# 海面力学高度の分だけ、各断面の高さに下駄を履かせてやる
		West = np.sum(ZonTsp.West) * (zgrid[depth - 1] + np.average(ssh_Sec.West)) / zgrid[depth - 1]
		East = np.sum(ZonTsp.East) * (zgrid[depth - 1] + np.average(ssh_Sec.East)) / zgrid[depth - 1]
		North = np.sum(MerTsp.North) * (zgrid[depth - 1] + np.average(ssh_Sec.North)) / zgrid[depth - 1]
		South = np.sum(MerTsp.South) * (zgrid[depth - 1] + np.average(ssh_Sec.South)) / zgrid[depth - 1]

		w, _, _ = self.Get_data_of_area(w, 'w', product_n)
		s_bottom, _, _ = self.Get_data_of_area(s_bottom, 's', product_n)
		Bottom = self.Square * np.average(1e-3 * rho0 * w * s_bottom)

		sff, _, _ = self.Get_data_of_area(sff, 'sff', product_n)
		s_surface, _, _ = self.Get_data_of_area(s_surface, 's', product_n)
		Surface = self.Square * np.average(1e-3 * rho0 * sff * s_surface) / (60 * 60 * 24 * 30.0)

		# 海面力学高度の分だけ、水柱の高さに下駄を履かせてやる
		dS, _, _ = self.Get_data_of_area(dS, 's', product_n)
		Change = 1e-3 * rho0 * np.average(dS) * (zgrid[depth - 1] + np.average(ssh_Area)) * self.Square / (60 * 60 * 24 * 30.0)

		return South, North, West, East, Bottom, Surface, Change
示例#14
0
	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
示例#15
0
def cal_Salt_Transport(s, u, Zonal_or_Meridional, product_n):
	# 東西輸送量も鉛直輸送量もどっちも求められます。
	# Zonal : Zonal_or_Meridional = 0
	# Meridional : Zonal_or_Meridional = 1
	rho0 = 1024.0				# 面倒くさいので密度は一定値。
	yn = s.shape[0]
	xn = s.shape[1]
	zn = s.shape[2]
	ns_dist = subroutine.dist_on_sphere([0.0, - 0.5], [0.0, 0.5])
	xgrid, ygrid, zgrid = D.get_grid_value('s', product_n)
	Data = np.zeros((yn, xn, zn))

	for j in range(0, yn):
		if j == 0:
			Data[j, :, :] = np.nan
		else:
			y0 = j - 1
			y1 = j
			lat1 = ygrid[y1]

			if Zonal_or_Meridional == 0:
				L = ns_dist		# 東西輸送量であれば、南北に積分
			elif Zonal_or_Meridional == 1:
				L = subroutine.dist_on_sphere([0.0, lat1], [1.0, lat1]) # 南北輸送量であれば、東西に積分
			else:
				raise ValueError('your Zonal_or_Meridional argument is not valid!')

			for i in range(0, xn):
				x1 = i
				if i == 0:
					x0 = xn - 1
				else:
					x0 = i - 1


				if np.isnan(s[y1, x1, 0]) == True:
					Data[y1, x1, :] = np.nan
				else:
					for k in range(0, zn):
						# U = np.array([u[y0, x0, k], u[y1, x0, k], u[y0, x1, k], u[y1, x1, k]])
						# Data[y1, x1, k] = L * lz[k] * 1e-3 * rho0 * s[y1, x1, k] * \
						# 				  np.average(U[np.where(np.isnan(U) == False)])
						Data[y1, x1, k] = L * lz[k] * 1e-3 * rho0 * s[y1, x1, k] * \
										  average_of_4data(u[y0, x0, k], u[y1, x0, k], u[y0, x1, k], u[y1, x1, k])

	return Data
示例#16
0
def get_data_for_draw_12month_cycle(depthn = 1, product_n = 3, Ekman_or_Geost = 'Ekman', Vector_or_Scalar = 'Scalar'):
	xgrid, ygrid, zgrid = D.get_grid_value('u', product_n)
	if Ekman_or_Geost == 'Ekman':
		fname = 'Ekman'
	elif Ekman_or_Geost == 'Geost':
		fname = 'Geostrophic'
	else:
		raise ValueError("your Ekman_or_Geost argument is not vald!")

	if Vector_or_Scalar == 'Scalar':
		DataDrawN = 0
		Data = np.zeros((12, ygrid.size, xgrid.size))
	elif Vector_or_Scalar == 'Vector':
		DataDrawN = 1
		Data = np.zeros((12, 2, ygrid.size, xgrid.size))
	else:
		raise ValueError("your Vector_or_Scalar argument is not vald!")


	fy = 1990
	ly = 2011


	for i in range(0, 12):
		month = i + 1
		print 'month=', month
		# データの取得
		each_u = np.zeros((ygrid.size, xgrid.size, ly - fy + 1))
		each_v = np.zeros((ygrid.size, xgrid.size, ly - fy + 1))
		for year in range(fy, ly + 1):
			k = year - fy
			tmpu, tmpv = load_data_of_npz(year, month, product_n = product_n, Ekman_or_Geost = Ekman_or_Geost)
			each_u[:, :, k] = tmpu[:, :, depthn - 1]
			each_v[:, :, k] = tmpv[:, :, depthn - 1]

		if Vector_or_Scalar == 'Scalar':
			Data[i, :, :] = np.sqrt(np.average(each_u, axis = 2)**2, np.average(each_v, axis = 2)**2)
		elif Vector_or_Scalar == 'Vector':
			Data_d1 = np.average(each_u, axis = 2)
			Data_d2 = np.average(each_v, axis = 2)
			Data[i, :, :, :] = np.array([Data_d1, Data_d2])
		else:
			raise ValueError("your Vector_or_Scalar argument is not vald!")

	return Data
示例#17
0
	def save_data_as_npz(self, Timeseries, fy, ly, var = 's', depthn = 1, product_n = 3, Rawdata_or_Anomaly = 'Rawdata', fy_of_Anomalydata = 1990, ly_of_Anomalydata = 2011):
		import D
		import subroutine
		import Var
		title_name = D.Data[product_n].title_name
		xgrid, ygrid, zgrid = D.get_grid_value('s', product_n)
		vid = Var.var_to_id(var)
		formal_name = Var.VAR[vid].Get_formal_name()

		if Rawdata_or_Anomaly == 'Rawdata':
			fname_RA = formal_name
		elif Rawdata_or_Anomaly == 'Anomaly':
			fname_RA = '[Anomaly_of_' + formal_name + str(fy_of_Anomalydata) + '-' + str(ly_of_Anomalydata) + ']'
		else:
			raise ValueError('your Rawdata_or_Anomaly argument is not valid!')

		subroutine.save_npz(Timeseries, self.AreaName + '_of_' + fname_RA + '_at_' + str(zgrid[depthn - 1]) + \
							'm_Year' + str(fy) + '-' + str(ly) + '_' + title_name)
示例#18
0
def get_depth_of_minimum_of_vertical_gradient_from_profile(profile, product_n = 3):
	# プロファイルの鉛直勾配が負に最大になる深さを求める。
	# 塩分に関してはアラビア海向け。
	_, _, zgrid = D.get_grid_value('s', product_n)
	zn = zgrid.size
	Grad = np.zeros(zn)
	for k in range(1, zn - 1):
		dz = 0.5 * (zgrid[k + 1] - zgrid[k - 1])
		Grad[k] = (profile[k + 1] - profile[k - 1]) / dz

	Grad[np.where(np.isnan(Grad) == True)] = np.inf
	GradMin = np.min(Grad)

	if GradMin == 0.0:
		Depth_of_GradMin = np.nan
	else:
		K1 = np.where(Grad == GradMin)[0][0]
		Depth_of_GradMin = zgrid[K1]

	return Depth_of_GradMin
示例#19
0
	def Get_data_of_area(self, data, var, product_n):
		# 2次元のデータは勿論、3次元のデータもこの関数を使ってtrimmingできます。
		import D
		import numpy as np
		import convert
		xgrid, ygrid, zgrid = D.get_grid_value('t', product_n)
		if var == 'u' or var == 'v':
			if data.ndim == 3:
				data = convert.convert_UVgrid_value_to_Sgrid_value_3D(data)
			elif data.ndim == 2:
				data = convert.convert_UVgrid_value_to_Sgrid_value_2D(data)

		mx = np.where(xgrid == self.wlon)[0][0]
		nx = np.where(xgrid == self.elon)[0][0] + 1
		my = np.where(ygrid == self.slat)[0][0]
		ny = np.where(ygrid == self.nlat)[0][0] + 1
		data = data[my:ny, mx:nx]
		xgrid = xgrid[mx:nx]
		ygrid = ygrid[my:ny]
		return data, xgrid, ygrid
def get_smoothed_ssh(year, month, product_n = 3):
	ssh = D.get_data(year, month, 'ht', 1, product_n)
	xgrid, ygrid, zgrid = D.get_grid_value('ht', product_n)
	xn = xgrid.size
	yn = ygrid.size
	ssh_new = np.zeros((yn, xn))

	for j in range(0, yn):
		if j == 0 or j == yn - 1:
			ssh_new[j, :] = np.nan
		else:
			y0 = j - 1
			y1 = j
			y2 = j + 1

			for i in range(0, xn):
				x1 = i
				lon1 = xgrid[x1]
				if i == 0:
					x0 = xn - 1
					x2 = i + 1
				elif i == xn - 1:
					x0 = i - 1
					x2 = xn - 1
				else:
					x0 = i - 1
					x2 = i + 1

				ssh01 = ssh[y1, x0]
				ssh10 = ssh[y0, x1]
				ssh11 = ssh[y1, x1]
				ssh21 = ssh[y1, x2]
				ssh12 = ssh[y2, x1]
				if np.isnan(ssh11) == True:
					ssh_new[j, i] = np.nan
				else:
					ssh_around = np.array([ssh01, ssh10, ssh21, ssh12])
					ssh_new[j, i] = 0.5 * (ssh11 + np.average(ssh_around[np.where(np.isnan(ssh_around) == False)]))

	return ssh_new / 100.0
示例#21
0
	def make_Ave_or_Std_of_Data(self, fy, ly, product_n, Ave_or_Std = 'Ave'):
		import D
		import numpy as np
		title_name = D.Data[product_n].title_name
		xgrid, ygrid, zgrid = D.get_grid_value('t', product_n) # tでもuでもよい
		if self.dimension == 2:
			AvSt_of_Data = np.zeros((ygrid.size, xgrid.size, 12))
			for month in range(1, 13):
				each_Data = np.zeros((ygrid.size, xgrid.size, ly - fy + 1))
				for year in range(fy, ly + 1):
					k = year - fy
					each_Data[:, :, k] = self.load_data_of_npz(year, month, product_n)

				if Ave_or_Std == 'Ave':
					AvSt_of_Data[:, :, month - 1] = np.average(each_Data, axis = 2)
				elif Ave_or_Std == 'Std':
					AvSt_of_Data[:, :, month - 1] = np.std(each_Data, axis = 2)
				else:
					raise ValueError('your Ave_or_Std argument is not valid!')

		elif self.dimension == 3:
			AvSt_of_Data = np.zeros((ygrid.size, xgrid.size, zgrid.size, 12))
			for month in range(1, 13):
				each_Data = np.zeros((ygrid.size, xgrid.size, zgrid.size, ly - fy + 1))
				for year in range(fy, ly + 1):
					k = year - fy
					each_Data[:, :, :, k] = self.load_data_of_npz(year, month, product_n)

				if Ave_or_Std == 'Ave':
					AvSt_of_Data[:, :, :, month - 1] = np.average(each_Data, axis = 2)
				elif Ave_or_Std == 'Std':
					AvSt_of_Data[:, :, :, month - 1] = np.std(each_Data, axis = 2)
				else:
					raise ValueError('your Ave_or_Std argument is not valid!')

		else:
			raise ValueError('your dimension is not valid!')


		return AvSt_of_Data
示例#22
0
	def Get_data_of_AreaSection_from_data(self, data, var, product_n):
		# 例えばwlon=10.5, elon=19.5だったとしたら、
		# Data_wは経度10.0度、Data_e=は経度20度に於けるデータを取得することとします。
		import numpy as np
		import D
		import convert
		xgrid, ygrid, zgrid = D.get_grid_value('t', product_n)
		if var == 'u' or var == 'v':
			if data.ndim == 3:
				data = convert.convert_UVgrid_value_to_Sgrid_value_3D(data)
			elif data.ndim == 2:
				data = convert.convert_UVgrid_value_to_Sgrid_value_2D(data)

		mx = np.where(xgrid == self.wlon)[0][0]
		nx = np.where(xgrid == self.elon)[0][0] + 1
		my = np.where(ygrid == self.slat)[0][0]
		ny = np.where(ygrid == self.nlat)[0][0] + 1
		Data_S = 0.5 * (data[my - 1, mx:nx] + data[my, mx:nx])
		Data_N = 0.5 * (data[ny - 1, mx:nx] + data[ny, mx:nx])
		Data_W = 0.5 * (data[my:ny, mx - 1] + data[my:ny, mx])
		Data_E = 0.5 * (data[my:ny, nx - 1] + data[my:ny, nx])
		Data = EACH_SECTION(Data_S, Data_N, Data_W, Data_E)
		return Data
示例#23
0
	def cal_Mass_Budget(self, year, month, depth = 10, product_n = 3):
		# その領域における体積収支を計算する。
		# 注意! x,y,z軸方向のグリッドの大きさはすべて等しいと仮定して計算しております。
		# さらに、領域は南北に長くなく、EWdistで南北両側面の断面積を計算していいこととしております。
		import D
		import D2
		import numpy as np
		u = D.get_data(year, month, 'u', 0, product_n)[:, :, :depth]
		v = D.get_data(year, month, 'v', 0, product_n)[:, :, :depth]
		w = D.get_data(year, month, 'w', depth, product_n)
		ssh = D2.D2Data[33].load_data_of_npz(year, month, product_n)
		ssh_Sec = self.Get_data_of_AreaSection_from_data(ssh, 'ht', product_n)
		_, _, zgrid = D.get_grid_value('w', product_n)
		u = self.Get_data_of_AreaSection_from_data(u, 'u', product_n)
		v = self.Get_data_of_AreaSection_from_data(v, 'v', product_n)
		w, _, _ = self.Get_data_of_area(w, 'w', product_n)

		# 海面力学高度の分だけ、各断面の高さに下駄を履かせてやる
		West = np.average(u.West) * (zgrid[depth - 1] + np.average(ssh_Sec.West)) * self.NSdist
		East = np.average(u.East) * (zgrid[depth - 1] + np.average(ssh_Sec.East)) * self.NSdist
		North = np.average(v.North) * (zgrid[depth - 1] + np.average(ssh_Sec.North)) * self.EWdist
		South = np.average(v.South) * (zgrid[depth - 1] + np.average(ssh_Sec.South)) * self.EWdist
		Bottom = self.Square * np.average(w)
		return South, North, West, East, Bottom