Skip to content

Add test and delete lint errors#61

Open
theodchrn wants to merge 16 commits intomainfrom
dev/exploreResults
Open

Add test and delete lint errors#61
theodchrn wants to merge 16 commits intomainfrom
dev/exploreResults

Conversation

@theodchrn
Copy link
Collaborator

  • clean: remove old notebooks
  • fix: typos and minor errors in dealing w bayes matrices
  • add: tests and possibility to save and load datasets to tfrec and parquet format
  • improve: plotting modules
  • improve: test units
  • change global classes behaviour: no need for duplicate in Mouse_Results, remove dependency on window size and fix copy/paste issues for datahelper (different phases kepts the same Ref)
  • add: possibility to randomize the spikes inside the dataset for control
  • add: helper function for comparing bayes and ann
  • add: data helper behaviour without windowsize ms
  • fix: lots of typos and ruff linting issues

Copilot AI review requested due to automatic review settings February 4, 2026 15:16
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR performs extensive code cleanup and adds new functionality for dataset management. The main objectives are to fix linting errors, remove unused code, and add capabilities for saving/loading datasets in TFRecord and Parquet formats.

Changes:

  • Fixed numerous linting issues: replaced bare except clauses with specific exceptions, converted lambda functions to named functions, fixed type comparisons to use isinstance()
  • Removed old notebooks and deprecated code (old_code.py with ~1800 lines)
  • Added dataset saving/loading functionality for TFRecord and Parquet formats
  • Refactored global classes to remove window size dependencies and fix copy/paste issues
  • Added spike randomization capability for control experiments
  • Improved plotting modules and test coverage

Reviewed changes

Copilot reviewed 31 out of 38 changed files in this pull request and generated 26 comments.

Show a summary per file
File Description
uv.lock, pyproject.toml Added pyarrow, pdf2image, python-pptx dependencies
tests/test_*.py Improved test coverage, removed unused variables, added dataset saving tests
runAllMice.py Logic changes for force flag, mouse filtering, experiment selection; added dry-run flag
neuroencoders/utils/* Extensive linting fixes, improved exception handling, refactored global classes
neuroencoders/fullEncoder/an_network.py Added dataset save/load functionality, model rebuilding methods
neuroencoders/simpleBayes/decode_bayes.py Added spike loading methods, fixed lambda to named function
neuroencoders/importData/* Linting fixes, improved GUI time formatting, added linear spike sorting
neuroencoders/resultAnalysis/* Removed old_code.py, updated function calls for API changes
neuroEncoder Updated function calls, removed try-except wrappers, added debug print
.pre-commit-config.yaml Fixed YAML formatting, removed --exit-zero from ruff

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 247 to 249
helper.get_true_target(
l_function, in_place=True, show=show_figures, speedMask=True
windowSizeMS, l_function, in_place=True, show=show_figures, speedMask=True
)
Copy link

Copilot AI Feb 4, 2026

Choose a reason for hiding this comment

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

Incorrect function call: The method signature for get_true_target was changed to accept windowSizeMS as the first parameter (line 436-438), but this call doesn't provide it. This will cause a TypeError since windowSizeMS is now a required positional argument. The call should be: helper.get_true_target(windowSizeMS, l_function, in_place=True, show=show_figures, speedMask=True)

Copilot uses AI. Check for mistakes.
Comment on lines +529 to 547
if not hasattr(
self.trainerBayes, "spikeMatTimes"
) or not hasattr(self.trainerBayes, "spikeMat"):
raise ValueError(
"""
trainerBayes does not have spikeMatTimes or spikeMat attributes needed to extract spike counts.
Make sure to run decoding with extract_spike_counts=True first. You can run trainerBayes.train_order_by_pos.
"""
)
total_count, _ = extract_spike_counts_keops(
timesBayes[-1], self.trainerBayes.spikeMatTimes, ws / 1000
)
total_spikes_count.append(total_count)
matrix_count, _ = extract_spike_counts_from_matrix(
matrix_count, _ = extract_spike_counts_matrix_keops(
timesBayes[-1],
self.trainerBayes.spikeMat,
self.trainerBayes.spikeMatLabels,
self.trainerBayes.spikeMatTimes,
ws / 1000,
)
Copy link

Copilot AI Feb 4, 2026

Choose a reason for hiding this comment

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

Missing null handling: The try-except at lines 529-537 attempts to extract spike counts, but if trainerBayes.spikeMatTimes or trainerBayes.spikeMat don't exist (as checked in lines 529-531), the code will raise a ValueError but then continues to try accessing these attributes at lines 538-547. The control flow should either return early after raising the ValueError or ensure these attributes exist before proceeding.

Copilot uses AI. Check for mistakes.
runAllMice.py Outdated
"--target",
target_bayes,
"--flat_prior",
# "--flat_prior",
Copy link

Copilot AI Feb 4, 2026

Choose a reason for hiding this comment

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

Commented out critical parameter: The '--flat_prior' flag has been commented out at line 251. This changes the behavior of the Bayesian decoder. If this is intentional, consider removing the line entirely or adding a comment explaining why. If it's temporary for testing, it should be uncommented before merging.

Copilot uses AI. Check for mistakes.

# regarding data augmentation
self.dataAugmentation = kwargs.pop("dataAugmentation", True)
self.dataAugmentation = kwargs.pop("dataAugmentation", False)
Copy link

Copilot AI Feb 4, 2026

Choose a reason for hiding this comment

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

The dataAugmentation default has been changed from True to False (line 1706). This is a significant behavior change that will affect model training. Ensure this is intentional and documented, as it may impact model performance. Consider whether this should be mentioned in the PR description or release notes.

Suggested change
self.dataAugmentation = kwargs.pop("dataAugmentation", False)
self.dataAugmentation = kwargs.pop("dataAugmentation", True)

Copilot uses AI. Check for mistakes.
Comment on lines +865 to 867
self.xyOutput, positions = self._get_XYOutput_morph_maze(
positions, self.shock_zone_mask, self.ref, self.ratioIMAonREAL
)
Copy link

Copilot AI Feb 4, 2026

Choose a reason for hiding this comment

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

Missing return statement: The function _get_XYOutput_morph_maze now returns both XYOutput and positions (line 1027), but the assignment at line 865 captures only xyOutput, discarding the updated positions. This should be: self.xyOutput, positions = self._get_XYOutput_morph_maze(...). Without this change, the positions variable will not reflect any transformations applied inside the function.

Copilot uses AI. Check for mistakes.
try:
ls[dim][2][iaxis].remove()
except:
except (AttributeError, KeyError):
Copy link

Copilot AI Feb 4, 2026

Choose a reason for hiding this comment

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

'except' clause does nothing but pass and there is no explanatory comment.

Copilot uses AI. Check for mistakes.
try:
ls[dim][2].remove()
except:
except (AttributeError, KeyError):
Copy link

Copilot AI Feb 4, 2026

Choose a reason for hiding this comment

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

'except' clause does nothing but pass and there is no explanatory comment.

Copilot uses AI. Check for mistakes.
try:
l3.remove()
except:
except (AttributeError, KeyError):
Copy link

Copilot AI Feb 4, 2026

Choose a reason for hiding this comment

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

'except' clause does nothing but pass and there is no explanatory comment.

Copilot uses AI. Check for mistakes.
try:
mask = indices == frame
except:
except (TypeError, AttributeError):
Copy link

Copilot AI Feb 4, 2026

Choose a reason for hiding this comment

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

This statement is unreachable.

Copilot uses AI. Check for mistakes.
try:
mask = indices == frame
except:
except (TypeError, AttributeError):
Copy link

Copilot AI Feb 4, 2026

Choose a reason for hiding this comment

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

This statement is unreachable.

Copilot uses AI. Check for mistakes.
@theodchrn
Copy link
Collaborator Author

@copilot open a new pull request to apply changes based on the comments in this thread

Copy link
Contributor

Copilot AI commented Feb 5, 2026

@theodchrn I've opened a new pull request, #62, to work on those changes. Once the pull request is ready, I'll request review from you.

Copilot AI and others added 5 commits February 5, 2026 11:26
…ming

Co-authored-by: theodchrn <48409582+theodchrn@users.noreply.github.com>
…g builtin

Co-authored-by: theodchrn <48409582+theodchrn@users.noreply.github.com>
…nused code

Co-authored-by: theodchrn <48409582+theodchrn@users.noreply.github.com>
Co-authored-by: theodchrn <48409582+theodchrn@users.noreply.github.com>
Address PR review comments: remove debug code, fix variable shadowing, improve error handling
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.

2 participants