cryosparc.row#
Classes:
Type variable for a |
|
|
Provides row-by-row access to a dataset. |
|
List-like dataset row accessor class with support for splitting and randomizing based on row fields |
- class cryosparc.row.Row(cols: Dict[str, Column], idx: int)#
Provides row-by-row access to a dataset. Do not initialize directly. See dataset module.
Methods:
to_list
([exclude_uid])Convert into a list of native python types in the same order as the declared fields.
- to_list(exclude_uid=False)#
Convert into a list of native python types in the same order as the declared fields.
- class cryosparc.row.Spool(items: Iterable[R], rng: Generator | None = None)#
List-like dataset row accessor class with support for splitting and randomizing based on row fields
- Parameters:
items (Iterable[R]) – List of rows
rng (Generator, optional) – Numpy random number generator. Uses
numpy.random.default_rng()
if not specified. Defaults to None.
Methods:
get_random_subset
(num)Randomly selected subset of the given size, without replacement.
make_batches
([num])Get a list of lists, each one a consecutive list of
num
images.set_default_random
(rng)Reset the default random number generator for all Spools
set_random
(rng)Reset the random number generator for this Spool.
setup_spooling
([random])Determine the iteration order for the
spool()
method.split
(num[, random, prefix])Return two Spools with the elements of this spool.
split_by
(field)Split into a dictionary of lists, where each key is a possible value for the given field and each value is a list if elements that have that value.
split_by_splits
([prefix])Return two Spools divided by the value of the
{prefix}/split
field.split_from_field
(field[, vals])Split into two lists based on the given possible vals of the given field.
split_half_in_order
(prefix[, random])Split into two spools of approximately equal size.
split_into_quarter
(num)Randomly assign the elements of this Spool to two new Spools.
spool
(num[, peek])Get a list consisting of num randomly-selected elements.
- get_random_subset(num: int)#
Randomly selected subset of the given size, without replacement.
- Parameters:
num (int) – number of elements to select from the Spool
- Returns:
selected elements
- Return type:
list[R]
- make_batches(num: int = 200)#
Get a list of lists, each one a consecutive list of
num
images.- Parameters:
num (int, optional) – Size of each batch. Defaults to 200.
- Returns:
Split batches
- Return type:
list[list[R]]
- classmethod set_default_random(rng: Generator)#
Reset the default random number generator for all Spools
- Parameters:
rng (Generator) – Numpy random generator.
- set_random(rng: Generator)#
Reset the random number generator for this Spool.
- Parameters:
rng (Generator) – Numpy random generator.
- setup_spooling(random=True)#
Determine the iteration order for the
spool()
method.- Parameters:
random (bool, optional) – Randomize spooling order. Defaults to True.
- split(num: int, random: bool = True, prefix: str | None = None)#
Return two Spools with the elements of this spool. The first Spool contains
num
elements. The second containslen(self) - num
elements.- Parameters:
num (int) – Number of elements in first split.
random (bool, optional) – If True, add elements to each split in random order. Defaults to True.
prefix (str, optional) – If specified, set each
{prefix}/split
field to0
in the first split and1
in the second split. Defaults to None.
- Returns:
the two split lists
- Return type:
- split_by(field: str) Dict[Any, List[R]] #
Split into a dictionary of lists, where each key is a possible value for the given field and each value is a list if elements that have that value.
- Parameters:
field (str) – dataset field to split on
- Returns:
dict of split element lists
- Return type:
dict[any, list[R]]
- split_by_splits(prefix: str = 'alignments')#
Return two Spools divided by the value of the
{prefix}/split
field.
- split_from_field(field: str, vals: Tuple[Any, Any] = (0, 1))#
Split into two lists based on the given possible vals of the given field.
- split_half_in_order(prefix: str, random: bool = True)#
Split into two spools of approximately equal size. Elements are added to each split in stable order.
- split_into_quarter(num: int)#
Randomly assign the elements of this Spool to two new Spools. The first Spool contains
num
elements. The second containslen(self) - num
elements.
- spool(num: int, peek: bool = False)#
Get a list consisting of num randomly-selected elements. Advance the spool. If peek is true, don’t advance the spool, just return the first num elements.
- Parameters:
num (int) – Number of elements to get from the spool.
peek (bool, optional) – If True, does not advance internal spool index. Will return the same elements on the next
spool()
call. Defaults to False.
- Returns:
list of selected spool elements
- Return type:
list[R]