コード例 #1
0
def get_theta_from_grb(DATE):
    """
    Gets the potential temperature at a point from the HRRR surface field
    files for a single time.
    """

    VALID_DATE = DATE + timedelta(hours=fxx)

    DIR = '/uufs/chpc.utah.edu/common/home/horel-group/archive/%04d%02d%02d/models/' % (
        DATE.year, DATE.month, DATE.day)

    # Open HRRR and get surface temperature and surface pressure
    grbs = pygrib.open(DIR + 'hrrr/hrrr.t%02dz.wrfsfcf%02d.grib2' %
                       (DATE.hour, fxx))
    temp = grbs.select(name="2 metre temperature")[0].values[
        subset[domain][0]:subset[domain][1],
        subset[domain][2]:subset[domain][3]] - 273.15
    sfcpres = grbs.select(name="Surface pressure")[0].values[
        subset[domain][0]:subset[domain][1],
        subset[domain][2]:subset[domain][3]] / 100
    lat, lon = grbs.select(name="2 metre temperature")[0].latlons()
    lat = lat[subset[domain][0]:subset[domain][1],
              subset[domain][2]:subset[domain][3]]
    lon = lon[subset[domain][0]:subset[domain][1],
              subset[domain][2]:subset[domain][3]]
    # Get the 700 hPa temperatures
    T700 = grbs.select(name="Temperature")[1].values[
        subset[domain][0]:subset[domain][1],
        subset[domain][2]:subset[domain][3]] - 273.15

    # Convert temperatures to potental temperature (theta)
    theta_sfc = TempPress_to_PotTemp(temp, sfcpres)
    theta_700 = TempPress_to_PotTemp(T700, 700)

    # Pluck value for the station location
    pluck_index = pluck_point(stn_lat, stn_lon, lat, lon)

    # use that pluck index on the flattened array to ge the value
    stn_theta_sfc = theta_sfc.flatten()[pluck_index]
    stn_theta_700 = theta_700.flatten()[pluck_index]

    # Return the values
    print "Got it:", DATE

    # close the grib file
    grbs.close()

    return [VALID_DATE, stn_theta_sfc, stn_theta_700]
コード例 #2
0
def plot_excess_temp_map(input):
    DATE = input - timedelta(hours=12)

    date = DATE.strftime('%Y-%m-%d_%H%M')
    print 'working on', date

    DIR = '/uufs/chpc.utah.edu/common/home/horel-group/archive/%04d%02d%02d/models/' % (
        DATE.year, DATE.month, DATE.day)

    # Open HRRR and get surface temperature and surface pressure
    grbs = pygrib.open(DIR + 'hrrr/hrrr.t%02dz.wrfsfcf12.grib2' % (DATE.hour))
    temp = grbs.select(name="2 metre temperature")[0].values[
        subset[domain][0]:subset[domain][1],
        subset[domain][2]:subset[domain][3]] - 273.15
    sfcpres = grbs.select(name="Surface pressure")[0].values[
        subset[domain][0]:subset[domain][1],
        subset[domain][2]:subset[domain][3]] / 100
    lat, lon = grbs.select(name="2 metre temperature")[0].latlons()
    lat = lat[subset[domain][0]:subset[domain][1],
              subset[domain][2]:subset[domain][3]]
    lon = lon[subset[domain][0]:subset[domain][1],
              subset[domain][2]:subset[domain][3]]

    # Get the 700 hPa temperatures
    T700 = grbs.select(name="Temperature")[1].values[
        subset[domain][0]:subset[domain][1],
        subset[domain][2]:subset[domain][3]] - 273.15

    # Convert temperatures to potental temperature (theta)
    theta_sfc = TempPress_to_PotTemp(temp, sfcpres)
    theta_700 = TempPress_to_PotTemp(T700, 700)

    # pluck the value for SLC
    SLC_lat = 40.77
    SLC_lon = -111.95
    pluck_index = pluck_point(SLC_lat, SLC_lon, lat, lon)

    # use that pluck index on the flattened array to ge the value
    SLC_sfc_temp = temp.flatten()[pluck_index]
    SLC_sfc_theta = theta_sfc.flatten()[pluck_index]
    SLC_700_temp = T700.flatten()[pluck_index]
    SLC_700_theta = theta_700.flatten()[pluck_index]

    return [SLC_sfc_temp, SLC_sfc_theta, SLC_700_temp, SLC_700_theta]