mroberge / hydrofunctions

A suite of convenience functions for working with hydrology data in an interactive Python session.
MIT License
62 stars 27 forks source link

extract_nwis_df wrong variable name #89

Closed lapidesd closed 3 years ago

lapidesd commented 3 years ago

Description

I ran a hydrofunctions.NWIS query to get all temperature data in the state of California. When converting to a dataframe, there was a division by zero error since the data frequency was miscalculated.

What I Did to resolve this error

I adjusted the source code so that in the extract_nwis_df at lines 571 and 572 of hydrofunctions.py (version on github), I replaced the variable 'freqs' with 'freqs2', which removes the zeros and prevents the division by zero error.
mroberge commented 3 years ago

Hi @lapidesd! Thank you for filing this issue! Could you tell me the query that you used to get this error? I'm curious about what went wrong.

I'm guessing it was something like this::

hf.NWIS(stateCd="CA", service="dv", parameterCd="00020")

# "00020" is for air temperature, "00010" is for water temperature (much more commonly collected)

But that didn't bring up an error for me.

Also, if you are interested in submitting a pull request, I'm always looking for contributors! https://hydrofunctions.readthedocs.io/en/latest/contributing.html

lapidesd commented 3 years ago

Hi,

I did the query for water temperature ‘00010’. The full query is:

state_data = hf.NWIS(site=None, stateCd=‘CA', service='dv', start_date='1950-01-01', end_date='2021-04-01', parameterCd = '00010') state_data = state_data.df()

The error shows up on conversion to a dataframe. I just made a pull request for the bug fix.

Best, Dana

——————————————————— Dana Lapides, PhD Wisconsin Water Resources Science-Policy Fellow UW Madison Aquatic Science Center Wisconsin Department of Natural Resources www.danalapides.com http://www.danalapides.com/

On May 7, 2021, at 10:49, Martin Roberge @.***> wrote:

Hi @lapidesd https://github.com/lapidesd! Thank you for filing this issue! Could you tell me the query that you used to get this error? I'm curious about what went wrong.

I'm guessing it was something like this::

hf.NWIS(stateCd="CA", service="dv", parameterCd="00020")

"00020" is for air temperature, "00010" is for water temperature (much more commonly collected)

But that didn't bring up an error for me.

Also, if you are interested in submitting a pull request, I'm always looking for contributors! https://hydrofunctions.readthedocs.io/en/latest/contributing.html https://hydrofunctions.readthedocs.io/en/latest/contributing.html — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/mroberge/hydrofunctions/issues/89#issuecomment-834651826, or unsubscribe https://github.com/notifications/unsubscribe-auth/AE7XC3XCKJH5AGXX62TGL7LTMQRZJANCNFSM44KOUYGQ.

mroberge commented 3 years ago

Excellent! This query illustrates a problem with how hydrofunctions converts the JSON from the NWIS into a dataframe. It basically takes the data from every single temperature-measuring station in the state of California and resamples it to the frequency of the station with the shortest frequency for the entire length of the query. So if there is a station that recorded temperature every five minutes one day back in 2005, hydrofunctions will output a dataframe with a row for every five minutes starting in 1950 until 2021. And it performs this "service" for you just because you asked for some data.

My plan for the future is to change this so that the data is stored internally in the WaterML format, and a dataframe is created only when you ask for a dataframe. That way the 'upsampling' only occurs if you ask it to occur.

mroberge commented 3 years ago

In the meantime, you can see what stations have collected temperature by just requesting the most recent value:

hf.NWIS(stateCd="CA", service="dv", parameterCd="00010")

You can also use hf.data_catalog(station_id) or hf.site_file(station_id to learn more about individual stations.

mroberge commented 3 years ago

closed with 16dd705