neuroscout/tasks/utils/io.py
def analysis_to_json(analysis_id, run_id=None):
    """" Serialize analysis and related PredictorEvents to JSON.
    Queries PredictorEvents to get all events for all runs and predictors. """

    # Query for analysis
    analysis = Analysis.query.filter_by(hash_id=analysis_id).one()

    # Dump analysis JSON
    analysis_json = AnalysisFullSchema().dump(analysis)
    resources_json = AnalysisResourcesSchema().dump(analysis)

    # Get run IDs
    all_runs = [r['id'] for r in analysis_json['runs']]
    if run_id is None:
        run_id = all_runs
    if not set(run_id) <= set(all_runs):
        raise ValueError("Incorrect run id specified")

    pes = dump_predictor_events(
        [(p['id']) for p in analysis_json['predictors']],
        run_id
        )

    dataset_path = Path(analysis.dataset.local_path)
    preproc_path = dataset_path / 'derivatives' / 'fmriprep'

    if preproc_path.exists():
        dataset_path = preproc_path
    else:
        preproc_path = dataset_path / 'derivatives' / 'preproc'
        if preproc_path.exists():
            dataset_path = preproc_path

    TR = analysis.runs[0].task.TR if analysis.runs else None

    return (analysis.id, analysis_json, resources_json, pes,
            str(dataset_path), TR)
 Serialize analysis and related PredictorEvents to JSON.
    Queries PredictorEvents to get all events for all runs and predictors. 
Serialize analysis and related PredictorEvents to JSON.
Queries PredictorEvents to get all events for all runs and predictors.
Serialize analysis and related PredictorEvents to JSON . Queries PredictorEvents to get all events for all runs and predictors .
def analysis_to_json(analysis_id, run_id=None):
    analysis = Analysis.query.filter_by(hash_id=analysis_id).one()
    analysis_json = AnalysisFullSchema().dump(analysis)
    resources_json = AnalysisResourcesSchema().dump(analysis)
    all_runs = [r['id'] for r in analysis_json['runs']]
    if run_id is None:
        run_id = all_runs
    if not set(run_id) <= set(all_runs):
        raise ValueError("Incorrect run id specified")
    pes = dump_predictor_events(
        [(p['id']) for p in analysis_json['predictors']],
        run_id
        )
    dataset_path = Path(analysis.dataset.local_path)
    preproc_path = dataset_path / 'derivatives' / 'fmriprep'
    if preproc_path.exists():
        dataset_path = preproc_path
    else:
        preproc_path = dataset_path / 'derivatives' / 'preproc'
        if preproc_path.exists():
            dataset_path = preproc_path
    TR = analysis.runs[0].task.TR if analysis.runs else None
    return (analysis.id, analysis_json, resources_json, pes,
            str(dataset_path), TR)
def analysis_to_json ( analysis_id , run_id = None ) : analysis = Analysis . query . filter_by ( hash_id = analysis_id ) . one ( ) analysis_json = AnalysisFullSchema ( ) . dump ( analysis ) resources_json = AnalysisResourcesSchema ( ) . dump ( analysis ) all_runs = [ r [ 'id' ] for r in analysis_json [ 'runs' ] ] if run_id is None : run_id = all_runs if not set ( run_id ) <= set ( all_runs ) : raise ValueError ( "Incorrect run id specified" ) pes = dump_predictor_events ( [ ( p [ 'id' ] ) for p in analysis_json [ 'predictors' ] ] , run_id ) dataset_path = Path ( analysis . dataset . local_path ) preproc_path = dataset_path / 'derivatives' / 'fmriprep' if preproc_path . exists ( ) : dataset_path = preproc_path else : preproc_path = dataset_path / 'derivatives' / 'preproc' if preproc_path . exists ( ) : dataset_path = preproc_path TR = analysis . runs [ 0 ] . task . TR if analysis . runs else None return ( analysis . id , analysis_json , resources_json , pes , str ( dataset_path ) , TR )
Serialize analysis and related PredictorEvents to JSON.
Serialize analysis and related PredictorEvents to JSON .
"""" Serialize analysis and related PredictorEvents to JSON.
    Queries PredictorEvents to get all events for all runs and predictors. """ # Query for analysis # Dump analysis JSON # Get run IDs
analysis_id
run_id