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
brixs/__init__.py ADDED
@@ -0,0 +1,47 @@
1
+ # settings (must be imported first)
2
+ from .config import settings
3
+
4
+ # backpack
5
+ from .backpack import *
6
+
7
+ # brixs
8
+ from .brixs import Image
9
+ from .brixs import PhotonEvents
10
+ from .brixs import Spectrum
11
+ from .brixs import Spectra
12
+ from .brixs import Dummy
13
+ from .brixs import figure
14
+ from .brixs import subplots
15
+
16
+ # reserved and forbidden words
17
+ # these words will raise an error if the user try to define attrs with these words
18
+ # this avoids errors when converting from one object to another (e.g. im -> s)
19
+ # this also avoid that import methods or variables are overwritten
20
+ # reserved words of an object: methods, vars, and pseudovars of the object
21
+ # forbidden words of an object: (all methods of a given object) + (methods, vars, and pseudovar from all other objects)
22
+ import types
23
+ for object in (Spectrum, Spectra, Image, PhotonEvents, Dummy):
24
+ name = object.__name__
25
+ _s = object()
26
+ attrs = _s.__dir__()
27
+ for attr in attrs:
28
+ if attr.startswith('_'):
29
+ pass
30
+ elif type(getattr(_s, attr)) == types.MethodType:
31
+ settings._reserved_words[name]['methods'] += [attr]
32
+ else:
33
+ settings._reserved_words[name]['pseudovars'] += [attr]
34
+ settings._reserved_words[name]['vars'] = list(_s.__dict__)
35
+ del _s, attrs, name
36
+ for name in settings._forbidden_words:
37
+ for name2 in settings._forbidden_words:
38
+ settings._forbidden_words[name] += settings._reserved_words[name2]['methods']
39
+ if name != name2:
40
+ settings._forbidden_words[name] += [pseudovar for pseudovar in settings._reserved_words[name2]['pseudovars'] if pseudovar not in settings._reserved_words[name]['pseudovars']]
41
+ settings._forbidden_words[name] += [var for var in settings._reserved_words[name2]['vars'] if var not in settings._reserved_words[name]['vars']]
42
+ settings._forbidden_words[name] = remove_duplicates(settings._forbidden_words[name])
43
+
44
+ # addons
45
+ from .addons import labels
46
+ from .addons import finder
47
+ # import .addons
File without changes
@@ -0,0 +1,417 @@
1
+ #! /usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+ """Centroid algorithm"""
4
+
5
+ # %% ------------------------- Standard Imports --------------------------- %% #
6
+ import numpy as np
7
+ # %%
8
+
9
+ # %% -------------------------- brixs Imports ----------------------------- %% #
10
+ import brixs as br
11
+ # %%
12
+
13
+ # %% -------------------------- support functions ------------------------- %% #
14
+ def calculate_threshold_via_photon_energy(photon_energy, avg_multiplication_factor=0.2, avg_multiplication_factor_double=1):
15
+ """return estimated avg_threshold from photon energy (from ESRF toolbox)
16
+
17
+ Args:
18
+ photon_energy (number): average energy of the photons hitting the detector
19
+ in eV.
20
+ avg_multiplication_factor (number, optional): analog-to-digital (ADU)
21
+ multiplication factor. Default is 0.2
22
+ avg_multiplication_factor_double (number, optional): analog-to-digital (ADU)
23
+ multiplication factor for discriminating double from single events.
24
+ Default is 1
25
+
26
+ Returns:
27
+ avg_threshold, double_threshold
28
+ """
29
+ # Multiplication factor * ADU/photon
30
+ photons = photon_energy/3.6/1.06
31
+
32
+ avg_threshold = avg_multiplication_factor * photons
33
+ double_threshold = avg_multiplication_factor_double * photons
34
+
35
+ return avg_threshold, double_threshold
36
+
37
+ def calculate_threshold_via_std(nstd, std_pixel_value, average_pixel_value=0):
38
+ """return estimated avg_threshold via standard deviation method (from XFEL toolbox)
39
+
40
+ Args:
41
+ nstd (number): number of standard deviations above the averaged pixel
42
+ value to be considered a photon hit candidate.
43
+ std_pixel_value (number): standard deviation of the pixel value.
44
+ average_pixel_value (number, optional): average pixel value. Default is
45
+ zero.
46
+
47
+ Returns:
48
+ avg_threshold, double_threshold
49
+ """
50
+ avg_threshold = average_pixel_value + nstd*std_pixel_value
51
+ double_threshold = 1.5*avg_threshold
52
+ return avg_threshold, double_threshold
53
+
54
+ def _centroid(self, n1, n2, avg_threshold, double_threshold, floor=False, avg_threshold_max=None, include_doubles=True, MAX_PHOTONS=100000):
55
+ """Returns a PhotonEvents object.
56
+
57
+ This function is adapted from the ESRF RIXS toolbox and from XFEL SCS toolbox.
58
+
59
+ Warning:
60
+ for the algorithm to work, the background average must be zero. One can accomplish that by
61
+ using the function im.floor(x_start, x_stop, y_start, y_stop), where start and stop args
62
+ can be used to select a region of the image which is only background. One can also use the
63
+ argument floor=True in this function. This will `floor` the whole image (the average of the
64
+ whole image is zero). This should be ok for most images with low number of photons.
65
+
66
+ Note:
67
+ image x_centers and y_centers must be monotonic
68
+
69
+ Args:
70
+ n1 (int): number of pixels to average to detect a photon hit candidate, e.g., a photon hit candidate
71
+ is selected if the average of the intensities within a n1-by-n1 square exceeds avg_threshold.
72
+ n2 (int): For a photon hit candidates the 'center-of-mass' of the photon hit is calculated
73
+ within a n2-by-n2 square.
74
+ avg_threshold (number): any pixel with intensity higher than avg_threshold in the n1-by-n1
75
+ averaged spot surrounding said pixel will be selected as a photon-hit-candidate position.
76
+ double_threshold (number): any a photon-hit-candidate position where the sum of the surrounding
77
+ n2-by-n2 square is higher than double_threshold is considered a double hit.
78
+ floor (bool, optional): if True, an intensity offset is added to the image such as the average
79
+ intensity of the whole image is zero. Default is False.
80
+ avg_threshold_max (number or None, optional): any pixel with intensity higher than avg_threshold_max
81
+ in the n1-by-n1 averaged spot surrounding said pixel will removed from the photon-hit-candidate list. If None,
82
+ this functionality is disabled and only the lower limit avg_threshold is used. Default is None.
83
+ include_doubles (bool, optional): if False, double photon events will be removed from the
84
+ final result
85
+ MAX_PHOTONS (number or False): if number, this function will raise an error if the number of
86
+ detected photons exceed MAX_PHOTONS
87
+
88
+ Returns:
89
+ PhotonEvents and double PhotonEvents in terms of x_centers and y_centers
90
+
91
+ Note:
92
+ The averaging n1 prevents that noise is counted as a candidate. By averaging, we are
93
+ requiring that, not only the `central` pixel is illuminated, but also the surrounding
94
+ pixels. n1=2 seems like a good averaging for most cases.
95
+
96
+ Note:
97
+ n2 must be roughly the same number of pixel which a photon can excite. For example,
98
+ if n2 = 4, we are expecting that a photon will excite at most a 4x4 array of pixels.
99
+
100
+ Note:
101
+ if n2 is too large, than the algorithm might mistakenly assign double photon hits as
102
+ it will think that multiple photons will be falling within the n2 squares.
103
+
104
+ Note:
105
+ I think a good metric for setting up the avg_threshold is to choose the highest threshold possible
106
+ such as one has no photon at `negative` energy loss. One can do this by slowly increasing
107
+ avg_threshold, and/or by visually inspecting the image using
108
+
109
+ >>> avg_threshold = <increase_value_slowly>
110
+ >>> n1 = 2
111
+ >>> n2 = 2
112
+ >>> pe, pe2 = scs.centroid(n1, n2, avg_threshold, double_threshold=<very_high_number>, floor=True)
113
+ >>>
114
+ >>> br.figure()
115
+ >>> im.moving_average(n1).plot()
116
+ >>> pe.plot()
117
+
118
+ if the photon count per image is so low that the elastic line cannot be identified and therefore
119
+ the `negative` energy loss region is unknown, then one have to sum many images.
120
+
121
+ Note:
122
+ For determining a reasonable double_threshold, I think the best option is to get a pixel which
123
+ for sure is a single hit, then draw a n2 square around it, and sum the intensities inside
124
+ this square and multiply by 1.5. For example, given the following matrix with a single photon
125
+ hit in the center (note that the center is slightly shifted to the left and top because the
126
+ length of the square is a even number):
127
+
128
+ [[ 4, 6, -4, 8],
129
+ [-9, 79, 52, 10],
130
+ [-2, 19, 17, -2],
131
+ [-6, -9, 2, -8]]
132
+
133
+ we see that the photon hit is on 79, then for n2=4 we have that the sum is 157 (see also example
134
+ below). A suitable double hit threshold would be 1.5 * 157 = 235.
135
+
136
+
137
+ Example:
138
+
139
+ This example goes over the step-by-step algorithm for detecting a candidate and assigning a photon hit.
140
+
141
+ Given the following matrix:
142
+
143
+ [[14, -7, 4, 6, -4, 8],
144
+ [14, 4, -9, 79, 52, 10],
145
+ [ 1, 17, -2, 19, 17, -2],
146
+ [-1, -4, -6, -9, 2, -8],
147
+ [-4, 3, 2, 7, -9, -3]]
148
+
149
+ Its approx. rounded averaged counterpart for n1=2 is:
150
+
151
+ [[ 6, -4, 18, 33, 16, 1],
152
+ [ 9, 1, 20, 42, 19, 0],
153
+ [ 3, 1, 0, 6, 2, -5],
154
+ [-2, -1, -2, -5, -7, -6],
155
+ [ 0, 4, 4, -2, -6, 0]]
156
+
157
+ note that in this example we are using a "approx" rounded average to facilitate the visualization
158
+ of the matrix (instead of an "exact" average), but the script does an exact calculation.
159
+
160
+ For avg_threshold = 25, we have two spots which are candidates: (x, y) = (3, 0) and (3, 1), with
161
+ intensity values 33 and 42, respectively.
162
+
163
+ Between these two spots, (3, 0) will be disregarded, because the intensity of (3, 1) is
164
+ brightest. Going back to the original matrix, we see that position (3, 1) yields intensity 79
165
+ (note that the pixels pixels that yielded 42 in the averaged (n1 x n1) matrix are:
166
+
167
+ [[79, 52],
168
+ [19, 17]]
169
+
170
+ From now on, we don't need to worry about the averaged (n1 x n1) matrix. This matrix is only
171
+ used to find the candidates.
172
+
173
+ In this example, the only candidate is (3, 1). We then gather pixel rows and cols to the
174
+ left/right/top/bottom of the candidate so to make a square of size n2. For n2 = 4 we have
175
+
176
+ [[ 4, 6, -4, 8],
177
+ [-9, 79, 52, 10],
178
+ [-2, 19, 17, -2],
179
+ [-6, -9, 2, -8]]
180
+
181
+ this is what we call a `spot`. Now we only have to determine if this spot is a double or
182
+ single hit.
183
+
184
+ the sum of the spot is 157. Let's say that double_threshold = 255, therefore, this spot is
185
+ a single hit.
186
+
187
+ Here is an example where it is known to be a double hit
188
+
189
+ Original:
190
+ [[-6, -1, 8, -4, 6, 0],
191
+ [ 4, -9, 14, 23, 0, 7],
192
+ [ 4, 4, 99, 41, -9, -9],
193
+ [37, 81, 50, 12, 13, -9],
194
+ [-3, 46, 16, -6, 5, -9]]
195
+
196
+ approx. rounded averaged for n1=2
197
+ [[-4, 2, 10, 6, 3, 1],
198
+ [ 0, 27, 45, 14, -4, -1],
199
+ [31, 59, 51, 14, -6, -3],
200
+ [40, 48, 18, 6, -1, -1],
201
+ [12, 17, 3, -1, 0, -2]]
202
+
203
+ From the averaged matrix we have many candidates (intensity > avg_threshold = 25). Taking the
204
+ brightest one, we have x, y = (1, 2), which has intensity 59
205
+
206
+ the spot for this pixel is (given n2=4)
207
+
208
+ [[ 4, -9, 14, 23],
209
+ [ 4, 4, 99, 41],
210
+ [37, 81, 50, 12],
211
+ [-3, 46, 16, -6]]
212
+
213
+ For this example, we know that a photon hit threshold should be around 200. Therefore, a
214
+ suitable double hit threshold would be 1.5 * 200 = 300.
215
+
216
+ This sum is 413, so it will be regarded as a double photon hit.
217
+
218
+ The position of a photon hit is then calculated by the 2D weighted sum of the intensities
219
+ (the mean x and y values within a spot).
220
+ """
221
+ ###################
222
+ # check n1 and n2 #
223
+ ###################
224
+ assert n1 > 0, f'n1 must be an positive integer'
225
+ assert n2 > 0, f'n2 must be an positive even integer'
226
+ # assert n2%2 == 0, f'n2 must be an even number to ensure that the `center of mass` of a photon hit is calculated in a square where the pixel with the photon hit is the central one'
227
+
228
+ #################################
229
+ # check x_centers and y_centers #
230
+ #################################
231
+ if self.x_monotonicity is None:
232
+ self.check_x_monotonicity()
233
+ if self.y_monotonicity is None:
234
+ self.check_y_monotonicity()
235
+
236
+ ###############
237
+ # floor image #
238
+ ###############
239
+ if floor:
240
+ image = self.floor()
241
+ else:
242
+ image = self.copy()
243
+
244
+ ##################
245
+ # moving average #
246
+ ##################
247
+ if n1 > 1:
248
+ image = image.moving_average(n1)
249
+
250
+ ##########################
251
+ # check double threshold #
252
+ ##########################
253
+ assert double_threshold > avg_threshold, 'avg_threshold must be smaller than double_threshold'
254
+
255
+ ###################
256
+ # find candidates #
257
+ ###################
258
+ # remove the edges of image (because one cannot calculated the `center of mass` at the edges)
259
+ # select pixels with intensity between low_threshold and high_threshold
260
+ if avg_threshold_max is not None:
261
+ assert avg_threshold_max > avg_threshold, 'avg_threshold must be smaller than avg_threshold_max'
262
+ if n2 > 0:
263
+ cp = np.argwhere((image.data[n2//2:-n2//2, n2//2:-n2//2] > avg_threshold)*(image.data[n2//2 : -n2//2, n2//2 : -n2//2] < avg_threshold_max))
264
+ else:
265
+ cp = np.argwhere((image.data > avg_threshold)*(image.data < avg_threshold_max))
266
+ else:
267
+ if n2 > 0:
268
+ cp = np.argwhere((image.data[n2//2:-n2//2, n2//2:-n2//2] > avg_threshold))
269
+ else:
270
+ cp = np.argwhere((image.data > avg_threshold))
271
+
272
+
273
+ #############################################################
274
+ # shift photon position because we removed the edges before #
275
+ #############################################################
276
+ # when we were looking for candidates, we excluded the edges
277
+ # now, to have the candidates position in terms of positions
278
+ # in the original image (image) we have to add back the edges
279
+ # that we excluded
280
+ cp += np.array((n2//2, n2//2))
281
+
282
+ #################################
283
+ # max allowed number of photons #
284
+ #################################
285
+ if MAX_PHOTONS:
286
+ if len(cp) > MAX_PHOTONS:
287
+ raise RuntimeError(f'number of detected photons is too high (> {MAX_PHOTONS}). Maybe try and change MAX_PHOTONS or Threshold.')
288
+
289
+ ########################
290
+ # centroid algorithm 1 #
291
+ ########################
292
+ # runs slower than algorithm 2 (I guess)
293
+ # has the problem that the brightest pixel must have n1 x n1 average above threshold for this pixel to be counted
294
+ # res = []
295
+ # dres = []
296
+ # for i, (y, x) in enumerate(cp):
297
+
298
+ # # isolate the spot where photon hit is in the center
299
+ # spot = self.data[y-n2//2:y+n1+n2//2, x-n2//2:x+n1+n2//2]
300
+
301
+ # # check if the central spot is the brightest one
302
+ # if (spot > self.data[y, x]).sum() == 0:
303
+
304
+ # # calculate x center of mass
305
+ # mx = np.average(np.arange(x-n2//2, x+n1+n2//2), weights=spot.sum(axis=0))
306
+
307
+ # # calculate y center of mass
308
+ # my = np.average(np.arange(y-n2//2, y+n1+n2//2), weights=spot.sum(axis=1))
309
+
310
+ # # check if spot is a double event
311
+ # # if (spot.sum() >= SpotLOW) and (spot.sum() < SpotHIGH):
312
+ # if (spot.sum() <= double_threshold):
313
+ # res.append((mx, my))
314
+ # else:
315
+ # if include_doubles:
316
+ # res.append((mx, my))
317
+ # res.append((mx, my))
318
+ # dres.append((mx, my))
319
+
320
+ ########################
321
+ # centroid algorithm 2 #
322
+ ########################
323
+ # an improved version of algorithm 1
324
+ flag = []
325
+ res = []
326
+ dres = []
327
+ for i, (y, x) in enumerate(cp):
328
+
329
+ # isolate the spot where photon hit is in the center
330
+ if n2%2 == 0:
331
+ spot = self.data[y-n2//2+1:y+n2//2+1, x-(n2//2+1):x+n2//2+1]
332
+ else:
333
+ spot = self.data[y-(n2//2):y+1+n2//2, x-(n2//2):x+1+n2//2]
334
+
335
+ # offset the spot to force all pixel values to be positive
336
+ # this is a requirement for the weighted sum (center of mass) to work fine
337
+ # if one mixes negative and positive weights, than the sum of the weights may
338
+ # be zero (or close to zero) and the weighted average x and/or y positions
339
+ # are wrong
340
+ # vmin = np.min(spot)
341
+ # vmax = np.max(spot)
342
+ # if vmin < 0 and vmax > 0:
343
+ # spot = spot - vmin
344
+ spot[spot < 0] = 0
345
+ # I still don't like this, if we are putting an offset in the spot, I think the
346
+ # threshold should also be offset. I don't know.
347
+ # to be honest, It does not make much sense that we have negative pixel values
348
+
349
+ # get brightest pixel
350
+ _y, _x = np.unravel_index(np.argmax(spot), np.array(spot).shape)
351
+ bx = x + (_x - n2//2)
352
+ by = y + (_y - n2//2)
353
+
354
+ if (bx, by) not in flag:
355
+ # flag that this point has been accounted for
356
+ flag.append((bx, by))
357
+
358
+ # calculate center of mass
359
+ if n2%2 == 0:
360
+ mx = np.average(np.arange(x-n2//2+1, x+n2//2+1), weights=spot.sum(axis=0))
361
+ my = np.average(np.arange(y-n2//2+1, y+n2//2+1), weights=spot.sum(axis=1))
362
+ else:
363
+ mx = np.average(np.arange(x-n2//2, x+1+n2//2), weights=spot.sum(axis=0))
364
+ my = np.average(np.arange(y-n2//2, y+1+n2//2), weights=spot.sum(axis=1))
365
+ # print(x+500, y)
366
+ # print(list(spot))
367
+ # print(mx+500)
368
+
369
+ # OBSOLETE CODE FOR AVOIDING SUM OF THE WEIGHTS CLOSE TO ZERO
370
+ # allow_hit_outside_of_spot=False
371
+ # allow_hit_outside_of_spot (bool, optional): default is False. Sometimes, if threshold is too low or
372
+ # noise is too high, it may happen that when calculating the x and y weighted average of the pixel
373
+ # intensity, the sum of all pixels within a spot [(n1+n2)-by-(n1+n2) square] can be close to
374
+ # zero. This leads to a wrong weighted sum because the x and/or y averaged position of the hit may
375
+ # fall outside of the spot, which does not make sense. If allow_hit_outside_of_spot = False, it
376
+ # will raise an error when this happens.
377
+ # if allow_hit_outside_of_spot == False:
378
+ # if mx < x-n2//2 or mx > x+n1+n2//2 or my < y-n2//2 or my > y+n1+n2//2:
379
+ # report = 'x values = [' + ','.join([str(_) for _ in np.arange(x-n2//2, x+n1+n2//2)]) + ']\n'
380
+ # report += 'y values = [' + ','.join([str(_) for _ in np.arange(y-n2//2, y+n1+n2//2)]) + ']\n'
381
+ # report += 'spot = ' + '[' + ', '.join(['\n [' + ', '.join([str(_2) for _2 in _]) + ']' for _ in spot])[9:] + ']' + '\n'
382
+ # report += f'x_weights = {spot.sum(axis=0)} # spot.sum(axis=0)' + '\n'
383
+ # report += f'y_weights = {spot.sum(axis=1)} # spot.sum(axis=1)' + '\n'
384
+ # report += f'sum_of_weights = {sum(spot.sum(axis=0))}' + '\n'
385
+ # report += f'x_weighted_avg = {mx}' + '\n'
386
+ # report += f'y_weighted_avg = {my}' + '\n'
387
+ # raise ValueError(f'spot `{i}` have center of mass outside of the spot' + '\n' + 'possible causes: 1) threshold too low or 2) noise level too high for single photon count\n' + 'Please, try increasing the threshold' + report)
388
+
389
+ # check if spot is a double event
390
+ if (spot.sum() <= double_threshold):
391
+ res.append((mx, my))
392
+ else:
393
+ if include_doubles:
394
+ res.append((mx, my))
395
+ res.append((mx, my))
396
+ dres.append((mx, my))
397
+
398
+ ############################
399
+ # convert pixel to centers #
400
+ ############################
401
+ data = np.array([[self.x_centers[int(x)] + (self.x_centers[int(x)+1]-self.x_centers[int(x)])*(x-int(x)), self.y_centers[int(y)] + (self.y_centers[int(y)+1]-self.y_centers[int(y)])*(y-int(y))] for x, y in res])
402
+ if len(data) == 0:
403
+ pe = br.PhotonEvents()
404
+ else:
405
+ pe = br.PhotonEvents(x=data[:, 0], y=data[:, 1], xlim=(min(self.x_centers), max(self.x_centers)), ylim=(min(self.y_centers), max(self.y_centers)))
406
+ pe.copy_attrs_from(self)
407
+
408
+ data = np.array([[self.x_centers[int(x)] + (self.x_centers[int(x)+1]-self.x_centers[int(x)])*(x-int(x)), self.y_centers[int(y)] + (self.y_centers[int(y)+1]-self.y_centers[int(y)])*(y-int(y))] for x, y in dres])
409
+ if len(data) == 0:
410
+ bad = br.PhotonEvents()
411
+ else:
412
+ bad = br.PhotonEvents(x=data[:, 0], y=data[:, 1])
413
+ bad.copy_attrs_from(self)
414
+
415
+ # return res, bad
416
+ return pe, bad
417
+ br.Image.centroid = _centroid