Example #1
0
     os.makedirs(SAVE)
     print "created:", SAVE
     # then link the photo viewer
     photo_viewer = '/uufs/chpc.utah.edu/common/home/u0553130/public_html/Brian_Blaylock/photo_viewer/photo_viewer2.php'
     os.link(photo_viewer, SAVE + 'photo_viewer2.php')
 # Title over map
 figs[locName][1].set_title('UTC: %s' % (TS_dates[hh]))
 figs[locName][2].set_title(
     '       Run (UTC): %s f%02d\nValid (UTC): %s' %
     (H['anlys'].strftime('%Y %b %d, %H:%M'), fxx,
      H['valid'].strftime('%Y %b %d, %H:%M')))
 #
 # Project on map
 X, Y = maps[locName](H['lon'], H['lat'])  # HRRR grid
 # Trim the data
 cut_v, cut_h = pluck_point_new(l['latitude'], l['longitude'], H['lat'],
                                H['lon'])
 bfr = 15
 trim_X = X[cut_v - bfr:cut_v + bfr, cut_h - bfr:cut_h + bfr]
 trim_Y = Y[cut_v - bfr:cut_v + bfr, cut_h - bfr:cut_h + bfr]
 trim_dBZ = dBZ[cut_v - bfr:cut_v + bfr, cut_h - bfr:cut_h + bfr]
 trim_H_U = H_U['value'][cut_v - bfr:cut_v + bfr,
                         cut_h - bfr:cut_h + bfr]
 trim_H_V = H_V['value'][cut_v - bfr:cut_v + bfr,
                         cut_h - bfr:cut_h + bfr]
 #
 # Overlay Simulated Radar Reflectivity
 ctable = 'NWSReflectivity'
 norm, cmap = ctables.registry.get_with_steps(ctable, -0, 5)
 radar = figs[locName][1].pcolormesh(trim_X,
                                     trim_Y,
                                     trim_dBZ,
Example #2
0
def get_OSG_stats(locs, variable, stats, months=range(1,13), hours=range(0,24), extra=True, fxx=0):
    """
    Returns a dictionary of values plucked from the OSG HRRR statistics files.

    Input:
        locs - a dictionary with the latitude and longitude of each location
               e.g. {'NAME':{'latitude':40, 'longitude':-111}}
        variable - the HRRR variable name (e.g. 'TMP:2 m' or 'WIND:10 m')
        stats - a list of the requested statistics. May include:
               ['MAX', 'MIN', 'MEAN', 'P01', 'P05', 'P10', 'P90', 'P95', 'P99']
               (the more you ask for, the longer it takes)
        months - a list of months
        hours - a list of hours
        extra - returns other data if True, 
                count: sample size of statistics
                cores: number of cores used by the OSG node to compute the statistics
                timer: length of time to create the file on the OSG
        fxx - the forecast hour. So far only fxx is available
    """
    
    # The variable with underscores replacing the special characters in the 
    # HRRR variable name
    var = variable.replace(':', '_').replace(' ', '_')

    # Define an offset for temperature
    if variable == 'TMP:2 m' or variable == 'DPT:2 m':
        offset = 273.15
    else:
        offset = 0

    # Open the first file, so we can pluck the points and store the position
    A = '/uufs/chpc.utah.edu/common/home/horel-group/archive/'
    B = 'HRRR/OSG_hourbymonth_stats_20150418-2017731/'
    C = '%s/' % var

    DIR = A+B+C
    FILE = 'OSG_HRRR_%s_m%02d_h%02d_f%02d.nc' % (var, 1, 0, fxx)

    # Handle for every netCDF file we want: 
    # Starting with all hours for first month first, then all hours the second month, etc.
    a = [Dataset(DIR+'OSG_HRRR_%s_m%02d_h%02d_f%02d.nc' % (var, i, j, fxx), 'r') for i in months for j in hours]
    print 'Got the file handles'

    # Initalize the return dictionary
    return_this = {'month':np.array([i for i in months for j in hours]),
                   'hour':np.array([j for i in months for j in hours]),
                   'monthhour':np.array([i+j/24. for i in months for j in hours])}

    # Store the requested values in the return dictionary
    if extra==True:
        return_this['count'] = np.array([i.variables['count'][0] for i in a])
        return_this['cores'] = np.array([i.variables['cores'][0] for i in a])
        return_this['timer'] = np.array([''.join(i.variables['timer'][:]) for i in a])
        print 'Got the count, cores, and timer'

    # Get the pluck indexes for each requested location
    Hlat = a[0].variables['latitude'][:]  # HRRR latitude grid
    Hlon = a[0].variables['longitude'][:] # HRRR longitude grid
    for L in locs:
        print 'working on L...',
        Slat = locs[L]['latitude']            # Station latitude point
        Slon = locs[L]['longitude']           # Statin longitude point   
        x, y = pluck_point_new(Slat, Slon, Hlat, Hlon)
        print 'got the plucked points...',

        return_this[L] = {'stn_latlon':[Slat, Slon],
                          'hrrr_latlon':[Hlat[x[0],y[0]], Hlon[x[0],y[0]]]}
        if 'MAX' in stats:
            return_this[L]['MAX'] = np.array([i.variables['max_'+var][x[0],y[0]]-offset for i in a])
            print 'got the max...',
        if 'MIN' in stats:
            return_this[L]['MIN'] = np.array([i.variables['min_'+var][x[0],y[0]]-offset for i in a])
            print 'got the min...',
        if 'MEAN' in stats:
            return_this[L]['MEAN'] = np.array([i.variables['mean_'+var][x[0],y[0]]-offset for i in a])
            print 'got the mean...',
        if 'P01' in stats:
            return_this[L]['P01'] = np.array([i.variables['percentile'][0][x[0],y[0]]-offset for i in a])
            print 'got the P01...',
        if 'P05' in stats:
            return_this[L]['P05'] = np.array([i.variables['percentile'][1][x[0],y[0]]-offset for i in a])
            print 'got the P05...',
        if 'P10' in stats:
            return_this[L]['P10'] = np.array([i.variables['percentile'][2][x[0],y[0]]-offset for i in a])
            print 'got the P10...',
        if 'P90' in stats:
            return_this[L]['P90'] = np.array([i.variables['percentile'][3][x[0],y[0]]-offset for i in a])
            print 'got the P90...',
        if 'P95' in stats:
            return_this[L]['P95'] = np.array([i.variables['percentile'][4][x[0],y[0]]-offset for i in a])
            print 'got the P95...',
        if 'P99' in stats:
            return_this[L]['P99'] = np.array([i.variables['percentile'][5][x[0],y[0]]-offset for i in a])    
            print 'got the P99...',

    # Close the NetCDF files
    for close in a:
        close.close()
    print 'done!'

    return return_this
Example #3
0
def make_plots(inputs):
    VALIDDATE, fxx = inputs
    print 'working on %s f%02d' % (VALIDDATE, fxx)
    plt.clf()
    plt.cla()

    print fxx, VALIDDATE

    # === Some housekeeping variables =============================================
    # Convert Valid Date to Run Date, adjusted by the forecast
    DATE = VALIDDATE - timedelta(hours=fxx)

    # Parse Location lat/lon
    if ',' in location:
        # User put inputted a lat/lon point request
        lat, lon = location.split(',')
        lat = float(lat)
        lon = float(lon)
    else:
        # User requested a MesoWest station
        stninfo = get_station_info([location])
        lat = stninfo['LAT']
        lon = stninfo['LON']

    # Preload the latitude and longitude grid
    latlonpath = '/uufs/chpc.utah.edu/common/home/horel-group7/Pando/hrrr/HRRR_latlon.h5'
    latlonh5 = h5py.File(latlonpath, 'r')
    gridlat = latlonh5['latitude'][:]
    gridlon = latlonh5['longitude'][:]

    # === Create map of the domain ================================================

    if dsize == 'conus' and model != 'hrrrAK':
        barb_thin = 70
        alpha = 1
        t1 = datetime.now()
        #m = draw_CONUS_HRRR_map(res=map_res)
        m = np.load(
            '/uufs/chpc.utah.edu/common/home/u0553130/public_html/Brian_Blaylock/cgi-bin/HRRR_CONUS_map_object_'
            + map_res + '.npy').item()
        m.drawcountries(zorder=500)
        m.drawstates(zorder=500)
        m.drawcoastlines(zorder=500)
        m.fillcontinents(color='tan', lake_color='lightblue', zorder=0)
        m.drawmapboundary(fill_color='lightblue')
        t2 = datetime.now()
    else:
        # configure some setting based on the requested domain size
        if dsize == 'small':
            plus_minus_latlon = .27  # +/- latlon box around center point
            barb_thin = 1  # Thin out excessive wind barbs
            arcgis_res = 1000  # ArcGIS image resolution
            bfr = 15  # trim domain buffer
            alpha = .75  # Alpha (pcolormesh transparency)
        elif dsize == 'medium':
            plus_minus_latlon = .75
            barb_thin = 2
            arcgis_res = 800
            bfr = 35
            alpha = .75
        elif dsize == 'large':
            plus_minus_latlon = 2.5
            barb_thin = 6
            arcgis_res = 800
            bfr = 110
            alpha = .75
        elif dsize == 'xlarge':
            plus_minus_latlon = 5
            barb_thin = 12
            arcgis_res = 700
            bfr = 210
            alpha = .75
        elif dsize == 'xxlarge':  # If domain runs into HRRR boundary, then it'll fail
            plus_minus_latlon = 10
            barb_thin = 25
            arcgis_res = 700
            bfr = 430
            alpha = .75
        elif dsize == 'xxxlarge':
            plus_minus_latlon = 15
            barb_thin = 35
            arcgis_res = 1000
            bfr = 700
            alpha = .75
        m = Basemap(resolution=map_res, projection='cyl',\
                    area_thresh=3000,\
                    llcrnrlon=lon-plus_minus_latlon, llcrnrlat=lat-plus_minus_latlon,\
                    urcrnrlon=lon+plus_minus_latlon, urcrnrlat=lat+plus_minus_latlon,)
        m.drawstates(zorder=500)
        m.drawcountries(zorder=500)
        m.drawcoastlines(zorder=500)
        #if dsize == 'small' or dsize == 'medium':
        #    m.drawcounties()

    # === Add a Background image ==================================================
    # Start the map image
    plt.figure(1)
    if background == 'arcgis' and dsize != 'conus':
        m.arcgisimage(service='World_Shaded_Relief',
                      xpixels=arcgis_res,
                      verbose=False)
    elif background == 'arcgisSat' and dsize != 'conus':
        m.arcgisimage(service='ESRI_Imagery_World_2D',
                      xpixels=arcgis_res,
                      verbose=False)
    elif background == 'arcgisRoad' and dsize != 'conus':
        m.arcgisimage(service='NatGeo_World_Map',
                      xpixels=arcgis_res,
                      verbose=False)
    elif background == 'terrain':
        # Get data
        H_ter = get_hrrr_variable(
            DATE,
            'HGT:surface',
            model=model,
            fxx=fxx,
            outDIR='/uufs/chpc.utah.edu/common/home/u0553130/temp/',
            verbose=False,
            value_only=True)
        H_land = get_hrrr_variable(
            DATE,
            'LAND:surface',
            model=model,
            fxx=fxx,
            outDIR='/uufs/chpc.utah.edu/common/home/u0553130/temp/',
            verbose=False,
            value_only=True)

        # Plot the terrain
        m.contourf(gridlon,
                   gridlat,
                   H_ter['value'],
                   levels=range(0, 4000, 200),
                   cmap='Greys_r',
                   zorder=1,
                   latlon=True)
        # Plot Water area
        m.contour(gridlon,
                  gridlat,
                  H_land['value'],
                  levels=[0, 1],
                  colors='b',
                  zorder=1,
                  latlon=True)
    elif background == 'landuse':
        # Get data
        from BB_cmap.landuse_colormap import LU_MODIS21
        if model == 'hrrr':
            VGTYP = 'VGTYP:surface'
        else:
            VGTYP = 'var discipline=2 center=59 local_table=1 parmcat=0 parm=198'
        H_LU = get_hrrr_variable(
            DATE,
            VGTYP,
            model=model,
            fxx=fxx,
            outDIR='/uufs/chpc.utah.edu/common/home/u0553130/temp/',
            verbose=False,
            value_only=True)

        # Plot the terrain
        cm, labels = LU_MODIS21()
        m.pcolormesh(gridlon,
                     gridlat,
                     H_LU['value'],
                     cmap=cm,
                     vmin=1,
                     vmax=len(labels) + 1,
                     zorder=1,
                     latlon=True)

    # Add SHAPEFILE
    if is_FIRE:
        plt.gca().add_collection(
            PatchCollection(patches,
                            facecolor='indianred',
                            alpha=.65,
                            edgecolor='k',
                            linewidths=1,
                            zorder=1))

    # === Figure Title ============================================================
    if dsize != 'conus':
        m.scatter(lon, lat, marker='+', c='r', s=100, zorder=1000, latlon=True)
        plt.title('Center: %s\n%s' % (location, model.upper()),
                  fontweight='bold')
    else:
        plt.title('%s' % (model.upper()), fontweight='bold')
    plt.title('Run: %s F%02d' % (DATE.strftime('%Y-%m-%d %H:%M UTC'), fxx),
              loc='left')
    plt.title('Valid: %s' %
              (DATE + timedelta(hours=fxx)).strftime('%Y-%m-%d %H:%M UTC'),
              loc='right')
    # =============================================================================

    if '10mWind_Fill' in plotcode or '10mWind_Shade' in plotcode or '10mWind_Barb' in plotcode or '10mWind_Quiver' in plotcode or '10mWind_p95_fill' in plotcode:
        # Get data
        H_u = get_hrrr_variable(
            DATE,
            'UGRD:10 m',
            model=model,
            fxx=fxx,
            outDIR='/uufs/chpc.utah.edu/common/home/u0553130/temp/',
            verbose=False,
            value_only=True)
        H_v = get_hrrr_variable(
            DATE,
            'VGRD:10 m',
            model=model,
            fxx=fxx,
            outDIR='/uufs/chpc.utah.edu/common/home/u0553130/temp/',
            verbose=False,
            value_only=True)
        spd = wind_uv_to_spd(H_u['value'], H_v['value'])

        if '10mWind_Fill' in plotcode:
            m.pcolormesh(gridlon,
                         gridlat,
                         spd,
                         latlon=True,
                         cmap=cm_wind(),
                         vmin=0,
                         vmax=60,
                         alpha=alpha)
            cb = plt.colorbar(orientation='horizontal', pad=pad, shrink=shrink)
            cb.set_label(r'10 m Wind Speed (m s$\mathregular{^{-1}}$)')

        if '10mWind_Shade' in plotcode:
            m.contourf(gridlon,
                       gridlat,
                       spd,
                       levels=[10, 15, 20, 25],
                       colors=('yellow', 'orange', 'red'),
                       alpha=alpha,
                       extend='max',
                       zorder=1,
                       latlon=True)
            cb = plt.colorbar(orientation='horizontal', shrink=shrink, pad=pad)
            cb.set_label(r'10 m Wind Speed (ms$\mathregular{^{-1}}$)')

        if '10mWind_Barb' in plotcode or '10mWind_Quiver' in plotcode:
            # For small domain plots, trimming the edges significantly reduces barb plotting time
            if barb_thin < 20:
                cut_v, cut_h = pluck_point_new(lat, lon, gridlat, gridlon)
                Cgridlat = gridlat[cut_v - bfr:cut_v + bfr,
                                   cut_h - bfr:cut_h + bfr]
                Cgridlon = gridlon[cut_v - bfr:cut_v + bfr,
                                   cut_h - bfr:cut_h + bfr]
                H_u['value'] = H_u['value'][cut_v - bfr:cut_v + bfr,
                                            cut_h - bfr:cut_h + bfr]
                H_v['value'] = H_v['value'][cut_v - bfr:cut_v + bfr,
                                            cut_h - bfr:cut_h + bfr]
            else:
                Cgridlat = gridlat
                Cgridlon = gridlon

            thin = barb_thin
            # Add to plot
            if '10mWind_Barb' in plotcode:
                m.barbs(Cgridlon[::thin, ::thin],
                        Cgridlat[::thin, ::thin],
                        H_u['value'][::thin, ::thin],
                        H_v['value'][::thin, ::thin],
                        zorder=200,
                        length=5.5,
                        barb_increments={
                            'half': 2.5,
                            'full': 5,
                            'flag': 25
                        },
                        latlon=True)
            if '10mWind_Quiver' in plotcode:
                Q = m.quiver(Cgridlon[::thin, ::thin],
                             Cgridlat[::thin, ::thin],
                             H_u['value'][::thin, ::thin],
                             H_v['value'][::thin, ::thin],
                             zorder=350,
                             latlon=True)

                qk = plt.quiverkey(Q,
                                   .92,
                                   0.07,
                                   10,
                                   r'10 m s$^{-1}$',
                                   labelpos='S',
                                   coordinates='axes',
                                   color='darkgreen')
                qk.text.set_backgroundcolor('w')

        if '10mWind_p95_fill' in plotcode:
            DIR = '/uufs/chpc.utah.edu/common/home/horel-group8/blaylock/HRRR_OSG/hourly30/UVGRD_10_m/'
            FILE = 'OSG_HRRR_%s_m%02d_d%02d_h%02d_f00.h5' % (
                ('UVGRD_10_m', VALIDDATE.month, VALIDDATE.day, VALIDDATE.hour))
            with h5py.File(DIR + FILE, 'r') as f:
                spd_p95 = f["p95"][:]
            masked = spd - spd_p95
            masked = np.ma.array(masked)
            masked[masked < 0] = np.ma.masked

            m.pcolormesh(gridlon,
                         gridlat,
                         masked,
                         vmax=10,
                         vmin=0,
                         latlon=True,
                         cmap='viridis',
                         alpha=alpha)
            cb = plt.colorbar(orientation='horizontal', pad=pad, shrink=shrink)
            cb.set_label(
                r'10 m Wind Speed exceeding 95th Percentile (m s$\mathregular{^{-1}}$)'
            )

    if '80mWind_Fill' in plotcode or '80mWind_Shade' in plotcode or '80mWind_Barb' in plotcode:
        # Get data
        H_u = get_hrrr_variable(
            DATE,
            'UGRD:80 m',
            model=model,
            fxx=fxx,
            outDIR='/uufs/chpc.utah.edu/common/home/u0553130/temp/',
            verbose=False,
            value_only=True)
        H_v = get_hrrr_variable(
            DATE,
            'VGRD:80 m',
            model=model,
            fxx=fxx,
            outDIR='/uufs/chpc.utah.edu/common/home/u0553130/temp/',
            verbose=False,
            value_only=True)
        spd = wind_uv_to_spd(H_u['value'], H_v['value'])

        if '80mWind_Fill' in plotcode:
            m.pcolormesh(gridlon,
                         gridlat,
                         spd,
                         latlon=True,
                         cmap=cm_wind(),
                         vmin=0,
                         vmax=60,
                         alpha=alpha)
            cb = plt.colorbar(orientation='horizontal', pad=pad, shrink=shrink)
            cb.set_label(r'10 m Wind Speed (m s$\mathregular{^{-1}}$)')

        if '80mWind_Shade' in plotcode:
            m.contourf(gridlon,
                       gridlat,
                       spd,
                       levels=[10, 15, 20, 25],
                       colors=('yellow', 'orange', 'red'),
                       alpha=alpha,
                       extend='max',
                       zorder=10,
                       latlon=True)
            cb = plt.colorbar(orientation='horizontal', shrink=shrink, pad=pad)
            cb.set_label(r'10 m Wind Speed (ms$\mathregular{^{-1}}$)')

        if '80mWind_Barb' in plotcode:
            # For small domain plots, trimming the edges significantly reduces barb plotting time
            if barb_thin < 20:
                cut_v, cut_h = pluck_point_new(lat, lon, gridlat, gridlon)
                Cgridlat = gridlat[cut_v - bfr:cut_v + bfr,
                                   cut_h - bfr:cut_h + bfr]
                Cgridlon = gridlon[cut_v - bfr:cut_v + bfr,
                                   cut_h - bfr:cut_h + bfr]
                H_u['value'] = H_u['value'][cut_v - bfr:cut_v + bfr,
                                            cut_h - bfr:cut_h + bfr]
                H_v['value'] = H_v['value'][cut_v - bfr:cut_v + bfr,
                                            cut_h - bfr:cut_h + bfr]
            else:
                Cgridlat = gridlat
                Cgridlon = gridlon

            # Add to plot
            thin = barb_thin
            m.barbs(Cgridlon[::thin, ::thin],
                    Cgridlat[::thin, ::thin],
                    H_u['value'][::thin, ::thin],
                    H_v['value'][::thin, ::thin],
                    zorder=200,
                    length=5.5,
                    color='darkred',
                    barb_increments={
                        'half': 2.5,
                        'full': 5,
                        'flag': 25
                    },
                    latlon=True)

        if 'Fill80mWind' in plotcode:
            m.pcolormesh(gridlon,
                         gridlat,
                         spd,
                         latlon=True,
                         cmap=cm_wind(),
                         vmin=0,
                         vmax=60,
                         alpha=alpha)
            cb = plt.colorbar(orientation='horizontal', pad=pad, shrink=shrink)
            cb.set_label(r'80 m Wind Speed (m s$\mathregular{^{-1}}$)')

    if 'Gust_Hatch' in plotcode:
        H_gust = get_hrrr_variable(
            DATE,
            'GUST:surface',
            model=model,
            fxx=fxx,
            outDIR='/uufs/chpc.utah.edu/common/home/u0553130/temp/',
            verbose=False,
            value_only=True)

        # Add to plot
        m.contourf(gridlon,
                   gridlat,
                   H_gust['value'],
                   levels=[0, 10, 15, 20, 25],
                   hatches=[None, '.', '\\\\', '*'],
                   colors='none',
                   extend='max',
                   zorder=10,
                   latlon=True)
        cb = plt.colorbar(orientation='horizontal', shrink=shrink, pad=pad)
        cb.set_label(r'Surface Wind Gust (ms$\mathregular{^{-1}}$)')

        m.contour(gridlon,
                  gridlat,
                  H_gust['value'],
                  levels=[10, 15, 20, 25],
                  colors='k',
                  zorder=10,
                  latlon=True)

    if 'dBZ_Fill' in plotcode or 'dBZ_Contour' in plotcode:
        from BB_cmap.reflectivity_colormap import reflect_ncdc
        # Get Data
        if model == 'hrrr':
            REFC = 'REFC:entire'
        elif model == 'hrrrX' or model == 'hrrrAK':
            REFC = 'var discipline=0 center=59 local_table=1 parmcat=16 parm=196'
        H_ref = get_hrrr_variable(
            DATE,
            REFC,
            model=model,
            fxx=fxx,
            outDIR='/uufs/chpc.utah.edu/common/home/u0553130/temp/',
            verbose=False,
            value_only=True)

        # Mask values
        dBZ = H_ref['value']
        dBZ = np.ma.array(dBZ)
        dBZ[dBZ == -10] = np.ma.masked

        # Add Contour to plot
        if 'dBZ_Contour' in plotcode:
            cREF = m.contour(gridlon,
                             gridlat,
                             dBZ,
                             cmap=reflect_ncdc(),
                             levels=range(10, 80, 10),
                             latlon=True,
                             zorder=50)
            plt.clabel(cREF,
                       cREF.levels[::2],
                       fmt='%2.0f',
                       colors='k',
                       fontsize=9)
            #cb2 = plt.colorbar(orientation='horizontal', shrink=shrink, pad=pad)
            #cb2.set_label('Simulated Composite Reflectivity (dBZ)')

        # Add fill to plot
        if 'dBZ_Fill' in plotcode:
            m.pcolormesh(gridlon,
                         gridlat,
                         dBZ,
                         cmap=reflect_ncdc(),
                         vmax=80,
                         vmin=0,
                         alpha=alpha,
                         latlon=True)
            cb2 = plt.colorbar(orientation='horizontal',
                               shrink=shrink,
                               pad=pad)
            cb2.set_label('Simulated Composite Reflectivity (dBZ)')

    if '2mDPT_p95p05_fill' in plotcode:
        H_dpt = get_hrrr_variable(
            DATE,
            'DPT:2 m',
            model=model,
            fxx=fxx,
            outDIR='/uufs/chpc.utah.edu/common/home/u0553130/temp/',
            verbose=False,
            value_only=True)

        DIR = '/uufs/chpc.utah.edu/common/home/horel-group8/blaylock/HRRR_OSG/hourly30/DPT_2_m/'
        FILE = 'OSG_HRRR_%s_m%02d_d%02d_h%02d_f00.h5' % (
            ('DPT_2_m', VALIDDATE.month, VALIDDATE.day, VALIDDATE.hour))

        ### Plot Dew Point Depression
        with h5py.File(DIR + FILE, 'r') as f:
            dpt_p05 = f["p05"][:]
        masked = H_dpt[
            'value'] - dpt_p05  # both these datasets are in Kelvin, but when we take the difference it is in Celsius
        masked = np.ma.array(masked)
        masked[masked > 0] = np.ma.masked

        mesh_depression = m.pcolormesh(gridlon,
                                       gridlat,
                                       masked,
                                       vmax=10,
                                       vmin=-10,
                                       latlon=True,
                                       cmap='BrBG')

        ### Plot Dew Point Exceedance
        with h5py.File(DIR + FILE, 'r') as f:
            dpt_p95 = f["p95"][:]
        masked = H_dpt[
            'value'] - dpt_p95  # both these datasets are in Kelvin, but when we take the difference it is in Celsius
        masked = np.ma.array(masked)
        masked[masked < 0] = np.ma.masked

        mesh_exceedance = m.pcolormesh(gridlon,
                                       gridlat,
                                       masked,
                                       vmax=10,
                                       vmin=-10,
                                       latlon=True,
                                       cmap='BrBG')
        cb = plt.colorbar(orientation='horizontal', pad=pad, shrink=shrink)
        cb.set_label(
            r'5$\mathregular{^{th}}$/95$\mathregular{^{th}}$ percentile 2 m Dew Point Depression/Exceedance (C)'
        )

    if '2mTemp_Fill' in plotcode or '2mTemp_Freeze' in plotcode or '2mTemp_p95p05_fill' in plotcode:
        # Get Data
        H_temp = get_hrrr_variable(
            DATE,
            'TMP:2 m',
            model=model,
            fxx=fxx,
            outDIR='/uufs/chpc.utah.edu/common/home/u0553130/temp/',
            verbose=False,
            value_only=True)

        TMP = H_temp['value'] - 273.15

        # Add fill to plot
        if '2mTemp_Fill' in plotcode:
            m.pcolormesh(gridlon,
                         gridlat,
                         TMP,
                         cmap=cm_temp(),
                         vmax=50,
                         vmin=-50,
                         alpha=alpha,
                         zorder=3,
                         latlon=True)
            cbT = plt.colorbar(orientation='horizontal',
                               shrink=shrink,
                               pad=pad)
            cbT.set_label('2 m Temperature (C)')
        # Add freezing contour to plot
        if '2mTemp_Freeze' in plotcode:
            m.contour(gridlon,
                      gridlat,
                      TMP,
                      colors='b',
                      levels=[0],
                      zorder=400,
                      latlon=True)

        if '2mTemp_p95p05_fill' in plotcode:
            DIR = '/uufs/chpc.utah.edu/common/home/horel-group8/blaylock/HRRR_OSG/hourly30/TMP_2_m/'
            FILE = 'OSG_HRRR_%s_m%02d_d%02d_h%02d_f00.h5' % (
                ('TMP_2_m', VALIDDATE.month, VALIDDATE.day, VALIDDATE.hour))

            ### Plot Temperature Depression
            with h5py.File(DIR + FILE, 'r') as f:
                tmp_p05 = f["p05"][:]
            masked = H_temp[
                'value'] - tmp_p05  # both these datasets are in Kelvin, but when we take the difference it is in Celsius
            masked = np.ma.array(masked)
            masked[masked > 0] = np.ma.masked

            mesh_depression = m.pcolormesh(gridlon,
                                           gridlat,
                                           masked,
                                           vmax=10,
                                           vmin=-10,
                                           latlon=True,
                                           cmap='bwr')

            ### Plot Temperature Exceedance
            with h5py.File(DIR + FILE, 'r') as f:
                tmp_p95 = f["p95"][:]
            masked = H_temp[
                'value'] - tmp_p95  # both these datasets are in Kelvin, but when we take the difference it is in Celsius
            masked = np.ma.array(masked)
            masked[masked < 0] = np.ma.masked

            mesh_exceedance = m.pcolormesh(gridlon,
                                           gridlat,
                                           masked,
                                           vmax=10,
                                           vmin=-10,
                                           latlon=True,
                                           cmap='bwr')
            cb = plt.colorbar(orientation='horizontal', pad=pad, shrink=shrink)
            cb.set_label(
                r'5$\mathregular{^{th}}$/95$\mathregular{^{th}}$ percentile 2 m Temperature Depression/Exceedance (C)'
            )

    if '2mRH_Fill' in plotcode:
        # Get Data
        try:
            H_RH = get_hrrr_variable(
                DATE,
                'RH:2 m',
                model=model,
                fxx=fxx,
                outDIR='/uufs/chpc.utah.edu/common/home/u0553130/temp/',
                verbose=False,
                value_only=True)

            # Add fill to plot
            m.pcolormesh(gridlon,
                         gridlat,
                         H_RH['value'],
                         cmap=cm_rh(),
                         vmin=5,
                         vmax=90,
                         zorder=3,
                         latlon=True)
            cbT = plt.colorbar(orientation='horizontal',
                               pad=pad,
                               shrink=shrink)
            cbT.set_label('2m Relative Humidity (%)')

        except:
            print "!! Some errors getting the RH value."
            print "!! If you requested an old date, from HRRR version 1, there isn't a RH variable,"
            print "!! and this code doesn't get the dwpt and convert it to RH yet."

    if '700Temp_Fill' in plotcode or '700Temp_-12c' in plotcode:
        # Get Data
        H_temp = get_hrrr_variable(
            DATE,
            'TMP:700 mb',
            model=model,
            fxx=fxx,
            outDIR='/uufs/chpc.utah.edu/common/home/u0553130/temp/',
            verbose=False,
            value_only=True)

        TMP = H_temp['value'] - 273.15

        # Add fill to plot
        if '700Temp_Fill' in plotcode:
            m.pcolormesh(gridlon,
                         gridlat,
                         TMP,
                         cmap=cm_temp(),
                         vmax=50,
                         vmin=-50,
                         alpha=alpha,
                         zorder=3,
                         latlon=True)
            cbT = plt.colorbar(orientation='horizontal',
                               shrink=shrink,
                               pad=pad)
            cbT.set_label('700 mb Temperature (C)')
        # Add -12 C contour to plot
        if '700Temp_-12c' in plotcode:
            m.contour(gridlon,
                      gridlat,
                      TMP,
                      colors='b',
                      levels=[-12],
                      latlon=True,
                      zorder=400)

    if '500HGT_Contour' in plotcode:
        H_500 = get_hrrr_variable(
            DATE,
            'HGT:500 mb',
            model=model,
            fxx=fxx,
            outDIR='/uufs/chpc.utah.edu/common/home/u0553130/temp/',
            verbose=False,
            value_only=True)

        CS = m.contour(gridlon,
                       gridlat,
                       H_500['value'],
                       levels=range(5040, 6181, 60),
                       linewidths=1.7,
                       colors='k',
                       latlon=True,
                       zorder=400)
        plt.clabel(CS, inline=1, fmt='%2.f')

    if '500Wind_Fill' in plotcode or '500Wind_Barb' in plotcode or '500Vort_Fill' in plotcode or '500Conv_Fill' in plotcode:
        H_u = get_hrrr_variable(
            DATE,
            'UGRD:500 mb',
            model=model,
            fxx=fxx,
            outDIR='/uufs/chpc.utah.edu/common/home/u0553130/temp/',
            verbose=False,
            value_only=True)
        H_v = get_hrrr_variable(
            DATE,
            'VGRD:500 mb',
            model=model,
            fxx=fxx,
            outDIR='/uufs/chpc.utah.edu/common/home/u0553130/temp/',
            verbose=False,
            value_only=True)

        if '500Wind_Fill' in plotcode:
            spd = wind_uv_to_spd(H_u['value'], H_v['value'])

            m.pcolormesh(gridlon,
                         gridlat,
                         spd,
                         latlon=True,
                         cmap=cm_wind(),
                         vmin=0,
                         vmax=60)
            cb = plt.colorbar(orientation='horizontal', pad=pad, shrink=shrink)
            cb.set_label(r'500 mb Wind Speed (m s$\mathregular{^{-1}}$)')

        if '500Conv_Fill' in plotcode or '500Vort_Fill' in plotcode:
            dudx, dudy = np.gradient(H_u['value'], 3, 3)
            dvdx, dvdy = np.gradient(H_v['value'], 3, 3)
            if '500Vort_Fill' in plotcode:
                vorticity = dvdx - dudy
                # Mask values
                vort = vorticity
                vort = np.ma.array(vort)
                vort[np.logical_and(vort < .05, vort > -.05)] = np.ma.masked

                m.pcolormesh(gridlon,
                             gridlat,
                             vort,
                             latlon=True,
                             cmap='bwr',
                             vmax=np.max(vort),
                             vmin=-np.max(vort))
                cb = plt.colorbar(orientation='horizontal',
                                  pad=pad,
                                  shrink=shrink)
                cb.set_label(r'500 mb Vorticity (s$\mathregular{^{-1}}$)')
            if '500Conv_Fill' in plotcode:
                convergence = dudx + dvdy
                # Mask values
                conv = convergence
                conv = np.ma.array(conv)
                conv[np.logical_and(conv < .05, conv > -.05)] = np.ma.masked

                m.pcolormesh(gridlon,
                             gridlat,
                             conv,
                             latlon=True,
                             cmap='bwr',
                             vmax=np.max(conv),
                             vmin=-np.max(conv))
                cb = plt.colorbar(orientation='horizontal',
                                  pad=pad,
                                  shrink=shrink)
                cb.set_label(r'500 mb Convergence (s$\mathregular{^{-1}}$)')

        if '500Wind_Barb' in plotcode:
            # For small domain plots, trimming the edges significantly reduces barb plotting time
            if barb_thin < 20:
                cut_v, cut_h = pluck_point_new(lat, lon, gridlat, gridlon)
                Cgridlat = gridlat[cut_v - bfr:cut_v + bfr,
                                   cut_h - bfr:cut_h + bfr]
                Cgridlon = gridlon[cut_v - bfr:cut_v + bfr,
                                   cut_h - bfr:cut_h + bfr]
                H_u['value'] = H_u['value'][cut_v - bfr:cut_v + bfr,
                                            cut_h - bfr:cut_h + bfr]
                H_v['value'] = H_v['value'][cut_v - bfr:cut_v + bfr,
                                            cut_h - bfr:cut_h + bfr]
            else:
                Cgridlat = gridlat
                Cgridlon = gridlon
            thin = barb_thin
            m.barbs(Cgridlon[::thin, ::thin],
                    Cgridlat[::thin, ::thin],
                    H_u['value'][::thin, ::thin],
                    H_v['value'][::thin, ::thin],
                    zorder=200,
                    length=6,
                    color='navy',
                    barb_increments={
                        'half': 2.5,
                        'full': 5,
                        'flag': 25
                    },
                    latlon=True)
            #plt.ylabel(r'Barbs: half=2.5, full=5, flag=25 (ms$\mathregular{^{-1}}$)')

    if 'MSLP_Contour' in plotcode or 'MSLP_Fill' in plotcode:
        H = get_hrrr_variable(
            DATE,
            'MSLMA:mean sea level',
            model=model,
            fxx=fxx,
            outDIR='/uufs/chpc.utah.edu/common/home/u0553130/temp/',
            verbose=False,
            value_only=True)

        if 'MSLP_Contour' in plotcode:
            CS = m.contour(gridlon,
                           gridlat,
                           H['value'] / 100.,
                           latlon=True,
                           levels=range(952, 1200, 4),
                           colors='k',
                           zorder=400)
            CS.clabel(inline=1, fmt='%2.f', zorder=400)

        if 'MSLP_Fill' in plotcode:
            m.pcolormesh(gridlon,
                         gridlat,
                         H['value'] / 100.,
                         latlon=True,
                         cmap='viridis')

            cb = plt.colorbar(orientation='horizontal', pad=pad, shrink=shrink)
            cb.set_label('Mean Sea Level Pressure (hPa)')

    if '2mPOT_Fill' in plotcode:
        # Get Data
        H_temp = get_hrrr_variable(
            DATE,
            'POT:2 m',
            model=model,
            fxx=fxx,
            outDIR='/uufs/chpc.utah.edu/common/home/u0553130/temp/',
            verbose=False,
            value_only=True)

        TMP = H_temp['value'] - 273.15

        m.pcolormesh(gridlon,
                     gridlat,
                     TMP,
                     cmap="Oranges",
                     alpha=alpha,
                     zorder=3,
                     latlon=True)
        cbS = plt.colorbar(orientation='horizontal', shrink=shrink, pad=pad)
        cbS.set_label('2 m Potential Temperature (C)')

    if 'SkinTemp_Fill' in plotcode:
        # Get Data
        H_temp = get_hrrr_variable(
            DATE,
            'TMP:surface',
            model=model,
            fxx=fxx,
            outDIR='/uufs/chpc.utah.edu/common/home/u0553130/temp/',
            verbose=False,
            value_only=True)

        TMP = H_temp['value'] - 273.15

        m.pcolormesh(gridlon,
                     gridlat,
                     TMP,
                     cmap="Spectral_r",
                     alpha=alpha,
                     zorder=3,
                     latlon=True)
        cbS = plt.colorbar(orientation='horizontal', shrink=shrink, pad=pad)
        cbS.set_label('Skin Temperature (C)')

    if 'AccumPrecip_Fill' in plotcode or '1hrPrecip_Fill' in plotcode:

        if 'AccumPrecip_Fill' in plotcode:
            # Get Data
            H = get_hrrr_variable(
                DATE,
                'APCP:surface:0',
                model=model,
                fxx=fxx,
                outDIR='/uufs/chpc.utah.edu/common/home/u0553130/temp/',
                verbose=False,
                value_only=True)
            # Mask values
            prec = H['value']
            prec = np.ma.array(prec)
            prec[prec == 0] = np.ma.masked

            m.pcolormesh(gridlon,
                         gridlat,
                         prec,
                         cmap=cm_precip(),
                         alpha=alpha,
                         vmin=0,
                         vmax=762,
                         zorder=3,
                         latlon=True)
            cbS = plt.colorbar(orientation='horizontal',
                               shrink=shrink,
                               pad=pad)
            cbS.set_label('Accumulated Precipitation since F00 (mm)')

        if '1hrPrecip_Fill' in plotcode:
            # Get Data
            H = get_hrrr_variable(
                DATE,
                'APCP:surface',
                model=model,
                fxx=fxx,
                outDIR='/uufs/chpc.utah.edu/common/home/u0553130/temp/',
                verbose=False,
                value_only=True)
            # Mask values
            prec = H['value']
            prec = np.ma.array(prec)
            prec[prec == 0] = np.ma.masked

            m.pcolormesh(gridlon,
                         gridlat,
                         prec,
                         cmap=cm_precip(),
                         alpha=alpha,
                         vmin=0,
                         vmax=762,
                         zorder=3,
                         latlon=True)
            cbS = plt.colorbar(
                orientation='horizontal',
                shrink=shrink,
                pad=pad,
                extend="max",
            )
            cbS.set_label('1 hour Accumulated Precipitation (mm)')

    if 'SnowCover_Fill' in plotcode:
        # Get Data
        H = get_hrrr_variable(
            DATE,
            'SNOWC',
            model=model,
            fxx=fxx,
            outDIR='/uufs/chpc.utah.edu/common/home/u0553130/temp/',
            verbose=False,
            value_only=True)

        # Mask values
        snow = H['value']
        snow = np.ma.array(snow)
        snow[snow == 0] = np.ma.masked

        m.pcolormesh(gridlon,
                     gridlat,
                     snow,
                     cmap="Blues",
                     alpha=alpha,
                     zorder=3,
                     latlon=True)
        cbS = plt.colorbar(orientation='horizontal', shrink=shrink, pad=pad)
        cbS.set_label('Snow Cover (%)')

    if 'PWAT_Fill' in plotcode:
        # Get Data
        H = get_hrrr_variable(
            DATE,
            'PWAT:entire',
            model=model,
            fxx=fxx,
            outDIR='/uufs/chpc.utah.edu/common/home/u0553130/temp/',
            verbose=False,
            value_only=True)

        m.pcolormesh(gridlon,
                     gridlat,
                     H['value'],
                     cmap="RdYlGn",
                     alpha=alpha,
                     vmin=0,
                     zorder=3,
                     latlon=True)
        cbS = plt.colorbar(orientation='horizontal', shrink=shrink, pad=pad)
        cbS.set_label(
            r'Vertically Integrated Liquid Water (kg m$\mathregular{^{-2}}$)')

    if 'CAPE_Fill' in plotcode:
        # Get Data
        H = get_hrrr_variable(
            DATE,
            'CAPE:surface',
            model=model,
            fxx=fxx,
            outDIR='/uufs/chpc.utah.edu/common/home/u0553130/temp/',
            verbose=False,
            value_only=True)

        # Mask values
        cape = H['value']
        cape = np.ma.array(cape)
        cape[cape == 0] = np.ma.masked

        m.pcolormesh(gridlon,
                     gridlat,
                     cape,
                     cmap="Oranges",
                     alpha=alpha,
                     zorder=3,
                     latlon=True)
        cbS = plt.colorbar(orientation='horizontal', shrink=shrink, pad=pad)
        cbS.set_label(r'Surface CAPE (J kg$\mathregular{^{-1}}$)')

    if 'CIN_Fill' in plotcode:
        # Get Data
        H = get_hrrr_variable(
            DATE,
            'CIN:surface',
            model=model,
            fxx=fxx,
            outDIR='/uufs/chpc.utah.edu/common/home/u0553130/temp/',
            verbose=False,
            value_only=True)

        # Mask values
        cin = H['value']
        cin = np.ma.array(cin)
        cin[cin == 0] = np.ma.masked

        m.pcolormesh(gridlon,
                     gridlat,
                     cin,
                     cmap="BuPu",
                     alpha=alpha,
                     zorder=3,
                     latlon=True)
        cbS = plt.colorbar(orientation='horizontal', shrink=shrink, pad=pad)
        cbS.set_label(r'Surface CIN (J kg$\mathregular{^{-1}}$)')

    if 'RedFlag_Fill' in plotcode or 'RedFlag_Contour' in plotcode or 'RedFlagPot_Fill' in plotcode:
        # generalized criteria for red flag warning
        # Winds (gusts) greater than 6.7 m/s and RH < 25%
        rf_RH = 25
        rf_WIND = 6.7

        # Get Data
        H_gust = get_hrrr_variable(
            DATE,
            'GUST:surface',
            model=model,
            fxx=fxx,
            outDIR='/uufs/chpc.utah.edu/common/home/u0553130/temp/',
            verbose=False,
            value_only=True)
        H_rh = get_hrrr_variable(
            DATE,
            'RH:2 m',
            model=model,
            fxx=fxx,
            outDIR='/uufs/chpc.utah.edu/common/home/u0553130/temp/',
            verbose=False,
            value_only=True)

        RedFlag = np.logical_and(H_gust['value'] > rf_WIND,
                                 H_rh['value'] < rf_RH)
        if 'RedFlag_Contour' in plotcode:
            try:
                CS = m.contour(gridlon,
                               gridlat,
                               RedFlag,
                               latlon=True,
                               colors='maroon',
                               zorder=400)
            except:
                # maybe there isn't any contours in this domain
                pass

        if 'RedFlag_Fill' in plotcode:
            RedFlag = np.ma.array(RedFlag)
            RedFlag[RedFlag == 0] = np.ma.masked
            m.pcolormesh(gridlon,
                         gridlat,
                         RedFlag,
                         cmap="YlOrRd_r",
                         alpha=alpha,
                         zorder=4,
                         latlon=True)

        if 'RedFlagPot_Fill' in plotcode:
            cdict3 = {
                'red': ((0.0, 1.0, 1.0), (0.5, 0.5, 0.5), (0.5, 1.0, 1.0),
                        (1.0, 0.4, 0.4)),
                'green': ((0.0, 1.0, 1.0), (0.5, 0.5, 0.5), (0.5, 0.4, 0.4),
                          (1.0, 0.0, 0.0)),
                'blue': ((0.0, 1.0, 1.0), (0.5, 0.5, 0.5), (0.5, 0.0, 0.0),
                         (1.0, 0.0, 0.0))
            }

            plt.register_cmap(name='FirePot', data=cdict3)

            # Definate Red Flag Area:
            RED_FLAG = np.logical_and(H_rh['value'] < rf_RH,
                                      H_gust['value'] > rf_WIND)
            # Linear Equation
            b = (rf_RH - rf_WIND) * (rf_RH / rf_WIND)
            z = -(rf_RH / rf_WIND) * (H_rh['value'] - H_gust['value']) + b

            m.pcolormesh(gridlon,
                         gridlat,
                         z,
                         cmap="FirePot",
                         alpha=alpha,
                         vmax=200,
                         vmin=-200,
                         zorder=3,
                         latlon=True)
            cb = plt.colorbar(orientation='horizontal', pad=pad, shrink=shrink)
            cb.set_label(r'Red Flag Potential')

            m.contour(gridlon,
                      gridlat,
                      z,
                      colors='k',
                      levels=[0],
                      zorder=3,
                      latlon=True)
            m.contour(gridlon,
                      gridlat,
                      RED_FLAG,
                      colors='darkred',
                      levels=[0],
                      zorder=3,
                      latlon=True)

        plt.xlabel(
            r'Red Flag Criteria: Winds > 6.7 m s$\mathregular{^{-1}}$ and RH < 25%'
        )

    # =============================================================================
    # Hack! Plot an extra HRRR variable not listed on the webpage hrrr_custom.html
    # This extra argument will let you attempt to plot a different variable for
    # a quicklook.
    try:
        # Must be a variable from a line in the .idx file
        hrrrVAR = form['extraVAR'].value
        extraHRRR = get_hrrr_variable(
            DATE,
            hrrrVAR,
            model=model,
            fxx=fxx,
            outDIR='/uufs/chpc.utah.edu/common/home/u0553130/temp/',
            verbose=False,
            value_only=True)
        m.pcolormesh(gridlon,
                     gridlat,
                     extraHRRR['value'],
                     cmap='viridis',
                     alpha=alpha,
                     zorder=3,
                     latlon=True)
        cbS = plt.colorbar(orientation='horizontal', shrink=shrink, pad=pad)
        cbS.set_label(hrrrVAR + ' (units)')
    except:
        pass
    # =============================================================================

    #plt.ylabel('Section Timer:%s\nFull Timer:%s' % (t2-t1, datetime.now()-firsttimer))

    SAVEDIR = '/uufs/chpc.utah.edu/common/home/u0553130/public_html/oper/HRRR_yesterday/%s/%s/' % (
        MAP_DIR, DOMAIN)
    if not os.path.exists(SAVEDIR):
        os.makedirs(SAVEDIR)
    SAVEFIG = SAVEDIR + '%s_f%02d' % (VALIDDATE.strftime('h%H'), fxx)
    plt.savefig(SAVEFIG)  # Plot standard output.
    print 'SAVED:', SAVEFIG
Example #4
0
                          edgecolor='k',
                          zorder=100)

        # Overlay Simulated Radar Reflectivity
        ctable = 'NWSReflectivity'
        norm, cmap = ctables.registry.get_with_steps(ctable, -0, 5)
        maps[loc].pcolormesh(X, Y, dBZ, norm=norm, cmap=cmap, alpha=.5)
        cb = plt.colorbar(orientation='horizontal', pad=0.01, shrink=0.75)
        cb.set_label(
            'Simulated Radar Reflectivity (dBZ)\n\nBarbs: Half=5 mph, Full=10 mph, Flag=50 mph'
        )

        # Overlay wind barbs (need to trim this array before we plot it)
        # First need to trim the array
        cut_vertical, cut_horizontal = pluck_point_new(l['latitude'],
                                                       l['longitude'],
                                                       H['lat'], H['lon'])
        maps[loc].barbs(X[cut_vertical - 5:cut_vertical + 5,
                          cut_horizontal - 5:cut_horizontal + 5],
                        Y[cut_vertical - 5:cut_vertical + 5,
                          cut_horizontal - 5:cut_horizontal + 5],
                        H_U['value'][cut_vertical - 5:cut_vertical + 5,
                                     cut_horizontal - 5:cut_horizontal + 5],
                        H_V['value'][cut_vertical - 5:cut_vertical + 5,
                                     cut_horizontal - 5:cut_horizontal + 5],
                        zorder=200)

        # Overlay Utah Roads
        BASE = '/uufs/chpc.utah.edu/common/home/u0553130/'
        maps[loc].readshapefile(
            BASE +
def make_plots(inputs):
    VALID_DATE, fxx = inputs
    print 'working on %s f%02d' % (VALID_DATE, fxx)
    plt.clf(); plt.cla()

    print fxx, VALID_DATE

    # === Some housekeeping variables =============================================
    # Convert Valid Date to Run Date, adjusted by the forecast
    DATE = VALID_DATE - timedelta(hours=fxx)

    # Parse Location lat/lon
    if ',' in location:
        # User put inputted a lat/lon point request
        lat, lon = location.split(',')
        lat = float(lat)
        lon = float(lon)
    else:
        # User requested a MesoWest station
        stninfo = get_station_info([location])
        lat = stninfo['LAT']
        lon = stninfo['LON']

    # Preload the latitude and longitude grid
    latlonpath = '/uufs/chpc.utah.edu/common/home/horel-group/archive/HRRR/oper_HRRR_latlon.h5'
    latlonh5 = h5py.File(latlonpath, 'r')
    gridlat = latlonh5['latitude'][:]
    gridlon = latlonh5['longitude'][:]


    # === Create map of the domain ================================================

    if dsize == 'conus' and model != 'hrrrAK':
        barb_thin = 70
        alpha = 1
        t1= datetime.now()
        #m = draw_CONUS_HRRR_map(res=map_res)
        m = np.load('/uufs/chpc.utah.edu/common/home/u0553130/public_html/Brian_Blaylock/cgi-bin/HRRR_CONUS_map_object_'+map_res+'.npy').item()
        m.drawcountries(zorder=500)
        m.drawstates(zorder=500)
        m.drawcoastlines(zorder=500)
        m.fillcontinents(color='tan',lake_color='lightblue', zorder=0)
        m.drawmapboundary(fill_color='lightblue')
        t2 = datetime.now()
    else:
        # configure some setting based on the requested domain size
        if dsize == 'small':
            plus_minus_latlon = .27      # +/- latlon box around center point
            barb_thin = 1               # Thin out excessive wind barbs
            arcgis_res = 1000            # ArcGIS image resolution
            bfr = 15                     # trim domain buffer
            alpha = .75                  # Alpha (pcolormesh transparency)
        elif dsize == 'medium':
            plus_minus_latlon = .75
            barb_thin = 2
            arcgis_res = 800
            bfr = 35
            alpha = .75
        elif dsize == 'large':
            plus_minus_latlon = 2.5
            barb_thin = 6
            arcgis_res = 800
            bfr = 110
            alpha = .75
        elif dsize == 'xlarge':
            plus_minus_latlon = 5
            barb_thin = 12
            arcgis_res = 700
            bfr = 210
            alpha = .75
        elif dsize == 'xxlarge':   # If domain runs into HRRR boundary, then it'll fail
            plus_minus_latlon = 10
            barb_thin = 25
            arcgis_res = 700
            bfr = 430
            alpha = .75
        elif dsize == 'xxxlarge':
            plus_minus_latlon = 15
            barb_thin = 35
            arcgis_res = 1000
            bfr = 700
            alpha = .75
        m = Basemap(resolution=map_res, projection='cyl',\
                    area_thresh=3000,\
                    llcrnrlon=lon-plus_minus_latlon, llcrnrlat=lat-plus_minus_latlon,\
                    urcrnrlon=lon+plus_minus_latlon, urcrnrlat=lat+plus_minus_latlon,)
        m.drawstates(zorder=500)
        m.drawcountries(zorder=500)
        m.drawcoastlines(zorder=500)
        #if dsize == 'small' or dsize == 'medium':
        #    m.drawcounties()


    # === Add a Background image ==================================================
    # Start the map image
    plt.figure(1)
    if background == 'arcgis' and dsize != 'conus':
        m.arcgisimage(service='World_Shaded_Relief', xpixels=arcgis_res, verbose=False)
    elif background == 'arcgisSat' and dsize != 'conus':
        m.arcgisimage(service='ESRI_Imagery_World_2D', xpixels=arcgis_res, verbose=False)
    elif background == 'arcgisRoad' and dsize != 'conus':
        m.arcgisimage(service='NatGeo_World_Map', xpixels=arcgis_res, verbose=False)
    elif background == 'terrain':
        # Get data
        H_ter = get_hrrr_variable(DATE, 'HGT:surface',
                                model=model, fxx=fxx,
                                outDIR='/uufs/chpc.utah.edu/common/home/u0553130/temp/',
                                verbose=False, value_only=True)
        H_land = get_hrrr_variable(DATE, 'LAND:surface',
                                model=model, fxx=fxx,
                                outDIR='/uufs/chpc.utah.edu/common/home/u0553130/temp/',
                                verbose=False, value_only=True)        

        # Plot the terrain
        m.contourf(gridlon, gridlat, H_ter['value'],
                levels=range(0, 4000, 200),
                cmap='Greys_r',
                zorder=1,
                latlon=True)
        # Plot Water area
        m.contour(gridlon, gridlat, H_land['value'],
                levels=[0, 1],
                colors='b',
                zorder=1,
                latlon=True)
    elif background == 'landuse':
        # Get data
        from BB_cmap.landuse_colormap import LU_MODIS21
        if model=='hrrr':
            VGTYP = 'VGTYP:surface'
        else:
            VGTYP = 'var discipline=2 center=59 local_table=1 parmcat=0 parm=198'
        H_LU = get_hrrr_variable(DATE, VGTYP,
                                model=model, fxx=fxx,
                                outDIR='/uufs/chpc.utah.edu/common/home/u0553130/temp/',
                                verbose=False,
                                value_only=True)

        # Plot the terrain
        cm, labels = LU_MODIS21()
        m.pcolormesh(gridlon, gridlat, H_LU['value'],
                    cmap=cm, vmin=1, vmax=len(labels) + 1,
                    zorder=1,
                    latlon=True)

    # Add SHAPEFILE
    if is_FIRE:
        plt.gca().add_collection(PatchCollection(patches,
                        facecolor='indianred',
                        alpha=.65,
                        edgecolor='k',
                        linewidths=1,
                        zorder=1))

    # === Figure Title ============================================================
    if dsize != 'conus':
        m.scatter(lon, lat, marker='+', c='r', s=100, zorder=1000, latlon=True)
        plt.title('Center: %s\n%s' % (location, model.upper()), fontweight='bold')
    else:
        plt.title('%s' % (model.upper()), fontweight='bold')
    plt.title('Run: %s F%02d' % (DATE.strftime('%Y-%m-%d %H:%M UTC'), fxx), loc='left')
    plt.title('Valid: %s' % (DATE+timedelta(hours=fxx)).strftime('%Y-%m-%d %H:%M UTC') , loc='right')
    # =============================================================================


    if '10mWind_Fill' in plotcode or '10mWind_Shade' in plotcode or '10mWind_Barb' in plotcode:
        # Get data
        H_u = get_hrrr_variable(DATE, 'UGRD:10 m',
                                model=model, fxx=fxx,
                                outDIR='/uufs/chpc.utah.edu/common/home/u0553130/temp/',
                                verbose=False, value_only=True)
        H_v = get_hrrr_variable(DATE, 'VGRD:10 m',
                                model=model, fxx=fxx,
                                outDIR='/uufs/chpc.utah.edu/common/home/u0553130/temp/',
                                verbose=False, value_only=True)
        spd = wind_uv_to_spd(H_u['value'], H_v['value'])
        
        if '10mWind_Fill' in plotcode:
            m.pcolormesh(gridlon, gridlat, spd,
                        latlon=True,
                        cmap='magma_r',
                        vmin=0, alpha=alpha)
            cb = plt.colorbar(orientation='horizontal', pad=pad, shrink=shrink)
            cb.set_label(r'10 m Wind Speed (m s$\mathregular{^{-1}}$)')

        if '10mWind_Shade' in plotcode:
            m.contourf(gridlon, gridlat, spd,
                        levels=[10, 15, 20, 25],
                        colors=('yellow', 'orange', 'red'),
                        alpha=alpha,
                        extend='max',
                        zorder=1,
                        latlon=True)
            cb = plt.colorbar(orientation='horizontal', shrink=shrink, pad=pad)
            cb.set_label(r'10 m Wind Speed (ms$\mathregular{^{-1}}$)')
        
        if '10mWind_Barb' in plotcode:
            # For small domain plots, trimming the edges significantly reduces barb plotting time
            if barb_thin < 20:
                cut_v, cut_h = pluck_point_new(lat, lon, gridlat, gridlon)
                Cgridlat = gridlat[cut_v-bfr:cut_v+bfr, cut_h-bfr:cut_h+bfr]
                Cgridlon = gridlon[cut_v-bfr:cut_v+bfr, cut_h-bfr:cut_h+bfr]
                H_u['value'] = H_u['value'][cut_v-bfr:cut_v+bfr, cut_h-bfr:cut_h+bfr]
                H_v['value'] = H_v['value'][cut_v-bfr:cut_v+bfr, cut_h-bfr:cut_h+bfr]
            else:
                Cgridlat = gridlat
                Cgridlon = gridlon

            # Add to plot
            thin = barb_thin
            m.barbs(Cgridlon[::thin,::thin], Cgridlat[::thin,::thin],
                    H_u['value'][::thin,::thin], H_v['value'][::thin,::thin],
                    zorder=200, length=5.5,
                    barb_increments={'half':2.5, 'full':5,'flag':25},
                    latlon=True)


    if '80mWind_Fill' in plotcode or '80mWind_Shade' in plotcode or '80mWind_Barb' in plotcode:
            # Get data
        H_u = get_hrrr_variable(DATE, 'UGRD:80 m',
                                model=model, fxx=fxx,
                                outDIR='/uufs/chpc.utah.edu/common/home/u0553130/temp/',
                                verbose=False, value_only=True)
        H_v = get_hrrr_variable(DATE, 'VGRD:80 m',
                                model=model, fxx=fxx,
                                outDIR='/uufs/chpc.utah.edu/common/home/u0553130/temp/',
                                verbose=False, value_only=True)
        spd = wind_uv_to_spd(H_u['value'], H_v['value'])
        
        if '80mWind_Fill' in plotcode:
            m.pcolormesh(gridlon, gridlat, spd,
                        latlon=True,
                        cmap='magma_r',
                        vmin=0, alpha=alpha)
            cb = plt.colorbar(orientation='horizontal', pad=pad, shrink=shrink)
            cb.set_label(r'10 m Wind Speed (m s$\mathregular{^{-1}}$)')

        if '80mWind_Shade' in plotcode:
            m.contourf(gridlon, gridlat, spd,
                        levels=[10, 15, 20, 25],
                        colors=('yellow', 'orange', 'red'),
                        alpha=alpha,
                        extend='max',
                        zorder=10,
                        latlon=True)
            cb = plt.colorbar(orientation='horizontal', shrink=shrink, pad=pad)
            cb.set_label(r'10 m Wind Speed (ms$\mathregular{^{-1}}$)')
        
        if '80mWind_Barb' in plotcode:
            # For small domain plots, trimming the edges significantly reduces barb plotting time
            if barb_thin < 20:
                cut_v, cut_h = pluck_point_new(lat, lon, gridlat, gridlon)
                Cgridlat = gridlat[cut_v-bfr:cut_v+bfr, cut_h-bfr:cut_h+bfr]
                Cgridlon = gridlon[cut_v-bfr:cut_v+bfr, cut_h-bfr:cut_h+bfr]
                H_u['value'] = H_u['value'][cut_v-bfr:cut_v+bfr, cut_h-bfr:cut_h+bfr]
                H_v['value'] = H_v['value'][cut_v-bfr:cut_v+bfr, cut_h-bfr:cut_h+bfr]
            else:
                Cgridlat = gridlat
                Cgridlon = gridlon

            # Add to plot
            thin = barb_thin
            m.barbs(Cgridlon[::thin,::thin], Cgridlat[::thin,::thin],
                    H_u['value'][::thin,::thin], H_v['value'][::thin,::thin],
                    zorder=200, length=5.5, color='darkred',
                    barb_increments={'half':2.5, 'full':5,'flag':25},
                    latlon=True)

        

        if 'Fill80mWind' in plotcode:
            m.pcolormesh(gridlon, gridlat, spd,
                        latlon=True,
                        cmap='plasma_r',
                        vmin=0,
                        alpha=alpha)
            cb = plt.colorbar(orientation='horizontal', pad=pad, shrink=shrink)
            cb.set_label(r'80 m Wind Speed (m s$\mathregular{^{-1}}$)')


    if 'Gust_Hatch' in plotcode:
        H_gust = get_hrrr_variable(DATE, 'GUST:surface',
                                model=model, fxx=fxx,
                                outDIR='/uufs/chpc.utah.edu/common/home/u0553130/temp/',
                                verbose=False, value_only=True)

        # Add to plot
        m.contourf(gridlon, gridlat, H_gust['value'],
                levels=[0, 10, 15, 20, 25],
                hatches=[None, '.', '\\\\', '*'],
                colors='none',
                extend='max',
                zorder=10,
                latlon=True)
        cb = plt.colorbar(orientation='horizontal', shrink=shrink, pad=pad)
        cb.set_label(r'Surface Wind Gust (ms$\mathregular{^{-1}}$)')
        
        m.contour(gridlon, gridlat, H_gust['value'],
                    levels=[10, 15, 20, 25],
                    colors='k',
                    zorder=10,
                    latlon=True)


    if 'dBZ_Fill' in plotcode or 'dBZ_Contour' in plotcode:
        from BB_cmap.reflectivity_colormap import reflect_ncdc
        # Get Data
        if model == 'hrrr':
            REFC = 'REFC:entire'
        elif model == 'hrrrX' or model == 'hrrrAK':
            REFC = 'var discipline=0 center=59 local_table=1 parmcat=16 parm=196'
        H_ref = get_hrrr_variable(DATE, REFC,
                                model=model, fxx=fxx,
                                outDIR='/uufs/chpc.utah.edu/common/home/u0553130/temp/',
                                verbose=False, value_only=True)

        # Mask values
        dBZ = H_ref['value']
        dBZ = np.ma.array(dBZ)
        dBZ[dBZ == -10] = np.ma.masked
        
        # Add Contour to plot
        if 'dBZ_Contour' in plotcode:
            cREF = m.contour(gridlon, gridlat, dBZ,
                            cmap=reflect_ncdc(),
                            levels=range(10, 80, 10),
                            latlon=True,
                            zorder=50)
            plt.clabel(cREF, cREF.levels[::2], fmt='%2.0f', colors='k', fontsize=9)
            #cb2 = plt.colorbar(orientation='horizontal', shrink=shrink, pad=pad)
            #cb2.set_label('Simulated Composite Reflectivity (dBZ)')

        # Add fill to plot
        if 'dBZ_Fill' in plotcode:
            m.pcolormesh(gridlon, gridlat, dBZ,
                        cmap=reflect_ncdc(),
                        vmax=80, vmin=0,
                        alpha=alpha,
                        latlon=True)
            cb2 = plt.colorbar(orientation='horizontal', shrink=shrink, pad=pad)
            cb2.set_label('Simulated Composite Reflectivity (dBZ)')


    if '2mTemp_Fill' in plotcode or '2mTemp_Freeze' in plotcode:
        # Get Data
        H_temp = get_hrrr_variable(DATE, 'TMP:2 m',
                                model=model, fxx=fxx,
                                outDIR='/uufs/chpc.utah.edu/common/home/u0553130/temp/',
                                verbose=False, value_only=True)
        
        TMP = H_temp['value']-273.15

        # Add fill to plot
        if '2mTemp_Fill' in plotcode:
            m.pcolormesh(gridlon, gridlat, TMP,
                        cmap="Spectral_r",
                        alpha=alpha,
                        zorder=3, latlon=True)
            cbT = plt.colorbar(orientation='horizontal', shrink=shrink, pad=pad)
            cbT.set_label('2m Temperature (C)')
        # Add freezing contour to plot
        if '2mTemp_Freeze' in plotcode:
            m.contour(gridlon, gridlat, TMP,
                    colors='b',
                    levels=[0],
                    zorder=400,
                    latlon=True)


    if '2mRH_Fill' in plotcode:
        # Get Data
        try:
            H_RH = get_hrrr_variable(DATE, 'RH:2 m',
                                    model=model, fxx=fxx,
                                    outDIR='/uufs/chpc.utah.edu/common/home/u0553130/temp/',
                                    verbose=False, value_only=True)

            # Add fill to plot
            m.pcolormesh(gridlon, gridlat, H_RH['value'], cmap="BrBG",
                        vmin=0, vmax=100,
                        zorder=3,
                        latlon=True)
            cbT = plt.colorbar(orientation='horizontal', pad=pad, shrink=shrink)
            cbT.set_label('2m Relative Humidity (%)')

        except:
            print "!! Some errors getting the RH value."
            print "!! If you requested an old date, from HRRR version 1, there isn't a RH variable,"
            print "!! and this code doesn't get the dwpt and convert it to RH yet."

    if '700Temp_Fill' in plotcode or '700Temp_-12c' in plotcode:
        # Get Data
        H_temp = get_hrrr_variable(DATE, 'TMP:700 mb',
                                model=model, fxx=fxx,
                                outDIR='/uufs/chpc.utah.edu/common/home/u0553130/temp/',
                                verbose=False, value_only=True)

        TMP = H_temp['value']-273.15

        # Add fill to plot
        if '700Temp_Fill' in plotcode:
            m.pcolormesh(gridlon, gridlat, TMP,
                        cmap="Spectral_r",
                        alpha=alpha,
                        zorder=3, latlon=True)
            cbT = plt.colorbar(orientation='horizontal', shrink=shrink, pad=pad)
            cbT.set_label('700 mb Temperature (C)')
        # Add -12 C contour to plot
        if '700Temp_-12c' in plotcode:
            m.contour(gridlon, gridlat, TMP,
                    colors='b',
                    levels=[-12],
                    latlon=True,
                    zorder=400)


    if '500HGT_Contour' in plotcode:
        H_500 = get_hrrr_variable(DATE, 'HGT:500 mb',
                                model=model, fxx=fxx,
                                outDIR='/uufs/chpc.utah.edu/common/home/u0553130/temp/',
                                verbose=False, value_only=True)

        CS = m.contour(gridlon, gridlat, H_500['value'], 
                        levels=range(5040, 6181, 60),
                        linewidths=1.7,
                        colors='k', 
                        latlon=True,
                        zorder=400)
        plt.clabel(CS, inline=1, fmt='%2.f')


    if '500Wind_Fill' in plotcode or '500Wind_Barb' in plotcode or '500Vort_Fill' in plotcode or '500Conv_Fill' in plotcode:
        H_u = get_hrrr_variable(DATE, 'UGRD:500 mb',
                                model=model, fxx=fxx,
                                outDIR='/uufs/chpc.utah.edu/common/home/u0553130/temp/',
                                verbose=False, value_only=True)
        H_v = get_hrrr_variable(DATE, 'VGRD:500 mb',
                                model=model, fxx=fxx,
                                outDIR='/uufs/chpc.utah.edu/common/home/u0553130/temp/',
                                verbose=False, value_only=True)

        if '500Wind_Fill' in plotcode:
            spd = wind_uv_to_spd(H_u['value'], H_v['value'])

            m.pcolormesh(gridlon, gridlat, spd,
                        latlon=True, cmap='BuPu', vmin=0)
            cb = plt.colorbar(orientation='horizontal', pad=pad, shrink=shrink)
            cb.set_label(r'500 mb Wind Speed (m s$\mathregular{^{-1}}$)')

        if '500Conv_Fill' in plotcode or '500Vort_Fill' in plotcode:
            dudx, dudy = np.gradient(H_u['value'], 3, 3)
            dvdx, dvdy = np.gradient(H_v['value'], 3, 3)
            if '500Vort_Fill' in plotcode:    
                vorticity = dvdx - dudy
                # Mask values
                vort = vorticity
                vort = np.ma.array(vort)
                vort[np.logical_and(vort < .05, vort > -.05) ] = np.ma.masked

                m.pcolormesh(gridlon, gridlat, vort,
                            latlon=True, cmap='bwr',
                            vmax=np.max(vort),
                            vmin=-np.max(vort))
                cb = plt.colorbar(orientation='horizontal', pad=pad, shrink=shrink)
                cb.set_label(r'500 mb Vorticity (s$\mathregular{^{-1}}$)')
            if '500Conv_Fill' in plotcode:
                convergence = dudx + dvdy
                # Mask values
                conv = convergence
                conv = np.ma.array(conv)
                conv[np.logical_and(conv < .05, conv > -.05) ] = np.ma.masked

                m.pcolormesh(gridlon, gridlat, conv,
                            latlon=True, cmap='bwr',
                            vmax=np.max(conv),
                            vmin=-np.max(conv))
                cb = plt.colorbar(orientation='horizontal', pad=pad, shrink=shrink)
                cb.set_label(r'500 mb Convergence (s$\mathregular{^{-1}}$)')

        if '500Wind_Barb' in plotcode:        
            # For small domain plots, trimming the edges significantly reduces barb plotting time
            if barb_thin < 20:
                cut_v, cut_h = pluck_point_new(lat, lon, gridlat, gridlon)
                Cgridlat = gridlat[cut_v-bfr:cut_v+bfr, cut_h-bfr:cut_h+bfr]
                Cgridlon = gridlon[cut_v-bfr:cut_v+bfr, cut_h-bfr:cut_h+bfr]
                H_u['value'] = H_u['value'][cut_v-bfr:cut_v+bfr, cut_h-bfr:cut_h+bfr]
                H_v['value'] = H_v['value'][cut_v-bfr:cut_v+bfr, cut_h-bfr:cut_h+bfr]
            else:
                Cgridlat = gridlat
                Cgridlon = gridlon
            thin = barb_thin
            m.barbs(Cgridlon[::thin, ::thin], Cgridlat[::thin, ::thin], H_u['value'][::thin, ::thin], H_v['value'][::thin, ::thin],
                    zorder=200, length=6, color='navy',
                    barb_increments={'half':2.5, 'full':5,'flag':25},
                    latlon=True)
            #plt.ylabel(r'Barbs: half=2.5, full=5, flag=25 (ms$\mathregular{^{-1}}$)')

    if 'MSLP_Contour' in plotcode or 'MSLP_Fill' in plotcode:
        H = get_hrrr_variable(DATE, 'MSLMA:mean sea level',
                            model=model, fxx=fxx,
                            outDIR='/uufs/chpc.utah.edu/common/home/u0553130/temp/',
                            verbose=False, value_only=True)

        if 'MSLP_Contour' in plotcode:
            CS = m.contour(gridlon, gridlat, H['value']/100., 
                        latlon=True,
                        levels=range(952, 1200, 4),
                        colors='k',
                        zorder=400)
            CS.clabel(inline=1, fmt='%2.f',
                    zorder=400)

        if 'MSLP_Fill' in plotcode:
            m.pcolormesh(gridlon, gridlat, H['value']/100., 
                            latlon=True,
                            cmap='viridis')

            cb = plt.colorbar(orientation='horizontal', pad=pad, shrink=shrink)
            cb.set_label('Mean Sea Level Pressure (hPa)')


    if '2mPOT_Fill' in plotcode:
        # Get Data
        H_temp = get_hrrr_variable(DATE, 'POT:2 m',
                                model=model, fxx=fxx,
                                outDIR='/uufs/chpc.utah.edu/common/home/u0553130/temp/',
                                verbose=False, value_only=True)
        
        TMP = H_temp['value']-273.15

        m.pcolormesh(gridlon, gridlat, TMP,
                        cmap="Oranges",
                        alpha=alpha,
                        zorder=3, latlon=True)
        cbS = plt.colorbar(orientation='horizontal', shrink=shrink, pad=pad)
        cbS.set_label('2 m Potential Temperature (C)')

    if 'SkinTemp_Fill' in plotcode:
        # Get Data
        H_temp = get_hrrr_variable(DATE, 'TMP:surface',
                                model=model, fxx=fxx,
                                outDIR='/uufs/chpc.utah.edu/common/home/u0553130/temp/',
                                verbose=False, value_only=True)
        
        TMP = H_temp['value']-273.15

        m.pcolormesh(gridlon, gridlat, TMP,
                        cmap="Spectral_r",
                        alpha=alpha,
                        zorder=3, latlon=True)
        cbS = plt.colorbar(orientation='horizontal', shrink=shrink, pad=pad)
        cbS.set_label('Skin Temperature (C)')


    if 'AccumPrecip_Fill' in plotcode or '1hrPrecip_Fill' in plotcode:
        #import matplotlib.colors
        #cmap = matplotlib.colors.LinearSegmentedColormap.from_list("Precip", ["#00db16", "blue", "#d10000", 'black'])
        cdict3 = {'red':  ((0.0, 0.0, 0.0),
                    (0.25, 1.0, 1.0),
                    (0.5, 0.0, 0.0),
                    (1.0, 1.0, 1.0)),
                'green': ((0.0, 0.7, 0.7),
                        (0.25, 1.0, 1.0),
                        (0.5, 0.0, 0.0),
                        (1.0, 0.0, 0.0)),

                'blue':  ((0.0, 0.18, 0.18),
                        (0.25, 1.0, 1.0),
                        (0.5, 1.0, 1.0),
                        (1.0, 0.0, 0.0))
                }
        plt.register_cmap(name='BlueRed3', data=cdict3)
        cmap = 'BlueRed3'
        
        if 'AccumPrecip_Fill' in plotcode:
            # Get Data
            H = get_hrrr_variable(DATE, 'APCP:surface:0',
                                    model=model, fxx=fxx,
                                    outDIR='/uufs/chpc.utah.edu/common/home/u0553130/temp/',
                                    verbose=False, value_only=True)
            # Mask values
            prec = H['value']
            prec = np.ma.array(prec)
            prec[prec == 0] = np.ma.masked

            m.pcolormesh(gridlon, gridlat, prec,
                            cmap='BlueRed3',
                            alpha=alpha,
                            vmin=.25,
                            zorder=3, latlon=True)
            cbS = plt.colorbar(orientation='horizontal', shrink=shrink, pad=pad)
            cbS.set_label('Accumulated Precipitation since F00 (mm)')

        if '1hrPrecip_Fill' in plotcode:
            # Get Data
            H = get_hrrr_variable(DATE, 'APCP:surface',
                                    model=model, fxx=fxx,
                                    outDIR='/uufs/chpc.utah.edu/common/home/u0553130/temp/',
                                    verbose=False, value_only=True)
            # Mask values
            prec = H['value']
            prec = np.ma.array(prec)
            prec[prec == 0] = np.ma.masked

            m.pcolormesh(gridlon, gridlat, prec,
                            cmap='BlueRed3',
                            alpha=alpha,
                            vmin=.25, vmax=20,
                            zorder=3, latlon=True)
            cbS = plt.colorbar(orientation='horizontal', shrink=shrink, pad=pad, extend="max",)
            cbS.set_label('1 hour Accumulated Precipitation (mm)')

    if 'SnowCover_Fill' in plotcode:
        # Get Data
        H = get_hrrr_variable(DATE, 'SNOWC',
                            model=model, fxx=fxx,
                            outDIR='/uufs/chpc.utah.edu/common/home/u0553130/temp/',
                            verbose=False, value_only=True)

        # Mask values
        snow = H['value']
        snow = np.ma.array(snow)
        snow[snow == 0] = np.ma.masked

        m.pcolormesh(gridlon, gridlat, snow,
                        cmap="Blues",
                        alpha=alpha,
                        zorder=3, latlon=True)
        cbS = plt.colorbar(orientation='horizontal', shrink=shrink, pad=pad)
        cbS.set_label('Snow Cover (%)')

    # =============================================================================
    # Hack! Plot an extra HRRR variable not listed on the webpage hrrr_custom.html
    # This extra argument will let you attempt to plot a different variable for
    # a quicklook.
    try:
        # Must be a variable from a line in the .idx file
        hrrrVAR = form['extraVAR'].value
        extraHRRR = get_hrrr_variable(DATE, hrrrVAR,
                            model=model, fxx=fxx,
                            outDIR='/uufs/chpc.utah.edu/common/home/u0553130/temp/',
                            verbose=False, value_only=True)
        m.pcolormesh(gridlon, gridlat, extraHRRR['value'],
                        cmap='viridis',
                        alpha=alpha,
                        zorder=3, latlon=True)
        cbS = plt.colorbar(orientation='horizontal', shrink=shrink, pad=pad)
        cbS.set_label(hrrrVAR+' (units)')
    except:
        pass
    # =============================================================================

    #plt.ylabel('Section Timer:%s\nFull Timer:%s' % (t2-t1, datetime.now()-firsttimer))

    SAVEDIR = '/uufs/chpc.utah.edu/common/home/u0553130/public_html/PhD/HRRR/Events_Day/%s/' % EVENT
    if not os.path.exists(SAVEDIR):
        os.makedirs(SAVEDIR)
    SAVEFIG = SAVEDIR + '%s_f%02d' % (VALID_DATE.strftime('%Y-%m-%d_h%H'), fxx)
    plt.savefig(SAVEFIG)	# Plot standard output.
    print 'SAVED:', SAVEFIG
else:
    MWlat, MWlon = stn.split(',')
    MWlat = float(MWlat)
    MWlon = float(MWlon)

# List of percentiles computed in the percentiles file
percentiles = [0,1,2,3,4,5,10,25,33,50,66,75,90,95,96,97,98,99,100]

# Load HRRR lat/lon Grid
DIR = '/uufs/chpc.utah.edu/common/home/horel-group2/blaylock/HRRR_OSG/'
latlon_file = h5py.File(DIR+'OSG_HRRR_latlon.h5', 'r')
lat = latlon_file['latitude'].value
lon = latlon_file['longitude'].value

# Pluck point of MesoWest station location in HRRR grid
point = pluck_point_new(MWlat, MWlon, lat, lon)
x = point[0][0]
y = point[1][0]

print '     MesoWest  |  HRRR Nearest Point   '
print 'lat: %s        |  %s' % (MWlat, lat[x,y])
print 'lon: %s        |  %s' % (MWlon, lon[x,y])

# Bounding box around the point
LATS_BOX = lat[x-box_radius:x+box_radius+1,y-box_radius:y+box_radius+1]
LONS_BOX = lon[x-box_radius:x+box_radius+1,y-box_radius:y+box_radius+1]

top_right_lat = LATS_BOX.max()
top_right_lon = LONS_BOX.min()
bot_left_lat = LATS_BOX.min()
bot_left_lon = LONS_BOX.max()
Example #7
0
for i in range(len(stns)):
    STN[a['STNID'][i]]['LAT'] = a['LAT'][i]
    STN[a['STNID'][i]]['LON'] = a['LON'][i]
    STN[a['STNID'][i]]['NAME'] = a['NAME'][i]

for m in range(1, 13):
    for h in range(0, 24):
        FILE = 'OSG_HRRR_%s_m%02d_h%02d_f%02d.nc' % (var, m, h, fxx)
        print FILE
        nc = Dataset(FILE, 'r')
        #
        for S in STN.keys():
            # Pluck value from each location
            point = pluck_point_new(STN[S]['LAT'], STN[S]['LON'],
                                    nc.variables['latitude'][:],
                                    nc.variables['longitude'][:])
            #
            # append the data to the list
            STN[S]['count'] = np.append(STN[S]['count'],
                                        nc.variables['count'][0])
            STN[S]['cores'] = np.append(STN[S]['cores'],
                                        nc.variables['cores'][0])
            STN[S]['month'] = np.append(STN[S]['month'], m)
            STN[S]['hour'] = np.append(STN[S]['hour'], h)
            STN[S]['monthhour'] = np.append(STN[S]['monthhour'], m + h / 24.)
            STN[S]['MAX'] = np.append(
                STN[S]['MAX'], nc.variables['max_' + var][point[0], point[1]])
            STN[S]['MIN'] = np.append(
                STN[S]['MIN'], nc.variables['min_' + var][point[0], point[1]])
            STN[S]['MEAN'] = np.append(
Example #8
0
## ============================================================================
# Pluck a point from HRRR grid
latlon = h5py.File(
    '/uufs/chpc.utah.edu/common/home/horel-group2/blaylock/HRRR_OSG/daily30_20150418-20170801/OSG_HRRR_latlon.h5',
    'r')
lat = latlon['latitude'].value
lon = latlon['longitude'].value

wbb_lat = 40.76623
wbb_lon = -111.84755

from BB_data.grid_manager import pluck_point_new
from pylab import poly_between
from BB_rose.windrose import WindroseAxes

I, J = pluck_point_new(wbb_lat, wbb_lon, lat, lon)
i = I[0]
j = J[0]

wbb_rose_table = rose[i, j]

## ============================================================================
# Plot a rose for the point
new_bins = bins[0:-1]
new_nbins = num_spd_bins
new_nsector = num_dir_sectors
new_cmap = mpl.cm.jet
new_colors = [new_cmap(i) for i in np.linspace(0.0, 1.0, new_nbins)]
new_angles = np.arange(0, -2 * np.pi, -2 * np.pi / new_nsector) + np.pi / 2

plot_angles = np.hstack((new_angles, new_angles[-1] - 2 * np.pi / new_nsector))
        ROW = 10
        COL = 10
        timer = datetime.now()
        HTS = np.array([get_point(DIR+'OSG_HRRR_%s_m%02d_d%02d_h%02d_f00.h5' % \
                    (variable, month, day, hour), 'mean', ROW, COL) \
                    for month in months \
                    for day in range(1,days[month-1]+1) \
                    for hour in hours])
        print datetime.now()-timer
        '''
        # MesoWest Station Info
        stn = ['WBB']
        a = get_station_info(stn)

        # Pluck point
        point = pluck_point_new(a['LAT'][0], a['LON'][0], lat, lon)

        # Multiprocessing :)
        args_p90 = [[DIR+'OSG_HRRR_%s_m%02d_d%02d_h%02d_f00.h5' % \
                (variable, month, day, hour), 'p90', point[0][0], point[1][0]] \
                for month in months for day in range(1,days[month-1]+1) for hour in hours]
        num_proc = multiprocessing.cpu_count()
        p = multiprocessing.Pool(num_proc)
        HTS_p90 = p.map(get_point_MP, args_p90)
        p.close()

        # Multiprocessing :)
        args_p10 = [[DIR+'OSG_HRRR_%s_m%02d_d%02d_h%02d_f00.h5' % \
                (variable, month, day, hour), 'p10', point[0][0], point[1][0]] \
                for month in months for day in range(1,days[month-1]+1) for hour in hours]
        num_proc = multiprocessing.cpu_count()
Example #10
0
            result = p.map(HRRR_error, date_list)
        p.close()

        # Remove anny nan arrays
        samples_requested = len(result)
        result = np.array([i for i in result if not np.isnan(np.sum(i))])
        samples = len(result)

        # Calculate error statistics
        RMSE = np.sqrt(np.nanmean(result**2, axis=0))
        mean_error = np.nanmean(result, axis=0)

        for f in range(1,19):
            for h in range(24):
                for i in locations.keys():
                    # Pluck point
                    x, y = pluck_point_new(locations[i]['latitude'], locations[i]['longitude'], H['lat'], H['lon'])
                    locations[i]['mean error'][f-1, h] = mean_error[x[0], y[0]]
                    locations[i]['RMSE'][f-1, h] = RMSE[x[0], y[0]]

for i in locations.keys():
    fig, [ax1, ax2] = plt.subplots(nrows=1, ncols=2)
    plt.sca(ax1)
    plt.pcolormesh(locations[i]['mean error'])
    plt.title('Mean Error')
    
    plt.sca(ax2)
    plt.pcolormesh(locations[i]['RMSE'])
    plt.title('RMSE')

    plt.show()