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
def save_Area_Trimmed_variable_as_npz(self, year, month, var, product_n): import Var import D id = Var.var_to_id(var) VV = Var.VAR[id] if VV.dim == '3D': data = D.get_data(year, month, var, 0, product_n) elif VV.dim == '2D': data = D.get_data(year, month, var, 1, product_n) else: raise ValueError('your var is not valid!') Data, _, _ = self.Get_data_of_area(data, var, product_n) self.save_Area_Trimmed_data_as_npz(Data, year, month, VV.dir_name, VV.formal_name, product_n)
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
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
def get_UgVg_from_RawSSH(year, month, product_n = 3): product_n = 3 ht = get_smoothed_ssh(year, month, product_n) Ug, Vg, xgrid, ygrid = cal_GeostrophicCurrent_from_SSH(ht) # いらない部分の数字は欠損値ということで u = D.get_data(year, month, 'u', 1, product_n) Ug[np.where(np.isnan(u) == True)] = np.nan Vg[np.where(np.isnan(u) == True)] = np.nan return Ug, Vg, xgrid, ygrid
def timeseries_of_area_averaged_value(self, fy, ly, var, depth, product_n = 3): import numpy as np import D import subroutine Yn = ly - fy + 1 Timeseries = np.zeros(12 * Yn) months, label = subroutine.get_months_and_label(fy, ly) for year in range(fy, ly + 1): for month in range(1, 13): i = month - 1 + (year - fy) * 12 Data = D.get_data(year, month, var, depth, product_n) tmp, _, _ = self.Get_data_of_area(Data, var, product_n) Timeseries[i] = np.average(tmp[np.where(np.isnan(tmp) == False)]) return Timeseries, months, label
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
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 cal_UVg_from_UV_and_UVe(year, month, product_n, U_or_V_and_nu): if U_or_V_and_nu == 'U_5e-3': D2id = 23 var = 'u' elif U_or_V_and_nu == 'V_5e-3': D2id = 24 var = 'v' elif U_or_V_and_nu == 'U_1e-2': D2id = 29 var = 'u' elif U_or_V_and_nu == 'V_1e-2': D2id = 30 var = 'v' else: raise ValueError('your U_or_V argument is not valid!') D2D = D2.D2Data[D2id] Ue = D2D.load_data_of_npz(year, month, product_n) U = D.get_data(year, month, var, 0, product_n) Ug = U - Ue return Ug
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
def get_depth_of_minimum_of_vertical_gradient(year, month, var, product_n = 3): data = D.get_data(year, month, var, 0, product_n) Depth_of_GradMax = get_depth_of_minimum_of_vertical_gradient_from_data(data, var, product_n = product_n) return Depth_of_GradMax
def get_MeridionalGradient_of_variable(year, month, var, product_n = 3): data = D.get_data(year, month, var, 0, product_n) _, Data = get_Gradient_of_variable_from_data(data, var, product_n = product_n) return Data
def Get_VerticalSection(self, year, month, var, product_n): import D data = D.get_data(year, month, var, 0, product_n) Data, hgrid, zgrid = self.Get_VerticalSection_from_data(data, var, product_n) return Data, hgrid, zgrid
def Get_Current_of_VerticalSection(self, year, month, product_n): import D u = D.get_data(year, month, 'u', 0, product_n) v = D.get_data(year, month, 'v', 0, product_n) Data, hgrid, zgrid = self.Get_Current_of_VerticalSection_from_UV(u, v, product_n) return Data, hgrid, zgrid
def make_100m_Averaged_Variable(year, month, var, product_n = 3): data = D.get_data(year, month, var, 0, product_n) return np.average(data[:, :, :10], axis = 2)
def make_MLD_dt02_Averaged_Variable(year, month, var, product_n = 3): data = D.get_data(year, month, var, 0, product_n) MLD = D2.D2Data[7].load_data_of_npz(year, month, product_n) Data = make_LD_Averaged_Data(data, MLD, product_n = product_n) return Data