def driver(extracted_files, src_name): postprocessed_files = [] sub_scan = {} for i in extracted_files: folder = get_folder_name(i['path']) if (folder not in sub_scan.keys()): sub_scan[folder] = {} sub_scan[folder].update({i['name']: i['path']}) else: sub_scan[folder].update({i['name']: i['path']}) postprocessed_files = list_directory(f"{POSTPROCESS}/{src_name}") total_files = len(sub_scan) count = 0 print("\n" + "-" * 25 + "PROGRESS" + "-" * 25 + "\n") update_progress(count, total_files) print("\n" + "-" * 58 + "\n") for k in sub_scan: count += 1 if (k not in postprocessed_files): if (not postprocess(k, src_name, sub_scan)): continue print("\n" + "-" * 25 + "PROGRESS" + "-" * 25 + "\n") update_progress(count, total_files) print("\n" + "-" * 58 + "\n")
def divide(name, path, parts): print("\nDIVIDING FILES\n") divided_dirs = [] dirs = [] dir_list = os.listdir(path) num_dir = len(dir_list) div = int(num_dir / parts) for i in range(1, num_dir + 1): if (i % div == 0): dirs.append(dir_list[i - 1]) divided_dirs.append(dirs) dirs = [] else: dirs.append(dir_list[i - 1]) if (dirs not in divided_dirs and len(dirs) != 0): divided_dirs.append(dirs) dir_count = 0 file_count = 0 for divide in divided_dirs: dir_count += 1 for folder in divide: file_count += 1 print(f"\nDIR COUNT:{dir_count} FILE COUNT: {file_count}\n") count = 0 for divide in divided_dirs: os.makedirs(f"{DIVIDE}/{name}") divided_file_paths = [] count += 1 for folder in divide: dest_directory = f"{DIVIDE}/{name}/{folder}" src_directory = f"{path}/{folder}" os.makedirs(dest_directory) shutil.copyfile(f"{src_directory}/mri.nii", f"{dest_directory}/mri.nii") shutil.copyfile(f"{src_directory}/pet.nii", f"{dest_directory}/pet.nii") shutil.make_archive(f"{DIVIDE}/{name}_{count}", 'zip', f"{DIVIDE}/{name}") shutil.rmtree(f"{DIVIDE}/{name}") update_progress(count, file_count)
def processData(rawData): STRONG_ACCELERATION_PRECISION = 7.5 output = [] currentDate = 0 print('Processing the data...') general.update_progress(0) print 'Hello' for i in range(0, len(rawData)): error = False blockID = int(rawData[i][0])*256 + int(rawData[i][1]) verificationBlock = int(rawData[i][22])*256 + int(rawData[i][23]) line = [] if blockID != i: print('Error on line {} : block ID inconsistent.\n Please have a look at the raw-data file to figure out the error.'.format(i+1)) error = True if verificationBlock != 28785: print('Error on line {} : verification bytes inconsistent.\n Please have a look at the raw-data file to figure out the error.'.format(i+1)) error = True if error == False: line.append(int(rawData[i][0])*256+int(rawData[i][1])) line.append(currentDate) for x in range(1,11): data = [int(rawData[i][x*2+1]),int(rawData[i][x*2]),0,0] b = struct.pack('4B', *data) line.append(struct.unpack('>f', b)[0]) constShift1 = 2 constShift2 = 5 #for j in range(0,3): # if line[constShift2+j] < STRONG_ACCELERATION_PRECISION : # del line[constShift2+j] # constShift2 -= 1 # else: # del line[constShift1+j] # constShift1 -= 1 # constShift2 -= 1 output.append(line) currentDate += 100.8 general.update_progress(i/len(rawData)) else: raise Exception('Error with the data') return output
def downloadOverSerial(): communicationError = False serialSocket = chooseSerialPort() print "Connected" # Ask for the number of blocks stored on EEPROM : serialSocket.write(chr(125)) print "Asking for #bytes" time.sleep(2) # Wait for a response : waiting = True requestTime = time.time() while waiting: if serialSocket.inWaiting() > 1: numberOfBlocks = ord(serialSocket.read(1)) * 256 + ord(serialSocket.read(1)) print ( "There are {} datapoints stored on the device ({} bytes) !".format(numberOfBlocks, numberOfBlocks * 25) ) waiting = False elif time.time() - requestTime > 2: print "Connection timout : is the device still plugged ?" waiting = False communicationError = True serialSocket.close() time.sleep(0.1) if communicationError == False: print "Let's download the data" rawData = [] general.update_progress(0) # Download all the blocks 1 by 1 : for i in range(0, numberOfBlocks + 1): rawData.append(receiveABlock(serialSocket)) general.update_progress(float(float(i) / float(numberOfBlocks))) general.update_progress(1) print ("All data downloaded from device !") fileManagement.createRawDatafile(rawData) else: sys.exit("Communication error") return rawData
def processData(rawData): STRONG_ACCELERATION_PRECISION = 7.5 date = [] acceleration = [] rotation = [] pressure = [] currentDate = 0 print('Processing the data...') general.update_progress(0) for i in range(0, len(rawData)): error = False blockID = int(rawData[i][0])*256 + int(rawData[i][1]) currentDate = currentDate + int(rawData[i][2])*256 + int(rawData[i][3]) verificationBlock = int(rawData[i][24])*256 + int(rawData[i][25]) line = [] if blockID != i: print('Error on line {} : block ID inconsistent.\n Please have a look at the raw-data file to figure out the error.'.format(i+1)) error = True if verificationBlock != 31565: print('Error on line {} : verification bytes inconsistent.\n Please have a look at the raw-data file to figure out the error.'.format(i+1)) error = True if error == False: for x in range(0,13): if x == 1 : line.append(date) else: line.append(int(rawData[i][x*2])*256+int(rawData[i][x*2+1])) date.append(currentDate) acceleration.append([0,0,0]) #Select the appropriate acceleration : for j in range(0,3): if line[2+j] < STRONG_ACCELERATION_PRECISION : acceleration[i][j]=line[5+j] else: acceleration[i][j]=line[2+j] rotation.append(line[9:11]) pressure.append(line[12]) general.update_progress(i*0.4/len(rawData)) else: raise Exception('Error with the data') velocity = [[0,0,0]] for i in range(1,len(acceleration)-1): velocityLine = [] for j in range(0,3): velocityLine.append((((acceleration[i-1][j]+acceleration[i][j])*(date[i]-date[i-1])/2)+((acceleration[i][j]+acceleration[i+1][j])*(date[i+1]-date[i])/2))/2) velocity.append(velocityLine) general.update_progress(0.4+i*0.3/(len(acceleration)-1)) velocity.append([0,0,0]) position = [[0,0,0]] for i in range(1,len(velocity)-1): positionLine = [] for j in range(0,3): positionLine.append((((velocity[i-1][j]+velocity[i][j])*(date[i]-date[i-1])/2)+((velocity[i][j]+velocity[i+1][j])*(date[i+1]-date[i])/2))/2) position.append(positionLine) general.update_progress(0.7+i*0.3/(len(velocity)-1)) position.append([0,0,0]) general.update_progress(1) return [date, acceleration, rotation, pressure, velocity, position]