Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
python
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
Container 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
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Tom Rink
python
Commits
5222f8b8
Commit
5222f8b8
authored
4 years ago
by
rink
Browse files
Options
Downloads
Patches
Plain Diff
add press to altitude
parent
2b92b4b4
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
modules/util/util.py
+53
-0
53 additions, 0 deletions
modules/util/util.py
with
53 additions
and
0 deletions
modules/util/util.py
+
53
−
0
View file @
5222f8b8
import
numpy
as
np
from
metpy.units
import
units
from
metpy.calc
import
thickness_hydrostatic
class
MyGenericException
(
Exception
):
def
__init__
(
self
,
message
):
self
.
message
=
message
def
haversine_np
(
lon1
,
lat1
,
lon2
,
lat2
):
...
...
@@ -53,3 +60,49 @@ def get_breaks(t, threshold):
idxs
=
np
.
nonzero
(
d
>
threshold
)
return
idxs
def
pressure_to_altitude
(
pres
,
temp
,
prof_pres
,
prof_temp
,
sfc_pres
,
sfc_temp
,
sfc_elev
):
if
not
np
.
all
(
np
.
diff
(
prof_pres
)
>
0
):
raise
MyGenericException
(
"
target pressure profile must be monotonic increasing
"
)
if
pres
<
prof_pres
[
0
]:
raise
MyGenericException
(
"
target pressure less than top of pressure profile
"
)
if
temp
is
None
:
temp
=
np
.
interp
(
pres
,
prof_pres
,
prof_temp
)
i_top
=
np
.
argmax
(
np
.
extract
(
prof_pres
<=
pres
,
prof_pres
))
+
1
pres_s
=
prof_pres
.
tolist
()
temp_s
=
prof_temp
.
tolist
()
pres_s
=
[
pres
]
+
pres_s
[
i_top
:]
temp_s
=
[
temp
]
+
temp_s
[
i_top
:]
prof_pres
=
np
.
array
(
pres_s
)
prof_temp
=
np
.
array
(
temp_s
)
i_bot
=
prof_pres
.
shape
[
0
]
-
1
if
sfc_pres
>
prof_pres
[
i_bot
]:
pres_s
=
pres_s
+
[
sfc_pres
]
temp_s
=
temp_s
+
[
sfc_temp
]
else
:
idx
=
np
.
argmax
(
np
.
extract
(
prof_pres
<=
sfc_pres
,
prof_pres
))
if
sfc_temp
is
None
:
sfc_temp
=
np
.
interp
(
sfc_pres
,
prof_pres
,
prof_temp
)
pres_s
=
prof_pres
.
tolist
()
temp_s
=
prof_temp
.
tolist
()
pres_s
=
pres_s
[
0
:
idx
]
+
[
sfc_pres
]
temp_s
=
temp_s
[
0
:
idx
]
+
[
sfc_temp
]
prof_pres
=
np
.
array
(
pres_s
)
prof_temp
=
np
.
array
(
temp_s
)
prof_pres
=
prof_pres
*
units
.
hectopascal
prof_temp
=
prof_temp
*
units
.
kelvin
sfc_elev
=
sfc_elev
*
units
.
meter
z
=
thickness_hydrostatic
(
prof_pres
,
prof_temp
)
+
sfc_elev
return
z
\ 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