cryosparc.column

cryosparc.column#

Classes:

Column(field, data)

Dataset column that inherits from the native numpy array interface.

class cryosparc.column.Column(field: Tuple[str, str] | Tuple[str, str, Tuple[int, ...]], data: Data)#

Dataset column that inherits from the native numpy array interface.

Note

Storing a column instance outside of a dataset prevents the whole dataset from getting garbage collected. Create a copy of its contents to prevent this, e.g., np.array(dset['ctf/phase_shift_rad'])).

Note

If new fields are added to the original dataset, a column instance may no longer be valid and must be retrieved again from dataset[fieldname].

Examples

Storing column instances

>>> dset = Dataset.allocate(1000, [('col1', 'f4'), ('col2', 'f4'), ('col3', 'f4')])
Dataset(...)
>>> col = dset['col1']
>>> assert isinstance(col, Column)  # ok
>>> del dset             # col still available but dset not garbage collected
>>> col = np.array(col)  # dset now may be garbage collected

Invalid column instances after adding columns

>>> dset = Dataset.allocate(1000, [('col1', 'f4')])
Dataset(...)
>>> col = dset['col1']
>>> dset.add_fields([('col2', 'f4'), ('col3', 'f4')])
>>> np.sum(col)  # DANGER!! May result in invalid access
>>> col = dset['col1']
>>> np.sum(col)  # Retrieved from dataset, now valid
0

Methods:

to_fixed()

If this Column is composed of Python objects, convert to fixed-size strings.

to_fixed() Column#

If this Column is composed of Python objects, convert to fixed-size strings. Otherwise the array is already in fixed form and may be returned as is.

Returns:

Either same column with optionally converted data. If the

data type is numpy.object_, converts to numpy.bytes_ with a fixed element size based on the longest available string length.

Return type:

Column