Skip to content

flywheel.view_builder

ViewBuilder

Bases: object

Builder class that assists in constructing a DataView object.

Parameters:

Name Type Description Default
label str

The optional label, if saving this data view.

None
public bool

Whether or not to make this data view public when saving it.

required
match str

The file match type, one of: first, last, newest, oldest, all

None
zip_files str

The zip file filter, see the zip_member_filter function

None
columns list

The columns or column groups to add

None
process_files bool

Whether or not to process files, default is true

True
include_ids bool

Whether or not to include id columns, default is true

True
include_labels bool

Whether or not to include label columns, default is true

True
error_column bool

Whether or not to include errors column, default is true

None
group_by Union[str, list, DataViewGroupBy]

The Columns or column to group by

None
filter str

The dataview pagination filter to save on the spec

None
container str

When matching files, the container to match on

None
filename str

When matching files, the filename pattern to match

None
analysis_label str

When matching analysis files, the label match string

None
analysis_gear_name str

When matching analysis files, the gear name match string

None
analysis_gear_version str

When matching analysis files, the gear version match string

None
sort bool

Option to sort results

True

analysis_filter(label=None, gear_name=None, gear_version=None, regex=False)

Set the filter to use for matching analyses. If this is set, then analyses files will be matched instead of container.

Parameters:

Name Type Description Default
label str

The label match string, wildcards (*, ?) are supported.

None
gear_name str

The gear name match string, wildcards (*, ?) are supported.

None
gear_version str

The gear version match string, wildcards (*, ?) are supported.

None
regex bool

Whether to treat the match string as a regular expression (default is False)

False

Returns:

Type Description

self

build()

Build the DataView constructed with this builder.

Returns:

Type Description

The constructed DataView

column(src, dst=None, type=None, accumulator=None, expr=None)

Define a column for this data view.

Parameters:

Name Type Description Default
src str

The source field, or column alias name.

required
dst str

The optional destination field (defaults to source)

None
type str

The optional type for this column, one of: int, float, string bool.

None
accumulator str

The optional accumulation operation for group by aggregation.

None
expr str

The optional expression to apply

None

Returns:

Type Description

self

description(description)

Set the description for this data view.

Parameters:

Name Type Description Default
description str

The new description for the data view.

required

Returns:

Type Description

self

error_column(value=True)

Set whether or not to include error column by default.

Parameters:

Name Type Description Default
value bool

Whether or not to include errors (default is true)

True

Returns:

Type Description

self

file_column(src, dst=None, type=None)

Define a column to extract from a file.

Parameters:

Name Type Description Default
src str

The source field.

required
dst str

The optional destination field (defaults to source)

None
type str

The optional type for this column, one of: int, float, string bool.

None

Returns:

Type Description

self

file_container(container)

Set the container where files should be matched.

Parameters:

Name Type Description Default
container str

The container name, one of: project, subject, session, acquisition

required

Returns:

Type Description

self

file_filter(value=None, regex=False)

Set the filter to use for matching files.

Parameters:

Name Type Description Default
value str

The filename match string, wildcards (*, ?) are supported.

None
regex bool

Whether to treat the match string as a regular expression (default is False)

False

Returns:

Type Description

self

file_format(format_name)

Set the expected format of files to read.

NOTE: This shouldn't be needed very often. If not specified, autodetect will be used for processing files.

Parameters:

Name Type Description Default
format_name str

The expected file format, one of: csv, tsv, json.

required

Returns:

Type Description

self

file_format_options(**kwargs)

Set additional options for the file format. (e.g. arguments to be passed to csv reader function)

Parameters:

Name Type Description Default
kwargs dict

Arguments to pass to the file reader

{}

Returns:

Type Description

self

file_match(match_value)

Set the resolution strategy if multiple matching files or analyses are encountered.

Parameters:

Name Type Description Default
match_value str

The file match type, one of: first, last, newest, oldest, all

required

Returns:

Type Description

self

files(container, filename, analysis_label=None, analysis_gear_name=None, analysis_gear_version=None)

Set filter for matching files

Container is one of project, subject, session, acquisition Filename filters can use the (*, ?) wildcards Analysis filters also support wildcards

Parameters:

Name Type Description Default
container str

When matching files, the container to match on: one of project, subject, session, acquisition

required
filename str

When matching files, the filename pattern to match

required
analysis_label str

When matching analysis files, the label match string

None
analysis_gear_name str

When matching analysis files, the gear name match string

None
analysis_gear_version str

When matching analysis files, the gear version match string

None

Returns:

Type Description

self

filter(filter)

Set the filter for this data view.

Parameters:

Name Type Description Default
filter str

The dataview pagination filter to save on the spec.

required

Returns:

Type Description

self

group_by(src, dst=None)

Define a column for this data view.

Parameters:

Name Type Description Default
src str

The source field, or column alias name.

required
dst str

The optional destination field (defaults to source)

None

Returns:

Type Description

self

include_ids(value=True)

Set whether or not to include the id columns by default.

Parameters:

Name Type Description Default
value bool

Whether or not to include ids (default is true)

True

Returns:

Type Description

self

include_labels(value=True)

Set whether or not to include the label columns by default.

Parameters:

Name Type Description Default
value bool

Whether or not to include labels (default is true)

True

Returns:

Type Description

self

label(label)

Set the label for this data view.

Parameters:

Name Type Description Default
label str

The new label for the data view.

required

Returns:

Type Description

self

missing_data_strategy(value)

Set the resolution strategy if rows are missing data for a column. The default is to replace the column value with None.

Parameters:

Name Type Description Default
value str

The strategy to use for missing data, one of: none, drop-row

required

Returns:

Type Description

self

process_files(value)

Set whether or not to process files (default is True)

By default, files will be read and return a row for each row in the file. If you just want file attributes or info instead, you can set this to False.

Parameters:

Name Type Description Default
value bool

Whether or not to process files

required

Returns:

Type Description

self

public(value=True)

Set whether or not this data view should be made public.

Parameters:

Name Type Description Default
value bool

True if the data view should be public. (default)

True

Returns:

Type Description

self

sort(value=True)

Set the option to opt out of sorting the rows by setting false

Parameters:

Name Type Description Default
value bool

Opt out of sorting

True

Returns:

Type Description

self

zip_member_filter(value=None, regex=False, match=None)

Set the filter to use for matching members of a zip file.

Parameters:

Name Type Description Default
value str

The filename match string, wildcards (*, ?) are supported.

None
regex bool

Whether to treat the match string as a regular expression (default is False)

False
match str

The file match type, one of: first, last, newest, oldest, all

None

Returns:

Type Description

self