import numpy as np
import xarray as xr
import metpy.calc as mpcalc
from metpy.interpolate import cross_section
ds = xr.open_dataset("hrrr.t00z.wrfnatf00.grib2", engine="cfgrib", backend_kwargs={'filter_by_keys':{'typeOfLevel': 'hybrid'}})
cf_attrs = {
'grid_mapping_name': 'lambert_conformal_conic',
'standard_parallel': 38.5,
'longitude_of_central_meridian': -97.5,
'latitude_of_projection_origin': 38.5
}
ds = ds[['gh', 'pres', 't', 'u', 'v', 'q']].metpy.assign_crs(cf_attrs).metpy.assign_y_x()
ds
/home/jthielen/dev/MetPy/src/metpy/xarray.py:324: UserWarning: More than one time coordinate present for variable "gh". warnings.warn('More than one ' + axis + ' coordinate present for variable' /home/jthielen/dev/MetPy/src/metpy/xarray.py:324: UserWarning: More than one time coordinate present for variable "pres". warnings.warn('More than one ' + axis + ' coordinate present for variable' /home/jthielen/dev/MetPy/src/metpy/xarray.py:324: UserWarning: More than one time coordinate present for variable "t". warnings.warn('More than one ' + axis + ' coordinate present for variable' /home/jthielen/dev/MetPy/src/metpy/xarray.py:324: UserWarning: More than one time coordinate present for variable "u". warnings.warn('More than one ' + axis + ' coordinate present for variable' /home/jthielen/dev/MetPy/src/metpy/xarray.py:324: UserWarning: More than one time coordinate present for variable "v". warnings.warn('More than one ' + axis + ' coordinate present for variable' /home/jthielen/dev/MetPy/src/metpy/xarray.py:324: UserWarning: More than one time coordinate present for variable "q". warnings.warn('More than one ' + axis + ' coordinate present for variable'
<xarray.Dataset> Dimensions: (hybrid: 50, x: 1799, y: 1059) Coordinates: * hybrid (hybrid) int64 1 2 3 4 5 6 7 8 9 ... 42 43 44 45 46 47 48 49 50 longitude (y, x) float64 237.3 237.3 237.3 237.4 ... 299.0 299.0 299.1 latitude (y, x) float64 21.14 21.15 21.15 21.16 ... 47.86 47.85 47.84 valid_time datetime64[ns] 2020-08-05 step timedelta64[ns] 00:00:00 time datetime64[ns] 2020-08-05 crs object Projection: lambert_conformal_conic * y (y) float64 -1.587e+06 -1.584e+06 ... 1.584e+06 1.587e+06 * x (x) float64 -2.697e+06 -2.694e+06 ... 2.693e+06 2.696e+06 Data variables: gh (hybrid, y, x) float32 ... pres (hybrid, y, x) float32 ... t (hybrid, y, x) float32 ... u (hybrid, y, x) float32 ... v (hybrid, y, x) float32 ... q (hybrid, y, x) float32 ... Attributes: GRIB_edition: 2 GRIB_centre: kwbc GRIB_centreDescription: US National Weather Service - NCEP GRIB_subCentre: 0 Conventions: CF-1.7 institution: US National Weather Service - NCEP history: 2020-08-05T10:05:34 GRIB to CDM+CF via cfgrib-0....
array([ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50])
array([[237.280472, 237.307139, 237.33381 , ..., 287.656941, 287.683613, 287.710282], [237.272975, 237.299649, 237.326327, ..., 287.664421, 287.691101, 287.717776], [237.265474, 237.292155, 237.31884 , ..., 287.671906, 287.698592, 287.725275], ..., [225.93519 , 225.971716, 226.008253, ..., 298.979074, 299.015616, 299.052145], [225.919861, 225.956399, 225.992948, ..., 298.994375, 299.030929, 299.06747 ], [225.90452 , 225.94107 , 225.977631, ..., 299.009688, 299.046254, 299.082807]])
array([[21.138123, 21.14511 , 21.15209 , ..., 21.154509, 21.147531, 21.140547], [21.162995, 21.169984, 21.176967, ..., 21.179387, 21.172407, 21.165419], [21.187869, 21.194861, 21.201847, ..., 21.204268, 21.197285, 21.190294], ..., [47.789559, 47.799849, 47.810129, ..., 47.813691, 47.803415, 47.793128], [47.814093, 47.824386, 47.834669, ..., 47.838233, 47.827953, 47.817664], [47.838623, 47.84892 , 47.859206, ..., 47.862771, 47.852488, 47.842195]])
array('2020-08-05T00:00:00.000000000', dtype='datetime64[ns]')
array(0, dtype='timedelta64[ns]')
array('2020-08-05T00:00:00.000000000', dtype='datetime64[ns]')
array(<metpy.plots.mapping.CFProjection object at 0x7fc71aeb7a30>, dtype=object)
array([-1587248.352872, -1584248.462113, -1581248.571354, ..., 1580636.288537, 1583636.179296, 1586636.070055])
array([-2697421.915842, -2694422.025083, -2691422.134324, ..., 2690381.887161, 2693381.77792 , 2696381.668679])
[95257050 values with dtype=float32]
[95257050 values with dtype=float32]
[95257050 values with dtype=float32]
[95257050 values with dtype=float32]
[95257050 values with dtype=float32]
[95257050 values with dtype=float32]
start = (35.0, -105.0)
end = (40.5, -75.0)
cross = cross_section(ds, start, end)
cross
<xarray.Dataset> Dimensions: (hybrid: 50, index: 100) Coordinates: * hybrid (hybrid) int64 1 2 3 4 5 6 7 8 9 ... 42 43 44 45 46 47 48 49 50 longitude (index) float64 255.0 255.3 255.6 255.8 ... 284.4 284.7 285.0 latitude (index) float64 35.0 35.09 35.18 35.27 ... 40.47 40.48 40.5 valid_time datetime64[ns] 2020-08-05 step timedelta64[ns] 00:00:00 time datetime64[ns] 2020-08-05 crs object Projection: lambert_conformal_conic x (index) float64 -6.836e+05 -6.576e+05 ... 1.859e+06 1.885e+06 y (index) float64 -3.616e+05 -3.534e+05 ... 4.458e+05 4.54e+05 * index (index) int64 0 1 2 3 4 5 6 7 8 9 ... 91 92 93 94 95 96 97 98 99 Data variables: gh (hybrid, index) float64 1.645e+03 1.547e+03 ... 2.62e+04 pres (hybrid, index) float64 8.354e+04 8.444e+04 ... 2.23e+03 t (hybrid, index) float64 307.9 308.6 309.7 ... 223.3 223.4 223.3 u (hybrid, index) float64 5.217 6.452 4.287 ... -13.63 -13.97 v (hybrid, index) float64 -1.812 0.8694 2.493 ... -4.488 -4.548 q (hybrid, index) float64 0.005185 0.005713 ... 2.643e-06 Attributes: GRIB_edition: 2 GRIB_centre: kwbc GRIB_centreDescription: US National Weather Service - NCEP GRIB_subCentre: 0 Conventions: CF-1.7 institution: US National Weather Service - NCEP history: 2020-08-05T10:05:34 GRIB to CDM+CF via cfgrib-0....
array([ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50])
array([254.99999996, 255.27710406, 255.55483029, 255.83317685, 256.11214333, 256.39172917, 256.6719327 , 256.9527527 , 257.23418856, 257.51623857, 257.79890129, 258.08217549, 258.36605947, 258.65055173, 258.93565049, 259.22135385, 259.50766015, 259.79456744, 260.08207339, 260.37017613, 260.65887344, 260.94816291, 261.2380422 , 261.52850885, 261.81956028, 262.11119389, 262.40340686, 262.69619643, 262.98955964, 263.28349349, 263.57799494, 263.87306072, 264.16868762, 264.46487218, 264.76161104, 265.05890069, 265.35673729, 265.65511718, 265.95403677, 266.25349179, 266.55347843, 266.85399256, 267.15502983, 267.45658634, 267.75865739, 268.06123836, 268.36432513, 268.66791288, 268.97199668, 269.27657197, 269.58163333, 269.88717651, 270.19319612, 270.49968624, 270.80664233, 271.11405938, 271.42193094, 271.7302521 , 272.03901679, 272.34821979, 272.65785532, 272.96791671, 273.27839831, 273.58929502, 273.90059927, 274.21230551, 274.52440748, 274.83689837, 275.14977246, 275.46302261, 275.77664158, 276.09062427, 276.40496292, 276.71965023, 277.03468002, 277.35004513, 277.66573839, 277.98175291, 278.29808021, 278.61471488, 278.93164918, 279.24887388, 279.56638297, 279.88417006, 280.20222499, 280.52054159, 280.83911189, 281.15792816, 281.47698275, 281.79626711, 282.11577328, 282.43549489, 282.75542204, 283.07554647, 283.39586223, 283.71635941, 284.03702951, 284.35786526, 284.67885853, 285. ])
array([34.99999911, 35.09169 , 35.18274734, 35.27317047, 35.36295526, 35.45209582, 35.54059144, 35.62843808, 35.71562998, 35.8021663 , 35.88804281, 35.97325426, 36.05779961, 36.14167421, 36.22487357, 36.30739637, 36.38923756, 36.47039335, 36.55086223, 36.63063863, 36.70971973, 36.78810351, 36.86578402, 36.9427595 , 37.01902743, 37.0945812 , 37.16942043, 37.24354164, 37.31693865, 37.38961132, 37.46155532, 37.53276586, 37.60324215, 37.67297915, 37.74197363, 37.81022412, 37.87772486, 37.94447416, 38.0104699 , 38.07570559, 38.14018115, 38.20389322, 38.26683615, 38.32900995, 38.39041026, 38.45103309, 38.51087774, 38.56993908, 38.62821485, 38.6857036 , 38.7423995 , 38.79830193, 38.85340862, 38.90771341, 38.961217 , 39.01391569, 39.06580503, 39.11688502, 39.16715131, 39.216601 , 39.26523348, 39.31304372, 39.36003052, 39.40619247, 39.45152397, 39.4960254 , 39.53969449, 39.58252583, 39.62452045, 39.66567511, 39.70598598, 39.74545337, 39.78407354, 39.82184411, 39.85876494, 39.89483165, 39.93004325, 39.96439912, 39.99789455, 40.03052964, 40.06230338, 40.09321068, 40.12325298, 40.15242824, 40.18073216, 40.20816632, 40.23472833, 40.26041465, 40.28522668, 40.30916178, 40.33221749, 40.35439466, 40.37569056, 40.39610375, 40.41563469, 40.43428044, 40.45204044, 40.46891513, 40.48490109, 40.49999867])
array('2020-08-05T00:00:00.000000000', dtype='datetime64[ns]')
array(0, dtype='timedelta64[ns]')
array('2020-08-05T00:00:00.000000000', dtype='datetime64[ns]')
array(<metpy.plots.mapping.CFProjection object at 0x7fc71aeb7a30>, dtype=object)
array([-683640.73098309, -657634.25801538, -631632.08195635, -605634.07676879, -579640.1177087 , -553650.08133247, -527663.84550401, -501681.28940176, -475702.29352556, -449726.73970352, -423754.51109874, -397785.49221583, -371819.5689075 , -345856.62838084, -319896.55920361, -293939.25131034, -267984.59600829, -242032.48598328, -216082.81530538, -190135.47943445, -164190.3752255 , -138247.40093391, -112306.45622046, -86367.44215622, -60430.26122719, -34494.81733888, -8561.01582054, 17371.23657065, 43302.03164573, 69231.45978021, 95159.60991057, 121086.56953101, 147012.42469039, 172937.25998939, 198861.15857791, 224784.20215275, 250706.47095546, 276628.04377053, 302548.99792372, 328469.40928077, 354389.3522463 , 380308.89976301, 406228.12331112, 432147.09290812, 458065.87710881, 483984.54300563, 509903.15622922, 535821.78094938, 561740.47987622, 587659.31426173, 613578.34390157, 639497.62713723, 665417.22085845, 691337.18050602, 717257.56007489, 743178.41211758, 769099.78774793, 795021.73664523, 820944.30705861, 846867.54581184, 872791.49830841, 898716.20853705, 924641.71907743, 950568.07110643, 976495.30440454, 1002423.45736278, 1028352.56698988, 1054282.66891984, 1080213.79741987, 1106145.98539862, 1132079.26441487, 1158013.66468644, 1183949.2150996 , 1209885.94321874, 1235823.87529643, 1261763.03628383, 1287703.44984144, 1313645.13835027, 1339588.12292326, 1365532.42341712, 1391478.05844452, 1417425.04538658, 1443373.40040577, 1469323.13845906, 1495274.27331154, 1521226.81755024, 1547180.78259836, 1573136.17872982, 1599093.01508417, 1625051.29968168, 1651011.03943896, 1676972.24018471, 1702934.90667589, 1728899.0426141 , 1754864.65066241, 1780831.73246227, 1806800.28865091, 1832770.31887891, 1858741.82182802, 1884714.79522939])
array([-361552.13363909, -353390.13188592, -345222.89128606, -337050.5388552 , -328873.20127724, -320691.00489789, -312504.07571791, -304312.53938606, -296116.52119193, -287916.14605837, -279711.53853372, -271502.82278377, -263290.12258349, -255073.56130842, -246853.26192591, -238629.34698601, -230401.93861216, -222171.15849161, -213937.12786559, -205699.96751919, -197459.79777107, -189216.73846285, -180970.90894828, -172722.42808216, -164471.41420906, -156217.98515173, -147962.25819929, -139704.35009527, -131444.3770253 , -123182.45460462, -114918.69786541, -106653.22124383, -98386.13856687, -90117.56303899, -81847.60722854, -73576.38305401, -65304.00176996, -57030.57395294, -48756.20948705, -40481.01754938, -32205.10659528, -23928.58434339, -15651.55776057, -7374.13304662, 903.58438118, 9181.48990363, 17459.47971543, 25737.45084098, 34015.3011505 , 42292.92937615, 50570.2351284 , 58847.11891233, 67123.48214431, 75399.22716852, 83674.25727379, 91948.4767104 , 100221.790707 , 108494.10548763, 116765.32828884, 125035.36737676, 133304.13206435, 141571.53272869, 149837.48082817, 158101.88891994, 166364.67067717, 174625.74090648, 182885.01556531, 191142.41177927, 199397.84785958, 207651.24332037, 215902.51889603, 224151.59655856, 232398.39953478, 240642.85232354, 248884.88071292, 257124.41179726, 265361.37399424, 273595.69706173, 281827.31211465, 290056.15164172, 298282.14952207, 306505.2410417 , 314725.3629099 , 322942.45327545, 331156.45174271, 339367.29938757, 347574.93877318, 355779.3139656 , 363980.37054916, 372178.05564172, 380372.3179097 , 388563.10758289, 396750.37646909, 404934.07796848, 413114.16708778, 421290.60045419, 429463.33632909, 437632.33462144, 445797.55690096, 453958.96641107])
array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99])
array([[ 1644.62709894, 1547.3950844 , 1410.08484964, ..., 303.23847802, 168.25049523, 165.47601302], [ 1674.4439651 , 1577.32586557, 1440.15395996, ..., 332.69813149, 197.80439546, 195.04335153], [ 1726.25019484, 1629.32543607, 1492.43913474, ..., 384.18640594, 249.49780187, 246.71735292], ..., [23714.14434439, 23715.45754848, 23716.37655447, ..., 23795.38993278, 23803.74087101, 23809.55702078], [24826.49123716, 24825.55159785, 24825.24701541, ..., 24908.32339096, 24916.84259068, 24923.09889016], [26097.24200721, 26094.36946797, 26092.09349114, ..., 26183.4621917 , 26192.09776696, 26197.99635607]])
array([[83539.81792284, 84442.76166037, 85714.60662918, ..., 97645.72068345, 99166.16668944, 99203.01800642], [83294.63470822, 84194.6980772 , 85462.77914613, ..., 97355.08424887, 98871.07582667, 98908.02246155], [82847.41837151, 83742.0975184 , 85002.67410125, ..., 96822.97950684, 98330.38349921, 98367.0010712 ], ..., [ 3215.20361328, 3215.20361328, 3215.20385742, ..., 3215.203125 , 3215.203125 , 3215.203125 ], [ 2705.60205078, 2705.60205078, 2705.60229492, ..., 2705.6015625 , 2705.6015625 , 2705.6015625 ], [ 2230.30078125, 2230.30078125, 2230.30078125, ..., 2230.30053711, 2230.30053711, 2230.30053711]])
array([[307.86487952, 308.62406013, 309.66244068, ..., 297.69945139, 298.32998137, 298.2291266 ], [307.36219397, 308.10255892, 309.18284258, ..., 297.70588045, 298.52326157, 298.55918453], [306.77442542, 307.53274011, 308.65757403, ..., 297.55549884, 298.36722109, 298.5183605 ], ..., [218.36754804, 217.97530053, 217.88561269, ..., 218.07160603, 218.22775541, 218.43200006], [220.53372413, 220.02014551, 219.63878608, ..., 221.00781709, 220.93442427, 220.89025879], [222.29830905, 222.12113953, 221.83228412, ..., 223.30863953, 223.41940185, 223.32373834]])
array([[ 5.21690549e+00, 6.45233189e+00, 4.28736148e+00, ..., -7.67535665e-03, 2.96230910e-01, 6.57643155e-01], [ 5.85958500e+00, 7.19378302e+00, 4.83330769e+00, ..., 3.04038816e-01, 8.92241795e-01, 1.50811725e+00], [ 6.24440976e+00, 7.57659737e+00, 5.15674673e+00, ..., 8.14586967e-01, 1.33983860e+00, 2.18988652e+00], ..., [-1.28012018e+01, -1.25898482e+01, -1.16070538e+01, ..., -1.12421321e+01, -1.03435375e+01, -1.00345363e+01], [-1.48593788e+01, -1.43454499e+01, -1.44204061e+01, ..., -1.24229414e+01, -1.21902133e+01, -1.21718788e+01], [-1.66394198e+01, -1.72671524e+01, -1.83583902e+01, ..., -1.35123675e+01, -1.36290894e+01, -1.39687471e+01]])
array([[-1.81155913, 0.8694058 , 2.49319145, ..., 3.10682662, 2.55020093, 3.02169606], [-2.05249015, 0.89577768, 2.80360996, ..., 5.31881363, 5.53206144, 5.95132742], [-2.18795108, 0.83329454, 2.94953247, ..., 7.17671719, 7.14759429, 7.80193697], ..., [ 0.22072994, 0.38295555, 1.29442269, ..., -3.85792984, -3.70197581, -3.87864667], [ 1.65475638, 1.65964695, 1.2682968 , ..., -4.20229956, -4.02497673, -4.05167777], [ 1.72993965, 1.22095682, -0.36809105, ..., -4.2859621 , -4.48769978, -4.54756433]])
array([[5.18460489e-03, 5.71318029e-03, 6.25026499e-03, ..., 1.45200794e-02, 1.47219825e-02, 1.45176759e-02], [5.12465209e-03, 5.63651249e-03, 6.16680675e-03, ..., 1.44469754e-02, 1.45581439e-02, 1.43129969e-02], [5.09050213e-03, 5.58364058e-03, 6.12302346e-03, ..., 1.43362336e-02, 1.44757979e-02, 1.41760325e-02], ..., [3.38224516e-06, 3.32897992e-06, 3.25303418e-06, ..., 2.60991123e-06, 2.59358244e-06, 2.59286914e-06], [3.03594268e-06, 3.02025843e-06, 3.00076446e-06, ..., 2.52776013e-06, 2.52289206e-06, 2.53199057e-06], [2.90523181e-06, 2.98697467e-06, 3.05887918e-06, ..., 2.52401263e-06, 2.57112263e-06, 2.64342665e-06]])
# Quick sample plot
cross['t'].plot.contourf(levels=20)
/home/jthielen/miniconda3/envs/grib/lib/python3.8/site-packages/xarray/plot/utils.py:624: MatplotlibDeprecationWarning: The 'extend' parameter to Colorbar has no effect because it is overridden by the mappable; it is deprecated since 3.3 and will be removed two minor releases later. cbar = fig.colorbar(primitive, **cbar_kwargs)
<matplotlib.contour.QuadContourSet at 0x7fc709e4a8e0>