Skip to content

Centralise configuration, sample naming and Origin connection - #2

Open
jongsu-king wants to merge 1 commit into
claude/code-improvement-g67yx6from
main
Open

Centralise configuration, sample naming and Origin connection#2
jongsu-king wants to merge 1 commit into
claude/code-improvement-g67yx6from
main

Conversation

@jongsu-king

@jongsu-king jongsu-king commented Aug 6, 2026

Copy link
Copy Markdown
Owner

Centralise configuration, sample naming and Origin connectionSeven modules each re-derived the location of physisfera_config.json from their own __file__ with a hand-counted chain of .., and read the file independently. This consolidates that into one reader, and fixes the three defects the duplication was hiding.

Bug fixes

cell_area_cm2 was frozen at import time. scripts/JV/jv_core.py and scripts/Dark_JV/dark_jv_core.py captured the device area into a module constant when the module was first imported. The area scales Jsc — and therefore PCE — linearly, so correcting it in the config did nothing until the whole application was restarted. It is now read when the analysis runs, and parse_* / process_* accept an explicit area_cm2 for callers that want to pass one. A missing, zero, negative or unparseable value falls back to the documented 0.04 instead of producing an infinite conversion factor.

The XRD/PL panels could never find a configured API key. spectra/gui/tab_dashboard.py and spectra/gui/tab_pl.py counted one .. too many and looked one directory above the project root. The same bug had already been fixed in spectra/core/report.py; these two copies were missed.

Installing the package produced two empty namespaces. [tool.setuptools] packages listed only scripts and spectra, excluding all twelve subpackages, so every from scripts.JV.jv_core import ... failed after an install. Switched to discovery (15 packages) and declared the bundled ASTM G173-03 spectrum as package data.

Deduplication

New scripts/common/ modules:

  • app_config.py — the single reader/writer for physisfera_config.json. Caches on mtime so an edit is picked up without a restart, resolves the frozen-build path to the config next to the executable rather than into the unpacked bundle, honours PHYSISCORE_CONFIG, and writes atomically while preserving keys owned by other modules.
  • origin.pyconnect_to_origin, previously six near-identical copies. They differed only in log wording and a 30 s vs 60 s timeout, and each swallowed every exception from the minute-long wait loop with a bare except: — which catches KeyboardInterrupt, so Ctrl-C during the wait was ignored.
  • naming.pynatural_sort_key and the sample display-name rules, duplicated between the light and dark J-V parsers. Both scan types of one device now provably get the same label.

Performance

Both ALS baselines rebuilt their difference matrix in a format spsolve had to convert on every iteration. The operator is now hoisted out of the loop and built as CSC. This removes 32 of the 33 warnings the suite emitted; the last was a LabTalk \g being read as a Python escape.

Tests

35 new tests covering config resolution, the cell-area plumbing and the naming rules.

The 55 pre-existing tests are unchanged and still pass. GUI modules can't be imported in a headless environment, so intra-project imports and cross-module attribute access were checked statically via AST instead — no dangling references.

Notes for review

  • spectra now imports from scripts.common, which it did not before. Both ship in the same distribution, and one config reader seemed worth the new edge.
  • _legacy/ carries the same kind of duplication but was left alone as explicitly archived code.
  • Behaviour change worth flagging: a config edit now takes effect on the next analysis rather than the next application start. CONFIG.md and README.md are updated to say so.

Centralise configuration, sample naming and Origin connection
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant