def updateVisualizationOfNormalizedWeights():
     if self._relative_iteration_weights_box.isValid():
         weights = MultipleDataAssimilation.parseWeights(relative_iteration_weights_model.getValue())
         normalized_weights = MultipleDataAssimilation.normalizeWeights(weights)
         normalized_weights_model.setValue(", ".join("%.2f" % x for x in normalized_weights))
     else:
         normalized_weights_model.setValue("The weights are invalid!")
Exemplo n.º 2
0
    def test_normalized_weights(self):

        weights = mda.normalizeWeights([1])
        self.assertAlmostEqualList([1.0], weights)

        weights = mda.normalizeWeights([1, 1])
        self.assertAlmostEqualList([1.414214, 1.414214], weights)

        weights = mda.normalizeWeights([1, 0, 1])
        self.assertAlmostEqualList([1.414214, 1.414214], weights)

        weights = mda.normalizeWeights([1, 1, 1])
        self.assertAlmostEqualList([1.732051, 1.732051, 1.732051], weights)

        weights = mda.normalizeWeights([8, 4, 2, 1])
        self.assertAlmostEqualList([
            9.219544457292887, 4.6097722286464435, 2.3048861143232218,
            1.1524430571616109
        ], weights)

        weights = mda.normalizeWeights([
            9.219544457292887, 4.6097722286464435, 2.3048861143232218,
            1.1524430571616109
        ])
        self.assertAlmostEqualList([
            9.219544457292887, 4.6097722286464435, 2.3048861143232218,
            1.1524430571616109
        ], weights)
    def __init__(self):
        SimulationConfigPanel.__init__(
            self, MultipleDataAssimilation(getQueueConfig()))

        layout = QFormLayout()

        case_selector = CaseSelector()
        layout.addRow("Current case:", case_selector)

        run_path_label = QLabel("<b>%s</b>" % getRunPath())
        addHelpToWidget(run_path_label, "config/simulation/runpath")
        layout.addRow("Runpath:", run_path_label)

        number_of_realizations_label = QLabel("<b>%d</b>" %
                                              getRealizationCount())
        addHelpToWidget(number_of_realizations_label,
                        "config/ensemble/num_realizations")
        layout.addRow(QLabel("Number of realizations:"),
                      number_of_realizations_label)

        self._target_case_format_model = TargetCaseModel(format_mode=True)
        self._target_case_format_field = StringBox(
            self._target_case_format_model,
            "config/simulation/target_case_format")
        self._target_case_format_field.setValidator(ProperNameFormatArgument())
        layout.addRow("Target case format:", self._target_case_format_field)

        self._createInputForWeights(layout)

        self._analysis_module_selector = AnalysisModuleSelector(
            iterable=False, help_link="config/analysis/analysis_module")
        layout.addRow("Analysis Module:", self._analysis_module_selector)

        self._active_realizations_model = ActiveRealizationsModel()
        self._active_realizations_field = StringBox(
            self._active_realizations_model,
            "config/simulation/active_realizations")
        self._active_realizations_field.setValidator(
            RangeStringArgument(getRealizationCount()))
        layout.addRow("Active realizations", self._active_realizations_field)

        self._target_case_format_field.getValidationSupport(
        ).validationChanged.connect(self.simulationConfigurationChanged)
        self._active_realizations_field.getValidationSupport(
        ).validationChanged.connect(self.simulationConfigurationChanged)
        self._relative_iteration_weights_box.getValidationSupport(
        ).validationChanged.connect(self.simulationConfigurationChanged)

        self.setLayout(layout)
Exemplo n.º 4
0
    def test_weights(self):
        
        weights = mda.parseWeights("2, 2, 2, 2")
        print(weights)
        self.assertAlmostEqualList([2, 2, 2, 2], weights)

        weights = mda.parseWeights("1, 2, 3, ")
        self.assertAlmostEqualList([1, 2, 3], weights)

        weights = mda.parseWeights("1, 0, 1")
        self.assertAlmostEqualList([1, 1], weights)

        weights = mda.parseWeights("1.414213562373095, 1.414213562373095")
        self.assertAlmostEqualList([1.414213562373095, 1.414213562373095], weights)
  
        with self.assertRaises(ValueError):
            mda.parseWeights("2, error, 2, 2")
    def test_weights(self):

        weights = mda.parseWeights("2, 2, 2, 2")
        print(weights)
        self.assertAlmostEqualList([2, 2, 2, 2], weights)

        weights = mda.parseWeights("1, 2, 3, ")
        self.assertAlmostEqualList([1, 2, 3], weights)

        weights = mda.parseWeights("1, 0, 1")
        self.assertAlmostEqualList([1, 1], weights)

        weights = mda.parseWeights("1.414213562373095, 1.414213562373095")
        self.assertAlmostEqualList([1.414213562373095, 1.414213562373095], weights)

        with self.assertRaises(ValueError):
            mda.parseWeights("2, error, 2, 2")
    def test_normalized_weights(self):

        weights = mda.normalizeWeights([1])
        self.assertAlmostEqualList([1.0], weights)

        weights = mda.normalizeWeights([1, 1])
        self.assertAlmostEqualList([1.414214, 1.414214], weights)

        weights = mda.normalizeWeights([1, 0, 1])
        self.assertAlmostEqualList([1.414214, 1.414214], weights)

        weights = mda.normalizeWeights([1, 1, 1])
        self.assertAlmostEqualList([1.732051, 1.732051, 1.732051], weights)

        weights = mda.normalizeWeights([8, 4, 2, 1])
        self.assertAlmostEqualList([9.219544457292887, 4.6097722286464435, 2.3048861143232218, 1.1524430571616109], weights)

        weights = mda.normalizeWeights([9.219544457292887, 4.6097722286464435, 2.3048861143232218, 1.1524430571616109])
        self.assertAlmostEqualList([9.219544457292887, 4.6097722286464435, 2.3048861143232218, 1.1524430571616109], weights)