Skip to content
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

Fix truncated text and decode SPCL obs #2658

Merged
merged 2 commits into from
Sep 12, 2022
Merged

Conversation

nawendt
Copy link
Contributor

@nawendt nawendt commented Sep 10, 2022

This should fix the text truncation that was happening with surface and sounding data. The correct number of bytes are now read.

Additionally, I added functionality for surface data files that will decode the METAR text of SPECI (non-hourly) reports. This takes the metpy METAR parser and outputs as much data as possible into a JSON. I did conversions on certain parameters so that the output would be like GEMPAK would produces. The metpy parser does not fully decode the METAR, but it will get the most important information at least.

I also structured the method and output so that the special observations would be included when searching for the nearest time. The only question I had is whether there should be a user option for not decoding the special observations.

Text within GEMPAK files should no longer be truncated as the correct
number of bytes are now read. This affected surface and sounding files.

SPCL (non-hourly) surface observations were orginally only stored as
text. Methods were added to decode them in to JSON along with the hourly
observations. The `nearest_time` method now should be able to select
the closest match from both hourly and non-hourly observations.

Fixes Unidata#2112
@nawendt nawendt requested a review from a team as a code owner September 10, 2022 17:29
@nawendt nawendt requested review from dcamron and removed request for a team September 10, 2022 17:29
def test_surface_text(text_type, date_time):
"""Test text decoding of surface hourly and special observations."""
g = get_test_data('gem_surface_with_text.sfc')
d = get_test_data('gem_surface_with_text.csv')

Check warning

Code scanning / CodeQL

File is not always closed

File is opened but is not closed.
@pytest.mark.parametrize('text_type', ['txta', 'txtb', 'txtc', 'txpb'])
def test_sounding_text(text_type):
"""Test for proper decoding of coded message text."""
g = get_test_data('gem_unmerged_with_text.snd')

Check warning

Code scanning / CodeQL

File is not always closed

File may not be closed if an exception is raised.
def test_sounding_text(text_type):
"""Test for proper decoding of coded message text."""
g = get_test_data('gem_unmerged_with_text.snd')
d = get_test_data('gem_unmerged_with_text.csv')

Check warning

Code scanning / CodeQL

File is not always closed

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

Is there a way in the output to determine which reports are the SPECI? It seems fine to me to just decide everything and allow the user to drop as desired.

@nawendt
Copy link
Contributor Author

nawendt commented Sep 10, 2022

Yes. Within the JSON output, the METAR text is stored with the text key for the hourly data and with the spcl key for the non-hourly data (as is done in GEMPAK). The user should be able to filter based on the presence of that key.

dopplershift
dopplershift previously approved these changes Sep 12, 2022
Copy link
Member

@dopplershift dopplershift left a comment

Choose a reason for hiding this comment

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

Looks good. Just a minor tweak necessary to make codespell happy and this can go in.

src/metpy/io/gempak.py Show resolved Hide resolved
src/metpy/io/gempak.py Show resolved Hide resolved
@dopplershift dopplershift added Type: Bug Something is not working like it should Area: IO Pertains to reading data labels Sep 12, 2022
@dopplershift dopplershift added this to the September 2022 milestone Sep 12, 2022
@dopplershift dopplershift merged commit 6ea76d3 into Unidata:main Sep 12, 2022
@nawendt nawendt deleted the fix-2112 branch September 16, 2022 04:18
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: Bug Something is not working like it should
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Text data not fully decoded for GEMPAK surface and sounding files
2 participants