Streaming¶
rddac.streaming is the offline-iteration namespace with four torch-free entry points:
iter_viewwalks a Croissant view record by record. Shares a unified index that recognises loose.h5files (rddac download --extract --remove-zip) and zipped*.ziparchives interchangeably.export_to_numpymaterialises a view as flat.npymemmap shards, with optional per-field and whole-record transforms. Requires every record to share the same shape per field.export_to_numpy_per_simwrites one.npzper experiment instead — the escape hatch for views whose raw fields have per-experiment sample counts.load_exportopens the memmap shards back as alen + getitem + iterprotocol object that plugs intotorch.utils.data.DataLoader,tf.data.Dataset.from_generator, JAX, or plain Python without any adapter.
rddac.streaming.iter_view¶
iter_view(view: str, *, source: str | Path | None = None, data_dir: str | Path | None = DEFAULT_DATA_DIR, dataset=None, sim_ids: list[int] | None = None, where: Callable[[pd.Series], bool] | None = None) -> Iterator[dict[str, np.ndarray]]
¶
Yield one record per RDDAC experiment for a Croissant view.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
view
|
str
|
Name of the RecordSet to stream (published, e.g. |
required |
source
|
str | Path | None
|
Override the Croissant manifest URL/path. |
None
|
data_dir
|
str | Path | None
|
Directory holding |
DEFAULT_DATA_DIR
|
dataset
|
A pre-loaded |
None
|
|
sim_ids
|
list[int] | None
|
Optional allowlist of experiment ids (name kept for drop-in
DDACS compatibility). Requested ids that cannot be served warn via
:class: |
None
|
where
|
Callable[[Series], bool] | None
|
Predicate applied to each |
None
|
Yields:
| Type | Description |
|---|---|
dict[str, ndarray]
|
A |
dict[str, ndarray]
|
(plus the private |
Source code in rddac/streaming.py
rddac.streaming.export_to_numpy¶
export_to_numpy(view: str, out_dir: str | Path, *, source: str | Path | None = None, data_dir: str | Path | None = DEFAULT_DATA_DIR, dataset=None, sim_ids: list[int] | None = None, where: Callable[[pd.Series], bool] | None = None, transforms: dict[str, Callable[[Any], Any]] | None = None, record_transform: Callable[[dict[str, Any]], dict[str, Any]] | None = None, show_progress: bool = False) -> dict[str, Path]
¶
Materialize a Croissant view as flat .npy memmaps on disk.
Requires every record to share the same shape per field — raw RDDAC force
and traverse tables vary per experiment, so either slice/resample them via
record_transform or use :func:export_to_numpy_per_sim. See
:func:ddacs.streaming.export_to_numpy for the full parameter reference.
Source code in rddac/streaming.py
rddac.streaming.export_to_numpy_per_sim¶
export_to_numpy_per_sim(view: str, out_dir: str | Path, *, source: str | Path | None = None, data_dir: str | Path | None = DEFAULT_DATA_DIR, dataset=None, sim_ids: list[int] | None = None, where: Callable[[pd.Series], bool] | None = None, transforms: dict[str, Callable[[Any], Any]] | None = None, record_transform: Callable[[dict[str, Any]], dict[str, Any]] | None = None, compressed: bool = False, show_progress: bool = False) -> Path
¶
Write one <experiment_id>.npz per experiment under out_dir.
Same pipeline as :func:export_to_numpy but fields may have
experiment-dependent shapes (the natural fit for RDDAC's raw tables). See
:func:ddacs.streaming.export_to_numpy_per_sim for details.
Source code in rddac/streaming.py
rddac.streaming.load_export¶
load_export(directory: str | Path, fields: list[str] | None = None) -> _LoadedExport
¶
Open a directory of .npy shards produced by :func:export_to_numpy.
Returns a lazy reader that exposes the standard Python data model
(len(reader), reader[i], for r in reader, reader.by_sim_id(sid)).
Each record is a plain dict[str, numpy.ndarray] backed by
mmap_mode='r', so the full release fits even when it exceeds RAM --
only the rows actually accessed page in.
The returned object is framework-agnostic. Pass it directly into
torch.utils.data.DataLoader(loader, batch_size=...) because it
satisfies the map-style Dataset protocol. The same instance also
works with tf.data.Dataset.from_generator(lambda: iter(loader), ...),
with JAX, or with plain Python loops -- no adapter required and no
torch import inside.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
directory
|
str | Path
|
Path produced by :func: |
required |
fields
|
list[str] | None
|
Optional subset of field aliases to load. |
None
|
Returns:
| Type | Description |
|---|---|
_LoadedExport
|
A reader instance. The concrete type is private; rely on the |
_LoadedExport
|
documented protocol rather than the class name. |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
|
ValueError
|
|
Example
export = ddacs.streaming.load_export("./data/tutorial_export") len(export), export.fields # (1, ('delta', 'forming', ...)) export[0] # {alias: ndarray} export.by_sim_id(258864) # lookup by simulation id from torch.utils.data import DataLoader DataLoader(export, batch_size=16, shuffle=True)