- matplotlib

Valid keywords: precip,prate,pmax. Valid accum for precip only: 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) 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') models = np.array(['rrfsp1','rrfsp3','rrfsp4','rrfspe1','rrfspe2','rrfspe3','rrfspe4','rrfspe5','rrfspe6','rrfspe7','rrfspe8','rrfspe9','rrfsmpe1','rrfsmpe2','rrfsmpe3','rrfsmpe4','rrfsmpe5','rrfsmpe6','rrfsmpe7','rrfsmpe8','rrfsmpe9','rrfspq1','rrfspq2','rrfspq3','rrfspq4','rrfspq5','rrfspq6','rrfspq7','rrfspq8','rrfspq9','rrfspq10','rrfsp5','rrfsp6','rrfsp7','mrms']) hours = np.array([85]*len(models)) cycles = np.array(['00','06','12','18']) #nvar = 'pmax' if nvar != 'precip': 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 == 'pmax': #vm = 25 lab = "In/hr" cmap = rmap norm = rnorm intervals = rate_int vals = rate_int elif nvar == 'covp6': lab = "Grid pts" cmap = gmap norm = gnorm intervals = gp_int vals = gp_int arra = np.zeros([np.size(cycles),len(models),103]) 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/dash/{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)) + int(c) #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] arra[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/dash/{fil}").readlines() xx = len(fh) #print('file:',fil,'x:',x) except: continue try: for j,i in enumerate(fh): #which one #console.log(f'text: {i}') 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])+int(temp[1]) #account for cycle offset #print(j,i,x,m,k) jj = np.where(models==temp[3].lower())[0] arra[x,jj,k] = float(temp[6]) except: print('missing:',m) arra[arra==0] = np.nan # Generate image dashboard for the 00z runs fig, axs = plt.subplot_mosaic([['a'], ['b'], ['c'], ['d']],figsize=(20,16),sharex=True,dpi=150) # ,constrained_layout=True) fig.suptitle(nvar.upper()+' '+accum+' hr, CONUS Max Values @ '+now ) im = axs['a'].imshow(arra[0],interpolation='none',origin='lower',aspect=.5,vmin=0,vmax=vm) axs['b'].imshow(arra[1],interpolation='none',origin='lower',aspect=.5,vmin=0,vmax=vm) axs['c'].imshow(arra[2],interpolation='none',origin='lower',aspect=.5,vmin=0,vmax=vm) axs['d'].imshow(arra[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(arra[0]) axs['a'].set_title(str(round(mc,1)),loc='left') mc = np.nanmax(arra[1]) axs['b'].set_title(str(round(mc,1)),loc='left') mc = np.nanmax(arra[2]) axs['c'].set_title(str(round(mc,1)),loc='left') mc = np.nanmax(arra[3]) axs['d'].set_title(str(round(mc,1)),loc='left') for y,i in enumerate(arra[0]): mc = np.nanmax(i) axs['a'].text(96,y-0.25,str(round(mc,1)),color='r',fontsize=5) for y,i in enumerate(arra[1]): mc = np.nanmax(i) axs['b'].text(96,y-0.25,str(round(mc,1)),color='r',fontsize=5) for y,i in enumerate(arra[2]): mc = np.nanmax(i) axs['c'].text(96,y-0.25,str(round(mc,1)),color='r',fontsize=5) for y,i in enumerate(arra[3]): mc = np.nanmax(i) axs['d'].text(96,y-0.25,str(round(mc,1)),color='r',fontsize=5) axs['d'].set_xlabel(f"Hours past {today} 00 UTC") axs['a'].set_yticks(np.arange(0,np.size(models),1),labels=models,fontsize=4) axs['b'].set_yticks(np.arange(0,np.size(models),1),labels=models,fontsize=4) axs['c'].set_yticks(np.arange(0,np.size(models),1),labels=models,fontsize=4) axs['d'].set_yticks(np.arange(0,np.size(models),1),labels=models,fontsize=4) for tt in [12,24,36,48,60,72,84,96]: axs['a'].axvline(tt,ls='--',color='white') axs['b'].axvline(tt,ls='--',color='white') axs['c'].axvline(tt,ls='--',color='white') axs['d'].axvline(tt,ls='--',color='white') 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)