def visualisation(): elements = [] for i in range(0, GRID[0]): for j in range(0, GRID[1]): p = [ round(longitude1 + (longitude_delta * j), 3), round(latitude1 + (latitude_delta * i), 3) ] try: point = asShape({'type': 'Point', 'coordinates': p}) if point.is_valid: elements.append(point) except: pass for z in zone.objects(ztype='zone'): print 'PROCESSING: ' + str(z.zid) + ' ' + str(z.name) zpolygon = asShape(z.polygon) for e in elements: if zpolygon.intersects(e): print mapping(e) point = wave.objects(loc__geo_intersects=mapping(e)).first() point2 = wavedirection.objects( loc__geo_intersects=mapping(e)).first() data = [] if point and point2: point = point['values'] point2 = point2['values'] data = [] for i in range(1, 366): if data: wavedirection_visualisation.objects.insert(data) data = [] if str(i) in point and point[str(i)].get( '0', None) and str(i) in point2 and point2[str( i)].get('0', None): wdv = wavedirection_visualisation(zid=z.zid) wdv.date = datetime(year=2018, month=1, day=1) + timedelta(days=i - 1) wdv.loc = mapping(e) wdv.height = point[str(i)]['0'] wdv.direction = point2[str(i)]['0'] data.append(wdv) else: if data: wavedirection_visualisation.objects.insert(data) data = []
def visualisation(): elements = [] for i in range(0, GRID[0]): for j in range(0, GRID[1]): if i!=GRID[0]-1 and j!=GRID[1]-1: p1 = [round(float(LNG[i][j]), 3), round(float(LAT[i][j]), 3)] p2 = [round(float(LNG[i][j+1]), 3), round(float(LAT[i][j+1]), 3)] p3 = [round(float(LNG[i+1][j+1]), 3), round(float(LAT[i+1][j+1]), 3)] p4 = [round(float(LNG[i+1][j]), 3), round(float(LAT[i+1][j]), 3)] try: polygon = asShape({'type': 'Polygon', 'coordinates': [[p1, p2, p3, p4, p1]]}) if polygon.is_valid: elements.append(polygon) except: pass for z in zone.objects(ztype='zone'): print 'PROCESSING: '+str(z.zid)+' '+str(z.name) zpolygon = asShape(z.polygon) for e in elements: if zpolygon.intersects(e): print mapping(e) points = [t['values'] for t in tide.objects(loc__geo_intersects=mapping(e))] if points: data = [] for i in range(1,366): if data: tide_visualisation.objects.insert(data) data = [] values = [] for p in points: try: values.append(p[str(i)]['0']) except: pass if values: tv = tide_visualisation(zid=z.zid) tv.date = datetime(year=2018, month=1, day=1)+timedelta(days=i-1) tv.polygon = mapping(e) tv.depth = mean(values) data.append(tv) else: if data: tide_visualisation.objects.insert(data) data = []
def visualisation(): elements = [] for i in range(0, GRID[0]): for j in range(0, GRID[1]): p = [round(float(LNG[i][j]), 3), round(float(LAT[i][j]), 3)] try: point = asShape({'type': 'Point', 'coordinates': p}) if point.is_valid: elements.append(point) except: pass for z in zone.objects(ztype='zone'): print 'PROCESSING: ' + str(z.zid) + ' ' + str(z.name) zpolygon = asShape(z.polygon) for e in elements: if zpolygon.intersects(e): print mapping(e) point = current.objects(loc__geo_intersects=mapping(e)).first() point2 = currentdirection.objects( loc__geo_intersects=mapping(e)).first() if point and point2: point = point['values'] point2 = point2['values'] data = [] for i in range(1, 366): if data: current_visualisation.objects.insert(data) data = [] if str(i) in point and str(i) in point2: cv = current_visualisation(zid=z.zid) cv.date = datetime(year=2018, month=1, day=1) + timedelta(days=i - 1) cv.loc = mapping(e) cv.speed = point[str(i)]['0'] cv.direction = point2[str(i)]['0'] data.append(cv) else: if data: current_visualisation.objects.insert(data) data = []
def visualisation(): elements = [] for c in current.objects(zid=zid): try: point = asShape(c.loc) if point.is_valid: elements.append(point) except: pass for z in zone.objects(ztype='project', zid=zid): print 'PROCESSING: ' + str(z.zid) + ' ' + str(z.name) zpolygon = asShape(z.polygon) for e in elements: if zpolygon.intersects(e): print mapping(e) point = current.objects( zid=zid, loc__geo_intersects=mapping(e)).first() point2 = currentdirection.objects( zid=zid, loc__geo_intersects=mapping(e)).first() if point and point2: point = point['values'] point2 = point2['values'] data = [] for i in range(1, 366): if data: current_visualisation.objects.insert(data) data = [] if str(i) in point and str(i) in point2: cv = current_visualisation(zid=z.zid) cv.date = datetime(year=2018, month=1, day=1) + timedelta(days=i - 1) cv.loc = mapping(e) cv.speed = point[str(i)]['0'] cv.direction = point2[str(i)]['0'] data.append(cv) else: if data: current_visualisation.objects.insert(data) data = []
import scipy.io import matplotlib matplotlib.use('Agg') import matplotlib.pyplot as plt from download.models import zone, zonedata, wave, wavedirection, waveperiod, bathymetry, tide, current, currentdirection # grid_path = '/Users/ravi/Desktop/current/uv/1_jan_current.mat' # MAT = scipy.io.loadmat(grid_path) # X = MAT['data']['X'][0][0] # Y = MAT['data']['Y'][0][0] # XVAL = MAT['data']['XComp'][0][0][0] # YVAL = MAT['data']['YComp'][0][0][0] # Q = plt.quiver(LNG, LAT, XVAL, YVAL) for z in zone.objects(zid='b951a954-f3f7-44f6-80a6-0194cbee50a1'): print z.zid, z.name X = [] #np.full(X.shape, np.nan) Y = [] #np.full(X.shape, np.nan) U = [] #np.full(X.shape, np.nan) V = [] #np.full(X.shape, np.nan) # fetch data current_data = {} for c in current.objects(loc__geo_intersects=z.polygon): key = ','.join([str(i) for i in c.loc['coordinates']]) value = c.values['1']['0'] if key in current_data: current_data[key]['s'] = value else: current_data[key] = {'s': value}
def visualisation(): elements = [] for i in range(0, GRID[0]): for j in range(0, GRID[1]): if i != GRID[0] - 1 and j != GRID[1] - 1: p1 = [ round( Angle(str(longitude1 + (longitude_delta * j)) + 's').degree, 10), round( Angle(str(latitude1 + (latitude_delta * i)) + 's').degree, 10) ] p2 = [ round( Angle( str(longitude1 + (longitude_delta * (j + 1))) + 's').degree, 10), round( Angle(str(latitude1 + (latitude_delta * i)) + 's').degree, 10) ] p3 = [ round( Angle( str(longitude1 + (longitude_delta * (j + 1))) + 's').degree, 10), round( Angle( str(latitude1 + (latitude_delta * (i + 1))) + 's').degree, 10) ] p4 = [ round( Angle(str(longitude1 + (longitude_delta * j)) + 's').degree, 10), round( Angle( str(latitude1 + (latitude_delta * (i + 1))) + 's').degree, 10) ] try: polygon = asShape({ 'type': 'Polygon', 'coordinates': [[p1, p2, p3, p4, p1]] }) if polygon.is_valid: elements.append(polygon) except: pass for z in zone.objects(zid='b3913413-5b23-4021-a41b-182166e9fd2f'): print 'PROCESSING: ' + str(z.zid) + ' ' + str(z.name) zpolygon = asShape(z.polygon) data = [] for e in elements: if data and len(data) % 1000 == 0: bathymetry_visualisation.objects.insert(data) data = [] if zpolygon.intersects(e): print mapping(e) points = [ b['values'] for b in bathymetry.objects(loc__geo_intersects=mapping(e)) ] if points: values = [] for p in points: values.append(p.depth) bv = bathymetry_visualisation(zid=z.zid) bv.polygon = mapping(e) bv.depth = mean(values) data.append(bv) else: if data: bathymetry_visualisation.objects.insert(data) data = []
from_date+=timedelta(days=1) else: while from_date<=to_date: try: day = str(from_date.timetuple().tm_yday) v = values[day]['0'] data[day] = v except: pass from_date+=timedelta(days=1) return data for z in zone.objects(ztype='zone'): print z.zid, z.name data = [] origin = z.polygon['coordinates'][0][0] p = transform_polygon(z.polygon['coordinates'][0], origin=origin) tri_data = tri_input(p) with open('/tmp/visualisation/'+z.zid+'.poly', 'w') as f: f.write(tri_data) max_area = int(Polygon(p).area/400) out_bytes = subprocess.check_output(['triangle', '-pq25a'+str(max_area), '/tmp/visualisation/'+str(z.zid)+'.poly']) output = out_bytes.decode('utf-8') if 'Writing '+str(z.zid)+'.1.node' and 'Writing '+str(z.zid)+'.1.ele': vertices = tri_get_vertices('/tmp/visualisation/'+str(z.zid)+'.1.node')
# pipeline = [ # { "$match": {'l': {'$geoIntersects': {'$geometry': {'type': 'Polygon', 'coordinates': [t]}}}} }, # { "$group": {"_id": None, "depth": { "$avg": "$d" }} }, # ] # value = 0 # q = list(userbathymetry.objects.aggregate(*pipeline)) # if q: # value = round(q[0].get('depth', 0), 2) # if value<0: # data.append([t, value]) # # uz.triangles = data # uz.save() # public zones for z in zone.objects(ztype='bathymetry'): print z.zid data = [] origin = z.polygon['coordinates'][0][0] p = transform_polygon(z.polygon['coordinates'][0], origin=origin) tri_data = tri_input(p) with open('/tmp/triangle/' + z.zid + '.node', 'w') as f: f.write(tri_data) max_area = int(Polygon(p).area / 400) out_bytes = subprocess.check_output([ 'triangle', '-a' + str(max_area), '/tmp/triangle/' + str(z.zid) + '.node' ]) output = out_bytes.decode('utf-8')
def visualisation(): elements = [] for i in range(0, GRID[0]): for j in range(0, GRID[1]): if i != GRID[0] - 1 and j != GRID[1] - 1: p1 = [ round(longitude1 + (longitude_delta * j), 3), round(latitude1 + (latitude_delta * i), 3) ] p2 = [ round(longitude1 + (longitude_delta * (j + 1)), 3), round(latitude1 + (latitude_delta * i), 3) ] p3 = [ round(longitude1 + (longitude_delta * (j + 1)), 3), round(latitude1 + (latitude_delta * (i + 1)), 3) ] p4 = [ round(longitude1 + (longitude_delta * j), 3), round(latitude1 + (latitude_delta * (i + 1)), 3) ] try: polygon = asShape({ 'type': 'Polygon', 'coordinates': [[p1, p2, p3, p4, p1]] }) if polygon.is_valid: elements.append(polygon) except: pass for z in zone.objects(ztype='zone'): print 'PROCESSING: ' + str(z.zid) + ' ' + str(z.name) zpolygon = asShape(z.polygon) for e in elements: if zpolygon.intersects(e): print mapping(e) points = [ w['values'] for w in wave.objects(loc__geo_intersects=mapping(e)) ] if points: data = [] for i in range(1, 366): if data: wave_visualisation.objects.insert(data) data = [] values = [] for p in points: try: values.append(p[str(i)]['0']) except: pass if values: wv = wave_visualisation(zid=z.zid) wv.date = datetime(year=2018, month=1, day=1) + timedelta(days=i - 1) wv.polygon = mapping(e) wv.height = mean(values) data.append(wv) else: if data: wave_visualisation.objects.insert(data) data = []
if element==ELEMENT_COUNT and node==NODE_COUNT: for E in ELEMENTS: if E: polygon = {'type': 'Polygon', 'coordinates': [[NODES[n] for n in E]]} try: polygon = asShape(polygon) if polygon.is_valid: elements.append(polygon) except: pass print 'ELEMENTS: '+str(len(elements)) break for z in zone.objects(ztype='project', zid=zid): print 'PROCESSING: '+str(z.zid)+' '+str(z.name) zpolygon = asShape(z.polygon) for e in elements: if zpolygon.intersects(e): print mapping(e) points = [t['values'] for t in tide.objects(zid=zid, loc__geo_intersects=mapping(e))] if points: data = [] for i in range(1,366): if data: tide_visualisation.objects.insert(data) data = [] values = [] for p in points: