def test_list_folders(self): path = ospath.abspath('.') folder1 = ospath.join(path, 'folder1') + '/' sub1 = ospath.join(path, 'folder1', 'subfolder') + '/' folders = ospath.list_folders(path, subfolders=False, add_parent=False) self.assertEqual(folders, [folder1]) folders = ospath.list_folders(path, subfolders=False, add_parent=True) self.assertEqual(folders, [path, folder1]) folders = ospath.list_folders(path, subfolders=True, add_parent=False) self.assertEqual(folders, [folder1, sub1]) folders = ospath.list_folders(path, subfolders=True, add_parent=True) self.assertEqual(folders, [path, folder1, sub1])
def __init__(self, patient_list: list = None, readonly=False): """ Load a list of Patients (edf format). Resample if necessary. :param patient_list: A list of strings pointing to Patients """ if isinstance(patient_list, str): patient_list = ospath.list_folders(patient_list) assert isinstance(patient_list, list), 'patient_list must be type list' self.patients = [] # return if list is empty if len(patient_list) == 0: return None # must be either Patients or strings to make patients from. all_patients = all(['Patient' in str(type(x)) for x in patient_list]) all_strings = all([isinstance(x, str) for x in patient_list]) assert all_patients or all_strings, \ "patient_list must be either strings or Patients" if all_strings: # natural sorting of file list patient_list = sorted(patient_list, key=natsort_key) tqdm_loop = tqdm if all_strings else lambda x, *args, **kwargs: x for patient in tqdm_loop(patient_list, desc='Loading Patients'): try: patient = Patient(patient, readonly=readonly) self.add(patient) except Exception as e: print('Error in', patient) raise e return None
def index(folder): folders = ospath.list_folders(folder) folders = [f for f in folders if not any([x in f for x in EXCLUDED])] files = folders + ospath.list_files(folder, relative=True) fnames = [fname for fname in sorted(files) if fname not in EXCLUDED] header = os.path.basename(folder) html = Template(INDEX_TEMPLATE).render(names=fnames, header=header) return html
def main(root): folders = ospath.list_folders(root, subfolders=True, add_parent=True) folders = [f for f in folders if not any([exc in f for exc in EXCLUDED])] for folder in folders: print(f'index for {folder}') if '.git' in folder: continue if 'joblib' in folder: continue html = index(folder) with open(folder + '/index.html', 'w') as f: f.write(html)
import numpy as np import config as cfg import scipy import scipy.signal as signal from sleep import SleepSet import seaborn as sns import matplotlib.pyplot as plt from tqdm import tqdm import plotting import ospath from itertools import permutations plt.close('all') stimer.start('All calculations') files = ospath.list_folders(cfg.folder_unisens) stimer.start() ss = SleepSet(files, readonly=True) stimer.stop() # ss = ss.filter(lambda x: 'body' in x) # only take patients with body position sensors # ss = ss.filter(lambda x: x.drug_hrv==0 and x.drug_sleep==0) ss = ss.stratify() # only use matched participants p = ss[2] # apply this type of pvalue correction per table, # see from statsmodels.stats.multitest.multipletests correction = 'holm' # only analyse the first 3 REM cycles max_epochs = int(2 * 60 * 4.5)