Comments (3)
This issue is related to #113
from hydrotools.
Parking this example here:
from hydrotools.nwis_client.iv import IVDataService
import numpy as np
import pint
def convert(values, from_units, to_units):
"""Convert scientific units of values.
Parameters
==========
values: npt.ArrayLike
Values to convert
from_units: pint.UnitRegistry.Quantity compatible object
Original units of values.
to_units: pint.UnitRegistry.Quantity compatible object
Desired conversion units.
Returns
=======
result: npt.ArrayLike
Same shape as values containing converted values.
"""
# Setup registry
u = pint.UnitRegistry()
# Pint Array
quantities = u.Quantity(np.asarray(values), from_units)
# Convert units
return quantities.to(to_units).magnitude
def main():
# Setup client
client = IVDataService(value_time_label="value_time")
# Retrieve some data
df = client.get(
sites="01013500",
startDT="20211001T00:00",
endDT="20211002T00:00"
)
# Convert to cubic meters per second
df["value"] = convert(df["value"], "ft^3/s", "m^3/s")
df["measurement_unit"] = "m^3/s"
# Look at the data
print(df.head())
if __name__ == "__main__":
main()
Output
value_time variable_name usgs_site_code measurement_unit value qualifiers series
0 2021-10-01 00:00:00 streamflow 01013500 m^3/s 16.112286 ['P'] 0
1 2021-10-01 00:15:00 streamflow 01013500 m^3/s 16.112286 ['P'] 0
2 2021-10-01 00:30:00 streamflow 01013500 m^3/s 16.112286 ['P'] 0
3 2021-10-01 00:45:00 streamflow 01013500 m^3/s 16.112286 ['P'] 0
4 2021-10-01 01:00:00 streamflow 01013500 m^3/s 16.112286 ['P'] 0
from hydrotools.
Minimal example to compute discharge per unit area (AKA total runoff)
# Set up registry
u = pint.UnitRegistry()
# Parameters
catchment_area = u.Quantity(25.0, "miles^2").to("ft^2")
period = u.Quantity(15.0, "minutes").to("s")
discharge = u.Quantity(500.0, "ft^3/s")
# Compute discharge per unit area
discharge_per_unit_area = discharge * period / catchment_area
# Display in inches
print(discharge_per_unit_area.to("inches"))
Output
0.007747933884297518 inch
from hydrotools.
Related Issues (20)
- NWIS IV Client `FutureWarning` HOT 3
- NWM Client New Test Failure: AttributeError: 'EntryPoints' object has no attribute 'get' HOT 5
- Pandas >= 2.0.0 package compliance audit HOT 4
- `nwis_client` "sqlite3.OperationalError: database is locked" HOT 6
- Move `hydrotools` namespace packages to separate repositories HOT 3
- "Run Slow Unit Tests" Action has been failing for some time HOT 2
- 3.7 Tests failing: xarray EntryPoints has no attribute get HOT 6
- DeprecationWarning: Deprecated call to `pkg_resources.declare_namespace HOT 1
- AWS Retrospective HOT 10
- SVI Client slow unit tests failing HOT 8
- nwm_client_new documentation is incomplete for private servers. HOT 1
- nwm_client_new `get` methods fails with custom Parquet Store
- Consider supporting MS Azure (`nwm_client_new`) HOT 1
- Determine feasibility of _restclient's continued dependence on `aiohttp_cache_client` HOT 5
- SVI Client get method failing due to Pydantic>2 issue HOT 1
- New version of `_restclient` cannot be pushed to PyPI b.c. namespace packages with leading `_` in package name cannot be uploaded HOT 1
- Add some basic information about the NWM operational configuration to the `nwm_client_new` package. HOT 1
- Event Detection methods are raising `FutureWarning` HOT 3
- question about update cycle for hydrotools HOT 3
- NWPS API Available HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hydrotools.