MHKiT-Python provides the marine renewable energy (MRE) community tools for data processing, visualization, quality control, resource assessment, and device performance.
Two bugs in mhkit.tidal.io.noaa.request_noaa_data :
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
2. 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.
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:
```
### 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")
Describe the bug:
Two bugs in
mhkit.tidal.io.noaa.request_noaa_data
: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:
UnboundLocalError: local variable 'data' referenced before assignment
from mhkit.tidal.io import noaa
noaa.request_noaa_data('9446484', 'water_level', '20171113', '20171118')