self.varwidgets[var] = range_widget
self.variablesRangesWidget.layout().insertWidget(idx_var, range_widget)
+ def set_pyscript_label_from_vars(self, exchange_vars):
+ input_var_names = [var.name for var in exchange_vars.inputVarList]
+ text = "This script must create a NumPy array of dimension (n, %d)" % len(input_var_names)
+ text += " named <b>sample</b> where n is the number of points in the sample."
+ if len(input_var_names) > 1:
+ text += "<br>The order of the input variables (columns of the sample) must be"
+ for i, var in enumerate(input_var_names):
+ if i != 0:
+ text += ","
+ text += " <b>" + var + "</b>"
+ text += "."
+ self.pyscriptLabel.setText(text)
+
def study_to_gui(self, param_study):
if param_study.sample_definition_method == ParametricStudy.SAMPLE_VAR_RANGE:
self.variableRangeRB.setChecked(True)
def define_values(self):
exchange_vars = self.select_vars_frame.getSelectedExchangeVariables()
self.define_values_frame.set_variables(exchange_vars.inputVarList)
+ self.define_values_frame.set_pyscript_label_from_vars(exchange_vars)
def set_pyscript_label(self):
exchange_vars = self.select_vars_frame.getSelectedExchangeVariables()
def generate_data(self):
if self.sample_definition_method == ParametricStudy.SAMPLE_VAR_RANGE:
self.generate_data_complete_sampling()
+ elif self.sample_definition_method == ParametricStudy.SAMPLE_PYTHON_SCRIPT:
+ self.generate_data_python_script()
elif self.sample_definition_method == ParametricStudy.SAMPLE_CSV_FILE:
self.generate_data_from_csv_file()
else:
self._value_dict[varname] = value
self._fill_data_complete_sampling(next_var_list)
+ def generate_data_python_script(self):
+ context = {}
+ exec self.sample_python_script in context
+
+ # Basic check on the "sample" array
+ if not context.has_key("sample"):
+ raise Exception('Python script did not create "sample" object')
+ sample = context["sample"]
+ if type(sample) != numpy.ndarray:
+ raise Exception('"sample" object created in Python script is not a numpy array')
+ if sample.ndim != 2:
+ raise Exception('Wrong dimension: "sample" array should be a 2-dimension array')
+ if sample.shape[1] != len(self.input_vars):
+ raise Exception('Wrong size: "sample" array should have %d columns' % len(self.input_vars))
+
+ # Store data in the parametric study
+ self.data = {}
+ for (idx, varname) in enumerate(self.input_vars):
+ self.data[varname] = sample[:,idx]
+ self.datasize = sample.shape[0]
+
def generate_data_from_csv_file(self, sep = ","):
if self.sample_csv_file is None:
raise Exception("CSV file for input data is not defined")