In [1]:
import xray
import datetime
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
%matplotlib inline

In [2]:
URL = 'http://thredds.ucar.edu/thredds/dodsC/grib/NCEP/GFS/Global_0p5deg/Best'

In [3]:
ds = xray.open_dataset(URL)

In [4]:
# select lat,lon region of interest
# note: slice(20.5,55.0) fails
dsloc = ds.sel(lon=slice(230.5,300.0),lat=slice(55.0,20.5))

In [ ]:
# select closest data to time of interest
date = datetime.datetime(2015,7,15,3,0,0)
#date = datetime.datetime.now()
ds_snapshot = dsloc.sel(time1=date,method='nearest')

In [6]:
# ds.data_vars
# ds.coords
# ds.attrs

In [7]:
t = ds_snapshot['Temperature_surface']

In [8]:
t.shape


Out[8]:
(209, 70, 140)

In [9]:
plt.pcolormesh(t.lon.data,t.lat.data,t.data)
plt.title(t.name+pd.Timestamp(t.time.values).strftime(': %Y-%m-%d  %H:%M:%S %Z %z'));


---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-9-ae43f2f1e663> in <module>()
----> 1 plt.pcolormesh(t.lon.data,t.lat.data,t.data)
      2 plt.title(t.name+pd.Timestamp(t.time.values).strftime(': %Y-%m-%d  %H:%M:%S %Z %z'));

/home/usgs/miniconda/envs/ioos/lib/python2.7/site-packages/matplotlib/pyplot.pyc in pcolormesh(*args, **kwargs)
   3034         ax.hold(hold)
   3035     try:
-> 3036         ret = ax.pcolormesh(*args, **kwargs)
   3037         draw_if_interactive()
   3038     finally:

/home/usgs/miniconda/envs/ioos/lib/python2.7/site-packages/matplotlib/axes/_axes.pyc in pcolormesh(self, *args, **kwargs)
   5087         allmatch = (shading == 'gouraud')
   5088 
-> 5089         X, Y, C = self._pcolorargs('pcolormesh', *args, allmatch=allmatch)
   5090         Ny, Nx = X.shape
   5091 

/home/usgs/miniconda/envs/ioos/lib/python2.7/site-packages/matplotlib/axes/_axes.pyc in _pcolorargs(funcname, *args, **kw)
   4690         if len(args) == 3:
   4691             X, Y, C = args
-> 4692             numRows, numCols = C.shape
   4693         else:
   4694             raise TypeError(

ValueError: too many values to unpack

In [16]:
# time series closest to specified lon,lat location
ds_series = ds.sel(lon=250.,lat=33.,method='nearest')

In [17]:
# Select temperature and convert to Pandas Series
v_series = ds_series['Temperature_surface'].to_series()

In [18]:
v_series.plot(title=v_series.name);



In [19]:
ds_snapshot.to_netcdf('ds_snapshot.nc')

In [20]:
ds_snapshot


Out[20]:
<xray.Dataset>
Dimensions:                                                                     (altitude_above_msl: 3, depth_below_surface_layer: 4, depth_below_surface_layer_bounds_1: 2, height_above_ground: 1, height_above_ground1: 2, height_above_ground2: 1, height_above_ground3: 3, height_above_ground4: 3, height_above_ground_layer: 1, height_above_ground_layer1: 1, height_above_ground_layer1_bounds_1: 2, height_above_ground_layer_bounds_1: 2, isobaric: 12, isobaric1: 1, isobaric2: 21, isobaric3: 26, lat: 70, lon: 140, potential_vorticity_surface: 2, pressure_difference_layer: 1, pressure_difference_layer1: 1, pressure_difference_layer1_bounds_1: 2, pressure_difference_layer2: 2, pressure_difference_layer2_bounds_1: 2, pressure_difference_layer_bounds_1: 2, sigma: 1, sigma_layer: 4, sigma_layer_bounds_1: 2, time1: 209, time2: 208, time2_bounds_1: 2)
Coordinates:
  * lat                                                                         (lat) float32 55.0 ...
  * lon                                                                         (lon) float32 230.5 ...
    time                                                                        datetime64[ns] 2015-07-15T03:00:00 ...
    reftime                                                                     datetime64[ns] 2015-07-15 ...
  * time1                                                                       (time1) datetime64[ns] 2015-07-01 ...
    reftime1                                                                    (time1) datetime64[ns] 2015-07-01 ...
  * time2                                                                       (time2) datetime64[ns] 2015-07-01T03:00:00 ...
    reftime2                                                                    (time2) datetime64[ns] 2015-07-01 ...
  * depth_below_surface_layer                                                   (depth_below_surface_layer) float32 0.05 ...
  * isobaric                                                                    (isobaric) float32 1000.0 ...
  * height_above_ground_layer                                                   (height_above_ground_layer) float32 1500.0 ...
  * height_above_ground                                                         (height_above_ground) float32 2.0 ...
  * potential_vorticity_surface                                                 (potential_vorticity_surface) float32 -2e-06 ...
  * pressure_difference_layer                                                   (pressure_difference_layer) float32 1500.0 ...
  * isobaric1                                                                   (isobaric1) float32 50000.0 ...
  * height_above_ground1                                                        (height_above_ground1) float32 2.0 ...
  * height_above_ground2                                                        (height_above_ground2) float32 80.0 ...
  * isobaric2                                                                   (isobaric2) float32 10000.0 ...
  * sigma                                                                       (sigma) float32 0.995 ...
  * altitude_above_msl                                                          (altitude_above_msl) float32 1829.0 ...
  * height_above_ground3                                                        (height_above_ground3) float32 10.0 ...
  * height_above_ground_layer1                                                  (height_above_ground_layer1) float32 3000.0 ...
  * pressure_difference_layer1                                                  (pressure_difference_layer1) float32 12750.0 ...
  * isobaric3                                                                   (isobaric3) float32 1000.0 ...
  * sigma_layer                                                                 (sigma_layer) float32 0.58 ...
  * pressure_difference_layer2                                                  (pressure_difference_layer2) float32 9000.0 ...
  * height_above_ground4                                                        (height_above_ground4) float32 2.0 ...
  * depth_below_surface_layer_bounds_1                                          (depth_below_surface_layer_bounds_1) int64 0 ...
  * height_above_ground_layer1_bounds_1                                         (height_above_ground_layer1_bounds_1) int64 0 ...
  * height_above_ground_layer_bounds_1                                          (height_above_ground_layer_bounds_1) int64 0 ...
  * pressure_difference_layer1_bounds_1                                         (pressure_difference_layer1_bounds_1) int64 0 ...
  * pressure_difference_layer2_bounds_1                                         (pressure_difference_layer2_bounds_1) int64 0 ...
  * pressure_difference_layer_bounds_1                                          (pressure_difference_layer_bounds_1) int64 0 ...
  * sigma_layer_bounds_1                                                        (sigma_layer_bounds_1) int64 0 ...
  * time2_bounds_1                                                              (time2_bounds_1) int64 0 ...
Data variables:
    LatLon_Projection                                                           int64 0 ...
    time2_bounds                                                                (time2, time2_bounds_1) datetime64[ns] 2015-07-01 ...
    depth_below_surface_layer_bounds                                            (depth_below_surface_layer, depth_below_surface_layer_bounds_1) float32 0.0 ...
    height_above_ground_layer_bounds                                            (height_above_ground_layer, height_above_ground_layer_bounds_1) float32 3000.0 ...
    pressure_difference_layer_bounds                                            (pressure_difference_layer, pressure_difference_layer_bounds_1) float32 3000.0 ...
    height_above_ground_layer1_bounds                                           (height_above_ground_layer1, height_above_ground_layer1_bounds_1) float32 6000.0 ...
    pressure_difference_layer1_bounds                                           (pressure_difference_layer1, pressure_difference_layer1_bounds_1) float32 25500.0 ...
    sigma_layer_bounds                                                          (sigma_layer, sigma_layer_bounds_1) float32 0.44 ...
    pressure_difference_layer2_bounds                                           (pressure_difference_layer2, pressure_difference_layer2_bounds_1) float32 18000.0 ...
    Total_ozone_entire_atmosphere_single_layer                                  (time1, lat, lon) float32 345.5 ...
    Ozone_Mixing_Ratio_isobaric                                                 (time1, isobaric, lat, lon) float32 1.2811e-05 ...
    Momentum_flux_u-component_surface_Mixed_intervals_Average                   (time2, lat, lon) float32 -0.263 ...
    Momentum_flux_v-component_surface_Mixed_intervals_Average                   (time2, lat, lon) float32 -0.024 ...
    Surface_Lifted_Index_surface                                                (time1, lat, lon) float32 3.9 ...
    Downward_Short-Wave_Radiation_Flux_surface_Mixed_intervals_Average          (time2, lat, lon) float32 428.0 ...
    Downward_Long-Wave_Radp_Flux_surface_Mixed_intervals_Average                (time2, lat, lon) float32 305.0 ...
    MSLP_Eta_model_reduction_msl                                                (time1, lat, lon) float32 102217.0 ...
    Pressure_high_cloud_bottom_Mixed_intervals_Average                          (time2, lat, lon) float32 27790.0 ...
    Pressure_low_cloud_bottom_Mixed_intervals_Average                           (time2, lat, lon) float32 80830.4 ...
    Pressure_low_cloud_top_Mixed_intervals_Average                              (time2, lat, lon) float32 73250.4 ...
    Pressure_high_cloud_top_Mixed_intervals_Average                             (time2, lat, lon) float32 20510.0 ...
    Vertical_Speed_Shear_potential_vorticity_surface                            (time1, potential_vorticity_surface, lat, lon) float32 nan ...
    Pressure_middle_cloud_top_Mixed_intervals_Average                           (time2, lat, lon) float32 nan ...
    Pressure_middle_cloud_bottom_Mixed_intervals_Average                        (time2, lat, lon) float32 nan ...
    Ventilation_Rate_planetary_boundary                                         (time1, lat, lon) float32 3800.0 ...
    Pressure_convective_cloud_top                                               (lat, lon) float32 nan ...
    Pressure_convective_cloud_bottom                                            (lat, lon) float32 nan ...
    Vertical_Speed_Shear_tropopause                                             (time1, lat, lon) float32 -0.008 ...
    Wind_speed_gust_surface                                                     (time1, lat, lon) float32 3.2 ...
    Pressure_of_level_from_which_parcel_was_lifted_pressure_difference_layer    (time1, pressure_difference_layer1, lat, lon) float32 94382.7 ...
    Temperature_low_cloud_top_Mixed_intervals_Average                           (time2, lat, lon) float32 275.7 ...
    Temperature_middle_cloud_top_Mixed_intervals_Average                        (time2, lat, lon) float32 nan ...
    Temperature_high_cloud_top_Mixed_intervals_Average                          (time2, lat, lon) float32 218.1 ...
    Categorical_Rain_surface_Mixed_intervals_Average                            (time2, lat, lon) float32 1.0 ...
    Potential_Evaporation_Rate_surface                                          (lat, lon) float32 99.0 ...
    Volumetric_Soil_Moisture_Content_depth_below_surface_layer                  (time1, depth_below_surface_layer, lat, lon) float32 0.24 ...
    Ice_cover_surface                                                           (time1, lat, lon) float32 0.0 ...
    Land_cover_0__sea_1__land_surface                                           (time1, lat, lon) float32 1.0 ...
    Pressure_surface                                                            (time1, lat, lon) float32 94634.4 ...
    Specific_humidity_pressure_difference_layer                                 (time1, pressure_difference_layer, lat, lon) float32 0.007171 ...
    Temperature_pressure_difference_layer                                       (time1, pressure_difference_layer, lat, lon) float32 287.0 ...
    Temperature_surface                                                         (time1, lat, lon) float32 290.7 ...
    Albedo_surface_Mixed_intervals_Average                                      (time2, lat, lon) float32 21.1 ...
    Relative_humidity_sigma_layer                                               (time1, sigma_layer, lat, lon) float32 23.0 ...
    Relative_humidity_pressure_difference_layer                                 (time1, pressure_difference_layer, lat, lon) float32 67.0 ...
    Haines_Index_surface                                                        (time1, lat, lon) float32 3.0 ...
    Soil_temperature_depth_below_surface_layer                                  (time1, depth_below_surface_layer, lat, lon) float32 287.8 ...
    u-component_of_wind_pressure_difference_layer                               (time1, pressure_difference_layer, lat, lon) float32 3.54 ...
    v-component_of_wind_pressure_difference_layer                               (time1, pressure_difference_layer, lat, lon) float32 0.2 ...
    Geopotential_height_surface                                                 (time1, lat, lon) float32 656.161 ...
    Water_runoff_surface_Mixed_intervals_Accumulation                           (time2, lat, lon) float32 0.1752 ...
    Convective_available_potential_energy_pressure_difference_layer             (time1, pressure_difference_layer2, lat, lon) float32 14.0 ...
    Convective_available_potential_energy_surface                               (time1, lat, lon) float32 27.0 ...
    Convective_inhibition_pressure_difference_layer                             (time1, pressure_difference_layer2, lat, lon) float32 -2.0 ...
    Convective_inhibition_surface                                               (time1, lat, lon) float32 0.0 ...
    Precipitation_rate_surface_Mixed_intervals_Average                          (time2, lat, lon) float32 0.0 ...
    Storm_relative_helicity_height_above_ground_layer                           (time1, height_above_ground_layer, lat, lon) float32 -13.0 ...
    Total_precipitation_surface_Mixed_intervals_Accumulation                    (time2, lat, lon) float32 0.0 ...
    Convective_precipitation_surface_Mixed_intervals_Accumulation               (time2, lat, lon) float32 0.04 ...
    Latent_heat_net_flux_surface_Mixed_intervals_Average                        (time2, lat, lon) float32 99.0 ...
    Sensible_heat_net_flux_surface_Mixed_intervals_Average                      (time2, lat, lon) float32 145.0 ...
    Snow_depth_surface                                                          (time1, lat, lon) float32 0.0 ...
    Water_equivalent_of_accumulated_snow_depth_surface                          (time1, lat, lon) float32 0.0 ...
    Total_cloud_cover_high_cloud_Mixed_intervals_Average                        (time2, lat, lon) float32 22.0 ...
    Total_cloud_cover_convective_cloud                                          (lat, lon) float32 0.0 ...
    Total_cloud_cover_low_cloud_Mixed_intervals_Average                         (time2, lat, lon) float32 12.0 ...
    Total_cloud_cover_middle_cloud_Mixed_intervals_Average                      (time2, lat, lon) float32 0.0 ...
    Total_cloud_cover_boundary_layer_cloud_Mixed_intervals_Average              (time2, lat, lon) float32 2.0 ...
    Cloud_Work_Function_entire_atmosphere_single_layer_Mixed_intervals_Average  (time2, lat, lon) float32 0.0 ...
    Sunshine_Duration_surface                                                   (time1, lat, lon) float32 450.0 ...
    Best_4_layer_Lifted_Index_surface                                           (time1, lat, lon) float32 4.5 ...
    Upward_Short-Wave_Radiation_Flux_atmosphere_top_Mixed_intervals_Average     (time2, lat, lon) float32 159.0 ...
    Upward_Short-Wave_Radiation_Flux_surface_Mixed_intervals_Average            (time2, lat, lon) float32 90.0 ...
    Upward_Long-Wave_Radp_Flux_surface_Mixed_intervals_Average                  (time2, lat, lon) float32 395.0 ...
    Upward_Long-Wave_Radp_Flux_atmosphere_top_Mixed_intervals_Average           (time2, lat, lon) float32 264.0 ...
    5-Wave_Geopotential_Height_isobaric                                         (time1, isobaric1, lat, lon) float32 5820.33 ...
    Relative_humidity_highest_tropospheric_freezing                             (time1, lat, lon) float32 33.0 ...
    Relative_humidity_entire_atmosphere_single_layer                            (time1, lat, lon) float32 22.0 ...
    Categorical_Freezing_Rain_surface_Mixed_intervals_Average                   (time2, lat, lon) float32 0.0 ...
    Ground_Heat_Flux_surface_Mixed_intervals_Average                            (time2, lat, lon) float32 -16.0 ...
    Wilting_Point_surface                                                       (time1, lat, lon) float32 0.0469 ...
    Per_cent_frozen_precipitation_surface                                       (time1, lat, lon) float32 0.0 ...
    Temperature_isobaric                                                        (time1, isobaric3, lat, lon) float32 238.4 ...
    Relative_humidity_isobaric                                                  (time1, isobaric3, lat, lon) float32 0.0 ...
    Relative_humidity_zeroDegC_isotherm                                         (time1, lat, lon) float32 33.0 ...
    u-component_of_wind_isobaric                                                (time1, isobaric3, lat, lon) float32 -12.7 ...
    v-component_of_wind_isobaric                                                (time1, isobaric3, lat, lon) float32 1.6 ...
    Geopotential_height_isobaric                                                (time1, isobaric3, lat, lon) float32 31827.2 ...
    Geopotential_height_zeroDegC_isotherm                                       (time1, lat, lon) float32 3274.4 ...
    U-Component_Storm_Motion_height_above_ground_layer                          (time1, height_above_ground_layer1, lat, lon) float32 8.76 ...
    Zonal_Flux_of_Gravity_Wave_Stress_surface_Mixed_intervals_Average           (time2, lat, lon) float32 0.065 ...
    u-component_of_wind_planetary_boundary                                      (time1, lat, lon) float32 3.6 ...
    Categorical_Ice_Pellets_surface_Mixed_intervals_Average                     (time2, lat, lon) float32 0.0 ...
    Vertical_velocity_pressure_isobaric                                         (time1, isobaric2, lat, lon) float32 0.01149 ...
    Absolute_vorticity_isobaric                                                 (time1, isobaric3, lat, lon) float32 0.000114 ...
    Pressure_reduced_to_MSL_msl                                                 (time1, lat, lon) float32 102168.0 ...
    Cloud_mixing_ratio_isobaric                                                 (time1, isobaric2, lat, lon) float32 0.0 ...
    Pressure_maximum_wind                                                       (time1, lat, lon) float32 23430.4 ...
    Temperature_altitude_above_msl                                              (time1, altitude_above_msl, lat, lon) float32 278.2 ...
    Temperature_maximum_wind                                                    (time1, lat, lon) float32 220.7 ...
    u-component_of_wind_altitude_above_msl                                      (time1, altitude_above_msl, lat, lon) float32 2.87 ...
    u-component_of_wind_maximum_wind                                            (time1, lat, lon) float32 29.5 ...
    ICAO_Standard_Atmosphere_Reference_Height_maximum_wind                      (time1, lat, lon) float32 10779.2 ...
    v-component_of_wind_altitude_above_msl                                      (time1, altitude_above_msl, lat, lon) float32 0.65 ...
    v-component_of_wind_maximum_wind                                            (time1, lat, lon) float32 -6.8 ...
    Apparent_temperature_height_above_ground                                    (time1, height_above_ground, lat, lon) float32 289.5 ...
    Geopotential_height_maximum_wind                                            (time1, lat, lon) float32 11064.5 ...
    V-Component_Storm_Motion_height_above_ground_layer                          (time1, height_above_ground_layer1, lat, lon) float32 -6.05 ...
    Meridional_Flux_of_Gravity_Wave_Stress_surface_Mixed_intervals_Average      (time2, lat, lon) float32 2.281 ...
    Field_Capacity_surface                                                      (time1, lat, lon) float32 0.2821 ...
    v-component_of_wind_planetary_boundary                                      (time1, lat, lon) float32 0.5 ...
    Precipitable_water_entire_atmosphere_single_layer                           (time1, lat, lon) float32 15.6 ...
    Categorical_Snow_surface_Mixed_intervals_Average                            (time2, lat, lon) float32 0.0 ...
    Pressure_height_above_ground                                                (time1, height_above_ground2, lat, lon) float32 93748.7 ...
    Pressure_tropopause                                                         (time1, lat, lon) float32 21156.9 ...
    Specific_humidity_height_above_ground                                       (time1, height_above_ground1, lat, lon) float32 0.00766 ...
    Temperature_tropopause                                                      (time1, lat, lon) float32 218.2 ...
    Temperature_height_above_ground                                             (time1, height_above_ground4, lat, lon) float32 289.5 ...
    Relative_humidity_height_above_ground                                       (time1, height_above_ground, lat, lon) float32 62.2 ...
    u-component_of_wind_height_above_ground                                     (time1, height_above_ground3, lat, lon) float32 2.88 ...
    u-component_of_wind_tropopause                                              (time1, lat, lon) float32 27.5 ...
    ICAO_Standard_Atmosphere_Reference_Height_tropopause                        (time1, lat, lon) float32 11427.1 ...
    v-component_of_wind_height_above_ground                                     (time1, height_above_ground3, lat, lon) float32 0.04 ...
    v-component_of_wind_tropopause                                              (time1, lat, lon) float32 -4.9 ...
    Maximum_temperature_height_above_ground_Mixed_intervals_Maximum             (time2, height_above_ground, lat, lon) float32 289.6 ...
    Geopotential_height_tropopause                                              (time1, lat, lon) float32 11719.5 ...
    Minimum_temperature_height_above_ground_Mixed_intervals_Minimum             (time2, height_above_ground, lat, lon) float32 287.5 ...
    Dewpoint_temperature_height_above_ground                                    (time1, height_above_ground, lat, lon) float32 282.3 ...
    Temperature_sigma                                                           (time1, sigma, lat, lon) float32 288.4 ...
    Relative_humidity_sigma                                                     (time1, sigma, lat, lon) float32 63.0 ...
    Potential_temperature_sigma                                                 (time1, sigma, lat, lon) float32 293.4 ...
    u-component_of_wind_sigma                                                   (time1, sigma, lat, lon) float32 3.21 ...
    v-component_of_wind_sigma                                                   (time1, sigma, lat, lon) float32 0.12 ...
    Planetary_Boundary_Layer_Height_surface                                     (time1, lat, lon) float32 1044.0 ...
    Convective_Precipitation_Rate_surface_Mixed_intervals_Average               (time2, lat, lon) float32 4e-06 ...
    Vertical_velocity_pressure_sigma                                            (time1, sigma, lat, lon) float32 0.384 ...
    Total_cloud_cover_entire_atmosphere_Mixed_intervals_Average                 (time2, lat, lon) float32 32.0 ...
    Geopotential_height_highest_tropospheric_freezing                           (time1, lat, lon) float32 3275.2 ...
    Cloud_water_entire_atmosphere_single_layer                                  (time1, lat, lon) float32 0.0 ...
    Pressure_potential_vorticity_surface                                        (time1, potential_vorticity_surface, lat, lon) float32 nan ...
    Temperature_potential_vorticity_surface                                     (time1, potential_vorticity_surface, lat, lon) float32 nan ...
    u-component_of_wind_potential_vorticity_surface                             (time1, potential_vorticity_surface, lat, lon) float32 nan ...
    v-component_of_wind_potential_vorticity_surface                             (time1, potential_vorticity_surface, lat, lon) float32 nan ...
    Geopotential_height_potential_vorticity_surface                             (time1, potential_vorticity_surface, lat, lon) float32 nan ...
Attributes:
    Originating_or_generating_Center: US National Weather Service, National Centres for Environmental Prediction (NCEP)
    Originating_or_generating_Subcenter: 0
    GRIB_table_version: 2,1
    Type_of_generating_process: Forecast
    Analysis_or_forecast_generating_process_identifier_defined_by_originating_centre: Analysis from GFS (Global Forecast System)
    file_format: GRIB-2
    Conventions: CF-1.6
    history: Read using CDM IOSP GribCollection v3
    featureType: GRID
    _CoordSysBuilder: ucar.nc2.dataset.conv.CF1Convention

In [ ]: