def load_grid(turn=0): dir_path = os.path.dirname(os.path.realpath(__file__)) test_path = os.path.join(dir_path, 'test_files') hexagons = gridmap.read_hexagons( filename='river_axis_grid%d.geojson' % turn, path=test_path) return hexagons
def update(turn): dir_path = os.path.dirname(os.path.realpath(__file__)) store_path = os.path.join(dir_path, 'test_files') hexagons = gridmap.read_hexagons( filename='hexagons%d.geojson' % turn, path=store_path) #hexagons = adjust.biosafe_area(hexagons) #hexagons = gridmap.hexagons_to_fill(hexagons) for feature in hexagons.features: #feature.properties["z_changed"] = True #feature.properties["landuse_changed"] = True feature.properties["owned"] = False feature.properties["owner"] = None feature.properties["ownership_change"] = False """ hexagons_old = gridmap.read_hexagons( filename='hexagons%d.geojson' % turn, path=test_path) turn += 1 hexagons_new = gridmap.read_hexagons( filename='hexagons%d.geojson' % turn, path=test_path) for feature in hexagons_new.features: reference_hex = hexagons_old[feature.id] feature.properties["behind_dike"] = reference_hex.properties["behind_dike"] feature.properties["dike_reference"] = reference_hex.properties["dike_reference"] feature.properties["floodplain_north"] = reference_hex.properties["floodplain_north"] feature.properties["floodplain_south"] = reference_hex.properties["floodplain_south"] print("done turn: " + str(turn)) with open(os.path.join(test_path, 'hexagons%d.geojson' % turn), 'w') as f: geojson.dump(hexagons_new, f, sort_keys=True, indent=2) """ with open(os.path.join(store_path, 'hexagons%d.geojson' % turn), 'w') as f: geojson.dump(hexagons, f, sort_keys=True, indent=2) return
def main(): turn = 0 dir_path = os.path.dirname(os.path.realpath(__file__)) test_path = os.path.join(dir_path, 'test_files') hexagons = gridmap.read_hexagons(filename='hexagons%d.geojson' % turn, path=test_path) hexagons = determine_neighbours(hexagons) hexagons = generate_ownership(hexagons) hexagons = determine_ownership(hexagons) """
def main(): turn = 0 dir_path = os.path.dirname(os.path.realpath(__file__)) test_path = os.path.join(dir_path, 'storing_files') hexagons = gridmap.read_hexagons(filename='hexagons%d.geojson' % turn, path=test_path) hexagons = determine_neighbours(hexagons) hexagons = generate_ownership(hexagons) hexagons = determine_ownership(hexagons) with open(os.path.join(test_path, 'hexagons%d.geojson' % turn), 'w') as f: geojson.dump(hexagons, f, sort_keys=True, indent=2)
def main(): turn=0 dir_path = os.path.dirname(os.path.realpath(__file__)) test_path = os.path.join(dir_path, 'test_files') hexagons = gridmap.read_hexagons( filename='hexagons%d.geojson' % turn, path=test_path) hexagons = biosafe_area(hexagons) with open('hexagons_biosafe.geojson', 'w') as f: geojson.dump(hexagons, f, sort_keys=True, indent=2) return
def main(): dir_path = os.path.dirname(os.path.realpath(__file__)) test_path = os.path.join(dir_path, 'test_files') turn = 0 hexagons = gridmap.read_hexagons(filename='hexagons%d.geojson' % turn, path=test_path) turn += 1 hexagons_new = gridmap.read_hexagons(filename='hexagons%d.geojson' % turn, path=test_path) #cost = Costs() #cost.cost_per_hex() indicators = Indicators() #indicators.set_score(0, 0, 0, 0, turn=5) indicators.add_indicator_values(50, 50, 100, 0) indicators.add_indicator_values(60, 30, 80, 1) indicators.add_indicator_values(70, 30, 60, 2) indicators.add_indicator_values(70, 60, 40, 3) indicators.update_flood_safety([600, 400, 800], [600, 400, 600]) indicators.update_water_and_dike_levels(hexagons, hexagons_new, turn) indicators.plot(3)
def main(): turn = 0 dir_path = os.path.dirname(os.path.realpath(__file__)) test_path = os.path.join(dir_path, 'temp_files') hexagons = gridmap.read_hexagons(filename='hexagons%d.geojson' % turn, path=test_path) fig, axes = plt.subplots(nrows=1, ncols=2, figsize=(18, 6)) polygons = [] for feature in hexagons.features: if feature.properties["ghost_hexagon"]: continue poly = feature.geometry.coordinates[0] polygon = Polygon(poly, False, fill=False, linewidth=0.5) polygons.append(polygon) p = PatchCollection(polygons, facecolors=None, alpha=0.4) colors = 100 * np.random.rand(len(polygons)) p.set_array(np.array(colors)) axes[0].add_collection(p) fig.colorbar(p, ax=axes[0]) axes[0].set_xlim([-400, 400]) axes[0].set_ylim([-300, 300]) axes[1].set_xlim([-400, 400]) axes[1].set_ylim([-300, 300]) """ df = json_normalize(hexagons.features) cols = ["properties.z_reference", "properties.landuse", "properties.biosafe"] df = df.loc[:,cols] df.columns = ["z_reference", "landuse" ,"biosafe"] print(df) test = df.groupby('landuse').sum() print(test) test2 = test.z_reference print(test2) #hexagons = set_ecotope(hexagons) #print(hexagons.features) #test = hexagons.features[0] #print(test) #test = pd.DataFrame(test.properties) #test = {} #for feature in hexagons.features: # test.update([feature.id: ]) #test = pd.read_json(hexagons.features.properties) #print(test) """ return
def get_hexagons(self): """ Function that creates/gets the new hexagons. Gets them from either the camera (live mode) or file (test mode). """ if not (self.test or self.reloading): self.hexagons_sandbox = detect.detect_markers( self.turn_img, self.pers, self.img_x, self.img_y, self.origins, self.radius, self.hexagons_sandbox, method='LAB', path=self.store_path, debug=self.debug) if not self.initialized: self.hexagons_sandbox = ghosts.set_values( self.hexagons_sandbox) else: if self.reloading: path = self.store_path print("Reloading: Getting new board state from store folder.") else: path = self.test_path print("TEST MODE: Getting new board state from test folder.") try: self.hexagons_sandbox = gridmap.read_hexagons( filename='hexagons%d.geojson' % self.turn, path=path) except FileNotFoundError: if self.reloading: print("No more files to reload") else: print("No more files to test") return False """ if self.test: self.hexagons_sandbox = adjust.test_mode_z_correction( self.hexagons_sandbox) if not self.initialized: self.hexagons_sandbox = ghosts.set_values( self.hexagons_sandbox) """ print("Retrieved board state.") return True
Chezy = (h ** (-3 / 2.)) * (T1 + T2 + T3) else: """ Emergent vegetation """ Cb = 18 * np.log10(12 * h / vegpar["kb"]) Chezy = np.sqrt((vegpar["Cd"] * vegpar["n"] * h / (2 * g) + Cb ** -2) ** -1) return Chezy def manning(h, n): """ Manning formula. """ Chezy = (h ** (1 / 6)) / n return Chezy if __name__ == '__main__': hexagons = gridmap.read_hexagons(filename='storing_files\\hexagons0.geojson') model = D3D.initialize_model() face_grid = gridmap.read_face_grid(model) face_grid = gridmap.index_face_grid(hexagons, face_grid) hexagons, face_grid = hex_to_points(model, hexagons, face_grid) with open('hexagons_vegetation.geojson', 'w') as f: geojson.dump(hexagons, f, sort_keys=True, indent=2) with open('face_grid_vegetation.geojson', 'w') as f: geojson.dump(face_grid, f, sort_keys=True, indent=2) #gridmap.run_model(grid)