- matplotlib

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


Default Models: gfs,fv3href,nam,hrrr,rrfsp1,nssl. order determines position (in default mrms is at the top), lower case only, and separated by commas





# 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 gp_int = [0,1,10,50,100,500,1000,5000,10000,50000,100000,500000,1000000] gmap = plt.cm.tab20c gnorm = mcolors.BoundaryNorm(gp_int, gmap.N) 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 model_hr(model): hrd = {'gfs':85, 'fv3href':61, 'nam':61,'hrrr':48,'rrfsp1':61, 'rrfsp3':85,'rrfsp4':85,'nssl':48, 'mrms':85} return hrd[model] 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 try: modela = Element('model').element.value #console.log(f"empty?: {modela}") except: modela = None #print('no models entered') if modela == '': models = np.array(['gfs','fv3href','nssl','nam','hrrr','rrfsp1','rrfsp3','rrfsp4','mrms']) else: models = modela.split(',') models.append('mrms') models = np.array(models) console.log(f"Models: {models}") # need a dict for the models run time hours = [] for q,model in enumerate(models): hours.append(model_hr(model)) hours = np.array(hours) console.log(hours) cycles = np.array(['00','06','12','18']) #nvar = 'pmax' if (nvar == 'prate' or nvar == 'pmax' or nvar == 'uh'): accum = '1' elif nvar == 'covp6': accum = '6' 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 elif nvar == 'covp6': lab = "Grid pts" cmap = gmap norm = gnorm intervals = gp_int vals = gp_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/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)) #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/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]) #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 ) 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'].axvline(12,ls='--',color='white') axs['a'].axvline(24,ls='--',color='white') axs['a'].axvline(36,ls='--',color='white') axs['a'].axvline(48,ls='--',color='white') axs['a'].axvline(60,ls='--',color='white') axs['a'].axvline(72,ls='--',color='white') axs['b'].axvline(6,ls='--',color='white') axs['b'].axvline(18,ls='--',color='white') axs['b'].axvline(30,ls='--',color='white') axs['b'].axvline(42,ls='--',color='white') axs['b'].axvline(54,ls='--',color='white') axs['b'].axvline(66,ls='--',color='white') axs['b'].axvline(78,ls='--',color='white') axs['c'].axvline(12,ls='--',color='white') axs['c'].axvline(24,ls='--',color='white') axs['c'].axvline(36,ls='--',color='white') axs['c'].axvline(48,ls='--',color='white') axs['c'].axvline(60,ls='--',color='white') axs['c'].axvline(72,ls='--',color='white') axs['d'].axvline(18,ls='--',color='white') axs['d'].axvline(30,ls='--',color='white') axs['d'].axvline(42,ls='--',color='white') axs['d'].axvline(54,ls='--',color='white') axs['d'].axvline(66,ls='--',color='white') axs['d'].axvline(78,ls='--',color='white') 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') for y,i in enumerate(arr[0]): mc = np.nanmax(i) axs['a'].text(78,y-0.25,str(round(mc,1)),color='r') for y,i in enumerate(arr[1]): mc = np.nanmax(i) axs['b'].text(78,y-0.25,str(round(mc,1)),color='r') for y,i in enumerate(arr[2]): mc = np.nanmax(i) axs['c'].text(78,y-0.25,str(round(mc,1)),color='r') for y,i in enumerate(arr[3]): mc = np.nanmax(i) axs['d'].text(78,y-0.25,str(round(mc,1)),color='r') 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)