pcot 1.1.0rc1__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 (285) hide show
  1. pcot/VERSION.txt +2 -0
  2. pcot/__init__.py +158 -0
  3. pcot/__main__.py +6 -0
  4. pcot/ancillary/__init__.py +20 -0
  5. pcot/ancillary/aupe.py +97 -0
  6. pcot/ancillary/bandancillary.py +62 -0
  7. pcot/ancillary/keys.py +38 -0
  8. pcot/ancillary/multifile.py +69 -0
  9. pcot/app.py +120 -0
  10. pcot/assets/__init__.py +42 -0
  11. pcot/assets/data/builtin_spectral_parameters.yaml +116 -0
  12. pcot/assets/data/colour_correction/ae_dl_ccm.csv +3 -0
  13. pcot/assets/data/colour_correction/pc_nl_ccm.csv +3 -0
  14. pcot/assets/data/colour_correction/pc_nl_spl_o.npz +0 -0
  15. pcot/assets/data/colour_correction/pc_th_ccm.csv +3 -0
  16. pcot/assets/data/colour_correction/pc_th_spl_o.npz +0 -0
  17. pcot/assets/icons/arrow-down-darkmode.svg +1 -0
  18. pcot/assets/icons/arrow-down.svg +1 -0
  19. pcot/assets/icons/arrow-up-darkmode.svg +1 -0
  20. pcot/assets/icons/arrow-up.svg +1 -0
  21. pcot/assets/icons/chevrons-down-darkmode.svg +1 -0
  22. pcot/assets/icons/chevrons-down.svg +1 -0
  23. pcot/assets/icons/chevrons-up-darkmode.svg +1 -0
  24. pcot/assets/icons/chevrons-up.svg +1 -0
  25. pcot/assets/icons/info-darkmode.svg +1 -0
  26. pcot/assets/icons/info.svg +1 -0
  27. pcot/assets/icons/lock-darkmode.svg +1 -0
  28. pcot/assets/icons/lock.svg +1 -0
  29. pcot/assets/icons/maximize-2-darkmode.svg +1 -0
  30. pcot/assets/icons/maximize-2.svg +1 -0
  31. pcot/assets/icons/unlock-darkmode.svg +1 -0
  32. pcot/assets/icons/unlock.svg +1 -0
  33. pcot/assets/icons/x-circle-darkmode.svg +1 -0
  34. pcot/assets/icons/x-circle.svg +1 -0
  35. pcot/assets/images/blackAndCols.png +0 -0
  36. pcot/assets/images/corrib.png +0 -0
  37. pcot/assets/images/gradRGB.png +0 -0
  38. pcot/assets/images/marsRGB.png +0 -0
  39. pcot/assets/images/simpct.png +0 -0
  40. pcot/assets/images/tstreg1.png +0 -0
  41. pcot/assets/images/tstreg2.png +0 -0
  42. pcot/assets/ui/dialogs/about.css +12 -0
  43. pcot/assets/ui/dialogs/about.md +39 -0
  44. pcot/assets/ui/dialogs/about.ui +71 -0
  45. pcot/assets/ui/dialogs/import.ui +104 -0
  46. pcot/assets/ui/dialogs/main.ui +512 -0
  47. pcot/assets/ui/dialogs/presets.ui +82 -0
  48. pcot/assets/ui/dialogs/rawloader.ui +207 -0
  49. pcot/assets/ui/dialogs/reorderplots.ui +129 -0
  50. pcot/assets/ui/dialogs/showcamsrefls.ui +331 -0
  51. pcot/assets/ui/inputs/inputenvi.ui +74 -0
  52. pcot/assets/ui/inputs/inputmultifile.ui +204 -0
  53. pcot/assets/ui/inputs/inputparc.ui +138 -0
  54. pcot/assets/ui/inputs/inputpdsfile.ui +225 -0
  55. pcot/assets/ui/inputs/inputrgb.ui +160 -0
  56. pcot/assets/ui/tabs/tabPCA.ui +200 -0
  57. pcot/assets/ui/tabs/tabassignfilters.ui +102 -0
  58. pcot/assets/ui/tabs/tabbanddepth.ui +83 -0
  59. pcot/assets/ui/tabs/tabcirc.ui +210 -0
  60. pcot/assets/ui/tabs/tabcolmap.ui +365 -0
  61. pcot/assets/ui/tabs/tabcomment.ui +106 -0
  62. pcot/assets/ui/tabs/tabconnector.ui +62 -0
  63. pcot/assets/ui/tabs/tabcontrast.ui +68 -0
  64. pcot/assets/ui/tabs/tabcrosscalib.ui +178 -0
  65. pcot/assets/ui/tabs/tabcurve.ui +134 -0
  66. pcot/assets/ui/tabs/tabdecorr.ui +149 -0
  67. pcot/assets/ui/tabs/tabdqmod.ui +198 -0
  68. pcot/assets/ui/tabs/tabexpr.ui +91 -0
  69. pcot/assets/ui/tabs/tabgen.ui +173 -0
  70. pcot/assets/ui/tabs/tabhistogram.ui +62 -0
  71. pcot/assets/ui/tabs/tabimportroi.ui +106 -0
  72. pcot/assets/ui/tabs/tabinset.ui +116 -0
  73. pcot/assets/ui/tabs/tabmacro.ui +74 -0
  74. pcot/assets/ui/tabs/tabmacroparam.ui +66 -0
  75. pcot/assets/ui/tabs/tabmanreg.ui +239 -0
  76. pcot/assets/ui/tabs/tabmultidot.ui +281 -0
  77. pcot/assets/ui/tabs/tabnorm.ui +74 -0
  78. pcot/assets/ui/tabs/taboffset.ui +100 -0
  79. pcot/assets/ui/tabs/tabpainted.ui +190 -0
  80. pcot/assets/ui/tabs/tabpctcalib.ui +288 -0
  81. pcot/assets/ui/tabs/tabpctdetection.ui +305 -0
  82. pcot/assets/ui/tabs/tabpixtest.ui +238 -0
  83. pcot/assets/ui/tabs/tabpoly.ui +186 -0
  84. pcot/assets/ui/tabs/tabrect.ui +220 -0
  85. pcot/assets/ui/tabs/tabreflectance.ui +294 -0
  86. pcot/assets/ui/tabs/tabroicull.ui +71 -0
  87. pcot/assets/ui/tabs/tabroidq.ui +202 -0
  88. pcot/assets/ui/tabs/tabroiexpr.ui +242 -0
  89. pcot/assets/ui/tabs/tabscalartest.ui +161 -0
  90. pcot/assets/ui/tabs/tabspecparam.ui +93 -0
  91. pcot/assets/ui/tabs/tabspectrum.ui +422 -0
  92. pcot/assets/ui/tabs/tabstitch.ui +104 -0
  93. pcot/assets/ui/tabs/tabstringtest.ui +70 -0
  94. pcot/batch.py +39 -0
  95. pcot/calib/__init__.py +2 -0
  96. pcot/calib/apply.py +106 -0
  97. pcot/calib/colorchecker_classic.py +80 -0
  98. pcot/calib/fit.py +296 -0
  99. pcot/calib/pct.py +40 -0
  100. pcot/calib/target.py +47 -0
  101. pcot/cameras/__init__.py +89 -0
  102. pcot/cameras/camdata.py +254 -0
  103. pcot/cameras/filters.py +221 -0
  104. pcot/cameras/filtresponse.py +188 -0
  105. pcot/cameras/reflectances.py +519 -0
  106. pcot/cameras/show.py +247 -0
  107. pcot/canvasnormalise.py +93 -0
  108. pcot/colour_correction/__init__.py +2 -0
  109. pcot/colour_correction/colour_transforms.py +121 -0
  110. pcot/colour_correction/constants.py +30 -0
  111. pcot/colour_correction/correct.py +74 -0
  112. pcot/config.py +365 -0
  113. pcot/connbrushes.py +67 -0
  114. pcot/dataformats/__init__.py +5 -0
  115. pcot/dataformats/envi.py +353 -0
  116. pcot/dataformats/load.py +463 -0
  117. pcot/dataformats/pds4.py +343 -0
  118. pcot/dataformats/raw.py +185 -0
  119. pcot/datum.py +554 -0
  120. pcot/datumexceptions.py +58 -0
  121. pcot/datumfuncs.py +1441 -0
  122. pcot/datumtypes.py +446 -0
  123. pcot/document.py +419 -0
  124. pcot/documentsettings.py +30 -0
  125. pcot/dq.py +102 -0
  126. pcot/expressions/__init__.py +4 -0
  127. pcot/expressions/eval.py +152 -0
  128. pcot/expressions/instructions.py +211 -0
  129. pcot/expressions/ops.py +343 -0
  130. pcot/expressions/parse.py +255 -0
  131. pcot/expressions/prattparser.py +444 -0
  132. pcot/expressions/register.py +266 -0
  133. pcot/expressions/types.py +205 -0
  134. pcot/imagecube.py +1287 -0
  135. pcot/imageexport.py +163 -0
  136. pcot/inputs/__init__.py +11 -0
  137. pcot/inputs/directinput.py +54 -0
  138. pcot/inputs/envimethod.py +119 -0
  139. pcot/inputs/inp.py +311 -0
  140. pcot/inputs/inputmethod.py +236 -0
  141. pcot/inputs/multifile.py +575 -0
  142. pcot/inputs/nullinput.py +27 -0
  143. pcot/inputs/parc.py +299 -0
  144. pcot/inputs/pds4input.py +524 -0
  145. pcot/inputs/rgb.py +172 -0
  146. pcot/macros.py +668 -0
  147. pcot/main.py +26 -0
  148. pcot/operations/__init__.py +64 -0
  149. pcot/operations/curve.py +55 -0
  150. pcot/operations/norm.py +94 -0
  151. pcot/palette.py +303 -0
  152. pcot/parameters/__init__.py +10 -0
  153. pcot/parameters/autodoc.py +227 -0
  154. pcot/parameters/inputs.py +153 -0
  155. pcot/parameters/parameterfile.py +588 -0
  156. pcot/parameters/runner.py +319 -0
  157. pcot/parameters/taggedaggregates.py +943 -0
  158. pcot/rois.py +1123 -0
  159. pcot/sources.py +591 -0
  160. pcot/subcommands/__init__.py +17 -0
  161. pcot/subcommands/batch.py +28 -0
  162. pcot/subcommands/config.py +117 -0
  163. pcot/subcommands/gencam.py +364 -0
  164. pcot/subcommands/genrefl.py +111 -0
  165. pcot/subcommands/lscams.py +107 -0
  166. pcot/subcommands/lsrefls.py +74 -0
  167. pcot/subcommands/parcutils.py +76 -0
  168. pcot/subcommands/subcommands.py +77 -0
  169. pcot/ui/__init__.py +168 -0
  170. pcot/ui/canvas.py +1981 -0
  171. pcot/ui/canvasdq.py +94 -0
  172. pcot/ui/collapser.py +227 -0
  173. pcot/ui/datadialog.py +13 -0
  174. pcot/ui/datawidget.py +221 -0
  175. pcot/ui/dqwidget.py +93 -0
  176. pcot/ui/filepathedit.py +82 -0
  177. pcot/ui/gradient.py +194 -0
  178. pcot/ui/graphscene.py +945 -0
  179. pcot/ui/graphview.py +156 -0
  180. pcot/ui/help.py +170 -0
  181. pcot/ui/importdialog.py +61 -0
  182. pcot/ui/inputs.py +388 -0
  183. pcot/ui/linear.py +386 -0
  184. pcot/ui/mainwindow.py +805 -0
  185. pcot/ui/mplwidget.py +94 -0
  186. pcot/ui/namedialog.py +42 -0
  187. pcot/ui/number.py +94 -0
  188. pcot/ui/presetmgr.py +304 -0
  189. pcot/ui/roiedit.py +283 -0
  190. pcot/ui/smallwidgets.py +14 -0
  191. pcot/ui/spectrumwidget.py +121 -0
  192. pcot/ui/tabledialog.py +53 -0
  193. pcot/ui/tablemodel.py +386 -0
  194. pcot/ui/tabs.py +359 -0
  195. pcot/ui/tabulardatawidget.py +110 -0
  196. pcot/ui/taggedaggregates/__init__.py +199 -0
  197. pcot/ui/taggedaggregates/configui.py +122 -0
  198. pcot/ui/taggedaggregates/editors.py +480 -0
  199. pcot/ui/textedit.py +104 -0
  200. pcot/ui/texttogglebutton.py +79 -0
  201. pcot/ui/theme.py +129 -0
  202. pcot/ui/uiloader.py +245 -0
  203. pcot/ui/variantwidget.py +99 -0
  204. pcot/ui/zoomevents.py +29 -0
  205. pcot/utils/__init__.py +111 -0
  206. pcot/utils/annotations.py +129 -0
  207. pcot/utils/archive.py +571 -0
  208. pcot/utils/cluster.py +94 -0
  209. pcot/utils/colour.py +32 -0
  210. pcot/utils/datumstore.py +308 -0
  211. pcot/utils/deb.py +104 -0
  212. pcot/utils/debayering.py +84 -0
  213. pcot/utils/decorr.py +102 -0
  214. pcot/utils/demosaicing/__init__.py +42 -0
  215. pcot/utils/demosaicing/malvar.py +184 -0
  216. pcot/utils/demosaicing/menon.py +378 -0
  217. pcot/utils/demosaicing/utils.py +85 -0
  218. pcot/utils/flood.py +127 -0
  219. pcot/utils/geom.py +76 -0
  220. pcot/utils/gradient.py +89 -0
  221. pcot/utils/html.py +57 -0
  222. pcot/utils/image.py +56 -0
  223. pcot/utils/interp.py +127 -0
  224. pcot/utils/maths.py +34 -0
  225. pcot/utils/params.py +3 -0
  226. pcot/utils/spectralparameters.py +178 -0
  227. pcot/utils/spectrum.py +244 -0
  228. pcot/utils/spectrumdata.py +455 -0
  229. pcot/utils/table.py +225 -0
  230. pcot/utils/tabular_provider.py +74 -0
  231. pcot/utils/text.py +74 -0
  232. pcot/value.py +456 -0
  233. pcot/xform.py +1669 -0
  234. pcot/xforms/__init__.py +23 -0
  235. pcot/xforms/favourite.py +36 -0
  236. pcot/xforms/tabgeneric.py +89 -0
  237. pcot/xforms/xformassignfilters.py +219 -0
  238. pcot/xforms/xformautoregister.py +78 -0
  239. pcot/xforms/xformbanddepth.py +137 -0
  240. pcot/xforms/xformcalibtargets.py +625 -0
  241. pcot/xforms/xformcirc.py +189 -0
  242. pcot/xforms/xformcolourcorrection.py +66 -0
  243. pcot/xforms/xformcolourmap.py +622 -0
  244. pcot/xforms/xformcomment.py +164 -0
  245. pcot/xforms/xformconstant.py +109 -0
  246. pcot/xforms/xformcontrast.py +175 -0
  247. pcot/xforms/xformcrop.py +36 -0
  248. pcot/xforms/xformcrosscalib.py +355 -0
  249. pcot/xforms/xformcurve.py +83 -0
  250. pcot/xforms/xformcustomtabexample.py +251 -0
  251. pcot/xforms/xformdecorr.py +129 -0
  252. pcot/xforms/xformdqmod.py +219 -0
  253. pcot/xforms/xformdummy.py +25 -0
  254. pcot/xforms/xformexpr.py +342 -0
  255. pcot/xforms/xformgen.py +265 -0
  256. pcot/xforms/xformhist.py +129 -0
  257. pcot/xforms/xformhistequal.py +102 -0
  258. pcot/xforms/xformimportroi.py +110 -0
  259. pcot/xforms/xforminput.py +70 -0
  260. pcot/xforms/xforminset.py +232 -0
  261. pcot/xforms/xformmanualregister.py +506 -0
  262. pcot/xforms/xformmultidot.py +686 -0
  263. pcot/xforms/xformnorm.py +55 -0
  264. pcot/xforms/xformoffset.py +82 -0
  265. pcot/xforms/xformpainted.py +199 -0
  266. pcot/xforms/xformpca.py +400 -0
  267. pcot/xforms/xformpctpatchdetection.py +1277 -0
  268. pcot/xforms/xformpoly.py +173 -0
  269. pcot/xforms/xformrect.py +220 -0
  270. pcot/xforms/xformreflectance.py +699 -0
  271. pcot/xforms/xformroicull.py +90 -0
  272. pcot/xforms/xformroidq.py +263 -0
  273. pcot/xforms/xformroiexpr.py +504 -0
  274. pcot/xforms/xformsimpleexample.py +135 -0
  275. pcot/xforms/xformsink.py +61 -0
  276. pcot/xforms/xformspecparam.py +111 -0
  277. pcot/xforms/xformspectrum.py +491 -0
  278. pcot/xforms/xformstitch.py +321 -0
  279. pcot/xforms/xformstriproi.py +46 -0
  280. pcot/xforms/xformtests.py +718 -0
  281. pcot-1.1.0rc1.dist-info/LICENSE +20 -0
  282. pcot-1.1.0rc1.dist-info/METADATA +305 -0
  283. pcot-1.1.0rc1.dist-info/RECORD +285 -0
  284. pcot-1.1.0rc1.dist-info/WHEEL +4 -0
  285. pcot-1.1.0rc1.dist-info/entry_points.txt +4 -0
pcot/VERSION.txt ADDED
@@ -0,0 +1,2 @@
1
+ 1.1.0rc1 TBD MEXICO CROSS
2
+ 0.10.0 # version number of oldest legible document
pcot/__init__.py ADDED
@@ -0,0 +1,158 @@
1
+ import importlib.util
2
+ import os
3
+ import re
4
+ import traceback
5
+
6
+ try:
7
+ import pcot.macros as macros
8
+ except AttributeError as e:
9
+ traceback.print_exc()
10
+ print("""
11
+ This error MAY mean that you should turn off Qt Compatible debugging in PyCharm. It's a bug
12
+ https://youtrack.jetbrains.com/issue/PY-50959
13
+ """)
14
+ exit(0)
15
+
16
+ import pcot.ui as ui
17
+ import pcot.xform as xform
18
+ import pcot.xforms
19
+ from pcot.config import getUserName, addMainWindowHook, addExprFuncHook
20
+ from pcot.utils import archive, spectralparameters
21
+ from pcot.xforms import *
22
+ import logging
23
+ import pkgutil
24
+
25
+ import faulthandler
26
+
27
+ faulthandler.enable()
28
+
29
+ plugins_loaded = False
30
+
31
+
32
+ def load_plugins():
33
+ """plugin dirs are semicolon separated, stored in Locations/plugins"""
34
+
35
+ import sys
36
+
37
+ # make sure this only happens once - we can call pcot.setup() lots
38
+ # of times during tests.
39
+
40
+ global plugins_loaded
41
+ if plugins_loaded:
42
+ return
43
+ plugins_loaded = True
44
+
45
+ pluginDirs = pcot.config.getDefaultDir('pluginpath')
46
+
47
+ # Load any plugins by recursively walking the plugin directories and importing .py files.
48
+
49
+ for d in pluginDirs:
50
+ for root, dirs, files in os.walk(d):
51
+ for filename in files:
52
+ base, ext = os.path.splitext(filename)
53
+ if ext == '.py':
54
+ path = os.path.join(root, filename)
55
+ logger.info(f"Loading plugin : {path}")
56
+ spec = importlib.util.spec_from_file_location(base, path)
57
+ module = importlib.util.module_from_spec(spec)
58
+ sys.modules[base] = module
59
+ spec.loader.exec_module(module)
60
+
61
+
62
+ def setup():
63
+ """Call this to initialise PCOT. We could just call it here, but other things would break then.
64
+ You'll see that main() calls it."""
65
+
66
+ # forces the file to be parsed, which uses decorators to register functions etc.
67
+ import pcot.expressions.register
68
+ # force import of builtin functions!
69
+ import pcot.datumfuncs
70
+ # register the built-in ancillary data (sidecar) loaders - before plugins, so they're tried first
71
+ import pcot.ancillary
72
+
73
+ load_plugins()
74
+
75
+ # creates xform type singletons, which also causes the expression evaluator to be
76
+ # created as part of XFormExpr, running the functions registered above and thus
77
+ # allowing *them* to register functions etc.
78
+ xform.createXFormTypeInstances()
79
+
80
+ # load camera set data
81
+ config.loadCameras()
82
+ # and reflectances
83
+ config.loadReflectances()
84
+
85
+ spectralparameters.loadSpectralParameters()
86
+
87
+
88
+ # If we run without a GUI, we still need an application. This will provide that.
89
+ from pcot.app import checkApp
90
+ checkApp()
91
+
92
+
93
+ logging.basicConfig(format='%(levelname)s %(asctime)s %(name)s: %(message)s', force=True)
94
+ logger = logging.getLogger(__name__)
95
+ logger.setLevel(logging.INFO)
96
+
97
+ # matplotlib spews a lot of debugging data - turn it off
98
+ logging.getLogger('matplotlib.font_manager').disabled = True
99
+
100
+
101
+ logger.debug("Starting PCOT")
102
+
103
+ # get version data, which consists of something like
104
+ # 0.0.0 ISO-DATE RAINBOW CODE NAME
105
+ tmp = pkgutil.get_data('pcot', 'VERSION.txt')
106
+ if tmp is None:
107
+ raise ValueError('cannot find VERSION.txt')
108
+
109
+ # this string gets turned into pcot.__fullversion__, while pcot.__version__
110
+ # is just the first word (0.0.0 in the example). That word must be a PEP 440 version
111
+ # (e.g. 1.2.0, or 1.2.0b1 for a pre-release) identical to the version in pyproject.toml;
112
+ # tests/config/test_version_check.py checks both of these.
113
+
114
+ # There's a second line too, which is the oldest document version we can safely load.from
115
+
116
+ tmp = tmp.decode('utf-8')
117
+ lines = tmp.splitlines()
118
+
119
+ __fullversion__ = lines[0].strip()
120
+ __version__ = __fullversion__.split(maxsplit=1)[0]
121
+
122
+ oldest_valid_version = lines[1].split(maxsplit=1)[0]
123
+
124
+ def compatible_version_check(version):
125
+ """This checks to see if this version of PCOT can load data created by the version passed in"""
126
+
127
+ def _do_check(version):
128
+ # remove any trailing stuff from the document version
129
+ version = version.split()[0]
130
+
131
+ def _parse(v):
132
+ # take the leading digits of each part, dropping any pre-release suffix: both
133
+ # the old "0.12.0-beta" style found in older documents and PEP 440 "1.1.0b1"
134
+ return tuple(int(re.match(r"\d+", part).group()) for part in v.split("."))
135
+
136
+ doc_maj, doc_min, doc_patch = _parse(version)
137
+ app_maj, app_min, app_patch = _parse(oldest_valid_version)
138
+
139
+ if doc_maj > app_maj:
140
+ return True
141
+ if doc_maj < app_maj:
142
+ return False
143
+
144
+ # major versions the same; check minor
145
+ if doc_min > app_min:
146
+ return True
147
+ if doc_min < app_min:
148
+ return False
149
+
150
+ # major and minor the same, check patch
151
+ return doc_patch >= app_patch
152
+
153
+ result = _do_check(version)
154
+ if not result:
155
+ if config.ignore_version:
156
+ logger.warning(f"PCOT version {version} does not match PCOT version {oldest_valid_version}")
157
+ return True
158
+ return result
pcot/__main__.py ADDED
@@ -0,0 +1,6 @@
1
+ # used to run with -m.
2
+
3
+ import pcot.main
4
+
5
+ if __name__ == "__main__":
6
+ pcot.main.main()
@@ -0,0 +1,20 @@
1
+ """
2
+ This package deals with ancillary data attached to ImageCube objects. This is read either from the data
3
+ itself (ENVI, PDS4) or from files of similar names parallel to the image data (multifile).
4
+
5
+ Ancillary data is typically per-band, although we may also need to support data for the cube as a whole.
6
+
7
+ A typical example of ancillary data is the exposure time of a particular band.
8
+
9
+ The data is read in this package, but reading is invoked by the image loaders in pcot.dataformats.load
10
+ (e.g. load.multifile(), which the Multifile input method uses). Reading needs to be very
11
+ flexible - both in determining the data source (e.g. the name of the parallel .xml file to a .png file)
12
+ and in processing it (because different cameras and versions of their export software may produce different
13
+ XML files).
14
+ """
15
+
16
+ from pcot.ancillary.multifile import multifile_loader
17
+
18
+ # importing the built-in loaders registers them
19
+ import pcot.ancillary.aupe
20
+
pcot/ancillary/aupe.py ADDED
@@ -0,0 +1,97 @@
1
+ """
2
+ This is a sidecar loader for AUPE3 files (as of 25 Sep 2026)
3
+ """
4
+ import logging
5
+ from pathlib import Path
6
+ from typing import Any, Optional, Dict, List, Tuple, Callable
7
+ from logging import getLogger
8
+ from pcot import ui
9
+ from pcot.ancillary import keys
10
+ from pcot.ancillary.multifile import MultifileSidecarLoader, add_multifile_sidecar_loader
11
+
12
+ logger = getLogger(__name__)
13
+
14
+ # multiply AUPE3's exposure_time by this to get seconds. It's already in seconds (a typical
15
+ # value is 0.009911), but it's kept as a constant in case a later convention differs.
16
+ EXPOSURE_TIME_TO_SECONDS = 1.0
17
+
18
+ # The ImageMetadata fields we read: AUPE3 field name -> (ancillary key, function converting the
19
+ # field's string value into the key's unit). Fields missing from a file are just left out.
20
+ FIELDS: Dict[str, Tuple[keys.AncillaryKey, Callable[[str], Any]]] = {
21
+ "exposure_time": (keys.EXPOSURE, lambda v: float(v) * EXPOSURE_TIME_TO_SECONDS),
22
+ "filter_num": (keys.FILTER_NUMBER, int),
23
+ }
24
+
25
+ # The "Camera" entry in the metadata attribute (outside ImageMetadata) -> the lens it captures through.
26
+ # Other cameras (e.g. the HRC) have no lens.
27
+ CAMERA_TO_LENS = {
28
+ "WAC_LEFT": "L",
29
+ "WAC_RIGHT": "R",
30
+ }
31
+
32
+
33
+ def _load(fname) -> Dict[str, Any]:
34
+ """Read ancillary data from an AUPE XML metadata file. Raises an exception describing the
35
+ problem if the file isn't in the format we expect, including if none of the fields in FIELDS
36
+ are present. Once the file is recognised, a field with a bad value is left out with a warning
37
+ (not an exception - no other loader will be asked to read the file)."""
38
+ import xml.etree.ElementTree as ET
39
+ tree = ET.parse(fname)
40
+ root = tree.getroot()
41
+ cont = root.find("context")
42
+ if cont is None:
43
+ raise ValueError("no <context> element")
44
+
45
+ metadata = [x for x in cont.findall("attribute") if x.get("name") == "metadata"]
46
+ if len(metadata) == 0:
47
+ raise ValueError("no metadata attribute in <context>")
48
+ value = metadata[0].get("value")
49
+ if value is None:
50
+ raise ValueError("metadata attribute has no value")
51
+
52
+ mds = value.split(";")
53
+ mds = list(filter(lambda x: len(x) > 1, map(lambda x: x.split("="), mds)))
54
+ mds = {x[0]: x[1] for x in mds}
55
+ if "ImageMetadata" not in mds:
56
+ raise ValueError("no ImageMetadata in metadata")
57
+
58
+ md = mds["ImageMetadata"].split("|")
59
+ md = dict(zip(md[::2], md[1::2]))
60
+ if not any(field in md for field in FIELDS):
61
+ raise ValueError(f"none of the expected fields ({', '.join(FIELDS)}) in ImageMetadata")
62
+
63
+ output = {}
64
+
65
+ # the lens comes from the Camera entry in the metadata attribute, not from ImageMetadata
66
+ camera = mds.get("Camera")
67
+ if camera in CAMERA_TO_LENS:
68
+ output[keys.LENS.name] = CAMERA_TO_LENS[camera]
69
+ else:
70
+ logger.debug(f"{fname}: no lens for camera {camera!r}")
71
+
72
+ for field, (key, convert) in FIELDS.items():
73
+ if field not in md:
74
+ logger.debug(f"{fname}: no {field} in ImageMetadata")
75
+ continue
76
+ try:
77
+ output[key.name] = convert(md[field])
78
+ except Exception as e:
79
+ ui.log(f"Bad value for {field} in {fname} ({md[field]!r}): {e} - ignoring it",
80
+ loglevel=logging.WARNING)
81
+ return output
82
+
83
+
84
+ class AUPE3MultifileLoader(MultifileSidecarLoader):
85
+ def attempt_load(self, path: Path, problems: List[str]) -> Optional[Dict[str, Any]]:
86
+ p = path.with_suffix(path.suffix + '.xml') # look for AUPE's .png.xml style XML sidecar
87
+ if not p.exists():
88
+ return None
89
+ try:
90
+ return _load(p)
91
+ except Exception as e:
92
+ problems.append(f"AUPE3 loader could not read {p.name}: {e}")
93
+ return None
94
+
95
+
96
+ # register the loader when this file is imported
97
+ add_multifile_sidecar_loader(AUPE3MultifileLoader())
@@ -0,0 +1,62 @@
1
+ """
2
+ Per-band ancillary data for an ImageCube. See internalDocs/docs/ancillary.md for the rules about
3
+ which operations keep it and which drop it.
4
+ """
5
+ from typing import List, Dict, Any, Optional, Iterable
6
+
7
+
8
+ class BandAncillary:
9
+ """Ancillary data for each band of an ImageCube: one dict per band, keyed by the names in
10
+ pcot.ancillary.keys. A band with no ancillary data has an empty dict. The API deliberately
11
+ mirrors MultiBandSource, so code which rearranges bands can do the same thing to both.
12
+
13
+ ASSUMPTION: although the values are typed as Any, they must be JSON-serialisable (str, int,
14
+ float, bool, None, or lists/dicts of those - not e.g. numpy scalars), because they are saved
15
+ as-is in documents and PARC archives. A value which isn't will make saving fail, with an error
16
+ from the archive code naming the offending item."""
17
+ bands: List[Dict[str, Any]]
18
+
19
+ def __init__(self, bands: List[Dict[str, Any]]):
20
+ self.bands = bands
21
+
22
+ @classmethod
23
+ def empty(cls, n: int) -> 'BandAncillary':
24
+ """Create ancillary data with nothing in it for n bands"""
25
+ return cls([{} for _ in range(n)])
26
+
27
+ @classmethod
28
+ def concat(cls, lst: Iterable['BandAncillary']) -> 'BandAncillary':
29
+ """Join the bands of several BandAncillary objects together, in order (e.g. when merging images)"""
30
+ return cls([dict(d) for a in lst for d in a.bands])
31
+
32
+ def copy(self) -> 'BandAncillary':
33
+ return BandAncillary([dict(d) for d in self.bands])
34
+
35
+ def select(self, bands: List[int]) -> 'BandAncillary':
36
+ """Get the data for a subset (or reordering) of the bands"""
37
+ return BandAncillary([dict(self.bands[i]) for i in bands])
38
+
39
+ def get(self, key: str) -> List[Optional[Any]]:
40
+ """Get the value of a key for every band, with None for bands which don't have it"""
41
+ return [d.get(key) for d in self.bands]
42
+
43
+ def serialise(self) -> List[Dict[str, Any]]:
44
+ """Serialise as a list of dicts, one per band (the values must be JSON-serialisable)"""
45
+ return [dict(d) for d in self.bands]
46
+
47
+ @classmethod
48
+ def deserialise(cls, lst: List[Dict[str, Any]]) -> 'BandAncillary':
49
+ return cls([dict(d) for d in lst])
50
+
51
+ def isEmpty(self) -> bool:
52
+ """True if no band has any ancillary data"""
53
+ return not any(self.bands)
54
+
55
+ def __len__(self):
56
+ return len(self.bands)
57
+
58
+ def __getitem__(self, band: int) -> Dict[str, Any]:
59
+ return self.bands[band]
60
+
61
+ def __repr__(self):
62
+ return f"BandAncillary({self.bands})"
pcot/ancillary/keys.py ADDED
@@ -0,0 +1,38 @@
1
+ """
2
+ The standard keys used in ancillary data dicts, and their units. Loaders must convert whatever
3
+ they read into these units, and should always refer to keys through the constants here (e.g.
4
+ keys.EXPOSURE.name), never as string literals - the set of keys is expected to change, and this
5
+ way a key can be renamed, given a different unit, or added in one place.
6
+
7
+ Values stored under these keys must be JSON-serialisable (see BandAncillary).
8
+ """
9
+ from dataclasses import dataclass
10
+ from typing import Dict
11
+
12
+
13
+ @dataclass(frozen=True)
14
+ class AncillaryKey:
15
+ name: str # the key used in ancillary data dicts
16
+ unit: str # the unit all loaders must convert to, or empty string
17
+ description: str # human-readable description
18
+
19
+
20
+ EXPOSURE = AncillaryKey("exposure", "s", "Exposure time")
21
+ # The filter a band was captured through, as the camera's own filter wheel number and lens. These are
22
+ # raw facts from the capture: matching them to a filter in PCOT's camera data is done by the image
23
+ # loader, which knows the camera (see load.multifile()).
24
+ FILTER_NUMBER = AncillaryKey("filter_number", "", "Filter wheel position number (an int)")
25
+ LENS = AncillaryKey("lens", "", "Lens the band was captured through: 'L' or 'R'")
26
+
27
+ # ENVI-specific (probably)
28
+ GAIN = AncillaryKey("gain", "", "Gain value from ENVI file")
29
+ OFFSET = AncillaryKey("offset", "", "Offset value from ENVI file")
30
+
31
+ # all the keys, by name
32
+ ALL_KEYS: Dict[str, AncillaryKey] = {k.name: k for k in [
33
+ EXPOSURE,
34
+ FILTER_NUMBER,
35
+ LENS,
36
+ GAIN,
37
+ OFFSET,
38
+ ]}
@@ -0,0 +1,69 @@
1
+ """
2
+ Handles loading ancillary data from multifile images (or "sidecar" XML files)
3
+ """
4
+ import logging
5
+ from abc import ABC, abstractmethod
6
+ from pathlib import Path
7
+ from typing import List, Dict, Any, Optional
8
+
9
+ from pcot import ui
10
+
11
+ logger = logging.getLogger(__name__)
12
+
13
+
14
+ class MultifileSidecarLoader(ABC):
15
+ @abstractmethod
16
+ def attempt_load(self, path: Path, problems: List[str]) -> Optional[Dict[str, Any]]:
17
+ """The path here is the name of the original .png or .jpg; we'll try to
18
+ infer a path for the sidecar and load data from it. If any of that fails
19
+ we return None and move on to the next loader - this should never raise.
20
+
21
+ If there's no sidecar this loader recognises, just return None. If there is one
22
+ but it can't be read (malformed, or perhaps in a different convention), also
23
+ append a short description of the problem to 'problems' - these are only shown
24
+ to the user if no loader manages to read the file, so that a file in another
25
+ loader's convention doesn't produce spurious warnings."""
26
+ pass
27
+
28
+
29
+ # this is a list of sidecar loaders - each is processed in order, and the first one
30
+ # that returns a set of data wins.
31
+ LOADERS: List[MultifileSidecarLoader] = []
32
+
33
+ def add_multifile_sidecar_loader(loader: MultifileSidecarLoader, first: bool = False):
34
+ """Adds a multifile sidecar loader to the list of loaders. The first
35
+ loader to successfully load data wins. Loaders are normally added to the end of
36
+ the list, so built-in loaders (registered before plugins) are tried first. Set
37
+ 'first' to add the loader at the start instead - for example, a plugin loader for
38
+ a newer convention which a built-in loader would also (wrongly) read successfully.
39
+ If several loaders are added with 'first', the most recently added is tried first."""
40
+ if loader not in LOADERS:
41
+ if first:
42
+ LOADERS.insert(0, loader)
43
+ else:
44
+ LOADERS.append(loader)
45
+
46
+
47
+ def multifile_loader(path:Path) -> Dict[str, Any]:
48
+ """Given the path of a file being loaded into a multifile image band,
49
+ try all the loaders to see if we can find a suitable sidecar file"""
50
+
51
+ problems = []
52
+ for x in LOADERS:
53
+ try:
54
+ data = x.attempt_load(path, problems)
55
+ except Exception as e:
56
+ # loaders shouldn't raise, but a buggy one (perhaps from a plugin) mustn't
57
+ # stop the image itself from loading.
58
+ logger.exception(f"sidecar loader {type(x).__name__} raised an exception for {path}")
59
+ problems.append(f"{type(x).__name__}: unexpected error: {e}")
60
+ continue
61
+ if data is not None:
62
+ return data
63
+
64
+ if problems:
65
+ ui.log(f"Could not read ancillary data for {path}: a sidecar file was found but no loader could "
66
+ f"read it - it may be malformed, or in a convention no loader recognises yet. "
67
+ f"Problems: {'; '.join(problems)}", loglevel=logging.WARNING)
68
+ # otherwise return an empty dict, no extra data was found.
69
+ return {}
pcot/app.py ADDED
@@ -0,0 +1,120 @@
1
+ """
2
+ This is the file which creates and runs the PCOT user interface
3
+ """
4
+ import os
5
+ from pathlib import Path
6
+
7
+ from PySide6 import QtWidgets
8
+ from PySide6.QtCore import QCommandLineParser, QCommandLineOption
9
+ import logging
10
+ import os
11
+ import getpass
12
+ import sys
13
+
14
+ import pcot.config
15
+ import pcot.ui.mainwindow
16
+ from pcot.document import Document
17
+ from pcot.ui import collapser
18
+
19
+ logger = logging.getLogger(__name__)
20
+
21
+ app = None
22
+
23
+ def setup_qt_platform():
24
+ # only bother with this check on Linux.
25
+ if not sys.platform.lower().startswith('linux'):
26
+ return
27
+
28
+ uid = os.getuid()
29
+ wayland_socket = f"/run/user/{uid}/wayland-0"
30
+ has_display = bool(os.environ.get("DISPLAY"))
31
+ has_wayland = bool(os.environ.get("WAYLAND_DISPLAY"))
32
+
33
+ # No X11. Maybe headless, but need to check Wayland
34
+ if not has_display:
35
+ if has_wayland:
36
+ # Wayland but no socket; that's no good.
37
+ if not os.path.exists(wayland_socket):
38
+ os.environ["QT_QPA_PLATFORM"] = "offscreen"
39
+ return
40
+ else:
41
+ # No X11 and no Wayland - definitely headless
42
+ os.environ["QT_QPA_PLATFORM"] = "offscreen"
43
+ return
44
+
45
+ # We have a working display. GNOME under Wayland fails to give Qt dialogs a
46
+ # server-side decoration (they render borderless and can overlap the main
47
+ # window - see PYSIDE6_MIGRATION_TODO.md), which forcing XWayland works around.
48
+ # Let the config override this since it's only confirmed on GNOME so far.
49
+ override = pcot.config.data.qt_platform if pcot.config.data is not None else "auto"
50
+ if override == "xcb":
51
+ os.environ["QT_QPA_PLATFORM"] = "xcb"
52
+ elif override == "auto" and not has_display and has_wayland:
53
+ desktop = os.environ.get("XDG_CURRENT_DESKTOP", "").lower()
54
+ if "gnome" in desktop:
55
+ os.environ["QT_QPA_PLATFORM"] = "xcb"
56
+
57
+ def checkApp():
58
+ """Makes sure an app exists - we can't run certain code without one, and we often
59
+ won't have one if we're not using a GUI. Note that the UI package also stores this
60
+ if we are running the PCOT program."""
61
+
62
+ setup_qt_platform()
63
+
64
+ global app
65
+ if app is None:
66
+ app = QtWidgets.QApplication()
67
+
68
+
69
+ def run(file):
70
+ """the main function: loads any file specified, opens a mainwindow and runs its code.
71
+ Command line parsing is done in main, which calls this."""
72
+
73
+ global app
74
+
75
+ setup_qt_platform()
76
+
77
+ # note that we don't use Qt to process the args. This is just so Qt could
78
+ # potentially use its internal arguments.
79
+ app = QtWidgets.QApplication(sys.argv)
80
+ if sys.platform.lower().startswith('win'):
81
+ # Qt 6.7+ defaults to the "Windows11" style on Windows 11, which uses wider
82
+ # side-by-side spin box buttons instead of the old compact stacked arrows.
83
+ # Fusion keeps the compact spin boxes, and unlike "windowsvista" (which is
84
+ # light-only) it is palette-driven, so it can follow the system dark mode.
85
+ # macOS and Linux use their own native/Fusion styles and are unaffected by
86
+ # this, so leave them be.
87
+ app.setStyle("fusion")
88
+ app.setApplicationVersion(pcot.__fullversion__) # this comes from the VERSION.txt file
89
+ app.setApplicationName("PCOT")
90
+ app.setOrganizationName('Aberystwyth University')
91
+ app.setOrganizationDomain('aber.ac.uk')
92
+ pcot.ui.setApp(app)
93
+
94
+ pcot.config.main_app_running = True
95
+ pcot.setup()
96
+
97
+ # create a document either ab initio or from a file, depending on file and config.
98
+ if file is not None:
99
+ path = Path(file)
100
+ if not path.is_file() or path.suffix != ".pcot":
101
+ logger.error(f"'{file}' is not a PCOT file or subcommand - type 'pcot -h' for help")
102
+ sys.exit(1)
103
+ else:
104
+ doc = Document(file)
105
+ else:
106
+ loadfile = pcot.config.data.loadfile
107
+ if loadfile and loadfile != "" and loadfile != ".": # "." because it's a Path which can't be empty
108
+ doc = Document(os.path.expanduser(loadfile))
109
+ else:
110
+ doc = Document()
111
+ doc.importFromConfigArchives() # import faves and macros from files in the config settings
112
+
113
+ # Create an instance of a main window on that document
114
+ # Autolayout not done by default - the user might have arranged things how they like.
115
+ window = pcot.ui.mainwindow.MainUI(doc, doAutoLayout=False)
116
+
117
+ # run the application until exit
118
+ app.exec()
119
+ logger.info("Leaving app")
120
+ pcot.config.save()
@@ -0,0 +1,42 @@
1
+ """
2
+ This package handles and contains assets, usually strings but some binaries.
3
+ """
4
+ import importlib
5
+ import importlib.resources
6
+ import pkgutil
7
+
8
+ from PySide6.QtGui import QIcon
9
+
10
+ from pcot.ui.theme import isDarkMode
11
+
12
+
13
+ def getAssetAsString(fn, package="pcot.assets"):
14
+ """Find a file in the assets package and return its contents as a string, assuming it is utf-8 encoded"""
15
+ s = pkgutil.get_data(package, fn)
16
+ if s is None:
17
+ raise ValueError(f'cannot find asset {fn}')
18
+ return s.decode('utf-8')
19
+
20
+
21
+ def getAssetPath(fn, package="pcot.assets"):
22
+ """Find a file in the assets package and return its path. The file may be in a
23
+ subdirectory of the package, in which case use '/' to separate path components
24
+ (regardless of platform)."""
25
+ resource = importlib.resources.files(package)
26
+ for part in fn.split('/'):
27
+ resource = resource / part
28
+ with importlib.resources.as_file(resource) as p:
29
+ return p
30
+
31
+
32
+ class Icons:
33
+ icons = {}
34
+ @classmethod
35
+ def get(cls, name):
36
+ if isDarkMode():
37
+ name = name + "-darkmode"
38
+
39
+ if name not in cls.icons:
40
+ icon = QIcon(str(getAssetPath("icons/" + name + ".svg")))
41
+ cls.icons[name] = icon
42
+ return cls.icons[name]