Migrate to DASCore 1.0
The easiest way to migrate code written for DASCore 0.1.x is the dascore-migrate-to-v1 agent skill, which holds this guide plus the steps an agent follows. Your agent can use it directly, without DASCore 1.0 installed first; see agent onboarding.
This guide covers the changes between DASCore 0.1.24 and 1.0 which can break existing code. Most of them raise a clear error, but a few change results without one; those are marked silent below and deserve a search of your code even if it runs. See the announcement for what is new.
Summary
The sections after this summary list every change.
- Coordinates belong to coordinates.
patch.attrsno longer repeats coordinate information such astime_min,time_step, ordistance_units; usepatch.get_coord("time").min(),.step, or.units, and change coordinates withupdate_coords. Emptynetwork,station,instrument_id, andacquisition_idfields are gone. - Renamed and removed APIs.
assign_coords→update_coords,iselect→select(..., samples=True)orisel,Patch.from_parts→dc.Patch(...). Thepatch.trannamespace is gone,rfftbecomesdft(dim, real=True), andspectrogrambecomesstft.MemorySpool,DirectorySpool, andFileSpoolare replaced bydc.spool(...). - Spools. Directory indexes are SQLite files; old
.dascore_index.h5files can be deleted.Spool.selectraises on unknown keywords, andchunkcombines only patches of the same kind. - Coordinates and processing. The coordinate classes are unified behind
dc.get_coord(...). Operations that need evenly sampled data raise on coordinates with gaps; usefill_gaps,split_gaps, orsnap_coordsfirst. - Files. 0.1.x DASDAE files need an opt-in to read, 1.0 DASDAE files need
file_version="1"for 0.1.x readers, and the PICKLE format is disabled by default. Format authors implementget_version,get_metadata, andread_array; see adding a new format. - Silent changes. Coordinate fields set or read through attrs, numeric attribute units, gap merging in
chunk, label snapping indc.get_coord, glob negation,stftwindows,correlateunits,taperedges, andSpool.stacklabels.
Requirements
DASCore 1.0 raises its minimum Python, NumPy, and pandas versions; check requires-python and dependencies in pyproject.toml.
pandas 3 stores text columns as strings rather than object, which can affect code that inspects Spool.get_contents() or dc.scan_to_df() dtypes.
Removed APIs
| 0.1.x | 1.0 |
|---|---|
patch.assign_coords(...) |
patch.update_coords(...) |
patch.iselect(time=(0, 10)) |
patch.select(time=(0, 10), samples=True) or patch.isel(time=slice(0, 10)) |
patch.iresample(...) |
patch.resample(..., samples=True) |
patch.tran.* |
the same method on the patch, e.g. patch.dft(...) |
dascore.transform.rfft, patch.rfft, patch.tran.rfft |
patch.dft(dim, real=True). Silent: dft scales by the sample spacing, so its values are the old ones times the step, and it pads to a fast length unless pad=False |
patch.spectrogram(...) |
patch.stft(time=<window>, ...), which returns complex coefficients rather than the real power values spectrogram returned; take abs(...) ** 2 of the data for power |
patch.viz.spectrogram(nperseg=..., noverlap=...) |
patch.viz.spectrogram(time=<window>, overlap=...), with the same window arguments as patch.stft |
Patch.from_parts(...) |
dc.Patch(data=..., coords=..., attrs=...) |
velocity_to_strain_rate(gauge_multiple=g) |
velocity_to_strain_rate(step_multiple=2 * g); copying the value unchanged halves the gauge length |
correlate(..., lag=...) |
drop lag, which 0.1.x ignored; to restrict the output, select on its lag coordinate, e.g. out.select(lag_time=(-1, 1)) |
slope_filter(..., notch=...) |
slope_filter(..., invert=...) |
MemorySpool, DirectorySpool, FileSpool, dascore.clients |
dc.spool(...), which returns a dc.Spool |
select_kwargs |
call spool.select(...) |
spool.map(func, progress=True) |
spool.map(func); progress takes "standard", "basic", None, or False |
dascore.io.PatchFileSummary |
dc.PatchSummary |
dascore.io.indexer.DirectoryIndexer |
dc.spool(path) |
dascore.io.sintela_binary |
dascore.io.sintela (reading through dc.read is unchanged) |
dascore.utils.hdf5.PyTablesReader, HDF5Reader, HDF5Writer |
H5Reader, H5Writer; these open h5py files, so code using the PyTables node API must move to h5py |
dascore.utils.array.hash_numpy_array |
dascore.utils.array.hash_array |
to_float.register, to_int.register |
register on the private _to_float, _to_int |
dc.proc.align_patch_coords |
dascore.utils.patch.align_patch_coords |
DEFAULT_ATTRS_TO_IGNORE, PATCH_MERGE_ATTRS, attrs_to_ignore= |
the patch_kind_attrs config option; see Patch compatibility |
dascore.utils.patch.merge_patches(patches) |
dc.spool(patches).chunk(time=None) |
dascore.utils.patch.concatenate_patches(patches, time=None) |
dc.spool(patches).concatenate(time=None), which puts patches that cannot be concatenated together in separate outputs rather than skipping them |
dascore.utils.patch.get_patch_window_size, get_window_axis_step |
dascore.utils.window.resolve_window(...); .full_size() gives the window along every axis |
dascore.utils.pd.get_regex |
dascore.utils.misc.glob_to_regex, which negates a character class with [^...] rather than fnmatch’s [!...] |
dascore.utils.hdf5.unpack_scalar_h5_dataset(dataset) |
dataset[()], taking the first element of a length-one array |
dascore.utils.misc.yield_sub_sequences |
slice the sequence directly |
Attributes and coordinates
In 0.1.x, patch.attrs duplicated each coordinate’s bounds, step, and units as flat fields such as time_min and distance_step, and every patch carried empty network, station, instrument_id, and acquisition_id fields. In 1.0, attrs hold only non-coordinate metadata, the coordinates are the single source of truth, and an attribute exists only when something sets it.
| 0.1.x | 1.0 |
|---|---|
patch.attrs.time_min, patch.attrs["time_max"] |
patch.get_coord("time").min(), .max(), or patch.coords.min("time") |
patch.attrs.time_step |
patch.get_coord("time").step |
patch.attrs.distance_units |
patch.get_coord("distance").units |
patch.attrs.coords, patch.attrs.dims |
patch.coords, patch.dims |
patch.update_attrs(time_min=t) |
patch.update_coords(time_min=t) |
patch.attrs.network, station (always present, possibly empty) |
patch.attrs.get("network"); set them explicitly, or use acquisition_key |
patch.attrs.acquisition_id |
patch.attrs.acquisition_key (network.fiber_array.location.acquisition) |
patch.attrs.instrument_id |
usually patch.attrs["interrogator.serial_number"]; the Febus and OptoDAS readers report interrogator.name |
*_units companion attrs such as gauge_length_units or pulse_width_units |
gone; attrs are stored in fixed units: lengths such as gauge_length in meters, pulse_width in seconds, pulse_rate in hertz |
a pulse stated as a length, e.g. Febus pulse_width in meters |
pulse_length, in meters |
patch.attrs.flat_dump() with time_min style keys |
patch.summary.flat_dump(); patch.attrs.flat_dump() no longer includes coordinate fields |
missing numeric attrs (gauge_length, pulse_width, …) as nan |
None |
Attribute names are no longer interpreted as coordinate metadata.
patch.update_attrs(time_min=...), and the same for{dim}_maxand{dim}_step, used to change the coordinate. In 1.0 it stores an ordinary attribute, leaves the coordinate unchanged, and warns. Move these calls toupdate_coords.- Silent:
update_attrs(distance_units=...)andpatch.new(attrs={"time_min": ...})change nothing about the coordinates and do not warn. - Silent:
patch.attrs.get("time_min")returnsNone, andpatch.attrs.flat_dump()leaves coordinate fields out. - Silent: numeric attrs read from files are converted to the fixed units above, so a
pulse_widthonce stated in nanoseconds is now in seconds.
An extra attribute holds one value. An array belongs on the patch as a coordinate: patch.update_coords(name=(dims, array)).
dc.scan(path) returns PatchSummary objects rather than PatchAttrs. Read coordinate envelopes from summary.get_coord_summary("time").min, or use dc.scan_to_df(path), whose time_min style columns remain.
Spools
- Indexes. Directory indexes are now
.dascore_index.sqlite3. Old.dascore_index.h5files are no longer used and can be deleted; DASCore warns when it finds one. SQLite indexes are not supported on network filesystems with unreliable locking. updateis allowed only on the spool returned bydc.spool(path), not on one derived from it byselect,chunk, slicing, or+. Callupdate()first.- Unknown attributes.
Spool.selectraisesInvalidSpoolQueryErrorfor a keyword which is neither a coordinate nor an attribute some patch states; 0.1.x ignored unknown names and treated the standard attributes as present but empty. Checkspool.get_contents().columnsbefore selecting on an optional attribute. - Contents.
get_contents()andscan_to_df()have nopatch,history, or{dim}_dtypecolumns, and leave out attributes no patch states, such as an emptystationordata_units. Thepath,file_format, andfile_versioncolumns are nowsource_path,source_format, andsource_version. - Silent: joining.
chunkjoins two patches only where the later starts one step after the earlier ends, give or takemax_shift(0.2 of a step by default, fromdascore.config.max_shift), where 0.1.x joined any seam up totolerance=1.5steps wide. Seams 1.2 to 1.5 steps wide, and later patches more than 0.2 step off the earlier one’s grid (including overlaps half a step off it), now start a new patch. Passtolerance=1.5for the 0.1.x joining;toleranceis now off by default, a number is still a seam width in steps, and a quantity or timedelta is now the seam’s width rather than the excess over one step. Each stretch of joined patches gets one evenly sampled grid: the roundest step its files state that keeps every file’s ends withinmax_shift, else its span spread evenly as 0.1.x did, sochunk(time=...)windows rejoin exactly. Labels with no step join where they overlap or touch, and across a seam only under a quantity or timedeltatolerance.get_gapsandget_coveragetake the sametoleranceandmax_shiftand list wherechunksplits, with amissingsample count. - Silent: gaps. A
tolerancewide enough to span a gap joins the patches and spreads their labels evenly over it, as 0.1.x did, with the same warning above 1.5 steps. To keep the declared step and write the missing samples instead, fill first withSpool.fill_gaps, e.g.spool.fill_gaps(time=10).chunk(time=None);chunkitself never fills. chunk(snap_coords=...)is deprecated and ignored, with a warning:chunkalways fits one grid per stretch. UseSpool.concatenateto join patches keeping their recorded labels, andPatch.snap_coordsto regularize labels.- Kinds.
chunk,concatenate, andstackcombine only patches of the same kind, decided by thepatch_kind_attrsconfig option; patches of other kinds come out separately, andstackwarns.data_typeis no longer part of a patch’s kind, so chunking a spool which mixes, say, strain rate and velocity raisesCoordMergeError, or merges them underconflict="drop". Passgroup="data_type"to keep them apart as 0.1.x did. - Directory names. Hive-style
key=valuedirectory names become string attributes of the patches beneath them.
Coordinates
The coordinate classes were unified into one run-based NumericCoord, plus string coordinates. Build coordinates with dc.get_coord rather than a class.
| 0.1.x | 1.0 |
|---|---|
CoordRange, CoordArray, CoordMonotonicArray, CoordPartial |
NumericCoord; build with dc.get_coord(...) |
isinstance(coord, CoordRange) |
coord.evenly_sampled |
coord.limits |
(coord.min(), coord.max()) |
coord.start |
coord.values[0] |
coord.stop (exclusive, in sampling order) |
coord.values[-1] + coord.step |
coord.update_data(values) |
coord.update(values=values) |
hash(coord) |
coord.data_id |
coord.data remains as an alias of coord.values.
dc.get_coord(data=..., step=...) now places the values on the stated grid, as one grid or a segment per stretch of consecutive positions; if it does not restate every value, or the stretches pass 256, all are kept as one list of labels with no step; 0.1.x ignored the step.
Selecting samples by a mask or array (select, dropna) leaves each stretch of kept samples its own segment on the original step (past 256 segments, one list of the kept labels with no step), where 0.1.x dropped the step; Spool.concatenate keeps each patch its own segment too. A coordinate of several segments has no step, and coordinates with equal labels compare equal however they are split. differentiate, integrate, taper, sobel_filter, and filtered decimate raise CoordError on a coordinate of more than one segment, where 0.1.x computed across the gaps. Use fill_gaps or split_gaps first. One list of labels, such as irregular sensor positions or labels off a grid, is still an irregular axis these operations compute on by its labels, as in 0.1.x.
Silent: dc.get_coord(data=...) without a step reads labels exactly by default: labels within 0.1% of one spacing of a grid, which 0.1.x snapped onto it, now come back as labels with no step unless they are within two millionths of a step of a grid, which they then become. Pass snap=True for the 0.1.x result, or call snap_coords on the patch.
Processing
- Functional entry points take the patch positionally:
dc.proc.demean(patch), notdc.proc.demean(patch=patch). Patch.apply_ufunctakes the patch first:patch.apply_ufunc(np.add, other). Code callingPatch.apply_ufunc(ufunc, patch)should usedascore.utils.array.apply_ufunc.np.sort,np.argsort,np.partition, andnumpy.fftraise on patches instead of returning mislabelled coordinates. Apply them topatch.data, or usePatch.dft.- Arithmetic between patches no longer requires
data_unitsto match; attributes inpatch_kind_attrs, such astag, still must. It raisesPatchCoordinateErrorwhen a shared dimension has no overlapping values instead of returning an empty patch. Patch.orderraisesUnknownCoordinateErrorfor a coordinate the patch does not have, asselectalready did, andCoordErrorfor values (or, withsamples=True, positions) the coordinate does not hold, which 0.1.x dropped. Order only by values the coordinate holds.Patch.coords_from_dfraisesParameterErrorrather than overwrite an existing coordinate. Drop it first withdrop_coords, or set it withupdate_coords.- Silent: stack labels.
Spool.stack(dim_vary=...)keeps the first patch’s labels fordim_vary; 0.1.x relabelled it to start at zero (1970 for times). hampel_filterwithout a dimension raises instead of returning the data unchanged.Patch.rollingis deprecated in favour ofPatch.window.rolling(time=1, step=0.5).mean()iswindow(time=1, step=0.5, align="right").mean(), androlling(...).apply(func)iswindow(..., align="right").reduce(func). Withoutalign="right"a window is labelled by its middle sample, whererollinglabelled its last.rolling(center=True)is the defaultalign="center"when no step is given; with a step,rollinglabelled centred windows off their centre.- Silent: STFT.
Patch.stftplaces its windows differently, so depending on window length and overlap the outputtimevalues, and the number of windows, can differ from 0.1.x. The output also carries{dim}_startand{dim}_stopcoordinates giving each window’s edges. - Silent: correlation units.
correlatereports the square of the input data units. - Silent: taper.
taperbuilds its ramp from2n + 1samples rather than2n, changing edge values slightly. - Inventory enrichment.
Patch.enrichandSpool.enrichraisePatchErrorwhen a value the file header states disagrees with the inventory; 0.1.x kept the header value. Fix the inventory, or passenrich(conflict="keep_first")for the old behaviour ("keep_last"lets the inventory win).
Units and time
dc.to_floatraisesUnitErrorfor a dimensionless or non-time quantity; 0.1.x silently reduced it to base units, so25 MBbecame2e8. A time quantity converts to seconds. Useconvert_unitsfor other conversions.notch_filterraisesUnitErrorfor a dimensionless quantity such as20 %on a coordinate without units; 0.1.x read it as a bare number.dc.to_datetime64anddc.to_timedelta64raiseTimeOverflowErrorfor times outside the nanosecond range rather than wrapping or returningNaT.
Files
- Reading 0.1.x DASDAE files. DASDAE files written by 0.1.x store coordinate metadata as a pickle, which 1.0 does not unpickle by default, so reading, scanning, or indexing them raises
DASDAEUnpickleError. For files you trust, read them insidewith dc.config_context(allow_dasdae_format_unpickle=True):, and rewrite them once with 1.0 to drop the need. - Reading pickles. Unpickling a file can run arbitrary code, so 1.0 neither detects nor reads the PICKLE format by default.
dc.readanddc.get_formatraisePickleFormatDisabledErrorfor a DASCore pickle, and scans and directory spools skip it with a warning, whatever its extension. For files you trust, read them insidewith dc.config_context(allow_pickle_format=True):, and rewrite them as DASDAE. While the setting is on, a scan unpickles every file whose header names a DASCore patch or spool, so do not enable it for directories that may hold files from others. A directory index built with the setting off has no entries for its pickles; rebuild it after opting in.dc.get_example_patchreads a local path under your config rather than enabling any unpickling for it. - Writing DASDAE.
dc.write(..., "DASDAE")writes format version 2, which 0.1.x cannot read. Passfile_version="1"while collaborators still run 0.1.x. Version 1 cannot hold fractional steps or gaps, and 0.1.x reads theorigin_idanddata_idsuch files carry as ordinary attributes, so merging patches with different ids there needsconflict="drop". - Write options.
dc.writeraisesParameterErrorfor an option the format’s writer does not declare, rather than ignoring it. - Silent: globs. String metadata globs follow SQLite, so a character class is negated with
[^...]. The 0.1.x spelling[!...]no longer negates, and selects a different set of patches without an error. - Patch names.
get_patch_namesdefaults toacquisition_keyandtag, rather thannetwork,station, andtag, which changes the names DASCore gives patches inside files it writes.