Open CBroz1 opened 1 month ago
All these would be good to clean up as far as I know.
At @samuelbray32 's suggestion, I wrote a script to look at tables on shared prefixes, without a Spyglass class, with contents. They are listed at the end of the script below.
These seem to primarily be first drafts of tables that were later renamed. Unless there are objections, I plan to drop these tables as well.
Process
Using a sql command, I fetched tables with no rows, as recorded in the info schema. Some weren't actually empty, so I narrowed down the list by fetching with dj, and then looked for which items weren't represented in the package
Script
```python import inspect import pkgutil import sys import datajoint as dj from datajoint.user_tables import TableMeta from datajoint.utils import from_camel_case from tqdm import tqdm import spyglass from spyglass.utils.database_settings import SHARED_MODULES def empty_in_shared_module(full_table_name): if full_table_name.split(".")[0].split("_")[0] not in SHARED_MODULES: return False # private prefix if full_table_name.split(".")[1][0] == "~": # hidden table return False return len(dj.FreeTable(dj.conn(), full_table_name)) == 0 class_cache = dict() # Cache results to avoid re-importing modules sql_tbls = dict() # Cache for schema.list_tables() def load_cache(): for importer, modname, ispkg in tqdm( pkgutil.walk_packages(spyglass.__path__), desc="Loading cache", total=300, ): module = importer.find_module(modname).load_module(modname) if not hasattr(module, "schema"): continue database = module.schema.database if not class_cache.get(database): class_cache[database] = set() sql_tbls[database] = set() schema_list = module.schema.list_tables() sql_tbls[database].update(schema_list) for attr_name in getattr(module, "__dict__", []): if not isinstance(getattr(module, attr_name), TableMeta): continue if attr_name.startswith("_"): continue snake_case_name = from_camel_case(attr_name) if snake_case_name in schema_list: class_cache[database].add(from_camel_case(attr_name)) def class_exists_in_package(full_table_name): if not class_cache: load_cache() schema_name, table_name = full_table_name.split(".") schema_tables = class_cache.get(schema_name, []) return table_name in schema_tables my_query = """ select table_schema as database_name, table_name from information_schema.tables where table_type = 'BASE TABLE' and table_rows = 0 and table_schema not in('information_schema', 'sys', 'performance_schema', 'mysql') order by table_schema, table_name; """ mysql_empty = [".".join(t) for t in dj.conn().query(my_query).fetchall()] no_content = [name for name in mysql_empty if empty_in_shared_module(name)] no_class = [t for t in mysql_empty if not class_exists_in_package(t)] neither = list(set(no_content).intersection(set(no_class))) no_content_has_class = list(set(no_content).difference(set(no_class))) ```Resulting Lists
First pass with an older version of the script above, will update soon ```python no_content = [ "common_behav._head_dir", "common_behav._lin_pos", "common_behav._speed", "common_behav.merged_position", "common_behav.merged_position__method_two_position", "common_behav.merged_position__raw_position", "common_behav.method_two_position", "common_curation.__automatic_curation_sorting", "common_curation.__curated_spike_sorting", "common_curation.__curated_spike_sorting__unit", "common_curation.__selected_units", "common_curation.automatic_curation_parameters", "common_curation.automatic_curation_selection", "common_curation.curated_spike_sorting_selection", "common_curation.selected_units_parameters", "common_ephys.electrode_brain_region", "common_lab.__analysis_nwbfile_kachery", "common_lab.__nwbfile_kachery", "common_metrics.__quality_metrics", "common_metrics.metric_selection", "common_nwbfile.__analysis_nwbfile_kachery", "common_nwbfile.__nwbfile_kachery", "common_nwbfile.analysis_nwbfile_kachery", "common_nwbfile.analysis_nwbfile_kachery_selection", "common_nwbfile.nwbfile_kachery", "common_nwbfile.nwbfile_kachery_selection", "common_position.__position_video", "common_ripple.l_f_p_selection", "common_ripple.l_f_p_selection__l_f_p_electrode", "common_ripple.ripple_artifact_detection_selection", "common_session._experimenter_list", "common_session._experimenter_list__experimenter", "common_session.session_group_session", "common_sortingview.__sortingview_workspace__sortings", "common_spikesorting.__automatic_curation", "common_spikesorting.__curated_spike_sorting", "common_spikesorting.__curated_spike_sorting__unit", "common_spikesorting.__modify_sorting", "common_spikesorting.__spike_sorting", "common_spikesorting.__spike_sorting_workspace", "common_spikesorting.automatic_curation_selection", "common_spikesorting.curated_spike_sorting_selection", "common_spikesorting.modify_sorting_parameters", "common_spikesorting.modify_sorting_selection", "common_spikesorting.modify_sorting_selection__sortings_i_ds", "common_spikesorting.sorting", "common_spikesorting.sorting_i_d", "common_spikesorting.sorting_list", "common_spikesorting.sortings", "common_spikesorting.spike_sorting_artifact_parameters", "common_spikesorting.spike_sorting_filter_parameters", "common_task.apparatus", "common_usage.insert_error", "common_waveforms.__waveforms", "common_waveforms.waveform_selection", "decoding._decode_spikes_selection", "decoding._decode_spikes_selection__decode_spikes", "decoding.decode_spikes_selection", "decoding.decode_spikes_selection__decode_spikes", "decoding_clusterless.__multiunit_firing_rate", "decoding_clusterless.__multiunit_high_synchrony_events", "decoding_clusterless.mark_indicator_parameters", "decoding_sortedspikes.__my_sorted_spikes_indicator", "decoding_sortedspikes.__sorted_spikes_results", "lfp_imported._imported_l_f_p", "lfp_merge.l_f_p_output__imported_l_f_p", "lfp_v1.__l_f_p_band_artifact_detection", "lfp_v1._imported_l_f_p_v1", "lfp_v1.l_f_p_band_artifact_detection_parameters", "lfp_v1.l_f_p_band_artifact_detection_selection", "lfp_v1.l_f_p_band_artifact_removed_interval_list", "position_dlc_model.__d_l_c_model_evaluation", "position_dlc_selection.__d_l_c_pos_video", "position_linearization_merge.linearized_position_output__linearized_position_v0", "position_merge.__position_video", "position_merge.position_video_selection", "position_position.__position_video", "position_position.final_position__common_pos", "position_position.final_position__trodes_pos_v1", "position_position.position_video_selection", "position_trodes_position.__trodes_pos_v1", "position_v1_dlc_model.__d_l_c_model_evaluation", "position_v1_dlc_selection.__d_l_c_pos_video", "position_v1_trodes_position.__trodes_pos_video", "spikesorting_artifact.artifact_detection_parameter", "spikesorting_curation.__units", "spikesorting_curation.unit_inclusion_parameters", "spikesorting_group_v1.sorted_spikes_group__sort_group", "spikesorting_merge.unit_inclusion", "spikesorting_recording.__sort_group_targeted_location", "spikesorting_recording.electrode_brain_location", "spikesorting_recording.spike_sorting_preprocessing_parameter", "spikesorting_sorting.spike_sorter_parameter", "spikesorting_v1_unit_inclusion.imported_unit_inclusion_v1", ] no_class = [ "common_behav._head_dir", "common_behav._lin_pos", "common_behav._speed", "common_behav.merged_position", "common_behav.merged_position__method_two_position", "common_behav.merged_position__raw_position", "common_behav.method_two_position", "common_curation.__automatic_curation_sorting", "common_curation.__curated_spike_sorting__unit", "common_curation.__selected_units", "common_curation.selected_units_parameters", "common_lab.__nwbfile_kachery", "common_nwbfile.__nwbfile_kachery", "common_nwbfile.nwbfile_kachery", "common_nwbfile.nwbfile_kachery_selection", "common_ripple.l_f_p_selection__l_f_p_electrode", "common_ripple.ripple_artifact_detection_selection", "common_session._experimenter_list", "common_session._experimenter_list__experimenter", "common_sortingview.__sortingview_workspace__sortings", "common_spikesorting.__curated_spike_sorting__unit", "common_spikesorting.__modify_sorting", "common_spikesorting.__spike_sorting_workspace", "common_spikesorting.modify_sorting_parameters", "common_spikesorting.modify_sorting_selection", "common_spikesorting.modify_sorting_selection__sortings_i_ds", "common_spikesorting.sorting", "common_spikesorting.sorting_i_d", "common_spikesorting.sorting_list", "common_spikesorting.sortings", "common_spikesorting.spike_sorting_artifact_parameters", "common_spikesorting.spike_sorting_filter_parameters", "common_task.apparatus", "decoding._decode_spikes_selection", "decoding._decode_spikes_selection__decode_spikes", "decoding.decode_spikes_selection", "decoding.decode_spikes_selection__decode_spikes", "decoding_clusterless.__multiunit_firing_rate", "decoding_clusterless.__multiunit_high_synchrony_events", "decoding_clusterless.mark_indicator_parameters", "decoding_sortedspikes.__my_sorted_spikes_indicator", "decoding_sortedspikes.__sorted_spikes_results", "lfp_merge.l_f_p_output__imported_l_f_p", "lfp_v1.__l_f_p_band_artifact_detection", "lfp_v1._imported_l_f_p_v1", "lfp_v1.l_f_p_band_artifact_detection_parameters", "lfp_v1.l_f_p_band_artifact_detection_selection", "lfp_v1.l_f_p_band_artifact_removed_interval_list", "position_linearization_merge.linearized_position_output__linearized_position_v0", "position_position.final_position__common_pos", "position_position.final_position__trodes_pos_v1", "spikesorting_artifact.artifact_detection_parameter", "spikesorting_curation.__units", "spikesorting_group_v1.sorted_spikes_group__sort_group", "spikesorting_merge.unit_inclusion", "spikesorting_recording.__sort_group_targeted_location", "spikesorting_recording.electrode_brain_location", "spikesorting_recording.spike_sorting_preprocessing_parameter", "spikesorting_sorting.spike_sorter_parameter", "spikesorting_v1_unit_inclusion.imported_unit_inclusion_v1", ] neither = [ "common_spikesorting.sortings", "common_behav._head_dir", "decoding.decode_spikes_selection__decode_spikes", "common_curation.curated_spike_sorting_selection", "position_position.final_position__common_pos", "position_merge.__position_video", "lfp_v1.l_f_p_band_artifact_detection_selection", "spikesorting_group_v1.sorted_spikes_group__sort_group", "spikesorting_artifact.artifact_detection_parameter", "common_session._experimenter_list", "common_behav.merged_position__method_two_position", "decoding._decode_spikes_selection__decode_spikes", "common_nwbfile.analysis_nwbfile_kachery_selection", "common_spikesorting.__spike_sorting_workspace", "decoding.decode_spikes_selection", "spikesorting_curation.__units", "common_position.__position_video", "common_waveforms.__waveforms", "decoding_sortedspikes.__sorted_spikes_results", "common_spikesorting.sorting", "common_nwbfile.nwbfile_kachery_selection", "position_position.__position_video", "common_curation.__automatic_curation_sorting", "common_curation.automatic_curation_parameters", "spikesorting_recording.spike_sorting_preprocessing_parameter", "position_v1_dlc_selection.__d_l_c_pos_video", "common_spikesorting.__curated_spike_sorting", "common_spikesorting.sorting_i_d", "position_v1_dlc_model.__d_l_c_model_evaluation", "common_metrics.metric_selection", "common_nwbfile.nwbfile_kachery", "position_dlc_selection.__d_l_c_pos_video", "common_curation.automatic_curation_selection", "spikesorting_sorting.spike_sorter_parameter", "common_ripple.ripple_artifact_detection_selection", "common_spikesorting.__curated_spike_sorting__unit", "common_behav.merged_position__raw_position", "common_spikesorting.__modify_sorting", "common_spikesorting.__spike_sorting", "common_curation.selected_units_parameters", "common_nwbfile.__nwbfile_kachery", "lfp_v1.l_f_p_band_artifact_removed_interval_list", "common_behav.merged_position", "position_position.position_video_selection", "lfp_v1.l_f_p_band_artifact_detection_parameters", "common_spikesorting.sorting_list", "spikesorting_v1_unit_inclusion.imported_unit_inclusion_v1", "common_curation.__curated_spike_sorting", "decoding_clusterless.mark_indicator_parameters", "common_curation.__selected_units", "position_dlc_model.__d_l_c_model_evaluation", "spikesorting_recording.__sort_group_targeted_location", "common_spikesorting.modify_sorting_selection__sortings_i_ds", "common_metrics.__quality_metrics", "lfp_v1._imported_l_f_p_v1", "position_position.final_position__trodes_pos_v1", "position_linearization_merge.linearized_position_output__linearized_position_v0", "common_ripple.l_f_p_selection__l_f_p_electrode", "decoding_clusterless.__multiunit_firing_rate", "spikesorting_recording.electrode_brain_location", "decoding_clusterless.__multiunit_high_synchrony_events", "common_spikesorting.spike_sorting_artifact_parameters", "common_sortingview.__sortingview_workspace__sortings", "lfp_v1.__l_f_p_band_artifact_detection", "common_behav._lin_pos", "position_trodes_position.__trodes_pos_v1", "common_ripple.l_f_p_selection", "common_curation.__curated_spike_sorting__unit", "common_waveforms.waveform_selection", "common_behav.method_two_position", "common_spikesorting.__automatic_curation", "common_task.apparatus", "common_spikesorting.automatic_curation_selection", "position_v1_trodes_position.__trodes_pos_video", "spikesorting_merge.unit_inclusion", "common_lab.__analysis_nwbfile_kachery", "common_behav._speed", "common_spikesorting.spike_sorting_filter_parameters", "common_nwbfile.__analysis_nwbfile_kachery", "lfp_imported._imported_l_f_p", "common_lab.__nwbfile_kachery", "decoding_sortedspikes.__my_sorted_spikes_indicator", "decoding._decode_spikes_selection", "common_nwbfile.analysis_nwbfile_kachery", "lfp_merge.l_f_p_output__imported_l_f_p", "common_session._experimenter_list__experimenter", "common_spikesorting.curated_spike_sorting_selection", "common_spikesorting.modify_sorting_parameters", "common_spikesorting.modify_sorting_selection", ] no_content_has_class = [ "spikesorting_curation.unit_inclusion_parameters", "common_session.session_group_session", "common_ephys.electrode_brain_region", "common_usage.insert_error", "position_merge.position_video_selection", ] ```Result
There are ....
common_analytic_signal
: last used by Xulu 05/23common_artifact
: last used by Alison 11/22common_backup
: last used by Kyu 02/22common_curation
: last used by Eric 02/22common_metrics
: last used by Jen 03/22common_sortingview
: last used by Alison 11/22common_waveform
: last used by Jen 03/22decoding
: last used by Eric 05/23position_position
: last used by Daniel 04/23common_behav._head_dir
). See 'neither' in list above.spikesorting_curation.unit_inclusion_parameters
: declared 07/22common_session.session_group_session
: declared 03/22common_ephys.electrode_brain_region
: declared 05/22position_merge.position_video_selection
: 04/23common_usage.insert_error
: declared 02/24 - worth preserving for outside-lab insert errors?Proposed
0.6.0
. Inserts into these tables can be overwritten to temporarily launch a deprecation warning and then log incommon_usage
to let us know they're being used.