|
6 | 6 |
|
7 | 7 | from viscy.representation.embedding_writer import read_embedding_dataset |
8 | 8 | from viscy.representation.evaluation.distance import ( |
9 | | - calculate_normalized_euclidean_distance_cell, |
10 | | - compute_displacement_mean_std_full, |
| 9 | + calculate_normalized_euclidean_distance_cell, |
| 10 | + compute_displacement_mean_std_full, |
11 | 11 | ) |
12 | 12 |
|
13 | | -# %% paths |
| 13 | +# %% paths |
14 | 14 |
|
15 | 15 | features_path_30_min = Path( |
16 | | - "/hpc/projects/intracellular_dashboard/viral-sensor/infection_classification/models/time_sampling_strategies/time_interval/predict/feb_test_time_interval_1_epoch_178.zarr" |
| 16 | + "/hpc/projects/intracellular_dashboard/viral-sensor/infection_classification/models/time_sampling_strategies/time_interval/predict/feb_test_time_interval_1_epoch_178.zarr" |
17 | 17 | ) |
18 | 18 |
|
19 | | -feature_path_no_track = Path("/hpc/projects/intracellular_dashboard/viral-sensor/infection_classification/models/time_sampling_strategies/negpair_random_sampling2/feb_fixed_test_predict.zarr") |
| 19 | +feature_path_no_track = Path( |
| 20 | + "/hpc/projects/intracellular_dashboard/viral-sensor/infection_classification/models/time_sampling_strategies/negpair_random_sampling2/feb_fixed_test_predict.zarr" |
| 21 | +) |
20 | 22 |
|
21 | | -features_path_any_time = Path("/hpc/projects/intracellular_dashboard/viral-sensor/infection_classification/models/time_sampling_strategies/negpair_difcell_randomtime_sampling/Ver2_updateTracking_refineModel/predictions/Feb_2chan_128patch_32projDim/2chan_128patch_56ckpt_FebTest.zarr") |
| 23 | +features_path_any_time = Path( |
| 24 | + "/hpc/projects/intracellular_dashboard/viral-sensor/infection_classification/models/time_sampling_strategies/negpair_difcell_randomtime_sampling/Ver2_updateTracking_refineModel/predictions/Feb_2chan_128patch_32projDim/2chan_128patch_56ckpt_FebTest.zarr" |
| 25 | +) |
22 | 26 |
|
23 | 27 | data_path = Path( |
24 | | - "/hpc/projects/intracellular_dashboard/viral-sensor/2024_02_04_A549_DENV_ZIKV_timelapse/8-train-test-split/registered_test.zarr" |
| 28 | + "/hpc/projects/intracellular_dashboard/viral-sensor/2024_02_04_A549_DENV_ZIKV_timelapse/8-train-test-split/registered_test.zarr" |
25 | 29 | ) |
26 | 30 |
|
27 | 31 | tracks_path = Path( |
28 | | - "/hpc/projects/intracellular_dashboard/viral-sensor/2024_02_04_A549_DENV_ZIKV_timelapse/8-train-test-split/track_test.zarr" |
| 32 | + "/hpc/projects/intracellular_dashboard/viral-sensor/2024_02_04_A549_DENV_ZIKV_timelapse/8-train-test-split/track_test.zarr" |
29 | 33 | ) |
30 | 34 |
|
31 | 35 | # %% Load embedding datasets for all three sampling |
32 | | -fov_name = '/B/4/6' |
| 36 | +fov_name = "/B/4/6" |
33 | 37 | track_id = 52 |
34 | 38 |
|
35 | 39 | embedding_dataset_30_min = read_embedding_dataset(features_path_30_min) |
36 | 40 | embedding_dataset_no_track = read_embedding_dataset(feature_path_no_track) |
37 | 41 | embedding_dataset_any_time = read_embedding_dataset(features_path_any_time) |
38 | 42 |
|
39 | | -#%% |
| 43 | +# %% |
40 | 44 | # Calculate displacement for each sampling |
41 | | -time_points_30_min, cosine_similarities_30_min = calculate_normalized_euclidean_distance_cell(embedding_dataset_30_min, fov_name, track_id) |
42 | | -time_points_no_track, cosine_similarities_no_track = calculate_normalized_euclidean_distance_cell(embedding_dataset_no_track, fov_name, track_id) |
43 | | -time_points_any_time, cosine_similarities_any_time = calculate_normalized_euclidean_distance_cell(embedding_dataset_any_time, fov_name, track_id) |
| 45 | +time_points_30_min, cosine_similarities_30_min = ( |
| 46 | + calculate_normalized_euclidean_distance_cell( |
| 47 | + embedding_dataset_30_min, fov_name, track_id |
| 48 | + ) |
| 49 | +) |
| 50 | +time_points_no_track, cosine_similarities_no_track = ( |
| 51 | + calculate_normalized_euclidean_distance_cell( |
| 52 | + embedding_dataset_no_track, fov_name, track_id |
| 53 | + ) |
| 54 | +) |
| 55 | +time_points_any_time, cosine_similarities_any_time = ( |
| 56 | + calculate_normalized_euclidean_distance_cell( |
| 57 | + embedding_dataset_any_time, fov_name, track_id |
| 58 | + ) |
| 59 | +) |
44 | 60 |
|
45 | 61 | # %% Plot displacement over time for all three conditions |
46 | 62 |
|
47 | 63 | plt.figure(figsize=(10, 6)) |
48 | 64 |
|
49 | | -plt.plot(time_points_no_track, cosine_similarities_no_track, marker='o', label='classical contrastive (no tracking)') |
50 | | -plt.plot(time_points_any_time, cosine_similarities_any_time, marker='o', label='cell aware') |
51 | | -plt.plot(time_points_30_min, cosine_similarities_30_min, marker='o', label='cell & time aware (interval 30 min)') |
| 65 | +plt.plot( |
| 66 | + time_points_no_track, |
| 67 | + cosine_similarities_no_track, |
| 68 | + marker="o", |
| 69 | + label="classical contrastive (no tracking)", |
| 70 | +) |
| 71 | +plt.plot( |
| 72 | + time_points_any_time, cosine_similarities_any_time, marker="o", label="cell aware" |
| 73 | +) |
| 74 | +plt.plot( |
| 75 | + time_points_30_min, |
| 76 | + cosine_similarities_30_min, |
| 77 | + marker="o", |
| 78 | + label="cell & time aware (interval 30 min)", |
| 79 | +) |
52 | 80 |
|
53 | 81 | plt.xlabel("Time Delay (t)", fontsize=10) |
54 | 82 | plt.ylabel("Normalized Euclidean Distance with First Time Point", fontsize=10) |
55 | | -plt.title("Normalized Euclidean Distance (Features) Over Time for Infected Cell", fontsize=12) |
| 83 | +plt.title( |
| 84 | + "Normalized Euclidean Distance (Features) Over Time for Infected Cell", fontsize=12 |
| 85 | +) |
56 | 86 |
|
57 | 87 | plt.grid(True) |
58 | 88 | plt.legend(fontsize=10) |
59 | 89 |
|
60 | | -#plt.savefig('4_euc_dist_full.svg', format='svg') |
| 90 | +# plt.savefig('4_euc_dist_full.svg', format='svg') |
61 | 91 | plt.show() |
62 | 92 |
|
63 | 93 |
|
64 | 94 | # %% Paths to datasets |
65 | | -features_path_30_min = Path("/hpc/projects/intracellular_dashboard/viral-sensor/infection_classification/models/time_sampling_strategies/time_interval/predict/feb_test_time_interval_1_epoch_178.zarr") |
66 | | -feature_path_no_track = Path("/hpc/projects/intracellular_dashboard/viral-sensor/infection_classification/models/time_sampling_strategies/negpair_random_sampling2/feb_fixed_test_predict.zarr") |
| 95 | +features_path_30_min = Path( |
| 96 | + "/hpc/projects/intracellular_dashboard/viral-sensor/infection_classification/models/time_sampling_strategies/time_interval/predict/feb_test_time_interval_1_epoch_178.zarr" |
| 97 | +) |
| 98 | +feature_path_no_track = Path( |
| 99 | + "/hpc/projects/intracellular_dashboard/viral-sensor/infection_classification/models/time_sampling_strategies/negpair_random_sampling2/feb_fixed_test_predict.zarr" |
| 100 | +) |
67 | 101 |
|
68 | 102 | embedding_dataset_30_min = read_embedding_dataset(features_path_30_min) |
69 | 103 | embedding_dataset_no_track = read_embedding_dataset(feature_path_no_track) |
70 | 104 |
|
71 | 105 |
|
72 | 106 | # %% |
73 | | -max_tau = 10 |
| 107 | +max_tau = 10 |
74 | 108 |
|
75 | | -mean_displacement_30_min_euc, std_displacement_30_min_euc = compute_displacement_mean_std_full(embedding_dataset_30_min, max_tau) |
76 | | -mean_displacement_no_track_euc, std_displacement_no_track_euc = compute_displacement_mean_std_full(embedding_dataset_no_track, max_tau) |
| 109 | +mean_displacement_30_min_euc, std_displacement_30_min_euc = ( |
| 110 | + compute_displacement_mean_std_full(embedding_dataset_30_min, max_tau) |
| 111 | +) |
| 112 | +mean_displacement_no_track_euc, std_displacement_no_track_euc = ( |
| 113 | + compute_displacement_mean_std_full(embedding_dataset_no_track, max_tau) |
| 114 | +) |
77 | 115 |
|
78 | 116 | # %% Plot 2: Cosine Displacements |
79 | 117 | plt.figure(figsize=(10, 6)) |
|
83 | 121 | mean_values_30_min_euc = list(mean_displacement_30_min_euc.values()) |
84 | 122 | std_values_30_min_euc = list(std_displacement_30_min_euc.values()) |
85 | 123 |
|
86 | | -plt.plot(taus, mean_values_30_min_euc, marker='o', label='Cell & Time Aware (30 min interval)', color='green') |
87 | | -plt.fill_between(taus, |
88 | | - np.array(mean_values_30_min_euc) - np.array(std_values_30_min_euc), |
89 | | - np.array(mean_values_30_min_euc) + np.array(std_values_30_min_euc), |
90 | | - color='green', alpha=0.3, label='Std Dev (30 min interval)') |
| 124 | +plt.plot( |
| 125 | + taus, |
| 126 | + mean_values_30_min_euc, |
| 127 | + marker="o", |
| 128 | + label="Cell & Time Aware (30 min interval)", |
| 129 | + color="green", |
| 130 | +) |
| 131 | +plt.fill_between( |
| 132 | + taus, |
| 133 | + np.array(mean_values_30_min_euc) - np.array(std_values_30_min_euc), |
| 134 | + np.array(mean_values_30_min_euc) + np.array(std_values_30_min_euc), |
| 135 | + color="green", |
| 136 | + alpha=0.3, |
| 137 | + label="Std Dev (30 min interval)", |
| 138 | +) |
91 | 139 |
|
92 | 140 | mean_values_no_track_euc = list(mean_displacement_no_track_euc.values()) |
93 | 141 | std_values_no_track_euc = list(std_displacement_no_track_euc.values()) |
94 | 142 |
|
95 | | -plt.plot(taus, mean_values_no_track_euc, marker='o', label='Classical Contrastive (No Tracking)', color='blue') |
96 | | -plt.fill_between(taus, |
97 | | - np.array(mean_values_no_track_euc) - np.array(std_values_no_track_euc), |
98 | | - np.array(mean_values_no_track_euc) + np.array(std_values_no_track_euc), |
99 | | - color='blue', alpha=0.3, label='Std Dev (No Tracking)') |
| 143 | +plt.plot( |
| 144 | + taus, |
| 145 | + mean_values_no_track_euc, |
| 146 | + marker="o", |
| 147 | + label="Classical Contrastive (No Tracking)", |
| 148 | + color="blue", |
| 149 | +) |
| 150 | +plt.fill_between( |
| 151 | + taus, |
| 152 | + np.array(mean_values_no_track_euc) - np.array(std_values_no_track_euc), |
| 153 | + np.array(mean_values_no_track_euc) + np.array(std_values_no_track_euc), |
| 154 | + color="blue", |
| 155 | + alpha=0.3, |
| 156 | + label="Std Dev (No Tracking)", |
| 157 | +) |
100 | 158 |
|
101 | | -plt.xlabel('Time Shift (τ)') |
102 | | -plt.ylabel('Euclidean Distance') |
103 | | -plt.title('Embedding Displacement Over Time (Features)') |
| 159 | +plt.xlabel("Time Shift (τ)") |
| 160 | +plt.ylabel("Euclidean Distance") |
| 161 | +plt.title("Embedding Displacement Over Time (Features)") |
104 | 162 |
|
105 | 163 | plt.grid(True) |
106 | 164 | plt.legend() |
|
0 commit comments