def testListFromData(data): #return value is list of lists; # 0 - polygons labeldd 'train' # 1 - polygons labeled 'pos' # 2 - polygons labeled 'neg' lTrain, lPos, lNeg = [], [], [] for site in data['sites']: pList = [] dList = [] for i2 in range(len(site['lats'])): pList.append(pointClass.Point(site['lons'][i2], site['lats'][i2])) for datePairs in site['dates']: mindate = datetime.strptime(datePairs['min'].split('T')[0], '%Y-%m-%d').date() maxdate = datetime.strptime(datePairs['max'].split('T')[0], '%Y-%m-%d').date() dList.append((mindate, maxdate)) name = site["name"] if name == "train": lTrain.append(pointClass.spaceTimePlane(pList, dList, name)) elif name == "pos": lPos.append(pointClass.spaceTimePlane(pList, dList, name)) elif name == "neg": lNeg.append(pointClass.spaceTimePlane(pList, dList, name)) else: print "Polygon name does not follow correct scheme, (train, pos, neg)" return (lTrain, lPos, lNeg)
def createHull(cluster, bUseTime): loLa = set([]) for point in cluster.records: loLa.add(str(point.lon)+","+str(point.lat)) loLa = map(lambda x: [float(x.split(",")[0]), float(x.split(",")[1])],loLa) if len(loLa) > 2: loLa = np.array(loLa) hull = ConvexHull(loLa) lClustPoints = [] lPointObj = [] for verts in hull.vertices: lClustPoints.append([loLa[verts,1], loLa[verts,0]]) lPointObj.append(pointClass.Point(loLa[verts,0], loLa[verts,1])) if bUseTime: cluster.objPoly = pointClass.spaceTimePlane(lPointObj,[(cluster.dt.date(), cluster.dt.date())],"Hull") else: cluster.objPoly = pointClass.Polygon(lPointObj) cluster.poly = lClustPoints else: lPointObj = [] lClustPoints = [] for lolaOff in [(-0.001,-0.001), (-0.001,0.001), (0.001,0.001), (0.001,-0.001),]: offset = [loLa[0][0]+lolaOff[0], loLa[0][1]+lolaOff[1]] lPointObj.append(pointClass.Point(offset[0], offset[1])) lClustPoints.append([offset[1], offset[0]]) if bUseTime: cluster.objPoly = pointClass.spaceTimePlane(lPointObj,[(cluster.dt.date(), cluster.dt.date())],"Hull") else: cluster.objPoly = pointClass.Polygon(lPointObj) cluster.poly = lClustPoints
def testListFromData(data): # return value is list of lists; # 0 - polygons labeldd 'train' # 1 - polygons labeled 'pos' # 2 - polygons labeled 'neg' lTrain, lPos, lNeg = [], [], [] for site in data["sites"]: pList = [] dList = [] for i2 in range(len(site["lats"])): pList.append(pointClass.Point(site["lons"][i2], site["lats"][i2])) for datePairs in site["dates"]: mindate = datetime.strptime(datePairs["min"].split("T")[0], "%Y-%m-%d").date() maxdate = datetime.strptime(datePairs["max"].split("T")[0], "%Y-%m-%d").date() dList.append((mindate, maxdate)) name = site["name"] if name == "train": lTrain.append(pointClass.spaceTimePlane(pList, dList, name)) elif name == "pos": lPos.append(pointClass.spaceTimePlane(pList, dList, name)) elif name == "neg": lNeg.append(pointClass.spaceTimePlane(pList, dList, name)) else: print "Polygon name does not follow correct scheme, (train, pos, neg)" return (lTrain, lPos, lNeg)
def createHull(cluster, bUseTime): loLa = set([]) for point in cluster.records: loLa.add(str(point.lon) + "," + str(point.lat)) loLa = map(lambda x: [float(x.split(",")[0]), float(x.split(",")[1])], loLa) if len(loLa) > 2: loLa = np.array(loLa) hull = ConvexHull(loLa) lClustPoints = [] lPointObj = [] for verts in hull.vertices: lClustPoints.append([loLa[verts, 1], loLa[verts, 0]]) lPointObj.append(pointClass.Point(loLa[verts, 0], loLa[verts, 1])) if bUseTime: cluster.objPoly = pointClass.spaceTimePlane( lPointObj, [(cluster.dt.date(), cluster.dt.date())], "Hull") else: cluster.objPoly = pointClass.Polygon(lPointObj) cluster.poly = lClustPoints else: lPointObj = [] lClustPoints = [] for lolaOff in [ (-0.001, -0.001), (-0.001, 0.001), (0.001, 0.001), (0.001, -0.001), ]: offset = [loLa[0][0] + lolaOff[0], loLa[0][1] + lolaOff[1]] lPointObj.append(pointClass.Point(offset[0], offset[1])) lClustPoints.append([offset[1], offset[0]]) if bUseTime: cluster.objPoly = pointClass.spaceTimePlane( lPointObj, [(cluster.dt.date(), cluster.dt.date())], "Hull") else: cluster.objPoly = pointClass.Polygon(lPointObj) cluster.poly = lClustPoints
def readInShapeDocument(data): lST = [] siteList = data["sites"] for site in siteList: pList = [] dList = [] for i2 in range(len(site["lats"])): pList.append(pointClass.Point(site["lons"][i2], site["lats"][i2])) for datePairs in site["dates"]: mindate = datetime.strptime(datePairs["min"].split("T")[0], "%Y-%m-%d").date() maxdate = datetime.strptime(datePairs["max"].split("T")[0], "%Y-%m-%d").date() dList.append((mindate, maxdate)) lST.append(pointClass.spaceTimePlane(pList, dList, site["name"])) return lST
def readInShapeDocument(data): lST = [] siteList = data['sites'] for site in siteList: pList = [] dList = [] for i2 in range(len(site['lats'])): pList.append(pointClass.Point(site['lons'][i2], site['lats'][i2])) for datePairs in site['dates']: mindate = datetime.strptime(datePairs['min'].split('T')[0], '%Y-%m-%d').date() maxdate = datetime.strptime(datePairs['max'].split('T')[0], '%Y-%m-%d').date() dList.append((mindate, maxdate)) lST.append(pointClass.spaceTimePlane(pList, dList, site['name'])) return lST
############# ############# ############# ############# #############