Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions dataretrieval/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
except PackageNotFoundError:
__version__ = "version-unknown"

from dataretrieval.nadp import *
from dataretrieval.nwis import *
from dataretrieval.samples import *
from dataretrieval.streamstats import *
from dataretrieval.utils import *
from dataretrieval.waterdata import *
from dataretrieval.waterwatch import *
from dataretrieval.wqp import *
from dataretrieval.nadp import * # noqa: F403
from dataretrieval.nwis import * # noqa: F403
from dataretrieval.samples import * # noqa: F403
from dataretrieval.streamstats import * # noqa: F403
from dataretrieval.utils import * # noqa: F403
from dataretrieval.waterdata import * # noqa: F403
from dataretrieval.waterwatch import * # noqa: F403
from dataretrieval.wqp import * # noqa: F403
4 changes: 2 additions & 2 deletions dataretrieval/codes/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
from .states import *
from .timezones import *
from .states import * # noqa: F403
from .timezones import * # noqa: F403
6 changes: 3 additions & 3 deletions dataretrieval/nldi.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

try:
import geopandas as gpd
except ImportError:
raise ImportError("Install geopandas to use the NLDI module.")
except ImportError as err:
raise ImportError("Install geopandas to use the NLDI module.") from err

NLDI_API_BASE_URL = "https://api.water.usgs.gov/nldi/linked-data"
_AVAILABLE_DATA_SOURCES = None
Expand Down Expand Up @@ -281,7 +281,7 @@ def get_features(
query_params = {}

if lat:
err_msg = f"Error getting features for lat '{lat}'" f" and long '{long}'"
err_msg = f"Error getting features for lat '{lat}' and long '{long}'"
elif feature_source:
err_msg = (
f"Error getting features for feature source '{feature_source}'"
Expand Down
11 changes: 6 additions & 5 deletions dataretrieval/nwis.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"The 'nwis' services are deprecated and being decommissioned. "
"Please use the 'waterdata' module to access the new services.",
DeprecationWarning,
stacklevel=2
stacklevel=2,
)

WATERDATA_BASE_URL = "https://nwis.waterdata.usgs.gov/"
Expand Down Expand Up @@ -141,7 +141,7 @@ def get_qwdata(
"""
raise NameError(
"`nwis.get_qwdata` has been replaced with `waterdata.get_samples()`."
)
)


def get_discharge_measurements(
Expand All @@ -157,7 +157,7 @@ def get_discharge_measurements(
Parameters
----------
sites: string or list of strings, optional, default is None
start: string, optional, default is None
start: string, optional, default is None
Supply date in the format: YYYY-MM-DD
end: string, optional, default is None
Supply date in the format: YYYY-MM-DD
Expand Down Expand Up @@ -344,7 +344,7 @@ def get_gwlevels(

if datetime_index is True:
df = format_datetime(df, "lev_dt", "lev_tm", "lev_tz_cd")

# Filter by kwarg parameterCd because the service doesn't do it
if "parameterCd" in kwargs:
pcodes = kwargs["parameterCd"]
Expand Down Expand Up @@ -696,7 +696,8 @@ def get_info(ssl_check: bool = True, **kwargs) -> Tuple[pd.DataFrame, BaseMetada
"refer to https://waterdata.usgs.gov.nwis/qwdata and "
"https://doi-usgs.github.io/dataRetrieval/articles/Status.html "
"or email CompTools@usgs.gov."
)
),
stacklevel=2,
)
# convert bool to string if necessary
kwargs["seriesCatalogOutput"] = "True"
Expand Down
40 changes: 24 additions & 16 deletions dataretrieval/samples.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,19 @@

from __future__ import annotations

from typing import TYPE_CHECKING, Literal, get_args

import pandas as pd
import warnings
from typing import TYPE_CHECKING

from dataretrieval.utils import BaseMetadata

if TYPE_CHECKING:
from typing import Optional, Tuple, Union
from dataretrieval.waterdata import SERVICES, PROFILES

from pandas import DataFrame

from dataretrieval.waterdata import PROFILES, SERVICES


def get_usgs_samples(
ssl_check: bool = True,
service: SERVICES = "results",
Expand Down Expand Up @@ -111,7 +112,7 @@ def get_usgs_samples(
A user supplied characteristic name describing one or more results.
boundingBox: list of four floats, optional
Filters on the the associated monitoring location's point location
by checking if it is located within the specified geographic area.
by checking if it is located within the specified geographic area.
The logic is inclusive, i.e. it will include locations that overlap
with the edge of the bounding box. Values are separated by commas,
expressed in decimal degrees, NAD83, and longitudes west of Greenwich
Expand All @@ -120,7 +121,7 @@ def get_usgs_samples(
- Western-most longitude
- Southern-most latitude
- Eastern-most longitude
- Northern-most longitude
- Northern-most longitude
Example: [-92.8,44.2,-88.9,46.0]
countryFips : string or list of strings, optional
Example: "US" (United States)
Expand All @@ -143,7 +144,7 @@ def get_usgs_samples(
usgsPCode : string or list of strings, optional
5-digit number used in the US Geological Survey computerized
data system, National Water Information System (NWIS), to
uniquely identify a specific constituent. Check the
uniquely identify a specific constituent. Check the
`characteristic_lookup()` function in this module for all possible
inputs.
Example: "00060" (Discharge, cubic feet per second)
Expand Down Expand Up @@ -173,7 +174,7 @@ def get_usgs_samples(
recordIdentifierUserSupplied : string or list of strings, optional
Internal AQS record identifier that returns 1 entry. Only available
for the "results" service.

Returns
-------
df : ``pandas.DataFrame``
Expand All @@ -187,8 +188,8 @@ def get_usgs_samples(

>>> # Get PFAS results within a bounding box
>>> df, md = dataretrieval.samples.get_usgs_samples(
... boundingBox=[-90.2,42.6,-88.7,43.2],
... characteristicGroup="Organics, PFAS"
... boundingBox=[-90.2, 42.6, -88.7, 43.2],
... characteristicGroup="Organics, PFAS",
... )

>>> # Get all activities for the Commonwealth of Virginia over a date range
Expand All @@ -197,22 +198,31 @@ def get_usgs_samples(
... profile="sampact",
... activityStartDateLower="2023-10-01",
... activityStartDateUpper="2024-01-01",
... stateFips="US:51")
... stateFips="US:51",
... )

>>> # Get all pH samples for two sites in Utah
>>> df, md = dataretrieval.samples.get_usgs_samples(
... monitoringLocationIdentifier=['USGS-393147111462301', 'USGS-393343111454101'],
... usgsPCode='00400')
... monitoringLocationIdentifier=[
... "USGS-393147111462301",
... "USGS-393343111454101",
... ],
... usgsPCode="00400",
... )

"""

warnings.warn(
"`get_usgs_samples` is deprecated and will be removed. Use `waterdata.get_samples` instead.",
(
"`get_usgs_samples` is deprecated and will be removed. "
"Use `waterdata.get_samples` instead."
),
DeprecationWarning,
stacklevel=2,
)

from dataretrieval.waterdata import get_samples

result = get_samples(
ssl_check=ssl_check,
service=service,
Expand Down Expand Up @@ -242,5 +252,3 @@ def get_usgs_samples(
)

return result


2 changes: 1 addition & 1 deletion dataretrieval/streamstats.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,4 +158,4 @@ def from_streamstats_json(cls, streamstats_json):

def __init__(self, rcode, xlocation, ylocation):
"""Init method that calls the :obj:`from_streamstats_json` method."""
self = get_watershed(rcode, xlocation, ylocation)
get_watershed(rcode, xlocation, ylocation)
12 changes: 6 additions & 6 deletions dataretrieval/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,16 @@ def to_str(listlike, delimiter=","):
'0+10+42'

"""
if type(listlike) == list:
if isinstance(listlike, list):
return delimiter.join([str(x) for x in listlike])

elif type(listlike) == pd.core.series.Series:
elif isinstance(listlike, pd.core.series.Series):
return delimiter.join(listlike.tolist())

elif type(listlike) == pd.core.indexes.base.Index:
elif isinstance(listlike, pd.core.indexes.base.Index):
return delimiter.join(listlike.tolist())

elif type(listlike) == str:
elif isinstance(listlike, str):
return listlike


Expand Down Expand Up @@ -91,6 +91,7 @@ def format_datetime(df, date_field, time_field, tz_field):
f"Warning: {count} incomplete dates found, "
+ "consider setting datetime_index to False.",
UserWarning,
stacklevel=2,
)

return df
Expand Down Expand Up @@ -229,6 +230,5 @@ def __init__(self, url):

def __str__(self):
return (
"No sites/data found using the selection criteria specified in url: "
"{url}"
"No sites/data found using the selection criteria specified in url: {url}"
).format(url=self.url)
Loading
Loading