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

ENH/DEV: Formula Viewer for Archive Viewer #1095

Merged
merged 15 commits into from
Aug 29, 2024

Conversation

aksharsarvesh
Copy link
Contributor

@aksharsarvesh aksharsarvesh commented Jul 22, 2024

Created class FormulaCurveItem. This accepts a formula (in the form of a string) and a dictionary of string : BasePlotCurveItem and populates a new data buffer with the function of the data being passed in. Can be used to graph functions of other functions, by passing FormulaCurveItems in the dictionary and referencing them in the formula string.

This is useful for the Archive Viewer because one of the requested functionalities is the ability to graph a function of one or more PVs rather than graphing only PVs themselves. As the new class extends BasePlotCurveItem, this is usable in other contexts where BasePlotCurveItems are being used.

@aksharsarvesh aksharsarvesh changed the title Formula Viewer for Archive Viewer ENH/DEV: Formula Viewer for Archive Viewer Jul 22, 2024
@aksharsarvesh aksharsarvesh force-pushed the Formula-Viewer branch 9 times, most recently from 9b4365c to 6617140 Compare July 22, 2024 23:02
@aksharsarvesh aksharsarvesh force-pushed the Formula-Viewer branch 4 times, most recently from a3e8d88 to d41f1b1 Compare July 23, 2024 16:41
@aksharsarvesh
Copy link
Contributor Author

Hi there @YektaY @nstelter-slac @jbellister-slac I was wondering if one or more of you would be free to look at this when you get the chance? Hoping to finish this because I have a couple of other branches that are dependent on this. Thanks so much in advance!

@ZLLentz
Copy link
Member

ZLLentz commented Jul 29, 2024

I'm not one of the at-mentions, but I'm a bit confused by this PR because the documentation is sparse. What's the expected usage here? Why is this implemented strictly for the archive viewer, rather than being implemented more broadly like the calc plugin is? What kinds of new/better/easier displays can we make with this PR?

I think having an explanation in the PR description and/or an update to the PyDM documentation pages related to this feature as part of the PR would go a long way in making this reviewable.

@aksharsarvesh
Copy link
Contributor Author

Hi @ZLLentz, yes sorry the documentation is sparse. I'll add to it soon, but I thought I'd respond first.

What's the expected usage here? Why is this implemented strictly for the archive viewer, rather than being implemented more broadly like the calc plugin is?

One of the requested functionalities on the archive viewer was the ability to graph functions of PVs as opposed to just the PVs themselves. Currently, my project is focused on enhancing the archive viewer, so I made changes under that context.

I am happy to broaden that context to support usage outside of the archive viewer - would you have recommendations/suggestions for what you would like that to look like?. The FormulaCurveItem class extends a BasePlotCurveItem, which means tools that use baseplot will also be able to use the formulas.

Currently we expect archived data, so one fix would be removing that expectation such that formulas could be used with timeplots as well.

What kinds of new/better/easier displays can we make with this PR?

If other projects would ever need the ability to graph functions of PVs, this class could be useful for them.

@aksharsarvesh
Copy link
Contributor Author

aksharsarvesh commented Aug 1, 2024

Ok, thank you very much. I think I am ready for review fully now @nstelter-slac

Copy link
Collaborator

@nstelter-slac nstelter-slac left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice patch! sry for the delay

added some suggestions I had, mainly I think there is some stuff that could make the main logic part a bit more readable and therefore maintainable.

lets try to get at least one other reviewer on this before we merge

thanks!

pydm/widgets/archiver_time_plot_editor.py Outdated Show resolved Hide resolved
examples/archiver_time_plot/formula_curve_example.py Outdated Show resolved Hide resolved
pydm/widgets/archiver_time_plot.py Outdated Show resolved Hide resolved
examples/archiver_time_plot/formula_curve_example.py Outdated Show resolved Hide resolved
examples/archiver_time_plot/formula_curve_example.py Outdated Show resolved Hide resolved
pydm/widgets/archiver_time_plot.py Outdated Show resolved Hide resolved
pydm/widgets/archiver_time_plot.py Outdated Show resolved Hide resolved
pydm/widgets/archiver_time_plot.py Show resolved Hide resolved
pydm/widgets/archiver_time_plot.py Outdated Show resolved Hide resolved
pydm/widgets/archiver_time_plot.py Outdated Show resolved Hide resolved
examples/archiver_time_plot/formula_curve_example.py Outdated Show resolved Hide resolved
pydm/widgets/archiver_time_plot.py Show resolved Hide resolved
pydm/widgets/archiver_time_plot.py Show resolved Hide resolved
pydm/widgets/archiver_time_plot.py Outdated Show resolved Hide resolved
pydm/widgets/archiver_time_plot.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@jbellister-slac jbellister-slac left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding the additional context to the PR description, and thanks also for your patience while we take a look at this. It is looking very good!

My main thought on the first pass through is that there's quite a lot of data processing happening in a GUI widget here - I think most of it could be potentially moved to the data plugin layer.

One possible way of putting this together would be to use the calc plugin prefix. An end user can then enter in a formula like here, this example only uses a single PV but multiple PVs are fine too:

<string>{&quot;y_channel&quot;: &quot;calc://circley?angle=ca://DEMO:ANGLE&amp;expr=math.sin(math.radians(180-angle))&quot;, &quot;x_channel&quot;: &quot;calc://circleX?angle=ca://DEMO:ANGLE&amp;expr=-1*math.cos(math.radians(180-angle))&quot;, &quot;name&quot;: &quot;Angle&quot;, &quot;color&quot;: &quot;#ffd509&quot;, &quot;lineStyle&quot;: 0, &quot;lineWidth&quot;: 5, &quot;symbol&quot;: &quot;o&quot;, &quot;symbolSize&quot;: 5, &quot;redraw_mode&quot;: 3, &quot;buffer_size&quot;: 1}</string>

The archiver_plugin would need to be modified to handle this case (using the code you've already written). Then the archiver_time_plot becomes simpler after this as it can just say give me the result of this calculation between these PVs and display it. It no longer has to maintain its own list/dict of curve items for its calculations, that's all handled for it now. The live data functionality is also free at that point since it's just already what the time plot does using the calc plugin, and maybe the new FormulaCurveItem can just inherit most of its functionality from ArchivePlotCurveItem at that point. I think this could be cleaner and easier to maintain. And makes it easier if other widgets or clients want the same functionality.

That said, it might be easiest to get some of these PRs merged in before any potential refactor so the relevant code is all moved at once. And I might still need to get some more context to fully understand the precise use case that we're going for here since it looks like it involves the archiver application built on top of PyDM. But the code looks great so far and works well! This will be nice functionality to add.

pydm/widgets/timeplot.py Outdated Show resolved Hide resolved
pydm/widgets/archiver_time_plot.py Outdated Show resolved Hide resolved
@jbellister-slac
Copy link
Collaborator

Also if it would be helpful, I'm happy to drop by early next week to chat in person about any of this, or on zoom would be fine too.

@aksharsarvesh
Copy link
Contributor Author

Texting you on Slack about meeting next week for this! Thank you

Copy link
Collaborator

@YektaY YektaY left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me

@YektaY YektaY merged commit 8fff1fa into slaclab:master Aug 29, 2024
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants