My data contains latitude and longitude values but I am unable to slice along them using Xarray. When I attempt to run code like this:
SeaIce[0].sel(latitude = slice(72,80))
I get the following error
ValueError: dimensions or multi-index levels ['latitude'] do not exist
But the dimensions do exist. Here's an example of one of the datasets I'm working with:
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
I've tried slicing along the xgrid and ygrid dimensions, and those work, but naturally it's challenging to focus on the correct area without latitude and longitude dimensions.
I managed to get around this using.where and a series of commands below:
dr = te.where((te.latitude > 72) & (te.latitude < 80) & (te.longitude > -15) & (te.longitude < 10),drop=True)
This selected the region bound by 72 to 80 latitude and -15 to 10 longitude.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.