Commit c67d9243 authored by Anthony's avatar Anthony
Browse files

Clean up of Rviewer

parent e386da07
############################
Selection des points par lon / lat dans class routing
self.G = [i for i in range(r.nbpt) if (r.var_land["lat"][i]>lat_min)*(r.var_land["lat"][i]<lat_max)*(r.var_land["lon"][i]>lon_min)*(r.var_land["lon"][i]<lon_max)]
############################
Polygone, line vector dans la classe vectors non ?
############################
Dictionnaire afin de définir les différentes couleurs !! Avec valeur par défault
############################
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
class Folium
@author: A. Schrapffer
"""
import sys
from class_shapes import points, vector
from class_Routing import routing
from Voronoi_grid import get_voronoi_polygons
import folium
import geopandas as gpd
from math import atan
import numpy as np
import numpy.ma as ma
class folium_rout:
def __init__(self,r):
self.r = r
self.G = None
self.lon_min = None
#
def recut_basin(self, bid):
extent = self.r.get_extent(bid)
if self.lon_min is None: self.recut_lonlat(extent)
mask = np.sum(self.r.basin_mask(bid), axis = 0)
self.mask_land = [1 if mask[j,i]>0 else 0 for j,i in self.r.conv_land2ij]
if self.G is None:
self.G = [i for i in range(self.r.nbpt) if self.mask_land[i]==1]
else:
self.G = [i for i in self.G if self.mask_land[i]==1]
#
def recut_lonlat(self, extent = None):
if extent is not None:
self.lon_min = extent[0]
self.lon_max = extent[1]
self.lat_min = extent[2]
self.lat_max = extent[3]
if self.G is None:
self.G = [i for i in range(self.r.nbpt)
if (self.r.var_land["lat"][i]>self.lat_min)*(self.r.var_land["lat"][i]<self.lat_max)*(self.r.var_land["lon"][i]>self.lon_min)*(self.r.var_land["lon"][i]<self.lon_max)]
lonc = self.lon_min + (self.lon_max- self.lon_min)/2
latc = self.lat_min + (self.lat_max- self.lat_min)/2
self.m = folium.Map([latc, lonc], zoom_start=5, tiles='cartodbpositron')
else:
self.G = [i for i in range(self.r.nbpt)]
#
def draw_grid(self, gg = None):
"""
Draw the atmospherical grid
"""
if gg is not None:
cols = gg
fill = True
else:
cols = ['#000000']*len(self.G)
fill = False
for i, ig in enumerate(self.G):
folium.GeoJson(
self.r.GRID[ig],
style_function=lambda x :{'fillColor':cols[i] ,'lineColor': '#312d37'},
highlight_function=lambda feature: {"fillcolor": "red"}).add_to(self.m)
#
def draw_routing_pts(self,x,y):
"""
Draw the routing points
"""
for xx, yy in zip(x,y):
if len(xx)>1:
aline=folium.PolyLine(locations=[[yy[0], xx[0]], [yy[1], xx[1]]],weight=5,color = 'blue')
self.m.add_child(aline)
#
"""
def draw_full_routing(self):
#Draw the full routing
#-> façon d'avoir la liste de tous les points et optimiser recherche
#dans class Routing
for ig in self.G:
nbas = int(self.r.var_land["routenbintobas"][ig])
for ib in range(nbas):
p1 = points(self.r, ig, ib)
g,b = self.downstream(ig, ib)
if b <self.r.nbasmax:
p2 = points(self.r, g,b)
v = vector(p1, p2)
aline=folium.PolyLine(locations=v.locations,weight=5,color = 'blue')
self.m.add_child(aline)
#folium.RegularPolygonMarker(location=v.pc, fill = True, fill_color='#000000',color = '#000000', number_of_sides=3, radius=10, rotation = v.rotation).add_to(self.m)
"""
#
def draw_HTUs(self):
"""
Draw HTUs and their Voronoid Polygon
"""
color = ['#3186cc',"#8B0000"]
for ig in self.G:
nbas = int(self.r.var_land["routenbintobas"][ig])
if nbas>3:
htus = [[lon, lat] for lon, lat in zip(self.r.var_land["CG_lon"][ig][:nbas], self.r.var_land["CG_lat"][ig][:nbas])]
polygons = get_voronoi_polygons(htus, self.r.GRID[ig])
for i,p in enumerate(polygons):
if p != []:
folium.GeoJson(
p,
style_function=lambda x :{'fillColor':'#000000' ,'lineColor': '#000000', "fill":False}).add_to(self.m)
for ib in range(nbas):
p1=points(self.r, ig, ib)
loc = [p1.lat, p1.lon]
g,b = self.downstream(ig, ib)
popup = "lon: {0} / lat: {1}".format(p1.lat, p1.lon)
c = color[0]
if b >=self.r.nbasmax: c = color[1]
folium.CircleMarker(
location=loc,radius=1, popup=popup, color=c,
fill=True,fill_color=c).add_to(self.m)
def downstream(self, ig,ib):
"""
Get the downstream points
-> méthode de recherche dans class_Routing donc à supprimer
"""
b = int(self.r.var_land["routetobasin"][ig][ib]-1)
g = int(self.r.var_land["routetogrid"][ig][ib]-1)
return g,b
def save(self, dire):
folium.Map.save(self.m, dire)
......@@ -14,7 +14,6 @@ import time
class routing:
def __init__(self, dfile):
self.nc = NetCDFFile(dfile, "r")
#self.varlist = list(self.nc.variables.keys())
self.varlist = ["lon_bnd", "lat_bnd", "basinid", "land", "nbpt_glo"]
#
self.get_vars()
......@@ -129,8 +128,7 @@ class routing:
area = [self.basin_numpts(bid) for bid in basin_list]
basin_sort = np.flip(np.argsort(area))
"""
print(np.sort(basin_list)[:10])
#self.basin_list = [[int(basin_list[i]), int(area[i])] for i in basin_sort]
print("Top 10 basins number:", np.sort(basin_list)[:10])
#
def basin_numpts(self,bid):
a = np.count_nonzero(self.var["basinid"] == float(bid))
......@@ -204,16 +202,6 @@ class routing:
htusout = self.get_htusout(htus)
x = [(cglon[H[0],H[1],H[2]], cglon[O[0],O[1],O[2]]) if O[0]<self.nbasmax else [cglon[H[0],H[1],H[2]]] for H,O in zip(htus,htusout)]
y = [(cglat[H[0],H[1],H[2]], cglat[O[0],O[1],O[2]]) if O[0]<self.nbasmax else [cglat[H[0],H[1],H[2]]] for H,O in zip(htus,htusout)]
"""
for i in range(len(htusout)):
a,b,c = htus[i]; k,j,i = htusout[i]
if k<self.nbasmax:
x.append((cglon[a,b,c], cglon[k,jj,ii]))
y.append((cglat[a,b,c], cglon[k,jj,ii]))
else:
x.append([cglon[a,b,c]])
y.append([cglat[a,b,c]])
"""
return x,y
#
##############################
......
......@@ -86,25 +86,19 @@ class UI(QtWidgets.QMainWindow):
self.PARAM["vmax"] = self.vmax.text()
self.update_graph()
# Garde fous : pas de HTUs si trop de points
# Pas de points si trop nombreux
# Pas de fetch si percentile trop bas
# Basin -> donne couleur
def OPEN(self, b):
self.fname, _ = QFileDialog.getOpenFileName(self, 'Open file',
'./',"NetCDF File (*.nc)")
#self.fname= "/home/anthony/Documents/LOCAL/RoutingPP/1-GRAPHS/LC_Spain_test_graph.nc"
#self.fname= "/home/anthony/Documents/LOCAL/RoutingPP/1-GRAPHS/AmSud_A_MERIT_graph.nc"
print(self.fname)
self.label = self.findChild(QLabel, 'label_10')
self.label.setText("File: " + self.fname + " (loading...)")
self.rout = routing(self.fname)
# Actualiser les lon_lat par défaut
# Update the lon/lat limits
self.lat_min = np.round(np.nanmin(self.rout.var["lat_bnd"]),2); self.Dlimits["lat_min"].setText(str(self.lat_min))
self.lat_max = np.round(np.nanmax(self.rout.var["lat_bnd"]),2); self.Dlimits["lat_max"].setText(str(self.lat_max))
self.lon_min = np.round(np.nanmin(self.rout.var["lon_bnd"]),2); self.Dlimits["lon_min"].setText(str(self.lon_min))
......@@ -123,7 +117,6 @@ class UI(QtWidgets.QMainWindow):
if self.bid is not None:
self.recut_basin(self.bid)
# Option pour colorier basin
if self.showHTUs or self.showgrid or self.showfetch:
self.G = [i for i in self.G if (self.rout.var_land["lat"][i]>self.lat_min)*(self.rout.var_land["lat"][i]<self.lat_max) \
*(self.rout.var_land["lon"][i]>self.lon_min)*(self.rout.var_land["lon"][i]<self.lon_max)]
......@@ -136,10 +129,6 @@ class UI(QtWidgets.QMainWindow):
# HTUs
if self.showHTUs:
VORONOI = self.get_VORONOI()
# Ajout d'une case variable avec vmin, vmax, cmap
# get_variables_value_VORONOI(self, varname)
#plt.fill(x,y, color = self.viridis(self.norm(area[i])), alpha = 0.6)
#plt.plot(x,y,color = "k")
else:
VORONOI = []
# GRID
......@@ -168,10 +157,7 @@ class UI(QtWidgets.QMainWindow):
self.MplWidget.plot_map(grid, extent = self.extent, VORONOI = VORONOI, \
mainfetch = fetch, htuvar = htuvar, PARAM = self.PARAM)
# Should I draw the lon/ Lat limit for user to see ?
def recut_basin(self, bid):
# mettre un bouton pour load basin
extent = self.rout.get_extent(bid)
for i in [0,2]:
self.extent[i] = np.max([self.extent[i],extent[i]])
......@@ -218,7 +204,6 @@ class UI(QtWidgets.QMainWindow):
return VORONOI
def get_variables_value_VORONOI(self, varname):
# Cas area avec % du total
var = self.rout.get_var(varname)
varout = []
for nb in self.G:
......
import cartopy
import cartopy.crs as ccrs
import matplotlib.pyplot as plt
import numpy as np
class map:
def __init__(self, extent):
self.fig = plt.figure(figsize= (10,10))
self.ax = plt.axes(projection=ccrs.PlateCarree())
self.ax.set_extent(extent)
self.ax.add_feature(cartopy.feature.COASTLINE) #
self.ax.add_feature(cartopy.feature.BORDERS)
def draw_basin():
pass
def draw_grid():
pass
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment