<jupyter_start><jupyter_text>Centered Parameter Study with HydroTrend [HydroTrend](https://csdms.colorado.edu/wiki/Model:HydroTrend) is a numerical model that creates synthetic river discharge and sediment load time series as a function of climate trends and basin morphology.In this example, we'll perform a [centered parameter study](https://dakota.sandia.gov//sites/default/files/docs/6.4/html-ref/method-centered_parameter_study.html),evaluating how changing two HydroTrend input parameters:* `starting_mean_annual_temperature` and* `total_annual_precipitation`affects two output parameters* median long-term suspended sediment load at the river mouth and* mean discharge at the river mouthover a one-year run. Before we start, make sure that you've installed Dakota, HydroTrend, and this package on your computer, using the instructions in the [README](https://github.com/csdms/dakota/blob/master/README.md) file. Start by importing the Dakota class.<jupyter_code>from dakotathon import Dakota<jupyter_output><empty_output><jupyter_text>Create a Dakota instance to perform a centered parameter study with HydroTrend.<jupyter_code>d = Dakota(method='centered_parameter_study', plugin='hydrotrend')<jupyter_output><empty_output><jupyter_text>Define the HydroTrend input variables to be used in the parameter study, as well as the initial point in parameter space, the step size, and the range of the variables.<jupyter_code>d.variables.descriptors = ['starting_mean_annual_temperature', 'total_annual_precipitation']
d.variables.initial_point = [15.0, 2.0]
d.method.steps_per_variable = [2, 5]
d.method.step_vector = [2.5, 0.2]<jupyter_output><empty_output><jupyter_text>Define the HydroTrend outputs to be used in the parameter study, as well as the statistics to be calculated from them.<jupyter_code>d.responses.response_descriptors = ['Qs_median', 'Q_mean']
d.responses.response_files = ['HYDROASCII.QS', 'HYDROASCII.Q']
d.responses.response_statistics = ['median', 'mean']<jupyter_output><empty_output><jupyter_text>HydroTrend requires a set of files to run.They're included in the **data** directory of this example.They can also be obtained directly from the HydroTrend [GitHub repository](https://github.com/mcflugen/hydrotrend/tree/add-bmi-metadata).Set paths to these files with the following statements.<jupyter_code>import os

data_dir = os.path.join(os.getcwd(), 'data')
template_file = os.path.join(data_dir, 'hydrotrend.in.tmpl')
parameters_file = os.path.join(data_dir, 'parameters.yaml')
hypsometry_file = os.path.join(data_dir, 'HYDRO0.HYPS')<jupyter_output><empty_output><jupyter_text>The *template file* provides the configuration file for HydroTrend, but with all parameter values replaced by variables in the form `{parameter_name}`. The *parameters file* provides descriptions, ranges, and default values for all of the parameters represented in the template file. The *hypsometry file* describes the change in elevation along the river's course from source to sea. From the template and parameters files,we can create an input file that HydroTrend can run.Included in the CSDMS Dakota package is a routine that replaces the variables in the template file with default values from the parameters file.Import this routine and use it to create a HydroTrend input file.<jupyter_code>from dakotathon.plugins.base import write_dflt_file

default_input_file = write_dflt_file(template_file, parameters_file, run_duration=365)
print default_input_file<jupyter_output><empty_output><jupyter_text>Next, we must replace the default values for the variables for `starting_mean_annual_temperature` and `total_annual_precipitation` with variable names for Dakota to substitute into. The CSDMS Dakota package also includes a routine to do this. Import this routine and use it to create a Dakota template file.<jupyter_code>from dakotathon.plugins.base import write_dtmpl_file

dakota_template_file = write_dtmpl_file(template_file, default_input_file, d.variables.descriptors)
print dakota_template_file<jupyter_output><empty_output><jupyter_text>Associate the Dakota template file and the hypsometry file with the Dakota instance.<jupyter_code>d.template_file = dakota_template_file
d.auxiliary_files = hypsometry_file<jupyter_output><empty_output><jupyter_text>Call the setup method to create files needed by Dakota, then run the experiment.<jupyter_code>d.setup()
d.run()<jupyter_output><empty_output><jupyter_text>Check the output; in particular, the **dakota.dat** file.<jupyter_code>%cat dakota.dat<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.08007039155301364, 'fraction_numerical': 0.003739551253849538, 'mean_word_length': 7.1341681574239715, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 41, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '10', 'dir': 'jupyter-structured-clean-dedup', 'id': '404730', 'license': 'MIT', 'n_tokens_mistral': 1388, 'n_tokens_neox': 1334, 'n_words': 430, 'path': 'examples/hydrotrend-centered-parameter-study.ipynb', 'repo_name': 'csdms/dakotathon', 'size': '4546'}