<xarray.DataArray 'nc_file' (time: 20, latitude: 360, longitude: 720, N: 3)>
[34992000 values with dtype=float64]
Coordinates:
* latitude (latitude) float64 89.75 89.25 88.75 88.25 87.75 87.25 86.75 ...
* longitude (longitude) float64 -179.8 -179.2 -178.8 -178.2 -177.8 -177.2 ...
* time (time) float64 0.0 1.826e+03 3.652e+03 5.479e+03 7.305e+03 ...
Dimensions without coordinates: N
Attributes:
units: 1
long_name: sample data var
How do I drop N
from the netCDF using xarray? the xarray drop
command does not work
Assuming hndl_nc is the handle to the netCDF file, I tried hndl_nc.drop('N')
not clear what you want to do: dataarr.drop('N') will remove only coordinate ; mostly useful for redundant coordinate.
but your data's equivalent numpy dimensions would still be array of shape (20,360,720,3) so you will always have N
now you have to decide what you want to do with the last dimension N. had you selected N=1 or sum or some reduction operation on dimension N; then drop('N') will work.
If N just repeating same dataset of (time: 20, latitude: 360, longitude: 720) three times, then you can use hndl_nc.isel(N=0)
to drop the dimension, N.
If N gave you different dataset of (time: 20, latitude: 360, longitude: 720), you can keep the data by hndl_nc.squeeze('N')
, but noted that the structure of the data will be changed.
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.