Conversation
There was a problem hiding this comment.
Pull request overview
This PR introduces pre-commit tooling and applies automated formatting/cleanup across the repository to standardize style as part of a broader refactor effort.
Changes:
- Added a
.pre-commit-config.yamland applied formatting/whitespace fixes repo-wide (Python, Markdown, Enaml, data files). - Introduced a
pixi.tomlworkspace for reproducible base/dev environments and pre-commit tasks. - Refactored multiple Python modules for import hygiene and style consistency (notably
xfuncs.py, attenuator/transfocator utilities, and pv_explorer).
Reviewed changes
Copilot reviewed 21 out of 60 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| versioneer.py | Formatting-only changes to Versioneer helper (strings, spacing). |
| setup.py | Formatting; still reads README via bare open().read(). |
| requirements_backup.txt | Reordered dependency line (eiger-io). |
| README.md | Converted header to Markdown # style and reflowed text. |
| pixi.toml | Added Pixi workspace + base/terminal/dev dependencies and tasks. |
| LICENSE | EOF/whitespace normalization. |
| chxtools/xfuncs.py | Large refactor/formatting; introduces a runtime error and accidental API renames. |
| chxtools/X-ray_database/rc_Si220.dat | EOF/whitespace normalization. |
| chxtools/X-ray_database/rc_Si111.dat | EOF/whitespace normalization. |
| chxtools/X-ray_database/rc_Ge220.dat | EOF/whitespace normalization. |
| chxtools/X-ray_database/rc_Ge111.dat | EOF/whitespace normalization. |
| chxtools/X-ray_database/PhElAbsCross_Si.dat | Whitespace normalization in tabular data/comments. |
| chxtools/X-ray_database/n_W.dat | EOF/whitespace normalization. |
| chxtools/X-ray_database/n_SiO2.dat | EOF/whitespace normalization. |
| chxtools/X-ray_database/n_Si3N4.dat | EOF/whitespace normalization. |
| chxtools/X-ray_database/n_Si.dat | EOF/whitespace normalization. |
| chxtools/X-ray_database/n_Pt.dat | EOF/whitespace normalization. |
| chxtools/X-ray_database/n_protein.dat | EOF/whitespace normalization. |
| chxtools/X-ray_database/n_Pd.dat | EOF/whitespace normalization. |
| chxtools/X-ray_database/n_nucleosome.dat | EOF/whitespace normalization. |
| chxtools/X-ray_database/n_mica.dat | EOF/whitespace normalization. |
| chxtools/X-ray_database/n_lipid.dat | EOF/whitespace normalization. |
| chxtools/X-ray_database/n_kapton.dat | EOF/whitespace normalization. |
| chxtools/X-ray_database/n_ice.dat | EOF/whitespace normalization. |
| chxtools/X-ray_database/n_Hg.dat | EOF/whitespace normalization. |
| chxtools/X-ray_database/n_H2O.dat | EOF/whitespace normalization. |
| chxtools/X-ray_database/n_dna.dat | EOF/whitespace normalization. |
| chxtools/X-ray_database/n_diamond.dat | EOF/whitespace normalization. |
| chxtools/X-ray_database/n_Cu.dat | EOF/whitespace normalization. |
| chxtools/X-ray_database/n_C.dat | EOF/whitespace normalization. |
| chxtools/X-ray_database/n_C_test.dat | EOF/whitespace normalization. |
| chxtools/X-ray_database/n_Be.dat | EOF/whitespace normalization. |
| chxtools/X-ray_database/n_Au.dat | EOF/whitespace normalization. |
| chxtools/X-ray_database/n_Al.dat | EOF/whitespace normalization. |
| chxtools/X-ray_database/n_Ag.dat | EOF/whitespace normalization. |
| chxtools/X-ray_database/mu_Si3N4.dat | EOF/whitespace normalization. |
| chxtools/X-ray_database/mu_Si.dat | EOF/whitespace normalization. |
| chxtools/X-ray_database/mu_Be.dat | EOF/whitespace normalization. |
| chxtools/X-ray_database/id_CHX_IVU20_10042016.dat | Whitespace cleanup in header comments. |
| chxtools/X-ray_database/id_CHX_IVU20_06062016.dat | Whitespace cleanup in header comments. |
| chxtools/X-ray_database/id_CHX_IVU20_05272017.dat | Whitespace cleanup in header comments. |
| chxtools/X-ray_database/id_CHX_IVU20_03222016.dat | Whitespace cleanup in header comments. |
| chxtools/X-ray_database/id_CHX_IVU20_03182016.dat | Whitespace cleanup in header comments. |
| chxtools/X-ray_database/id_CHX_IVU20_01162017.dat | Whitespace cleanup in header comments. |
| chxtools/transfuncs.py | Import tightening + formatting; minor docstring/spelling fixes. |
| chxtools/pv_explorer/view.enaml | Trailing blank line removal. |
| chxtools/pv_explorer/run.py | Formatting and import wrapping cleanup. |
| chxtools/pv_explorer/model.py | Replace import * with explicit atom imports; formatting updates. |
| chxtools/pv_explorer/init.py | Quote normalization. |
| chxtools/plot_sid.py | Docstring + formatting cleanup; removed unused import. |
| chxtools/handlers.py | Formatting and string literal normalization; import cleanup. |
| chxtools/chx_wrapper.py | Formatting and exception handling cleanup; explicit pyepics import. |
| chxtools/bpm_stability.py | Formatting/refactor; introduces metadata key mismatch that will crash plotting. |
| chxtools/attfuncs2.py | Formatting, import cleanup, and docstring/comment normalization. |
| chxtools/attfuncs.py | Formatting, import cleanup, and safer comparisons; still heavy PV usage. |
| chxtools/_version.py | Formatting-only changes to generated Versioneer output. |
| chxtools/init.py | Quote normalization and minor formatting. |
| .pre-commit-config.yaml | Added pre-commit hook set (ruff/blacken-docs/prettier/typos/etc.). |
| .gitignore | Fixed spelling in comment (“documentation”). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| else: | ||
| ( | ||
| print( | ||
| "error: energy " | ||
| + "%3.4f" % E | ||
| + "[keV] out of range (" | ||
| + "%3.4f" % np.min(m[:, 0] / 1000) | ||
| ) | ||
| + "=<E<=" | ||
| + "%3.4f" % np.max(m[:, 0] / 1000) | ||
| + "keV)" | ||
| ) |
There was a problem hiding this comment.
In get_mu(), the out-of-range branch wraps a print() call in parentheses and then concatenates strings onto its return value (None). This will raise a TypeError when the energy is out of range, instead of printing the message. Build the full error string first and print it (or raise an exception) without attempting to add to the print() result.
| meta_pvdict = dict( | ||
|
|
||
| pv_Px = 'XF:11IDB-BI{XBPM:02}Fdbk:AKp-SP', | ||
| pv_Ix = 'XF:11IDB-BI{XBPM:02}Fdbk:AKi-SP', | ||
| pv_Dx = 'XF:11IDB-BI{XBPM:02}Fdbk:AKd-SP', | ||
| pv_fdx= 'XF:11IDB-BI{XBPM:02}Fdbk:AEn-SP', | ||
| pv_sklx= 'XF:11IDB-BI{XBPM:02}Fdbk:ACtrlScaleFactor-SP', | ||
| pv_Kx = 'XF:11IDB-BI{XBPM:02}Pos:Kx-SP', | ||
|
|
||
| pv_Py = 'XF:11IDB-BI{XBPM:02}Fdbk:BKp-SP', | ||
| pv_Iy = 'XF:11IDB-BI{XBPM:02}Fdbk:BKi-SP', | ||
| pv_Dy = 'XF:11IDB-BI{XBPM:02}Fdbk:BKd-SP', | ||
| pv_fdy= 'XF:11IDB-BI{XBPM:02}Fdbk:BEn-SP', | ||
| pv_skly= 'XF:11IDB-BI{XBPM:02}Fdbk:BCtrlScaleFactor-SP', | ||
| pv_Ky = 'XF:11IDB-BI{XBPM:02}Pos:Ky-SP', | ||
|
|
||
| pv_fdHz = 'XF:11IDB-BI{XBPM:02}Fdbk:delT-I', | ||
| ) | ||
| pv_Px="XF:11IDB-BI{XBPM:02}Fdbk:AKp-SP", | ||
| pv_Ix="XF:11IDB-BI{XBPM:02}Fdbk:AKi-SP", | ||
| pv_Dx="XF:11IDB-BI{XBPM:02}Fdbk:AKd-SP", | ||
| pv_fdx="XF:11IDB-BI{XBPM:02}Fdbk:AEn-SP", | ||
| pv_sklx="XF:11IDB-BI{XBPM:02}Fdbk:ACtrlScaleFactor-SP", | ||
| pv_Kx="XF:11IDB-BI{XBPM:02}Pos:Kx-SP", | ||
| pv_Py="XF:11IDB-BI{XBPM:02}Fdbk:BKp-SP", | ||
| pv_It="XF:11IDB-BI{XBPM:02}Fdbk:BKi-SP", | ||
| pv_Dy="XF:11IDB-BI{XBPM:02}Fdbk:BKd-SP", | ||
| pv_fdy="XF:11IDB-BI{XBPM:02}Fdbk:BEn-SP", | ||
| pv_skly="XF:11IDB-BI{XBPM:02}Fdbk:BCtrlScaleFactor-SP", | ||
| pv_Ky="XF:11IDB-BI{XBPM:02}Pos:Ky-SP", | ||
| pv_fdHz="XF:11IDB-BI{XBPM:02}Fdbk:delT-I", | ||
| ) |
There was a problem hiding this comment.
meta_pvdict defines the Y integral gain key as "pv_It", but plot_posxy_fft() looks up metadata["pv_Iy"] (via "pv_I%s" % pp when pp="y"). This will cause a KeyError at runtime. Rename the dict key to pv_Iy (or update the lookup logic) so the metadata keys are consistent.
| def get_Game(Qz, alpha_i=0.12, E=8): | ||
| hlpstr = "by sof 01/12/2003 Returns the angle Gamma (out-of-plane angle in GIXD) defined in terms of Qz, the incident angle and the energy of the X-Ray beam. Type getGame(Qz [1/A], Incident Angle [deg] (default: 0.12deg) , E[keV] (default:8keV)), This function is vector compatible. Type get_Game('?') for help" | ||
| if Qz == "?": | ||
| print(hlpstr) | ||
| else: | ||
| Qz=np.array(Qz);alpha_i=np.array(alpha_i);E=np.array(E) | ||
| lam=get_Lambda(E,'A') | ||
| return np.degrees(lam*Qz/(2*np.pi)-np.sin(alpha_i)) | ||
|
|
||
| def get_Qll(Ty,alpha_i=.12,d=1000,E=8): | ||
| hlpstr="LW 26-01-2005 Function returns the parallel wavevector transfer in GI-XPCS geometry [cm^-1]. Type: get_Qll(Ty[mm],alpha_i[deg] (default: 0.12deg), d [mm] (default: 1000mm),E[keV] (default:8keV))=>qll[cm^-1]; type get_Qll(\'?\') for help" | ||
| if Ty=='?': | ||
| print ( hlpstr) | ||
| Qz = np.array(Qz) | ||
| alpha_i = np.array(alpha_i) | ||
| E = np.array(E) | ||
| lam = get_Lambda(E, "A") | ||
| return np.degrees(lam * Qz / (2 * np.pi) - np.sin(alpha_i)) |
There was a problem hiding this comment.
The public function name appears to have changed from get_Gam() to get_Game(). This is likely an accidental rename (the help string still references get_Game/getGame inconsistently) and is a breaking API change for callers importing get_Gam. Consider restoring the original name (or providing a backwards-compatible alias) and aligning the help string with the actual function name.
| def get_Qz(Game, alpha_i=0.12, E=8): | ||
| hlpstr = "function by sof 01/12/2003 Returns the Qz z-component of wavevector transfer defined in terms of the incident and measured angles and the energy of the X-Ray beam. Type get_Qz(Game [deg], alpha_i [deg] (default: 0.12deg), E[keV] (default: 8keV)). This function is vector compatible. Type get_Qz('?') for help." | ||
| if Game == "?": | ||
| print(hlpstr) | ||
| else: | ||
| E=np.array(E);Gam=np.deg2rad(np.array(Gam));alpha_i=np.deg2rad(np.array(alpha_i)) | ||
| lam=get_Lambda(E,'A') | ||
| return 2*np.pi*(np.sin(Gam)+np.sin(alpha_i))/lam | ||
| E = np.array(E) | ||
| Game = np.deg2rad(np.array(Game)) | ||
| alpha_i = np.deg2rad(np.array(alpha_i)) | ||
| lam = get_Lambda(E, "A") | ||
| return 2 * np.pi * (np.sin(Game) + np.sin(alpha_i)) / lam |
There was a problem hiding this comment.
Similarly, get_Qz() now takes parameter name Game instead of Gam. While positional calls still work, any keyword calls using Gam= will break, and the rename looks tied to the get_Gam/get_Game change. Consider reverting the parameter name (or supporting both via **kwargs) to preserve backwards compatibility.
| author="Brookhaven National Laboratory", | ||
| long_description=open("README.md").read(), | ||
| long_description_content_type="text/markdown", | ||
| packages=find_packages(), |
There was a problem hiding this comment.
setup.py reads README.md with open(...).read() without a context manager or explicit encoding. This can leave the file handle unclosed and may fail on systems with a non-UTF-8 default encoding. Prefer reading it via a context manager (and specify encoding="utf-8").
this PR applies pre-commit to all files to this repo in an effort to refactor the repo