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 ...@@ -12,11 +12,11 @@ import numpy as np
import mne import mne
from mne.preprocessing import ICA 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) 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 # compute downsampling frequency and final chop length
...@@ -115,7 +115,7 @@ class DCNN(object): ...@@ -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): info=None, verbose=False):
""" """
init via config dict: init via config dict:
...@@ -125,7 +125,7 @@ class DCNN(object): ...@@ -125,7 +125,7 @@ class DCNN(object):
---------- ----------
version : string, optional, default: None version : string, optional, default: None
n_jobs : int, optional, default: 1. n_jobs : int, optional, default: 1.
path : dict, optional, default: None path : dict, optional, default: {}
meg : dict, optional, default: {} meg : dict, optional, default: {}
init MEG CLS init MEG CLS
...@@ -143,7 +143,6 @@ class DCNN(object): ...@@ -143,7 +143,6 @@ class DCNN(object):
""" """
self.version = version self.version = version
self.path = path
self.config_info = info self.config_info = info
if res: if res:
...@@ -152,12 +151,16 @@ class DCNN(object): ...@@ -152,12 +151,16 @@ class DCNN(object):
self.model = {'res_time': None ,'res_space': None} self.model = {'res_time': None ,'res_space': None}
# the following will later be saved in one file for each experiment # 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._MEG = DCNN_MEG(**meg) # MEG system and data settings
self._ICA = DCNN_ICA(**ica) self._ICA = DCNN_ICA(**ica)
self._SOURCES = DCNN_SOURCES(**sources) self._SOURCES = DCNN_SOURCES(**sources)
self.n_jobs = n_jobs # set n_jobs for MEG not ICA self.n_jobs = n_jobs # set n_jobs for MEG not ICA
self.verbose = verbose self.verbose = verbose
@property
def path(self): return self._PATH
@property @property
def meg(self): return self._MEG def meg(self): return self._MEG
...@@ -183,9 +186,10 @@ class DCNN(object): ...@@ -183,9 +186,10 @@ class DCNN(object):
@verbose.setter @verbose.setter
def verbose(self ,v): def verbose(self ,v):
self._verbose = v self._verbose = v
self.meg.verbose = v self.path.verbose = v
self.ica.verbose = v self.meg.verbose = v
self.ica.verbose = v
self.sources.verbose = v self.sources.verbose = v
def _meg_filter_resample(self,raw=None): def _meg_filter_resample(self,raw=None):
...@@ -583,6 +587,7 @@ class DCNN(object): ...@@ -583,6 +587,7 @@ class DCNN(object):
# data = pickle.load(f) # data = pickle.load(f)
# load gDCNN data # load gDCNN data
fname= expandvars(fname)
logger.info('Start loading gDCNN results from disk ....\n -> {}'.format(fname)) logger.info('Start loading gDCNN results from disk ....\n -> {}'.format(fname))
npz = np.load(fname, allow_pickle=True) npz = np.load(fname, allow_pickle=True)
logger.info('Done loading gDCNN results from disk\n') logger.info('Done loading gDCNN results from disk\n')
...@@ -592,7 +597,7 @@ class DCNN(object): ...@@ -592,7 +597,7 @@ class DCNN(object):
logger.info("gDCNN data: {}\n{}".format(k, v)) logger.info("gDCNN data: {}\n{}".format(k, v))
# get details # 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)) logger.info("path:\n -> {}".format(self.path))
self.model = npz.get('model').item() # load dict self.model = npz.get('model').item() # load dict
...@@ -623,7 +628,7 @@ class DCNN(object): ...@@ -623,7 +628,7 @@ class DCNN(object):
logger.info("input fnout: ".format(fnout)) logger.info("input fnout: ".format(fnout))
name = op.basename(self.meg.fname).rsplit('.')[0] name = op.basename(self.meg.fname).rsplit('.')[0]
if not path_out: if not path_out:
path_out = self.path['data_train'] path_out = self.path.data_train
if not op.exists(path_out): if not op.exists(path_out):
makedirs(path_out) makedirs(path_out)
fnout = os.path.join(path_out, name + '-gdcnn.npz') fnout = os.path.join(path_out, name + '-gdcnn.npz')
...@@ -636,7 +641,7 @@ class DCNN(object): ...@@ -636,7 +641,7 @@ class DCNN(object):
self.model['fname_gdcnn'] = fnout 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()) meg=self.meg.dump(), ica=self.ica.dump(), sources=self.sources.dump())
logger.info('Done saving results to disk: {}'.format(fnout)) logger.info('Done saving results to disk: {}'.format(fnout))
...@@ -647,8 +652,6 @@ class DCNN(object): ...@@ -647,8 +652,6 @@ class DCNN(object):
# get details # get details
# --- init dicts # --- init dicts
msg = ["DCNN Info", msg = ["DCNN Info",
" -> path :",
" -> {}".format(self.path),
" -> sources:", " -> sources:",
" -> {}".format(self.sources), " -> {}".format(self.sources),
" -> model:", " -> model:",
...@@ -656,6 +659,7 @@ class DCNN(object): ...@@ -656,6 +659,7 @@ class DCNN(object):
logger.info("\n".join(msg)) logger.info("\n".join(msg))
# -- objs # -- objs
self.path.get_info()
self.meg.get_info() self.meg.get_info()
self.ica.get_info() self.ica.get_info()
self.sources.get_info() self.sources.get_info()
......
...@@ -617,10 +617,11 @@ def run1(fname=None,verbose=False): ...@@ -617,10 +617,11 @@ def run1(fname=None,verbose=False):
# -- init DCNN with raw # -- init DCNN with raw
dp = DCNN_PERFORMANCE(verbose=verbose) 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() ) logger.info( dp.meg.picks.dump() )
dp.run() #dp.run()
# ToDo FB # ToDo FB
# plot sources and components # plot sources and components
...@@ -634,16 +635,20 @@ def run1(fname=None,verbose=False): ...@@ -634,16 +635,20 @@ def run1(fname=None,verbose=False):
# ica.plot_sources(raw_chop,block=True) # ica.plot_sources(raw_chop,block=True)
# ica.plot_overlay(raw_chop, exclude=ica.exclude, picks='mag') # 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__": if __name__ == "__main__":
# Test setup # Test setup
nz_path = "$JUMEG_PATH_LOCAL_DATA"+"/exp/dcnn/ica_labeled/Juelich" 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 = "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) fnz = os.path.join(nz_path,nz_fname)
verbose = True verbose = True
logger = setup_script_logging() logger = setup_script_logging()
run1(fname=fnz) #run1(fname=fnz)
ck_labels(fname=fnz)
...@@ -35,23 +35,28 @@ def run(fnconfig=None,basedir=None,data_meg=None,data_train=None,pattern='-raw.f ...@@ -35,23 +35,28 @@ def run(fnconfig=None,basedir=None,data_meg=None,data_train=None,pattern='-raw.f
cfg = DCNN_CONFIG(verbose=verbose) cfg = DCNN_CONFIG(verbose=verbose)
cfg.load(fname=fnconfig) cfg.load(fname=fnconfig)
#-- init dcnn CLS
dcnn = DCNN(**cfg.config) # init object with config details
dcnn.verbose = True
#---
if basedir: # FB test if basedir: # FB test
cfg.config['path']['basedir'] = expandvars(basedir) cfg.config['path']['basedir'] = expandvars(basedir)
if data_meg: if data_meg:
cfg.config['path']['data_meg']= expandvars(data_meg) # input directory cfg.config['path']['data_meg']= expandvars(data_meg) # input directory
if data_train: if data_train:
cfg.config['path']['data_train']= expandvars(data_train) # input directory 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 # run ICA auto labelling
# ========================================================== # ==========================================================
if do_label_ica: 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'])
# -- looper catch error via try/exception setup log2file 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): for fnraw in file_looper(rootdir=path_in,pattern=pattern,version=__version__,verbose=verbose,logoverwrite=True,log2file=log2file):
logger.info(fnraw) logger.info(fnraw)
...@@ -70,7 +75,7 @@ def run(fnconfig=None,basedir=None,data_meg=None,data_train=None,pattern='-raw.f ...@@ -70,7 +75,7 @@ def run(fnconfig=None,basedir=None,data_meg=None,data_train=None,pattern='-raw.f
# check ICA auto labelling # check ICA auto labelling
# ========================================================== # ==========================================================
if do_label_check: 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): 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