<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 <img src="http
Step1:  Create a Dakota instance to perform a centered parameter study with HydroTrend.
Step2:  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.
Step3:  Define the HydroTrend outputs to be used in the parameter study, as well as the statistics to be calculated from them.
Step4:  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.
Set paths to these files with the following statements.
Step5:  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.
Step6:  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.
Step7:  Associate the Dakota template file and the hypsometry file with the Dakota instance.
Step8:  Call the setup method to create files needed by Dakota, then run the experiment.
Step9:  Check the output; in particular, the dakota.dat file.
<ASSISTANT_TASK:>
Python Code:
from dakotathon import Dakota
Explanation: <img src="http://csdms.colorado.edu/mediawiki/images/CSDMS_high_res_weblogo.jpg">
Centered Parameter Study with HydroTrend
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,
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 mouth
over 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 file.
Start by importing the Dakota class.
End of explanation
d = Dakota(method='centered_parameter_study', plugin='hydrotrend')
Explanation: Create a Dakota instance to perform a centered parameter study with HydroTrend.
End of explanation
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]
Explanation: 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.
End of explanation
d.responses.response_descriptors = ['Qs_median', 'Q_mean']
d.responses.response_files = ['HYDROASCII.QS', 'HYDROASCII.Q']
d.responses.response_statistics = ['median', 'mean']
Explanation: Define the HydroTrend outputs to be used in the parameter study, as well as the statistics to be calculated from them.
End of explanation
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')
Explanation: 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.
Set paths to these files with the following statements.
End of explanation
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
Explanation: 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.
End of explanation
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
Explanation: 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.
End of explanation
d.template_file = dakota_template_file
d.auxiliary_files = hypsometry_file
Explanation: Associate the Dakota template file and the hypsometry file with the Dakota instance.
End of explanation
d.setup()
d.run()
Explanation: Call the setup method to create files needed by Dakota, then run the experiment.
End of explanation
%cat dakota.dat
Explanation: Check the output; in particular, the dakota.dat file.
End of explanation
<END_TASK>