Commit 57988f24 authored by Boers, Frank's avatar Boers, Frank
Browse files

add path cls

parent 72859e2d
......@@ -12,11 +12,11 @@ import numpy as np
import mne
from mne.preprocessing import ICA
from dcnn_utils import (logger, get_chop_times_indices, auto_label_cardiac,
from dcnn_utils import (logger,get_chop_times_indices, auto_label_cardiac,expandvars,
auto_label_ocular, get_unique_list, transform_mne_ica2data)
from dcnn_base import DCNN_MEG, DCNN_ICA, DCNN_SOURCES
from dcnn_base import DCNN_PATH,DCNN_MEG, DCNN_ICA, DCNN_SOURCES
__version__= "2020.06.23.002"
__version__= "2020.06.25.001"
# -----------------------------------------------------
# compute downsampling frequency and final chop length
......@@ -115,7 +115,7 @@ class DCNN(object):
"""
def __init__(self, version=None, n_jobs=1, path=None, meg={}, ica={}, sources={}, res={},
def __init__(self, version=None, n_jobs=1, path={}, meg={}, ica={}, sources={}, res={},
info=None, verbose=False):
"""
init via config dict:
......@@ -125,7 +125,7 @@ class DCNN(object):
----------
version : string, optional, default: None
n_jobs : int, optional, default: 1.
path : dict, optional, default: None
path : dict, optional, default: {}
meg : dict, optional, default: {}
init MEG CLS
......@@ -143,7 +143,6 @@ class DCNN(object):
"""
self.version = version
self.path = path
self.config_info = info
if res:
......@@ -152,12 +151,16 @@ class DCNN(object):
self.model = {'res_time': None ,'res_space': None}
# the following will later be saved in one file for each experiment
self._PATH = DCNN_PATH(**path)
self._MEG = DCNN_MEG(**meg) # MEG system and data settings
self._ICA = DCNN_ICA(**ica)
self._SOURCES = DCNN_SOURCES(**sources)
self.n_jobs = n_jobs # set n_jobs for MEG not ICA
self.verbose = verbose
@property
def path(self): return self._PATH
@property
def meg(self): return self._MEG
......@@ -184,6 +187,7 @@ class DCNN(object):
@verbose.setter
def verbose(self ,v):
self._verbose = v
self.path.verbose = v
self.meg.verbose = v
self.ica.verbose = v
self.sources.verbose = v
......@@ -583,6 +587,7 @@ class DCNN(object):
# data = pickle.load(f)
# load gDCNN data
fname= expandvars(fname)
logger.info('Start loading gDCNN results from disk ....\n -> {}'.format(fname))
npz = np.load(fname, allow_pickle=True)
logger.info('Done loading gDCNN results from disk\n')
......@@ -592,7 +597,7 @@ class DCNN(object):
logger.info("gDCNN data: {}\n{}".format(k, v))
# get details
self.path = npz.get('path').item() # load dict
self.path.init(**npz.get('path').item(),overwrite=False) # load dict
logger.info("path:\n -> {}".format(self.path))
self.model = npz.get('model').item() # load dict
......@@ -623,7 +628,7 @@ class DCNN(object):
logger.info("input fnout: ".format(fnout))
name = op.basename(self.meg.fname).rsplit('.')[0]
if not path_out:
path_out = self.path['data_train']
path_out = self.path.data_train
if not op.exists(path_out):
makedirs(path_out)
fnout = os.path.join(path_out, name + '-gdcnn.npz')
......@@ -636,7 +641,7 @@ class DCNN(object):
self.model['fname_gdcnn'] = fnout
np.savez(fnout, path=self.path, model=self.model,
np.savez(fnout,model=self.model, path=self.path.dump(),
meg=self.meg.dump(), ica=self.ica.dump(), sources=self.sources.dump())
logger.info('Done saving results to disk: {}'.format(fnout))
......@@ -647,8 +652,6 @@ class DCNN(object):
# get details
# --- init dicts
msg = ["DCNN Info",
" -> path :",
" -> {}".format(self.path),
" -> sources:",
" -> {}".format(self.sources),
" -> model:",
......@@ -656,6 +659,7 @@ class DCNN(object):
logger.info("\n".join(msg))
# -- objs
self.path.get_info()
self.meg.get_info()
self.ica.get_info()
self.sources.get_info()
......
......@@ -617,10 +617,11 @@ def run1(fname=None,verbose=False):
# -- init DCNN with raw
dp = DCNN_PERFORMANCE(verbose=verbose)
dp.load_gdc dp.run()nn(fname)
#dp.load_gdc
# dp.run()nn(fname)
logger.info( dp.meg.picks.dump() )
dp.run()
#dp.run()
# ToDo FB
# plot sources and components
......@@ -634,16 +635,20 @@ def run1(fname=None,verbose=False):
# ica.plot_sources(raw_chop,block=True)
# ica.plot_overlay(raw_chop, exclude=ica.exclude, picks='mag')
def ck_labels(fname=None):
dcnn = DCNN(verbose=True)
dcnn.load_gdcnn(fname)
dcnn.check_labels(save=True)
if __name__ == "__main__":
# Test setup
nz_path = "$JUMEG_PATH_LOCAL_DATA"+"/exp/dcnn/ica_labeled/Juelich"
nz_fname = "4D_101611_CAU01A_100706_1432_1_c,rfDC_bcc,nr-raw-gdcnn.npz"
nz_fname = "205399_MEG94T_121220_1322_2_c,rfDC_EC_bcc - raw - gdcnn.npz"
nz_fname = "205399_MEG94T_121220_1322_2_c,rfDC_EC_bcc-raw-gdcnn.npz"
fnz = os.path.join(nz_path,nz_fname)
verbose = True
logger = setup_script_logging()
run1(fname=fnz)
#run1(fname=fnz)
ck_labels(fname=fnz)
......@@ -35,10 +35,8 @@ def run(fnconfig=None,basedir=None,data_meg=None,data_train=None,pattern='-raw.f
cfg = DCNN_CONFIG(verbose=verbose)
cfg.load(fname=fnconfig)
#-- init dcnn CLS
dcnn = DCNN(**cfg.config) # init object with config details
dcnn.verbose = True
#---
if basedir: # FB test
cfg.config['path']['basedir'] = expandvars(basedir)
if data_meg:
......@@ -46,11 +44,18 @@ def run(fnconfig=None,basedir=None,data_meg=None,data_train=None,pattern='-raw.f
if data_train:
cfg.config['path']['data_train']= expandvars(data_train) # input directory
#-- init dcnn CLS
dcnn = DCNN(**cfg.config) # init object with config details
dcnn.verbose = True
dcnn.get_info()
# ==========================================================
# run ICA auto labelling
# ==========================================================
if do_label_ica:
path_in = os.path.join(cfg.config['path']['basedir'],cfg.config['path']['data_meg'])
#path_in = os.path.join(cfg.config['path']['basedir'],cfg.config['path']['data_meg'])
path_in = dcnn.path.data_meg
# -- looper catch error via try/exception setup log2file
for fnraw in file_looper(rootdir=path_in,pattern=pattern,version=__version__,verbose=verbose,logoverwrite=True,log2file=log2file):
......@@ -70,7 +75,7 @@ def run(fnconfig=None,basedir=None,data_meg=None,data_train=None,pattern='-raw.f
# check ICA auto labelling
# ==========================================================
if do_label_check:
path_in = cfg.config['path']['data_train']
path_in = dcnn.path.data_train
for fname in file_looper(rootdir=path_in, pattern='*.npz',version=__version__,verbose=verbose,log2file=log2file,logoverwrite=False):
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment