nimare.studyset.Studyset
- class Studyset(source, target='mni152_2mm', mask=None, annotations=None, basepath=None)[source]
Bases:
objectA collection of studies for meta-analysis.
- Parameters:
source (
dict,str, orStudysetStore) – A NIMADS studyset dictionary, a path to one as JSON, a path to a parquet release directory, or an existing store.target (
stror None, default=”mni152_2mm”) – Space to report coordinates in. The raw coordinates are always kept, so re-targeting is exact rather than cumulative.mask (Niimg-like or
NiftiMasker, optional) – Masker for execution. Defaults to the template brain mask fortarget.annotations (
listofdict, optional) – Extra NIMADS annotation payloads to attach.basepath (
str, optional) – Directory that relative image paths are resolved against.
Methods
One analysis per study, foci and images concatenated.
Return the foci for the selection, grouped by analysis.
copy()Return a new handle on the same immutable store.
exclude_study_ids(study_ids)Return a studyset without the requested studies.
filter_annotations(labels[, threshold, ...])Keep analyses whose annotation labels reach
threshold.filter_ids(ids)Keep the named analyses, by full id or short analysis id.
filter_metadata(field, op, value)Keep analyses whose metadata
fieldsatisfiesop value.filter_study_ids(study_ids)Return a studyset with only the requested studies.
from_dataset(dataset)Convert a legacy
Dataset.from_nimads(source, **kwargs)Read a NIMADS studyset from a dict or a JSON path.
from_parquet(directory, **kwargs)Read a parquet studyset release directory.
from_sleuth(sleuth_file, **kwargs)Read a Sleuth text file.
get_analyses_by_annotations(key[, value])Analyses carrying
key, which may name a label or a whole annotation.get_analyses_by_coordinate(xyz[, r, n])Short analysis ids near
xyz, by radius or by count.get_analyses_by_label([labels, ...])Short analysis ids whose labels reach the threshold.
get_analyses_by_mask(mask)Short analysis ids with at least one focus inside
mask.get_analyses_by_metadata(key[, value]){analysis id: {key: value}}for analyses carryingkey.get_annotations([analyses]){analysis id: {label: value}}, merged across every annotation.get_images([imtype, ids, policy])Image types present, or one type's paths.
get_labels([ids])Labels present in the studyset's annotations.
get_metadata([field, ids])Metadata field names, or one field's values.
get_points([analyses]){analysis id: [point dicts]}.get_studies_by_coordinate(xyz[, r])Full analysis ids with a focus within
rmm of any ofxyz.get_studies_by_label([labels, ...])Full analysis ids whose labels reach the threshold.
get_studies_by_mask(mask)Full analysis ids with at least one focus inside
mask.get_texts([text_type, ids])Text field names, or one field's values.
harmonized(target)Return a studyset whose stored coordinates are in
target.image_block(imtype, *[, policy])Return the images of one type for the selection.
keep_images(image_mask)Return a studyset holding only the flagged images.
label_block([annotation])Return the annotation matrix for the selection.
load(filename)Load a pickled studyset.
Return a studyset whose store holds only the currently selected foci.
merge(right)Merge another studyset in, preferring this one on conflicts.
resolve(requirements_[, drop_invalid])Narrow to the analyses that satisfy every requirement, and build blocks.
Return
{analysis id: row in this studyset}, memoised.sample_sizes([reduce])One sample size per analysis, from whichever level declares it.
save(filename)Pickle the studyset.
select_analyses(mask)Keep the analyses a boolean mask -- or an array of positions -- selects.
select_points(point_mask)Keep a subset of foci and every analysis.
slice([ids, analyses, filter_level])Return a studyset with only the requested ids.
text_block([field])Return one text field for the selection.
Convert to a legacy
Dataset.to_dict()Build the nested NIMADS document for the selected analyses.
to_nimads(filename)Write NIMADS JSON.
to_parquet(directory)Write a parquet studyset release directory.
update_path(new_path)Resolve relative image paths against
new_path.with_annotation(name, labels, matrix[, ...])Return a studyset carrying an extra annotation.
with_annotation_payload(payload)Return a studyset carrying a NIMADS annotation payload.
with_annotations_df(frame[, name, replace])Return a studyset carrying
frameas an annotation.with_context(**changes)Return a studyset with different space, masker or basepath.
with_images(analysis_positions, refs, ...)Return a studyset with extra images.
with_metadata(name, values, *[, level])Return a studyset with one extra metadata column.
with_points(analysis_positions, xyz, **kwargs)Return a studyset with extra foci.
with_texts(rows, field, values)Return a studyset with text added.
Properties
Read-only nested accessors for the selected analyses.
listofAnnotationSet.Every annotation flattened into one frame.
Return the directory relative image paths resolve against.
One row per focus.
Return the studyset id.
full
study-analysisidentifiers.One row per stored image.
One row per analysis, one column per image type.
Return the masker images are sampled onto.
One row per analysis, study metadata merged in.
Return the studyset name.
Return the space coordinates are reported in.
The immutable store behind this studyset.
Read-only nested accessors for the selected studies.
unique study identifiers.
Return one row per analysis of the text fields.
The selection over that store.
- property analyses
Read-only nested accessors for the selected analyses.
- property annotations
listofAnnotationSet.
- property annotations_df
Every annotation flattened into one frame.
Collisions between annotations are qualified with the annotation id and recorded in
frame.attrs["annotation_collisions"]rather than one silently overwriting the other.
- property basepath
Return the directory relative image paths resolve against.
- combine_analyses()[source]
One analysis per study, foci and images concatenated.
Annotation notes name pre-merge analyses, so they cannot be carried over and are dropped.
- property coordinates
One row per focus.
- exclude_study_ids(study_ids)[source]
Return a studyset without the requested studies.
An id matching nothing is not an error.
- filter_annotations(labels, threshold=0.001, match='all', annotation=None)[source]
Keep analyses whose annotation labels reach
threshold.
- filter_ids(ids)[source]
Keep the named analyses, by full id or short analysis id.
Raises
ValueErrornaming any id that matches nothing.
- filter_study_ids(study_ids)[source]
Return a studyset with only the requested studies.
Raises
ValueErrornaming any id that matches nothing.
- classmethod from_dataset(dataset)[source]
Convert a legacy
Dataset.Not optimised:
Datasetis deprecated, and this is the boundary where it becomes a studyset before anything else touches it.
- classmethod from_nimads(source, **kwargs)[source]
Read a NIMADS studyset from a dict or a JSON path.
- get_analyses_by_annotations(key, value=None)[source]
Analyses carrying
key, which may name a label or a whole annotation.Accepts either form: the previous implementation keyed on the annotation id here while
get_studies_by_labelkeyed on the label.
- get_analyses_by_coordinate(xyz, r=None, n=None)[source]
Short analysis ids near
xyz, by radius or by count.
- get_analyses_by_label(labels=None, label_threshold=0.001, annotation=None)[source]
Short analysis ids whose labels reach the threshold.
- get_analyses_by_metadata(key, value=None)[source]
{analysis id: {key: value}}for analyses carryingkey.
- get_annotations(analyses=None)[source]
{analysis id: {label: value}}, merged across every annotation.
- get_images(imtype=None, ids=None, policy='first')[source]
Image types present, or one type’s paths.
- get_studies_by_coordinate(xyz, r=20)[source]
Full analysis ids with a focus within
rmm of any ofxyz.
- get_studies_by_label(labels=None, label_threshold=0.001, annotation=None)[source]
Full analysis ids whose labels reach the threshold.
- property id
Return the studyset id.
- property ids
full
study-analysisidentifiers.- Type:
- property image_rows
One row per stored image. The shape an image mask is aligned to.
- property images
One row per analysis, one column per image type.
- keep_images(image_mask)[source]
Return a studyset holding only the flagged images. Copy-on-write.
image_maskis a boolean aligned to the rows ofimage_rows, so a predicate over that frame selects directly:studyset.keep_images(studyset.image_rows["id"] != "study-1")
Note that
imagesis the wide frame – one row per analysis, one column per type – so it is not the right thing to mask against. Foci are untouched, so a point selection made earlier stays valid.
- property masker
Return the masker images are sampled onto.
- property metadata
One row per analysis, study metadata merged in.
- property name
Return the studyset name.
- resolve(requirements_, drop_invalid=True)[source]
Narrow to the analyses that satisfy every requirement, and build blocks.
- sample_sizes(reduce='mean')[source]
One sample size per analysis, from whichever level declares it.
- select_analyses(mask)[source]
Keep the analyses a boolean mask – or an array of positions – selects.
- slice(ids=None, *, analyses=None, filter_level='analysis')[source]
Return a studyset with only the requested ids.
Changed in version 0.21.0: An id naming nothing raises instead of being ignored.
- Parameters:
ids (
stror array_like ofstr) – Analysis ids, or study ids whenfilter_level="study". An analysis may be named by its full"<study id>-<analysis id>"id, whichidslists, or by its analysis id alone. A short id shared by several analyses selects all of them.analyses (array_like of
str, optional) – An alias forids.filter_level ({"analysis", "study"}, default="analysis") – Which level
idsnames.
- Returns:
A studyset holding only the named analyses.
- Return type:
- Raises:
ValueError – If any id names nothing in this studyset, naming the ids that failed. An empty
idsis not an error.
- property space
Return the space coordinates are reported in.
- property store
The immutable store behind this studyset.
- property studies
Read-only nested accessors for the selected studies.
Views over the columns rather than a second copy of the data, so reading them cannot drift from what the store holds.
- property study_ids
unique study identifiers.
- Type:
- property texts
Return one row per analysis of the text fields.
- to_dataset()[source]
Convert to a legacy
Dataset.Not optimised:
Datasetis deprecated and this exists so that existing data can still be written out.
- property view
The selection over that store.
- with_annotation(name, labels, matrix, rows=None, note_key_types=None)[source]
Return a studyset carrying an extra annotation. Copy-on-write.
- with_annotation_payload(payload)[source]
Return a studyset carrying a NIMADS annotation payload. Copy-on-write.
- with_annotations_df(frame, name=None, replace=False)[source]
Return a studyset carrying
frameas an annotation. Copy-on-write.The write counterpart of
annotations_df: a frame with an id column and one column per label.replace=Truediscards the existing annotations, which is what a caller who round-trippedannotations_dfmeans.
- with_images(analysis_positions, refs, imtype, **kwargs)[source]
Return a studyset with extra images. Copy-on-write.
- with_metadata(name, values, *, level='analysis')[source]
Return a studyset with one extra metadata column. Copy-on-write.
Examples using nimare.studyset.Studyset
Run a coordinate-based meta-analysis (CBMA) workflow
Coordinate-based meta-regression with a model formula
Predictive ALE: fast FWE correction without Monte Carlo
Stability diagnostics: Jackknife vs. ResampledStability