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

Quentin 08/06/2022: update Lib Python to MNHPy=0.2.0, list of changes :

- Quentin 28/03/2022: bugfix orography should work with Lxx 2D or 1D
- Quentin 29/03/2022: bugfixes on ticks labelsize +
- bugfix : xyTicksLabelSize now applied with cartopy projection
- bugfix : cbTicksLabelSize now applied correctly on colorbar
- add vectors legendSize
- add Lcbformatlabel for psectionV
- Quentin 06/04/2022: possibility to read non-mesonh netcdf File
- Quentin 06/04/2022: bugfix miss-use nj/ni dimensions in RectBivariateSpline functions with respect to commonly MesoNH variables ordered by z/y/x arrays
- Quentin 02/05/2022: oblique_proj bugfix for domain size not squared and nj> ni : RectBivariateSpline must have
args strictly in ascending order. Works for 2D and 3D variables oblique projection
- Quentin 06/05/2022: bugfix x/y ticks labels not hidden with cartopy > 0.18
- Quentin 12/05/2022: add possibility to use multiple paths for reading files
- Quentin 12/05/2022: add position of legend for pXY_lines and pXY_bar : LlocLegend
- Quentin 12/05/2022: add Panel title vertical position : bigtitlepad
- Quentin 12/05/2022: possibility to read netcdf MNH files without 'time' variable (such as PGD files)
- Quentin + Tanguy: 01/06/2022: autopep8 except main init of args of Panel_Plot
- Quentin 01/06/2022: add Linewidth for contours
- Olivier C. 01/06/2022: oblique_proj bugfix : inversion of coordinates in ev functions of RectBivariateSpline as variables are in y/x order for nj/ni coordinates
- Quentin 02/06/2022: bugfix gridlines with cartopy>0.18
- Quentin 08/06/2022: minor, apply Llinewidth to contour only (not contourf)
parent 93ed9801
No related branches found
No related tags found
No related merge requests found
This diff is collapsed.
...@@ -13,207 +13,214 @@ from scipy.interpolate import RectBivariateSpline ...@@ -13,207 +13,214 @@ from scipy.interpolate import RectBivariateSpline
import numpy as np import numpy as np
import math import math
def convert_date(datesince, time_in_sec): def convert_date(datesince, time_in_sec):
return str(time_in_sec) + datesince[:33] return str(time_in_sec) + datesince[:33]
class mean_operator(): class mean_operator():
def MYM(self,var): def MYM(self, var):
ny = var.shape[1] ny = var.shape[1]
out = copy.deepcopy(var) out = copy.deepcopy(var)
for j in range(ny-1): for j in range(ny - 1):
out[:,j,:] = (var[:,j,:] + var[:,j+1,:])*0.5 out[:, j, :] = (var[:, j, :] + var[:, j + 1, :]) * 0.5
return out return out
def MXM(self,var): def MXM(self, var):
nx = var.shape[2] nx = var.shape[2]
out = copy.deepcopy(var) out = copy.deepcopy(var)
for i in range(nx-1): for i in range(nx - 1):
out[:,:,i] = (var[:,:,i] + var[:,:,i+1])*0.5 out[:, :, i] = (var[:, :, i] + var[:, :, i + 1]) * 0.5
return out return out
def MZM(self,var): def MZM(self, var):
nz = var.shape[0] nz = var.shape[0]
out = copy.deepcopy(var) out = copy.deepcopy(var)
for k in range(nz-1): for k in range(nz - 1):
out[k,:,:] = (var[k,:,:] + var[k+1,:,:])*0.5 out[k, :, :] = (var[k, :, :] + var[k + 1, :, :]) * 0.5
return out return out
def windvec_verti_proj(u, v, level, angle): def windvec_verti_proj(u, v, level, angle):
"""Compute the projected horizontal wind vector on an axis with a given angle w.r.t. the x/ni axes (West-East) """Compute the projected horizontal wind vector on an axis with a given angle w.r.t. the x/ni axes (West-East)
Parameters Parameters
---------- ----------
u : array 3D u : array 3D
U-wind component U-wind component
v : array 3D v : array 3D
V-wind component V-wind component
level : array 1D level : array 1D
level dimension array level dimension array
angle : float angle : float
angle (radian) of the new axe w.r.t the x/ni axes (West-East). angle = 0 for (z,x) sections, angle=pi/2 for (z,y) sections angle (radian) of the new axe w.r.t the x/ni axes (West-East). angle = 0 for (z,x) sections, angle=pi/2 for (z,y) sections
Returns Returns
------- -------
projected_wind : array 3D projected_wind : array 3D
a 3D wind component projected on the axe to be used with Panel_Plot.pvector as Lvar1 a 3D wind component projected on the axe to be used with Panel_Plot.pvector as Lvar1
""" """
projected_wind = copy.deepcopy(u) projected_wind = copy.deepcopy(u)
for k in range(len(level)): for k in range(len(level)):
projected_wind[k,:,:] = u[k,:,:]*math.cos(angle) + v[k,:,:]*math.sin(angle) projected_wind[k, :, :] = u[k, :, :] * math.cos(angle) + v[k, :, :] * math.sin(angle)
return projected_wind return projected_wind
def oblique_proj(var, ni, nj, lvl, i_beg, j_beg, i_end, j_end): def oblique_proj(var, ni, nj, lvl, i_beg, j_beg, i_end, j_end):
"""Compute an oblique projection of a variable w.r.t. its axes """Compute an oblique projection of a variable w.r.t. its axes
Parameters Parameters
---------- ----------
var : array 3D or 2D var : array 3D or 2D
the variable to project (e.g. THT, ZS) the variable to project (e.g. THT, ZS)
ni : array 1D ni : array 1D
1D x-axis of the 3D dimension 1D x-axis of the 3D dimension
nj : array 1D nj : array 1D
1D y-axis of the 3D dimension 1D y-axis of the 3D dimension
level : array 1D level : array 1D
1D z-axe of the 3D dimension 1D z-axe of the 3D dimension
i_beg, j_beg : int i_beg, j_beg : int
coordinate of the begin point of the new axe coordinate of the begin point of the new axe
i_end, j_end : int i_end, j_end : int
coordinate of the end point of the new axe coordinate of the end point of the new axe
Returns Returns
------- -------
angle_proj : float angle_proj : float
the angle (radian) of the new axe w.r.t the x/ni axes (West-East) the angle (radian) of the new axe w.r.t the x/ni axes (West-East)
out_var : array 2D or 1D out_var : array 2D or 1D
a 2D (z,m) or 1D (m) variable projected on the oblique axe a 2D (z,m) or 1D (m) variable projected on the oblique axe
axe_m : array 1D axe_m : array 1D
a 1D m new axe (distance from the beggining point) 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 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: if var.ndim == 3:
out_var = np.zeros((len(lvl),int(dist_seg)+1)) # Initialisation du nouveau champs projeté dans la coupe (z,m) out_var = np.zeros((len(lvl), int(dist_seg) + 1)) # Initialisation du nouveau champs projeté dans la coupe (z,m)
else: # 2D else: # 2D
out_var = np.zeros(int(dist_seg)+1) # Initialisation du nouveau champs projeté dans la coupe (m) 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 = 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 = [] # 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 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) 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.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_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) 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)
if var.ndim ==3: # 3D variables to project if var.ndim == 3: # 3D variables to project
for k in range(len(lvl)): 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 a = RectBivariateSpline(nj, ni, var[k, :, :], kx=1, ky=1)
for m in range(int(dist_seg)+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é # La fonction ev de RectBivariate retourne la valeur la plus proche du point considéré
out_var[k, m] = a.ev(axe_m_coord[m][1], axe_m_coord[m][0])
else: # 2D variables to project else: # 2D variables to project
a=RectBivariateSpline(ni, nj,var[:,:],kx=1,ky=1) a = RectBivariateSpline(nj, ni, var[:, :], kx=1, ky=1)
for m in range(int(dist_seg)+1): for m in range(int(dist_seg) + 1):
out_var[m] = a.ev(axe_m_coord[m][0],axe_m_coord[m][1]) out_var[m] = a.ev(axe_m_coord[m][1], axe_m_coord[m][0])
angle_proj = math.acos((ni[i_end]-ni[i_beg])/axe_m[-1]) angle_proj = math.acos((ni[i_end] - ni[i_beg]) / axe_m[-1])
return angle_proj, out_var, axe_m return angle_proj, out_var, axe_m
def comp_altitude1DVar(oneVar2D, orography, ztop, level, n_xory): def comp_altitude1DVar(oneVar2D, orography, ztop, level, n_xory):
"""Compute and returns an altitude and x or y grid mesh variable in 2D following the topography in 1D """Compute and returns an altitude and x or y grid mesh variable in 2D following the topography in 1D
To be used with 2D simulations To be used with 2D simulations
Parameters Parameters
---------- ----------
oneVar2D : array 2D oneVar2D : array 2D
a 2D array (e.g. UT, THT) a 2D array (e.g. UT, THT)
orography : array 1D orography : array 1D
1D orography (ZS) 1D orography (ZS)
ztop : real ztop : real
scalar of the top height of the model (ZTOP) scalar of the top height of the model (ZTOP)
level : array 1D level : array 1D
1D level variable (level or level_w) 1D level variable (level or level_w)
n_xory : array 1D n_xory : array 1D
1D directionnal grid variable (ni_u, nj_u, ni_v or nj_v) 1D directionnal grid variable (ni_u, nj_u, ni_v or nj_v)
Returns Returns
------- -------
altitude altitude
a 2D altitude variable with topography taken into account a 2D altitude variable with topography taken into account
n_xory_2D n_xory_2D
a 2D directionnal variable duplicated from n_xory a 2D directionnal variable duplicated from n_xory
""" """
n_xory_2D = copy.deepcopy(oneVar2D) n_xory_2D = copy.deepcopy(oneVar2D)
altitude = copy.deepcopy(oneVar2D) altitude = copy.deepcopy(oneVar2D)
for k in range(len(level)): for k in range(len(level)):
n_xory_2D[k,:] = n_xory n_xory_2D[k, :] = n_xory
for j in range(len(n_xory)): for j in range(len(n_xory)):
for k in range(len(level)): for k in range(len(level)):
altitude[k,j] = orography[j] + level[k]*((ztop-orography[j])/ztop) altitude[k, j] = orography[j] + level[k] * ((ztop - orography[j]) / ztop)
return altitude, n_xory_2D return altitude, n_xory_2D
def comp_altitude2DVar(oneVar3D, orography, ztop, level, n_y, n_x): def comp_altitude2DVar(oneVar3D, orography, ztop, level, n_y, n_x):
"""Compute and returns an altitude and x or y grid mesh variable in 3D following the topography in 2D """Compute and returns an altitude and x or y grid mesh variable in 3D following the topography in 2D
To be used with 3D simulations To be used with 3D simulations
Parameters Parameters
---------- ----------
oneVar3D : array 3D oneVar3D : array 3D
a 3D array (e.g. UT, THT) a 3D array (e.g. UT, THT)
orography : array 2D orography : array 2D
2D orography (ZS) 2D orography (ZS)
ztop : real ztop : real
scalar of the top height of the model (ZTOP) scalar of the top height of the model (ZTOP)
level : array 1D level : array 1D
1D level variable (level or level_w) 1D level variable (level or level_w)
n_x : array 1D n_x : array 1D
1D directionnal grid variable along i (ni_u, or ni_v) 1D directionnal grid variable along i (ni_u, or ni_v)
n_y : array 1D n_y : array 1D
1D directionnal grid variable along j (nj_u, or nj_v) 1D directionnal grid variable along j (nj_u, or nj_v)
Returns Returns
------- -------
altitude altitude
a 3D altitude variable with topography taken into account a 3D altitude variable with topography taken into account
n_x3D n_x3D
a 3D directionnal variable duplicated from n_x a 3D directionnal variable duplicated from n_x
n_y3D n_y3D
a 3D directionnal variable duplicated from n_y a 3D directionnal variable duplicated from n_y
""" """
n_x3D = copy.deepcopy(oneVar3D) n_x3D = copy.deepcopy(oneVar3D)
n_y3D = copy.deepcopy(oneVar3D) n_y3D = copy.deepcopy(oneVar3D)
altitude = copy.deepcopy(oneVar3D) altitude = copy.deepcopy(oneVar3D)
for i in range(len(level)): for i in range(len(level)):
n_y3D[i,:] = n_y n_y3D[i, :] = n_y
n_x3D[i,:] = n_x n_x3D[i, :] = n_x
for i in range(oneVar3D.shape[2]): for i in range(oneVar3D.shape[2]):
for j in range(oneVar3D.shape[1]): for j in range(oneVar3D.shape[1]):
if ztop==0: if ztop == 0:
altitude[:,i,j] = level[:] altitude[:, i, j] = level[:]
else: else:
for k in range(len(level)): for k in range(len(level)):
altitude[k,j,i] = orography[j,i] + level[k]*((ztop-orography[j,i])/ztop) altitude[k, j, i] = orography[j, i] + level[k] * ((ztop - orography[j, i]) / ztop)
return altitude, n_x3D, n_y3D return altitude, n_x3D, n_y3D
This diff is collapsed.
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