Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Méso-NH code
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Méso-NH
Méso-NH code
Commits
ff73cbbd
Commit
ff73cbbd
authored
3 years ago
by
RODIER Quentin
Browse files
Options
Downloads
Patches
Plain Diff
Quentin 28/07/2021: Python LIB, add oblique projection for 2D variables
parent
95d018cf
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/LIB/Python/misc_functions.py
+26
-16
26 additions, 16 deletions
src/LIB/Python/misc_functions.py
with
26 additions
and
16 deletions
src/LIB/Python/misc_functions.py
+
26
−
16
View file @
ff73cbbd
...
@@ -67,12 +67,12 @@ def windvec_verti_proj(u, v, level, angle):
...
@@ -67,12 +67,12 @@ def windvec_verti_proj(u, v, level, 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
3D
variable w.r.t. its axes
"""
Compute an oblique projection of a variable w.r.t. its axes
Parameters
Parameters
----------
----------
var : array 3D
var : array 3D
or 2D
the
3D
variable to project (e.g. THT)
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
...
@@ -94,27 +94,37 @@ def oblique_proj(var, ni, nj, lvl, i_beg, j_beg, i_end, j_end):
...
@@ -94,27 +94,37 @@ def oblique_proj(var, ni, nj, lvl, i_beg, j_beg, i_end, j_end):
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
out_var : array 2D
or 1D
a 2D (z,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
out_var
=
np
.
zeros
((
len
(
lvl
),
int
(
dist_seg
)
+
1
))
# Initialisation du nouveau champs projeté dans la coupe (z,m)
if
var
.
ndim
==
3
:
axe_m
=
np
.
zeros
(
int
(
dist_seg
)
+
1
)
#Axe des abscisses qui sera tracé selon la coupe
out_var
=
np
.
zeros
((
len
(
lvl
),
int
(
dist_seg
)
+
1
))
# Initialisation du nouveau champs projeté dans la coupe (z,m)
axe_m_coord
=
[]
#Coordonnées x,y des points qui composent l'axe
else
:
# 2D
axe_m_coord
.
append
(
(
ni
[
i_beg
],
nj
[
j_beg
])
)
#Le premier point est celui donné par l'utilisateur
out_var
=
np
.
zeros
(
int
(
dist_seg
)
+
1
)
# Initialisation du nouveau champs projeté dans la coupe (m)
for
m
in
range
(
int
(
dist_seg
)):
#Discrétisation selon distance de la coupe / int(distance_de_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
.
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
.
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
)
for
k
in
range
(
len
(
lvl
)):
if
var
.
ndim
==
3
:
# 3D variables to project
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
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
):
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
])
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
...
@@ -206,4 +216,4 @@ def comp_altitude2DVar(oneVar3D, orography, ztop, level, n_y, n_x):
...
@@ -206,4 +216,4 @@ def comp_altitude2DVar(oneVar3D, orography, ztop, level, n_y, n_x):
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
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment