Visualization
Classes¶
NumpyEncoder
¶
Bases: JSONEncoder
Used to serialize numpy arrays before a .json export.
Functions¶
default(obj)
¶
Handle numpy array serialization.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj
|
object to serialize |
required |
Returns:
Type | Description |
---|---|
serializable representation of the object |
Source code in opentak/visualization.py
67 68 69 70 71 72 73 74 75 |
|
ExportTAK(sorted_array, dico_label_color, dict_label_id)
dataclass
¶
Class for exporting the TAK.
Initialize the ExportTAK object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sorted_array
|
sorted array of patient sequences |
required | |
dico_label_color
|
dictionary mapping labels to colors |
required | |
dict_label_id
|
dictionary mapping treatments to IDs |
required |
Source code in opentak/visualization.py
86 87 88 89 90 91 92 93 94 95 |
|
Functions¶
TakVisualizer(tak, dico_evt_for_legend=None)
¶
Creation of the TakVisualizer object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tak
|
Tak
|
Tak object with fitted clustering results |
required |
dico_evt_for_legend
|
dict[str, str] | None
|
the mapping for legend names of events |
None
|
Source code in opentak/visualization.py
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 |
|
Functions¶
update_colors(dict_new_colors=None, **kwargs)
¶
Update the color dictionary.
Allows the user to set colors for specific labels.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dict_new_colors
|
dict[str, str] | None
|
Dict 'label'->'color' |
None
|
kwargs
|
Any
|
You can specify new colors here, for example by using .update_colors(drug_A=(24,90,0)) |
{}
|
Source code in opentak/visualization.py
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 |
|
split(list_ids)
¶
Split the TAK array and only keep list_ids IDs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
list_ids
|
list[int]
|
IDs to keep in the TAK |
required |
Source code in opentak/visualization.py
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 |
|
reset_split()
¶
Reset the TAK after a split so it contains the whole initial population.
Source code in opentak/visualization.py
290 291 292 293 294 295 296 297 298 |
|
process_visualization(num_cluster=None, soften_angles=0, unblurred_events=None, base_date=None, process_medoids=False, **kwargs)
¶
Transform the image into an array of sequence (with a daily timeline) of similar patients.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
num_cluster
|
int | None
|
cluster to process |
None
|
soften_angles
|
size of the blur filter |
0
|
|
unblurred_events
|
Sequence[str] | None
|
events to not consider for the blur |
None
|
base_date
|
datetime | None
|
date to be filled in to set the first date of the x-axis |
None
|
process_medoids
|
bool
|
whether to use medoids instead of patients Keyword Arguments: - |
False
|
Source code in opentak/visualization.py
323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 |
|
get_plot(plot_title='Analysis of treatment lines', unit_as_years=False, unit_as_months=False, nb_months=None, offset=0, add_sep=False, dendrogram=False, **kwargs)
¶
Allow the display of TAK with Plotly.
Note
if unit_as_years=False and unit_as_month=False, units are in TIMESTAMP
if self.base_date = True, xaxes will be in years
Kwargs
list_len_clusters_ordered
: (list) number of patients in each cluster, starting from the bottom of the TAKwrite_annotation
: (bool) whether or not to write the annotation at the right of the TAK. Default: Trueclusters_names
: (list) liste des noms des clusters à associer à list_len_clusters_ordered. Default: ["A", "B", etc...]color_annotation
: (str) color of the lines and of the text at the left of the graph. Default: "#4CA094" (green-blue)width_line
: (int) width of the lines. Default: 3size_annotation
: (int) size of the font for annotation at the right of the TAK. Default: 10
Parameters:
Name | Type | Description | Default |
---|---|---|---|
plot_title
|
str
|
Title of the plot (str) |
'Analysis of treatment lines'
|
unit_as_years
|
bool
|
specify whether the units are years (True) or other (False) |
False
|
unit_as_months
|
bool
|
specify whether the units are months (True) or other (False) |
False
|
nb_months
|
int | None
|
specify every how many months do we add a xtick (ignored if unit_as_month=False) |
None
|
offset
|
int
|
specify if an offset (in TIMESTAMP) should be apply to xaxes |
0
|
add_sep
|
bool
|
whether to add horizontal line on the tak or not |
False
|
dendrogram
|
bool
|
whether to add a dendrogram on the side or not |
False
|
kwargs
|
options to deal with cluster sizes, names, colors and width of the lines and size of the annotations |
{}
|
Returns:
Type | Description |
---|---|
Figure
|
Plotly figure |
Source code in opentak/visualization.py
507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 |
|
imshow()
¶
Allow the display of TAK with Plotly using imshow.
TO DO : Very basic function -> needs better implantation
Returns:
Type | Description |
---|---|
Plotly figure |
Source code in opentak/visualization.py
718 719 720 721 722 723 724 725 726 727 |
|
graph_events_rep_on_tak(events_not_shown=None, events_not_in_percent=None, threshold_percent=2, represented_patients_name='patients involved')
¶
Generate the graph of the distribution of each event along the tak_viz, based on the values of the TAK array.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
events_not_shown
|
list | None
|
The list of events not to show on the graph. |
None
|
events_not_in_percent
|
list | None
|
List of events to ignore in the %age of curves. It changes the denominator of other curves. |
None
|
threshold_percent
|
float
|
% minimum of patients represented on the first graph |
2
|
represented_patients_name
|
str
|
Name to give to patients, default value |
'patients involved'
|
Returns:
Type | Description |
---|---|
Figure
|
Plotly figure |
Source code in opentak/visualization.py
753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 |
|
export_tak(path_folder, file_name='tak_result.json')
¶
Export the TAK for datashader visualization.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path_folder
|
str | Path
|
Folder name to store results |
required |
file_name
|
str
|
Result file name |
'tak_result.json'
|
Source code in opentak/visualization.py
1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 |
|
NiceScale(minv, maxv)
¶
Compute optimal parameters to set the scale.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
minv
|
Min value of the range |
required | |
maxv
|
Max value of the range |
required |
Source code in opentak/visualization.py
1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 |
|
Functions¶
calculate()
¶
Calculate and updates values for tick spacing and nice minimum and maximum data points on the axis.
Source code in opentak/visualization.py
1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 |
|
nice_num(lst, rround)
¶
Return a "nice" number approximately equal to range.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
rround
|
Rounds the number if rround = true Takes the ceiling if rround = false. |
required | |
lst
|
Local range |
required |
Source code in opentak/visualization.py
1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 |
|
Functions¶
soften_angles_sample(base_image, soften_angles, image_length, image_width)
¶
Apply blur on the picture.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
base_image
|
NDArray
|
incoming image |
required |
soften_angles
|
int
|
size of the blur filter |
required |
image_length
|
int | None
|
length of the image before the filter is applied |
required |
image_width
|
int | None
|
width of the image before the filter is applied |
required |
Returns:
Type | Description |
---|---|
tuple[Image, Image]
|
image_bigsize: image with size (image_width, image_length) and image_outlines: same size and blurred |
Source code in opentak/visualization.py
1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 |
|
get_clusters_names_default(list_len_clusters_ordered, max_nb_clusters=26)
¶
Return the list of default clusters names (reversed alphabetic order, ending by A).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
list_len_clusters_ordered
|
list
|
list of the number of patients in each cluster, order starting at the botton of the TAK |
required |
max_nb_clusters
|
int
|
max number of clusters before raising an error |
26
|
Returns:
Type | Description |
---|---|
list
|
list of default clusters names (["F", "E", "D", ...]) |
Source code in opentak/visualization.py
1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 |
|
nice_plotly_show(fig)
¶
Display nicely a plotly graph.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fig
|
Plotly figure |
required |
Source code in opentak/visualization.py
1143 1144 1145 1146 1147 1148 1149 |
|
add_grid_on_tak_fig(fig, grid='xy', params=None)
¶
Add grid on the TAK heatmap in the plotly fig "fig".
Note
default params for xgrid_params and ygrid_params: line_width = 0.5, line_dash = "dot", line_color = "grey", opacity = 0.5
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fig
|
Figure
|
plotly heatmap TAK on which to add the grid |
required |
grid
|
str
|
whether to add grid on x and/or y axes |
'xy'
|
params
|
dict | None
|
dict params for add_vline (grid for x), 2 keys : "x" and/or "y", and each value is a dictionary of parameters |
None
|
Returns:
Type | Description |
---|---|
Figure
|
copy of fig with grid |
Source code in opentak/visualization.py
1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 |
|