umyelab / LabGym

Quantify user-defined behaviors.
GNU General Public License v3.0
64 stars 5 forks source link

Refactor `tools.estimate_constants()` #85

Closed rohansatapathy closed 8 months ago

rohansatapathy commented 8 months ago

This pull request refactors estimate_constants() into separate functions. Since extracting (or loading) the backgrounds, getting the animal area, and getting the optogenetic stimulation time are three different processes, I split them into four different functions to illustrate that.

At first, I made no changes to analyzebehaviors.py and focused on making the estimate_constants() function behave exactly the same, while doing the refactoring in tools.py. After I made sure everything worked properly, I then changed the calling code in analyzebehaviors.py, which made it more clear which specific constants were being estimated.

Each of the new functions contains type signatures and docstrings, both of which help LabGym developers understand what each function does. The type signatures aren't enforced by Python, but they help the language tooling in IDEs like VS Code catch common errors like forgetting to check for a None value or passing the wrong data type to a function. I've chosen to write the docstrings according to Google's Python Style Guide since it's format seems the most readable to me.