Пример #1
0
	def trans_dynamic_netattr(self, subject_scan, atlas_name, feature_name, window_length, step_size, value):
		if value.ndim == 2:  # 这里要改一下
			arr = netattr.DynamicAttr(value.swapaxes(0,1), atlas.get(atlas_name), window_length, step_size, subject_scan, feature_name)
			return arr
		else:
			net = netattr.DynamicNet(value.swapaxes(0,2).swapaxes(0,1), atlas.get(atlas_name), window_length, step_size, subject_scan, feature_name)
			return net
Пример #2
0
 def get_dynamic_net(self,
                     scan,
                     atlas_name,
                     window_length,
                     step_size,
                     comment={}):
     """ Return to dynamic attr object directly """
     query = dict(scan=scan, comment=comment)
     col = self.getcol(atlas_name, 'BOLD.net', window_length, step_size)
     if self.dndb[col].find_one(query) == None:
         raise NoRecordFoundException((scan, atlas, 'BOLD.net'))
     else:
         records = self.dndb[col].find(query).sort([('slice',
                                                     pymongo.ASCENDING)])
         atlasobj = atlas.get(atlas_name)
         net = netattr.DynamicNet(None, atlasobj, window_length, step_size,
                                  scan, 'BOLD.net')
         for record in records:
             net.append_one_slice(pickle.loads(record['value']))
         return net
Пример #3
0
def load_single_dynamic_network(scan, atlasobj, dynamic_conf, rootFolder = rootconfig.path.feature_root):
	"""
	Return a DynamicNet (net.data[timeIdx, tickIdx, tickIdx])
	"""
	if type(atlasobj) is str:
		atlasobj = atlas.get(atlasobj)
	window_length = dynamic_conf[0]
	step_size = dynamic_conf[1]
	start = 0
	dynamic_foler_path = os.path.join(rootFolder, scan, atlasobj.name, 'bold_net', 'dynamic %d %d' % (step_size, window_length))
	time_slice_count = len(list(os.listdir(dynamic_foler_path))) - 1 # get rid of timeseries.csv
	dynamic_net = netattr.DynamicNet(np.zeros((atlasobj.count, atlasobj.count, time_slice_count)), atlasobj, window_length, step_size, scan = scan, feature_name = 'BOLD.net')
	timeIdx = 0
	while True:
		dynamic_net_filepath = os.path.join(dynamic_foler_path, 'corrcoef-%d.%d.csv' % (start, start+window_length))
		if os.path.exists(dynamic_net_filepath):
			time_slice_net = load_csvmat(dynamic_net_filepath)
			dynamic_net.data[:, :, timeIdx] = time_slice_net
			timeIdx += 1
			start += step_size
		else:
			break
	return dynamic_net
Пример #4
0
	def run_feature(self, feature_name, feature_config):
		"""
		Override super run_feature.
		Stores csv files to MongoDB directly
		"""
		if feature_config['file_type'] != '.csv':
			# only supports csv features
			return
		in_file_list, out_file_list = self.get_feature_file_path(feature_config)
		if self.is_dynamic and feature_config['modal'] == 'BOLD':
			if len(in_file_list) < 1:
				print('==Not Exist:', self.mriscan, self.atlasname, feature_name)
				return
			if feature_name.find('net') != -1:
				feature = netattr.DynamicNet(None, self.atlasname, self.dataconfig['dynamic']['window_length'], self.dataconfig['dynamic']['step_size'], scan = self.mriscan, feature_name = feature_name)
				for file in in_file_list:
					feature.append_one_slice(load_csvmat(file))
				try:
					self.mdb.save_dynamic_network(feature)
				except mongodb_database.MultipleRecordException:
					if self.force:
						# delete and overwrite
						self.mdb.remove_dynamic_network(self.mriscan, self.dataconfig['dynamic']['window_length'], self.dataconfig['dynamic']['step_size'], self.atlasname)
						self.mdb.save_dynamic_network(feature)
					else:
						print('!!!Already Exist: %s %s %s. Skipped' % (self.mriscan, self.atlasname, feature_name))
			else:
				feature = netattr.DynamicAttr(None, self.atlasname, self.dataconfig['dynamic']['window_length'], self.dataconfig['dynamic']['step_size'], scan = self.mriscan, feature_name = feature_name)
				for file in in_file_list:
					feature.append_one_slice(load_csvmat(file))
				try:
					self.mdb.save_dynamic_attr(feature)
				except mongodb_database.MultipleRecordException:
					if self.force:
						# delete and overwrite
						self.mdb.remove_dynamic_attr(self.mriscan, feature_name, self.dataconfig['dynamic']['window_length'], self.dataconfig['dynamic']['step_size'], self.atlasname)
						self.mdb.save_dynamic_attr(feature)
					else:
						print('!!!Already Exist: %s %s %s. Skipped' % (self.mriscan, self.atlasname, feature_name))
		elif self.is_dynamic:
			# dynamic but not BOLD feature
			return
		else:
			# not dynamic
			for file in in_file_list:
				if not os.path.isfile(file):
					print('==Not Exist:', self.mriscan, self.atlasname, feature_name)
					continue
				if feature_name.find('net') != -1:
					feature = netattr.Net(load_csvmat(file), self.atlasname, self.mriscan, feature_name)
				else:
					feature = netattr.Attr(load_csvmat(file), self.atlasname, self.mriscan, feature_name)
				try:
					self.mdb.save_static_feature(feature)
				except mongodb_database.MultipleRecordException:
					if self.force:
						# delete and overwrite
						self.mdb.remove_static_feature(self.mriscan, self.atlasname, feature_name)
						self.mdb.save_static_feature(feature)
					else:
						print('!!!Already Exist: %s %s %s. Skipped' % (self.mriscan, self.atlasname, feature_name))