Full-repo audit and cleanup: correctness, efficiency, redundancy, docstrings, static typing - #132
Merged
Merged
Conversation
almilder
force-pushed
the
pr-4-audit-cleanup
branch
from
August 25, 2026 14:44
5557786 to
9a9ae8e
Compare
almilder
force-pushed
the
pr-4-audit-cleanup
branch
from
August 26, 2026 14:44
9a9ae8e to
4e5aa93
Compare
almilder
force-pushed
the
pr-4-audit-cleanup
branch
from
August 26, 2026 17:12
4e5aa93 to
b60c887
Compare
…strings, static typing Correctness fixes: - calc_series.py: fixed a real NameError (undefined fe_val/velocity) and a wrong-argument-count call to plot_dist in the non-angular 2D-distribution plotting branch. - loss_function.py: loss() called self.unravel_pytree, an attribute that was never assigned (only unravel_weights was ever set); loss_functionals() raised an opaque UnboundLocalError for an unrecognized loss_method instead of a clear ValueError. - warpcorr.py: added a clear NotImplementedError for non-EPW instruments instead of a silent crash. - distribution_functions/base.py: calc_moment now raises a clear error for unsupported distribution-function shapes instead of returning an unbound variable. - load_ts_data.py: fixed two invalid \m escape sequences in axis-label strings. Efficiency improvements: - loss_function.py: removed a duplicate forward-model call in calc_loss, vectorized calculate_covariance_matrix with vmap instead of an unrolled Python loop. - form_factor.py: cached the Z-prime table disk reads instead of reloading them on every FormFactor construction. - postprocess.py / calc_series.py: hoisted ThomsonScatteringDiagnostic construction out of per-batch/per-iteration loops. - warpcorr.py: vectorized the pixel-by-pixel dewarping loop (up to ~1M iterations per shot) using np.add.at-based scatter-accumulation; verified byte-exact against the original loop-based implementation on real shot data. - correct_throughput.py: replaced a tile+transpose allocation with plain broadcasting, and a cell-by-cell xlrd read loop with vectorized col_values calls; also drops the deprecated numpy.matlib.repmat import. Both verified exact-match against the originals. Redundancy / simplification: - generate_spectra.py: consolidated ion_spectrum/electron_spectrum and their _detailed counterparts around shared core methods; verified bit-exact against the pristine pre-refactor implementation on both the fast and detailed paths. - plotters.py: factored detailed_lineouts's duplicated worst/best plotting blocks into a shared helper, fixing a real bug uncovered in the process (the "worst" block never set the ion subplot's y-limit due to a copy-paste slip); factored the duplicated white-transition colormap construction. - example_plot.py: deleted -- never functional as written, and nothing referenced it beyond a stale auto-generated docs stub. - edf_movie.py: replaced a hardcoded personal file path with a documented, editable constant. Docstrings: added missing public function/method docstrings across the touched modules, and module-level docstrings to every file in the package that lacked one. Documentation: docs/source/getting_started.rst now documents the standalone postprocessor runner and cluster job submission (queue_tsadar.py, the machine config field, and the required Slurm environment variables), neither of which were previously documented. Full test suite (pytest tests/) passes: 125 passed, 5 skipped, throughout.
almilder
force-pushed
the
pr-4-audit-cleanup
branch
from
August 27, 2026 13:45
b60c887 to
b293e66
Compare
launch_data_visualizer gated the background-lineout plot on config["data"] ["background"]["report_background"] with a bare dict lookup, so any config predating that field (an external deck, or one from before this PR) would raise an unhelpful bare KeyError: 'report_background' from inside prepare_data. Checks for the key explicitly first and raises with a message that says what's missing and how to fix it, matching the pattern already used by the calibration fallback's missing-key errors. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Collaborator
Author
Review summaryReviewed the full diff against
Finding
FixChecks for the key explicitly and raises with a message that says what's missing and how to fix it, instead of a bare if "report_background" not in config["data"]["background"]:
raise KeyError(
"config['data']['background'] is missing 'report_background'; add it (True/False) to your deck"
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Full-repo audit and cleanup covering correctness, efficiency, redundancy, docstrings, user-facing docs, and static-typing issues surfaced by pyright/Pylance.
Correctness fixes
Efficiency improvements
Redundancy / simplification
Docstrings
Added missing public function/method docstrings across the touched modules, and module-level docstrings to every file in the package that lacked one.
Documentation
docs/source/getting_started.rst now documents the standalone postprocessor runner and cluster job submission (queue_tsadar.py, the machine config field, and the required Slurm environment variables), neither of which were previously documented.
Test plan