(self, results, pipelines)
add results
add results
add results
def add(self, results, pipelines):
        """add results"""

        def to_list(res):
            if type(res) is dict:
                return [res]
            elif type(res) is not list:
                raise ValueError(
                    "Results are given as neither dict nor"
                    "list but {}".format(type(res).__name__)
                )
            else:
                return res

        with h5py.File(self.filepath, "r+") as f:
            for name, data_dict in results.items():
                digest = get_digest(pipelines[name])
                if digest not in f.keys():
                    # create pipeline main group if nonexistant
                    f.create_group(digest)

                ppline_grp = f[digest]
                ppline_grp.attrs["name"] = name
                ppline_grp.attrs["repr"] = repr(pipelines[name])

                dlist = to_list(data_dict)
                d1 = dlist[0]  # FIXME: handle multiple session ?
                dname = d1["dataset"].code
                n_add_cols = len(self.additional_columns)
                if dname not in ppline_grp.keys():
                    # create dataset subgroup if nonexistant
                    dset = ppline_grp.create_group(dname)
                    dset.attrs["n_subj"] = len(d1["dataset"].subject_list)
                    dset.attrs["n_sessions"] = d1["dataset"].n_sessions
                    dt = h5py.special_dtype(vlen=str)
                    dset.create_dataset("id", (0, 2), dtype=dt, maxshape=(None, 2))
                    dset.create_dataset(
                        "data", (0, 3 + n_add_cols), maxshape=(None, 3 + n_add_cols)
                    )
                    dset.attrs["channels"] = d1["n_channels"]
                    dset.attrs.create(
                        "columns",
                        ["score", "time", "samples", *self.additional_columns],
                        dtype=dt,
                    )
                dset = ppline_grp[dname]
                for d in dlist:
                    # add id and scores to group
                    length = len(dset["id"]) + 1
                    dset["id"].resize(length, 0)
                    dset["data"].resize(length, 0)
                    dset["id"][-1, :] = np.asarray([str(d["subject"]), str(d["session"])])
                    try:
                        add_cols = [d[ac] for ac in self.additional_columns]
                    except KeyError:
                        raise ValueError(
                            f"Additional columns: {self.additional_columns} "
                            f"were specified in the evaluation, but results"
                            f" contain only these keys: {d.keys()}."
                        ) from None
                    dset["data"][-1, :] = np.asarray(
                        [d["score"], d["time"], d["n_samples"], *add_cols]
                    )
def add ( self , results , pipelines ) : def to_list ( res ) : if type ( res ) is dict : return [ res ] elif type ( res ) is not list : raise ValueError ( "Results are given as neither dict nor" "list but {}" . format ( type ( res ) . __name__ ) ) else : return res with h5py . File ( self . filepath , "r+" ) as f : for name , data_dict in results . items ( ) : digest = get_digest ( pipelines [ name ] ) if digest not in f . keys ( ) : # create pipeline main group if nonexistant f . create_group ( digest ) ppline_grp = f [ digest ] ppline_grp . attrs [ "name" ] = name ppline_grp . attrs [ "repr" ] = repr ( pipelines [ name ] ) dlist = to_list ( data_dict ) d1 = dlist [ 0 ] # FIXME: handle multiple session ? dname = d1 [ "dataset" ] . code n_add_cols = len ( self . additional_columns ) if dname not in ppline_grp . keys ( ) : # create dataset subgroup if nonexistant dset = ppline_grp . create_group ( dname ) dset . attrs [ "n_subj" ] = len ( d1 [ "dataset" ] . subject_list ) dset . attrs [ "n_sessions" ] = d1 [ "dataset" ] . n_sessions dt = h5py . special_dtype ( vlen = str ) dset . create_dataset ( "id" , ( 0 , 2 ) , dtype = dt , maxshape = ( None , 2 ) ) dset . create_dataset ( "data" , ( 0 , 3 + n_add_cols ) , maxshape = ( None , 3 + n_add_cols ) ) dset . attrs [ "channels" ] = d1 [ "n_channels" ] dset . attrs . create ( "columns" , [ "score" , "time" , "samples" , * self . additional_columns ] , dtype = dt , ) dset = ppline_grp [ dname ] for d in dlist : # add id and scores to group length = len ( dset [ "id" ] ) + 1 dset [ "id" ] . resize ( length , 0 ) dset [ "data" ] . resize ( length , 0 ) dset [ "id" ] [ - 1 , : ] = np . asarray ( [ str ( d [ "subject" ] ) , str ( d [ "session" ] ) ] ) try : add_cols = [ d [ ac ] for ac in self . additional_columns ] except KeyError : raise ValueError ( f"Additional columns: {self.additional_columns} " f"were specified in the evaluation, but results" f" contain only these keys: {d.keys()}." ) from None dset [ "data" ] [ - 1 , : ] = np . asarray ( [ d [ "score" ] , d [ "time" ] , d [ "n_samples" ] , * add_cols ] )