2.11.1.3. pycsamt.jones.cbase#
Classes
|
Minimal stateful base for collections of J files. |
|
Core scanner for J files that extracts light metadata. |
Lightweight helpers for scanning Jones J-format text. |
- class pycsamt.jones.cbase.JParseMixin[source]
Bases:
objectLightweight helpers for scanning Jones J-format text.
The mixin implements tolerant, file-level utilities used by higher-level parsers and collections. It focuses on small, dependency-free pieces such as path coercion, candidate file discovery, banner and header probing, and quick content reads.
The mixin does not keep state. Methods are small and side-effect free so they can be reused by different classes (e.g.,
JCoreParser,JCBBase,JCollection).Notes
Utilities are designed to be permissive. They handle odd encodings, mixed line endings, and common filename patterns. They also accept both
pathlib.Pathand strings.The intent is to keep the heavy parsing in dedicated readers, while providing robust file discovery and quick checks here.
Examples
Discover candidate files in a folder:
>>> m = JParseMixin() >>> root = "data/j" >>> list(m._iter_j_files([root]))[:1] [PosixPath('...kb0-s001.txt')]
Coerce user inputs to
Path:>>> p = m._as_path("data/j/kb0-s001.txt") >>> p.exists() True
See also
JCoreParserAdds content probing (station, dtype, counts).
JCBBaseState-holding base for collections.
pycsamt.jones.validation.IsJFile-level validator for J candidates.
pycsamt.jones.j.JFileHigh-level reader that builds Z/Tipper/R blocks.
References
[JParseMixin-1]Jones (1994). J-format v2.0. MTNet notes.
- J_SUFFIXES = {'.dat', '.j', '.jones', '.txt'}
- is_j_like(src, *, deep=True)[source]
Light heuristic to decide if
srclooks like a Jones file.
- is_j_file(src, *, deep=True)[source]
Spec-level check via
IsJ. ReturnsTrueif the file satisfies the structural requirements;Falseotherwise. Never raises.
- class pycsamt.jones.cbase.JCoreParser(*, recursive=True, strict=False, on_dup='replace', verbose=0)[source]
Bases:
JParseMixinCore scanner for J files that extracts light metadata.
Extends
JParseMixinwith small, read-only probes that inspect the top header and first data head triple. This class can reveal the station code, presence of info keys, encountered data kinds, and the declared row count of the first block. It avoids loading the whole file.The implementation aims to be fast and safe for directory crawls, where many files are filtered before full parse.
- Variables:
encoding (str, default
'utf-8') – Encoding used when reading text. Implementations may choose a tolerant variant such as'utf-8-sig'witherrors='replace'.- Parameters:
- _read_text(path)
Return the file content as a single text string.
- _scan_one(path)
Return a small dict of hints (e.g.,
station,kinds,nrows) obtained without full parsing.
- _looks_like_j(path)
Heuristic check that a path is a J candidate.
- _iter_info_keys(text)
Yield info keys (
>KEY=VALUE) from the header area.
Notes
The scanner is structural. It does not validate numeric content or cross-block consistency. It is designed to be called many times in batch workflows.
Examples
Quick peek of a single file:
>>> p = "data/j/kb0-s001.txt" >>> core = JCoreParser() >>> hints = core._scan_one(p) >>> "station" in hints and "kinds" in hints True
Filter a folder to J candidates:
>>> paths = list(core._iter_j_files(["data/j"])) >>> all(core._looks_like_j(p) for p in paths) True
See also
JParseMixinPath and discovery helpers used by this scanner.
JCBBaseCollection base that can cache these hints.
pycsamt.jones.heads.HeadsFull header reader (Info + Head + Banner).
pycsamt.jones.blocks.JBlocksFull data block reader.
References
[JCoreParser-1]Jones (1994). J-format v2.0. MTNet notes.
- results: list[_JParseResult]
- parse(sources)[source]
- errors()[source]
- Return type:
- class pycsamt.jones.cbase.JCBBase(items=None, *, verbose=0)[source]
Bases:
objectMinimal stateful base for collections of J files.
The class manages a list of parsed items (usually
JFile), keeps light metadata for indexing and filtering, and offers a stable surface for higher-level collection types. It is intentionally small so projects can extend it without tight coupling.- Parameters:
- Variables:
- add(obj)[source]
Append an item. Returns the item for chaining.
- Parameters:
jf (JFile)
- Return type:
None
- parse(paths)
Build and add items from paths. Uses the light probes from
JCoreParserbefore full parse.
- filter(**kws)
Optional helper that returns a new instance filtered by station, component family, or other metadata.
- __len__(), __iter__()[source]
Python container protocol for lists of items.
Notes
Subclasses are encouraged to keep the API stable while augmenting with domain-specific helpers, like saving index CSV files or computing per-site quality metrics.
The base class uses tolerant discovery, so it can be used on mixed folders where some files are not Jones J-format.
Examples
Build a collection from a folder:
>>> col = JCBBase(verbose=0) >>> items = col.parse(["data/j"]) >>> len(items) == col.n True
Iterate over sites and write quick summaries:
>>> for it in col: ... print(getattr(it, "site", None))
See also
pycsamt.jones.collection.JCollectionHigher-level collection with convenience features.
pycsamt.jones.j.JFileHigh-level reader used as per-item object.
JCoreParserProvides the fast scanning used during
parse.
References
[JCBBase-1]Jones (1994). J-format v2.0. MTNet notes.
- classmethod load(sources, *, parser=None, recursive=True, strict=False, on_dup='replace', verbose=0)[source]
- write(savepath, *, pattern='{station}.j', **kwargs)[source]
- property items[source]
unified iterator over stored items.
- Type:
Internal