========================== Grid Levels and Parameters ========================== `Notebook `_ This example covers the callable methods of the Python AWIPS DAF when working with gridded data. We start with a connection to an EDEX server, then query data types, then grid names, parameters, levels, and other information. Finally the gridded data is plotted for its domain using Matplotlib and Cartopy. DataAccessLayer.getSupportedDatatypes() --------------------------------------- getSupportedDatatypes() returns a list of available data types offered by the EDEX server defined above. .. code:: ipython3 from awips.dataaccess import DataAccessLayer import unittest DataAccessLayer.changeEDEXHost("edex-cloud.unidata.ucar.edu") dataTypes = DataAccessLayer.getSupportedDatatypes() dataTypes.sort() list(dataTypes) .. parsed-literal:: ['acars', 'airep', 'binlightning', 'bufrmosAVN', 'bufrmosETA', 'bufrmosGFS', 'bufrmosHPC', 'bufrmosLAMP', 'bufrmosMRF', 'bufrua', 'climate', 'common_obs_spatial', 'gfe', 'gfeEditArea', 'grid', 'maps', 'modelsounding', 'obs', 'pirep', 'practicewarning', 'profiler', 'radar', 'radar_spatial', 'satellite', 'sfcobs', 'topo', 'warning'] DataAccessLayer.getAvailableLocationNames() ------------------------------------------- Now create a new data request, and set the data type to **grid** to request all available grids with **getAvailableLocationNames()** .. code:: ipython3 request = DataAccessLayer.newDataRequest() request.setDatatype("grid") available_grids = DataAccessLayer.getAvailableLocationNames(request) available_grids.sort() list(available_grids) .. parsed-literal:: ['AUTOSPE', 'CMC', 'ESTOFS', 'ETSS', 'FFG-ALR', 'FFG-FWR', 'FFG-KRF', 'FFG-MSR', 'FFG-ORN', 'FFG-PTR', 'FFG-RHA', 'FFG-RSA', 'FFG-STR', 'FFG-TAR', 'FFG-TIR', 'FFG-TUA', 'GEFS', 'GFS', 'GFS20', 'HFR-EAST_6KM', 'HFR-EAST_PR_6KM', 'HFR-US_EAST_DELAWARE_1KM', 'HFR-US_EAST_FLORIDA_2KM', 'HFR-US_EAST_NORTH_2KM', 'HFR-US_EAST_SOUTH_2KM', 'HFR-US_EAST_VIRGINIA_1KM', 'HFR-US_HAWAII_1KM', 'HFR-US_HAWAII_2KM', 'HFR-US_HAWAII_6KM', 'HFR-US_WEST_500M', 'HFR-US_WEST_CENCAL_2KM', 'HFR-US_WEST_LOSANGELES_1KM', 'HFR-US_WEST_LOSOSOS_1KM', 'HFR-US_WEST_NORTH_2KM', 'HFR-US_WEST_SANFRAN_1KM', 'HFR-US_WEST_SOCAL_2KM', 'HFR-US_WEST_WASHINGTON_1KM', 'HFR-WEST_6KM', 'HPCGuide', 'HPCqpfNDFD', 'HRRR', 'LAMP2p5', 'MRMS_0500', 'MRMS_1000', 'NAM12', 'NAM40', 'NOHRSC-SNOW', 'NationalBlend', 'RAP13', 'RTMA', 'RTOFS-Now-WestAtl', 'RTOFS-Now-WestConus', 'RTOFS-WestAtl', 'RTOFS-WestConus', 'SPCGuide', 'SeaIce', 'TPCWindProb', 'URMA25', 'WaveWatch'] DataAccessLayer.getAvailableParameters() ---------------------------------------- After datatype and model name (locationName) are set, you can query all available parameters with **getAvailableParameters()** .. code:: ipython3 request.setLocationNames("RAP13") availableParms = DataAccessLayer.getAvailableParameters(request) availableParms.sort() list(availableParms) .. parsed-literal:: ['36SHRMi', '50dbzZ', 'AV', 'Along', 'AppT', 'BLI', 'BRN', 'BRNEHIi', 'BRNSHR', 'BRNmag', 'BRNvec', 'BdEPT06', 'BlkMag', 'BlkShr', 'CAPE', 'CFRZR', 'CICEP', 'CIn', 'CP', 'CP1hr', 'CPr', 'CPrD', 'CRAIN', 'CSNOW', 'CURU', 'CXR', 'CapeStk', 'Corf', 'CorfF', 'CorfFM', 'CorfM', 'CritT1', 'CumNrm', 'CumShr', 'DivF', 'DivFn', 'DivFs', 'DpD', 'DpT', 'EHI', 'EHI01', 'EHIi', 'EPT', 'EPTA', 'EPTC', 'EPTGrd', 'EPTGrdM', 'EPTs', 'EPVg', 'EPVs', 'EPVt1', 'EPVt2', 'ESP', 'ESP2', 'FVecs', 'FeatMot', 'FnVecs', 'FsVecs', 'Fzra1', 'Fzra2', 'GH', 'GHxSM', 'GHxSM2', 'Gust', 'HI', 'HI1', 'HI3', 'HI4', 'HIdx', 'HPBL', 'Heli', 'HeliC', 'INV', 'IPLayer', 'Into', 'KI', 'L-I', 'LIsfc2x', 'LM5', 'LM6', 'MAdv', 'MCon', 'MCon2', 'MLLCL', 'MMP', 'MMSP', 'MSFDi', 'MSFi', 'MSFmi', 'MSG', 'MTV', 'Mix1', 'Mix2', 'Mmag', 'MpV', 'NBE', 'NST', 'NST1', 'NST2', 'OmDiff', 'P', 'PAdv', 'PBE', 'PEC', 'PFrnt', 'PGrd', 'PGrd1', 'PGrdM', 'PIVA', 'PR', 'PTvA', 'PTyp', 'PVV', 'PW', 'PW2', 'PoT', 'PoTA', 'QPV1', 'QPV2', 'QPV3', 'QPV4', 'REFC', 'RH', 'RH_001_bin', 'RH_002_bin', 'RM5', 'RM6', 'RMprop', 'RMprop2', 'RRtype', 'RV', 'Rain1', 'Rain2', 'Rain3', 'Ro', 'SH', 'SHx', 'SLI', 'SNSQ', 'SNW', 'SNWA', 'SRMl', 'SRMlM', 'SRMm', 'SRMmM', 'SRMr', 'SRMrM', 'SSP', 'SSi', 'STP', 'STP1', 'Shear', 'ShrMag', 'SnD', 'Snow1', 'Snow2', 'Snow3', 'SnowT', 'St-Pr', 'StrTP', 'StrmMot', 'SuCP', 'T', 'TAdv', 'TGrd', 'TGrdM', 'TORi', 'TORi2', 'TP', 'TP1hr', 'TQIND', 'TShrMi', 'TV', 'TW', 'T_001_bin', 'Tdef', 'Tdend', 'ThGrd', 'Thom5', 'Thom5a', 'Thom6', 'TmDpD', 'Tmax', 'Tmin', 'Topo', 'TotQi', 'Tstk', 'TwMax', 'TwMin', 'Twstk', 'TxSM', 'USTM', 'VAdv', 'VAdvAdvection', 'VGP', 'VSTM', 'Vis', 'WCD', 'WD', 'WEASD', 'WEASD1hr', 'WGS', 'Wind', 'WndChl', 'ageoVC', 'ageoW', 'ageoWM', 'cCape', 'cCin', 'cTOT', 'capeToLvl', 'dCape', 'dP', 'dT', 'dVAdv', 'dZ', 'defV', 'del2gH', 'df', 'fGen', 'fnD', 'fsD', 'gamma', 'gammaE', 'geoVort', 'geoW', 'geoWM', 'loCape', 'maxEPT', 'minEPT', 'mixRat', 'msl-P', 'muCape', 'pV', 'pVeq', 'qDiv', 'qVec', 'qnVec', 'qsVec', 'shWlt', 'snoRat', 'snoRatCrocus', 'snoRatEMCSREF', 'snoRatOv2', 'snoRatSPC', 'snoRatSPCdeep', 'snoRatSPCsurface', 'staticCoriolis', 'staticSpacing', 'staticTopo', 'swtIdx', 'tTOT', 'tWind', 'tWindU', 'tWindV', 'uFX', 'uW', 'uWStk', 'ulSnoRat', 'vSmthW', 'vTOT', 'vW', 'vWStk', 'vertCirc', 'wDiv', 'wSp', 'wSp_001_bin', 'wSp_002_bin', 'wSp_003_bin', 'wSp_004_bin', 'zAGL'] DataAccessLayer.getAvailableLevels() ------------------------------------ Selecting **"T"** for temperature. .. code:: ipython3 request.setParameters("T") availableLevels = DataAccessLayer.getAvailableLevels(request) for lvl in availableLevels: print(lvl) .. parsed-literal:: 0.0SFC 350.0MB 475.0MB 610.0_40000.0FHAG 225.0MB 120.0_150.0BL 900.0MB 125.0MB 0.0_610.0FHAG 450.0MB 575.0MB 325.0MB 100.0MB 1000.0MB 60.0_90.0BL 275.0MB 1.0PV 950.0MB 150.0MB 1.5PV 700.0MB 825.0MB 150.0_180.0BL 250.0MB 375.0MB 1000.0_500.0MB 800.0MB 4000.0FHAG 925.0MB 2.0PV 0.5PV 0.0TROP 750.0MB 500.0MB 625.0MB 400.0MB 0.0FHAG 2.0FHAG 875.0MB 175.0MB 0.0_1000.0FHAG 850.0MB 600.0MB 725.0MB 0.0_6000.0FHAG 975.0MB 550.0MB 0.0_3000.0FHAG 675.0MB 425.0MB 200.0MB 0.0_30.0BL 30.0_60.0BL 650.0MB 525.0MB 300.0MB 90.0_120.0BL 1000.0FHAG 775.0MB 340.0_350.0K 290.0_300.0K 700.0_600.0MB 700.0_300.0MB 320.0Ke 800.0_750.0MB 60.0TILT 5.3TILT 1000.0_900.0MB 340.0K 5500.0_6000.0FHAG 255.0K 255.0_265.0K 3000.0_6000.0FHAG 25.0TILT 2000.0FHAG 0.0_500.0FHAG 1000.0_850.0MB 850.0_250.0MB 280.0_290.0Ke 1524.0FHAG 320.0_330.0K 0.0TILT 310.0_320.0Ke 310.0Ke 330.0K 900.0_800.0MB 550.0_500.0MB 2.4TILT 50.0TILT 3500.0FHAG 35.0TILT 12.0TILT 300.0_310.0K 3000.0_12000.0FHAG 0.9TILT 320.0K 400.0_350.0MB 500.0FHAG 750.0_700.0MB 1000.0_400.0MB 345.0K 250.0_260.0K 300.0Ke 290.0Ke 950.0_900.0MB 4572.0FHAG 275.0_285.0Ke 335.0Ke 295.0_305.0Ke 275.0_285.0K 600.0_550.0MB 310.0K 9000.0FHAG 335.0K 1000.0_7000.0FHAG 700.0_500.0MB 9144.0FHAG 325.0_335.0K 2000.0_8000.0FHAG 0.0_609.6FHAG 300.0K 0.0MAXOMEGA 315.0_325.0K 325.0K 340.0Ke 0.0_4000.0FHAG 5000.0_5500.0FHAG 300.0_250.0MB 1.5TILT 335.0_345.0K 315.0K 3.4TILT 2500.0FHAG 10000.0FHAG 0.0_2000.0FHAG 7000.0FHAG 5000.0FHAG 330.0Ke 500.0_400.0MB 1000.0_1500.0FHAG 305.0K 285.0_295.0Ke 14.0TILT 3000.0_3500.0FHAG 325.0_335.0Ke 2000.0_5000.0FHAG 7620.0FHAG 850.0_800.0MB 6096.0FHAG 6000.0_7000.0FHAG 2000.0_7000.0FHAG 9000.0_10000.0FHAG 295.0Ke 305.0Ke 265.0_275.0K 7000.0_8000.0FHAG 3000.0_8000.0FHAG 700.0_650.0MB 1000.0_6000.0FHAG 0.5TILT 450.0_400.0MB 1.8TILT 330.0_340.0K 800.0_700.0MB 850.0_300.0MB 6.0TILT 900.0_850.0MB 3657.6FHAG 0.0_5000.0FHAG 320.0_330.0Ke 8.7TILT 650.0_600.0MB 600.0_400.0MB 55.0TILT 270.0_280.0Ke 30.0TILT 310.0_320.0K 1500.0FHAG 1000.0_950.0MB 5500.0FHAG 250.0_200.0MB 500.0_1000.0FHAG 400.0_300.0MB 500.0_100.0MB 1000.0_3000.0FHAG 8000.0FHAG 285.0Ke 290.0K 305.0_315.0K 285.0_295.0K 0.0_2500.0FHAG 925.0_850.0MB 275.0Ke 1500.0_2000.0FHAG 300.0_200.0MB 260.0_270.0K 2743.2FHAG 3000.0FHAG 315.0_325.0Ke 600.0_500.0MB 16.7TILT 280.0K 500.0_250.0MB 40.0TILT 3048.0FHAG 400.0_200.0MB 300.0_310.0Ke 270.0_280.0K 1000.0_700.0MB 45.0TILT 850.0_500.0MB 2500.0_3000.0FHAG 609.6FHAG 0.0_8000.0FHAG 295.0K 4.3TILT 295.0_305.0K 330.0_340.0Ke 270.0K 4000.0_4500.0FHAG 280.0_290.0K 925.0_700.0MB 0.0_1500.0FHAG 260.0K 10.0TILT 3500.0_4000.0FHAG 325.0Ke 285.0K 290.0_300.0Ke 7.5TILT 1828.8FHAG 280.0Ke 500.0_450.0MB 305.0_315.0Ke 250.0K 4500.0FHAG 1250.0FHAG 0.0_10000.0FHAG 4500.0_5000.0FHAG 250.0_350.0K 270.0Ke 275.0K 315.0Ke 500.0_300.0MB 350.0_300.0MB 750.0FHAG 19.5TILT 2000.0_2500.0FHAG 850.0_700.0MB 350.0K 265.0K 6000.0FHAG 8000.0_9000.0FHAG 700.0_300.0LYRMB 850.0_700.0LYRMB - **0.0SFC** is the Surface level - **FHAG** stands for Fixed Height Above Ground (in meters) - **NTAT** stands for Nominal Top of the ATmosphere - **BL** stands for Boundary Layer, where **0.0\_30.0BL** reads as *0-30 mb above ground level* - **TROP** is the Tropopause level **request.setLevels()** For this example we will use Surface Temperature .. code:: ipython3 request.setLevels("2.0FHAG") DataAccessLayer.getAvailableTimes() ----------------------------------- - **getAvailableTimes(request, True)** will return an object of *run times* - formatted as ``YYYY-MM-DD HH:MM:SS`` - **getAvailableTimes(request)** will return an object of all times - formatted as ``YYYY-MM-DD HH:MM:SS (F:ff)`` - **getForecastRun(cycle, times)** will return a DataTime array for a single forecast cycle. .. code:: ipython3 cycles = DataAccessLayer.getAvailableTimes(request, True) times = DataAccessLayer.getAvailableTimes(request) fcstRun = DataAccessLayer.getForecastRun(cycles[-1], times) list(fcstRun) .. parsed-literal:: [, , , , , , , , , , , , , , , , , , , , , ] DataAccessLayer.getGridData() ----------------------------- Now that we have our ``request`` and DataTime ``fcstRun`` arrays ready, it's time to request the data array from EDEX. .. code:: ipython3 response = DataAccessLayer.getGridData(request, [fcstRun[-1]]) for grid in response: data = grid.getRawData() lons, lats = grid.getLatLonCoords() print('Time :', str(grid.getDataTime())) print('Model:', str(grid.getLocationName())) print('Parm :', str(grid.getParameter())) print('Unit :', str(grid.getUnit())) print(data.shape) .. parsed-literal:: Time : 2020-09-04 18:00:00 Model: RAP13 Parm : T Unit : K (337, 451) Plotting with Matplotlib and Cartopy ------------------------------------ **1. pcolormesh** .. code:: ipython3 %matplotlib inline import matplotlib.pyplot as plt import matplotlib import cartopy.crs as ccrs import cartopy.feature as cfeature from cartopy.mpl.gridliner import LONGITUDE_FORMATTER, LATITUDE_FORMATTER import numpy as np import numpy.ma as ma from scipy.io import loadmat from scipy.constants import convert_temperature def make_map(bbox, projection=ccrs.PlateCarree()): fig, ax = plt.subplots(figsize=(16, 9), subplot_kw=dict(projection=projection)) ax.set_extent(bbox) ax.coastlines(resolution='50m') gl = ax.gridlines(draw_labels=True) gl.top_labels = gl.right_labels = False gl.xformatter = LONGITUDE_FORMATTER gl.yformatter = LATITUDE_FORMATTER return fig, ax #convert temp from K to F dataf = convert_temperature(data, 'K', 'F') cmap = plt.get_cmap('rainbow') bbox = [lons.min(), lons.max(), lats.min(), lats.max()] fig, ax = make_map(bbox=bbox) cs = ax.pcolormesh(lons, lats, dataf, cmap=cmap) cbar = fig.colorbar(cs, extend='both', shrink=0.5, orientation='horizontal') cbar.set_label(grid.getLocationName() +" " + grid.getLevel() + " " \ + grid.getParameter() + " (F) " \ + "valid " + str(grid.getDataTime().getRefTime())) .. image:: Grid_Levels_and_Parameters_files/Grid_Levels_and_Parameters_16_0.png **2. contourf** .. code:: ipython3 fig2, ax2 = make_map(bbox=bbox) cs2 = ax2.contourf(lons, lats, dataf, 80, cmap=cmap, vmin=dataf.min(), vmax=dataf.max(), extend='both') cbar2 = fig2.colorbar(cs2, shrink=0.5, orientation='horizontal') cbar2.set_label(grid.getLocationName() +" " + grid.getLevel() + " " \ + grid.getParameter() + " (F) " \ + "valid " + str(grid.getDataTime().getRefTime())) .. image:: Grid_Levels_and_Parameters_files/Grid_Levels_and_Parameters_18_0.png