Skip to content
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

Fix hardcoding of MAD in return_good_lfp_trial_inds in lfp_processing module #324

Open
kmaigler opened this issue Jan 23, 2025 · 2 comments

Comments

@kmaigler
Copy link

No description provided.

@abuzarmahmood
Copy link
Collaborator

Add a default value as the argument

@abuzarmahmood
Copy link
Collaborator

The issue involves addressing the hardcoding of the MAD (Median Absolute Deviation) threshold in the return_good_lfp_trial_inds function within the lfp_processing module of the blech_clust repository. The following suggestions and changes were made:

  1. File to Modify:

    • File: /home/exouser/Desktop/blech_github_bot/src/repos/katzlabbrandeis/blech_clust/utils/ephys_data/lfp_processing.py
    • Description: This file contains the return_good_lfp_trial_inds function, which is responsible for returning a boolean array of good trials based on a MAD threshold. The function currently has a hardcoded deviation threshold value of 3.
  2. Suggested Code Change:

    • Modify the return_good_lfp_trial_inds function to include a parameter for the deviation threshold, allowing users to specify a different value if needed. This will replace the hardcoded value and improve the function's usability.
  3. Updated Code:

    def return_good_lfp_trial_inds(data, MAD_threshold=3):
        """
        Return boolean array of good trials (for all channels) based on MAD threshold
        Remove trials based on deviation from median LFP per trial
    
        Inputs:
            data : shape (n_channels, n_trials, n_timepoints)
            MAD_threshold : number of MADs to use as threshold for individual timepoints
    
        Outputs:
            good_trials_bool : boolean array of good trials
        """
        lfp_median = np.median(data, axis=1)
        lfp_MAD = MAD(data, axis=1)
        # Use total deviation per trial scaled by MAD to remove trial
        mean_trial_deviation = np.mean(
            np.abs(data - lfp_median[:, np.newaxis, :])/lfp_MAD[:, None], axis=2)
        deviation_median = np.median(mean_trial_deviation, axis=1)
        deviation_MAD = MAD(mean_trial_deviation, axis=1)
        fin_deviation_threshold = deviation_median + MAD_threshold * deviation_MAD
        # Remove trials with high deviation
        good_trials_bool = mean_trial_deviation < fin_deviation_threshold[:, np.newaxis]
        # Take only trials good for both regions
        good_trials_bool = np.all(good_trials_bool, axis=0)
        return good_trials_bool
  4. Specific Changes:

    • Replace the hardcoded deviation_threshold = 3 with the MAD_threshold parameter in the calculation of fin_deviation_threshold.

This change allows the function to use a default MAD threshold of 3, but also provides flexibility for users to specify a different threshold if needed.

TERMINATE


This response was automatically generated by blech_bot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants