Fetch and process data from the National Water Model
Project description
nwm
Python library to fetch and process the National Water Model (NWM) NetCDF datasets.
If you have any suggestion to improve the current function, please create a github issue here.
Get Started
Install package
$ pip install nwm
Download NWM Data
You can launch binder to test and run the code below.
Example 1: use NwmHs class to download data (Recommended method)
import matplotlib.pyplot as plt
from nwm import NwmHs
# get data from National water model HydroShare App
nwm_data = NwmHs()
dataset = nwm_data.get_data(archive='harvey', config='short_range', geom='channel_rt', variable='streamflow',
comid=[5781915], init_time=0, start_date='2017-08-23')
# show metadata
dataset.attrs
# plot data
plt.figure(figsize=(9,5))
dataset.plot()
plt.xlabel('Year 2017')
plt.ylabel('{} ({})'.format(dataset.variable_name,dataset.variable_unit))
plt.title('Short range streamflow forecast for Channel 5781915 during Harvey Hurricane Event')
Example 2: use BmiNwmHs class to download data (Demonstration of how to use BMI)
import matplotlib.pyplot as plt
import numpy as np
import cftime
from nwm import BmiNwmHs
# initiate a data component
data_comp = BmiNwmHs()
data_comp.initialize('config_file.yaml')
# get variable info
var_name = data_comp.get_output_var_names()[0]
var_unit = data_comp.get_var_units(var_name)
print(' variable_name: {}\n var_unit: {}\n'.format(var_name, var_unit))
# get time info
start_time = data_comp.get_start_time()
end_time = data_comp.get_end_time()
time_step = data_comp.get_time_step()
time_unit = data_comp.get_time_units()
time_steps = int((end_time - start_time)/time_step) + 1
print(' start_time:{}\n end_time:{}\n time_step:{}\n time_unit:{}\n time_steps:{}\n'.format(start_time, end_time, time_step, time_unit, time_steps))
# initiate numpy arrays to store data
stream_value = np.empty(1)
stream_array = np.empty(time_steps)
cftime_array = np.empty(time_steps)
for i in range(0, time_steps):
data_comp.get_value(var_name, stream_value)
stream_array[i] = stream_value
cftime_array[i] = data_comp.get_current_time()
data_comp.update()
time_array = cftime.num2date(cftime_array, time_unit, only_use_cftime_datetimes=False, only_use_python_datetimes=True)
# plot data
plt.figure(figsize=(9,5))
plt.plot(time_array, stream_array)
plt.xlabel('Year 2017')
plt.ylabel('{} ({})'.format(var_name, var_unit))
plt.title('Short range streamflow forecast for Channel 5781915 during Harvey Hurricane Event')
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
nwm-0.1.3-py3-none-any.whl
(12.6 kB
view details)
File details
Details for the file nwm-0.1.3-py3-none-any.whl
.
File metadata
- Download URL: nwm-0.1.3-py3-none-any.whl
- Upload date:
- Size: 12.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3a5d30df7d1fe4b408c1c8f98d6069d6b5765f426f655a01adcf281fd209dda0 |
|
MD5 | 275adbbb5a8625f3120d63a3a73f3de8 |
|
BLAKE2b-256 | 1313011ec32afb442076882915e8778fd8d021d45e704d12e11547a5b85731c0 |