Skip to content

Conversation

@23ccozad
Copy link
Contributor

@23ccozad 23ccozad commented Jun 28, 2021

In response to issue #1153, the PR introduces a new function in the IO module for parsing WPC coded surface bulletins. Provided a path to a file, or a file-like object, the function returns a geopandas GeoDataFrame containing the data from the bulletin. Each row of the dataframe represents a pressure center or frontal boundary. The main use of this function is to provide support for the ability to plot surface analyses with MetPy.

Additionally, this PR includes a small change to open_as_needed() in _tools.py. In order to get some WPC surface bulletins, I was using urllib.request.urlopen("https://www.wpc.ncep.noaa.gov/basicwx/coded_srp.txt"), which returns an HTTPRequest object. open_as_needed() was throwing an error when trying to use seek(0) on that HTTPRequest object. Maybe there is a better solution than adding a try/except, so any additional feedback on that would be great.

Checklist

@23ccozad 23ccozad added this to the 1.1.0 milestone Jun 28, 2021
@23ccozad 23ccozad added Area: IO Pertains to reading data Area: Plots Pertains to producing plots Type: Feature New functionality and removed Area: Plots Pertains to producing plots labels Jun 28, 2021
@23ccozad
Copy link
Contributor Author

How do I add a new text file to our staticdata folder and use get_test_data() to access it from a test function?

I've tried adding my file to staticdata on my local repo, but when trying to use get_test_data(), it looks for the file on the Unidata repo (https://github.com/Unidata/MetPy/raw/main/staticdata/WPC_sfc_fronts_20210628_1800.txt)

@23ccozad
Copy link
Contributor Author

Above issue resolved by recreating the data registry with python -c "import pooch; pooch.make_registry('staticdata', 'src/metpy/static-data-manifest.txt')" after putting the new data file in the staticdata folder.

@23ccozad 23ccozad force-pushed the wpc_fronts branch 3 times, most recently from c0441f0 to 8f057be Compare July 1, 2021 18:59
@dopplershift dopplershift modified the milestones: 1.1.0, 1.2.0 Aug 2, 2021
@dopplershift dopplershift modified the milestones: 1.2.0, 1.3.0 Jan 14, 2022
@dopplershift dopplershift modified the milestones: 1.3.0, May 2022 Mar 31, 2022
@dopplershift dopplershift mentioned this pull request Apr 8, 2022
8 tasks
@dopplershift dopplershift modified the milestones: May 2022, July 2022 May 16, 2022
@dopplershift dopplershift removed this from the October 2022 milestone Oct 18, 2022
from .metar import * # noqa: F403
from .nexrad import * # noqa: F403
from .station_data import * # noqa: F403
from .text import * # noqa: F403

Check notice

Code scanning / CodeQL

'import *' may pollute namespace

Import pollutes the enclosing namespace, as the imported module [metpy.io.text](1) does not define '__all__'.
"""Test parser reading a WPC coded surface bulletin into a geodataframe."""
# Get rows 17 and 47 from dataframe representing parsed text file
# Row 17 is a pressure center and row 47 is front
input_file = get_test_data('WPC_sfc_fronts_20210628_1800.txt')

Check warning

Code scanning / CodeQL

File is not always closed

File is opened but is not closed.
@dopplershift
Copy link
Member

@23ccozad I've taken what you started and pushed it across the finish line, leveraging what's in #2420. Can you mark this as no longer a draft? I'm unable to do so.

@dopplershift dopplershift added this to the April 2023 milestone Mar 31, 2023
@23ccozad 23ccozad marked this pull request as ready for review March 31, 2023 17:53
@23ccozad 23ccozad requested a review from a team as a code owner March 31, 2023 17:53
@23ccozad 23ccozad removed the request for review from a team March 31, 2023 17:53
@23ccozad 23ccozad requested a review from dopplershift March 31, 2023 17:53
@dopplershift dopplershift force-pushed the wpc_fronts branch 2 times, most recently from 1bfb415 to 976556e Compare April 2, 2023 07:38
@dopplershift
Copy link
Member

dopplershift commented Apr 7, 2023

Ok, rebased on #2420 so that we can sensibly plot. One idea I had was to make an example of a simple low pressure system plot using this stuff as a simpler example using the path effects.

EDIT: Simple example done separately in #2997

@dopplershift
Copy link
Member

Hrmm...also one other issue: We're currently optionally depending on Shapely, which is no burden since it comes in with the optional dependency on Cartopy. This would be harder to keep optional here.

@dopplershift dopplershift force-pushed the wpc_fronts branch 2 times, most recently from ce900bf to 7736950 Compare April 7, 2023 21:59
Copy link
Member

@dcamron dcamron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really like how this is done, thanks y'all. Just some doc and testing thoughts, mostly.

@dopplershift
Copy link
Member

@dcamron any thoughts on what to do with Shapely (e.g. depending on it or jumping through hoops)?

@dcamron
Copy link
Member

dcamron commented Apr 11, 2023

Hmmm... Would it be more difficult than the cartopy machinery you've already put in place? Not to totally rebuild WPC parsing to be able to work without Shapely, but to just have it fail on run instead of import without it.

I think realistically it would affect very few people negatively to fully depend on Shapely. It does feel a little conceptually gross if we've already done similar work to help out those very few people, and Shapely does feel ever so slightly heavier to jam into all of metpy.io than say Pandas.

@dopplershift
Copy link
Member

We could import Shapely inside the wpc parsing function since it's only used there. That seems pretty limited. We'd need to add some machinery to require shapely for the tests, which isn't scary. I'd say that's the way to go.

23ccozad and others added 6 commits April 17, 2023 15:11
This requires a year value potentially to be provided, though we try to
look for one in the product header.
Users can easily convert to a GeoDataFrame if they need that
functionality, but the DataFrame is already a dependency and is
sufficient for our needs.
@dopplershift dopplershift force-pushed the wpc_fronts branch 2 times, most recently from c282ceb to 89ef972 Compare April 17, 2023 20:33
This avoids an import-time failure for MetPy if Shapely isn't installed.
# Row 17 is a pressure center and row 47 is front
import shapely.geometry as sgeom

input_file = get_test_data('WPC_sfc_fronts_lowres_20210628_1800.txt')

Check warning

Code scanning / CodeQL

File is not always closed

File is opened but is not closed.
As opposed to the "high res" product.
Copy link
Member

@dcamron dcamron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, I think this is good to go in!

@dcamron dcamron merged commit 0fcfd64 into Unidata:main Apr 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: IO Pertains to reading data Type: Feature New functionality

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

WPC Frontal Analysis

3 participants