<jupyter_start><jupyter_text>Introduction [nwm package](https://github.com/gantian127/nwm) provides a set of functions that allows downloading of the National Water Model datasets for data visualization and analysis. nwm package also includes a Basic Model Interface ([BMI](https://bmi.readthedocs.io/en/latest/)). [pymt_nwm package](https://github.com/gantian127/pymt_nwm) uses the BMI of nwm to convert it into a reusable, plug-and-play data component for [PyMT](https://pymt.readthedocs.io/en/latest/?badge=latest) modeling framework. This allows the National Water Model datasets to be easily coupled with other datasets or models that expose a BMI. **To install pymt_nwm, use the following command:**<jupyter_code>! pip install pymt_nwm<jupyter_output><empty_output><jupyter_text>Coding Example Import Nwm class and instantiate it. A configuration file (yaml file) is required to provide the parameter settings for data download. An example config_file.yaml is provided in the same folder with this Jupyter Notebook file. For more details of the parameters specified in the config.yaml file, please check with the link [here](https://nwm.readthedocs.io/en/latest/?badge=latestparameter-settings).<jupyter_code>import matplotlib.pyplot as plt
import numpy as np
import cftime


from pymt.models import Nwm

# initiate a data component
data_comp = Nwm()
data_comp.initialize('config_file.yaml')<jupyter_output><empty_output><jupyter_text>Use variable related methods to check the variable information of the dataset.<jupyter_code># get variable info
var_name = data_comp.output_var_names[0]
var_unit = data_comp.var_units(var_name)
var_location = data_comp.var_location(var_name)
var_type = data_comp.var_type(var_name)
var_grid = data_comp.var_grid(var_name)

print('variable_name: {} \nvar_unit: {} \nvar_location: {} \nvar_type: {} \nvar_grid: {}'.format(
    var_name, var_unit, var_location, var_type, var_grid))<jupyter_output>variable_name: Flow Forecast 
var_unit: cfs 
var_location: none 
var_type: float64 
var_grid: None<jupyter_text>Use time related methods to check the time information of the dataset. Please note that the time values are stored in a format which follows [CF convention](http://cfconventions.org/Data/cf-conventions/cf-conventions-1.8/cf-conventions.pdf).<jupyter_code># get time info
start_time = data_comp.start_time
end_time = data_comp.end_time
time_step = data_comp.time_step
time_units = data_comp.time_units
time_steps = int((end_time - start_time)/time_step) + 1

print('start_time: {} \nend_time: {} \ntime_step: {} \ntime_units: {} \ntime_steps: {}'.format(
    start_time, end_time, time_step, time_units, time_steps))<jupyter_output>start_time: 1503450000.0 
end_time: 1503511200.0 
time_step: 3600 
time_units: seconds since 1970-01-01 00:00:00 UTC 
time_steps: 18<jupyter_text>Loop through each time step to get the flow and time values. stream_array stores flow forecast values. cftime_array stores the numerical time values. time_array stores the corresponding Python datetime objects. get_value( ) method returns the flow forecast value at each time step. update( ) method updates the current time step of the data component.<jupyter_code># get variable data
stream_array = np.empty(time_steps)
cftime_array = np.empty(time_steps)

for i in range(0, time_steps):
    stream_array[i] = data_comp.get_value(var_name)
    cftime_array[i] = data_comp.time
    data_comp.update()

time_array = cftime.num2date(cftime_array, time_units, only_use_cftime_datetimes=False, only_use_python_datetimes=True )<jupyter_output><empty_output><jupyter_text>Now let's make a plot of the streamflow data.<jupyter_code># 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')<jupyter_output><empty_output><jupyter_text>Complete the example by finalizing the component.<jupyter_code>data_comp.finalize()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09266123054114159, 'fraction_numerical': 0.01704966641957005, 'mean_word_length': 6.4003656307129795, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 27, 'https://': 5, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '240123', 'license': 'MIT', 'n_tokens_mistral': 1374, 'n_tokens_neox': 1298, 'n_words': 373, 'path': 'notebooks/pymt_nwm.ipynb', 'repo_name': 'gantian127/pymt_nwm', 'size': '4047'}