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

Exception handling needed in _get_data method of WyomingUpperAir for missing or erroneous metadata #751

Open
nerojia opened this issue Dec 2, 2023 · 2 comments

Comments

@nerojia
Copy link

nerojia commented Dec 2, 2023

Body:

Hello,

I encountered an issue while using the WyomingUpperAir class to download and parse upper air observations, specifically when dealing with data from certain stations that have missing or erroneous metadata.

For example, the entire 2022 data for station 95282 has missing or incorrect values for Station latitude , Station elevation and Station longitute. The current implementation of the _get_data method does not handle these cases well, leading to a ValueError when it tries to parse these fields into floats.

Here is a sample traceback:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: could not convert string to float: '******'

This issue could be resolved by adding exception handling to the float conversion process. Here's a proposed solution:

# Safe parsing of float values
def safe_float(value):
    try:
        return float(value)
    except ValueError:
        return np.nan

latitude = safe_float(lines[4].split(':')[1].strip())
longitude = safe_float(lines[5].split(':')[1].strip())
elevation = safe_float(lines[6].split(':')[1].strip())
pw = safe_float(lines[-1].split(':')[1].strip())

In this solution, a helper function safe_float is used to attempt the float conversion, and if it fails, np.nan is returned instead. This prevents a ValueError from being raised and allows the function to complete successfully, even if some metadata fields cannot be converted to floats.

This issue is particularly important because it affects the usability of the library for any station with missing or erroneous metadata, not just station 95282.

I hope this information is helpful and look forward to your feedback.

Best regards,
Nero Jia

@tkschuler
Copy link

Duplicate of #749

@nerojia
Copy link
Author

nerojia commented Dec 5, 2023

Duplicate of #749

Thank you for your response! I understand, and I appreciate it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants