def convert(cls, files: List[str], cluster_size: int, max_colors: int) -> BytesIO: images: List[Image.Image] = [Image.open(f) for f in files] compressed = [ Compressor.compress_pixels(im, cluster_size) for im in images ] if cluster_size > 1 else images color_mif, color_compressed = Compressor.compress_colors_collective( compressed, max_colors) mifs = [color_mif ] + [Im2Mif.mifify(im, color_mif) for im in color_compressed] names = ["colors.foo"] + [str(basename(f)) for f in files] ret = zip_(names, [StringIO(str(x)) for x in mifs]) [x.close() for x in images + compressed + color_compressed if x] return ret
def __init__(self, dump_name, dump_dir=".", compress=None): Compressor.__init__(self, compress) self.comms = {} self.dump_name = dump_name self.dump_dir = dump_dir self.process = MpiProcess() self._check_valid_compressor(compress) self._set_open() self.root_path = os.path.join(dump_dir, dump_name) self.procs_path = os.path.join(self.root_path, "procs") self.comms_path = os.path.join(self.root_path, "comms") if (MPI.COMM_WORLD.Get_rank() == 0): try: os.mkdir(self.root_path) os.mkdir(self.procs_path) os.mkdir(self.comms_path) self._create_ini_file() except Exception as e: print e MPI.COMM_WORLD.Abort() MPI.COMM_WORLD.Barrier()
def main(): print "start" comp = Compressor("MyFile.csv", 4, ",") comp.compress() comp.decompress("MyCompressedFile.csv") print "end"
if LORAWAN: lora = LoRa(mode=LoRa.LORAWAN) increase_delivary_chances_function = CoAP.increase_delivary_chances_functions[ "LORAWAN"] if SIGFOX: sigfox = Sigfox(mode=Sigfox.SIGFOX, rcz=Sigfox.RCZ1) increase_delivary_chances_function = CoAP.increase_delivary_chances_functions[ "SIGFOX"] RM = RuleManager() RM.addRule(rule_coap0) RM.addRule(rule_coap1) RM.addRule(rule_coap2) p = Parser() comp = Compressor(RM) dec = Decompressor(RM) coapC = CoAP.CoAPSM(p, comp, dec, IPv6_source, IPv6_dest, increase_delivary_chances_function) app_eui = binascii.unhexlify('00 00 00 00 00 00 00 00'.replace(' ', '')) app_key = binascii.unhexlify( '11 22 33 44 55 66 77 88 11 22 33 44 55 66 77 88'.replace(' ', '')) pycom.heartbeat(False) if LORAWAN: mac = lora.mac() print('MAC:') print(hex(mac[0]), end='-') print(hex(mac[1]), end='-')
if __name__ == '__main__': from Compressor import Compressor compressor = Compressor('images/image4.bmp', 8, 8, 100, 200) compressor.process()
from Compressor import Compressor from IPython import embed filepath = 'testfiles/news.txt' filepath = 'testfiles/book1.txt' # compressor = Compressor(filepath, data='baaaabaaabc', method='CM') # compressor.compress() # compressor.decompress() # compressor2 = Compressor(filepath, data='baacaabasaab', method='FC') # compressor2.compress() # compressor2.decompress() compressor = Compressor(filepath, method='CM') compressor.compress() result = compressor.compress_result embed() compressor.export_compress_result() compressor.decompress() compressor2 = Compressor(filepath, method='FC') compressor2.compress() compressor2.decompress() compressor = Compressor(filepath, method='CM') compressor.compress() compressor.export_compress_result() compressor.decompress()
from Model import Model from Compressor import Compressor from Read_bit import Read_bit from Decompressor import Decompressor import sys,os mode = sys.argv[1] filename = sys.argv[2] model = Model(filename.split(".")[0]+'.txt') #print model.c if mode == "-c": print "----------compressing-----------" c = Compressor(filename,model) c.compress() elif mode == "-d": print "---------decompressing----------" d = Decompressor(filename,model) d.decompress()
def calculate_eff(q_cap, work_fl, amb_work_fl_cond, amb_work_fl_evap, t_cond, overc_cond, t_evap, overh_evap, press_bef_turb, temp_bef_turb, pr_evap, amb_pr_evap, pr_cond, amb_pr_cond, pr_boil, amb_t_evap_in, amb_t_evap_out, amb_t_cond_in, amb_t_cond_out, amb_p_evap_out, amb_p_cond_out, isent_eff_turb, isent_eff_pump, elec_eff_pump, isent_eff_comp, eff_boil, fuel_heat_val, eff_turboeq): # The functions starts with creating tables to collect values of important attributes, each of them has 11 places: # indexes 1,2,3,4 for refrigeration cycle (1 is before the compressor, 4 is before evaporator), # indexes 5,6,7,8 - for power cycle (5 is before the turbine, 8 is before the boiler) # indexes 9, 10 - for condenser applied for both cycles pres = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] temp = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] enth = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] entr = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] temp[10] = t_cond - overc_cond temp[3] = temp[10] temp[7] = temp[10] temp[4] = t_evap pres[5] = press_bef_turb temp[5] = temp_bef_turb pres[8] = press_bef_turb / pr_boil # Calculation of the refrigeration cycle starts from throttling valve, as for the next step the value of enthalpy # in two-phase zone is needed. throttling_valve = ThrottlingValve(temp_in=temp[3], overc_cond=overc_cond, temp_out=temp[4], work_fl=work_fl) throttling_valve.calculate() enth[3] = throttling_valve.enth_in entr[3] = throttling_valve.entr_in enth[4] = throttling_valve.enth_out entr[4] = throttling_valve.entr_out pres[3] = throttling_valve.press_in pres[4] = throttling_valve.press_out enth[10] = throttling_valve.enth_in entr[10] = throttling_valve.entr_in pres[10] = pres[3] pres[7] = pres[3] pres[9] = pres[10] / pr_cond pres[2] = pres[9] pres[6] = pres[9] # The next step is evaporator: evaporator = Evaporator(enth_in=enth[4], temp_in=temp[4], overh=overh_evap, q_cap=q_cap, work_fl=work_fl, amb_work_fl=amb_work_fl_evap, pr=pr_evap, amb_pr=amb_pr_evap, amb_temp_in=amb_t_evap_in, amb_temp_out=amb_t_evap_out, amb_press_out=amb_p_evap_out) evaporator.set_attr_refr_cyc() evaporator.calculate() temp[1] = evaporator.temp_out pres[1] = evaporator.press_out enth[1] = evaporator.enth_out entr[1] = evaporator.entr_out throttling_valve.mass_fl = evaporator.mass_fl # The next step, after calculating output of evaporator, is a compressor. compressor = Compressor(press_in=pres[1], entr_in=entr[1], enth_in=enth[1], work_fl=work_fl, press_out=pres[2], isent_eff=isent_eff_comp, mass_fl=evaporator.mass_fl) compressor.calculate() temp[2] = compressor.temp_out enth[2] = compressor.enth_out entr[2] = compressor.entr_out # With the compressor power demand calculated, it is possible to calculate the power demand of the turbine using # the class Turboequipment, which was created for the purpose of the combined cycle. # Turbine: turbine = Turbine(cycle_name="cycle", press_in=pres[5], temp_in=temp[5], press_out=pres[6], work_fl=work_fl, isent_eff=isent_eff_turb) turbine.calculate() entr[5] = turbine.entr_in enth[5] = turbine.enth_in entr[6] = turbine.entr_out enth[6] = turbine.enth_out temp[6] = turbine.temp_out turboequipment = Turboequipment(compressor=compressor, turbine=turbine, eff=eff_turboeq) turboequipment.calculate() # Pump: pump = Pump(cycle_name="cycle", mass_fl=turbine.mass_fl, press_in=pres[7], press_out=pres[8], temp_in=temp[7], work_fl=work_fl, isent_eff=isent_eff_pump, elec_eff=elec_eff_pump) # For the instance of class Pump received mass flow as argument, the function calculate() will calculate powers. # Using additionally function Pump.calculate_powers() is unnecessary. pump.calculate() enth[7] = pump.enth_in entr[7] = pump.entr_in entr[8] = pump.entr_out enth[8] = pump.enth_out temp[8] = pump.temp_out # The last step is creating an instance of class Boiler in order to calculate the value of fuel demand. boiler = Boiler(temp_in=temp[8], temp_out=temp[5], press_out=pres[5], work_fl=work_fl, mass_fl=turbine.mass_fl, fuel_heat_val=fuel_heat_val, eff=eff_boil, pr=pr_boil) boiler.calculate_fuel_dem() # In order to calculate required mass flow of the ambient air in condenser: mixer = Mixer(press_in=pres[6], enth_in_1=enth[6], enth_in_2=enth[2], mass_fl_in_1=turbine.mass_fl, mass_fl_in_2=compressor.mass_fl, work_fl=work_fl) mixer.calculate() temp[9] = mixer.temp_out pres[9] = mixer.press_out enth[9] = mixer.enth_out entr[9] = mixer.entr_out # To be sure, that the TESPy software will read the points properly (it's unsure what phase the fluid will be), # the refrigeration condenser will be calculated, as it uses values of enthalpies in the function calculate(), # which, in combination with pressures, ensures proper choice of the parameters points on the p-h plot. condenser = Condenser(enth_out=enth[10], enth_in=enth[9], press_in=pres[9], mass_fl=mixer.mass_fl_out, work_fl=work_fl, amb_work_fl=amb_work_fl_cond, pr=pr_cond, amb_pr=amb_pr_cond, amb_temp_in=amb_t_cond_in, amb_temp_out=amb_t_cond_out, amb_press_out=amb_p_cond_out) condenser.set_attr_combined_cycle() condenser.calculate_combined_cyc() temp_in_cond = evaporator.generate_enthalpies_data(accuracy=10) efficiency = round( evaporator.q_cap / (boiler.fuel_dem * boiler.fuel_heat_val), 8) print(efficiency) return efficiency
def compression_process(): global config global logger mycompressor = Compressor(config, logger) mycompressor.run()