Closed jmpmcmanus closed 1 year ago
This nwm_client_new
package is still in beta and has not been deployed to PyPI yet. If you would like to test the new package, you can install the package directly from GitHub using:
$ python3 -m pip install git+http://github.com/NOAA-OWP/hydrotools.git#subdirectory=python/nwm_client_new
Alternatively, you can install the current stable nwm_client
package from PyPI:
# Base package
$ python3 -m pip install hydrotools.nwm_client
# ...or install with Google Cloud Support
$ python3 -m pip install hydrotools.nwm_client[gcp]
Thanks. That worked. However, when I attempt to run the example:
from hydrotools.nwm_client_new.NWMFileClient import NWMFileClient import pandas as pd
client = NWMFileClient()
yesterday = pd.Timestamp.utcnow() - pd.Timedelta("1D") reference_time = yesterday.strftime("%Y%m%dT%-HZ")
forecast_data = client.get( configuration = "short_range", reference_times = [reference_time] )
print(forecast_data.info(memory_usage='deep')) print(forecast_data[['value_time', 'value']].head())
I get the following error: RuntimeError: asyncio.run() cannot be called from a running event loop
Below is the full error output:
RuntimeError Traceback (most recent call last)
nwm_client_new
and nwis_client
use the asyncio
library which currently has problems with interactive environments like Jupyter Notebooks and Spyder. If you're using one of these environments you'll want to import and apply nest_asyncio
as shown below. Note this must be done before any other imports.
# Import necessary for interactive environments
import nest_asyncio
nest_asyncio.apply()
# Import the nwm Client
from hydrotools.nwm_client_new.NWMFileClient import NWMFileClient
import pandas as pd
# Instantiate model data client
# Defaults to Google Cloud Platform
client = NWMFileClient()
# Set reference time
yesterday = pd.Timestamp.utcnow() - pd.Timedelta("1D")
reference_time = yesterday.strftime("%Y%m%dT%-HZ")
# Retrieve forecast data
# By default, only retrieves data at USGS gaging sites in
# CONUS that are used for model assimilation
forecast_data = client.get(
configuration = "analysis_assim",
reference_times = [reference_time]
)
# Look at the data
print(forecast_data.info(memory_usage='deep'))
print(forecast_data[['value_time', 'value']].head())
I am using Jupyter, and that worked. However, now I am getting error about sort_values:
AttributeError: 'DataFrame' object has no attribute 'sort_values'
I get this error when running it in Jupyter and the Python prompt. Here is the full output from the python prompt:
warnings.warn(message)
Traceback (most recent call last):
File "
That's odd. Is it possible you're using an older version of dask
?
I already had dask installed as part of pangeo. It was installed using conda. Its version number is 2021.02.0. I will try it on a newer version.
I updated my pangeo environment installing dask 2021.11.1 and everything is working! Thanks for your help!!
Great news! We'll leave this ticket open until nwm_client_new
is deployed to PyPI.
Two years late, but a version of nwm_client_new
has been deployed to PyPI and is installable via pip
.
https://pypi.org/project/hydrotools.nwm-client-new/7.1.0/
Hi - I installed hydrotools using pip: https://pypi.org/project/hydrotools/ but when I try to import anything from hydrotools.nwm_client_new I get:
from hydrotools.nwm_client_new.NWMFileClient import NWMFileClient raceback (most recent call last): File "", line 1, in
ModuleNotFoundError: No module named 'hydrotools.nwm_client_new'
Why is nwm_client_new not available in the pip version?
Thanks Jim