Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes issues found with linear fitting guess function #44

Merged
merged 3 commits into from
Oct 29, 2024

Conversation

jackbdoughty
Copy link
Contributor

Found issues with linear fitting whereby the guess function would not work as expected e.g not guessing a straight line and division by zero error. This fixes by instead using the already implemented polynomial guess function and passing 1 as the polynomial degree. Should test by creating an example plan and two blocks to scan against eachother from- use a python script to repeatedly write to one of the blocks to simulate data from scan. See below. Check that initial guess produced in plot window fits the data provided well.

See fitting docs for more info.

Run this separately

def linear(x, m, c):
    return m * x + c

g.set_pv("CS:SB:bob", 1, is_local=True)

while True:

    val = g.get_pv("CS:SB:bob", is_local=True)
    g.set_pv("CS:SB:alice", linear(val, 0, 1),is_local=True)

Use a plan that looks like this

def plan():

    alice = block_r(float, "alice")
    bob = block_rw(float, "bob", write_config=BlockWriteConfig(settle_time_s=0.5))

    lf = LiveFit(Linear.fit(), "alice", "bob")

    fig, ax = plt.subplots()
    
    @subs_decorator(
        [
            LiveTable([bob.name, alice.name]),
            LiveFitPlot(lf, ax=ax, color="r", num_points=1000),
            LivePlot(y=alice.name, x=bob.name, ax=ax, marker="x", linestyle="none"),
        ]
    )
    def _inner() -> Generator[Msg, None, None]:
        yield from ensure_connected(bob, alice)
        yield from bp.scan([alice], bob, -5, 5, num=15)
        logger.blueskylogger.info("Some useful message")
    yield from _inner()

@jackbdoughty jackbdoughty changed the title Fixes issue found with linear fitting guess Fixes issues found with linear fitting guess function Oct 28, 2024
@Tom-Willemsen Tom-Willemsen merged commit 7063ad4 into main Oct 29, 2024
11 checks passed
@Tom-Willemsen Tom-Willemsen deleted the fixes_linear_fitting branch October 29, 2024 14:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants