import dascore as dc
file_spool = dc.spool("examples://terra15_das_1_trimmed.hdf5")
patch = file_spool[0]Working with Files
DASCore reads many DAS formats and writes several; see supported formats. Paths may be local pathlib.Path objects or remote UPath resources.
Reading
Open a file with dc.spool and index the spool to load a patch. DASCore detects the format.
dc.spool(directory) opens every supported file below a directory as one lazy spool. Select and chunk first; arrays load only when you iterate or index:
directory = dc.examples.spool_to_directory(dc.get_example_spool("diverse_das"))
spool = (
dc.spool(directory)
.select(acquisition_key="DAS2.*")
.select(time=(..., "2022-01-01"))
.chunk(time=2, overlap=0.5)
)
for chunk in spool:
processed = chunk.detrend("time")The first dc.spool(directory) creates a hidden index, .dascore_index.sqlite3, which stores file metadata so selections run before data is loaded. Call spool.update() after files change; it scans new or modified files and drops deleted ones. See the spool tutorial for selecting and chunking, and the index note for the index lifecycle.
A directory may also hold an .inventory companion describing the observing system. The index and inventory use reserved hidden names, so they are never read as data.
Writing
Write a patch through Patch.io, naming the format:
from pathlib import Path
path = Path("output_file.h5")
patch.io.write(path, "DASDAE")
round_trip = dc.spool(path)[0]dc.write does the same for a patch or a spool. Remote destinations work the same way with UPath:
from upath import UPath
remote_path = UPath("memory://dascore/tutorial/output.h5")
patch.io.write(remote_path, "DASDAE")
remote_patch = dc.spool(remote_path)[0]Some formats need a local, seekable file and go through a local cache; see Working with remote patches. For compression, chunking, Zarr stores, XDAS files, and how readers grid stored coordinates, see File formats in depth.
Scanning metadata
dc.scan returns one PatchSummary per patch without loading arrays.
summary_index = 0
summary = dc.scan("examples://terra15_das_1_trimmed.hdf5")[summary_index]
print(summary.source_path)
print(summary.get_coord_summary("time").min)/home/runner/work/dascore/dascore/.test_data_cache/0.0.0/terra15_das_1_trimmed.hdf5
2021-10-11T22:43:37.380047104
Summaries also report source_format, source_version, and source_patch_key, which identify the formatter and the patch inside a multi-patch file. dc.scan_to_df returns the same information as a dataframe.
Scan results and file-spool rows share one order, so a summary’s position loads the same patch:
source_spool = dc.spool(
summary.source_path,
file_format=summary.source_format,
file_version=summary.source_version,
)
loaded = source_spool[summary_index]dc.scan_payloads returns PatchMeta objects instead: patch metadata without the data, with full coordinates. With snap=False, formats that store per-sample coordinates expose their exact values. Payload scans may read large coordinate arrays, so reserve them for targeted files.
payload = dc.scan_payloads(summary.source_path, snap=False)[0]
time = payload.coords.get_coord("time")External formats
Patch.io also converts patches to structures used by pandas, xarray, and ObsPy. See the external conversion recipe.