pchandler.data_io.csv

CSV / ASCII file-format handler class.

Functions

generate_ascii_load_dtype(column_names)

Generate a dtype object for loading ASCII data based on column names.

sniff_file(file[, delimiters, ...])

Read part of the file and determine some information about its structure.

Classes

AsciiInfo

Summary of what the class does.

CsvHandler

Handle TXT- and CSV-like file input/output for point clouds.

class pchandler.data_io.csv.CsvHandler

Bases: AbstractIOHandler

Handle TXT- and CSV-like file input/output for point clouds.

Supported file extensions:

  • .txt

  • .csv

  • .xyz

  • .asc

  • .ascii

  • .pts

FORMATS: list[str] = ['.txt', '.csv', '.xyz', '.asc', '.ascii', '.pts']
classmethod load(path, scalar_fields=None, remove_prefix=True, prefix='scalar_', column_names_row=-1, comment='//', delimiter=None, **pcd_kw)

Load a point cloud from a CSV-like file.

Parameters:
  • path (str or Path)

  • scalar_fields (list of str, default=None) – List of specific scalar fields to extract from the PLY file. Setting None will retrieve all scalar fields. Setting to [] will ignore scalar fields in the file.

  • remove_prefix (bool, default=True) – Flag to remove prefixes on scalar field names.

  • prefix (str, default="scalar_") – Prefix to strip from scalar field names if remove_prefix is True.

  • column_names_row (int, default=-1) – Header row index where column names are defined. Default is -1 for the last line of the header.

  • comment (str, default = "//") – Character used for comments or header in the file

  • delimiter (str, default=None) – Delimiting character(s) type. If None is set, the file will be sniffed and attempt to automatically it.

  • config (dict)

Return type:

PointCloudData

Notes

Strict-by-name contract: When the file has a parsed header (file_info.fields non-empty), every name in the scalar_fields=[...] list MUST appear in the header. Any missing name causes a ValueError that lists the unknown names and the available header fields. This is a deliberate fail-loud policy — silent positional mis-mapping (the previous behaviour) is no longer possible when a header is present.

Positional-fallback condition: When no header can be parsed (file_info.fields == [], e.g. raw .xyz files without a header line, or files where column_names_row is out of range), the loader falls back to positional column mapping: columns 0/1/2 → XYZ, columns 3..3+N → requested scalar fields in their declared order.

pcd_kwargs pass-through: Additional keyword arguments (**pcd_kw) are forwarded directly to the PointCloudData constructor. This includes, for example, numerical_optimization_shift and socs_origin.

classmethod save(pcd, path, scalar_fields=None, add_prefix=True, prefix='scalar_', revert_sf_types=False, delimiter=',', **config)

Save a point cloud to a text-delimited file (CSV / TXT / similar).

Parameters:
  • pcd (PointCloudData) – Point cloud object

  • path (str or Path) – File path

  • scalar_fields (list[str], default=None) – List of specific scalar fields to extract from the PLY file. Setting None will retrieve all scalar fields. Setting to [] will ignore scalar fields in the file.

  • add_prefix (bool, default=False) – Flag to add prefixes on scalar field names

  • prefix (str, default="scalar_") – Prefix to strip from scalar field names if remove_prefix is True.

  • revert_sf_types (bool, default=False) – Flag to revert scalar field values to their original types or not

  • delimiter (str, default=",") – Delimiter to separate fields in the file.

  • config (dict of str, Any)