コード例 #1
0
ファイル: fitting.py プロジェクト: rosswhitfield/mantid
def parse_fit_options(mass_values, profile_strs, background_str="", constraints_str=""):
    """Parse the function string into a more usable format"""

    # Individual functions are separated by semi-colon separators
    mass_functions = profile_strs.rstrip(";").split(";")
    if len(mass_functions) != len(mass_values):
        raise ValueError("Expected the number of 'function=' definitions to equal the number of masses. "
                         "Found {0} masses but {1} function definition".format(len(mass_values), len(mass_functions)))
    mass_profiles = []
    for mass_value, prop_str in zip(mass_values, mass_functions):
        mass_profiles.append(profiles.create_from_str(prop_str, mass_value))

    if background_str != "":
        background = backgrounds.create_from_str(background_str)
    else:
        background = None

    if constraints_str != "":
        constraint_strings = constraints_str.split(";")
        constraints = []
        for constr_str in constraint_strings:
            constraints.append(ast.literal_eval(constr_str))
    else:
        constraints = None

    return FittingOptions(mass_profiles, background, constraints)
コード例 #2
0
def parse_fit_options(mass_values,
                      profile_strs,
                      background_str="",
                      constraints_str=""):
    """Parse the function string into a more usable format"""

    # Individual functions are separated by semi-colon separators
    mass_functions = profile_strs.rstrip(";").split(";")
    if len(mass_functions) != len(mass_values):
        raise ValueError(
            "Expected the number of 'function=' definitions to equal the number of masses. "
            "Found {0} masses but {1} function definition".format(
                len(mass_values), len(mass_functions)))
    mass_profiles = []
    for mass_value, prop_str in zip(mass_values, mass_functions):
        mass_profiles.append(profiles.create_from_str(prop_str, mass_value))

    if background_str != "":
        background = backgrounds.create_from_str(background_str)
    else:
        background = None

    if constraints_str != "":
        constraint_strings = constraints_str.split(";")
        constraints = []
        for constr_str in constraint_strings:
            constraints.append(ast.literal_eval(constr_str))
    else:
        constraints = None

    return FittingOptions(mass_profiles, background, constraints)
コード例 #3
0
    def test_create_object_from_str(self):
        background_str = "function=Polynomial,order=2"

        background = create_from_str(background_str)
        self.assertTrue(isinstance(background, PolynomialBackground))
        self.assertEqual(2, background.order)
コード例 #4
0
    def test_create_object_from_str(self):
        background_str = "function=Polynomial,order=2"

        background = create_from_str(background_str)
        self.assertTrue(isinstance(background, PolynomialBackground))
        self.assertEqual(2, background.order)