Questions tagged [python-xarray]

Xarray - N-D labeled arrays and datasets in Python

Xarray is an open source project and Python package that introduces labels in the form of dimensions, coordinates, and attributes on top of raw NumPy-like arrays, which allows for more intuitive, more concise, and less error-prone user experience.

Xarray includes a large and growing library of domain-agnostic functions for advanced analytics and visualization with these data structures.

Resources

2296 questions
0
votes
1 answer

Remove colorbar from map plot

I have a plot of a map containing areas which are color coded. I need to remove the automatic color bar from the plot and replace with a legend. However, I cannot find a way to remove the color bar. Xarray was used to create the data array. map_crs…
Helen
  • 1
  • 1
0
votes
0 answers

How can i open several .nc files as one in python with xarray?

I have 30 .nc files with dimensions: time, lat, lon, pres; coordinates: time, lat, lon, pres and 18 different variables. I would like to open them in one dataset. If I use xarray.open_mfdataset (), it won't work, as the dimensions of pres are all…
Cathi
  • 1
0
votes
1 answer

Read compressed GRIB file from URL into xarray dataframe entirely in memory in Python

I am trying to read the gzipped grib2 files at tis URL: https://mtarchive.geol.iastate.edu/2022/12/24/mrms/ncep/SeamlessHSR/ I want to read the grib file into an xarray DataFrame. I know I could write a script to download the file to disk,…
hm8
  • 1,381
  • 3
  • 21
  • 41
0
votes
1 answer

how to round-trip an xarray.Dataset through it's own groupby method

The xarray.Dataset.groupby method prepares a dataset for iteration over subsets determined by the group argument. If the group argument is a constant value (i.e. one "subset" that's the whole dataset) broadcast to an xarray.DataArray with matching…
Ian
  • 1,062
  • 1
  • 9
  • 21
0
votes
1 answer

`coordinates` attribute of a netcdf variable is missing in xarray

I have a netcdf variable, namely mesh2d_sa1 which contains an attribute coordinates. But when I tried to call this attribute by ds.mesh2d_sa1.attrs["coordinates"], it is not found. The following is an extract of the output of ncdump -h xxxxxxx.nc,…
Ken T
  • 2,255
  • 1
  • 23
  • 30
0
votes
0 answers

SVD on huge dataset with dask and xarray

I use xarray and dask to open multiple netcdf4 files that all together are around 200Gb via import xarray as xr ds = xr.open_mfdataset('/path/files*.nc', parallel=True) The dimensions of this dataset "ds" are (longitude, latitude, height,…
FelixK
  • 1
  • 1
0
votes
0 answers

How to efficiently implement a kernel-based outlier detection on 2D arrays that includes a condition in Python?

I have a satellite image which is quite noisy. I wanted to try a Water Anomaly Filter proposed here. It is straight-foreword and appears to be suited for my use case, as it expects that the "real" structures on the ground are much larger than the…
eimes
  • 3
  • 2
0
votes
0 answers

How to subset a xarray.Dataset according to lat/lon values taken from a SRTM DEM extents

I have a year wise (1980-2020) precipitation data set in netCDF format. I am importing them in xarray to have 40 years of merged precipitation values: import netCDF4 import numpy import xarray as xr import pandas as…
Sayantan4796
  • 169
  • 1
  • 10
0
votes
0 answers

How to apply textwrap.wrap as ufunc on xarray.Dataarray

I am desperately trying to split strings within an xarray.Dataarray. What should happen to every element of the array is e.g. "aaabbbccc" --> [aaa, bbb, ccc] Fortunately, such a function already exists in the textwrap library, but applying it to my…
0
votes
1 answer

How can I change the dimensions of a xarray variable?

I have a gridded xarray dataset that looks like this: print(ds) Dimensions: (month: 12, isobaricInhPa: 37, latitude: 721, longitude: 1440) Coordinates: * isobaricInhPa (isobaricInhPa) float64 1e+03 975.0 950.0 ... 3.0 2.0…
e5k
  • 194
  • 1
  • 14
0
votes
0 answers

xarray to_netcdf group flipping latitude

I have the following xarray dataset: Dimensions: (latitude: 17664, longitude: 22656, time: 1) Coordinates: * longitude (longitude) float32 -46.0 -46.0 -45.99 -45.99 ... 12.99 13.0 13.0 * latitude (latitude) float32 66.0 66.0 65.99 65.99…
Ben Howey
  • 33
  • 3
0
votes
1 answer

Resampling a netCDF file with multiple bands in python

I have daily mean precipitation netCDF file that covers a period of five years. The specifics of the file are: Dimensions: (rlat: 412, rlon: 424, time: 1826, bnds: 2) Coordinates: lat (rlat, rlon) float64 ... lon …
0
votes
1 answer

How can I open an arbitrary netCDF file with xarray and get the *n*th time slice as a NumPy array?

When I open a netCDF file with xarray in Python, I open it as a Dataset object: ds = xr.open_dataset(file_path) How do I get the nth time slice of this dataset as a NumPy array? I know that I can get that if I know the NetCDF variable name, like…
HelloGoodbye
  • 3,624
  • 8
  • 42
  • 57
0
votes
0 answers

From meteorological GRIB with 1D x and y coordinates to 2D lat lon coordinates in netCDF format

I want to compile a meteorological dataset out of DWD weather data (https://opendata.dwd.de/climate_environment/REA/COSMO_REA6/daily/2D/) in .grb format with one dimensional coordinates (x and y) into a spatial subset in the netCDF fileformat with…
b_robran
  • 1
  • 1
0
votes
0 answers

Assign_crs and assign_y_x to an xarray dataset that contains a data variable created by MetPy's interpolate_to_grid

I have an xarray dataset that contains a data variable 'tmpc_obs' that was created using the interpolate_to_grid function within MetPy. I would like to be able to interpolate specific point values from lat lon pairs using xarray.interp, but I need…
Cane89
  • 3
  • 3
1 2 3
99
100