-
Notifications
You must be signed in to change notification settings - Fork 416
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Find peaks #3729
Merged
Merged
Find peaks #3729
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
2f1d1d5
ENH: Add function to identify peaks
dopplershift 316ebf8
ENH: Make scattertext() a public API
dopplershift eea0ecf
ENH: Allow passing a scalar text value to scattertext()
dopplershift 393da7c
ENH: Add formatter support to scattertext()
dopplershift 041a077
DOC: Switch example to use scattertext
dopplershift 03cf123
DOC: Add example using high/low identification
dopplershift c1256a5
DOC: Mark GEMPAK HIGH/LOW as implemented
dopplershift File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# Copyright (c) 2025 MetPy Developers. | ||
# Distributed under the terms of the BSD 3-Clause License. | ||
# SPDX-License-Identifier: BSD-3-Clause | ||
""" | ||
================= | ||
High/Low Analysis | ||
================= | ||
|
||
This uses MetPy's `find_peaks` function to automatically identify locations of high and low | ||
centers, and then plots them on a map. | ||
""" | ||
|
||
import cartopy.crs as ccrs | ||
import cartopy.feature as cfeature | ||
import matplotlib.pyplot as plt | ||
import xarray as xr | ||
|
||
from metpy.calc import find_peaks | ||
from metpy.cbook import get_test_data | ||
from metpy.plots import add_metpy_logo, scattertext | ||
from metpy.units import units | ||
|
||
########################################### | ||
# Start by loading some data from our sample GFS model dataset. Pull out the geopotential | ||
# heights field for the 850 hPa layer, as well as grab the projection metadata. | ||
data = xr.open_dataset(get_test_data('GFS_test.nc', as_file_obj=False)).metpy.parse_cf() | ||
mslp = data.Geopotential_height_isobaric.metpy.sel(vertical=850 * units.hPa).squeeze() | ||
dataproj = mslp.metpy.cartopy_crs | ||
|
||
|
||
########################################### | ||
# Here we use `find_peaks` to find the locations of the highs and then the lows | ||
h_y, h_x = find_peaks(mslp.values) | ||
l_y, l_x = find_peaks(mslp.values, maxima=False) | ||
|
||
########################################### | ||
# Plot the analyzed locations on top of the contours of height on a map | ||
fig = plt.figure(figsize=(11., 8.)) | ||
ax = fig.add_subplot(1, 1, 1, projection=ccrs.LambertConformal(central_longitude=-95)) | ||
ax.contour(mslp.metpy.x, mslp.metpy.y, mslp, range(0, 2000, 30), | ||
colors='k', linewidths=1.25, linestyles='solid', transform=dataproj) | ||
|
||
# Using scattertext() plot the high centers using a red 'H' and put the height value | ||
# below the 'H' using a smaller font. | ||
scattertext(ax, mslp.metpy.x[h_x], mslp.metpy.y[h_y], 'H', size=20, color='red', | ||
fontweight='bold', transform=dataproj) | ||
scattertext(ax, mslp.metpy.x[h_x], mslp.metpy.y[h_y], mslp.values[h_y, h_x], formatter='.0f', | ||
size=12, color='red', loc=(0, -15), fontweight='bold', transform=dataproj) | ||
|
||
# Now do the same for the lows using a blue 'L' | ||
scattertext(ax, mslp.metpy.x[l_x], mslp.metpy.y[l_y], 'L', size=20, color='blue', | ||
fontweight='bold', transform=dataproj) | ||
scattertext(ax, mslp.metpy.x[l_x], mslp.metpy.y[l_y], mslp.values[l_y, l_x], formatter='.0f', | ||
size=12, color='blue', loc=(0, -15), fontweight='bold', transform=dataproj) | ||
|
||
ax.add_feature(cfeature.OCEAN) | ||
ax.add_feature(cfeature.LAND) | ||
ax.add_feature(cfeature.COASTLINE) | ||
|
||
ax.set_title('Automated 850hPa High and Low Locations') | ||
add_metpy_logo(fig, 275, 295, size='large') | ||
plt.show() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check notice
Code scanning / CodeQL
'import *' may pollute namespace Note