Python 关于metpy截面坐标的问题

Python 关于metpy截面坐标的问题,python,python-xarray,cartopy,metpy,Python,Python Xarray,Cartopy,Metpy,我按照代码在这个站点上绘制了横截面图。 () 在本例中,运行以下代码将生成此结果(交叉)。 cross=横截面(数据、开始、结束)。设置坐标(('lat','lon')) 但是,与示例不同的是,运行横截面代码后结果值的x、y坐标已更改。经纬度是固定的。 我不明白为什么这个结果是这样的 我的代码 我的代码必须根据等压层划分的nc文件进行分析,因此我将为每个层划分的值合并在一起。 像这样, tmp1 = NC['TMP_1000mb'] tmp2 = NC['TMP_975mb'] ... tmp

我按照代码在这个站点上绘制了横截面图。 ()

在本例中,运行以下代码将生成此结果(交叉)。
cross=横截面(数据、开始、结束)。设置坐标(('lat','lon'))

但是,与示例不同的是,运行横截面代码后结果值的x、y坐标已更改。经纬度是固定的。 我不明白为什么这个结果是这样的

我的代码

我的代码必须根据等压层划分的nc文件进行分析,因此我将为每个层划分的值合并在一起。 像这样,

tmp1 = NC['TMP_1000mb']
tmp2 = NC['TMP_975mb']
...
tmp23 = NC['TMP_70mb']
tmp24 = NC['TMP_50mb']

TMP = xr.concat([tmp1,tmp2],'isobaric')
TMP = xr.concat([TMP,tmp3],'isobaric')
...
TMP = xr.concat([TMP,tmp23],'isobaric')
TMP = xr.concat([TMP,tmp24],'isobaric')

TMP['isobaric']=p_list

NC['Temperature'] = TMP
所以,我打印NC。结果是

<xarray.Dataset>
Dimensions:            (isobaric: 24, x: 602, y: 781)
Coordinates:
    * y                  (y) float64 0.0 1.5e+03 3e+03 ... 1.168e+06 1.17e+06
    * x                  (x) float64 0.0 1.5e+03 3e+03 ... 9e+05 9.015e+05
    latitude           (y, x) float64 32.26 32.26 32.26 ... 42.94 42.94 42.93
    longitude          (y, x) float64 121.8 121.9 121.9 ... 132.5 132.5 132.5
    time               datetime64[ns] 2019-04-04
    metpy_crs          object Projection: latitude_longitude
    * isobaric           (isobaric) float64 1e+03 975.0 950.0 ... 100.0 70.0 50.0
Data variables:
    ...
    ...
    Temperature        (isobaric, y, x) float32 282.87515 282.87515 ... nan nan

Attributes:
    Conventions:          CF-1.0
    History:              created by wgrib2
    GRIB2_grid_template:  30

尺寸:(等压:24,x:602,y:781)
协调:
*y(y)浮动64 0.01.5e+03 3e+03。。。1.168e+06 1.17e+06
*x(x)浮动64 0.01.5e+03 3e+03。。。9e+05 9.015 E+05
纬度(y,x)浮动64 32.26 32.26 32.26。。。42.94 42.94 42.93
经度(y,x)浮动64121.8121.9121.9。。。132.5 132.5 132.5
时间日期时间64[ns]2019-04-04
metpy_crs对象投影:经纬度
*等压浮子64 1e+03 975.0 950.0。。。100.0 70.0 50.0
数据变量:
...
...
温度(等压,y,x)32 282.87515 282.87515。。。楠楠
属性:
公约:CF-1.0
历史记录:由wgrib2创建
GRIB2_网格_模板:30
但是,当我运行“横截面”时,x、y将更改为“开始”和“结束”,并且原始经度和纬度是固定的

start = (37.5, 126.63)
end = (37.8 ,128.86)
cross = cross_section(NC, start, end)
#I didn't write .set_codes here because unlike the example, coordinates are given 
#latitude and longitude.

print(cross)
<xarray.Dataset>
Dimensions:            (index: 100, isobaric: 24)
Coordinates:
    latitude           (index) float64 32.26 32.26 32.26 ... 32.26 32.26 32.26
    longitude          (index) float64 121.8 121.8 121.8 ... 121.8 121.8 121.8
    time               datetime64[ns] 2019-04-04
    metpy_crs          object Projection: latitude_longitude
    x                  (index) float64 126.6 126.7 126.7 ... 128.8 128.8 128.9
    y                  (index) float64 37.5 37.5 37.51 37.51 ... 37.79 37.8 37.8
  * index              (index) int32 0 1 2 3 4 5 6 7 ... 92 93 94 95 96 97 98 99
  * isobaric           (isobaric) float64 1e+03 975.0 950.0 ... 100.0 70.0 50.0
Data variables:
    ...
    ...
    Temperature        (isobaric, index) float64 282.9 282.9 ... 209.6 209.6
Attributes:
    Conventions:          CF-1.0
    History:              created by wgrib2
    GRIB2_grid_template:  30
start=(37.5126.63)
完=(37.8128.86)
横截面=横截面(NC、起点、终点)
#我没有写。在这里设置_代码,因为与示例不同,坐标是给定的
#经纬度。
打印(交叉)
尺寸:(指数:100,等压:24)
协调:
纬度(指数)浮动64 32.26 32.26 32.26。。。32.26 32.26 32.26
经度(指数)浮动64121.8121.8121.8121.8。。。121.8 121.8 121.8
时间日期时间64[ns]2019-04-04
metpy_crs对象投影:经纬度
x(指数)浮动64 126.6 126.7 126.7。。。128.8 128.8 128.9
y(指数)浮动64 37.5 37.5 37.51 37.51。。。37.79 37.8 37.8
*索引(索引)int32 0 1 2 3 4 5 6 7。。。92 93 94 95 96 97 98 99
*等压浮子64 1e+03 975.0 950.0。。。100.0 70.0 50.0
数据变量:
...
...
温度(等压,指数)浮动64 282.9 282.9。。。209.6 209.6
属性:
公约:CF-1.0
历史记录:由wgrib2创建
GRIB2_网格_模板:30
我希望保持x,y,并将纬度经度保持在示例中的开始和结束范围内。 我真的不明白为什么会这样

谢谢你的关注

为了便于参考,我附上了数据源和初始数据。 数据源:来自KMA的LDAPS数据

完整NC数据(初始数据)


尺寸:(时间:1,x:602,y:781)
协调:
*y(y)浮动64 0.01.5e+03 3e+03。。。1.168e+06 1.17e+06
*x(x)浮动64 0.01.5e+03 3e+03。。。9e+05 9.015 E+05
纬度(y,x)浮动64。。。
经度(y,x)浮动64。。。
*时间日期时间64[ns]2019-04-04
数据变量:
DZDT_1000mb(时间,y,x)浮动32。。。
DZDT975MB(时间,y,x)浮动32。。。
...
DZDT_70mb(时间,y,x)浮动32。。。
DZDT_50mb(时间,y,x)浮动32。。。
UGRD_1000mb(时间,y,x)浮动32。。。
VGRD_1000mb(时间,y,x)浮动32。。。
UGRD_975mb(时间,y,x)浮点32。。。
VGRD975MB(时间,y,x)浮动32。。。
...
UGRD_70mb(时间,y,x)浮动32。。。
VGRD_70mb(时间,y,x)浮动32。。。
UGRD_50mb(时间,y,x)浮点32。。。
VGRD_50mb(时间,y,x)浮动32。。。
HGT_1000mb(时间,y,x)浮动32。。。
HGT_975mb(时间,y,x)浮动32。。。
...
HGT_70mb(时间,y,x)浮动32。。。
HGT_50mb(时间,y,x)浮点32。。。
TMP_1000mb(时间,y,x)浮动32。。。
TMP_975mb(时间,y,x)浮动32。。。
...
TMP_70mb(时间,y,x)浮动32。。。
TMP_50mb(时间,y,x)浮点32。。。
var0_1_194_1000mb(时间,y,x)浮动32。。。
var0_1_194_975mb(时间,y,x)浮点32。。。
...
var0_1_194_70mb(时间,y,x)浮点32。。。
var0_1_194_50mb(时间,y,x)浮点32。。。
RH_1000mb(时间,y,x)浮动32。。。
RH_975mb(时间,y,x)浮动32。。。
...
RH_70mb(时间,y,x)浮动32。。。
RH_50mb(时间,y,x)浮动32。。。
属性:
公约:CF-1.0
历史记录:由wgrib2创建
GRIB2_网格_模板:30

请注意,数据集中从
.metpy.parse_cf()
中标识的
metpy\u crs
被指定为
投影:经纬度
,这是不正确的,因为您的数据集在投影网格空间中具有二维经纬度坐标和1D y/x坐标。这可能是由于数据集的元数据不符合CF而触发的。现在,正因为如此,MetPy将你的
x
坐标视为经度,将
y
视为纬度(注意这些坐标中的范围),即使它们不是。这里的结果肯定远远不够理想(没有错误消息或任何东西),因此我建议在MetPy的问题跟踪程序上提交一个问题


要直接解决问题,您需要手动指定数据的CRS/投影。要执行此操作(在MetPy v1.0及更高版本中),请使用而不是使用
parse_cf
(仅适用于符合cf的数据集)。

请注意,数据集中从
识别的
MetPy_crs
。MetPy.parse_cf()
作为
投影:纬度经度
给出,而不是corr>
start = (37.5, 126.63)
end = (37.8 ,128.86)
cross = cross_section(NC, start, end)
#I didn't write .set_codes here because unlike the example, coordinates are given 
#latitude and longitude.

print(cross)
<xarray.Dataset>
Dimensions:            (index: 100, isobaric: 24)
Coordinates:
    latitude           (index) float64 32.26 32.26 32.26 ... 32.26 32.26 32.26
    longitude          (index) float64 121.8 121.8 121.8 ... 121.8 121.8 121.8
    time               datetime64[ns] 2019-04-04
    metpy_crs          object Projection: latitude_longitude
    x                  (index) float64 126.6 126.7 126.7 ... 128.8 128.8 128.9
    y                  (index) float64 37.5 37.5 37.51 37.51 ... 37.79 37.8 37.8
  * index              (index) int32 0 1 2 3 4 5 6 7 ... 92 93 94 95 96 97 98 99
  * isobaric           (isobaric) float64 1e+03 975.0 950.0 ... 100.0 70.0 50.0
Data variables:
    ...
    ...
    Temperature        (isobaric, index) float64 282.9 282.9 ... 209.6 209.6
Attributes:
    Conventions:          CF-1.0
    History:              created by wgrib2
    GRIB2_grid_template:  30
<xarray.Dataset>
Dimensions:            (time: 1, x: 602, y: 781)
Coordinates:
* y                  (y) float64 0.0 1.5e+03 3e+03 ... 1.168e+06 1.17e+06
* x                  (x) float64 0.0 1.5e+03 3e+03 ... 9e+05 9.015e+05
latitude           (y, x) float64 ...
longitude          (y, x) float64 ...
* time               (time) datetime64[ns] 2019-04-04
Data variables:
DZDT_1000mb        (time, y, x) float32 ...
DZDT_975mb         (time, y, x) float32 ...
...
DZDT_70mb          (time, y, x) float32 ...
DZDT_50mb          (time, y, x) float32 ...
UGRD_1000mb        (time, y, x) float32 ...
VGRD_1000mb        (time, y, x) float32 ...
UGRD_975mb         (time, y, x) float32 ...
VGRD_975mb         (time, y, x) float32 ...
...
UGRD_70mb          (time, y, x) float32 ...
VGRD_70mb          (time, y, x) float32 ...
UGRD_50mb          (time, y, x) float32 ...
VGRD_50mb          (time, y, x) float32 ...
HGT_1000mb         (time, y, x) float32 ...
HGT_975mb          (time, y, x) float32 ...
...
HGT_70mb           (time, y, x) float32 ...
HGT_50mb           (time, y, x) float32 ...
TMP_1000mb         (time, y, x) float32 ...
TMP_975mb          (time, y, x) float32 ...
...
TMP_70mb           (time, y, x) float32 ...
TMP_50mb           (time, y, x) float32 ...
var0_1_194_1000mb  (time, y, x) float32 ...
var0_1_194_975mb   (time, y, x) float32 ...
...
var0_1_194_70mb    (time, y, x) float32 ...
var0_1_194_50mb    (time, y, x) float32 ...
RH_1000mb          (time, y, x) float32 ...
RH_975mb           (time, y, x) float32 ...
...
RH_70mb            (time, y, x) float32 ...
RH_50mb            (time, y, x) float32 ...
Attributes:
Conventions:          CF-1.0
History:              created by wgrib2
GRIB2_grid_template:  30