In [3]:
import netCDF4
import matplotlib.pyplot as plt
# link to local or OpeNDAP dataset
url='http://thredds.ucar.edu/thredds/dodsC/grib/NCEP/NAM/CONUS_12km/conduit/best'
# Open the dataset
ncv = netCDF4.Dataset(url).variables
# Show a list of variables
for ncv.keys()
[u'LambertConformal_Projection', u'pressure_difference_layer_bounds', u'pressure_difference_layer1_bounds', u'pressure_difference_layer2_bounds', u'sigma_layer_bounds', u'depth_below_surface_layer_bounds', u'depth_below_surface_layer1_bounds', u'height_above_ground_layer_bounds', u'pressure_difference_layer3_bounds', u'height_above_ground_layer1_bounds', u'pressure_difference_layer4_bounds', u'isobaric_layer_bounds', u'pressure_difference_layer5_bounds', u'depth_below_surface_layer2_bounds', u'time1_bounds', u'time2_bounds', u'time3_bounds', u'time4_bounds', u'x', u'y', u'isobaric', u'pressure_difference_layer', u'height_above_ground', u'hybrid', u'pressure_difference_layer1', u'height_above_ground1', u'pressure_difference_layer2', u'sigma_layer', u'depth_below_surface_layer', u'depth_below_surface', u'depth_below_surface_layer1', u'height_above_ground2', u'height_above_ground_layer', u'pressure_difference_layer3', u'isobaric1', u'sigma', u'height_above_ground3', u'height_above_ground_layer1', u'pressure_difference_layer4', u'isobaric_layer', u'pressure_difference_layer5', u'depth_below_surface_layer2', u'isobaric2', u'time', u'time1', u'time2', u'time3', u'time4', u'Temperature_surface', u'Temperature_cloud_tops', u'Temperature_isobaric', u'Temperature_height_above_ground', u'Temperature_sigma', u'Temperature_hybrid', u'Temperature_pressure_difference_layer', u'Potential_temperature_height_above_ground', u'Potential_temperature_hybrid', u'Maximum_temperature_height_above_ground_1_Hour_Interval', u'Minimum_temperature_height_above_ground_1_Hour_Interval', u'Dewpoint_temperature_height_above_ground', u'Dewpoint_temperature_hybrid', u'Latent_heat_net_flux_surface', u'Sensible_heat_net_flux_surface', u'Large_Scale_Condensate_Heating_Rate_entire_atmosphere_Mixed_intervals_Average', u'Deep_Convective_Heating_Rate_entire_atmosphere_Mixed_intervals_Average', u'Specific_humidity_height_above_ground', u'Specific_humidity_hybrid', u'Relative_humidity_height_above_ground', u'Relative_humidity_sigma_layer', u'Relative_humidity_hybrid', u'Relative_humidity_pressure_difference_layer', u'Precipitable_water_entire_atmosphere', u'Precipitation_rate_surface', u'Total_precipitation_surface_3_Hour_Accumulation', u'Convective_precipitation_surface_3_Hour_Accumulation', u'Snow_depth_surface', u'Water_equivalent_of_accumulated_snow_depth_surface', u'Water_equivalent_of_accumulated_snow_depth_surface_Mixed_intervals_Accumulation', u'Snow_melt_surface_Mixed_intervals_Accumulation', u'Rain_mixing_ratio_hybrid', u'Snow_mixing_ratio_hybrid', u'Maximum_relative_humidity_height_above_ground_1_Hour_Interval', u'Categorical_Rain_surface', u'Categorical_Freezing_Rain_surface', u'Categorical_Ice_Pellets_surface', u'Categorical_Snow_surface', u'Convective_Precipitation_Rate_surface', u'Horizontal_Moisture_Divergence_entire_atmosphere', u'Minimum_Relative_Humidity_height_above_ground_1_Hour_Interval', u'Snow_Cover_surface', u'Rime_Factor_hybrid', u'Total_Column_Integrated_Rain_entire_atmosphere', u'Total_Column_Integrated_Snow_entire_atmosphere', u'Total_column-integrated_supercooled_liquid_water_entire_atmosphere', u'Total_column-integrated_melting_ice_entire_atmosphere', u'u-component_of_wind_height_above_ground', u'u-component_of_wind_hybrid', u'u-component_of_wind_pressure_difference_layer', u'u-component_of_wind_planetary_boundary', u'v-component_of_wind_height_above_ground', u'v-component_of_wind_hybrid', u'v-component_of_wind_pressure_difference_layer', u'v-component_of_wind_planetary_boundary', u'Vertical_velocity_pressure_isobaric', u'Vertical_velocity_pressure_hybrid', u'Absolute_vorticity_isobaric', u'Wind_speed_gust_surface', u'U-Component_Storm_Motion_height_above_ground_layer', u'V-Component_Storm_Motion_height_above_ground_layer', u'Frictional_Velocity_surface', u'U_Component_of_Hourly_Maximum_10m_Wind_Speed_height_above_ground_1_Hour_Maximum', u'V_Component_of_Hourly_Maximum_10m_Wind_Speed_height_above_ground_1_Hour_Maximum', u'Ventilation_Rate_planetary_boundary', u'Pressure_surface', u'Pressure_cloud_base', u'Pressure_cloud_tops', u'Pressure_hybrid', u'Pressure_grid_scale_cloud_bottom', u'Pressure_grid_scale_cloud_top', u'Pressure_convective_cloud_bottom', u'Pressure_convective_cloud_top', u'Pressure_shallow_convective_cloud_bottom', u'Pressure_shallow_convective_cloud_top', u'Pressure_deep_convective_cloud_bottom', u'Pressure_deep_convective_cloud_top', u'Pressure_reduced_to_MSL_msl', u'Geopotential_height_surface', u'Geopotential_height_adiabatic_condensation_lifted', u'Geopotential_height_hybrid', u'Geopotential_height_cloud_ceiling', u'Geopotential_height_planetary_boundary', u'Geopotential_height_lowest_level_of_the_wet_bulb_zero', u'Geopotential_height_lowest_level_water_layer', u'Geopotential_height_highest_level_water_layer', u'MSLP_Eta_model_reduction_msl', u'Planetary_Boundary_Layer_Height_surface', u'Pressure_of_level_from_which_parcel_was_lifted_pressure_difference_layer', u'Brightness_temperature_atmosphere_top', u'Downward_Short-Wave_Radiation_Flux_surface', u'Downward_Short-Wave_Radiation_Flux_surface_Mixed_intervals_Average', u'Upward_Short-Wave_Radiation_Flux_surface', u'Solar_Radiative_Heating_Rate_entire_atmosphere', u'Downward_Long-Wave_Radp_Flux_surface', u'Upward_Long-Wave_Radp_Flux_surface', u'Upward_Long-Wave_Radp_Flux_atmosphere_top', u'Long-Wave_Radiative_Heating_Rate_entire_atmosphere', u'Total_cloud_cover_entire_atmosphere', u'Convective_cloud_cover_entire_atmosphere', u'Low_cloud_cover_low_cloud', u'Medium_cloud_cover_middle_cloud', u'High_cloud_cover_high_cloud', u'Convective_Cloud_Efficiency_entire_atmosphere', u'Total_Column-Integrated_Cloud_Water_entire_atmosphere', u'Total_Column-Integrated_Cloud_Ice_entire_atmosphere', u'Total_Column-Integrated_Condensate_entire_atmosphere', u'Parcel_lifted_index_to_500_hPa_pressure_difference_layer', u'Convective_available_potential_energy_surface', u'Convective_available_potential_energy_pressure_difference_layer', u'Convective_inhibition_surface', u'Convective_inhibition_pressure_difference_layer', u'Storm_relative_helicity_height_above_ground_layer', u'Surface_Lifted_Index_isobaric_layer', u'Best_4_layer_Lifted_Index_pressure_difference_layer', u'Reflectivity_height_above_ground', u'Reflectivity_hybrid', u'Composite_reflectivity_entire_atmosphere', u'Echo_Top_entire_atmosphere', u'Lightning_surface', u'Visibility_surface', u'Albedo_surface', u'Turbulent_kinetic_energy_hybrid', u'Maximum_Snow_Albedo_surface', u'Snow-Free_Albedo_surface', u'Baseflow-Groundwater_Runoff_surface_Mixed_intervals_Accumulation', u'Storm_Surface_Runoff_surface_Mixed_intervals_Accumulation', u'Probability_of_Frozen_Precipitation_surface', u'Land_cover_0__sea_1__land_surface', u'Surface_roughness_surface', u'Soil_temperature_depth_below_surface', u'Soil_temperature_depth_below_surface_layer', u'Soil_moisture_content_depth_below_surface_layer', u'Vegetation_surface', u'Volumetric_Soil_Moisture_Content_depth_below_surface_layer', u'Moisture_Availability_depth_below_surface_layer', u'Exchange_Coefficient_surface', u'Plant_Canopy_Surface_Water_surface', u'Blackadars_Mixing_Length_Scale_hybrid', u'Vegetation_Type_surface', u'Canopy_Conductance_surface', u'Minimal_Stomatal_Resistance_surface', u'Wilting_Point_surface', u'Solar_parameter_in_canopy_conductance_surface', u'Temperature_parameter_in_canopy_conductance_surface', u'Humidity_parameter_in_canopy_conductance_surface', u'Soil_moisture_parameter_in_canopy_conductance_surface', u'Soil_type_surface', u'Liquid_Volumetric_Soil_Moisture_non_Frozen_depth_below_surface_layer', u'Number_of_Soil_Layers_in_Root_Zone_surface', u'Transpiration_Stress-onset_soil_moisture_surface', u'Direct_Evaporation_Cease_soil_moisture_surface', u'Soil_Porosity_surface', u'Haines_Index_surface', u'Ice_cover_surface', u'Water_temperature_surface']
In [10]:
# looks for keys that have the substring "lon" in them:
substr = 'lon'
print "\n".join([var for var in ncv.keys() if substr in var.lower()])
Downward_Long-Wave_Radp_Flux_surface
Upward_Long-Wave_Radp_Flux_surface
Upward_Long-Wave_Radp_Flux_atmosphere_top
Long-Wave_Radiative_Heating_Rate_entire_atmosphere
In [8]:
import netCDF4
import matplotlib.pyplot as plt
# link to local or OpeNDAP dataset
url='http://thredds.ucar.edu/thredds/dodsC/grib/NCEP/NAM/CONUS_12km/conduit/best'
# Open the dataset
ncv = netCDF4.Dataset(url).variables
# Show a list of variables
ncv.keys()
# Get lat and lon
#lon = ncv.variables['lon'].getValue()
# look at a variable
temp = ncv['Temperature_height_above_ground']
print temp
# read all data for a specified layer and time
itime = -1
layer = 0
t = temp[itime,layer,:,:]
# plot it
plt.pcolormesh(t);
plt.colorbar();
<type 'netCDF4.Variable'>
float32 Temperature_height_above_ground(u'time', u'height_above_ground', u'y', u'x')
long_name: Temperature @ Specified height level above ground
units: K
missing_value: nan
abbreviation: TMP
grid_mapping: LambertConformal_Projection
Grib_Variable_Id: VAR_0-0-0_L103
Grib2_Parameter: [0 0 0]
Grib2_Parameter_Discipline: Meteorological products
Grib2_Parameter_Category: Temperature
Grib2_Parameter_Name: Temperature
Grib2_Level_Type: 103
Grib2_Generating_Process_Type: Forecast
unlimited dimensions = ()
current size = (145, 1, 428, 614)
Out[8]:
<matplotlib.colorbar.Colorbar instance at 0x2d4e638>
In [ ]:
Content source: rsignell-usgs/notebook
Similar notebooks: