【问题标题】:Unable to slice along latitude and longitude in NetCDF satellite file (Xarray)无法在 NetCDF 卫星文件 (Xarray) 中沿纬度和经度切片
【发布时间】:2021-06-11 02:48:02
【问题描述】:

我的数据包含纬度和经度值,但我无法使用 Xarray 对它们进行切片。当我尝试运行这样的代码时:

SeaIce[0].sel(latitude = slice(72,80))

我收到以下错误

ValueError: dimensions or multi-index levels ['latitude'] do not exist

但维度确实存在。这是我正在使用的数据集之一的示例:

Dimensions:                                 (time: 1, xgrid: 304, ygrid: 448)
Coordinates:
  * time                                    (time) datetime64[ns] 2002-01-01
  * ygrid                                   (ygrid) float32 5.838e+06 ... -5....
  * xgrid                                   (xgrid) float32 -3.838e+06 ... 3....
    latitude                                (ygrid, xgrid) float64 31.1 ... 3...
    longitude                               (ygrid, xgrid) float64 168.3 ... ...
Data variables:
    projection                              |S1 b''
    seaice_conc_monthly_cdr                 (time, ygrid, xgrid) float32 0.0 ...
    stdev_of_seaice_conc_monthly_cdr        (time, ygrid, xgrid) float32 ...
    melt_onset_day_seaice_conc_monthly_cdr  (time, ygrid, xgrid) float32 ...
    qa_of_seaice_conc_monthly_cdr           (time, ygrid, xgrid) float32 ...
    goddard_merged_seaice_conc_monthly      (time, ygrid, xgrid) float32 ...
    goddard_nt_seaice_conc_monthly          (time, ygrid, xgrid) float32 ...
    goddard_bt_seaice_conc_monthly          (time, ygrid, xgrid) float32 ...
Attributes: (12/41)
    Conventions:               CF-1.6, ACDD-1.3
    title:                     NOAA/NSIDC Climate Data Record of Passive Micr...
    references:                Comiso, J. C., and F. Nishio. 2008. Trends in ...
    comment:                   The variable melt_onset_day_seaice_conc_monthl...
    program:                   NOAA Climate Data Record Program
    cdr_variable:              seaice_conc_monthly_cdr
                       ...
    history:                   seaice_conc_monthly_nh_f13_200201_v03r01.nc cr...
    platform:                  DMSP 5D-2/F13 > Defense Meteorological Satelli...
    sensor:                    SSM/I > Special Sensor Microwave/Imager
    date_created:              2017-11-27T02:44:53Z
    time_coverage_start:       2002-01-01T00:00:00Z
    time_coverage_end:         2002-01-31T23:59:59Z

我尝试过沿 x​​grid 和 ygrid 维度进行切片,并且这些都有效,但自然很难在没有纬度和经度维度的情况下关注正确的区域。

【问题讨论】:

    标签: python netcdf python-xarray


    【解决方案1】:

    我设法使用 .where 和下面的一系列命令解决了这个问题:

    dr = te.where((te.latitude > 72) & (te.latitude < 80) & (te.longitude > -15) & (te.longitude < 10),drop=True)
    

    这选择了以 72 到 80 纬度和 -15 到 10 经度为界的区域。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-02-26
      • 2021-12-03
      • 1970-01-01
      • 1970-01-01
      • 2017-06-26
      • 2022-06-12
      • 2021-09-18
      • 2014-03-25
      相关资源
      最近更新 更多