<jupyter_start><jupyter_text>1D Clusterless Classifier<jupyter_code>clusterless_classifier_1D = ClusterlessClassifier(
    place_bin_size=place_bin_size,
    movement_var=movement_var,
    replay_speed=replay_speed,
    discrete_transition_diag=discrete_diag,
    continuous_transition_types=continuous_transition_types,
    model=model,
    model_kwargs=model_kwargs,
)
clusterless_classifier_1D.fit(
    position_1D,
    data["multiunit"],
    is_training=is_training,
    track_graph=track_graph,
    center_well_id=center_well_id,
    edge_order=EDGE_ORDER,
    edge_spacing=EDGE_SPACING,
)
time_slice = slice(*data["ripple_times"].loc[ripple_number, ["start_time", "end_time"]])
m = data["multiunit"].sel(time=time_slice)

clusterless_results_1D = clusterless_classifier_1D.predict(m, m.time - m.time[0])
clusterless_results_1D = clusterless_results_1D.assign_coords(
    state=lambda ds: ds.state.to_index().map(TRANSITION_TO_CATEGORY)
)
import os

from src.visualization import plot_1D_results
from src.parameters import FIGURE_DIR
from src.figure_utilities import save_figure

plot_1D_results(
    multiunit_times,
    data,
    clusterless_results_1D,
    clusterless_classifier_1D,
    ripple_number,
)

fig_name = (
    "figure2_"
    f"{animal}_{day:02d}_{epoch:02d}_{ripple_number:04d}_"
    f"clusterless_1D_acasual_classification"
)
save_figure(os.path.join(FIGURE_DIR, "Figure2", fig_name))
import os
from src.visualization import plot_1D_projected_to_2D
from src.figure_utilities import save_figure
from src.parameters import FIGURE_DIR

plot_1D_projected_to_2D(
    data, clusterless_results_1D, clusterless_classifier_1D, ripple_number,
)

fig_name = (
    "figure2_1D_projected_to_2D_"
    f"{animal}_{day:02d}_{epoch:02d}_{ripple_number:04d}_"
    f"clusterless_1D_acasual_classification"
)
save_figure(os.path.join(FIGURE_DIR, "Figure2", fig_name))<jupyter_output><empty_output><jupyter_text>1D Sorted Spikes Classifier<jupyter_code>from dask.distributed import Client

client = Client(n_workers=16)
client
sorted_spikes_classifier_1D = SortedSpikesClassifier(
    place_bin_size=place_bin_size,
    movement_var=movement_var,
    replay_speed=replay_speed,
    discrete_transition_diag=discrete_diag,
    spike_model_penalty=spike_model_penalty,
    knot_spacing=knot_spacing,
    continuous_transition_types=continuous_transition_types,
)
sorted_spikes_classifier_1D.fit(
    position_1D,
    data["spikes"],
    is_training=is_training,
    track_graph=track_graph,
    center_well_id=center_well_id,
    edge_order=EDGE_ORDER,
    edge_spacing=EDGE_SPACING,
)
time_slice = slice(ripple_start, ripple_end)
s = data["spikes"].loc[time_slice]
sorted_spikes_results_1D = sorted_spikes_classifier_1D.predict(
    s, time=s.index - s.index[0]
)
sorted_spikes_results_1D = sorted_spikes_results_1D.assign_coords(
    state=lambda ds: ds.state.to_index().map(TRANSITION_TO_CATEGORY)
)
from src.analysis import get_place_field_max

place_field_max = get_place_field_max(sorted_spikes_classifier_1D)
linear_position_order = place_field_max.argsort(axis=0).squeeze()

ordered_spike_times = [spike_times[i] for i in linear_position_order]
import os

from src.visualization import plot_1D_results
from src.parameters import FIGURE_DIR
from src.figure_utilities import save_figure

plot_1D_results(
    ordered_spike_times,
    data,
    sorted_spikes_results_1D,
    sorted_spikes_classifier_1D,
    ripple_number,
    data_type="sorted_spikes",
)

fig_name = (
    "figure2_"
    f"{animal}_{day:02d}_{epoch:02d}_{ripple_number:04d}_"
    f"sorted_spikes_1D_acasual_classification"
)
save_figure(os.path.join(FIGURE_DIR, "Figure2", fig_name))
import os
from src.visualization import plot_1D_projected_to_2D
from src.figure_utilities import save_figure
from src.parameters import FIGURE_DIR

plot_1D_projected_to_2D(
    data, sorted_spikes_results_1D, sorted_spikes_classifier_1D, ripple_number,
)

fig_name = (
    "figure2_1D_projected_to_2D_"
    f"{animal}_{day:02d}_{epoch:02d}_{ripple_number:04d}_"
    f"sorted_spikes_1D_acasual_classification"
)
save_figure(os.path.join(FIGURE_DIR, "Figure2", fig_name))
# from src.figure_utilities import save_figure

# fig, ax = plt.subplots(figsize=(1, 3))
# ax.set_visible(False)
# cax = plt.colorbar(
#     plt.gcf(),
#     orientation="horizontal",
#     ax=ax,
#     extend="max",
#     ticks=h.colorbar.get_clim(),
#     label="Posterior",
# )
# cax.ax.set_xticklabels([0, "Max"])
# # save_figure("figure2_colorbar")
from src.visualization import make_classifier_movie
import os
import xarray as xr

animal, day, epoch = epoch_key
data_type, dim = "clusterless", "1D"

model_name = os.path.join(
    PROCESSED_DATA_DIR, f"{animal}_{day:02}_{epoch:02}_{data_type}_{dim}_model.pkl"
)

classifier = ClusterlessClassifier.load_model(model_name)

results = xr.open_dataset(
    os.path.join(PROCESSED_DATA_DIR, f"{animal}_{day:02d}_{epoch:02d}.nc"),
    group=f"/{data_type}/{dim}/classifier/ripples/",
)

make_classifier_movie(classifier, results, ripple_number, data, epoch_key)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09962517261787335, 'fraction_numerical': 0.01874136910633261, 'mean_word_length': 6.670196671709531, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '244434', 'license': 'MIT', 'n_tokens_mistral': 1982, 'n_tokens_neox': 1925, 'n_words': 250, 'path': 'notebooks/Figure2.ipynb', 'repo_name': 'edeno/sleep_analysis', 'size': '5069'}