Пример #1
0
def get_lake_temp(DATE):

    DIR = '/uufs/chpc.utah.edu/common/home/horel-group/archive/%04d%02d%02d/models/hrrrX/' % (
        DATE.year, DATE.month, DATE.day)
    FILE = 'hrrrX.t%02dz.wrfsfcf00.grib2' % (DATE.hour)

    # Get Surface Temperature from the HRRR
    grbs = pygrib.open(DIR + FILE)
    print DATE
    print 'Grabbed:', grbs(name='Temperature')[-1]
    lat, lon = grbs(name='Temperature')[-1].latlons()
    T_surface = grbs(name='Temperature')[-1].values

    # Plot a circle where the GSL Buoy is Located, grab the HRRR surface
    # temperature, and comment that below.
    buoy_lat = 40.89068
    buoy_lon = -112.34551
    p = pluck_point(buoy_lat, buoy_lon, lat, lon)
    buoy_temp = T_surface.flatten()[p]
    """
    If I trim the data to just the Utah Domain it might plot a lot faster!! :)
    """

    # Return the data we want, and convert temperatures to Celsius.
    return_this = {
        'DATE': DATE,
        'LAT': lat,
        'LON': lon,
        'T_surface': T_surface - 273.15,
        'buoy_temp': buoy_temp - 273.15,
        'buoy_lat': buoy_lat,
        'buoy_lon': buoy_lon
    }

    return return_this
def plot_excess_temp_map(input):
    DATE = input

    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
    try:
        grbs = pygrib.open(DIR + 'hrrrX/hrrrX.t%02dz.wrfsfcf00.grib2' %
                           (DATE.hour))
        print "opened", DATE

        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 (!! NOT AVAILABLE IN HRRR-X FILE)
        #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]

    except:
        print "could not open", DATE
        return [np.nan, np.nan]
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]
Пример #4
0
def get_lake_temp(DATE, HRRR_version='hrrr'):
    """
    Opens a HRRR file (hrrr or hrrrX) and returns the surface temperature 
    as well as surface temperatures for select stations.
    """

    try:
        DIR = '/uufs/chpc.utah.edu/common/home/horel-group/archive/%04d%02d%02d/models/%s/' % (
            DATE.year, DATE.month, DATE.day, HRRR_version)
        FILE = '%s.t%02dz.wrfsfcf00.grib2' % (HRRR_version, DATE.hour)

        # Get Surface Temperature from the HRRR
        grbs = pygrib.open(DIR + FILE)
        print DATE
        print 'Grabbed:', grbs(name='Temperature')[-1]
        lat, lon = grbs(name='Temperature')[-1].latlons()
        T_surface = grbs(name='Temperature')[-1].values
        temp_2m = grbs(name='2 metre temperature')[-1].values
        """
        If I trim the data to just the Utah Domain it might plot a lot faster!! :)
        """

        # Plot a circle where the GSL Buoy is Located, grab the HRRR surface
        # temperature, and comment that below.
        buoy_lat = 40.89068
        buoy_lon = -112.34551
        p = pluck_point(buoy_lat, buoy_lon, lat, lon)
        buoy_temp = T_surface.flatten()[p]
        buoy_2m = temp_2m.flatten()[p]

        # Plot a circle where the UofU tripod is located and grab temperature
        #stn = UFD09
        ufd09_lat = 40.92533
        ufd09_lon = -112.15936
        p2 = pluck_point(ufd09_lat, ufd09_lon, lat, lon)
        ufd09_temp = T_surface.flatten()[p2]
        # Since this station is in water, grab one point west of station to
        # get the land temperature on Antelope Island
        ufd09_temp2 = T_surface.flatten()[p2 - 1]

        ufd09_2m = temp_2m.flatten()[p]
        ufd09_2m2 = temp_2m.flatten()[p - 1]

        # Plot a circle where BFLAT station is located and grab temperature
        bflat_lat = 40.78422
        bflat_lon = -113.82946
        p3 = pluck_point(bflat_lat, bflat_lon, lat, lon)
        bflat_temp = T_surface.flatten()[p3]
        bflat_2m = temp_2m.flatten()[p]

        # Return the data we want, and convert temperatures to Celsius.
        return_this = {
            'DATE': DATE,
            'LAT': lat,
            'LON': lon,
            'HRRR Version': HRRR_version,
            'T_surface': T_surface - 273.15,
            'buoy_temp': buoy_temp - 273.15,  # surface temp
            'buoy_2m': buoy_2m - 273.15,  # 2m air temp
            'buoy_lat': buoy_lat,  # latitude
            'buoy_lon': buoy_lon,  # longitude
            'ufd09_temp': ufd09_temp - 273.15,
            'ufd09_temp2': ufd09_temp2 - 273.15,
            'ufd09_2m': ufd09_2m - 273.15,
            'ufd09_2m2': ufd09_2m2 - 273.15,
            'ufd09_lat': ufd09_lat,
            'ufd09_lon': ufd09_lon,
            'bflat_temp': bflat_temp - 273.15,
            'bflat_2m': bflat_2m - 273.15,
            'bflat_lat': bflat_lat,
            'bflat_lon': bflat_lon,
        }
    except:
        # Return the data we want, and convert temperatures to Celsius.
        return_this = {
            'DATE': DATE,
            'LAT': np.nan,
            'LON': np.nan,
            'HRRR Version': HRRR_version,
            'T_surface': np.nan,
            'buoy_temp': np.nan,
            'buoy_2m': np.nan,
            'buoy_lat': np.nan,
            'buoy_lon': np.nan,
            'ufd09_temp': np.nan,
            'ufd09_temp2': np.nan,
            'ufd09_2m': np.nan,
            'ufd09_2m2': np.nan,
            'ufd09_lat': np.nan,
            'ufd09_lon': np.nan,
            'bflat_temp': np.nan,
            'bflat_2m': np.nan,
            'bflat_lat': np.nan,
            'bflat_lon': np.nan,
        }

    return return_this