Jupyter-Notebook
About the Notebook API
The Notebook API is a new feature in the v0.12.0 release of SpectraFit
with major focus on working with Jupyter Notebooks.
The Notebook API is a work in progress and is subject to change.
Jupyter Notebook plugin for SpectraFit.
DataFrameDisplay
¶
Class for displaying a dataframe in different ways.
Source code in spectrafit/plugins/notebook.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
|
df_display(df, mode=None)
¶
Call the DataframeDisplay class.
About df_display
This function is used to display a dataframe in two different ways.
- Regular display mode:
- Via
IPython.display
for regular sliced displaying of the dataframe in the notebook. - Via
IPython.display
as Markdown for regular displaying of the complete dataframe in the notebook.
- Via
- Interactive display mode:
- Via
itables
for interactive displaying of the dataframe in the notebook, which allows for sorting, filtering, and jumping. For more information see itables. - Via
dtale
for interactive displaying of the dataframe in the notebook, which allows advanced data analysis of the dataframe in an external window. For more information see dtale.
- Via
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df | pd.DataFrame | Dataframe to display. | required |
mode | str, Optional | Display mode. Defaults to None. | None |
Raises:
Type | Description |
---|---|
ValueError | Raises ValueError if mode of displaying is not supported. |
Source code in spectrafit/plugins/notebook.py
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
|
dtale_display(df)
staticmethod
¶
Display the dataframe in a dtale way.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df | pd.DataFrame | Dataframe to display. | required |
Source code in spectrafit/plugins/notebook.py
111 112 113 114 115 116 117 118 |
|
interactive_display(df)
staticmethod
¶
Display the dataframe in an interactive way.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df | pd.DataFrame | Dataframe to display. | required |
Source code in spectrafit/plugins/notebook.py
102 103 104 105 106 107 108 109 |
|
markdown_display(df)
staticmethod
¶
Display the dataframe in a markdown way.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df | pd.DataFrame | Dataframe to display. | required |
Source code in spectrafit/plugins/notebook.py
120 121 122 123 124 125 126 127 |
|
regular_display(df)
staticmethod
¶
Display the dataframe in a regular way.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df | pd.DataFrame | Dataframe to display. | required |
Source code in spectrafit/plugins/notebook.py
93 94 95 96 97 98 99 100 |
|
DataFramePlot
¶
Class to plot a dataframe.
Source code in spectrafit/plugins/notebook.py
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 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 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 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 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 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 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 |
|
get_minor(args_plot)
¶
Get the minor axis arguments.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
args_plot | PlotAPI | PlotAPI object for the settings of the plot. | required |
Returns:
Type | Description |
---|---|
Dict[str, Union[str, bool]] | Dict[str, Union[str, bool]]: Dictionary with the minor axis arguments. |
Source code in spectrafit/plugins/notebook.py
382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 |
|
plot_2dataframes(args_plot, df_1, df_2=None)
¶
Plot of two dataframes.
About the plot
The plot is a combination of two plots. The first plot is the can be the residual plot of a fit or the modified data. The second plot can be the fit or the original data.
line_dash_map
Currently, the line_dash_map
is not working, and the dash is not plotted. Most likely, this is related to the fact that the columns are not labeled in the dataframe.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
args_plot | PlotAPI | PlotAPI object for the settings of the plot. | required |
df_1 | pd.DataFrame | First dataframe to plot, which will generate automatically a fit plot with residual plot. The ratio is 70% to 20% with 10% space in between. | required |
df_2 | Optional[pd.DataFrame] | Second optional dataframe to plot for comparsion. In this case, the ratio will between first and second plot will be same. Defaults to None. | None |
Source code in spectrafit/plugins/notebook.py
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 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 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 |
|
plot_dataframe(args_plot, df)
¶
Plot the dataframe according to the PlotAPI arguments.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
args_plot | PlotAPI | PlotAPI object for the settings of the plot. | required |
df | pd.DataFrame | Dataframe to plot. | required |
Source code in spectrafit/plugins/notebook.py
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 |
|
plot_global_fit(args_plot, df)
¶
Plot the global dataframe according to the PlotAPI arguments.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
args_plot | PlotAPI | PlotAPI object for the settings of the plot. | required |
df | pd.DataFrame | Dataframe to plot. | required |
Source code in spectrafit/plugins/notebook.py
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 |
|
plot_metric(args_plot, df_metric, bar_criteria, line_criteria)
¶
Plot the metric according to the PlotAPI arguments.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
args_plot | PlotAPI | PlotAPI object for the settings of the plot. | required |
df_metric | pd.DataFrame | Metric dataframe to plot. | required |
bar_criteria | Union[str, List[str]] | String or list of criteria to plot as bars. | required |
line_criteria | Union[str, List[str]] | String or l of criteria to plot as lines. | required |
Source code in spectrafit/plugins/notebook.py
275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 |
|
title_text(name, unit=None)
staticmethod
¶
Return the title text.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name | str | Name of the variable. | required |
unit | Optional[str] | Unit of the variable. Defaults to None. | None |
Returns:
Name | Type | Description |
---|---|---|
str | str | Title text. |
Source code in spectrafit/plugins/notebook.py
369 370 371 372 373 374 375 376 377 378 379 380 |
|
update_layout_axes(fig, args_plot, height)
¶
Update the layout of the plot.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fig | Figure | Figure to update. | required |
args_plot | PlotAPI | PlotAPI object for the settings of the plot. | required |
height | int | Height of the plot. | required |
Returns:
Name | Type | Description |
---|---|---|
Figure | Figure | Updated figure. |
Source code in spectrafit/plugins/notebook.py
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 |
|
ExportReport
¶
Bases: SolverResults
Class for exporting results as toml.
Source code in spectrafit/plugins/notebook.py
623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 |
|
make_input_contribution: InputAPI
property
¶
Make input contribution of the report.
Returns:
Name | Type | Description |
---|---|---|
InputAPI | InputAPI | Input contribution of the report as class. |
make_output_contribution: OutputAPI
property
¶
Make output contribution of the report.
Returns:
Name | Type | Description |
---|---|---|
OutputAPI | OutputAPI | Output contribution of the report as class. |
make_solver_contribution: SolverAPI
property
¶
Make solver contribution of the report.
Returns:
Name | Type | Description |
---|---|---|
SolverAPI | SolverAPI | Solver contribution of the report as class. |
__call__()
¶
Get the complete report as dictionary.
Returns:
Type | Description |
---|---|
Dict[str, Any] | Dict[str, Any]: Report as dictionary by using the |
Source code in spectrafit/plugins/notebook.py
709 710 711 712 713 714 715 716 717 718 719 720 |
|
__init__(description, initial_model, pre_processing, fname, args_out, df_org, df_fit, df_pre=pd.DataFrame())
¶
Initialize the ExportReport class.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
description | DescriptionAPI | Description of the fit project. | required |
initial_model | List[Dict[str, Dict[str, Dict[str, Any]]]] | Initial model for the fit. | required |
pre_processing | DataPreProcessingAPI | Data pre-processing settings. | required |
fname | FnameAPI | Filename of the fit project including the path, prefix, and suffix. | required |
args_out | Dict[str, Any] | Dictionary of SpectraFit settings and results. | required |
df_org | pd.DataFrame | Dataframe of the original data for performing the fit. | required |
df_fit | pd.DataFrame | Dataframe of the final fit data. | required |
df_pre | Optional[pd.DataFrame] | Dataframe of the pre-processed. Defaults to pd.DataFrame(). | pd.DataFrame() |
Source code in spectrafit/plugins/notebook.py
626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 |
|
ExportResults
¶
Class for exporting results as csv.
Source code in spectrafit/plugins/notebook.py
399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 |
|
export_df(df, args)
¶
Export the dataframe as csv.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df | pd.DataFrame | Dataframe to export. | required |
args | FnameAPI | Arguments for the file export including the path, prefix, and suffix. | required |
Source code in spectrafit/plugins/notebook.py
402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 |
|
export_report(report, args)
¶
Export the results as toml file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
report | Dict[Any, Any] | Results as dictionary to export. | required |
args | FnameAPI | Arguments for the file export including the path, prefix, and suffix. | required |
Source code in spectrafit/plugins/notebook.py
420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 |
|
fname2path(fname, suffix, prefix=None, folder=None)
staticmethod
¶
Translate string to Path object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fname | str | Filename | required |
suffix | str | Name of the suffix of the file. | required |
prefix | Optional[str] | Name of the prefix of the file. Defaults to None. | None |
folder | Optional[str] | Folder, where it will be saved. This folders will be created, if not exist. Defaults to None. | None |
Returns:
Name | Type | Description |
---|---|---|
Path | Path | Path object of the file. |
Source code in spectrafit/plugins/notebook.py
439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 |
|
SolverResults
¶
Class for storing the results of the solver.
Source code in spectrafit/plugins/notebook.py
468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 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 |
|
get_component_correlation: Dict[str, Any]
property
¶
Get the linear correlation of the components.
Returns:
Type | Description |
---|---|
Dict[str, Any] | Dict[str, Any]: Linear correlation of the components as dictionary. |
get_confidence_interval: Dict[Any, Any]
property
¶
Get the confidence interval.
Returns:
Type | Description |
---|---|
Dict[Any, Any] | Dict[Any, Any]: Confidence interval as dictionary with or without the confidence interval results. |
get_covariance_matrix: Dict[str, Any]
property
¶
Get the covariance matrix.
Returns:
Type | Description |
---|---|
Dict[str, Any] | Dict[str, Any]: Covariance matrix as dictionary. |
get_current_metric: pd.DataFrame
property
¶
Get the current metric.
About the regression metrics
For using the regression metrics, the regression_metrics
must be averaged to merge the results of the different configurations together with the goodness_of_fit
and variables
results.
Returns:
Type | Description |
---|---|
pd.DataFrame | pd.DataFrame: Current metric based on |
pd.DataFrame |
|
get_descriptive_statistic: Dict[str, Any]
property
¶
Get the descriptive statistic.
Returns:
Type | Description |
---|---|
Dict[str, Any] | Dict[str, Any]: Descriptive statistic as dictionary of the spectra, fit, and components as dictionary. |
get_errorbars: Dict[str, float]
property
¶
Get the comments about the error bars of fit values.
Returns:
Type | Description |
---|---|
Dict[str, float] | Dict[str, float]: Comments about the error bars as dictionary or dataframe. |
get_gof: Dict[str, float]
property
¶
Get the goodness of fit values.
Returns:
Type | Description |
---|---|
Dict[str, float] | Dict[str, float]: Goodness of fit values as dictionary. |
get_linear_correlation: Dict[str, Any]
property
¶
Get the linear correlation.
Returns:
Type | Description |
---|---|
Dict[str, Any] | Dict[str, Any]: Linear correlation of the spectra, fit, and components as dictionary. |
get_regression_metrics: Dict[str, Any]
property
¶
Get the regression metrics.
Returns:
Type | Description |
---|---|
Dict[str, Any] | Dict[str, Any]: Regression metrics as dictionary. |
get_variables: Dict[str, Dict[str, float]]
property
¶
Get the variables of the fit.
Returns:
Type | Description |
---|---|
Dict[str, Dict[str, float]] | Dict[str, Dict[str, float]]: Variables of the fit. |
settings_conf_interval: Union[bool, Dict[str, Any]]
property
¶
Confidence interval settings.
Returns:
Type | Description |
---|---|
Union[bool, Dict[str, Any]] | Union[bool, Dict[str, Any]]: Confidence interval settings. |
settings_configurations: Dict[str, Any]
property
¶
Configure settings.
Returns:
Type | Description |
---|---|
Dict[str, Any] | Dict[str, Any]: Configuration settings. |
settings_global_fitting: Union[bool, int]
property
¶
Global fitting settings.
Returns:
Type | Description |
---|---|
Union[bool, int] | Union[bool, int]: Global fitting settings. |
__init__(args_out)
¶
Initialize the SolverResults class.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
args_out | Dict[str, Any] | Dictionary of SpectraFit settings and results. | required |
Source code in spectrafit/plugins/notebook.py
471 472 473 474 475 476 477 |
|
SpectraFitNotebook
¶
Bases: DataFramePlot
, DataFrameDisplay
, ExportResults
Jupyter Notebook plugin for SpectraFit.
Source code in spectrafit/plugins/notebook.py
723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 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 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 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 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 |
|
export_df_act: None
property
¶
Export the dataframe.
export_df_fit: None
property
¶
Export the dataframe.
export_df_metric: None
property
¶
Export the dataframe.
export_df_org: None
property
¶
Export the dataframe.
export_df_pre: None
property
¶
Export the dataframe.
generate_report: None
property
¶
Generate the SpectraFit report of the final fit.
plot_current_df: None
property
¶
Plot the current spectra.
plot_original_df: None
property
¶
Plot the original spectra.
plot_preprocessed_df: None
property
¶
Plot the current processed spectra.
pre_process: None
property
¶
Pre-processing class.
return_df: pd.DataFrame
property
¶
Return the dataframe.
return_df_fit: pd.DataFrame
property
¶
Return the fit dataframe.
return_df_org: pd.DataFrame
property
¶
Return the original dataframe.
return_df_pre: Union[pd.DataFrame, None]
property
¶
Return the pre-processed dataframe.
return_pre_statistic: Dict[str, Any]
property
¶
Return the pre-processing statistic.
__init__(df, x_column, y_column, oversampling=False, smooth=0, shift=0, energy_start=None, energy_stop=None, title=None, xaxis_title=XAxisAPI(name='Energy', unit='eV'), yaxis_title=YAxisAPI(name='Intensity', unit='a.u.'), residual_title=ResidualAPI(name='Residual', unit='a.u.'), metric_title=MetricAPI(name_0='Metrics', unit_0='a.u.', name_1='Metrics', unit_1='a.u.'), run_title=RunAPI(name='Run', unit='#'), legend_title='Spectra', show_legend=True, legend=LegendAPI(orientation='h', yanchor='bottom', y=1.02, xanchor='right', x=1), font=FontAPI(family='Open Sans, monospace', size=12, color='black'), minor_ticks=True, color=ColorAPI(), grid=GridAPI(), size=(800, (600, 300)), fname='results', folder=None, description=DescriptionAPI())
¶
Initialize the SpectraFitNotebook class.
About Pydantic
-Definition
For being consistent with the SpectraFit
class, the SpectraFitNotebook
class refers to the Pydantic
-Definition of the SpectraFit
class. Currently, the following definitions are used:
XAxisAPI
: Definition of the x-axis including unitsYAxisAPI
: Definition of the y-axis including unitsResidualAPI
: Definition of the residual including unitsLegendAPI
: Definition of the legend according toPlotly
FontAPI
: Definition of the font according toPlotly
, which can be replaced by built-in definitionsColorAPI
: Definition of the colors according toPlotly
, which can be replace by built-in definitionsGridAPI
: Definition of the grid according toPlotly
DescriptionAPI
: Definition of the description of the fit project
All classes can be replaced by the corresponding dict
-definition.
LegendAPI(orientation="h", yanchor="bottom", y=1.02, xanchor="right", x=1)
can be also
dict(orientation="h", yanchor="bottom", y=1.02, xanchor="right", x=1)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df | pd.DataFrame | Dataframe with the data to fit. | required |
x_column | str | Name of the x column. | required |
y_column | Union[str, List[str]] | Name of the y column(s). | required |
oversampling | bool | Activate the oversampling options. Defaults to False. | False |
smooth | int | Activate the smoothing functions setting an | 0 |
shift | float | Apply shift to the x-column. Defaults to 0. | 0 |
energy_start | Optional[float] | Energy start. Defaults to None. | None |
energy_stop | Optional[float] | Energy stop. Defaults to None. | None |
title | Optional[str] | Plot title. Defaults to None. | None |
xaxis_title | XAxisAPI | X-Axis title. Defaults to XAxisAPI(). | XAxisAPI(name='Energy', unit='eV') |
yaxis_title | YAxisAPI | Y-Axis title. Defaults to YAxisAPI(). | YAxisAPI(name='Intensity', unit='a.u.') |
residual_title | ResidualAPI | Residual title. Defaults to ResidualAPI(). | ResidualAPI(name='Residual', unit='a.u.') |
metric_title | MetricAPI | Metric title for both axes, bar and line plot. Defaults to MetricAPI(). | MetricAPI(name_0='Metrics', unit_0='a.u.', name_1='Metrics', unit_1='a.u.') |
run_title | RunAPI | Run title. Defaults to RunAPI(). | RunAPI(name='Run', unit='#') |
legend_title | str | Legend title. Defaults to "Spectra". | 'Spectra' |
show_legend | bool | Show legend. Defaults to True. | True |
legend | LegendAPI | Legend options. Defaults to LegendAPI(). | LegendAPI(orientation='h', yanchor='bottom', y=1.02, xanchor='right', x=1) |
font | FontAPI | Font options. Defaults to FontAPI(). | FontAPI(family='Open Sans, monospace', size=12, color='black') |
minor_ticks | bool | Show minor ticks. Defaults to True. | True |
color | ColorAPI | Color options. Defaults to ColorAPI(). | ColorAPI() |
grid | GridAPI | Grid options. Defaults to GridAPI(). | GridAPI() |
size | Tuple[int, Tuple[int, int]] | Size of the fit- and metric- plot. First width defines the fit, the second the metrics. Defaults to (800, (600,300)). | (800, (600, 300)) |
fname | str | Filename of the export. Defaults to "results". | 'results' |
folder | Optional[str] | Folder of the export. Defaults to None. | None |
description | DescriptionAPI | Description of the data. Defaults to DescriptionAPI().. | DescriptionAPI() |
Raises:
Type | Description |
---|---|
ValueError | If the dataframe only contains one column. |
Source code in spectrafit/plugins/notebook.py
735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 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 |
|
display_current_df(mode='regular')
¶
Display the current dataframe.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mode | str | Display mode. Defaults to "regular". | 'regular' |
Source code in spectrafit/plugins/notebook.py
1159 1160 1161 1162 1163 1164 1165 |
|
display_fit_df(mode='regular')
¶
Display the fit dataframe.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mode | str | Display mode. Defaults to "regular". | 'regular' |
Source code in spectrafit/plugins/notebook.py
1135 1136 1137 1138 1139 1140 1141 |
|
display_original_df(mode='regular')
¶
Display the original dataframe.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mode | str | Display mode. Defaults to "regular". | 'regular' |
Source code in spectrafit/plugins/notebook.py
1151 1152 1153 1154 1155 1156 1157 |
|
display_preprocessed_df(mode='regular')
¶
Display the preprocessed dataframe.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mode | str | Display mode. Defaults to "regular". | 'regular' |
Source code in spectrafit/plugins/notebook.py
1143 1144 1145 1146 1147 1148 1149 |
|
plot_current_metric(bar_criteria=None, line_criteria=None)
¶
Plot the current metric.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
bar_criteria | Optional[Union[str, List[str]]] | Criteria for the bar plot. Defaults to None. | None |
line_criteria | Optional[Union[str, List[str]]] | Criteria for the line plot. Defaults to None. | None |
Source code in spectrafit/plugins/notebook.py
971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 |
|
plot_fit_df()
¶
Plot the fit.
Source code in spectrafit/plugins/notebook.py
964 965 966 967 968 969 |
|
solver_model(initial_model, show_plot=True, show_metric=True, show_df=False, show_peaks=False, conf_interval=False, bar_criteria=None, line_criteria=None)
¶
Solves the fit problem based on the proposed model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
initial_model | List[Dict[str, Dict[str, Dict[str, Any]]]] | List of dictionary with the initial model and its fitting parameters and options for the components. | required |
show_plot | bool | Show current fit results as plot. Defaults to True. | True |
show_metric | bool | Show the metric of the fit. Defaults to True. | True |
show_df | bool | Show current fit results as dataframe. Defaults to False. | False |
show_peaks | bool | Show the peaks of fit. Defaults to False. | False |
conf_interval | Union[bool, Dict[str, Any]] | Bool or dictionary for the parameter with the parameter for calculating the confidence interval. Using | False |
bar_criteria | Optional[Union[str, List[str]]] | Criteria for the bar plot. It is recommended to use attributes from | None |
line_criteria | Optional[Union[str, List[str]]] | Criteria for the line plot. It is recommended to use attributes from | None |
!!! info: "About criteria"
The criteria for the bar and line plot are defined as a list of strings.
The supported keywords are defined by the built-in metrics for
`goodness of fit` and `regression` and can be checked in [documentation](
https://anselmoo.github.io/spectrafit/doc/statistics/
).
Source code in spectrafit/plugins/notebook.py
1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 |
|
update_metric()
¶
Update the metric dataframe.
Source code in spectrafit/plugins/notebook.py
1128 1129 1130 1131 1132 1133 |
|
update_peaks()
¶
Update the peaks dataframe as multi-column dataframe.
The multi-column dataframe is used for the interactive display of the peaks with initial, current (model), and best fit values.
Source code in spectrafit/plugins/notebook.py
1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 |
|
Color Scheme¶
For changing the color scheme of the plots, additional color schemes can be added to the spectrafit.plugins.notebook
module. The color schemes are defined as a pydantic BaseSettings
class with the following attributes:
Color Schemas for the Plots in Jupyter Notebooks.
DraculaColor
¶
Bases: BaseModel
Dracula color schema for SpectraFit.
Dracula Color
The Dracula Color is a color schema is used for the dark mode of the SpectraFit
application. This color schema is used in the following way:
- Background #282a36 → paper, plot
- Current Line #44475a → not used
- Foreground #f8f8f2 → color, grid, ticks, font
- Comment #6272a4 → line
- Cyan #8be9fd → zero_line
- Green #50fa7b → fit
- Orange #ffb86c → not used
- Pink #ff79c6 → components
- Purple #bd93f9 → intensity
- Red #ff5555 → residual
- Yellow #f1fa8c → not used
Source code in spectrafit/plugins/color_schemas.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
|
DraculaFont
¶
Bases: BaseModel
Dracula font schema for SpectraFit.
Dracula Font
The Dracula Font is a font schema is used for the dark mode of the SpectraFit
application. This font schema is used in the following way:
- Font Family "Fira Code" → family
- Font Size 12 → size
- Font Color dracula white → color
See also: https://github.com/tonsky/FiraCode
Source code in spectrafit/plugins/color_schemas.py
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
|
Running SpectraFit in the builtin Jupyter-Notebook¶
For running SpectraFit
in the builtin Jupyter-Notebook, the following command can be used:
spectrafit-jupyter
And next, the SpectraFitNotebook
class can be used for fitting the data:
from spectrafit.plugins.notebook import SpectraFitNotebook