Пример #1
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)
Пример #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_string_with_constrained_width_produces_valid_object(self):
        function_str = "function=Gaussian,width=[2, 5, 7]"
        mass = 16.0

        profile = create_from_str(function_str, mass)
        self.assertTrue(isinstance(profile, GaussianMassProfile))
        self.assertAlmostEqual(mass, profile.mass)
        self.assertEqual([2, 5, 7], profile.width)
Пример #4
0
    def test_string_with_fixed_width_produces_valid_object(self):
        function_str = "function=GramCharlier,width=[2, 5,7],k_free=1,hermite_coeffs=[1,0,1],sears_flag=0,"
        mass = 16.0

        profile = create_from_str(function_str, mass)
        self.assertTrue(isinstance(profile, GramCharlierMassProfile))
        self.assertAlmostEqual(mass, profile.mass)
        self.assertEqual([2, 5, 7], profile.width)
        self.assertEqual([1, 0, 1], profile.hermite_co)
        self.assertEqual(0, profile.sears_flag)
        self.assertEqual(1, profile.k_free)