Пример #1
0
def main_loader(path, dataset_name=None, variable_name=None, num_channels=None, sampling_rate=None, epoch_length=1, mapping=True):
	if dir_exist(path):
		# get files only
		files = [file for file in os.listdir(path) if '.' in file]

		# look for metadata files
		for file in files:
			file_name, ext = file.split('.')
			if file_name == 'metadata' and ext == 'dat':
				return prainsa_loader(path, mapping).create_Prainsa()

		# look for Matlab files
		for file in files:
			file_name, ext = file.split('.')
			if ext == 'mat':
				return matlab_loader(file.path, dataset_name, variable_name, num_channels, sampling_rate, epoch_length).create_Prainsa()

		# look for NumPy files
		for file in files:
			file_name, ext = file.split('.')
			if ext == 'npy' or ext == 'npz':
				return numpy_loader(file.path, dataset_name, variable_name, num_channels, sampling_rate, epoch_length).create_Prainsa()

	elif file_exist(path):
		file_name, ext = os.path.splitext(path)
		if ext not in ['.mat', '.npz', '.npy']:
			raise Exception('File type is not recognized. Must be a ".mat", ".npz", or ".npy" file!')
		elif ext == '.mat':
			return matlab_loader(path, dataset_name, variable_name, num_channels, sampling_rate, epoch_length).create_Prainsa()
		else:
			return numpy_loader(path, dataset_name, variable_name, num_channels, sampling_rate, epoch_length).create_Prainsa()
	
	else:
		raise FileNotFoundError(errno.ENOENT, os.strerror(errno.ENOENT), '{}'.format(path))
Пример #2
0
	def load_lags(self):
		start = time()
		if file_exist('{}/lags.npz'.format(self.path)):
			lags_dict = np.load('{}/lags.npz'.format(self.path), mmap_mode=self.mapping)
			for key in [k for k in lags_dict.keys()]:
				self.prainsa_object.lags_dict[key] = lags_dict[key]
		end = time()
		self.loading_time += end - start
Пример #3
0
	def load_xcorr(self):
		start = time()
		if file_exist('{}/xcorr.npz'.format(self.path)):
			xcorr_dict = np.load('{}/xcorr.npz'.format(self.path), mmap_mode=self.mapping)
			for key in [k for k in xcorr_dict.keys()]:
				self.prainsa_object.xcorr_dict[key] = xcorr_dict[key]
		end = time()
		self.loading_time += end - start
Пример #4
0
	def load_dataset(self):
		start = time()
		if not file_exist('{}/dataset.npz'.format(self.path)):
			raise FileNotFoundError(errno.ENOENT, os.strerror(errno.ENOENT), '{}/dataset.npz'.format(self.path))
		self.dataset = np.load('{}/dataset.npz'.format(self.path), mmap_mode=self.mapping)
		self.dataset = self.dataset['dataset']
		end = time()
		self.loading_time += end - start
Пример #5
0
def mkdirs(dir_path: str):
    """
    make the dictionary according to the dir_path
    :param dir_path: the path of dir to be created
    :return:
    """
    if not file_exist(dir_path):
        os.makedirs(dir_path)
Пример #6
0
	def load_bands(self):
		start = time()
		if file_exist('{}/bands.npz'.format(self.path)):
			bands_dict = np.load('{}/bands.npz'.format(self.path), mmap_mode=self.mapping)
			available_keys = [k for k in bands_dict.keys() if k in ['delta','theta','alpha','beta','gamma']]
			for key in available_keys:
				self.prainsa_object.__dict__[key] = bands_dict[key]
		end = time()
		self.loading_time += end - start
Пример #7
0
 def change_file(self, file_name):
     '''changes the reader's file, leaves the previous file and \
         returns 0 if file not found, 1 for operation succesful'''
     file_name = file_name + ".code"
     if (file_exist(file_name)):
         self.file = open(file_name)
         return 1
     else:
         self.file = ""
         return 0
Пример #8
0
 def reload(self):
     """Load the data stored in the JSON file at __file_path if it exists,
     otherwise, do nothing.
     """
     if file_exist(self.__file_path):
         with open(self.__file_path, "r", encoding="UTF-8") as file:
             data = read_data(file)
             for key, value in data.items():
                 instance = BaseModel(**value)
                 FileStorage.__objects[key] = instance
Пример #9
0
	def load_metadata(self):
		start = time()
		if not file_exist('{}/metadata.dat'.format(self.path)):
			raise FileNotFoundError(errno.ENOENT, os.strerror(errno.ENOENT), '{}/metadata.dat'.format(self.path))
		with open('{}/metadata.dat'.format(self.path),'r') as metadata:
			for line in metadata:
				parameter, value = line.split('=')
				if parameter == 'name':
					self.__dict__[parameter] = value[:-1]
				else:
					self.__dict__[parameter] = int(value)
		end = time()
		self.loading_time += end - start
Пример #10
0
def check_path(path):
    if not file_exist(path):
        makedir(path)
Пример #11
0
 def check_path(self):
     if not file_exist(self.path):
         raise FileNotFoundError(errno.ENOENT, os.strerror(errno.ENOENT),
                                 self.path)