API cleanup #631
d-chambers
started this conversation in
Ideas
API cleanup
#631
Replies: 1 comment
Follow-up discussion: DASDAE scan/index still does too much conversion between flat index rows and PatchSummary.Current pain point:
Possible cleanup:
Goal: Once we’re out of Plan mode, I can post that as a PR comment directly. |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
DASCore API Cleanup Plan
(This was an API review by Claude)
Critical Issues
1.
updatename collision between Patch and Spoolpatch.update()creates a new copy with modified fields;spool.update()re-scans the index. These are completely different operations sharing the same name. Sincespool.update()is an IO side-effecting operation, consider renaming it tospool.refresh()orspool.rescan()to make the asymmetry clear.2. The
dimvs**kwargspattern is applied inconsistentlyThe library has two patterns for specifying which dimension to operate on:
**kwargsstyle:pass_filter(time=(1, 100)),pad(time=5),median_filter(time=0.1)dim=style:detrend(dim="time"),normalize(dim="time"),sobel_filter(dim="time")The implicit rule seems to be: use
**kwargswhen a per-dimension value accompanies the dimension name, and usedim=when only the dimension name is needed. Butsobel_filterbreaks this — it uses explicitdim=despite taking extra parameters (mode,cval) just likemedian_filter. Auditing allproc/andtransform/functions and enforcing a consistent rule would reduce cognitive load.3. Too many ways to access coordinate data
Since
BaseCoordimplements__array__, the transition fromcoords[name]returning an ndarray to returning aBaseCoordis not actually a breakage for normal use — numpy operations will work transparently. However, the proliferation of access paths is still worth rationalizing:The preferred public interface should be clearly documented as
patch.get_coord()(for the coord object) andpatch.get_array()(for raw data), withcoords[name]andcoords.coord_maptreated as internal/advanced access.Moderate Issues
4.
detrend(dim, type=...)shadows Python builtinRename
typetodetrend_typeormethod(consistent with scipy/MNE conventions). The builtin shadowing also confuses static analyzers.5. No
patch.copy()orpatch.astype(dtype)Copying a patch requires
patch.update()with no arguments, which is unintuitive.patch.copy()is a one-liner to add. Similarly, there's nopatch.astype(float32)— forcing users to dopatch.update(data=patch.data.astype(float32)).6.
patch.rolling()is the only method that doesn't return a PatchEvery other Patch method returns a Patch or a scalar, but
rolling()returns a roller object. This breaks the fluent chain unexpectedly. The docstring should prominently call this out. Alternatively, the most common uses (.mean(),.std(),.median()) could be provided as direct methods:patch.rolling_mean(dim, window).7.
experiment_idvsacquisition_idmismatchPatchAttrsusesacquisition_idbutPatchFileSummary(the IO index model) usesexperiment_idfor the same concept. Pick one.8.
dft(dims, ...)accepts a sequence, but most functions usedim(singular)This inconsistency in parameter naming (
dimvsdims) is confusing when scanning function signatures. At minimum, document thatdftaccepts multiple dims; at best, unify the naming.Minor / Polish Issues
9.
patch.viz.spectrogramvs deprecatedpatch.spectrogrampatch.spectrogram()(the transform) was deprecated in favor ofpatch.stft(). Butpatch.viz.spectrogram()(the visualization) is still valid. The same name doing two different things depending on namespace is a documentation hazard — make this distinction very explicit in the deprecation message.10. Missing common math UFuncs
patch.abs()works, butpatch.sqrt(),patch.sin(),patch.cos()aren't exposed. SincePatchUFunc(np.sqrt)etc. is trivial, these should be added — users doing phase/strain conversions frequently need them.11. No
patch.to_xarray()/patch.to_dataframe()exportInteroperability with the broader scientific Python ecosystem (xarray, pandas, scipy) is a common need. Even a basic
to_xarray()that maps coords →xr.DataArraywould be very useful.12. Visualization gaps
Only 4 viz functions exist. Missing:
dft)What's Working Well
spool → select → chunk → map) is elegant and composable.patch_functiondecorator pattern for registering processing steps and tracking history is a well-designed extensibility hook.CoordRangevsCoordArraydistinction is smart — it keeps memory usage low for regular DAS grids.set_units,convert_units,simplify_units) is more principled than most geophysics libraries.removed_in="0.2.0") is clean and user-friendly.Prioritized Action List
spool.update()→spool.refresh()orspool.rescan()dim=vs**kwargsrule across all proc/transform functionsget_coord()/get_array()as the preferred public coord access pathsdetrend(type=...)→detrend(method=...)patch.copy()andpatch.astype(dtype)experiment_id/acquisition_idacrossPatchAttrsandPatchFileSummarysqrt,sin,cosas UFuncspatch.to_xarray()All reactions