coh_df = pd.DataFrame(coh_matrix["cut_coh_table"], columns=None, index=None)
chan_df = pd.DataFrame(coh_matrix["chanmatrix"], columns=None, index=None)
def _get_unique(comb_index : int):
''' Finds and returns an array of unique channels and
the number of times those channels were counted.
Parameters
----------
comb_index : int
Index number for which comb is being used
Returns
-------
curr_chan_uq : 1darray
A 1darray of the unique channels that captured the
frequencies of the current comb
curr_chan_count : 1darray
A 1darray filled with the counts of each corresponding
channel in curr_chan_uq
'''
# Gets the bin indexes for a single comb set based off comb_index
bin_index = slt.match_bins(coh_matrix["frequencies"], freqs[combs_dict[combs_list[comb_index]]])
# Splits coh_df and chan_df index-wise by bin_index
coh_arr = np.array(coh_df.loc[sorted(bin_index)])
chan_arr = np.array(chan_df.loc[sorted(bin_index)])
# Returns an array containing only channels where
# their corresponding coherence value is over 0.05
chan_arr_sort = chan_arr[coh_arr > 0.05]
# Returns two arrays containing the unique channels found as well as
# their counts
curr_chan_uq, curr_chan_count = np.unique(chan_arr_sort, return_counts=True)
return curr_chan_uq, curr_chan_count
... # bunch of other code that never uses coh_df or chan_df
del coh_df, chan_df
The above code is a function (used to get unique data points) within a module. Right now I'm creating the dfs needed for this before the function is defined, but never use them outside of said function. I'm wondering if it would be better to just create and delete the dfs within the function (and therefore every time it is run), or if I should keep it as is.