Docstrings, documentation, unit tests, bug fixes, and refactors#31
Merged
Conversation
Deployed three sub-agents on the dev branch to improve documentation, test coverage, and code quality: Docstrings (docstrings-only; executable code verified byte-identical to master via AST comparison, and the full test suite passes): - Added NumPy-style docstrings so all 163 functions/classes across dynspec.py, scint_models.py, scint_sim.py, scint_utils.py, and ththmod.py are documented, plus module-level docstrings for each. Online documentation (docs/source): - Rewrote the placeholder dynspec.rst and simulation.rst pages with real usage examples drawn from the example notebooks. - Reconciled scint_models.rst and scint_utils.rst signatures with the code (e.g. thin_screen -> veff_thin_screen; removed stale entries; fixed default values and parameter types). Unit tests (tests/): - New pytest suite (conftest.py + four test modules) covering pure, deterministic functions in scint_utils, scint_models, ththmod, and scint_sim. Result: 58 passed, 2 xfailed. - The 2 xfails flag genuine bugs (np.complex_ removed in NumPy 2.0 breaks the ACF class; arc_power_curve is an unfinished stub). Code review (CODE_REVIEW.md): - Read-only review reporting 10 confirmed bugs and 5 suspected issues, plus refactoring opportunities and deprecation notes. No source fixes were applied; the report is left for maintainer review. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EG6cv3jHNLYv1TN2YWDqi3
Update the documented ACF class signature and methods in acf.rst to match the actual scint_sim.ACF implementation. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EG6cv3jHNLYv1TN2YWDqi3
Fixes all 10 confirmed bugs from CODE_REVIEW.md, plus 4 of the 5 plausible issues and the plt.colorbar no-op. No refactors applied. scint_sim.py: - Replace np.complex_ (removed in NumPy 2.0) with np.complex128 in ACF.calc_acf, unblocking the ACF class and the analytic 2D ACF fit. - Add missing parentheses to plt.colorbar() in plot_pulse. dynspec.py: - fit_arc: coerce constraint to a float ndarray so the default constraint=[0, np.inf] no longer raises TypeError in the non-lamsteps path. - SimDyn.__init__: set header from the simulation name instead of reading self.header before it exists. - get_scint_params: fix copy/paste slip that set tmin/tmax (with a frequency count) instead of fmin/fmax in the frequency-overflow crop branch. - BasicDyn: replace mutable default arguments with None and guard on len(...) instead of .size (which failed on list defaults); also use self.dt (not the raw dt arg) when deriving tobs. - MatlabDyn: catch KeyError (not NameError) for missing mat-file variables. - calc_sspec: check the real cache attribute (trapdyn, not trap). - plot_dyn: restore the nonzero-pixel filter in the intensity-scaling mask. - norm_sspec: apply masklin (not mask) to the logsteps linear spectrum. - Use np.longdouble instead of the non-portable np.float128. scint_models.py: - tau_sspec_model/dnu_sspec_model: accept an optional weights argument so scint_sspec_model no longer raises TypeError. - arc_power_curve: raise NotImplementedError instead of silently returning broken residuals from an empty model. - effective_velocity_annual: raise KeyError when no inclination parameter is supplied instead of hitting a later NameError on INC. - tau_acf_model/dnu_acf_model: copy weights before zeroing the first element so the caller's array is not mutated. scint_utils.py: - Use np.longdouble instead of np.float128. Deliberately left unchanged: the scint_velocity error-propagation term is a scientific formula needing domain confirmation; flagged in CODE_REVIEW.md. tests/: - Convert the two previously-xfailed tests (ACF, arc_power_curve) to passing tests, and add regression tests (test_dynspec.py plus new cases in test_scint_models.py) covering the fixes. Full suite: 67 passed. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EG6cv3jHNLYv1TN2YWDqi3
Refactoring opportunities from CODE_REVIEW.md, all behaviour-preserving (verified by imports, the unit suite, and bit-for-bit output comparison against captured baselines for the untested mosaic functions): - Consolidate the duplicated svd_model: add a shared svd_reconstruct core in scint_utils and have both scint_utils.svd_model and ththmod.svd_model use it. - Extract the ~6x copy-pasted mosaic weighting block in ththmod.py into a single chunk_mask() helper (mosaic, rotMos, rotInit, rotDer, fullMos, fullMosGrad, fullMosHess). Output verified bit-identical. - Replace the inline window construction in dynspec.scale_dyn with the existing scint_utils.get_window. - Centralize the repeated c = 299792458.0 literal onto scipy.constants.c (dynspec.py x4, scint_sim.py x1). - Remove the large commented-out sspec-method implementation block in get_scint_params (keeping the "not implemented" branch behaviour). New bug found while refactoring and fixed: - slow_FT called np.fft.fftshift(SS, axis=0); the numpy kwarg is `axes`, so the function raised TypeError on every call. Fixed to axes=0, and made the hard-coded mid-band reference frequency an optional fref parameter (default preserves previous behaviour). Deliberately left as-is (documented in CODE_REVIEW.md): the long scientific functions were not decomposed (untested core; risky without characterization tests), calc_scattered_image's fill was not merged into interp_nan_2d (different masking semantics), scint_velocity's error term (needs domain review), trim_edges' unused remove_short_sub (documented as reserved to avoid an API break), and make_dynspec (documented placeholder). Adds regression tests for svd_reconstruct/svd_model, chunk_mask, and slow_FT. Full suite: 74 passed. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EG6cv3jHNLYv1TN2YWDqi3
Add a "Test with pytest" step to the python-package workflow so the unit test suite under tests/ runs on every push and pull request, across the Python 3.8-3.10 matrix, in addition to the existing flake8 checks. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EG6cv3jHNLYv1TN2YWDqi3
The pytest step failed at collection with "No module named 'scintools'": CI installed the dependencies but never the package itself, and `pytest tests/` (unlike `python -m pytest`) does not put the repo root on sys.path. Install the package in editable mode (pip install -e .) and invoke the suite as `python -m pytest tests/` so imports resolve on the 3.8-3.10 matrix. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EG6cv3jHNLYv1TN2YWDqi3
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.
Overview
This PR improves documentation, test coverage, and code quality across
scintools, then fixes the bugs surfaced by the review and applies safe refactors. Work was done on thedevbranch across four commits.Documentation
master.docs/source/): rewrote the placeholderdynspec.rstandsimulation.rstpages with real, runnable examples drawn from the example notebooks; filled inacf.rst; and reconciledscint_models.rst/scint_utils.rst/acf.rstsignatures with the actual code (e.g.thin_screen→veff_thin_screen, corrected the staleACFsignature, fixed wrong defaults/types, removed stale entries).Tests
pytestsuite undertests/covering the pure/deterministic functions inscint_utils,scint_models,ththmod,scint_sim, and thedynspecwrapper classes. 74 passing.Bug fixes
Fixes all 10 confirmed bugs from the review (see
CODE_REVIEW.md), plus 4 plausible issues and aplt.colorbarno-op. Highlights:np.complex_(removed in NumPy 2.0) →np.complex128, which unblocks the entireACFclass and the analytic 2D ACF fit path.fit_arcno longer crashes withTypeErrorin its default mode (list-vs-float division onconstraint).SimDyn.__init__no longer raisesAttributeError(self.header = self.header).get_scint_params2D-crop copy/paste slip (tmin/tmax→fmin/fmax).BasicDynmutable defaults /.size-on-list;MatlabDynexcept NameError→KeyError;calc_sspecwrong cache attribute;plot_dynmask;norm_sspeclogsteps mask; in-place weight mutation;np.float128→np.longdouble.slow_FTcallednp.fft.fftshift(SS, axis=0)— numpy's kwarg isaxes, so it raisedTypeErroron every call. Fixed, and made the mid-band reference frequency an optionalfrefparameter.Refactors
All behavior-preserving (verified by imports, the test suite, and bit-for-bit output comparison against captured baselines for the untested mosaic code):
svd_modelonto a sharedsvd_reconstructcore.ththmod.pyinto a singlechunk_maskhelper (output verified bit-identical across all 9 affected functions).scale_dynnow reusesget_window; centralized thec = 299792458.0literal ontoscipy.constants.c; removed a large commented-out dead block.Deliberately left for maintainer review (documented in
CODE_REVIEW.md)scint_velocityerror-propagation term (scientific formula needing domain confirmation).get_scint_params,fit_arc,norm_sspec,ACF.calc_acf) — deferred until characterization tests exist, to avoid silently altering the untested scientific core.calc_scattered_imagefill not merged intointerp_nan_2d(different masking semantics);trim_edges' unusedremove_short_subdocumented as reserved rather than dropped (avoids an API break);make_dynspecplaceholder left in place.🤖 Generated with Claude Code
Generated by Claude Code