Porting Notes For original/betagui.py¶
Python 2 To 3 Issues¶
from Tkinter import *must become Python 3tkinterimports.from tkFileDialog import *andfrom FileDialog import *are Python 2 names.printstatements use Python 2 syntax throughout.threadmodule import is Python 2 specific and appears unnecessary.- Mixed tabs and spaces are present in several blocks and may break under stricter parsing or reformatting.
- Unicode literals such as
u"\N{GREEK SMALL LETTER Xi}"are fine in Python 3 but surrounding Tk code still needs migration. - Import-time
Tk()construction is hostile to headless testing and should be delayed.
Startup Blockers¶
epicsis required at import time because PVs are created immediately..get()is called on many PVs during import, so startup depends on live EPICS connectivity.Tk()is created at import time, so import requires a display-capable Tk environment.- matplotlib is imported and configured at import time.
rc('text', usetex=True)introduces a LaTeX dependency that may fail on startup.
Required Dependencies Observed In The Original¶
- Python 2 runtime
- Tk / Tkinter
- matplotlib
- numpy
- scipy
- pyepics
- a working EPICS environment with the referenced PVs reachable
- likely a working LaTeX installation because
usetex=Trueis enabled
Suspicious Helpers¶
set_Isextupole_slowly()¶
- uses undefined name
aself - mixes PV-name and PV-object usage
- creates
pvSextupoleand never uses it - appears incomplete / stale
BPDM()¶
- intended to read BPM waveform but currently returns zeros
- GUI orbit plot is therefore not a real orbit diagnostic
set_sext_degauss()¶
- always writes
pvS1P1andpvS1P2at the end even if they are not insextlist - I did not find an active caller in the main workflow
Missing Functions / Symbols¶
setcur(...)is called instart_poly()but is not defined anywhere in the file.fine_bump_statusappears in aglobalstatement but is never defined.mea_poly_status,scan4D_status,mat_status,bump_dim,cor_option, andBbufare used as globals with implicit lifecycle inside GUI callbacks; some are only created if specific UI paths are taken.
Likely Bugs And Typos¶
- Shebang is
#!usr/bin/pythoninstead of#!/usr/bin/python. - Duplicate imports:
threading,thread, andcurve_fitare imported twice. delayMeasTuneinput is read inMeaChrom()and never used.nmeasurementsis decremented inside the RF loop, changing behavior across scan points.np.delete(fbuf[l],np.argmax(...),np.argmin(...))is not valid use ofnp.delete; third positional argument isaxis, not a second index.print 'initial rf frequency is:',frf0,' MHz'conflicts with other comments treating RF as kHz or Hz.pvOptTabis created globally, butMeaChrom()reads a freshepics.PV('MLSOPCCP:actOptRmpTblSet')instead of reusing it.if cor_option==1and flag2D3D:is valid tokenization but poor style and easy to misread.start_bump()steps sextupoles by-1and then+1from the shifted value; it does not explicitly restore the original starting current after each dimension.start_poly()referencespvS2P2, whereas main correction logic often uses split channelspvS2P2KandpvS2P2L.bumpdataS=bumpdataS-bumpdataS[-float(paras[i][1].get())-1,:]uses a float index and is almost certainly broken.ScandSdingen_scan_tab()use the minimum value for both linspace endpoints, so they do not actually scan.ndd=int(Scanentries[2][2].get())probably should use row 3 instead of row 2.- Several variables and comments use inconsistent spellings, such as
pvwhitenosie,varibales,measuremnts,coeffecient,setupoles.
Stale / Dead / Low-Confidence Code¶
- commented-out alternate tune PVs
- commented-out BPM waveform decode
set_Isextupole_slowly()looks unused and incompleteset_sext_degauss()looks unused in the main GUI path- commented-out sextupole write calls in
gen_scan_tab()indicate a half-disabled feature docsmention of a “fine bump” workflow is not matched by complete executable code
Runtime Risks¶
- import can hang or fail if PVs are unavailable
- GUI updates are performed from worker threads, which is unsafe in Tkinter
- EPICS writes are active by default from the GUI
- machine-state restoration is incomplete if a run is interrupted at the wrong point
- matrix inversion has no error handling for singular or ill-conditioned matrices
- measurement logic assumes tune and RF reads always return numeric values
- file dialogs are used deep inside worker flows, mixing user interaction and background work
- offline testing is effectively impossible in the current structure
Minimal Safe Porting Direction¶
- keep the numerical workflow and GUI layout close to the original
- move EPICS access behind a thin adapter
- delay PV creation until runtime instead of import
- make import succeed without live EPICS, Tk, or matplotlib
- preserve write-capable operations but label them clearly and keep them opt-in
- keep matrix file format simple and compatible
- isolate enough measurement logic to support mock/offline tests