-
Notifications
You must be signed in to change notification settings - Fork 1
Visualization cache #224
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
Visualization cache #224
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
0035d8c
More efficient dataframe creation from proxy model
PaulJonasJost 57af072
Dataframe caching, should reduce calls to proxy by ~50%
PaulJonasJost 852f5b3
Function for proxy connections + PEtab constants usage
PaulJonasJost 4975356
Update src/petab_gui/views/utils.py
PaulJonasJost be211f0
Merge branch 'main' into visualization_cache
PaulJonasJost ef8562e
fixed problem with updating
PaulJonasJost 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
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 |
|---|---|---|
| @@ -1,45 +1,65 @@ | ||
| import pandas as pd | ||
| from petab.v1.C import ( | ||
| CONDITION_ID, | ||
| MEASUREMENT, | ||
| OBSERVABLE_ID, | ||
| PARAMETER_ID, | ||
| SIMULATION, | ||
| TIME, | ||
| X_OFFSET, | ||
| Y_OFFSET, | ||
| ) | ||
| from PySide6.QtCore import Qt | ||
|
|
||
|
|
||
| def proxy_to_dataframe(proxy_model): | ||
| """Convert Proxy Model to pandas DataFrame.""" | ||
| rows = proxy_model.rowCount() | ||
| cols = proxy_model.columnCount() | ||
|
|
||
| if rows <= 1: # <=1 due to "New row..." in every table | ||
| return pd.DataFrame() | ||
|
|
||
| headers = [proxy_model.headerData(c, Qt.Horizontal) for c in range(cols)] | ||
| data = [] | ||
|
|
||
| # Pre-allocate list of lists (faster than dicts) | ||
| data = [] | ||
| for r in range(rows - 1): | ||
| row = {headers[c]: proxy_model.index(r, c).data() for c in range(cols)} | ||
| for key, value in row.items(): | ||
| if isinstance(value, str) and value == "": | ||
| row[key] = None | ||
| row = [] | ||
| for c in range(cols): | ||
| value = proxy_model.index(r, c).data() | ||
| # Convert empty strings to None | ||
| row.append( | ||
| None if (isinstance(value, str) and value == "") else value | ||
| ) | ||
| data.append(row) | ||
|
|
||
| if not data: | ||
| return pd.DataFrame() | ||
| if proxy_model.source_model.table_type == "condition": | ||
| data = pd.DataFrame(data).set_index("conditionId") | ||
| elif proxy_model.source_model.table_type == "observable": | ||
| data = pd.DataFrame(data).set_index("observableId") | ||
| elif proxy_model.source_model.table_type == "parameter": | ||
| data = pd.DataFrame(data).set_index("parameterId") | ||
| elif proxy_model.source_model.table_type == "measurement": | ||
| # turn measurement and time to float | ||
| data = pd.DataFrame(data) | ||
| data["measurement"] = data["measurement"].astype(float) | ||
| data["time"] = data["time"].astype(float) | ||
| elif proxy_model.source_model.table_type == "simulation": | ||
| # turn simulation and time to float | ||
| data = pd.DataFrame(data) | ||
| data["simulation"] = data["simulation"].astype(float) | ||
| data["time"] = data["time"].astype(float) | ||
| elif proxy_model.source_model.table_type == "visualization": | ||
| data = pd.DataFrame(data) | ||
| if "xOffset" in data.columns: | ||
| data["xOffset"] = data["xOffset"].astype(float) | ||
| if "yOffset" in data.columns: | ||
| data["yOffset"] = data["yOffset"].astype(float) | ||
| else: | ||
| data = pd.DataFrame(data) | ||
|
|
||
| return data | ||
|
|
||
| # Create DataFrame in one shot | ||
| df = pd.DataFrame(data, columns=headers) | ||
|
|
||
| # Apply type-specific transformations | ||
| table_type = proxy_model.source_model.table_type | ||
|
|
||
| if table_type == "condition": | ||
| df = df.set_index(CONDITION_ID) | ||
| elif table_type == "observable": | ||
| df = df.set_index(OBSERVABLE_ID) | ||
| elif table_type == "parameter": | ||
| df = df.set_index(PARAMETER_ID) | ||
| elif table_type == "measurement": | ||
| # Use pd.to_numeric with errors='coerce' for robust conversion | ||
| df[MEASUREMENT] = pd.to_numeric(df[MEASUREMENT], errors="coerce") | ||
| df[TIME] = pd.to_numeric(df[TIME], errors="coerce") | ||
| elif table_type == "simulation": | ||
| df[SIMULATION] = pd.to_numeric(df[SIMULATION], errors="coerce") | ||
| df[TIME] = pd.to_numeric(df[TIME], errors="coerce") | ||
| elif table_type == "visualization": | ||
| if X_OFFSET in df.columns: | ||
| df[X_OFFSET] = pd.to_numeric(df[X_OFFSET], errors="coerce") | ||
| if Y_OFFSET in df.columns: | ||
| df[Y_OFFSET] = pd.to_numeric(df[Y_OFFSET], errors="coerce") | ||
|
|
||
| return df | ||
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.