Ejemplo n.º 1
0
def _try_mda_create_object(arg: Union[str, dict]) -> Union[None, dict]:
    if isinstance(arg, str):
        path = arg
        if path.startswith('sha1dir') or path.startswith('/'):
            dd = kp.read_dir(path)
            if dd is not None:
                if 'raw.mda' in dd['files'] and 'params.json' in dd[
                        'files'] and 'geom.csv' in dd['files']:
                    raw_path = path + '/raw.mda'
                    params_path = path + '/params.json'
                    geom_path = path + '/geom.csv'
                    geom_path_resolved = kp.load_file(geom_path)
                    assert geom_path_resolved is not None, f'Unable to load geom.csv from: {geom_path}'
                    params = kp.load_object(params_path)
                    assert params is not None, f'Unable to load params.json from: {params_path}'
                    geom = _load_geom_from_csv(geom_path_resolved)
                    return dict(recording_format='mda',
                                data=dict(raw=raw_path,
                                          geom=geom,
                                          params=params))

    if isinstance(arg, dict):
        if ('raw' in arg) and ('geom' in arg) and ('params' in arg) and (type(
                arg['geom']) == list) and (type(arg['params']) == dict):
            return dict(recording_format='mda',
                        data=dict(raw=arg['raw'],
                                  geom=arg['geom'],
                                  params=arg['params']))

    return None
Ejemplo n.º 2
0
def _try_nrs_create_object(arg: Union[str, dict]) -> Union[None, dict]:
    if isinstance(arg, str):
        path = arg
        if path.startswith('sha1dir') or path.startswith('/'):
            dd = kp.read_dir(path)
            if dd is not None:
                probe_file = None
                xml_file = None
                nrs_file = None
                dat_file = None
                for f in dd['files'].keys():
                    if f.endswith('.json'):
                        obj = kp.load_object(path + '/' + f)
                        if obj.get('format_version', None) in ['flatiron-probe-0.1', 'flatiron-probe-0.2']:
                            probe_file = path + '/' + f
                    elif f.endswith('.xml'):
                        xml_file = path + '/' + f
                    elif f.endswith('.nrs'):
                        nrs_file = path + '/' + f
                    elif f.endswith('.dat'):
                        dat_file = path + '/' + f
                if probe_file is not None and xml_file is not None and nrs_file is not None and dat_file is not None:
                    data = dict(
                        probe_file=probe_file,
                        xml_file=xml_file,
                        nrs_file=nrs_file,
                        dat_file=dat_file
                    )
                    return dict(
                        recording_format='nrs',
                        data=data
                    )
    
    if isinstance(arg, dict):
        if ('probe_file' in arg) and ('xml_file' in arg) and ('nrs_file' in arg) and ('dat_file' in arg):
            return dict(
                recording_format='nrs',
                data=dict(
                    probe_file=arg['probe_file'],
                    xml_file=arg['xml_file'],
                    nrs_file=arg['nrs_file'],
                    dat_file=arg['dat_file']
                )
            )
    
    return None