def record_temperatures(self): p = Progress(self.num_tiles, 'Getting hot...') iter_elevationfile = iter(self.parse(self.elevationfile)) iter_waterfile = iter(self.parse(self.waterfile, give_coords=False)) for tile in range(self.num_tiles): p.update() ele_char, coord = next(iter_elevationfile) wat_char = next(iter_waterfile) if coord[0] == 0 and self.temperaturefile.written == True: self.temperaturefile._write('\n') else: pass temp_lat = self.get_temperature_LATITUDE(coord[1]) temp_ele = self.get_temperature_ELEVATION(int(ele_char)) temp_wat = self.get_temperature_WATER(wat_char, coord[1]) total = temp_lat+temp_ele+temp_wat+random.randint(0, 2)/10.0 if total > 9: total = 9 elif total < 0: total = 0 else: total = int(round(total)) self.temperaturefile._write(str(total)) p.close()
def load_seeds(self): p = Progress(self.num_tiles, 'Loading seeds...') for char, coord in self.parse(self.seedfile): p.update() if char == '1': self.seeds.add(coord) else: continue p.close()
def record_seeds(self): p = Progress(self.map_size[1], 'Getting seeds...') for y in range(self.map_size[1]): p.update() self.seedfile.skipline_if_written() for x in range(self.map_size[0]): test = (x, y) if test in self.seeds: self.seedfile._write('1') else: self.seedfile._write(' ') p.close()
def draw_tiles(self): p = Progress(self.map_size[1], 'Drawing tiles...') y = -1 for line in self.tilefile._parse(): p.update() y += 1 x = -1 for char in line.strip(): x += 1 tile = self.tm.tile_map[char] position = (x*self.tile_length, y*self.tile_length) CanvasTile(self, tile, position) p.close() raw_input()
def record_watercount(self): p = Progress(self.num_tiles, 'Getting H2O...') for char, coord in self.parse(self.elevationfile): p.update() if coord[0] == 0 and self.waterfile.written == True: self.waterfile._write('\n') else: pass elevation = int(char) if elevation <= self.sealevel: watercount = self.water_symbol else: watercount = self.get_watercount(coord) self.waterfile._write(str(watercount)) p.close()
def record_tiles(self): p = Progress(self.num_tiles, 'Building tiles...') iter_elevationfile = iter(self.parse(self.elevationfile)) iter_temperaturefile = iter(self.parse(self.temperaturefile, give_coords=False)) for tile in range(self.num_tiles): p.update() ele_char, coord = next(iter_elevationfile) temp_char = next(iter_temperaturefile) corrected_temp = float(temp_char)/9*self.tRange+self.coldest tile_symbol = self.tm.choose_tile(int(ele_char), corrected_temp) if coord[0] == 0 and self.tilefile.written == True: self.tilefile._write('\n') else: pass if tile_symbol == None: raise Exception(str(ele_char)+'\t'+str(corrected_temp)) else: self.tilefile._write(str(tile_symbol)) p.close()
def cleanup_elevations(self): total_entries = self.raw_elevationfile.get_total_entries() p = Progress(total_entries, 'Getting high...') dummymap = File('dummy') if dummymap.written == True: dummymap._delete() elevationMEMORY = {} memCOUNT = 0 for strcoord, floatelevation in self.raw_elevationfile.parse(): p.update() coord = self.str2coord(strcoord) # elevation = int(round(float(floatelevation), 0)) if elevation > 9: elevation = 9 elif elevation < 0: elevation = 0 else: pass elevationMEMORY[coord] = elevation memCOUNT += 1 if memCOUNT > self.memLIMIT or p.progress == total_entries: if self.elevationfile.written == False: for y in range(self.map_size[1]): self.elevationfile.skipline_if_written() for x in range(self.map_size[0]): try: elevation = elevationMEMORY[(x, y)] except KeyError: elevation = 0 self.elevationfile._write(str(elevation)) else: y = -1 for line in self.elevationfile._parse(): dummymap.skipline_if_written() y += 1 x = -1 for char in line: x += 1 if char != '0': dummymap._write(char) else: try: elevation = elevationMEMORY[(x, y)] except KeyError: elevation = 0 dummymap._write(str(elevation)) self.elevationfile._delete() dummymap._rename(self.elevationfile.filename) self.elevationfile = dummymap dummymap = File('dummy') elevationMEMORY = {} memCOUNT = 0 else: continue p.close()
def record_rawelevations(self): if self.seeds == set(): self.load_seeds() else: pass total_count = len(self.seeds)-1 p = Progress(total_count, 'Growing seeds...') dummyfile = FaFile('dummy.fa') if dummyfile.written == True: dummyfile._delete() elevation_MEMORY = {} memCOUNT = 0 # ex. {coord:elevation} for seed in self.seeds: p.update() for coord, rel_coord in self.get_tiles_within_radius(self.mountain_check_radius, seed): randfactor = random.randint(0, 2)/10.0 dh = 5.0/(abs(rel_coord[0])+abs(rel_coord[1])+1)**(1.0/self.mountain_fatness)+randfactor try: elevation_MEMORY[coord] += dh except KeyError: elevation_MEMORY[coord] = dh memCOUNT += 1 if memCOUNT > self.memLIMIT or p.progress == total_count: if self.raw_elevationfile.written == False: for key, value in self.coord2str(elevation_MEMORY): self.raw_elevationfile.entry(key, str(value)) elevation_MEMORY = {} memCOUNT = 0 else: str_eleMEMORY = self.construct_str_eleMEMORY(elevation_MEMORY) for key, value in self.raw_elevationfile.parse(): try: str_eleMEMORY[key] += float(value) except KeyError: dummyfile.entry(key, str(value)) self.raw_elevationfile._delete() dummyfile._rename(self.raw_elevationfile.filename) self.raw_elevationfile = dummyfile dummyfile = FaFile('dummy.fa') for key, value in str_eleMEMORY.items(): self.raw_elevationfile.entry(key, str(value)) elevation_MEMORY = {} memCOUNT = 0 else: continue p.close()
class Browser(QDialog, Ui_BrowseDialog): # ------------------------------------------------------------------------- # public methods # ------------------------------------------------------------------------- # ------------------------------------------------------------------------- def __init__(self, app): QDialog.__init__(self) self.setupUi(self) self.app = app # init attributes self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(False) self.filename = "/home/vagrant/Bureau/fork/qgisws/banskel/bano-75.csv" self.browseButton.clicked.connect(self.__browse) self.buttonBox.button(QDialogButtonBox.Ok).clicked.connect(self.__ok) self.buttonBox.button(QDialogButtonBox.Cancel).clicked.connect(app.quit) self.projector = Projector() self.progress = Progress() # ------------------------------------------------------------------------- @property def filename(self): return self.__filename # ------------------------------------------------------------------------- @filename.setter def filename(self, filename): if os.path.isfile(filename): self.__filename = filename self.urlEdit.setText(self.__filename) self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(True) else: self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(False) msg = QMessageBox() msg.setText("Fichier introuvable") # ------------------------------------------------------------------------- # private methods # ------------------------------------------------------------------------- # ------------------------------------------------------------------------- def __in_progress(self): self.progress.progressBar.setValue(self.progress.progressBar.value()+1) # ------------------------------------------------------------------------- def __compute_done(self): self.progress.close() # ------------------------------------------------------------------------- def __ok(self): self.projector.filename = self.__filename self.projector.progressSignal.connect(self.__in_progress) self.projector.finishSignal.connect(self.__compute_done) self.projector.start() self.progress.progressBar.setRange(0,count_lines(self.__filename)) self.progress.progressBar.setValue(0) self.progress.show() # ------------------------------------------------------------------------- def __browse(self): self.filename = QFileDialog.getOpenFileName(self,"Sélectionner le fichier")