Questions tagged [xarray]

Use this tag for questions about `xarray` python package providing N-dimensional variants of the core pandas data structures

xarray (formerly xray) is an open source project and Python package that aims to bring the labeled data power of pandas to the physical sciences, by providing N-dimensional variants of the core pandas data structures.

Site: http://xarray.pydata.org/en/stable/

Githib: https://github.com/pydata/xarray

73 questions
3
votes
2 answers

How to save xarray.DataArray with complex128 data to netcdf

I have some complex data (numpy dtype complex128) in an xarray data set which I want to save with to_netcdf. I get the following error: TypeError: illegal primitive data type, must be one of dict_keys(['S1', 'i1', 'u1', 'i2', 'u2', 'i4', 'u4',…
3
votes
2 answers

How to downsample xarray dataset using groupby?

I'd like to downsample an xarray dataset based on a particular group, so I'm using groupby to select the group and then take 10% of the samples within each group. I'm using the code below but I get IndexError: index 1330 is out of bounds for axis 0…
Olga Botvinnik
  • 1,373
  • 1
  • 13
  • 28
3
votes
1 answer

When can I use a boolean DataArray for indexing?

I'm using an xarray DataArray object for boolean indexing. It works… sometimes. In the example below, it works for the large array but not for the small one: In [12]: x = xarray.DataArray(numpy.arange(336*49).reshape(336,49)) In [13]:…
gerrit
  • 17,590
  • 12
  • 72
  • 135
3
votes
2 answers

Adding and using additional coordinates with xarray

I'm learning how to use the python xarray package, however, I'm having troubles with multi-dimensional data. Specifically, how to add and use additional coordinates? Here's an example. import xarray as xr import pandas as pd import numpy as…
Geoff D
  • 309
  • 2
  • 12
3
votes
1 answer

Wrong time dimension after doing a groupby with library xarray (python)

my problem is that I would like to use the easy functionality of the xarray-library in python, but I run into problems with the time dimension in case of aggregating data. I have opened a dataset, which contains daily data over the year 2013:…
2
votes
1 answer

How can I find the maximum across all variables corrresponding to the max in one variable?

I have an xarray of daily data with a number of variables. I want to extract the maximum q_routed every year and the corresponding values of other variables on the day that the maximum q_routed happens. Dimensions: …
ferengi
  • 317
  • 2
  • 10
2
votes
1 answer

construct a large dask-backed xarray from an iterator of row vectors

How can I build xarray from from an iterator of row vectors. The resulting array may be larger than memory and will be backed by a dask array. The row vectors also come with unique labels which need to become the row index of the resulting…
Daniel Mahler
  • 6,213
  • 3
  • 40
  • 82
2
votes
1 answer

renaming __xarray_dataarray_variable__ in xarray dataarray

I have created a xarray dataarray using the xarray concat command. This has resulted in a dataarray with name __xarray_dataarray_variable__. However, I cannot seem to rename it using the rename command. Is there some other way to rename it? I tried…
user308827
  • 18,706
  • 61
  • 194
  • 336
2
votes
1 answer

xarray: How to apply a scipy function to a large netcdf dataset

I have a large netcdf file with several variables. I need to do discrete integration along a dimension to a variable say temperature of shape (80,100,300000) with dimensions (time, depth, nodes). So, I tried with dividing the large dataset into…
Jithu
  • 55
  • 7
2
votes
1 answer

Seam where longitude wraps around in matplotlib/cartopy Mollweide projection

I am plotting some NETCDF data, handled by xarray in Matplotlib using a Cartopy wrapper for the map projections. When I produce a filled contour plot (contourf), I end up with a 'seam' at longitude zero (where my data longitudes begin and end). Is…
2
votes
1 answer

Replace xarray coordinates with another coordinate

I try to replace two coordinates with the same length in a xarray.Dataset by using one coordinate for both of them. I do not care about the old coordinates or its values; I simply want to replace them. Is there any convenient method for this? import…
mrzo
  • 1,509
  • 1
  • 8
  • 18
2
votes
1 answer

Output int32 time dimension in netCDF using xarray

Let's say I have time data that looks like this in an xarray Dataset: ds = xr.Dataset({'time': pd.date_range('2000-01-01', periods=10)}) ds.to_netcdf('asdf.nc') xarray's to_netcdf() method outputs the time dimension as int64: $ ncdump -v time…
Dan
  • 820
  • 10
  • 13
2
votes
1 answer

Set values using name index in xarray

I'm trying an MA crossover I did in pandas panels using xarray. Data I'm using: Dimensions: (DATE: 3355, DN_NAME: 22670) Coordinates: * DATE (DATE) datetime64[ns] 2004-05-18 2004-05-19 2004-05-21 ... *…
svp
  • 23
  • 3
2
votes
1 answer

Easy way to create an xarray DataSet from metadata + values?

I'm working with single-cell RNA-sequencing data which is lately 10k-100k samples (cells) x 20k features (genes) of sparse values, and also includes a lot of metadata, e.g. the tissue ("Brain" vs "Liver") of origin. The metadata is ~10-100 columns…
Olga Botvinnik
  • 1,373
  • 1
  • 13
  • 28
2
votes
2 answers

Increase Dimensionality of a xarray from coordinates

Say I have the following 2d-array >>> import numpy as np >>> budgets = np.array([ [np.nan, 450.], [500. , 100.], [np.nan, 900.], ]) whose values are positioned like so >>> coords = [ ('name' , ['Jack_teen' ,…
keepAlive
  • 4,938
  • 4
  • 20
  • 36