def convertSimpleToInput(simple): inputWords=simple.inputWords labelsList=[] inputWordsList=[] for w in inputWords: labelsList.append(w.label) inputWordsList.append(w.text) return inputData.inputData("1",inputWordsList,labelsList)
def __init__(self, interface): self.interface = interface self.table = vtk.vtkTable self.colorBar = { 'Point1': [0, 0, 1, 0], 'Point2': [0.5, 1, 1, 0], 'Point3': [1, 1, 0, 0] } self.input_Data = inputData.inputData()
def get_normals(vtkclassdict): inputdata = inputData.inputData() labels = [] dataset_concatenated = [] # This looks really confusing but is really not for folderclass, vtklist in vtkclassdict.items(): try: with open(folderclass + ".pickle", 'rb') as f: dataset = pickle.load(f) normal_features = [] for vtkfilename in vtklist: #We'll load the same files and get the normals features = inputdata.load_features( vtkfilename, feature_points=["Normals"]) normal_features.append(features) #This reshaping stuff is to get the list of points, i.e., all connected points #and the corresponding label which is the normal in this case #The data in the dataset contains lists with different sizes normal_features = np.array(normal_features) featshape = np.shape(normal_features) labels.extend( normal_features.reshape(featshape[0], featshape[1], -1)) dsshape = np.shape(dataset) dataset_concatenated.extend( dataset.reshape(dsshape[0], dsshape[2], dsshape[3], -1)) except Exception as e: print('Unable to process', pickle_file, ':', e) raise # lens = np.array([len(dataset_concatenated[i]) for i in range(len(dataset_concatenated))]) # mask = np.arange(lens.max()) < lens[:,None] # padded = np.zeros(mask.shape + (3,)) # padded[mask] = np.vstack((dataset_concatenated[:])) # return np.array(padded), np.array(labels) return np.array(dataset_concatenated), np.array(labels)
def main(): #read the config file config = json.load(open('config.json')) #initalte the class try: dataClass = inputData(config) except FileNotFoundError as e: print(e.__str__()) exit() # Treating the file to adhere to the given formats dataClass.treatColsDataType() # for col in dataClass.Dataframe.columns: # print(col, type(dataClass.Dataframe.loc[0,col])) # For each collection modify the startup Details for collections in dataClass.validator['collections']: collectionName = list(collections.keys())[0] collectionDetails = list(collections.values())[0] #Modify database infoDict = dataClass.modifyInfo(collectionName, collectionDetails) dataClass.updateDatabase(collectionName, infoDict) #Validate and filter the non conforming data. Let us not bother too much now # startupData.validatedData() #change the structure of startupInfo # startupInfoList = startupData.modifyStartupInfo() # # insert data in collection # startupData.updateDatabase('startupInfo',startupInfoList) # change the structure of startupInfo # fundingInfoList = startupData.modifyFundingInfo() # insert data in collection # startupData.updateDatabase('fundingInfo', fundingInfoList) print("Finished updating the database") print()
import numpy as np from vtk.util import numpy_support parser = argparse.ArgumentParser(description='Shape Variation Analyzer') parser.add_argument('--dataPath', action='store', dest='dirwithSub', help='folder with subclasses', required=True) if __name__ == '__main__': args = parser.parse_args() dataPath = args.dirwithSub inputdata = inputData.inputData() data_folders = inputdata.get_folder_classes_list(dataPath) print(data_folders) polydata = vtk.vtkPolyData() for datafolders in data_folders: i = 0 vtklist = glob.glob(os.path.join(datafolders, "*.vtk")) print(vtklist) matfile = glob.glob(os.path.join(datafolders, "*.mat")) matfile_str = ''.join(map(str, matfile)) print('matfile', matfile_str) for matlabfilename in matfile: mat_contents = sio.loadmat(matlabfilename, squeeze_me=True)
def main(): print("Cut Calculator by Pyton") inputData()
import anneal import inputData if __name__ == '__main__': inputData.inputData() totalDistanceAnneal, pathAnneal = anneal.anneal() #print("Stimulated Annealing Results - ") #print("The path to be taken is:\n") print(" ".join(str(x) for x in pathAnneal)) #print("\nThe total distance covered will be: "+str(totalDistanceAnneal)+" units\n")
def generate(args): np.set_printoptions(threshold='nan') print('###########In generation shape#############') # #dataPathtrain=args.dirwithSubtrain #dataPathtest=args.dirwithSubtest pickle_file = args.picklefile pickle_file_output = args.pickle_file_new # Get the data from the folders with vtk files inputdata = inputData.inputData() fi = open(pickle_file, 'rb') dataset = pickle.load(fi) test_labels = dataset["test_labels"] train_labels = dataset["train_labels"] valid_labels = dataset["valid_labels"] test_dataset = dataset["test_dataset"] train_dataset = dataset["train_dataset"] valid_dataset = dataset["valid_dataset"] print(test_labels) #data_folders_train = inputdata.get_folder_classes_list(dataPathtrain) #data_folders_test = inputdata.get_folder_classes_list(dataPathtest) #pickled_datasets_train,vtklisttrain = inputdata.maybe_pickle(data_folders_train, 6, feature_points=args.feature_names) #pickled_datasets_test,vtklisttest = inputdata.maybe_pickle(data_folders_test, 0, feature_points=args.feature_names) #Create the labels, i.e., enumerate the groups #dataset_train,labels_train = get_labels(pickled_datasets_train) #print('pickled_datasets_train',pickled_datasets_train,'pickled_datasets_test',pickled_datasets_test) #dataset_test,labels_test = get_labels(pickled_datasets_test) # Compute the total number of shapes and train/test size total_number_shapes_train = train_dataset.shape[0] total_number_shapes_test = test_dataset.shape[0] print('total number of shapes train', total_number_shapes_train) print('total number of shapes test', total_number_shapes_test) print('labels to train', train_labels, 'labels to test', test_labels) #num_train = int(args.train_size*total_number_shapes_train) #num_valid = int((total_number_shapes_train - num_train)*args.validation_size) # Randomize the original dataset #print('shape before randomize',dataset_train.shape) shuffled_dataset, shuffled_labels = inputdata.randomize( train_dataset, train_labels) #print('shape after randomize',shuffled_dataset.shape) #shuffled_dataset_test,shuffled_labels_test = inputdata.randomize(dataset_test,labels_test) #shuffled_dataset = np.reshape(shuffled_dataset, (total_number_shapes_train, -1)) #print('shape after reshape',shuffled_dataset.shape) #shuffled_dataset_test = np .reshape(shuffled_dataset_test,(total_number_shapes_test,-1)) # Generate SMOTE with out including the valid/test samples, in some cases, this may raise an error # as the number of samples in one class is less than 5 and SMOTE cannot continue. Just run it again dataset_res, labels_res = generate_with_SMOTE(shuffled_dataset, shuffled_labels) # SANITY CHECKS print('dataset train', np.shape(train_dataset)) print('labels train', np.shape(train_labels)) #print('dataset_res',np.shape(dataset_res)) #print('labels_res',np.shape(labels_res)) #print('num_train', num_train) #print('num_valid', num_valid) print('number of labels', np.shape(np.unique(train_labels))) #print('number of labels resampled',np.shape(np.unique(labels_res))) #print('Labels resampled',np.unique(labels_res).tolist()) print('test labels', test_labels) #SVM_classification(dataset_res,labels_res,dataset_test,labels_test) #clf=LinearSVC(random_state=0) #clf=GaussianProcessClassifier(1.0 * RBF(1.0)) #clf.fit(dataset_res,labels_res) #prediction = clf.predict(dataset_test) #for i in range(0,total_number_shapes_test): # head,tail = os.path.split(vtklisttest[i]) # print(tail,prediction[i]) #PCA_plot(dataset,labels,dataset_res,labels_res) try: f = open(pickle_file_output, 'wb') save = { #'train_dataset': dataset_res, #'train_labels': labels_res, 'train_dataset': dataset_res, 'train_labels': labels_res, 'valid_dataset': valid_dataset, 'valid_labels': valid_labels, # 'test_dataset': dataset[num_train + num_valid:], #'test_labels': labels[num_train + num_valid:] 'test_dataset': test_dataset, 'test_labels': test_labels } pickle.dump(save, f, pickle.HIGHEST_PROTOCOL) #f.close() except Exception as e: print('Unable to save data to', pickle_file, ':', e) raise
# -*- coding: utf-8 -*- """ Created on Tue May 16 00:40:26 2017 @author: Administrator """ from multiprocessing.dummy import Pool as ThreadPool import numpy as np import pandas as pd from inputData import inputData from connect import connect #test on data preparation inp = inputData() inp.welcome() inp.requestData() inp.represent() #test on connection con = connect(inp.url) content = con.conn() title = con.getHeader(content)