Skip to content
Snippets Groups Projects
Commit ff73cbbd authored by RODIER Quentin's avatar RODIER Quentin
Browse files

Quentin 28/07/2021: Python LIB, add oblique projection for 2D variables

parent 95d018cf
No related branches found
No related tags found
No related merge requests found
......@@ -67,12 +67,12 @@ def windvec_verti_proj(u, v, level, angle):
return projected_wind
def oblique_proj(var, ni, nj, lvl, i_beg, j_beg, i_end, j_end):
"""Compute an oblique projection of a 3D variable w.r.t. its axes
"""Compute an oblique projection of a variable w.r.t. its axes
Parameters
----------
var : array 3D
the 3D variable to project (e.g. THT)
var : array 3D or 2D
the variable to project (e.g. THT, ZS)
ni : array 1D
1D x-axis of the 3D dimension
......@@ -94,27 +94,37 @@ def oblique_proj(var, ni, nj, lvl, i_beg, j_beg, i_end, j_end):
angle_proj : float
the angle (radian) of the new axe w.r.t the x/ni axes (West-East)
out_var : array 2D
a 2D (z,m) variable projected on the oblique axe
out_var : array 2D or 1D
a 2D (z,m) or 1D (m) variable projected on the oblique axe
axe_m : array 1D
a 1D m new axe (distance from the beggining point)
"""
dist_seg=np.sqrt((i_end-i_beg)**2.0 + (j_end-j_beg)**2.0) # Distance de la section oblique m
out_var = np.zeros((len(lvl),int(dist_seg)+1)) # Initialisation du nouveau champs projeté dans la coupe (z,m)
axe_m = np.zeros(int(dist_seg)+1) #Axe des abscisses qui sera tracé selon la coupe
axe_m_coord = [] #Coordonnées x,y des points qui composent l'axe
axe_m_coord.append( (ni[i_beg],nj[j_beg]) ) #Le premier point est celui donné par l'utilisateur
for m in range(int(dist_seg)): #Discrétisation selon distance de la coupe / int(distance_de_la_coupe)
dist_seg=np.sqrt((i_end-i_beg)**2.0 + (j_end-j_beg)**2.0) # Distance de la section oblique m
if var.ndim ==3:
out_var = np.zeros((len(lvl),int(dist_seg)+1)) # Initialisation du nouveau champs projeté dans la coupe (z,m)
else: # 2D
out_var = np.zeros(int(dist_seg)+1) # Initialisation du nouveau champs projeté dans la coupe (m)
axe_m = np.zeros(int(dist_seg)+1) # Axe des abscisses qui sera tracé selon la coupe
axe_m_coord = [] # Coordonnées x,y des points qui composent l'axe
axe_m_coord.append( (ni[i_beg],nj[j_beg]) ) # Le premier point est celui donné par l'utilisateur
for m in range(int(dist_seg)): # Discrétisation selon distance de la coupe / int(distance_de_la_coupe)
axe_m_coord.append( (axe_m_coord[0][0] + (ni[i_end]-ni[i_beg])/(int(dist_seg))*(m+1),
axe_m_coord[0][1] + (nj[j_end]-nj[j_beg])/(int(dist_seg))*(m+1) ))
axe_m[m+1] = np.sqrt((ni[i_beg]-axe_m_coord[m+1][0])**2 + (nj[j_beg]-axe_m_coord[m+1][1])**2)
for k in range(len(lvl)):
a=RectBivariateSpline(ni, nj,var[k,:,:],kx=1,ky=1) #Interpolation par niveau à l'ordre 1 pour éviter des valeurs négatives de champs strictement > 0
if var.ndim ==3: # 3D variables to project
for k in range(len(lvl)):
a=RectBivariateSpline(ni, nj,var[k,:,:],kx=1,ky=1) # Interpolation par niveau à l'ordre 1 pour éviter des valeurs négatives de champs strictement > 0
for m in range(int(dist_seg)+1):
out_var[k,m] = a.ev(axe_m_coord[m][0],axe_m_coord[m][1]) # La fonction ev de RectBivariate retourne la valeur la plus proche du point considéré
else: # 2D variables to project
a=RectBivariateSpline(ni, nj,var[:,:],kx=1,ky=1)
for m in range(int(dist_seg)+1):
out_var[k,m] = a.ev(axe_m_coord[m][0],axe_m_coord[m][1]) # La fonction ev de RectBivariate retourne la valeur la plus proche du point considéré
out_var[m] = a.ev(axe_m_coord[m][0],axe_m_coord[m][1])
angle_proj = math.acos((ni[i_end]-ni[i_beg])/axe_m[-1])
return angle_proj, out_var, axe_m
......@@ -206,4 +216,4 @@ def comp_altitude2DVar(oneVar3D, orography, ztop, level, n_y, n_x):
else:
for k in range(len(level)):
altitude[k,j,i] = orography[j,i] + level[k]*((ztop-orography[j,i])/ztop)
return altitude, n_x3D, n_y3D
\ No newline at end of file
return altitude, n_x3D, n_y3D
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment