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

NOAA data request #223

Closed
jmcvey3 opened this issue Feb 14, 2023 · 0 comments
Closed

NOAA data request #223

jmcvey3 opened this issue Feb 14, 2023 · 0 comments
Assignees

Comments

@jmcvey3
Copy link
Contributor

jmcvey3 commented Feb 14, 2023

Describe the bug:

Two bugs in mhkit.tidal.io.noaa.request_noaa_data :

  1. Imprecise error handling on line 139, where this error line appears to be bypassed. It would be useful to raise an Exception instead of a print statement, and pass-through the exact error to the user:
Data request URL:  https://tidesandcurrents.noaa.gov/api/datagetter?begin_date=20171113&end_date=20171118&station=9446484&product=water_level&units=metric&time_zone=gmt&application=web_services&format=xml
Traceback (most recent call last):

  File "C:\Users\mcve343\Anaconda3\lib\site-packages\spyder_kernels\py3compat.py", line 356, in compat_exec
    exec(code, globals, locals)

  File "c:\users\mcve343\onedrive - pnnl\documents\projects\mhkit-dolfyn\coops request issue.py", line 3, in <module>
    noaa.request_noaa_data('9446484', 'water_level', '20171113', '20171118')

  File "c:\users\mcve343\mhkit-python\mhkit\tidal\io\noaa.py", line 76, in request_noaa_data
    dataFrames[date_list[i]], metadata = _xml_to_dataframe(response)

  File "c:\users\mcve343\mhkit-python\mhkit\tidal\io\noaa.py", line 144, in _xml_to_dataframe
    df = pd.DataFrame(data[0].attrib, index=[0])

UnboundLocalError: local variable 'data' referenced before assignment
  1. This function can't handle (i.e. throws the above error) all of the keywords in https://api.tidesandcurrents.noaa.gov/api/prod/, where parameters like "water_level", "water_temperature", and "salinity" could all be useful.

To Reproduce:

This particular request is asking for water level data from the water level station in Tacoma, WA.

from mhkit.tidal.io import noaa

noaa.request_noaa_data('9446484', 'water_level', '20171113', '20171118')

Entering the "Data Request URL" from the error message into a web browser reveals the error code:
<error> Wrong Datum: Datum cannot be null or empty ***station=9446484</error>

Adding &datum=MLLW to the end of the url ("Mean Low Low Water" is the standard datum for all tide height measurements) returns the expected response, a clip of which is pasted below:

<data>
  <metadata id="9446484" name="Tacoma" lat="47.2667" lon="-122.4133"/>
    <observations>
    <wl t="2017-11-13 00:00" v="2.551" s="0.022" f="0,0,0,0" q="v"/>
    <wl t="2017-11-13 00:06" v="2.486" s="0.023" f="0,0,0,0" q="v"/>
    <wl t="2017-11-13 00:12" v="2.423" s="0.025" f="0,0,0,0" q="v"/>

Expected behavior:

Pass through the exact error from the website to the user, as well as add the ability to run a number of keywords from the data request website.

Desktop (please complete the following information):

  • OS: windows 10
  • MHKiT Version: 0.6.0

Additional context:

It would also be helpful to update the docstring to include a list of all the metocean variables that the function can call, as well as any extra required parameters those variables require (e.g. - 'water_level' (required args: "datum")

@ssolson ssolson self-assigned this May 11, 2023
ssolson pushed a commit that referenced this issue Jul 15, 2024
@jmcvey3 jmcvey3 closed this as completed Jul 22, 2024
@ssolson ssolson mentioned this issue Aug 12, 2024
ssolson pushed a commit that referenced this issue Aug 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants