HydUtils
HydUtils is a Python utility library designed for data handling and validation, especially for time series and hydrological datasets. It provides several useful functions for working with time series data, including validation, filtering, error metrics, and more, making it easier to handle and analyze hydrological and weather-related datasets.
Installation
pip install hydutils
Usage
1. Validate Columns for Nulls
The function validate_columns_for_nulls checks for columns that contain null values and raises an error if any are
found.
from hydutils.df_helper import validate_columns_for_nulls
import pandas as pd
df = pd.DataFrame({"a": [1, 2, 3], "b": [4, 5, None], "c": [7, 8, 9]})
# Validate for null values in any column
validate_columns_for_nulls(df)
# Specify columns to check
validate_columns_for_nulls(df, columns=["b"])
# Handling missing columns
validate_columns_for_nulls(df, columns=["d"]) # This will raise an error if column "d" is missing
2. Validate Time Series Interval
The validate_interval function checks that the time intervals between rows in the time series are consistent.
from hydutils.df_helper import validate_interval
import pandas as pd
df = pd.DataFrame({
"time": pd.date_range(start="2023-01-01", periods=5, freq="h")
})
# Check if the time intervals are consistent
validate_interval(df, interval=1)
3. Filter Time Series
The filter_timeseries function allows you to filter your time series DataFrame based on a start and/or end date.
from hydutils.df_helper import filter_timeseries
import pandas as pd
from datetime import datetime
df = pd.DataFrame({
"time": pd.date_range(start="2023-01-01", periods=5, freq="h")
})
# Filter data between a start and end date
start = datetime(2023, 1, 1, 1)
end = datetime(2023, 1, 1, 3)
filtered_data = filter_timeseries(df, start=start, end=end)
4. Error Metrics
The hydutils.metrics module includes several commonly used metrics to evaluate model performance. These include MSE,
RMSE, NSE, R², PBIAS, and FBIAS.
4.1 Mean Squared Error (MSE)
The mse function calculates the Mean Squared Error between two arrays.
from hydutils.statistical_metrics import mse
import numpy as np
simulated = np.array([3.0, 4.0, 5.0])
observed = np.array([2.9, 4.1, 5.0])
mse_value = mse(simulated, observed)
4.2 Root Mean Squared Error (RMSE)
The rmse function calculates the Root Mean Squared Error.
from hydutils.statistical_metrics import rmse
rmse_value = rmse(simulated, observed)
4.3 Nash-Sutcliffe Efficiency (NSE)
The nse function calculates the Nash-Sutcliffe Efficiency coefficient.
from hydutils.statistical_metrics import nse
nse_value = nse(simulated, observed)
4.4 R² (Coefficient of Determination)
The r2 function calculates the coefficient of determination, R².
from hydutils.statistical_metrics import r2
r2_value = r2(simulated, observed)
4.5 Percentage Bias (PBIAS)
The pbias function calculates the Percentage Bias between observed and simulated values.
from hydutils.statistical_metrics import pbias
pbias_value = pbias(observed, simulated)
4.6 Fractional Bias (FBIAS)
The fbias function calculates the Fractional Bias between observed and simulated values.
from hydutils.statistical_metrics import fbias
fbias_value = fbias(observed, simulated)
License
This library is released under the MIT License.
Metadata
Release files for hydutils 2.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| hydutils-2.0.0.tar.gz | 5.9 kB | Without provenance | Details for hydutils-2.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| hydutils-2.0.0-py3-none-any.whl | Python 3 | none | any | Details for hydutils-2.0.0-py3-none-any.whl |
Total release size: 12.8 kB
Release files / hydutils-2.0.0.tar.gz
| Download URL | hydutils-2.0.0.tar.gz |
|---|---|
| Size | 5.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f8eaeaecd402cc653308da919ea9a309c2c169b206237bf3d8a38f90a19186ac
|
|
BLAKE2b-256 checksum How to use checksums |
49a4da94493e79eb90be5b3e29d6cbd20c0b65faa03cd8c101a7bb60b828c831
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.4 CPython/3.12.3 Linux/6.8.0-51-generic
|
Release files / hydutils-2.0.0-py3-none-any.whl
| Download URL | hydutils-2.0.0-py3-none-any.whl |
|---|---|
| Size | 6.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
522e67f16584c38271bd898f8ab157f52cbe76a69c64a9931bd7a2c4d2a993be
|
|
BLAKE2b-256 checksum How to use checksums |
49e290841bf3de0aeef91cb42e145c14c67b13673573a22244eb78d58c1240fc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.4 CPython/3.12.3 Linux/6.8.0-51-generic
|
Security for hydutils 2.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.