-
Notifications
You must be signed in to change notification settings - Fork 53
add References
object to PlotArea
, other cleanup, better garbage collection
#467
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
e56c962
add References object to PlotArea, other cleanup
kushalkolar 7be7407
more cleanup
kushalkolar 8b82e89
black
kushalkolar b26a70c
add refcount utility to References, fix Graphic.name setter bug
kushalkolar ca435df
actually fix Graphic.name setter bug
kushalkolar 6a02647
more generalized event handler cleanup in Graphic
kushalkolar aed5fb1
all gc works now
kushalkolar c7bab03
black
kushalkolar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,200 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "9dfba6cf-38af-4003-90b9-463c0cb1063f", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import fastplotlib as fpl\n", | ||
"import numpy as np\n", | ||
"import pytest" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "7552eedc-3b9b-4682-8e3b-7d44e0e5510d", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"def test_references(plot_objects):\n", | ||
" for i in range(len(plot_objects)):\n", | ||
" with pytest.raises(ReferenceError) as failure:\n", | ||
" plot_objects[i]\n", | ||
" pytest.fail(f\"GC failed for object: {objects[i]}\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "948108e8-a4fa-4dc7-9953-a956428128cf", | ||
"metadata": {}, | ||
"source": [ | ||
"# Add graphics and selectors, add feature event handlers, test gc occurs" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "3d96bf14-b484-455e-bcd7-5b2fe7b45fb4", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"xs = np.linspace(0, 20 * np.pi, 1_000)\n", | ||
"ys = np.sin(xs)\n", | ||
"zs = np.zeros(xs.size)\n", | ||
"\n", | ||
"points_data = np.column_stack([xs, ys, zs])\n", | ||
"\n", | ||
"line_collection_data = [points_data[:, 1].copy() for i in range(10)]\n", | ||
"\n", | ||
"img_data = np.random.rand(2_000, 2_000)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "284b83e1-8cfc-4105-b7c2-6214137dab31", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"gp = fpl.GridPlot((2, 2))\n", | ||
"\n", | ||
"line = gp[0, 0].add_line(points_data, name=\"line\")\n", | ||
"scatter = gp[0, 1].add_scatter(points_data.copy(), name=\"scatter\")\n", | ||
"line_stack = gp[1, 0].add_line_stack(line_collection_data, name=\"line-stack\")\n", | ||
"image = gp[1, 1].add_image(img_data, name=\"image\")\n", | ||
"\n", | ||
"linear_sel = line.add_linear_selector(name=\"line_linear_sel\")\n", | ||
"linear_region_sel = line.add_linear_region_selector(name=\"line_region_sel\")\n", | ||
"\n", | ||
"linear_sel2 = line_stack.add_linear_selector(name=\"line-stack_linear_sel\")\n", | ||
"linear_region_sel2 = line_stack.add_linear_region_selector(name=\"line-stack_region_sel\")\n", | ||
"\n", | ||
"linear_sel_img = image.add_linear_selector(name=\"image_linear_sel\")\n", | ||
"linear_region_sel_img = image.add_linear_region_selector(name=\"image_linear_region_sel\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "bb2083c1-f6b7-417c-86b8-9980819917db", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"def feature_changed_handler(ev):\n", | ||
" pass\n", | ||
"\n", | ||
"\n", | ||
"objects = list()\n", | ||
"for subplot in gp:\n", | ||
" objects += subplot.objects\n", | ||
"\n", | ||
"\n", | ||
"for g in objects:\n", | ||
" for feature in g.feature_events:\n", | ||
" if isinstance(g, fpl.LineCollection):\n", | ||
" continue # skip collections for now\n", | ||
" \n", | ||
" f = getattr(g, feature)\n", | ||
" f.add_event_handler(feature_changed_handler)\n", | ||
"\n", | ||
"gp.show()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "ba9fffeb-45bd-4a0c-a941-e7c7e68f2e55", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"gp.clear()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "e33bf32d-b13a-474b-92ca-1d1e1c7b820b", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"test_references(objects)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "8078a7d2-9bc6-48a1-896c-7e169c5bbdcf", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"movies = [np.random.rand(100, 100, 100) for i in range(6)]\n", | ||
"\n", | ||
"iw = fpl.ImageWidget(movies)\n", | ||
"\n", | ||
"# add some events onto all the image graphics\n", | ||
"for g in iw.managed_graphics:\n", | ||
" for f in g.feature_events:\n", | ||
" fea = getattr(g, f)\n", | ||
" fea.add_event_handler(feature_changed_handler)\n", | ||
"\n", | ||
"iw.show()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "189bcd7a-40a2-4e84-abcf-c334e50f5544", | ||
"metadata": {}, | ||
"source": [ | ||
"# Test that setting new data with different dims clears old ImageGraphics" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "38557b63-997f-433a-b744-e562e30be6ae", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"old_graphics = iw.managed_graphics\n", | ||
"\n", | ||
"new_movies = [np.random.rand(100, 200, 200) for i in range(6)]\n", | ||
"\n", | ||
"iw.set_data(new_movies)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "59e3c193-5672-4a66-bdca-12f1dd675d32", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"test_references(old_graphics)" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3 (ipykernel)", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.11.3" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.