|
8 | 8 |
|
9 | 9 | import pandas as pd
|
10 | 10 |
|
11 |
| -from utils import (get_xyz, find_point_at_fraction, plot_spherical_head, |
12 |
| - plot_2d_head, stereographic_projection) |
13 |
| -from contour_labels import all_contours, system1020, system1010, system1005 |
| 11 | +from eeg_positions.utils import (get_xyz, find_point_at_fraction, |
| 12 | + plot_spherical_head, plot_2d_head, |
| 13 | + stereographic_projection) |
| 14 | +from eeg_positions.contour_labels import (ALL_CONTOURS, SYSTEM1020, SYSTEM1010, |
| 15 | + SYSTEM1005) |
14 | 16 |
|
15 | 17 |
|
16 | 18 | if __name__ == '__main__':
|
|
32 | 34 |
|
33 | 35 | # Calculate all positions
|
34 | 36 | # -----------------------
|
35 |
| - for contour in all_contours: |
| 37 | + for contour in ALL_CONTOURS: |
36 | 38 |
|
37 | 39 | if len(contour) == 21:
|
38 | 40 | midpoint_idx = 10
|
|
49 | 51 |
|
50 | 52 | # Calculate all other points at fractions of distance
|
51 | 53 | # see `contour_labels.py` and `test_contour_labels.py`
|
52 |
| - other_points = {} |
| 54 | + other_ps = {} |
53 | 55 | for i, label in enumerate(contour):
|
54 |
| - other_points[label] = find_point_at_fraction(p1, |
55 |
| - p2, |
56 |
| - p3, |
57 |
| - f=i/(len(contour)-1)) |
| 56 | + other_ps[label] = find_point_at_fraction(p1, |
| 57 | + p2, |
| 58 | + p3, |
| 59 | + frac=i/(len(contour)-1)) |
58 | 60 |
|
59 | 61 | # Append to data frame
|
60 |
| - tmp = pd.DataFrame.from_dict(other_points, orient='index') |
| 62 | + tmp = pd.DataFrame.from_dict(other_ps, orient='index') |
61 | 63 | tmp.columns = ['x', 'y', 'z']
|
62 | 64 | tmp['label'] = tmp.index
|
63 | 65 | df = df.append(tmp, ignore_index=True, sort=True)
|
|
71 | 73 | fname_template = os.path.join(fpath, '..', 'data', 'standard_{}.tsv')
|
72 | 74 |
|
73 | 75 | # First in 3D, then in 2D for each system
|
74 |
| - for system, fmt in zip([system1020, system1010, system1005], |
| 76 | + for system, fmt in zip([SYSTEM1020, SYSTEM1010, SYSTEM1005], |
75 | 77 | ['1020', '1010', '1005']):
|
76 | 78 |
|
77 | 79 | idx = df.label.isin(system)
|
78 | 80 | system_df = df.loc[idx, :]
|
79 |
| - system_df.sort_values(by='label', inplace=True) |
| 81 | + system_df = system_df.sort_values(by='label') |
80 | 82 | system_df.to_csv(fname_template.format(fmt), sep='\t', na_rep='n/a',
|
81 | 83 | index=False, float_format='%.4f')
|
82 | 84 |
|
83 | 85 | # Now in 2D using stereographic projection
|
84 |
| - xs, ys = stereographic_projection(system_df.values[:, 1], |
85 |
| - system_df.values[:, 2], |
86 |
| - system_df.values[:, 3]) |
| 86 | + xs, ys = stereographic_projection(system_df.to_numpy()[:, 1], |
| 87 | + system_df.to_numpy()[:, 2], |
| 88 | + system_df.to_numpy()[:, 3]) |
87 | 89 | system_df = system_df.loc[:, ['label', 'x', 'y']]
|
88 | 90 | system_df['x'] = xs
|
89 | 91 | system_df['x'] = ys
|
|
108 | 110 | # 2D
|
109 | 111 | fig2, ax2 = plot_2d_head()
|
110 | 112 |
|
111 |
| - xs, ys = stereographic_projection(df.x, df.y, df.z) |
| 113 | + xs, ys = stereographic_projection(df['x'], df['y'], df['z']) |
112 | 114 |
|
113 | 115 | ax2.scatter(xs, ys, marker='.', color='r')
|
114 | 116 |
|
115 |
| - for lab, x, y in zip(list(df.label), xs, ys): |
| 117 | + for lab, x, y in zip(list(df['label']), xs, ys): |
116 | 118 | ax2.annotate(lab, xy=(x, y), fontsize=5)
|
117 | 119 |
|
118 | 120 | ax2.set_title('standard_{}'.format(system))
|
|
0 commit comments