- matplotlib

Valid keywords: uh,precip,prate,pmax,snow. Valid accum for precip & snow: 1,3,6




# Copyright (c) 2014,2015,2016,2017,2019 MetPy Developers. # Distributed under the terms of the BSD 3-Clause License. # SPDX-License-Identifier: BSD-3-Clause #from js import document #from pyodide import create_proxy import matplotlib.pyplot as plt import matplotlib.colors as mcolors import numpy as np from datetime import datetime, timedelta from pyodide.http import open_url from js import console, document rate_int = [0.00,0.01, 0.1,.5,1.0,2.0,3.0,4.0,5.0,10.,20.,30,40,50,100] rmap = plt.cm.tab20c rnorm = mcolors.BoundaryNorm(rate_int, rmap.N) uh_int = [0,10,25,50,75,100,150,200,300,400,500,750,1000] umap = plt.cm.tab20c unorm = mcolors.BoundaryNorm(uh_int, umap.N) snow_int = [0,.1,1,2,3,4,6,8,12,18,24,30,36,48,60,72,96,120] scolors = [(1.0, 1.0, 1.0), (189./255., 215./255., 231./255.), (107./255., 174./255., 214./255.), (49./255., 130./255., 189./255.), (8./255., 81./255., 156./255.), (8./255., 38./255., 148./255.), (1.0, 1.0, 150./255.), (1.0, 196./255., 0./255.), (1.0, 135./255., 0./255.), (219./255., 20./255., 0./255.), (158./255., 0.0, 0./255), (105./255., 0.0, 0./255.), (54./255., 0.0, 0.0), (204./255., 204./255., 255./255.), (159./255., 140./255., 216./255.), (124./255., 82./255., 165./255.), (86./255., 28./255., 114./255.), (46/255., 0./255., 51./255.) ] smap = mcolors.ListedColormap(scolors, 'snows') snorm = mcolors.BoundaryNorm(snow_int, smap.N,clip=False) smap.set_over('darkviolet') precip_int = np.array([0.00,0.01, 0.1, 0.25, 0.50, 0.75, 1.0, 1.25, 1.5, 1.75, 2.0, 2.5, 3.0, 4.0, 5.0, 7.0, 10., 15., 20.]) colors = [(1.0, 1.0, 1.0), (199./255., 231./255., 192./255.), (161./255., 227./255., 155./255.), (116./255., 196./255., 118./255.), (49./255., 163./255., 83./255.), (0.0, 109./255., 44./255.), (1.0, 250./255., 138./255.), (1.0, 204./255., 79./255.), (254./255., 141./255., 60./255.), (252./255., 78./255., 42./255.), (214./255., 26./255., 28./255), (173./255., 0.0, 38./255.), (105./255., 0.0, 0.0), (1.0, 170./255., 250./255.), (1.0, 131./255., 249./255.), (1.0, 87./255., 247./255.), (230./255., 25./255., 249./255.), (148./255., 0.0, 204./255.)] pmap = mcolors.ListedColormap(colors, 'precipitation') pnorm = mcolors.BoundaryNorm(precip_int, pmap.N) def get_nvar(*args, **kwargs): nvar = Element('test-input').element.value input(nvar) def input(nvar): date = Element('date').element.value vm = int(Element('vmax').element.value) print(date) if len(date) > 3: console.log(f'text: {date}') today = Element('date').element.value else: today = datetime.strftime(datetime.utcnow(),'%Y%m%d') now = datetime.strftime(datetime.utcnow(),'%Y%m%d %H%M') #expect hrrr,gfs,fv3,p1,p2,nssl models = np.array(['gfs','fv3href','nam','hrrr','rrfsp1','rrfsp2','nssl','mrms']) hours = np.array([85,61,61,49,61,37,61,85]) cycles = np.array(['00','06','12','18']) #nvar = 'pmax' if (nvar == 'prate' or nvar == 'pmax' or nvar == 'uh'): accum = '1' else: accum = Element('naccum').element.value console.log(f'text: {nvar,accum}') if nvar == 'prate': #vm = 25 lab = 'In/hr' cmap = rmap norm = rnorm intervals = rate_int vals = rate_int elif nvar == 'precip': #vm = 20 lab = 'In' cmap = pmap intervals = precip_int vals = precip_int elif nvar == 'snow': #vm = 20 lab = 'In' cmap = smap intervals = snow_int vals = snow_int elif nvar == 'uh': #vm = 1000 lab = r'$m^{2}s^{-2}$' cmap = umap norm = unorm intervals = uh_int vals = uh_int elif nvar == 'pmax': #vm = 25 lab = "In/hr" cmap = rmap norm = rnorm intervals = rate_int vals = rate_int arr = np.zeros([np.size(cycles),np.size(models),np.max(hours)]) for cc,c in enumerate(cycles): try: fil = f"dash_mrms.csv" fh = open_url(f"https://www.wpc.ncep.noaa.gov/hmt/hmt_webpages/drawingtools/{fil}").readlines() console.log(f'MRMS Cycle: {c}, successful read') except: continue #convert the date and time into cycle relative forecast hours for j,i in enumerate(fh): try: #console.log(f'text: {i}') temp = i.split(',') tem = datetime.strptime(temp[0]+temp[1],'%Y%m%d%H') dt = int((tem-datetime.strptime(today+c,'%Y%m%d%H')).total_seconds()/(60*60)) console.log(f'text: {tem},{dt},{temp}') if dt >= 0 and dt < np.max(hours): if nvar == temp[4] and accum == temp[5]: jj = np.where(models==temp[3])[0] arr[cc,-1,dt] = float(temp[6]) except: continue for m in models[:-1]: console.log(f'Model read: {m}') try: fil = f"dash_{m}_{today}.csv" fh = open_url(f"https://www.wpc.ncep.noaa.gov/hmt/hmt_webpages/drawingtools/{fil}").readlines() xx = len(fh) #print('file:',fil,'x:',x) except: continue try: for j,i in enumerate(fh): temp = i.split(',') x = np.where(cycles == temp[1])[0][0] #print(j,i,x,m) if nvar == temp[4] and temp[0][0:8] == today and accum == temp[5]: k = int(temp[2]) #print(j,i,x,m,k) jj = np.where(models==temp[3].lower())[0] arr[x,jj,k] = float(temp[6]) except: print('missing:',m) arr[arr==0] = np.nan #mc = np.nanmax(arr) # Generate image dashboard for the 00z runs fig, axs = plt.subplot_mosaic([['a', 'b'], ['c', 'd']],figsize=(12,6),sharex=True,sharey=True) # ,constrained_layout=True) fig.suptitle(nvar.upper()+' '+accum+' hr, CONUS Max Values @ '+now ) #if nvar != 'precip': # axs['a'].imshow(arr[0],interpolation='none',origin='lower',aspect=5,cmap=cmap,norm=norm) # axs['b'].imshow(arr[1],interpolation='none',origin='lower',aspect=5,cmap=cmap,norm=norm) # axs['c'].imshow(arr[2],interpolation='none',origin='lower',aspect=5,cmap=cmap,norm=norm) # im = axs['d'].imshow(arr[3],interpolation='none',origin='lower',aspect=5,cmap=cmap,norm=norm) #else: im = axs['a'].imshow(arr[0],interpolation='none',origin='lower',aspect=5,vmin=0,vmax=vm) axs['b'].imshow(arr[1],interpolation='none',origin='lower',aspect=5,vmin=0,vmax=vm) axs['c'].imshow(arr[2],interpolation='none',origin='lower',aspect=5,vmin=0,vmax=vm) axs['d'].imshow(arr[3],interpolation='none',origin='lower',aspect=5,vmin=0,vmax=vm) axs['a'].set_title('00 UTC '+today) axs['b'].set_title('06 UTC '+today) axs['c'].set_title('12 UTC '+today) axs['d'].set_title('18 UTC '+today) mc = np.nanmax(arr[0]) axs['a'].set_title(str(round(mc,1)),loc='left') mc = np.nanmax(arr[1]) axs['b'].set_title(str(round(mc,1)),loc='left') mc = np.nanmax(arr[2]) axs['c'].set_title(str(round(mc,1)),loc='left') mc = np.nanmax(arr[3]) axs['d'].set_title(str(round(mc,1)),loc='left') axs['c'].set_xlabel('forecast hrs') axs['d'].set_xlabel('forecast hrs') axs['a'].set_yticks(np.arange(0,np.size(models),1),labels=models) axs['b'].set_yticks(np.arange(0,np.size(models),1),labels=models) axs['c'].set_yticks(np.arange(0,np.size(models),1),labels=models) axs['d'].set_yticks(np.arange(0,np.size(models),1),labels=models) cbar_ax = fig.add_axes([0.92, 0.1, 0.025, 0.8]) fig.colorbar(im, cax=cbar_ax,orientation='vertical',extend='max',label=lab) pyscript.write("plot",fig)