Beispiel #1
0
def print_json(outfile, samp_freq, time_offset, ch_name):
    """
    Print the json required by BIDS format.

    Parameters
    ----------
    outfile: str or path
        Fullpath to output file.
    samp_freq: float
        Frequency of sampling for the output file.
    time_offset: float
        Difference between beginning of file and first TR.
    ch_name: list of str
        List of channel names, as specified by BIDS format.

    Notes
    -----
    Outcome:
    outfile: .json file
        File containing information for BIDS.
    """
    start_time = -time_offset
    summary = dict(SamplingFrequency=samp_freq,
                   StartTime=round(start_time, 4),
                   Columns=ch_name)
    utils.write_json(outfile, summary, indent=4, sort_keys=False)
Beispiel #2
0
def test_write_json(tmpdir):
    test_json_filename = tmpdir.join('foo')
    test_json_data = dict(SamplingFrequency=42,
                          StartTime='00:00 ET',
                          Columns='Rick')
    utils.write_json(str(test_json_filename), test_json_data, indent=4, sort_keys=False)
    test_json_filename += '.json'
    assert os.path.isfile(test_json_filename)
    with open(test_json_filename, 'r') as src:
        loaded_data = json.load(src)
    assert test_json_data == loaded_data
Beispiel #3
0
def dataset_description_file(outdir):
    """
    Create dataset_description.json file if it does not exist.

    If it exists, do nothing.

    Parameters
    ----------
    outdir: path
        Full path to the output directory.

    """
    # dictionary that will be written for the basic dataset description version
    data_dict = {"Name": os.path.splitext(os.path.basename(outdir))[0],
                 "BIDSVersion": "1.4.0", "DatasetType": "raw"}
    file_path = os.path.join(outdir, 'dataset_description.json')
    # check if dataset_description.json exists, if it doesn't create it
    if not os.path.exists(file_path):
        LGR.warning('phys2bids could not find dataset_description.json,'
                    'generating it with provided info')
        utils.write_json(file_path, data_dict)