def __init__(self,G=None, generate=False, dens=1, dbh_mean=0.5, dbh_std=0.1): if not G: raise Exception('by design, you need G for terrain to work. (globalVar(), see sim.tools.py)') self.G=G self.trees=[] self.stumps=[] self.roots=[] self.holes=[] self.piles=[] self.obstacles=[] #should hold all the above, except boulders. self.stumpFile='undefined' self.treeFile='undefined' self.stumpsPerH=0 self.boulderFreq=0 self.meanBoulderV=0 #the following stuff are only used when the stand files are used. should maybe be separated. if not G.areaPoly: #create from A, square raise Exception('got too little information about the area, need areaPoly polygon. ') self.areaPoly=G.areaPoly self.area=polygon_area(G.areaPoly) lim=fun.polygonLim(self.areaPoly) self.xlim=list(lim[0:2]) self.ylim=list(lim[2:4]) if self.G and self.G.gridL: self._fixGrid(L=self.G.gridL) else: self._fixGrid() if not generate: self._fileini() else: self.generateTrees(dens, dbh_mean, dbh_std)
def __init__(self, origin=None, globalOrigin=None,areaPoly=None, gridtype=None): if not areaPoly: raise Exception('areaPoly must be given.') if not origin: origin=(0,0) if not globalOrigin: globalOrigin=(596120, 6727530) #sweref99..located on map.. nice position.. use as default. self.areaPoly=areaPoly xmin,xmax,ymin,ymax=fun.polygonLim(areaPoly) side=10 self.lim=np.array([xmin-0.5*side,xmax+0.5*side, ymin-0.5*side, ymax+0.5*side]) self.A=fun.polygon_area(areaPoly) self.Ainv=1./self.A #used a lot.. faster to just compute this once. self.origin=origin self.globalOrigin=globalOrigin self.type=gridtype x,y,z=GIS.readTerrain(globalOrigin=globalOrigin , areaPoly=areaPoly) #get a list of how x and y varies.. strictly ascending xlist=x[:,0] #just the variations, not the 2D-matrix ylist=y[0,:] self.interpol=RectBivariateSpline(xlist, ylist, z) #used pretty much everytime we need the height of a specific point. Implemented in fortran and very fast nx.Graph.__init__(self) self.t_x=x self.t_y=y self.t_z=z self.roadWidth=4 #width of road self.overlap={} #will later be filled. A speedup thing self.weightFunction=normalizedPitchDist #reference to exter self.areaCover=go.roadAreaCoverage(self) self.moviefig=None #may be used for movies later self.cmdfolder=os.path.split(os.path.dirname(os.path.abspath(__file__)))[0]
def prune(shape, record, threshold): '''Remove small islands etc.''' triangulation = triangulation_cache[record[configs.configs[CONFIG] ['name_identifier']]] new_shape = [] for i in range(len(shape)): area = functions.polygon_area(triangulation[i]) if area > threshold: new_shape.append(shape[i]) return new_shape
def findBugs(algList): """ algorithms is a list of algorithms that should be tested """ while True: seed = int(random.uniform(0, 1000000)) print "seed:", seed random.seed(seed) alg = random.choice(algList) print "chosen algorithm:", alg dx = random.uniform(-700, 700) globalOrigin = 596250 + dx, 6727996 areaPoly = list(random.uniform(2, 3) * np.array([(0, 0), (48, 0), (73, 105), (0, 96)])) for i in range(len(areaPoly)): areaPoly[i] = tuple(areaPoly[i]) R = gr.SqGridGraph(areaPoly=areaPoly, globalOrigin=globalOrigin) R = alg(R, aCap=0.2, anim=False) print "road area coverage:", go.roadAreaCoverage(R) print "internal evaluation of above:", R.areaCover print "total area:", fun.polygon_area(areaPoly) print "used total area:", R.A, R.Ainv print "total cost:", cf.totalCost(R)
def tmp(areaPoly=None): globalOrigin = 596250, 6727996 R = gr.SqGridGraph(areaPoly=areaPoly, globalOrigin=globalOrigin) simplified_bruteForce(R, aCap=0.2, anim=False) c = None for i in range(5): Rt = copy.deepcopy(R) Rt = simplified_bruteForce(Rt, aCap=0.2, anim=False) if c: assert c == Rt.cost c = Rt.cost R = simplified_bruteForce(R, aCap=0.2, anim=False) # R=stochastic(R,aCap=0.2) fig = plt.figure() ax = fig.add_subplot(111, aspect="equal") R.draw(ax) print "road area coverage:", go.roadAreaCoverage(R) print "internal evaluation of above:", R.areaCover print "total area:", fun.polygon_area(areaPoly) print "used total area:", R.A, R.Ainv print "total cost:", cf.totalCost(R)
water_sample = functions.sample_points_in_water( all_triangulation, 100, *configs.configs[CONFIG]['trim_bounds']) point_sets = [] circles = [] for region in split_dict: point_sets_local = [] constraints = [] areas = [] for shape, rec in split_dict[region]: triangulation = triangulation_cache[rec[configs.configs[CONFIG] ['name_identifier']]] total_area = sum([ functions.polygon_area(triangulation[i]) for i in range(len(shape)) ]) areas.append(total_area) for shape, rec in split_dict[region]: sample = functions.sample_shape( shape, rec, POINT_COUNT, triangulation_cache[rec[ configs.configs[CONFIG]['name_identifier']]], THRESHOLD) triangulation = triangulation_cache[rec[configs.configs[CONFIG] ['name_identifier']]] total_area = sum([ functions.polygon_area(triangulation[i]) for i in range(len(shape)) ]) point_sets_local.append(sample) point_sets.append(sample)