Make WPC parser more fault tolerant#3922
Draft
dopplershift wants to merge 1 commit intoUnidata:mainfrom
Draft
Conversation
When parsing a part of the file fails, allow parsing to continue with the remaining parts.
35bd9f1 to
75eecf2
Compare
Contributor
|
FWIW, a 2000 example resulting in an |
Contributor
|
More FWIW, I have ~7_000 CODSUS products for 2024 and just one fails with current Metpy main branch :) And here's a script to run them in bulk import sys
import traceback
from io import BytesIO
import httpx
from metpy.io import parse_wpc_surface_bulletin
from tqdm import tqdm
def main(argv):
"""Go Main Go."""
year = int(argv[1])
resp = httpx.get(
"https://mesonet.agron.iastate.edu/cgi-bin/afos/retrieve.py?"
f"sdate={year}-01-01&edate={year + 1}-01-01&limit=9999"
"&pil=CODSUS&fmt=text",
timeout=60,
)
failure = 0
progress = tqdm(resp.content.split(b"\003"))
for prod in progress:
progress.set_description(f"Failures: {failure}")
bio = BytesIO(prod)
try:
parse_wpc_surface_bulletin(bio, year=year)
except Exception:
traceback.print_exc()
with open(f"CODSUS_fail_{failure:04.0f}.txt", "wb") as fh:
fh.write(prod)
failure += 1
if __name__ == "__main__":
main(sys.argv) |
Member
Author
|
Thanks @akrherz ! That's really helpful and we can definitely include a few more fixes here. |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description Of Changes
When parsing a part of the file fails, allow parsing to continue with the remaining parts.
Checklist