Closed alexpiet closed 3 years ago
Might the fix be as simple as changing the @property
decorator into @cached_property
?
I'll investigate.
Oh, the @cached_property
decorator is only available starting in python 3.8. The SDK explicitly does not support 3.8, so we can't use it yet.
I followed the pattern in ophys/response_analysis/response_analysis.py to apply the LazyLoadable method to events. See commit 2591f10be889845a45fc7c8c81b8870075c04aea
Here's a screenshot of a notebook showing that the second time events is loaded, the load time is now under 1 ms:
@alexpiet, does this seem like a satisfactory solution?
Whenever we're able to upgrade to Python 3.8 (dependent on when the AllenSDK begins supporting it, see https://github.com/AllenInstitute/AllenSDK/issues/1652, https://github.com/AllenInstitute/AllenSDK/issues/1643, https://github.com/AllenInstitute/AllenSDK/issues/1610, https://github.com/AllenInstitute/AllenSDK/pull/1611), we should replace these LazyLoadable
calls, and probably many of the @property
decorators, with the newly supported @cached_property
decorator.
That seems great!
In reality my only concern was I didnt like that it printed a message "getting LO events now" twice. I would have been happy removing the print statement. :D
Great! Closing this issue. Note that this change is part of the epic dev
branch PR #693.
In the file visual_behavior/data_access/loading.py the
events()
function doesn't cache the events dataframe, it loads it from file every time the function is called. Further, when it loads it creates the events dataframe, it actually loads the events file twice.