'''Note: This does not work. I'm not too sure what happened, but I ran small tests and they seemed to be fine, but on the big one in created an n-1 number of identical files plus an empty one. Not sure what happened there.''' from ipyparallel import Client from WorkingPyDemo import * from time import time def initialize(): """ Write a function that initializes a Client object, creates a Direct View with all available engines, and imports scipy.sparse as spar on all engines. Return the DirectView. """ client = Client() # Only works if a cluster is running. dview = client[:] dview.execute("from WorkingPyDemo import *") #needed for others dview.block = True return dview if __name__ == "__main__": scenes = file_extractor(folder_name) images = image_extractor(scenes) dview = initialize() list_dic = np.load("first_dict.npy", allow_pickle=True) bins = [21,32,48] starttime = time() def save_an_image(filename): """ Takes in the filename and writes the compressed image """ list_dic = np.load("first_dict.npy", allow_pickle=True) bins = [21,32,48] image, new_error, diff = huffman(filename, 4, False) encoded_string = encoder(new_error, list_dic, diff, bins) inletters = bitstring_to_bytes(encoded_string) if filename[-5:] == ".tiff": newname = filename[:-5] else: newname = filename[:-4] with open(newname + "_Compressed.txt", 'wb') as f: f.write(inletters) def decode_an_image(filename): list_dic = np.load("first_dict.npy", allow_pickle=True) bins = [21,32,48] image, new_error, diff = huffman(filename, 4, False) if filename[-5:] == ".tiff": newname = filename[:-5] else: newname = filename[:-4] encoded_string2 = bytes_to_bitstring(read_from_file(newname + "_Compressed.txt")) reconstruct_image = decoder(encoded_string2, list_dic, bins, False) dview.map_sync(save_an_image, images[0]) # dview.map_sync(decode_an_image, images[0:6]) print(time() - starttime)