brixs 0.0.9__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (266) hide show
  1. brixs/__init__.py +47 -0
  2. brixs/addons/__init__.py +0 -0
  3. brixs/addons/centroid.py +417 -0
  4. brixs/addons/experimental.py +1628 -0
  5. brixs/addons/finder(safecopy).py +522 -0
  6. brixs/addons/finder.py +543 -0
  7. brixs/addons/fitting.py +419 -0
  8. brixs/addons/h5.py +172 -0
  9. brixs/addons/labels.py +94 -0
  10. brixs/addons/png2clipboard.py +59 -0
  11. brixs/addons/sendemail.py +54 -0
  12. brixs/addons/sound.py +90 -0
  13. brixs/addons/svg.py +142 -0
  14. brixs/backpack/__init__.py +6 -0
  15. brixs/backpack/arraymanip.py +456 -0
  16. brixs/backpack/figmanip.py +3967 -0
  17. brixs/backpack/filemanip.py +703 -0
  18. brixs/backpack/numanip.py +143 -0
  19. brixs/backpack/query.py +189 -0
  20. brixs/beamlines/PEAXIS.py +67 -0
  21. brixs/beamlines/VERITAS.py +1320 -0
  22. brixs/beamlines/VERITASods.py +679 -0
  23. brixs/beamlines/adress/__init__.py +3 -0
  24. brixs/beamlines/adress/adress.py +961 -0
  25. brixs/beamlines/i21/__init__.py +2 -0
  26. brixs/beamlines/i21/advanced.py +1037 -0
  27. brixs/beamlines/i21/core.py +524 -0
  28. brixs/beamlines/i21/obsolete/i21.py +797 -0
  29. brixs/beamlines/i21/template.py +4 -0
  30. brixs/beamlines/id32.py +301 -0
  31. brixs/beamlines/ipe/__init__.py +3 -0
  32. brixs/beamlines/ipe/advanced.py +818 -0
  33. brixs/beamlines/ipe/core.py +700 -0
  34. brixs/beamlines/ipe/experimental.py +182 -0
  35. brixs/beamlines/ipe/ipeods.py +857 -0
  36. brixs/beamlines/ipe/obsolete/IPE_old.py +1852 -0
  37. brixs/beamlines/ipe/obsolete/ipe.py +1675 -0
  38. brixs/beamlines/ipe/quickviewer/ascan.py +706 -0
  39. brixs/beamlines/ipe/quickviewer/back.png +0 -0
  40. brixs/beamlines/ipe/quickviewer/default.py +250 -0
  41. brixs/beamlines/ipe/quickviewer/folder.png +0 -0
  42. brixs/beamlines/ipe/quickviewer/update.png +0 -0
  43. brixs/beamlines/ipe/quickviewer/xas.py +701 -0
  44. brixs/beamlines/scs/__init__.py +3 -0
  45. brixs/beamlines/scs/scs.py +1912 -0
  46. brixs/brixs.py +10732 -0
  47. brixs/config.py +250 -0
  48. brixs/crystal/__init__.py +4 -0
  49. brixs/crystal/crystal.py +153 -0
  50. brixs/model/__init__.py +31 -0
  51. brixs/model/example.py +549 -0
  52. brixs/model/model(safe).py +2102 -0
  53. brixs/model/model.py +3259 -0
  54. brixs/model/model_functions.py +309 -0
  55. brixs/model/peaks.py +2466 -0
  56. brixs/sheets/common.py +65 -0
  57. brixs/sheets/libreoffice/attrs_cell.txt +110 -0
  58. brixs/sheets/libreoffice/attrs_doc_calc.txt +274 -0
  59. brixs/sheets/libreoffice/attrs_doc_writer.txt +307 -0
  60. brixs/sheets/libreoffice/attrs_range.txt +216 -0
  61. brixs/sheets/libreoffice/attrs_sheet.txt +313 -0
  62. brixs/sheets/libreoffice/mymacro.py +1776 -0
  63. brixs/sheets/libreoffice/obsolete/.gitignore +131 -0
  64. brixs/sheets/libreoffice/obsolete/LICENSE +674 -0
  65. brixs/sheets/libreoffice/obsolete/README.rst +387 -0
  66. brixs/sheets/libreoffice/obsolete/_aux/Sheets_attrs.text +348 -0
  67. brixs/sheets/libreoffice/obsolete/_aux/cell.txt +267 -0
  68. brixs/sheets/libreoffice/obsolete/_aux/document(calc)_attrs.text +271 -0
  69. brixs/sheets/libreoffice/obsolete/_aux/property.txt +104 -0
  70. brixs/sheets/libreoffice/obsolete/example_calc.py +251 -0
  71. brixs/sheets/libreoffice/obsolete/libreoffice_wrapper.py +2183 -0
  72. brixs/sheets/libreoffice/obsolete/scripts/optimize/.temporary_fig.svg +515 -0
  73. brixs/sheets/libreoffice/obsolete/scripts/optimize/.~lock.fit.ods# +1 -0
  74. brixs/sheets/libreoffice/obsolete/scripts/optimize/datafit.py +915 -0
  75. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/data/00_Co3O2BO3_15K.dat +6879 -0
  76. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/data/01_Co3O2BO3_17K.dat +2049 -0
  77. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/data/02_Co3O2BO3_18K.dat +2049 -0
  78. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/data/03_Co3O2BO3_20K.dat +2049 -0
  79. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/data/04_Co3O2BO3_22K.dat +2049 -0
  80. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/data/05_Co3O2BO3_22K.dat +2049 -0
  81. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/data/06_Co3O2BO3_23K.dat +2049 -0
  82. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/data/07_Co3O2BO3_24K.dat +2049 -0
  83. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/data/08_Co3O2BO3_25K.dat +2049 -0
  84. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/data/09_Co3O2BO3_26K.dat +2049 -0
  85. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/data/10_Co3O2BO3_27K.dat +2049 -0
  86. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/data/11_Co3O2BO3_28K.dat +2049 -0
  87. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/data/12_Co3O2BO3_28K.dat +2049 -0
  88. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/data/13_Co3O2BO3_29K.dat +2049 -0
  89. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/data/14_Co3O2BO3_30K.dat +2049 -0
  90. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/data/15_Co3O2BO3_31K.dat +2049 -0
  91. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/data/16_Co3O2BO3_32K.dat +2049 -0
  92. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/data/17_Co3O2BO3_33K.dat +2049 -0
  93. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/data/18_Co3O2BO3_33K.dat +2013 -0
  94. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/data/19_Co3O2BO3_34K.dat +2049 -0
  95. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/data/20_Co3O2BO3_35K.dat +2049 -0
  96. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/data/21_Co3O2BO3_36K.dat +2049 -0
  97. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/data/22_Co3O2BO3_37K.dat +2049 -0
  98. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/data/23_Co3O2BO3_38K.dat +2049 -0
  99. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/data/24_Co3O2BO3_39K.dat +2049 -0
  100. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/data/25_Co3O2BO3_40K.dat +2049 -0
  101. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/data/26_Co3O2BO3_41K.dat +2049 -0
  102. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/data/27_Co3O2BO3_42K.dat +2049 -0
  103. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/data/28_Co3O2BO3_42K.dat +2049 -0
  104. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/data/29_Co3O2BO3_43K.dat +2049 -0
  105. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/data/30_Co3O2BO3_43K.dat +2049 -0
  106. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/data/31_Co3O2BO3_44K.dat +2049 -0
  107. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/data/32_Co3O2BO3_45K.dat +2049 -0
  108. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/data/33_Co3O2BO3_45K.dat +2049 -0
  109. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/data/34_Co3O2BO3_46K.dat +2049 -0
  110. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/data/35_Co3O2BO3_47K.dat +2049 -0
  111. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/data/36_Co3O2BO3_48K.dat +2049 -0
  112. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/data/37_Co3O2BO3_49K.dat +2049 -0
  113. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/data/38_Co3O2BO3_50K.dat +2049 -0
  114. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/data/39_Co3O2BO3_51K.dat +2049 -0
  115. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/data/40_Co3O2BO3_52K.dat +2049 -0
  116. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/data/41_Co3O2BO3_53K.dat +2049 -0
  117. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/data/42_Co3O2BO3_54K.dat +2049 -0
  118. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/data/43_Co3O2BO3_56K.dat +2049 -0
  119. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/data/44_Co3O2BO3_57K.dat +2049 -0
  120. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/data/45_Co3O2BO3_58K.dat +2049 -0
  121. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/data/46_Co3O2BO3_60K.dat +2049 -0
  122. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/data/47_Co3O2BO3_60K.dat +2049 -0
  123. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/data/48_Co3O2BO3_61K.dat +2049 -0
  124. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/data/49_Co3O2BO3_62K.dat +2049 -0
  125. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/data/50_Co3O2BO3_65K.dat +2049 -0
  126. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/data/51_Co3O2BO3_70K.dat +3438 -0
  127. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/data/52_Co3O2BO3_70K.dat +2049 -0
  128. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/data/53_Co3O2BO3_70K.dat +2049 -0
  129. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/data/54_Co3O2BO3_80K.dat +3469 -0
  130. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/data/55_Co3O2BO3_80K.dat +2049 -0
  131. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/data/56_Co3O2BO3_90K.dat +3469 -0
  132. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/data/57_Co3O2BO3_90K.dat +2049 -0
  133. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/data/58_Co3O2BO3_100K.dat +6878 -0
  134. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/data/59_Co3O2BO3_150K.dat +2049 -0
  135. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/data/60_Co3O2BO3_200K.dat +3453 -0
  136. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/data/61_Co3O2BO3_200K.dat +2049 -0
  137. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/data/62_Co3O2BO3_210K.dat +6878 -0
  138. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/data/63_Co3O2BO3_260K.dat +2049 -0
  139. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/data/64_Co3O2BO3_300K.dat +2213 -0
  140. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/data/65_Co3O2BO3_300K.dat +3469 -0
  141. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/data/66_Co3O2BO3_300K.dat +6878 -0
  142. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/data/67_Co3O2BO3_320K.dat +2027 -0
  143. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/data/68_Co3O2BO3_340K.dat +2029 -0
  144. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/data/69_Co3O2BO3_360K.dat +2029 -0
  145. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/data/70_Co3O2BO3_360K.dat +2027 -0
  146. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/data/71_Co3O2BO3_380K.dat +2027 -0
  147. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/data/72_Co3O2BO3_400K.dat +3453 -0
  148. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/data/73_Co3O2BO3_400K.dat +2023 -0
  149. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/data/74_Co3O2BO3_420K.dat +2023 -0
  150. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/data/75_Co3O2BO3_440K.dat +1909 -0
  151. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/data/76_Co3O2BO3_450K.dat +3453 -0
  152. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/data/77_Co3O2BO3_455K.dat +1909 -0
  153. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/data/78_Co3O2BO3_465K.dat +2049 -0
  154. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/data/79_Co3O2BO3_470K.dat +2049 -0
  155. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/data/80_Co3O2BO3_472K.dat +3453 -0
  156. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/data/81_Co3O2BO3_480K.dat +2036 -0
  157. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/data/82_Co3O2BO3_482K.dat +3453 -0
  158. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/data/83_Co3O2BO3_489K.dat +3453 -0
  159. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/data/84_Co3O2BO3_490K.dat +2016 -0
  160. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/data/85_Co3O2BO3_500K.dat +3453 -0
  161. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/data/86_Co3O2BO3_500K.dat +1941 -0
  162. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/fit_data.py +607 -0
  163. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/fit_parameters.ods +0 -0
  164. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/optimized_parameters/00_Co3O2BO3_15K.dat +6853 -0
  165. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/optimized_parameters/01_Co3O2BO3_17K.dat +2027 -0
  166. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/optimized_parameters/02_Co3O2BO3_18K.dat +2024 -0
  167. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/optimized_parameters/03_Co3O2BO3_20K.dat +2019 -0
  168. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/optimized_parameters/04_Co3O2BO3_22K.dat +2023 -0
  169. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/optimized_parameters/05_Co3O2BO3_22K.dat +2022 -0
  170. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/optimized_parameters/06_Co3O2BO3_23K.dat +2021 -0
  171. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/optimized_parameters/07_Co3O2BO3_24K.dat +2025 -0
  172. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/optimized_parameters/08_Co3O2BO3_25K.dat +2022 -0
  173. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/optimized_parameters/09_Co3O2BO3_26K.dat +2021 -0
  174. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/optimized_parameters/10_Co3O2BO3_27K.dat +2017 -0
  175. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/optimized_parameters/11_Co3O2BO3_28K.dat +2023 -0
  176. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/optimized_parameters/12_Co3O2BO3_28K.dat +2023 -0
  177. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/optimized_parameters/13_Co3O2BO3_29K.dat +2025 -0
  178. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/optimized_parameters/14_Co3O2BO3_30K.dat +2022 -0
  179. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/optimized_parameters/15_Co3O2BO3_31K.dat +2013 -0
  180. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/optimized_parameters/16_Co3O2BO3_32K.dat +2021 -0
  181. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/optimized_parameters/17_Co3O2BO3_33K.dat +2029 -0
  182. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/optimized_parameters/18_Co3O2BO3_33K.dat +1987 -0
  183. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/optimized_parameters/19_Co3O2BO3_34K.dat +2023 -0
  184. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/optimized_parameters/20_Co3O2BO3_35K.dat +2021 -0
  185. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/optimized_parameters/21_Co3O2BO3_36K.dat +2022 -0
  186. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/optimized_parameters/22_Co3O2BO3_37K.dat +2022 -0
  187. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/optimized_parameters/23_Co3O2BO3_38K.dat +2025 -0
  188. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/optimized_parameters/24_Co3O2BO3_39K.dat +2021 -0
  189. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/optimized_parameters/25_Co3O2BO3_40K.dat +2024 -0
  190. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/optimized_parameters/26_Co3O2BO3_41K.dat +2019 -0
  191. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/optimized_parameters/27_Co3O2BO3_42K.dat +2021 -0
  192. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/optimized_parameters/28_Co3O2BO3_42K.dat +2021 -0
  193. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/optimized_parameters/29_Co3O2BO3_43K.dat +2019 -0
  194. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/optimized_parameters/30_Co3O2BO3_43K.dat +2021 -0
  195. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/optimized_parameters/31_Co3O2BO3_44K.dat +2015 -0
  196. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/optimized_parameters/32_Co3O2BO3_45K.dat +2017 -0
  197. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/optimized_parameters/33_Co3O2BO3_45K.dat +2022 -0
  198. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/optimized_parameters/34_Co3O2BO3_46K.dat +2021 -0
  199. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/optimized_parameters/35_Co3O2BO3_47K.dat +2014 -0
  200. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/optimized_parameters/36_Co3O2BO3_48K.dat +2017 -0
  201. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/optimized_parameters/37_Co3O2BO3_49K.dat +2017 -0
  202. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/optimized_parameters/38_Co3O2BO3_50K.dat +2021 -0
  203. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/optimized_parameters/39_Co3O2BO3_51K.dat +2021 -0
  204. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/optimized_parameters/40_Co3O2BO3_52K.dat +2018 -0
  205. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/optimized_parameters/41_Co3O2BO3_53K.dat +2021 -0
  206. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/optimized_parameters/42_Co3O2BO3_54K.dat +2021 -0
  207. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/optimized_parameters/43_Co3O2BO3_56K.dat +2018 -0
  208. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/optimized_parameters/44_Co3O2BO3_57K.dat +2015 -0
  209. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/optimized_parameters/45_Co3O2BO3_58K.dat +2019 -0
  210. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/optimized_parameters/46_Co3O2BO3_60K.dat +2018 -0
  211. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/optimized_parameters/47_Co3O2BO3_60K.dat +2025 -0
  212. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/optimized_parameters/48_Co3O2BO3_61K.dat +2021 -0
  213. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/optimized_parameters/49_Co3O2BO3_62K.dat +2019 -0
  214. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/optimized_parameters/50_Co3O2BO3_65K.dat +2027 -0
  215. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/optimized_parameters/51_Co3O2BO3_70K.dat +3407 -0
  216. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/optimized_parameters/52_Co3O2BO3_70K.dat +2025 -0
  217. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/optimized_parameters/53_Co3O2BO3_70K.dat +2032 -0
  218. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/optimized_parameters/54_Co3O2BO3_80K.dat +3439 -0
  219. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/optimized_parameters/55_Co3O2BO3_80K.dat +2033 -0
  220. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/optimized_parameters/56_Co3O2BO3_90K.dat +3438 -0
  221. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/optimized_parameters/57_Co3O2BO3_90K.dat +2034 -0
  222. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/optimized_parameters/58_Co3O2BO3_100K.dat +6861 -0
  223. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/optimized_parameters/59_Co3O2BO3_150K.dat +2034 -0
  224. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/optimized_parameters/60_Co3O2BO3_200K.dat +3423 -0
  225. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/optimized_parameters/61_Co3O2BO3_200K.dat +2033 -0
  226. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/optimized_parameters/62_Co3O2BO3_210K.dat +6863 -0
  227. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/optimized_parameters/63_Co3O2BO3_260K.dat +2033 -0
  228. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/optimized_parameters/64_Co3O2BO3_300K.dat +2180 -0
  229. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/optimized_parameters/65_Co3O2BO3_300K.dat +3449 -0
  230. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/optimized_parameters/66_Co3O2BO3_300K.dat +6856 -0
  231. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/optimized_parameters/67_Co3O2BO3_320K.dat +2006 -0
  232. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/optimized_parameters/68_Co3O2BO3_340K.dat +2008 -0
  233. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/optimized_parameters/69_Co3O2BO3_360K.dat +2008 -0
  234. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/optimized_parameters/70_Co3O2BO3_360K.dat +2005 -0
  235. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/optimized_parameters/71_Co3O2BO3_380K.dat +2001 -0
  236. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/optimized_parameters/72_Co3O2BO3_400K.dat +3422 -0
  237. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/optimized_parameters/73_Co3O2BO3_400K.dat +1997 -0
  238. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/optimized_parameters/74_Co3O2BO3_420K.dat +1997 -0
  239. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/optimized_parameters/75_Co3O2BO3_440K.dat +1884 -0
  240. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/optimized_parameters/76_Co3O2BO3_450K.dat +3422 -0
  241. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/optimized_parameters/77_Co3O2BO3_455K.dat +1884 -0
  242. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/optimized_parameters/78_Co3O2BO3_465K.dat +2033 -0
  243. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/optimized_parameters/79_Co3O2BO3_470K.dat +2032 -0
  244. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/optimized_parameters/80_Co3O2BO3_472K.dat +3421 -0
  245. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/optimized_parameters/81_Co3O2BO3_480K.dat +2019 -0
  246. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/optimized_parameters/82_Co3O2BO3_482K.dat +3423 -0
  247. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/optimized_parameters/83_Co3O2BO3_489K.dat +3421 -0
  248. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/optimized_parameters/84_Co3O2BO3_490K.dat +2000 -0
  249. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/optimized_parameters/85_Co3O2BO3_500K.dat +3422 -0
  250. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/optimized_parameters/86_Co3O2BO3_500K.dat +1925 -0
  251. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/optimized_parameters/fwhmVoigt#0.txt +21 -0
  252. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/optimized_parameters/fwhmVoigt#3.txt +21 -0
  253. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/optimized_parameters/fwhmVoigt#4.txt +21 -0
  254. brixs/sheets/libreoffice/obsolete/scripts/optimize/example/optimized_parameters/fwhmVoigt#5.txt +21 -0
  255. brixs/sheets/libreoffice/obsolete/scripts/optimize/fit.ods +0 -0
  256. brixs/sheets/libreoffice/obsolete/scripts/optimize/model_functions.py +227 -0
  257. brixs/sheets/libreoffice/obsolete/scripts/optimize/readme.rst +0 -0
  258. brixs/sheets/libreoffice/obsolete/tmux.conf +1 -0
  259. brixs/sheets/libreoffice/temporary.py +142 -0
  260. brixs/sheets/libreoffice.py +198 -0
  261. brixs/sheets/ods.py +465 -0
  262. brixs/sheets/xlsx.py +425 -0
  263. brixs-0.0.9.dist-info/METADATA +35 -0
  264. brixs-0.0.9.dist-info/RECORD +266 -0
  265. brixs-0.0.9.dist-info/WHEEL +4 -0
  266. brixs-0.0.9.dist-info/licenses/LICENSE +21 -0
@@ -0,0 +1,1628 @@
1
+ #! /usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+ """Experimental functions and methods"""
4
+
5
+ # %% ------------------------- Standard Imports --------------------------- %% #
6
+ import matplotlib.pyplot as plt
7
+ import matplotlib
8
+ import numpy as np
9
+ # %%
10
+
11
+ # %% -------------------------- brixs Imports ----------------------------- %% #
12
+ import brixs as br
13
+ # %%
14
+
15
+ # %% Spectra
16
+ def sequential_plot(self, xlim=None, ylim=None, keep=None, update_function=None, **kwargs):
17
+ """[EXPERIMENTAL] plot where you can use up and down keys to flip through spectra.
18
+
19
+ Warning:
20
+ Only one plot can be open at a time. Also, some default
21
+ matplotlib keybidings are changed (should not be a problem)
22
+
23
+ Args:
24
+ xlim (tuple, optional): min and max ``x`` value. Default is None (full
25
+ data range).
26
+ ylim (tuple, optional): min and max ``y`` value. Default is None.
27
+ keep (int, optional): index of the spectrum to keep on screen.
28
+ update_function (function, optional): function that is called when
29
+ the left or right arrows are pressed. update_function must be a
30
+ function of type:
31
+
32
+ >>> def update_function(ss, __i):
33
+ >>> plt.title(__i)
34
+ >>> ss[__i].plot(color='black', marker='o')
35
+
36
+ where ``__i`` is updated in every iteraction.
37
+ **kwargs: kwargs are passed to ``plt.plot()`` that plots the data.
38
+
39
+ Returns:
40
+ None
41
+ """
42
+ # vars
43
+ self.__i = 0
44
+ self.__xlim = xlim
45
+ self.__ylim = ylim
46
+ self.__ax = None
47
+
48
+ # change keybindings
49
+ try:
50
+ matplotlib.rcParams['keymap.back'].remove('left')
51
+ matplotlib.rcParams['keymap.forward'].remove('right')
52
+ except ValueError:
53
+ pass
54
+
55
+ # lims
56
+ if self.__xlim is None:
57
+ self.__xlim = [min(self[0].x), max(self[0].x)]
58
+ for s in self:
59
+ if min(s.x) < self.__xlim[0]:
60
+ self.__xlim[0] = min(s.x)
61
+ if max(s.x) > self.__xlim[1]:
62
+ self.__xlim[1] = max(s.x)
63
+ if self.__ylim is None:
64
+ self.__ylim = [min(self[0].y), max(self[0].y)]
65
+ for s in self:
66
+ if min(s.y) < self.__ylim[0]:
67
+ self.__ylim[0] = min(s.y)
68
+ if max(s.y) > self.__ylim[1]:
69
+ self.__ylim[1] = max(s.y)
70
+
71
+ # keep
72
+ if keep is not None:
73
+ if isinstance(keep, str):
74
+ assert keep == 'previous' or keep == 'next', 'keep must be a valid spectrum index, or "previous/next"'
75
+ else:
76
+ assert abs(keep) < len(self), 'keep must be a valid spectrum index, or "previous/next"'
77
+
78
+ # kwargs
79
+ if 'color' not in kwargs:
80
+ kwargs['color'] = 'black'
81
+ if 'marker' not in kwargs:
82
+ kwargs['marker'] = 'o'
83
+
84
+ # core update function
85
+ if update_function is None:
86
+ def _update(ss):
87
+ if self.__i >= len(self):
88
+ self.__i = len(self) - 1
89
+ elif self.__i < 0:
90
+ self.__i = 0
91
+
92
+ plt.title(self.__i)
93
+ if keep is not None:
94
+ if keep == 'next':
95
+ if self.__i+1 < len(self):
96
+ ss[self.__i+1].plot(color='red', alpha=0.5)
97
+ elif keep == 'previous':
98
+ if self.__i-1 >= 0:
99
+ ss[self.__i-1].plot(color='red', alpha=0.5)
100
+ else:
101
+ ss[keep].plot(color='red', alpha=0.5)
102
+ ss[self.__i].plot(**kwargs)
103
+
104
+ if self.__xlim is not None:
105
+ plt.xlim(self.__xlim)
106
+ if self.__ylim is not None:
107
+ plt.ylim(self.__ylim)
108
+ else:
109
+ # add counter and xlim/ylim to update function
110
+ def _update(ss):
111
+ if self.__i >= len(self):
112
+ self.__i = len(self) - 1
113
+ elif self.__i < 0:
114
+ self.__i = 0
115
+
116
+ update_function(ss, __i=self.__i)
117
+
118
+ if self.__xlim is not None:
119
+ plt.xlim(self.__xlim)
120
+ if self.__ylim is not None:
121
+ plt.ylim(self.__ylim)
122
+
123
+ # keyboard events
124
+ def keyboard(event, ss):
125
+ # print(event.key)
126
+ # print('keyboard')
127
+ # print(event.key)
128
+ if event.key == 'right' or event.key == 'up':
129
+ self.__i = self.__i + 1
130
+
131
+ # self.__ax.cla()
132
+ # for line in self.__ax.lines:
133
+ # line.remove()
134
+ self.__ax.lines.clear()
135
+ _update(ss)
136
+ plt.draw()
137
+
138
+ elif event.key == 'left' or event.key == 'down':
139
+ self.__i = self.__i - 1
140
+
141
+ # self.__ax.cla()
142
+ # for line in self.__ax.lines:
143
+ # line.remove()
144
+ self.__ax.lines.clear()
145
+ _update(ss)
146
+ plt.draw()
147
+
148
+ # mouse events
149
+ def mouse(event):
150
+ """Mouse can be used with a keyboard key"""
151
+ # print('mouse')
152
+ # print(event.key)
153
+ # print(event.button)
154
+ pass
155
+
156
+ # axis zoom changes
157
+ def on_xlims_change(event_ax):
158
+ # print("updated xlims: ", event_ax.get_xlim())
159
+ self.__xlim = event_ax.get_xlim()
160
+
161
+ def on_ylims_change(event_ax):
162
+ # print("updated ylims: ", event_ax.get_ylim())
163
+ self.__ylim = event_ax.get_ylim()
164
+
165
+ # plotting
166
+ fig, self.__ax = plt.subplots(1, 1)
167
+ _update(self)
168
+
169
+ # register callbacks
170
+ fig.canvas.mpl_connect('key_press_event', lambda event: keyboard(event, ss=self))
171
+ fig.canvas.mpl_connect('button_press_event', lambda event: mouse(event))
172
+
173
+ self.__ax.callbacks.connect('xlim_changed', on_xlims_change)
174
+ self.__ax.callbacks.connect('ylim_changed', on_ylims_change)
175
+ return
176
+ br.Spectra.sequential_plot = sequential_plot
177
+
178
+ def sequential_plot2(self, xlim=None, ylim=None, keep=None, update_function=None, **kwargs):
179
+ """[EXPERIMENTAL] plot where you can use arrows to flip through spectra.
180
+
181
+ Warning:
182
+ Old version, zoom is reset every time. Only one plot can be open at a time.
183
+ Also, some default matplotlib keybidings are changed (should not be a problem)
184
+
185
+ Args:
186
+ xlim (tuple, optional): min and max ``x`` value. Default is None (full
187
+ data range).
188
+ ylim (tuple, optional): min and max ``y`` value. Default is None.
189
+ keep (int, optional): index of the spectrum to keep on screen.
190
+ update_function (function, optional): function that is called when
191
+ the left or right arrows are pressed. update_function must be a
192
+ function of type:
193
+
194
+ >>> def update_function(ss, __i):
195
+ >>> plt.title(__i)
196
+ >>> ss[__i].plot(color='black', marker='o')
197
+
198
+ where ``__i`` is updated in every iteraction.
199
+ **kwargs: kwargs are passed to ``plt.plot()`` that plots the data.
200
+
201
+ Returns:
202
+ None
203
+ """
204
+ self.__i = 0
205
+
206
+ # change keybindings
207
+ try:
208
+ matplotlib.rcParams['keymap.back'].remove('left')
209
+ matplotlib.rcParams['keymap.forward'].remove('right')
210
+ except ValueError:
211
+ pass
212
+
213
+ # keep
214
+ if keep is not None:
215
+ if isinstance(keep, str):
216
+ assert keep == 'previous' or keep == 'next', 'keep must be a valid spectrum index, or "previous/next"'
217
+ else:
218
+ assert abs(keep) < len(self), 'keep must be a valid spectrum index, or "previous/next"'
219
+
220
+ # kwargs
221
+ if 'color' not in kwargs:
222
+ kwargs['color'] = 'black'
223
+ if 'marker' not in kwargs:
224
+ kwargs['marker'] = 'o'
225
+
226
+ # core update function
227
+ if update_function is None:
228
+ def _update(ss):
229
+ if self.__i >= len(self):
230
+ self.__i = len(self) - 1
231
+ elif self.__i < 0:
232
+ self.__i = 0
233
+
234
+ plt.title(self.__i)
235
+ if keep is not None:
236
+ if keep == 'next':
237
+ if self.__i+1 < len(self):
238
+ ss[self.__i+1].plot(color='red', alpha=0.5)
239
+ elif keep == 'previous':
240
+ if self.__i-1 >= 0:
241
+ ss[self.__i-1].plot(color='red', alpha=0.5)
242
+ else:
243
+ ss[keep].plot(color='red', alpha=0.5)
244
+ ss[self.__i].plot(**kwargs)
245
+
246
+ if xlim is not None:
247
+ plt.xlim(xlim)
248
+ if ylim is not None:
249
+ plt.ylim(ylim)
250
+ else:
251
+ # add counter and xlim/ylim to update function
252
+ def _update(ss):
253
+ if self.__i >= len(self):
254
+ self.__i = len(self) - 1
255
+ elif self.__i < 0:
256
+ self.__i = 0
257
+
258
+ update_function(ss, __i=self.__i)
259
+
260
+ if xlim is not None:
261
+ plt.xlim(xlim)
262
+ if ylim is not None:
263
+ plt.ylim(ylim)
264
+
265
+ # keyboard events
266
+ def keyboard(event, ss):
267
+ # print(event.key)
268
+ # print('keyboard')
269
+ # print(event.key)
270
+ if event.key == 'right' or event.key == 'up':
271
+ self.__i = self.__i + 1
272
+
273
+ plt.cla()
274
+ _update(ss)
275
+ plt.draw()
276
+ elif event.key == 'left' or event.key == 'down':
277
+ self.__i = self.__i - 1
278
+
279
+ plt.cla()
280
+ _update(ss)
281
+ plt.draw()
282
+
283
+ # mouse events
284
+ def mouse(event):
285
+ """Mouse can be used with a keyboard key"""
286
+ # print('mouse')
287
+ # print(event.key)
288
+ # print(event.button)
289
+ pass
290
+
291
+ # plotting
292
+ fig = br.figure()
293
+
294
+ # register callbacks
295
+ fig.canvas.mpl_connect('key_press_event', lambda event: keyboard(event, ss=self))
296
+ fig.canvas.mpl_connect('button_press_event', lambda event: mouse(event))
297
+
298
+ _update(self)
299
+ return
300
+ # br.Spectra.sequential_plot2 = sequential_plot2
301
+
302
+ def shift_plot(self, xlim=None, ylim=None, step=None, vlines=None, keep=None, update_function=None, **kwargs):
303
+ """[EXPERIMENTAL] flip through spectra (up/down keys), shift spectrum (a/d keys)
304
+
305
+ Warning:
306
+ Only one plot can be open at a time. Also, some default
307
+ matplotlib keybidings are changed (should not be a problem)
308
+
309
+ Args:
310
+ xlim (tuple, optional): min and max ``x`` value. Default is None (full
311
+ data range).
312
+ ylim (tuple, optional): min and max ``y`` value. Default is None.
313
+ step (number, optional): step. If None, 1% of the min datapoint
314
+ separation is used.
315
+ vlines (list or number, optional): vertical dashed lines for
316
+ reference, default is None.
317
+ keep (int, optional): index of the spectrum to keep on screen.
318
+ update_function (function, optional): function that is called when
319
+ the left or right arrows are pressed. update_function must be a
320
+ function of type:
321
+
322
+ >>> def update_function(ss, __i):
323
+ >>> plt.title(__i)
324
+ >>> ss[__i].plot(shift=ss._calculated_shift[__i])
325
+
326
+ where ``__i`` is updated in every iteraction.
327
+ **kwargs: kwargs are passed to ``plt.plot()`` that plots the data.
328
+
329
+ Returns:
330
+ None
331
+ """
332
+ self.__i = 0
333
+ self.__xlim = xlim
334
+ self.__ylim = ylim
335
+ self.__ax = None
336
+ self._calculated_shift = np.array([0.0]*len(self))
337
+
338
+ # set step
339
+ if step is None:
340
+ if self.step is None:
341
+ try:
342
+ self.check_step()
343
+ self.__step = self.step*0.5
344
+ except:
345
+ self.__step = min([np.mean(np.diff(s.x)) for s in self])*0.5
346
+ else:
347
+ self.__step = self.step*0.5
348
+ else:
349
+ self.__step = step
350
+
351
+ # change keybindings
352
+ try:
353
+ matplotlib.rcParams['keymap.back'].remove('left')
354
+ matplotlib.rcParams['keymap.forward'].remove('right')
355
+ except ValueError:
356
+ pass
357
+
358
+ # keep
359
+ if keep is not None:
360
+ if isinstance(keep, str):
361
+ assert keep == 'previous' or keep == 'next', 'keep must be a valid spectrum index, or "previous/next"'
362
+ else:
363
+ assert abs(keep) < len(self), 'keep must be a valid spectrum index, or "previous/next"'
364
+
365
+ # kwargs
366
+ if 'color' not in kwargs:
367
+ kwargs['color'] = 'black'
368
+ if 'marker' not in kwargs:
369
+ kwargs['marker'] = 'o'
370
+
371
+ # core update function
372
+ if update_function is None:
373
+ def _update(ss):
374
+ if self.__i >= len(self):
375
+ self.__i = len(self) - 1
376
+ elif self.__i < 0:
377
+ self.__i = 0
378
+
379
+ plt.title(f'{self.__i}: {self._calculated_shift[self.__i]}')
380
+ if keep is not None:
381
+ if keep == 'next':
382
+ if self.__i+1 < len(self):
383
+ ss[self.__i+1].plot(shift=self._calculated_shift[self.__i+1], color='red', alpha=0.5)
384
+ elif keep == 'previous':
385
+ if self.__i-1 >= 0:
386
+ ss[self.__i-1].plot(shift=self._calculated_shift[self.__i-1], color='red', alpha=0.5)
387
+ else:
388
+ ss[keep].plot(shift=self._calculated_shift[keep], color='red', alpha=0.5)
389
+ ss[self.__i].plot(shift=self._calculated_shift[self.__i], **kwargs)
390
+
391
+ if vlines is not None:
392
+ br.axvlines(vlines, colors='red', ls='--', lw=1)
393
+
394
+ if self.__xlim is not None:
395
+ plt.xlim(self.__xlim)
396
+ if self.__ylim is not None:
397
+ plt.ylim(self.__ylim)
398
+ else:
399
+ # add counter and xlim/ylim to update function
400
+ def _update(ss):
401
+ if self.__i >= len(self):
402
+ self.__i = len(self) - 1
403
+ elif self.__i < 0:
404
+ self.__i = 0
405
+
406
+ update_function(ss, __i=self.__i)
407
+
408
+ if vlines is not None:
409
+ br.axvlines(vlines, colors='red', ls='--', lw=1)
410
+
411
+ if xlim is not None:
412
+ plt.xlim(xlim)
413
+ if ylim is not None:
414
+ plt.ylim(ylim)
415
+
416
+ # keyboard events
417
+ def keyboard(event, ss):
418
+ # print(event.key)
419
+ # print('keyboard')
420
+ # print(event.key)
421
+ if event.key == 'up':
422
+ self.__i = self.__i + 1
423
+
424
+ self.__ax.callbacks.disconnect(2)
425
+ self.__ax.callbacks.disconnect(3)
426
+ self.__newx = False
427
+ self.__newy = False
428
+
429
+ plt.cla()
430
+ _update(ss)
431
+ plt.draw()
432
+
433
+ self.__ax.callbacks.connect('xlim_changed', on_xlims_change)
434
+ self.__ax.callbacks.connect('ylim_changed', on_ylims_change)
435
+ elif event.key == 'down':
436
+ self.__i = self.__i - 1
437
+
438
+ self.__ax.callbacks.disconnect(2)
439
+ self.__ax.callbacks.disconnect(3)
440
+ self.__newx = False
441
+ self.__newy = False
442
+
443
+ plt.cla()
444
+ _update(ss)
445
+ plt.draw()
446
+
447
+ self.__ax.callbacks.connect('xlim_changed', on_xlims_change)
448
+ self.__ax.callbacks.connect('ylim_changed', on_ylims_change)
449
+ elif event.key == 'right':
450
+ self._calculated_shift[self.__i] += self.__step
451
+
452
+ plt.cla()
453
+ _update(ss)
454
+ plt.draw()
455
+ elif event.key == 'left':
456
+ self._calculated_shift[self.__i] -= self.__step
457
+
458
+ plt.cla()
459
+ _update(ss)
460
+ plt.draw()
461
+
462
+ # mouse events
463
+ def mouse(event):
464
+ """Mouse can be used with a keyboard key"""
465
+ # print('mouse')
466
+ # print(event.key)
467
+ # print(event.button)
468
+ pass
469
+
470
+ # axis zoom changes
471
+ def on_xlims_change(event_ax):
472
+ if self.__newx:
473
+ # print("updated xlims: ", event_ax.get_xlim())
474
+ self.__xlim = event_ax.get_xlim()
475
+ self.__newx = True
476
+
477
+ def on_ylims_change(event_ax):
478
+ if self.__newy:
479
+ # print("updated ylims: ", event_ax.get_ylim())
480
+ self.__ylim = event_ax.get_ylim()
481
+ self.__newy = True
482
+
483
+ # plotting
484
+ fig, self.__ax = plt.subplots(1, 1)
485
+
486
+ # register callbacks
487
+ fig.canvas.mpl_connect('key_press_event', lambda event: keyboard(event, ss=self))
488
+ fig.canvas.mpl_connect('button_press_event', lambda event: mouse(event))
489
+
490
+ _update(self)
491
+ return
492
+ br.Spectra.shift_plot = shift_plot
493
+
494
+ def shift_plot2(self, xlim=None, ylim=None, step=None, vlines=None, keep=None, update_function=None, **kwargs):
495
+ """[EXPERIMENTAL] flip through spectra (up/down keys), shift spectrum (left/right keys)
496
+
497
+ Warning:
498
+ Old version, zoom is reset every time. Only one plot can be open at a time.
499
+ Also, some default matplotlib keybidings are changed (should not be a problem)
500
+
501
+ Args:
502
+ xlim (tuple, optional): min and max ``x`` value. Default is None (full
503
+ data range).
504
+ ylim (tuple, optional): min and max ``y`` value. Default is None.
505
+ step (number, optional): step. If None, 1% of the min datapoint
506
+ separation is used.
507
+ vlines (list or number, optional): vertical dashed lines for
508
+ reference, default is None.
509
+ keep (int, optional): index of the spectrum to keep on screen.
510
+ update_function (function, optional): function that is called when
511
+ the left or right arrows are pressed. update_function must be a
512
+ function of type:
513
+
514
+ >>> def update_function(ss, __i):
515
+ >>> plt.title(__i)
516
+ >>> ss[__i].plot(color='black', marker='o')
517
+
518
+ where ``__i`` is updated in every iteraction.
519
+ **kwargs: kwargs are passed to ``plt.plot()`` that plots the data.
520
+
521
+ Returns:
522
+ None
523
+ """
524
+ # vars
525
+ self.__i = 0
526
+ self._calculated_shift = np.array([0.0]*len(self))
527
+
528
+ # set step
529
+ if step is None:
530
+ if self.step is None:
531
+ try:
532
+ self.check_step()
533
+ self.__step = self.step*0.5
534
+ except:
535
+ self.__step = min([np.mean(np.diff(s.x)) for s in self])*0.5
536
+ else:
537
+ self.__step = self.step*0.5
538
+ else:
539
+ self.__step = step
540
+
541
+ # change keybindings
542
+ try:
543
+ matplotlib.rcParams['keymap.back'].remove('left')
544
+ matplotlib.rcParams['keymap.forward'].remove('right')
545
+ except ValueError:
546
+ pass
547
+
548
+ # keep
549
+ if keep is not None:
550
+ if isinstance(keep, str):
551
+ assert keep == 'previous' or keep == 'next', 'keep must be a valid spectrum index, or "previous/next"'
552
+ else:
553
+ assert abs(keep) < len(self), 'keep must be a valid spectrum index, or "previous/next"'
554
+
555
+ # kwargs
556
+ if 'color' not in kwargs:
557
+ kwargs['color'] = 'black'
558
+ if 'marker' not in kwargs:
559
+ kwargs['marker'] = 'o'
560
+
561
+ # core update function
562
+ if update_function is None:
563
+ def _update(ss):
564
+ if self.__i >= len(self):
565
+ self.__i = len(self) - 1
566
+ elif self.__i < 0:
567
+ self.__i = 0
568
+
569
+ plt.title(f'{self.__i}: {self._calculated_shift[self.__i]}')
570
+ if keep is not None:
571
+ if keep == 'next':
572
+ if self.__i+1 < len(self):
573
+ ss[self.__i+1].plot(shift=self._calculated_shift[self.__i+1], color='red', alpha=0.5)
574
+ elif keep == 'previous':
575
+ if self.__i-1 >= 0:
576
+ ss[self.__i-1].plot(shift=self._calculated_shift[self.__i-1], color='red', alpha=0.5)
577
+ else:
578
+ ss[keep].plot(shift=self._calculated_shift[keep], color='red', alpha=0.5)
579
+ ss[self.__i].plot(shift=self._calculated_shift[self.__i], **kwargs)
580
+
581
+ if vlines is not None:
582
+ br.axvlines(vlines, colors='red', ls='--', lw=1)
583
+
584
+ if xlim is not None:
585
+ plt.xlim(xlim)
586
+ if ylim is not None:
587
+ plt.ylim(ylim)
588
+ else:
589
+ # add counter and xlim/ylim to update function
590
+ def _update(ss):
591
+ if self.__i >= len(self):
592
+ self.__i = len(self) - 1
593
+ elif self.__i < 0:
594
+ self.__i = 0
595
+
596
+ update_function(ss, __i=self.__i)
597
+
598
+ if vlines is not None:
599
+ br.axvlines(vlines, colors='red', ls='--', lw=1)
600
+
601
+ if xlim is not None:
602
+ plt.xlim(xlim)
603
+ if ylim is not None:
604
+ plt.ylim(ylim)
605
+
606
+ # keyboard events
607
+ def keyboard(event, ss):
608
+ # print(event.key)
609
+ # print('keyboard')
610
+ # print(event.key)
611
+ if event.key == 'up':
612
+ self.__i = self.__i + 1
613
+
614
+ plt.cla()
615
+ _update(ss)
616
+ plt.draw()
617
+ elif event.key == 'down':
618
+ self.__i = self.__i - 1
619
+
620
+ plt.cla()
621
+ _update(ss)
622
+ plt.draw()
623
+ elif event.key == 'right':
624
+ self._calculated_shift[self.__i] += self.__step
625
+
626
+ plt.cla()
627
+ _update(ss)
628
+ plt.draw()
629
+ elif event.key == 'left':
630
+ self._calculated_shift[self.__i] -= self.__step
631
+
632
+ plt.cla()
633
+ _update(ss)
634
+ plt.draw()
635
+
636
+ # mouse events
637
+ def mouse(event):
638
+ """Mouse can be used with a keyboard key"""
639
+ # print('mouse')
640
+ # print(event.key)
641
+ # print(event.button)
642
+ pass
643
+
644
+ # plotting
645
+ fig = br.figure()
646
+ fig.canvas.mpl_connect('key_press_event', lambda event: keyboard(event, ss=self))
647
+ fig.canvas.mpl_connect('button_press_event', lambda event: mouse(event))
648
+ _update(self)
649
+ return
650
+ # br.Spectra.shift_plot2 = shift_plot2
651
+
652
+ def roll_plot(self, xlim=None, ylim=None, vlines=None, keep=None, update_function=None, **kwargs):
653
+ """[EXPERIMENTAL] flip through spectra (up/down keys), roll spectrum (a/d keys).
654
+
655
+ Warning:
656
+ Only one plot can be open at a time. Also, some default
657
+ matplotlib keybidings are changed (should not be a problem)
658
+
659
+ Args:
660
+ xlim (tuple, optional): min and max ``x`` value. Default is None (full
661
+ data range).
662
+ ylim (tuple, optional): min and max ``y`` value. Default is None.
663
+ vlines (list or number, optional): vertical dashed lines for
664
+ reference, default is None.
665
+ keep (int or str, optional): index of the spectrum to keep on screen.
666
+ Use 'previous' or 'next' to show previous or next spectrum.
667
+ update_function (function, optional): function that is called when
668
+ the left or right arrows are pressed. update_function must be a
669
+ function of type:
670
+
671
+ >>> def update_function(ss, __i):
672
+ >>> plt.title(__i)
673
+ >>> ss[__i].plot(color='black', marker='o')
674
+
675
+ where ``__i`` is updated in every iteraction. If update_function
676
+ is given, `keep` is disregarded.
677
+ **kwargs: kwargs are passed to ``plt.plot()`` that plots the data.
678
+
679
+ Returns:
680
+ None
681
+ """
682
+ # check step
683
+ if self.check_step is None:
684
+ try:
685
+ self.check_step()
686
+ except ValueError:
687
+ raise ValueError('cannot apply roll because step is not the same. Use shift_plot().')
688
+
689
+ # vars
690
+ self.__i = 0
691
+ self.__xlim = xlim
692
+ self.__ylim = ylim
693
+ self.__ax = None
694
+ self._calculated_roll = np.array([0]*len(self))
695
+
696
+ # change keybindings
697
+ try:
698
+ matplotlib.rcParams['keymap.back'].remove('left')
699
+ matplotlib.rcParams['keymap.forward'].remove('right')
700
+ except ValueError:
701
+ pass
702
+
703
+ # lims
704
+ if self.__xlim is None:
705
+ self.__xlim = [min(self[0].x), max(self[0].x)]
706
+ for s in self:
707
+ if min(s.x) < self.__xlim[0]:
708
+ self.__xlim[0] = min(s.x)
709
+ if max(s.x) > self.__xlim[1]:
710
+ self.__xlim[1] = max(s.x)
711
+ if self.__ylim is None:
712
+ self.__ylim = [min(self[0].y), max(self[0].y)]
713
+ for s in self:
714
+ if min(s.y) < self.__ylim[0]:
715
+ self.__ylim[0] = min(s.y)
716
+ if max(s.y) > self.__ylim[1]:
717
+ self.__ylim[1] = max(s.y)
718
+
719
+ # check if all data has well defined step
720
+ for i, s in enumerate(self):
721
+ try:
722
+ s.check_step()
723
+ except ValueError:
724
+ raise ValueError(f'Spectrum number {i} has non-uniform x-coord.\nRoll can only be applied with uniform x-coord.\nMaybe used ss.interp() to fix that.')
725
+
726
+ # keep
727
+ if keep is not None:
728
+ if isinstance(keep, str):
729
+ assert keep == 'previous' or keep == 'next', 'keep must be a valid spectrum index, or "previous/next"'
730
+ else:
731
+ assert abs(keep) < len(self), 'keep must be a valid spectrum index, or "previous/next"'
732
+
733
+ # kwargs
734
+ if 'color' not in kwargs:
735
+ kwargs['color'] = 'black'
736
+ if 'marker' not in kwargs:
737
+ kwargs['marker'] = 'o'
738
+
739
+ # core update function
740
+ if update_function is None:
741
+ def _update(ss):
742
+ if self.__i >= len(self):
743
+ self.__i = len(self) - 1
744
+ elif self.__i < 0:
745
+ self.__i = 0
746
+
747
+ plt.title(f'{self.__i}: {self._calculated_roll[self.__i]}')
748
+ if keep is not None:
749
+ if keep == 'next':
750
+ if self.__i+1 < len(self):
751
+ ss[self.__i+1].plot(shift=self._calculated_roll[self.__i+1]*ss[self.__i+1].step, color='red', alpha=0.5)
752
+ elif keep == 'previous':
753
+ if self.__i-1 >= 0:
754
+ ss[self.__i-1].plot(shift=self._calculated_roll[self.__i-1]*ss[self.__i-1].step, color='red', alpha=0.5)
755
+ else:
756
+ ss[keep].plot(shift=self._calculated_roll[keep]*ss[keep].step, color='red', alpha=0.5)
757
+ ss[self.__i].plot(shift=self._calculated_roll[self.__i]*ss[self.__i].step, **kwargs)
758
+
759
+ if vlines is not None:
760
+ br.axlines(vlines, colors='red', ls='--', lw=1)
761
+
762
+ if self.__xlim is not None:
763
+ plt.xlim(self.__xlim)
764
+ if self.__ylim is not None:
765
+ plt.ylim(self.__ylim)
766
+ else:
767
+ # add counter and xlim/ylim to update function
768
+ def _update(ss):
769
+ if self.__i >= len(self):
770
+ self.__i = len(self) - 1
771
+ elif self.__i < 0:
772
+ self.__i = 0
773
+
774
+ update_function(ss, __i=self.__i)
775
+
776
+ if vlines is not None:
777
+ br.axvlines(vlines, colors='red', ls='--', lw=1)
778
+
779
+ if self.__xlim is not None:
780
+ plt.xlim(self.__xlim)
781
+ if self.__ylim is not None:
782
+ plt.ylim(self.__ylim)
783
+
784
+ # keyboard events
785
+ def keyboard(event, ss):
786
+ # print(event.key)
787
+ # print('keyboard')
788
+ # print(event.key)
789
+ if event.key == 'up':
790
+ self.__i = self.__i + 1
791
+
792
+ # self.__ax.cla()
793
+ self.__ax.lines.clear()
794
+ _update(ss)
795
+ plt.draw()
796
+ elif event.key == 'down':
797
+ self.__i = self.__i - 1
798
+
799
+ # self.__ax.cla()
800
+ self.__ax.lines.clear()
801
+ _update(ss)
802
+ plt.draw()
803
+ elif event.key == 'right':
804
+ self._calculated_roll[self.__i] += 1
805
+
806
+ # self.__ax.cla()
807
+ self.__ax.lines.clear()
808
+ _update(ss)
809
+ plt.draw()
810
+ elif event.key == 'left':
811
+ self._calculated_roll[self.__i] -= 1
812
+
813
+ # self.__ax.cla()
814
+ self.__ax.lines.clear()
815
+ _update(ss)
816
+ plt.draw()
817
+
818
+ # axis zoom changes
819
+ def on_xlims_change(event_ax):
820
+ # print("updated xlims: ", event_ax.get_xlim())
821
+ self.__xlim = event_ax.get_xlim()
822
+
823
+ def on_ylims_change(event_ax):
824
+ # print("updated ylims: ", event_ax.get_ylim())
825
+ self.__ylim = event_ax.get_ylim()
826
+
827
+ # plotting
828
+ fig, self.__ax = plt.subplots(1, 1)
829
+ _update(self)
830
+
831
+ # register callbacks
832
+ fig.canvas.mpl_connect('key_press_event', lambda event: keyboard(event, ss=self))
833
+ # fig.canvas.mpl_connect('button_press_event', lambda event: mouse(event))
834
+ self.__ax.callbacks.connect('xlim_changed', on_xlims_change)
835
+ self.__ax.callbacks.connect('ylim_changed', on_ylims_change)
836
+
837
+ # _update(self)
838
+ return
839
+ br.Spectra.roll_plot = roll_plot
840
+
841
+ def roll_plot2(self, xlim=None, ylim=None, vlines=None, keep=None, update_function=None, **kwargs):
842
+ """[EXPERIMENTAL] flip through spectra (up/down keys), roll spectrum (left/right keys)
843
+
844
+ Warning:
845
+ Old version, zoom is reset every time. Only one plot can be open at a time.
846
+ Also, some default matplotlib keybidings are changed (should not be a problem)
847
+
848
+ Args:
849
+ xlim (tuple, optional): min and max ``x`` value. Default is None (full
850
+ data range).
851
+ ylim (tuple, optional): min and max ``y`` value. Default is None.
852
+ vlines (list or number, optional): vertical dashed lines for
853
+ reference, default is None.
854
+ keep (int, optional): index of the spectrum to keep on screen.
855
+ update_function (function, optional): function that is called when
856
+ the left or right arrows are pressed. update_function must be a
857
+ function of type:
858
+
859
+ >>> def update_function(ss, __i):
860
+ >>> plt.title(__i)
861
+ >>> ss[__i].plot(color='black', marker='o')
862
+
863
+ where ``__i`` is updated in every iteraction.
864
+ **kwargs: kwargs are passed to ``plt.plot()`` that plots the data.
865
+
866
+ Returns:
867
+ None
868
+ """
869
+ # check step
870
+ if self.check_step is None:
871
+ try:
872
+ self.check_step()
873
+ except ValueError:
874
+ raise ValueError('cannot apply roll because step is not the same. Use shift_plot().')
875
+
876
+ # vars
877
+ self.__i = 0
878
+ self._calculated_roll = np.array([0]*len(self))
879
+
880
+ # change keybindings
881
+ try:
882
+ matplotlib.rcParams['keymap.back'].remove('left')
883
+ matplotlib.rcParams['keymap.forward'].remove('right')
884
+ except ValueError:
885
+ pass
886
+
887
+ # check if all data has well defined step
888
+ for i, s in enumerate(self):
889
+ try:
890
+ s.check_step()
891
+ except ValueError:
892
+ raise ValueError(f'Spectrum number {i} has non-uniform x-coord.\nRoll can only be applied with uniform x-coord.\nMaybe used ss.interp() to fix that.')
893
+
894
+ # keep
895
+ if keep is not None:
896
+ if isinstance(keep, str):
897
+ assert keep == 'previous' or keep == 'next', 'keep must be a valid spectrum index, or "previous/next"'
898
+ else:
899
+ assert abs(keep) < len(self), 'keep must be a valid spectrum index, or "previous/next"'
900
+
901
+ # kwargs
902
+ if 'color' not in kwargs:
903
+ kwargs['color'] = 'black'
904
+ if 'marker' not in kwargs:
905
+ kwargs['marker'] = 'o'
906
+
907
+ # core update function
908
+ if update_function is None:
909
+ def _update(ss):
910
+ if self.__i >= len(self):
911
+ self.__i = len(self) - 1
912
+ elif self.__i < 0:
913
+ self.__i = 0
914
+
915
+ plt.title(f'{self.__i}: {self._calculated_roll[self.__i]}')
916
+ if keep is not None:
917
+ if keep == 'next':
918
+ if self.__i+1 < len(self):
919
+ ss[self.__i+1].plot(shift=self._calculated_roll[self.__i+1]*ss[self.__i+1].step, color='red', alpha=0.5)
920
+ elif keep == 'previous':
921
+ if self.__i-1 >= 0:
922
+ ss[self.__i-1].plot(shift=self._calculated_roll[self.__i-1]*ss[self.__i-1].step, color='red', alpha=0.5)
923
+ else:
924
+ ss[keep].plot(shift=self._calculated_roll[keep]*ss[keep].step, color='red', alpha=0.5)
925
+ ss[self.__i].plot(shift=self._calculated_roll[self.__i]*ss[self.__i].step, **kwargs)
926
+
927
+ if vlines is not None:
928
+ br.axvlines(vlines, colors='red', ls='--', lw=1)
929
+
930
+ if xlim is not None:
931
+ plt.xlim(xlim)
932
+ if ylim is not None:
933
+ plt.ylim(ylim)
934
+ else:
935
+ # add counter and xlim/ylim to update function
936
+ def _update(ss):
937
+ if self.__i >= len(self):
938
+ self.__i = len(self) - 1
939
+ elif self.__i < 0:
940
+ self.__i = 0
941
+
942
+ update_function(ss, __i=self.__i)
943
+
944
+ if vlines is not None:
945
+ br.axvlines(vlines, colors='red', ls='--', lw=1)
946
+
947
+ if xlim is not None:
948
+ plt.xlim(xlim)
949
+ if ylim is not None:
950
+ plt.ylim(ylim)
951
+
952
+ # keyboard events
953
+ def keyboard(event, ss):
954
+ # print(event.key)
955
+ # print('keyboard')
956
+ # print(event.key)
957
+ if event.key == 'up':
958
+ self.__i = self.__i + 1
959
+
960
+ plt.cla()
961
+ _update(ss)
962
+ plt.draw()
963
+ elif event.key == 'down':
964
+ self.__i = self.__i - 1
965
+
966
+ plt.cla()
967
+ _update(ss)
968
+ plt.draw()
969
+ elif event.key == 'right':
970
+ self._calculated_roll[self.__i] += 1
971
+
972
+ plt.cla()
973
+ _update(ss)
974
+ plt.draw()
975
+ elif event.key == 'left':
976
+ self._calculated_roll[self.__i] -= 1
977
+
978
+ plt.cla()
979
+ _update(ss)
980
+ plt.draw()
981
+
982
+
983
+ # plotting
984
+ fig = br.figure()
985
+ fig.canvas.mpl_connect('key_press_event', lambda event: keyboard(event, ss=self))
986
+
987
+ _update(self)
988
+ return
989
+ # br.Spectra.roll_plot2 = roll_plot2
990
+
991
+ def roll_plot3(self, xlim=None, ylim=None, vlines=None, keep=None, update_function=None, **kwargs):
992
+ """[experimental] flip through spectra (up/down keys), roll spectrum (left/right keys).
993
+
994
+ Warning:
995
+ [Experimental] Use mouse to click and drag spectra to the left or right.
996
+ Only one plot can be open at a time. Also, some default matplotlib
997
+ keybidings are changed (should not be a problem)
998
+
999
+ Args:
1000
+ xlim (tuple, optional): min and max ``x`` value. Default is None (full
1001
+ data range).
1002
+ ylim (tuple, optional): min and max ``y`` value. Default is None.
1003
+ vlines (list or number, optional): vertical dashed lines for
1004
+ reference, default is None.
1005
+ keep (int, optional): index of the spectrum to keep on screen.
1006
+ update_function (function, optional): function that is called when
1007
+ the left or right arrows are pressed. update_function must be a
1008
+ function of type:
1009
+
1010
+ >>> def update_function(ss, __i):
1011
+ >>> plt.title(__i)
1012
+ >>> ss[__i].plot(color='black', marker='o')
1013
+
1014
+ where ``__i`` is updated in every iteraction.
1015
+ **kwargs: kwargs are passed to ``plt.plot()`` that plots the data.
1016
+
1017
+ Returns:
1018
+ None
1019
+ """
1020
+ # check step
1021
+ if self.step is None:
1022
+ try:
1023
+ self.check_step()
1024
+ except ValueError:
1025
+ raise ValueError('cannot apply roll because step is not the same. Use shift_plot().')
1026
+
1027
+ # raise NotImplementedError('This is not implemented yet.')
1028
+ self.__i = 0
1029
+ self._calculated_roll = np.array([0]*len(self))
1030
+ self._mouse_press = 0
1031
+
1032
+ # change keybindings
1033
+ try:
1034
+ matplotlib.rcParams['keymap.back'].remove('left')
1035
+ matplotlib.rcParams['keymap.forward'].remove('right')
1036
+ except ValueError:
1037
+ pass
1038
+
1039
+ # check if all data has well defined step
1040
+ for i, s in enumerate(self):
1041
+ try:
1042
+ s.check_step()
1043
+ except ValueError:
1044
+ raise ValueError(f'Spectrum number {i} has non-uniform x-coord.\nRoll can only be applied with uniform x-coord.\nMaybe used ss.interp() to fix that.')
1045
+
1046
+ # keep
1047
+ if keep is not None:
1048
+ if isinstance(keep, str):
1049
+ assert keep == 'previous' or keep == 'next', 'keep must be a valid spectrum index, or "previous/next"'
1050
+ else:
1051
+ assert abs(keep) < len(self), 'keep must be a valid spectrum index, or "previous/next"'
1052
+
1053
+ # kwargs
1054
+ if 'color' not in kwargs:
1055
+ kwargs['color'] = 'black'
1056
+ if 'marker' not in kwargs:
1057
+ kwargs['marker'] = 'o'
1058
+
1059
+ # core update function
1060
+ if update_function is None:
1061
+ def _update(ss):
1062
+ if self.__i >= len(self):
1063
+ self.__i = len(self) - 1
1064
+ elif self.__i < 0:
1065
+ self.__i = 0
1066
+
1067
+ plt.title(f'{self.__i}: {self._calculated_roll[self.__i]}')
1068
+ if keep is not None:
1069
+ if keep == 'next':
1070
+ if self.__i+1 < len(self):
1071
+ ss[self.__i+1].plot(shift=self._calculated_roll[self.__i+1]*ss[self.__i+1].step, color='red', alpha=0.5)
1072
+ elif keep == 'previous':
1073
+ if self.__i-1 >= 0:
1074
+ ss[self.__i-1].plot(shift=self._calculated_roll[self.__i-1]*ss[self.__i-1].step, color='red', alpha=0.5)
1075
+ else:
1076
+ ss[keep].plot(shift=self._calculated_roll[keep]*ss[keep].step, color='red', alpha=0.5)
1077
+ ss[self.__i].plot(shift=self._calculated_roll[self.__i]*ss[self.__i].step, **kwargs)
1078
+
1079
+ if vlines is not None:
1080
+ br.axvlines(vlines, colors='red', ls='--', lw=1)
1081
+
1082
+ if xlim is not None:
1083
+ plt.xlim(xlim)
1084
+ if ylim is not None:
1085
+ plt.ylim(ylim)
1086
+ else:
1087
+ # add counter and xlim/ylim to update function
1088
+ def _update(ss):
1089
+ if self.__i >= len(self):
1090
+ self.__i = len(self) - 1
1091
+ elif self.__i < 0:
1092
+ self.__i = 0
1093
+
1094
+ update_function(ss, __i=self.__i)
1095
+
1096
+ if vlines is not None:
1097
+ br.axvlines(vlines, colors='red', ls='--', lw=1)
1098
+
1099
+ if xlim is not None:
1100
+ plt.xlim(xlim)
1101
+ if ylim is not None:
1102
+ plt.ylim(ylim)
1103
+
1104
+ # keyboard events
1105
+ def keyboard(event, ss):
1106
+ # print(event.key)
1107
+ # print('keyboard')
1108
+ # print(event.key)
1109
+ if event.key == 'up':
1110
+ self.__i = self.__i + 1
1111
+
1112
+ plt.cla()
1113
+ _update(ss)
1114
+ plt.draw()
1115
+ elif event.key == 'down':
1116
+ self.__i = self.__i - 1
1117
+
1118
+ plt.cla()
1119
+ _update(ss)
1120
+ plt.draw()
1121
+ elif event.key == 'right':
1122
+ self._calculated_roll[self.__i] += 1
1123
+
1124
+ plt.cla()
1125
+ _update(ss)
1126
+ plt.draw()
1127
+ elif event.key == 'left':
1128
+ self._calculated_roll[self.__i] -= 1
1129
+
1130
+ plt.cla()
1131
+ _update(ss)
1132
+ plt.draw()
1133
+
1134
+ # mouse events
1135
+ def mouse_press(event):
1136
+ """Mouse can be used with a keyboard key"""
1137
+ if event.button is not None:
1138
+ if event.button == 1:
1139
+ self._mouse_press = event.xdata
1140
+
1141
+ def mouse_release(event, ss):
1142
+ """Mouse can be used with a keyboard key"""
1143
+ if event.button is not None:
1144
+ if event.button == 1:
1145
+ self._calculated_roll[self.__i] += int(round((event.xdata - self._mouse_press)/self.step))
1146
+ plt.cla()
1147
+ _update(ss)
1148
+ plt.draw()
1149
+
1150
+ # plotting
1151
+ fig = br.figure()
1152
+ fig.canvas.mpl_connect('key_press_event', lambda event: keyboard(event, ss=self))
1153
+ fig.canvas.mpl_connect('button_press_event', lambda event: mouse_press(event))
1154
+ fig.canvas.mpl_connect('button_release_event', lambda event: mouse_release(event, ss=self))
1155
+
1156
+ _update(self)
1157
+ return
1158
+ # br.Spectra.roll_plot3 = roll_plot3
1159
+
1160
+ # %% IMAGE
1161
+ def linecuts(self, axis=0, xlim=None, ylim=None, ilim=None, keep=None, **kwargs):
1162
+ """[EXPERIMENTAL] Plot image and flip trhough linecuts with keyboard arrows.
1163
+
1164
+ Args:
1165
+ axis (int or string, optional): Axis along linecuts.
1166
+ By default, linecuts are in the vertical (0) direction.
1167
+ xlim, ylim, ilim (tuple, optional): Image ploting limits.
1168
+ keep (int or str, optional): index of the spectrum to keep on screen.
1169
+ Use 'previous' or 'next' to show previous or next spectrum.
1170
+ **kwargs: kwargs are passed to ``plt.plot()`` that plots the data.
1171
+
1172
+ Returns:
1173
+ None
1174
+ """
1175
+ # axis
1176
+ if axis == 0:
1177
+ ss = self.columns
1178
+ elif axis == 1:
1179
+ raise NotImplementedError('Not implemented yet for axis = 1')
1180
+ # ss = self.rows
1181
+ else:
1182
+ raise ValueError('axis must be 0 or 1')
1183
+
1184
+ # change keybindings
1185
+ try:
1186
+ matplotlib.rcParams['keymap.back'].remove('left')
1187
+ matplotlib.rcParams['keymap.forward'].remove('right')
1188
+ except ValueError:
1189
+ pass
1190
+
1191
+ # vars
1192
+ self.__i = 0
1193
+ self.__axes = None
1194
+ self.__xlim = xlim
1195
+ self.__ylim = ylim
1196
+ self.__ilim = ilim
1197
+
1198
+ # lims
1199
+ if self.__xlim is None:
1200
+ self.__xlim = [min(self._x_centers), max(self._x_centers)]
1201
+ if self.__ylim is None:
1202
+ self.__ylim = [min(self._y_centers), max(self._y_centers)]
1203
+ if self.__ilim is None:
1204
+ self.__ilim = [min([min(l) for l in self.data]), max([max(l) for l in self.data])]
1205
+
1206
+ # keep
1207
+ if keep is not None:
1208
+ if isinstance(keep, str):
1209
+ assert keep == 'previous' or keep == 'next', 'keep must be a valid spectrum index, or "previous/next"'
1210
+ else:
1211
+ assert abs(keep) < len(ss), 'keep must be a valid spectrum index, or "previous/next"'
1212
+
1213
+ # kwargs
1214
+ if 'color' not in kwargs:
1215
+ kwargs['color'] = 'black'
1216
+ if 'marker' not in kwargs:
1217
+ kwargs['marker'] = 'o'
1218
+
1219
+ # update function
1220
+ def update(ss):
1221
+ # plot spectrum
1222
+ ax = self.__axes[0]
1223
+ if axis == 0:
1224
+ ax.set_title(f'{self.__i}: {self.x_centers[self.__i]} eV')
1225
+ if keep is not None:
1226
+ if keep == 'next':
1227
+ if self.__i+1 < len(self):
1228
+ ss[self.__i+1].plot(color='red', alpha=0.5)
1229
+ elif keep == 'previous':
1230
+ if self.__i-1 >= 0:
1231
+ ss[self.__i-1].plot(color='red', alpha=0.5)
1232
+ else:
1233
+ ss[keep].plot(color='red', alpha=0.5)
1234
+ ss[self.__i].plot(ax=ax, **kwargs)
1235
+
1236
+ # lim
1237
+ if self.__ylim is not None:
1238
+ ax.set_xlim(self.__ylim)
1239
+ if self.__ilim is not None:
1240
+ ax.set_ylim(self.__ilim)
1241
+
1242
+
1243
+
1244
+ # plot map (shouldn't we put this outside of the update function?)
1245
+ ax = self.__axes[1]
1246
+
1247
+ # lim
1248
+ if self.__ilim is not None:
1249
+ self.pcolormesh(ax=ax, vmin=self.__ilim[0], vmax=self.__ilim[1])
1250
+ else:
1251
+ self.pcolormesh(ax=ax)
1252
+ if self.__xlim is not None:
1253
+ if axis == 0:
1254
+ ax.set_xlim(self.__xlim)
1255
+ else:
1256
+ pass
1257
+ # ax.set_xlim(self.__ylim)
1258
+ if self.__ylim is not None:
1259
+ if axis == 0:
1260
+ ax.set_ylim(self.__ylim)
1261
+ else:
1262
+ pass
1263
+ # ax.set_ylim(self.__ylim)
1264
+
1265
+ # vline
1266
+ if axis == 0:
1267
+ if keep is not None:
1268
+ if keep == 'next':
1269
+ if self.__i+1 < len(self):
1270
+ ax.plot([self.x_centers[self.__i+1], self.x_centers[self.__i+1]], [self.__ylim[0], self.__ylim[1]], color='red', alpha=0.5)
1271
+ elif keep == 'previous':
1272
+ if self.__i-1 >= 0:
1273
+ ax.plot([self.x_centers[self.__i-1], self.x_centers[self.__i-1]], [self.__ylim[0], self.__ylim[1]], color='red', alpha=0.5)
1274
+ else:
1275
+ ax.plot([self.x_centers[keep], self.x_centers[keep]], [self.__ylim[0], self.__ylim[1]], color='red', alpha=0.5)
1276
+ ax.plot([self.x_centers[self.__i], self.x_centers[self.__i]], [self.__ylim[0], self.__ylim[1]], color='white')
1277
+ # E = self.x_centers[self.__i]
1278
+ # br.axvlines(E, ax=ax, color='red', lw=1)
1279
+ else:
1280
+ E = self.y_centers[self.__i]
1281
+ br.axhlines(E, ax=ax, colors='red', lw=1)
1282
+
1283
+
1284
+
1285
+ def _update(ss):
1286
+ if self.__i >= len(ss):
1287
+ self.__i = len(ss) - 1
1288
+ elif self.__i < 0:
1289
+ self.__i = 0
1290
+
1291
+ update(ss)
1292
+
1293
+ # keyboard events
1294
+ def keyboard(event, ss):
1295
+ # print(event.key)
1296
+ # print('keyboard')
1297
+ # print(event.key)
1298
+ if event.key == 'right' or event.key == 'up':
1299
+ self.__i = self.__i + 1
1300
+
1301
+ for ax in self.__axes:
1302
+ # ax.cla()
1303
+ ax.lines.clear()
1304
+ _update(ss)
1305
+ plt.draw()
1306
+ elif event.key == 'left' or event.key == 'down':
1307
+ self.__i = self.__i - 1
1308
+
1309
+ for ax in self.__axes:
1310
+ # ax.cla()
1311
+ ax.lines.clear()
1312
+ _update(ss)
1313
+ plt.draw()
1314
+
1315
+ # axis zoom changes
1316
+ def on_1_xlims_change(event_ax):
1317
+ # print("updated xlims: ", event_ax.get_xlim())
1318
+ self.__xlim = event_ax.get_xlim()
1319
+
1320
+ def on_1_ylims_change(event_ax):
1321
+ # print("updated ylims: ", event_ax.get_ylim())
1322
+ self.__ylim = event_ax.get_ylim()
1323
+
1324
+ def on_0_xlims_change(event_ax):
1325
+ # print("updated xlims: ", event_ax.get_xlim())
1326
+ self.__ylim = event_ax.get_xlim()
1327
+
1328
+ def on_0_ylims_change(event_ax):
1329
+ # print("updated ylims: ", event_ax.get_ylim())
1330
+ self.__ilim = event_ax.get_ylim()
1331
+
1332
+ # figure
1333
+ fig, self.__axes = br.subplots(nrows=2, ncols=1)
1334
+ fig.canvas.mpl_connect('key_press_event', lambda event: keyboard(event, ss=ss))
1335
+ _update(ss)
1336
+
1337
+ self.__axes[0].callbacks.connect('xlim_changed', on_0_xlims_change)
1338
+ self.__axes[0].callbacks.connect('ylim_changed', on_0_ylims_change)
1339
+ self.__axes[1].callbacks.connect('xlim_changed', on_1_xlims_change)
1340
+ self.__axes[1].callbacks.connect('ylim_changed', on_1_ylims_change)
1341
+ # br.Image.linecuts = linecuts
1342
+
1343
+ def linecuts2(self, axis=0, xlim=None, ylim=None):
1344
+ """[EXPERIMENTAL] Plot image and flip trhough linecuts with keyboard arrows.
1345
+
1346
+ Warning: old version, with auto rescaling.
1347
+
1348
+ Args:
1349
+ axis (int or string, optional): Axis along linecuts.
1350
+ By default, linecuts are in the vertical (0) direction.
1351
+ xlim, ylim (tuple, optional): spectra ploting limits (not image
1352
+ ploting limits).
1353
+
1354
+ Returns:
1355
+ None
1356
+ """
1357
+ # axis
1358
+ if axis == 0:
1359
+ ss = self.columns
1360
+ elif axis == 1:
1361
+ ss = self.rows
1362
+ else:
1363
+ raise ValueError('axis must be 0 or 1')
1364
+
1365
+ # update function
1366
+ def update(ss):
1367
+ # plot
1368
+ ax = axes[0]
1369
+ ss[ss.__i].plot(ax=ax, color='black', marker='o')
1370
+
1371
+ # lim
1372
+ if xlim is not None:
1373
+ ax.set_xlim(xlim)
1374
+ if ylim is not None:
1375
+ ax.set_ylim(ylim)
1376
+ # br.label_rixs(ax=ax)
1377
+
1378
+ # plot map (shouldn't we put this outside of the update function?)
1379
+ ax = axes[1]
1380
+
1381
+ if ylim is not None:
1382
+ self.pcolormesh(ax=ax, vmin=ylim[0], vmax=ylim[1])
1383
+ else:
1384
+ self.pcolormesh(ax=ax)
1385
+ if xlim is not None:
1386
+ if axis == 0:
1387
+ ax.set_ylim(xlim)
1388
+ else:
1389
+ ax.set_xlim(xlim)
1390
+
1391
+ # vline
1392
+ if axis == 0:
1393
+ E = self.x_centers[ss.__i]
1394
+ br.axvlines(E, ax=ax, colors='red', lw=1)
1395
+ else:
1396
+ E = self.y_centers[ss.__i]
1397
+ br.axhlines(E, ax=ax, colors='red', lw=1)
1398
+
1399
+ # title
1400
+ axes[0].set_title(f'{ss.__i}: {E} eV')
1401
+
1402
+ def _update(ss):
1403
+ if ss.__i >= len(ss):
1404
+ ss.__i = len(ss) - 1
1405
+ elif ss.__i < 0:
1406
+ ss.__i = 0
1407
+
1408
+ update(ss)
1409
+
1410
+ # keyboard events
1411
+ def keyboard(event, ss):
1412
+ # print(event.key)
1413
+ # print('keyboard')
1414
+ # print(event.key)
1415
+ if event.key == 'right' or event.key == 'up':
1416
+ ss.__i = ss.__i + 1
1417
+
1418
+ for ax in axes:
1419
+ ax.cla()
1420
+ _update(ss)
1421
+ # for ax in axes:
1422
+ plt.draw()
1423
+ elif event.key == 'left' or event.key == 'down':
1424
+ ss.__i = ss.__i - 1
1425
+
1426
+ for ax in axes:
1427
+ ax.cla()
1428
+ _update(ss)
1429
+ # for ax in axes:
1430
+ plt.draw()
1431
+
1432
+ # figure
1433
+ fig, axes = br.subplots(nrows=2, ncols=1)
1434
+ fig.canvas.mpl_connect('key_press_event', lambda event: keyboard(event, ss=ss))
1435
+ _update(ss)
1436
+ # br.Image.linecuts2 = linecuts2
1437
+
1438
+ def roll_plot(self, axis=0, vlines=None, hlines=None, **kwargs):
1439
+ """[EXPERIMENTAL] Display data as an image. Wrapper for `matplotlib.pyplot.imshow()`_.
1440
+
1441
+ Warning:
1442
+ Pixels are always square. For irregular pixel row/columns, see Image.pcolormesh()
1443
+
1444
+ Args:
1445
+ axis (int or string, optional): Axis along roll.
1446
+ By default, columns are rolled down or up (0).
1447
+ vlines, hlines (list or number, optional): vertical or horizontal
1448
+ dashed lines for reference, default is None.
1449
+ **kwargs: kwargs are passed to `matplotlib.pyplot.imshow()`_.
1450
+
1451
+ If not specified, the following parameters are passed to `matplotlib.pyplot.imshow()`_:
1452
+
1453
+ Args:
1454
+ cmap: The Colormap instance. Default is 'jet'.
1455
+ aspect: The aspect ratio of the Axes. Default is 'auto'. If 'equal',
1456
+ an aspect ratio of 1 will be used (pixels will be square).
1457
+ origin: Location of the [0, 0] index. default is 'lower'.
1458
+ interpolation: The interpolation method used. Default is 'none'.
1459
+ Supported values are 'none', 'antialiased', 'nearest', 'bilinear',
1460
+ 'bicubic', 'spline16', 'spline36', 'hanning', 'hamming', 'hermite',
1461
+ 'kaiser', 'quadric', 'catrom', 'gaussian', 'bessel', 'mitchell',
1462
+ 'sinc', 'lanczos', 'blackman'.
1463
+ extent: minimun and maximum x and y values. Default will be given by
1464
+ the Image.x and Image.y attributes.
1465
+ vmin: Minimum intensity that the colormap covers. The intensity histogram is
1466
+ calculated and vmin is set on the position of the maximum.
1467
+ vmax: Maximmum intensity that the colormap covers. The intensity histogram is
1468
+ calculated and vmax is set to the value where the
1469
+ intensity drops below 0.01 % of the maximum.
1470
+ """
1471
+ # axis
1472
+ assert axis == 0 or axis == 1, 'axis must be 0 or 1'
1473
+
1474
+ # default arguments
1475
+ if 'cmap' not in kwargs:
1476
+ kwargs['cmap'] = 'jet'
1477
+ if 'aspect' not in kwargs:
1478
+ kwargs['aspect'] = 'auto'
1479
+ if 'origin' not in kwargs:
1480
+ kwargs['origin'] = 'lower'
1481
+ if 'interpolation' not in kwargs:
1482
+ kwargs['interpolation'] = 'none'
1483
+ if 'vmin' not in kwargs or 'vmax' not in kwargs:
1484
+ vmin, vmax = self._calculated_vmin_vmax()
1485
+ if 'vmin' not in kwargs:
1486
+ kwargs['vmin'] = vmin
1487
+ if 'vmax' not in kwargs:
1488
+ kwargs['vmax'] = vmax
1489
+
1490
+ # vars
1491
+ self.__i = 0
1492
+ self.__xlim = None
1493
+ self.__ylim = None
1494
+ self.__ax = None
1495
+ self.__temp = self.copy()
1496
+ if axis == 0:
1497
+ self._calculated_roll = np.array([0]*self.shape[1])
1498
+ else:
1499
+ raise NotImplementedError('axis = 1 nor implemented yet')
1500
+
1501
+ # change keybindings
1502
+ try:
1503
+ matplotlib.rcParams['keymap.back'].remove('left')
1504
+ matplotlib.rcParams['keymap.forward'].remove('right')
1505
+ except ValueError:
1506
+ pass
1507
+
1508
+ # lims
1509
+ if self.__xlim is None:
1510
+ self.__xlim = [min(self._x_centers), max(self._x_centers)]
1511
+ if self.__ylim is None:
1512
+ self.__ylim = [min(self._y_centers), max(self._y_centers)]
1513
+
1514
+ # vlines hlines warning
1515
+ if vlines is not None or hlines is not None:
1516
+ raise NotImplementedError('vlines is not implemented yet')
1517
+
1518
+ # core update function
1519
+ update_function = None
1520
+ if update_function is None:
1521
+ def _update(ss):
1522
+ if self.__i >= len(self):
1523
+ self.__i = len(self) - 1
1524
+ elif self.__i < 0:
1525
+ self.__i = 0
1526
+
1527
+ plt.title(f'{self.__i}: {self._calculated_roll[self.__i]}')
1528
+ im = self.__temp.imshow(ax=self.__ax, verbose=False)
1529
+
1530
+ if axis == 0:
1531
+ self.__ax.plot([self.x_centers[self.__i], self.x_centers[self.__i]], [self.__ylim[0], self.__ylim[1]], color='white')
1532
+ else:
1533
+ raise NotImplementedError('not implemented yet')
1534
+
1535
+ # if vlines is not None:
1536
+ # if isinstance(vlines, Iterable) == False:
1537
+ # vlines = [vlines, ]
1538
+ # for vline in vlines:
1539
+ # self.__ax.plot([vline, vline], [self.__ylim[0], self.__ylim[1]], color='red', ls='--', lw=1)
1540
+ # if hlines is not None:
1541
+ # if isinstance(hlines, Iterable) == False:
1542
+ # hlines = [hlines, ]
1543
+ # for hline in hlines:
1544
+ # self.__ax.plot([self.__xlim[0], self.__xlim[1]], [hline, hline], color='red', ls='--', lw=1)
1545
+
1546
+ if self.__xlim is not None:
1547
+ plt.xlim(self.__xlim)
1548
+ if self.__ylim is not None:
1549
+ plt.ylim(self.__ylim)
1550
+
1551
+ # keyboard events
1552
+ def keyboard(event, ss):
1553
+ # print(event.key)
1554
+ # print('keyboard')
1555
+ # print(event.key)
1556
+ if axis == 0:
1557
+ if event.key == 'up':
1558
+ self._calculated_roll[self.__i] += 1
1559
+
1560
+ if axis == 0:
1561
+ rolls = np.zeros(self.shape[1])
1562
+ rolls[self.__i] = 1
1563
+ self.__temp.set_roll(rolls)
1564
+ _update(ss)
1565
+ plt.draw()
1566
+ elif event.key == 'down':
1567
+ self._calculated_roll[self.__i] -= 1
1568
+
1569
+ if axis == 0:
1570
+ rolls = np.zeros(self.shape[1])
1571
+ rolls[self.__i] = -1
1572
+ self.__temp.set_roll(rolls)
1573
+ _update(ss)
1574
+ plt.draw()
1575
+ elif event.key == 'right':
1576
+ self.__i = self.__i + 1
1577
+
1578
+ # self.__ax.cla()
1579
+ self.__ax.lines.clear()
1580
+ _update(ss)
1581
+ plt.draw()
1582
+ elif event.key == 'left':
1583
+ self.__i = self.__i - 1
1584
+
1585
+ # self.__ax.cla()
1586
+ self.__ax.lines.clear()
1587
+ _update(ss)
1588
+ plt.draw()
1589
+
1590
+ # axis zoom changes
1591
+ def on_xlims_change(event_ax):
1592
+ # print("updated xlims: ", event_ax.get_xlim())
1593
+ self.__xlim = event_ax.get_xlim()
1594
+
1595
+ def on_ylims_change(event_ax):
1596
+ # print("updated ylims: ", event_ax.get_ylim())
1597
+ self.__ylim = event_ax.get_ylim()
1598
+
1599
+ # plotting
1600
+ fig, self.__ax = plt.subplots(1, 1)
1601
+ _update(self)
1602
+
1603
+ # register callbacks
1604
+ fig.canvas.mpl_connect('key_press_event', lambda event: keyboard(event, ss=self))
1605
+ # fig.canvas.mpl_connect('button_press_event', lambda event: mouse(event))
1606
+ self.__ax.callbacks.connect('xlim_changed', on_xlims_change)
1607
+ self.__ax.callbacks.connect('ylim_changed', on_ylims_change)
1608
+
1609
+ # _update(self)
1610
+ return
1611
+ # br.Image.roll_plot = roll_plot
1612
+
1613
+ # %% Other
1614
+ from IPython import get_ipython
1615
+ def is_notebook():
1616
+ """[EXPERIMENTAL] Return True if running from a ipython interactive terminal or jupyter notebook."""
1617
+ # assert IPythonok, 'is_notebook() cannot check for notebook\nError: python package `IPython` not found\nmaybe install it via ``pip install IPython``'
1618
+ try:
1619
+ shell = get_ipython().__class__.__name__
1620
+ if shell == 'ZMQInteractiveShell':
1621
+ return True # Jupyter notebook or qtconsole
1622
+ elif shell == 'TerminalInteractiveShell':
1623
+ return True # Terminal running IPython
1624
+ else:
1625
+ return False # Other type (?)
1626
+ except NameError:
1627
+ return False # Probably standard Python interpreter
1628
+