import numpy as np
import xarray as xr
import cartopy.crs as ccrs
from cartopy.io.shapereader import Reader
from cartopy.mpl.ticker import LongitudeFormatter
import matplotlib.pyplot as plt
## 导入关键库metpy
import metpy.calc as mpcalc ##计算天诊物理量的
from metpy.interpolate import cross_section ####关键
# 读取数据
"""
time:2020-4-17 12:00:00
var:[uwind,vwind,div,vor,tempreture,hgt, vertical velovity(垂直速度)]
level: [100,200,300,500,850,925,1000]
"""
ds=xr.open_dataset("D:\\DATA\\adata\\2020-4-17.nc")
ds
<xarray.Dataset> Dimensions: (longitude: 241, latitude: 241, level: 27, time: 1) Coordinates: * longitude (longitude) float32 70.0 70.25 70.5 70.75 ... 129.5 129.8 130.0 * latitude (latitude) float32 60.0 59.75 59.5 59.25 ... 0.75 0.5 0.25 0.0 * level (level) int32 100 125 150 175 200 225 ... 900 925 950 975 1000 * time (time) datetime64[ns] 2020-04-17T12:00:00 Data variables: d (time, level, latitude, longitude) float32 ... z (time, level, latitude, longitude) float32 ... t (time, level, latitude, longitude) float32 ... u (time, level, latitude, longitude) float32 ... v (time, level, latitude, longitude) float32 ... Attributes: Conventions: CF-1.6 history: 2022-04-17 05:47:25 GMT by grib_to_netcdf-2.24.3: /opt/ecmw...
array([ 70. , 70.25, 70.5 , ..., 129.5 , 129.75, 130. ], dtype=float32)
array([60. , 59.75, 59.5 , ..., 0.5 , 0.25, 0. ], dtype=float32)
array([ 100, 125, 150, 175, 200, 225, 250, 300, 350, 400, 450, 500, 550, 600, 650, 700, 750, 775, 800, 825, 850, 875, 900, 925, 950, 975, 1000])
array(['2020-04-17T12:00:00.000000000'], dtype='datetime64[ns]')
[1568187 values with dtype=float32]
[1568187 values with dtype=float32]
[1568187 values with dtype=float32]
[1568187 values with dtype=float32]
[1568187 values with dtype=float32]
# 利用 metpy 的CF解析 来准备使用的数据
ds = ds.metpy.parse_cf().squeeze()
#定义两个点当作起点和终点,两点确定一条直线
start =(32,118.5)# 南京经纬坐标
end =(22.5,108.5)# 南宁经纬坐标 粗略
# 获取截面数据
cross=cross_section(ds,start,end).set_coords(('latitude','longitude')) # 后面set_coords 是将lat/lon 转换为补充坐标 (里面latitude 对应dataset中的lat变量的名字)
cross
C:\Users\林子扬\AppData\Roaming\Python\Python39\site-packages\xarray\core\missing.py:562: FutureWarning: Passing method to Float64Index.get_loc is deprecated and will raise in a future version. Use index.get_indexer([item], method=...) instead. imin = index.get_loc(minval, method="nearest") C:\Users\林子扬\AppData\Roaming\Python\Python39\site-packages\xarray\core\missing.py:563: FutureWarning: Passing method to Float64Index.get_loc is deprecated and will raise in a future version. Use index.get_indexer([item], method=...) instead. imax = index.get_loc(maxval, method="nearest") C:\Users\林子扬\AppData\Roaming\Python\Python39\site-packages\xarray\core\missing.py:562: FutureWarning: Passing method to Float64Index.get_loc is deprecated and will raise in a future version. Use index.get_indexer([item], method=...) instead. imin = index.get_loc(minval, method="nearest") C:\Users\林子扬\AppData\Roaming\Python\Python39\site-packages\xarray\core\missing.py:563: FutureWarning: Passing method to Float64Index.get_loc is deprecated and will raise in a future version. Use index.get_indexer([item], method=...) instead. imax = index.get_loc(maxval, method="nearest") C:\Users\林子扬\AppData\Roaming\Python\Python39\site-packages\xarray\core\missing.py:562: FutureWarning: Passing method to Float64Index.get_loc is deprecated and will raise in a future version. Use index.get_indexer([item], method=...) instead. imin = index.get_loc(minval, method="nearest") C:\Users\林子扬\AppData\Roaming\Python\Python39\site-packages\xarray\core\missing.py:563: FutureWarning: Passing method to Float64Index.get_loc is deprecated and will raise in a future version. Use index.get_indexer([item], method=...) instead. imax = index.get_loc(maxval, method="nearest") C:\Users\林子扬\AppData\Roaming\Python\Python39\site-packages\xarray\core\missing.py:562: FutureWarning: Passing method to Float64Index.get_loc is deprecated and will raise in a future version. Use index.get_indexer([item], method=...) instead. imin = index.get_loc(minval, method="nearest") C:\Users\林子扬\AppData\Roaming\Python\Python39\site-packages\xarray\core\missing.py:563: FutureWarning: Passing method to Float64Index.get_loc is deprecated and will raise in a future version. Use index.get_indexer([item], method=...) instead. imax = index.get_loc(maxval, method="nearest") C:\Users\林子扬\AppData\Roaming\Python\Python39\site-packages\xarray\core\missing.py:562: FutureWarning: Passing method to Float64Index.get_loc is deprecated and will raise in a future version. Use index.get_indexer([item], method=...) instead. imin = index.get_loc(minval, method="nearest") C:\Users\林子扬\AppData\Roaming\Python\Python39\site-packages\xarray\core\missing.py:563: FutureWarning: Passing method to Float64Index.get_loc is deprecated and will raise in a future version. Use index.get_indexer([item], method=...) instead. imax = index.get_loc(maxval, method="nearest") C:\Users\林子扬\AppData\Roaming\Python\Python39\site-packages\xarray\core\missing.py:562: FutureWarning: Passing method to Float64Index.get_loc is deprecated and will raise in a future version. Use index.get_indexer([item], method=...) instead. imin = index.get_loc(minval, method="nearest") C:\Users\林子扬\AppData\Roaming\Python\Python39\site-packages\xarray\core\missing.py:563: FutureWarning: Passing method to Float64Index.get_loc is deprecated and will raise in a future version. Use index.get_indexer([item], method=...) instead. imax = index.get_loc(maxval, method="nearest") C:\Users\林子扬\AppData\Roaming\Python\Python39\site-packages\xarray\core\missing.py:562: FutureWarning: Passing method to Float64Index.get_loc is deprecated and will raise in a future version. Use index.get_indexer([item], method=...) instead. imin = index.get_loc(minval, method="nearest") C:\Users\林子扬\AppData\Roaming\Python\Python39\site-packages\xarray\core\missing.py:563: FutureWarning: Passing method to Float64Index.get_loc is deprecated and will raise in a future version. Use index.get_indexer([item], method=...) instead. imax = index.get_loc(maxval, method="nearest") C:\Users\林子扬\AppData\Roaming\Python\Python39\site-packages\xarray\core\missing.py:562: FutureWarning: Passing method to Float64Index.get_loc is deprecated and will raise in a future version. Use index.get_indexer([item], method=...) instead. imin = index.get_loc(minval, method="nearest") C:\Users\林子扬\AppData\Roaming\Python\Python39\site-packages\xarray\core\missing.py:563: FutureWarning: Passing method to Float64Index.get_loc is deprecated and will raise in a future version. Use index.get_indexer([item], method=...) instead. imax = index.get_loc(maxval, method="nearest") C:\Users\林子扬\AppData\Roaming\Python\Python39\site-packages\xarray\core\missing.py:562: FutureWarning: Passing method to Float64Index.get_loc is deprecated and will raise in a future version. Use index.get_indexer([item], method=...) instead. imin = index.get_loc(minval, method="nearest") C:\Users\林子扬\AppData\Roaming\Python\Python39\site-packages\xarray\core\missing.py:563: FutureWarning: Passing method to Float64Index.get_loc is deprecated and will raise in a future version. Use index.get_indexer([item], method=...) instead. imax = index.get_loc(maxval, method="nearest") C:\Users\林子扬\AppData\Roaming\Python\Python39\site-packages\xarray\core\missing.py:562: FutureWarning: Passing method to Float64Index.get_loc is deprecated and will raise in a future version. Use index.get_indexer([item], method=...) instead. imin = index.get_loc(minval, method="nearest") C:\Users\林子扬\AppData\Roaming\Python\Python39\site-packages\xarray\core\missing.py:563: FutureWarning: Passing method to Float64Index.get_loc is deprecated and will raise in a future version. Use index.get_indexer([item], method=...) instead. imax = index.get_loc(maxval, method="nearest")
<xarray.Dataset> Dimensions: (level: 27, index: 100) Coordinates: * level (level) int32 100 125 150 175 200 225 ... 900 925 950 975 1000 time datetime64[ns] 2020-04-17T12:00:00 metpy_crs object Projection: latitude_longitude longitude (index) float64 118.5 118.4 118.3 118.2 ... 108.7 108.6 108.5 latitude (index) float64 32.0 31.91 31.82 31.72 ... 22.8 22.7 22.6 22.5 * index (index) int32 0 1 2 3 4 5 6 7 8 9 ... 91 92 93 94 95 96 97 98 99 Data variables: d (level, index) float64 -2.646e-05 -2.477e-05 ... 1.617e-05 z (level, index) float64 1.61e+05 1.61e+05 ... 936.3 935.5 t (level, index) float64 208.8 208.7 208.5 ... 298.0 298.0 297.9 u (level, index) float64 20.56 20.37 20.16 ... -1.055 -0.9703 v (level, index) float64 -8.102 -7.789 -7.513 ... 1.928 2.232 2.522 Attributes: Conventions: CF-1.6 history: 2022-04-17 05:47:25 GMT by grib_to_netcdf-2.24.3: /opt/ecmw...
array([ 100, 125, 150, 175, 200, 225, 250, 300, 350, 400, 450, 500, 550, 600, 650, 700, 750, 775, 800, 825, 850, 875, 900, 925, 950, 975, 1000])
array('2020-04-17T12:00:00.000000000', dtype='datetime64[ns]')
array(<metpy.plots.mapping.CFProjection object at 0x0000010F9F0C4D90>, dtype=object)
array([118.5 , 118.3897333 , 118.27968583, 118.1698566 , 118.06024464, 117.95084893, 117.84166852, 117.7327024 , 117.6239496 , 117.51540914, 117.40708004, 117.29896133, 117.19105203, 117.08335118, 116.97585781, 116.86857095, 116.76148964, 116.65461291, 116.54793981, 116.44146938, 116.33520066, 116.2291327 , 116.12326456, 116.01759529, 115.91212393, 115.80684954, 115.70177119, 115.59688794, 115.49219884, 115.38770297, 115.28339939, 115.17928717, 115.07536539, 114.97163312, 114.86808944, 114.76473342, 114.66156416, 114.55858073, 114.45578222, 114.35316773, 114.25073633, 114.14848713, 114.04641923, 113.94453171, 113.84282369, 113.74129426, 113.63994254, 113.53876762, 113.43776863, 113.33694466, 113.23629485, 113.1358183 , 113.03551414, 112.93538148, 112.83541946, 112.7356272 , 112.63600383, 112.53654848, 112.43726029, 112.33813839, 112.23918192, 112.14039003, 112.04176185, 111.94329654, 111.84499323, 111.74685109, 111.64886926, 111.55104691, 111.45338318, 111.35587724, 111.25852826, 111.16133538, 111.0642978 , 110.96741466, 110.87068515, 110.77410844, 110.67768371, 110.58141013, 110.48528688, 110.38931315, 110.29348813, 110.197811 , 110.10228095, 110.00689717, 109.91165887, 109.81656523, 109.72161546, 109.62680876, 109.53214433, 109.43762137, 109.3432391 , 109.24899673, 109.15489346, 109.06092852, 108.96710112, 108.87341049, 108.77985583, 108.68643638, 108.59315136, 108.5 ])
array([32. , 31.90803332, 31.81596982, 31.72381003, 31.63155447, 31.53920366, 31.44675812, 31.35421838, 31.26158494, 31.16885833, 31.07603905, 30.98312761, 30.89012452, 30.79703028, 30.70384539, 30.61057035, 30.51720567, 30.42375182, 30.33020932, 30.23657864, 30.14286027, 30.0490547 , 29.95516241, 29.86118389, 29.76711961, 29.67297004, 29.57873567, 29.48441697, 29.39001439, 29.29552843, 29.20095952, 29.10630815, 29.01157478, 28.91675985, 28.82186384, 28.72688719, 28.63183035, 28.53669379, 28.44147794, 28.34618326, 28.25081018, 28.15535916, 28.05983062, 27.96422502, 27.86854279, 27.77278436, 27.67695016, 27.58104063, 27.4850562 , 27.38899728, 27.29286432, 27.19665772, 27.10037792, 27.00402533, 26.90760036, 26.81110344, 26.71453498, 26.61789539, 26.52118508, 26.42440445, 26.32755393, 26.2306339 , 26.13364477, 26.03658695, 25.93946083, 25.84226682, 25.7450053 , 25.64767667, 25.55028133, 25.45281966, 25.35529205, 25.2576989 , 25.16004058, 25.06231749, 24.96453 , 24.86667849, 24.76876335, 24.67078494, 24.57274366, 24.47463986, 24.37647394, 24.27824624, 24.17995715, 24.08160704, 23.98319626, 23.88472519, 23.78619419, 23.68760362, 23.58895383, 23.4902452 , 23.39147807, 23.29265281, 23.19376976, 23.09482929, 22.99583174, 22.89677745, 22.79766679, 22.6985001 , 22.59927772, 22.5 ])
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([[-2.64602149e-05, -2.47677592e-05, -2.45206402e-05, ..., -7.91492525e-06, -1.29256069e-05, -1.68228325e-05], [-2.47284993e-06, -5.67660785e-06, -8.62368341e-06, ..., 5.57984866e-06, 1.28142093e-05, 1.82648291e-05], [-6.74914190e-07, -4.25844900e-06, -7.29804017e-06, ..., 5.91720827e-07, 2.54753858e-06, 2.98796067e-06], ..., [ 2.92095729e-06, 3.13938771e-06, 6.52762924e-06, ..., 2.30864162e-05, 2.61257931e-05, 3.15315847e-05], [ 1.71488819e-06, 2.65803434e-06, 1.01399797e-05, ..., -1.21375464e-05, 1.33271720e-05, 4.54013716e-05], [ 7.60005651e-06, 5.89297184e-06, 9.96018467e-06, ..., -5.08654864e-06, 4.24496529e-06, 1.61653770e-05]])
array([[161007.171875 , 161031.74569464, 161055.51520499, ..., 162638.28136014, 162645.09635625, 162652.65625 ], [147638.53125 , 147669.38460088, 147700.24871327, ..., 149907.83606571, 149921.77490812, 149935.71875 ], [136602.03125 , 136642.39499553, 136681.95604092, ..., 139263.9374143 , 139282.94240193, 139301.21875 ], ..., [ 5609.765625 , 5611.2704807 , 5613.58366013, ..., 5335.00224868, 5335.41654392, 5335.1015625 ], [ 3429.9296875 , 3431.95075369, 3433.96806292, ..., 3109.33382225, 3109.45277794, 3110.3203125 ], [ 1295.0390625 , 1296.18066774, 1298.13436833, ..., 937.10002886, 936.28574032, 935.4765625 ]])
array([[208.80960083, 208.65375398, 208.51333645, ..., 197.42491273, 197.35614972, 197.27394104], [209.70132446, 209.58875079, 209.47733824, ..., 201.3305207 , 201.18637954, 201.06286621], [211.6289978 , 211.4823965 , 211.33708054, ..., 205.91079468, 205.87446379, 205.84599304], ..., [290.08087158, 290.11454328, 290.09935647, ..., 295.03556124, 295.23563988, 295.45025635], [291.81881714, 291.84462829, 291.8571397 , ..., 296.58244337, 296.54670653, 296.43307495], [293.27975464, 293.28087533, 293.30141362, ..., 297.96070672, 297.96718498, 297.86935425]])
array([[20.55778885, 20.36864167, 20.15963961, ..., 15.67251082, 15.79578983, 15.90855694], [21.22517395, 21.43654134, 21.65306113, ..., 23.07997192, 23.12642718, 23.10971069], [35.05789185, 35.05887064, 35.08829263, ..., 39.42116625, 38.97771551, 38.53622437], ..., [ 0.68424225, 0.50375853, 0.34502918, ..., -3.18127867, -3.31424769, -3.35707283], [ 0.63402367, 0.55150583, 0.42993818, ..., -2.63122501, -2.48435418, -2.3289032 ], [ 0.15429878, -0.07266681, -0.30530336, ..., -1.14924666, -1.05460871, -0.97034454]])
array([[ -8.1020298 , -7.78900485, -7.51282977, ..., 1.74202089, 2.04806985, 2.37069893], [-13.40801525, -13.45189351, -13.47726749, ..., 3.25847668, 3.3269794 , 3.38112783], [-13.57066917, -13.33617827, -13.09662804, ..., 6.11318909, 6.45477697, 6.8030324 ], ..., [ -4.3967123 , -4.50796503, -4.53491603, ..., 8.50487644, 8.85123736, 9.26379681], [ -2.44978762, -2.57459269, -2.56955707, ..., 6.23559953, 6.71385564, 7.27251244], [ 0.03808606, -0.19367437, -0.22804939, ..., 1.92817851, 2.23212264, 2.52226329]])
# 选取绘图需要的气象要素,本例选取的是位势高度,散度,正常风(u,v合成风),潜在温度(位温:θ)
# 位势高度 hgt
hgt=cross['z']
# 散度 div
div =cross['d']
# 正常风 n_wind 注:t_wind 是切向风
cross['t_wind'],cross['n_wind']=mpcalc.cross_section_components(cross['u'],cross['v'])
# 潜在温度
cross['P_t']=mpcalc.potential_temperature(cross['level'],cross['t'])
cross
<xarray.Dataset> Dimensions: (level: 27, index: 100) Coordinates: * level (level) int32 100 125 150 175 200 225 ... 900 925 950 975 1000 time datetime64[ns] 2020-04-17T12:00:00 metpy_crs object Projection: latitude_longitude longitude (index) float64 118.5 118.4 118.3 118.2 ... 108.7 108.6 108.5 latitude (index) float64 32.0 31.91 31.82 31.72 ... 22.8 22.7 22.6 22.5 * index (index) int32 0 1 2 3 4 5 6 7 8 9 ... 91 92 93 94 95 96 97 98 99 Data variables: d (level, index) float64 -2.646e-05 -2.477e-05 ... 1.617e-05 z (level, index) float64 1.61e+05 1.61e+05 ... 936.3 935.5 t (level, index) float64 208.8 208.7 208.5 ... 298.0 298.0 297.9 u (level, index) float64 20.56 20.37 20.16 ... -1.055 -0.9703 v (level, index) float64 -8.102 -7.789 -7.513 ... 1.928 2.232 2.522 t_wind (level, index) float64 -9.04 -9.124 -9.167 ... -0.8058 -1.069 n_wind (level, index) float64 20.16 19.81 19.46 ... -2.182 -2.333 -2.482 P_t (level, index) float64 <Quantity([[403.14822209 402.84732894 4... Attributes: Conventions: CF-1.6 history: 2022-04-17 05:47:25 GMT by grib_to_netcdf-2.24.3: /opt/ecmw...
array([ 100, 125, 150, 175, 200, 225, 250, 300, 350, 400, 450, 500, 550, 600, 650, 700, 750, 775, 800, 825, 850, 875, 900, 925, 950, 975, 1000])
array('2020-04-17T12:00:00.000000000', dtype='datetime64[ns]')
array(<metpy.plots.mapping.CFProjection object at 0x0000010F9F0C4D90>, dtype=object)
array([118.5 , 118.3897333 , 118.27968583, 118.1698566 , 118.06024464, 117.95084893, 117.84166852, 117.7327024 , 117.6239496 , 117.51540914, 117.40708004, 117.29896133, 117.19105203, 117.08335118, 116.97585781, 116.86857095, 116.76148964, 116.65461291, 116.54793981, 116.44146938, 116.33520066, 116.2291327 , 116.12326456, 116.01759529, 115.91212393, 115.80684954, 115.70177119, 115.59688794, 115.49219884, 115.38770297, 115.28339939, 115.17928717, 115.07536539, 114.97163312, 114.86808944, 114.76473342, 114.66156416, 114.55858073, 114.45578222, 114.35316773, 114.25073633, 114.14848713, 114.04641923, 113.94453171, 113.84282369, 113.74129426, 113.63994254, 113.53876762, 113.43776863, 113.33694466, 113.23629485, 113.1358183 , 113.03551414, 112.93538148, 112.83541946, 112.7356272 , 112.63600383, 112.53654848, 112.43726029, 112.33813839, 112.23918192, 112.14039003, 112.04176185, 111.94329654, 111.84499323, 111.74685109, 111.64886926, 111.55104691, 111.45338318, 111.35587724, 111.25852826, 111.16133538, 111.0642978 , 110.96741466, 110.87068515, 110.77410844, 110.67768371, 110.58141013, 110.48528688, 110.38931315, 110.29348813, 110.197811 , 110.10228095, 110.00689717, 109.91165887, 109.81656523, 109.72161546, 109.62680876, 109.53214433, 109.43762137, 109.3432391 , 109.24899673, 109.15489346, 109.06092852, 108.96710112, 108.87341049, 108.77985583, 108.68643638, 108.59315136, 108.5 ])
array([32. , 31.90803332, 31.81596982, 31.72381003, 31.63155447, 31.53920366, 31.44675812, 31.35421838, 31.26158494, 31.16885833, 31.07603905, 30.98312761, 30.89012452, 30.79703028, 30.70384539, 30.61057035, 30.51720567, 30.42375182, 30.33020932, 30.23657864, 30.14286027, 30.0490547 , 29.95516241, 29.86118389, 29.76711961, 29.67297004, 29.57873567, 29.48441697, 29.39001439, 29.29552843, 29.20095952, 29.10630815, 29.01157478, 28.91675985, 28.82186384, 28.72688719, 28.63183035, 28.53669379, 28.44147794, 28.34618326, 28.25081018, 28.15535916, 28.05983062, 27.96422502, 27.86854279, 27.77278436, 27.67695016, 27.58104063, 27.4850562 , 27.38899728, 27.29286432, 27.19665772, 27.10037792, 27.00402533, 26.90760036, 26.81110344, 26.71453498, 26.61789539, 26.52118508, 26.42440445, 26.32755393, 26.2306339 , 26.13364477, 26.03658695, 25.93946083, 25.84226682, 25.7450053 , 25.64767667, 25.55028133, 25.45281966, 25.35529205, 25.2576989 , 25.16004058, 25.06231749, 24.96453 , 24.86667849, 24.76876335, 24.67078494, 24.57274366, 24.47463986, 24.37647394, 24.27824624, 24.17995715, 24.08160704, 23.98319626, 23.88472519, 23.78619419, 23.68760362, 23.58895383, 23.4902452 , 23.39147807, 23.29265281, 23.19376976, 23.09482929, 22.99583174, 22.89677745, 22.79766679, 22.6985001 , 22.59927772, 22.5 ])
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([[-2.64602149e-05, -2.47677592e-05, -2.45206402e-05, ..., -7.91492525e-06, -1.29256069e-05, -1.68228325e-05], [-2.47284993e-06, -5.67660785e-06, -8.62368341e-06, ..., 5.57984866e-06, 1.28142093e-05, 1.82648291e-05], [-6.74914190e-07, -4.25844900e-06, -7.29804017e-06, ..., 5.91720827e-07, 2.54753858e-06, 2.98796067e-06], ..., [ 2.92095729e-06, 3.13938771e-06, 6.52762924e-06, ..., 2.30864162e-05, 2.61257931e-05, 3.15315847e-05], [ 1.71488819e-06, 2.65803434e-06, 1.01399797e-05, ..., -1.21375464e-05, 1.33271720e-05, 4.54013716e-05], [ 7.60005651e-06, 5.89297184e-06, 9.96018467e-06, ..., -5.08654864e-06, 4.24496529e-06, 1.61653770e-05]])
array([[161007.171875 , 161031.74569464, 161055.51520499, ..., 162638.28136014, 162645.09635625, 162652.65625 ], [147638.53125 , 147669.38460088, 147700.24871327, ..., 149907.83606571, 149921.77490812, 149935.71875 ], [136602.03125 , 136642.39499553, 136681.95604092, ..., 139263.9374143 , 139282.94240193, 139301.21875 ], ..., [ 5609.765625 , 5611.2704807 , 5613.58366013, ..., 5335.00224868, 5335.41654392, 5335.1015625 ], [ 3429.9296875 , 3431.95075369, 3433.96806292, ..., 3109.33382225, 3109.45277794, 3110.3203125 ], [ 1295.0390625 , 1296.18066774, 1298.13436833, ..., 937.10002886, 936.28574032, 935.4765625 ]])
array([[208.80960083, 208.65375398, 208.51333645, ..., 197.42491273, 197.35614972, 197.27394104], [209.70132446, 209.58875079, 209.47733824, ..., 201.3305207 , 201.18637954, 201.06286621], [211.6289978 , 211.4823965 , 211.33708054, ..., 205.91079468, 205.87446379, 205.84599304], ..., [290.08087158, 290.11454328, 290.09935647, ..., 295.03556124, 295.23563988, 295.45025635], [291.81881714, 291.84462829, 291.8571397 , ..., 296.58244337, 296.54670653, 296.43307495], [293.27975464, 293.28087533, 293.30141362, ..., 297.96070672, 297.96718498, 297.86935425]])
array([[20.55778885, 20.36864167, 20.15963961, ..., 15.67251082, 15.79578983, 15.90855694], [21.22517395, 21.43654134, 21.65306113, ..., 23.07997192, 23.12642718, 23.10971069], [35.05789185, 35.05887064, 35.08829263, ..., 39.42116625, 38.97771551, 38.53622437], ..., [ 0.68424225, 0.50375853, 0.34502918, ..., -3.18127867, -3.31424769, -3.35707283], [ 0.63402367, 0.55150583, 0.42993818, ..., -2.63122501, -2.48435418, -2.3289032 ], [ 0.15429878, -0.07266681, -0.30530336, ..., -1.14924666, -1.05460871, -0.97034454]])
array([[ -8.1020298 , -7.78900485, -7.51282977, ..., 1.74202089, 2.04806985, 2.37069893], [-13.40801525, -13.45189351, -13.47726749, ..., 3.25847668, 3.3269794 , 3.38112783], [-13.57066917, -13.33617827, -13.09662804, ..., 6.11318909, 6.45477697, 6.8030324 ], ..., [ -4.3967123 , -4.50796503, -4.53491603, ..., 8.50487644, 8.85123736, 9.26379681], [ -2.44978762, -2.57459269, -2.56955707, ..., 6.23559953, 6.71385564, 7.27251244], [ 0.03808606, -0.19367437, -0.22804939, ..., 1.92817851, 2.23212264, 2.52226329]])
array([[ -9.04018014, -9.12368286, -9.16723022, ..., -12.42647373, -12.72854711, -13.03469063], [ -5.80901829, -5.92952014, -6.06664004, ..., -18.78415454, -18.86525731, -18.8911473 ], [-15.58845678, -15.75304783, -15.94151745, ..., -32.46655423, -32.38814304, -32.31579344], ..., [ 2.58359401, 2.79043252, 2.92279196, ..., -3.66900983, -3.81599029, -4.07370904], [ 1.25876029, 1.40500591, 1.48843125, ..., -2.47635747, -2.91566314, -3.41729917], [ -0.13697327, 0.18733452, 0.37774101, ..., -0.52570979, -0.80582805, -1.06887944]])
array([[20.16285476, 19.80678094, 19.463185 , ..., 9.70798551, 9.57526266, 9.42333474], [24.42413128, 24.60324236, 24.77272036, ..., 13.80066348, 13.78413916, 13.73372882], [34.20846179, 34.04143865, 33.8906767 , ..., 23.18021324, 22.62597275, 22.06833325], ..., [ 3.62274876, 3.57617222, 3.48450796, ..., -8.30613171, -8.64678314, -8.97177596], [ 2.19521478, 2.22680143, 2.13823356, ..., -6.29870623, -6.5381023 , -6.82900385], [ 0.08060388, 0.08772688, -0.05028317, ..., -2.18226246, -2.33349785, -2.48211148]])
Magnitude | [[403.1482220916498 402.84732893584953 402.576225120726 ... |
---|---|
Units | kelvin |
plt.rcParams['font.sans-serif'] = ['SimHei'] ###防止无法显示中文并设置黑体
plt.rcParams['axes.unicode_minus'] = False ###用来正常显示负号
## 绘图部分
fig=plt.figure(figsize=(16,9))
ax=fig.subplots(1,1)
# 位势高度
denghgtlines=ax.contour(cross['longitude'],cross['level'],hgt,colors='k',linestyles='--')
plt.clabel(denghgtlines,inline=True,fontsize=8,fmt='%.0f')
# 散度
colorbar= ax.contourf(cross['longitude'],cross['level'],div*10**5,levels=np.linspace(div.data.min()*10**5,div.data.max()*10**5,25),cmap='bwr')
plt.colorbar(colorbar,extendrect='True',pad=0.01,fraction=0.04, shrink=1)
# 位温
denglines=ax.contour(cross['longitude'],cross['level'],cross['P_t'],levels=np.linspace(cross['P_t'].data.min(),cross['P_t'].data.max(),15),colors='g',linestyles='-')
plt.clabel(denglines,inline=True,fontsize=8,fmt='%.0f')
# 风羽图
ax.barbs(cross['longitude'][::4],cross['level'][::2],cross['t_wind'][::2,::4],cross['n_wind'][::2,::4],pivot='middle',length=6,barb_increments=dict(half=2,full=4,flag=20),color='k')
# 设置y轴以对数显示
ax.invert_yaxis()
ax.set_yscale('symlog')
ax.set_yticklabels(np.arange(1000,99,-100))
ax.set_yticks(np.arange(1000,99,-100))
ax.set_ylim(1000,100)
# # 暴力显示
# ax.set_yticks([1000,925,850,500,300,200,100],['1000','925','850','500','300','200','100'])
ax.set_ylabel('hPa')
# 设置x轴
ax.set_xticks(np.arange(108.5,119,1))
lon_formatter = LongitudeFormatter(zero_direction_label=False)
ax.xaxis.set_major_formatter(lon_formatter)
ax.set_xlabel('lon')
fig.suptitle('南京-南宁剖面图')
fig.savefig('../南京-南宁剖面图.png')
D:\Temp\ipykernel_34292\1699892978.py:20: UserWarning: FixedFormatter should only be used together with FixedLocator ax.set_yticklabels(np.arange(1000,99,-100))
# 可以绘制一个子图来显示是那里到那里的剖面图,就像开头那样的剖面图一样
## 绘图部分
fig=plt.figure(figsize=(16,9))
ax=fig.subplots(1,1)
# 位势高度
denghgtlines=ax.contour(cross['longitude'],cross['level'],hgt,colors='k',linestyles='--')
plt.clabel(denghgtlines,inline=True,fontsize=8,fmt='%.0f')
# 散度
colorbar= ax.contourf(cross['longitude'],cross['level'],div*10**5,levels=np.linspace(div.data.min()*10**5,div.data.max()*10**5,25),cmap='bwr')
plt.colorbar(colorbar,extendrect='True',pad=0.01,fraction=0.04, shrink=1)
# 位温
denglines=ax.contour(cross['longitude'],cross['level'],cross['P_t'],levels=np.linspace(cross['P_t'].data.min(),cross['P_t'].data.max(),15),colors='g',linestyles='-')
plt.clabel(denglines,inline=True,fontsize=8,fmt='%.0f')
# 风羽图
ax.barbs(cross['longitude'][::4],cross['level'][::2],cross['t_wind'][::2,::4],cross['n_wind'][::2,::4],pivot='middle',length=6,barb_increments=dict(half=2,full=4,flag=20),color='k')
# 设置y轴以对数显示
ax.invert_yaxis()
ax.set_yscale('symlog')
ax.set_yticklabels(np.arange(1000,50,-100))
ax.set_yticks(np.arange(1000,50,-100))
ax.set_ylim(1000,100)
# # 暴力显示
# ax.set_yticks([1000,925,850,500,300,200,100],['1000','925','850','500','300','200','100'])
ax.set_ylabel('hPa')
# 设置x轴
ax.set_xticks(np.arange(108.5,119,1))
lon_formatter = LongitudeFormatter(zero_direction_label=False)
ax.xaxis.set_major_formatter(lon_formatter)
ax.set_xlabel('lon')
## 地理子图
proj = ccrs.PlateCarree(central_longitude=113)
ax1=fig.add_axes([-0.05,0.62,0.5,0.25],projection=proj)
ax1.coastlines('50m')
ax1.add_geometries(Reader('D:\\maplist\\China_province\\bou2_4l.shp').geometries(), ccrs.PlateCarree(),
facecolor='none', edgecolor='gray', linewidth=0.8) ###添加省界
ax1.set_extent([70,130,0,60],ccrs.PlateCarree())
# 绘制500hPa等高线图
ax1.contour(ds['longitude'],ds['latitude'],ds['z'].loc[500,:,:],levels=np.arange(ds['z'].data.min(),ds['z'].data.max(),400),colors='b', linestyles='-', transform=ccrs.PlateCarree())
# 绘制南京和南宁的点,及其中间的连线
ax1.scatter(118.5,32,color='r',transform=ccrs.PlateCarree())
ax1.scatter(108.5,22.5,color='r',transform=ccrs.PlateCarree())
ax1.plot(cross['longitude'],cross['latitude'],color='g',transform=ccrs.PlateCarree())
fig.suptitle('南京-南宁剖面图带子图')
fig.savefig('../南京-南宁剖面图子图.png')
D:\Temp\ipykernel_34292\2887888344.py:21: UserWarning: FixedFormatter should only be used together with FixedLocator ax.set_yticklabels(np.arange(1000,50,-100))