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
27
votes
6 answers

xarray select nearest lat/lon with multi-dimension coordinates

I have a xarray dataset with irregular spaced latitude and longitudes coordinates. My goal is to find the value of a variable at the point nearest a certain lat/lon. Since the x and y dimensions are not the lat/lon values, it doesn't seem that the…
blaylockbk
  • 2,503
  • 2
  • 28
  • 43
27
votes
4 answers

How to get the coordinates of the maximum in xarray?

Simple question: I don't only want the value of the maximum but also the coordinates of it in an xarray DataArray. How to do that? I can, of course, write my own simple reduce function, but I wonder if there is anything built-in in xarray?
nandaloo
  • 1,007
  • 2
  • 11
  • 16
24
votes
2 answers

Is it possible to append to an xarray.Dataset?

I've been using the .append() method to concatenate two tables (with the same fields) in pandas. Unfortunately this method does not exist in xarray, is there another way to do it?
Itay Lieder
  • 748
  • 2
  • 6
  • 12
23
votes
2 answers

Extract coordinate values in xarray

I would like to extract the values of the coordinate variables. For example I create a DataArray as: import xarray as xr import numpy as np import pandas as pd years_arr=range(1982,1986) time = pd.date_range('14/1/' + str(years_arr[0]) + '…
Ray Bell
  • 1,508
  • 4
  • 18
  • 45
22
votes
1 answer

When to use multiindexing vs. xarray in pandas

The pandas pivot tables documentation seems to recomend dealing with more than two dimensions of data by using multiindexing: In [1]: import pandas as pd In [2]: import numpy as np In [3]: import pandas.util.testing as tm; tm.N = 3 In [4]: def…
kilojoules
  • 9,768
  • 18
  • 77
  • 149
19
votes
1 answer

replace values in xarray dataset with None

I want to replace values in a variable in an xarray dataset with None. I tried this approach but it did not work: da[da['var'] == -9999.]['var'] = None I get this error: *** TypeError: unhashable type: 'numpy.ndarray' Is there something like numpy…
user308827
  • 21,227
  • 87
  • 254
  • 417
19
votes
1 answer

What is the pandas.Panel deprecation warning actually recommending?

I have a package that uses pandas Panels to generate MultiIndex pandas DataFrames. However, whenever I use pandas.Panel, I get the following DeprecationError: DeprecationWarning: Panel is deprecated and will be removed in a future version. …
cge
  • 9,552
  • 3
  • 32
  • 51
19
votes
1 answer

Join/merge multiple NetCDF files using xarray

I have a folder with NetCDF files from 2006-2100, in ten year blocks (2011-2020, 2021-2030 etc). I want to create a new NetCDF file which contains all of these files joined together. So far I have read in the files: ds =…
Pad
  • 841
  • 2
  • 17
  • 45
19
votes
3 answers

Speeding up reading of very large netcdf file in python

I have a very large netCDF file that I am reading using netCDF4 in python I cannot read this file all at once since its dimensions (1200 x 720 x 1440) are too big for the entire file to be in memory at once. The 1st dimension represents time, and…
user308827
  • 21,227
  • 87
  • 254
  • 417
18
votes
4 answers

How to apply linear regression to every pixel in a large multi-dimensional array containing NaNs?

I have a 1D array of independent variable values (x_array) that match the timesteps in a 3D numpy array of spatial data with multiple time-steps (y_array). My actual data is much larger: 300+ timesteps and up to 3000 * 3000 pixels: import numpy as…
17
votes
4 answers

TypeError: cannot unpack non-iterable int objec

How can I solve this error After running my code as follows . I am using the function below and implementin running window for loop on it but end up getting the error below. The for loop works and hungs at a point. def get_grps(s, thresh=-1,…
user11036847
  • 455
  • 1
  • 4
  • 12
17
votes
3 answers

combining spatial netcdf files using xarray python

Is there a way to merge 2 or more netCDF files with the same time dimension but different spatial domains into a single netCDF file? The spatial domains are specified by latitude and longitude coordinates? In the documentation for xarray concat,…
user308827
  • 21,227
  • 87
  • 254
  • 417
15
votes
4 answers

Resample xarray object to lower resolution spatially

Use xarray to resample to lower spatial resolution I want to resample my xarray object to a lower spatial resolution (LESS PIXELS). import pandas as pd import numpy as np import xarray as xr time =…
Tommy Lees
  • 1,293
  • 3
  • 14
  • 34
15
votes
4 answers

Concise way to filter data in xarray

I need to apply a very simple 'match statement' to the values in an xarray array: Where the value > 0, make 2 Where the value == 0, make 0 Where the value is NaN, make NaN Here's my current solution. I'm using NaNs, .fillna, & type coercion in…
Maximilian
  • 7,512
  • 3
  • 50
  • 63
14
votes
2 answers

How can I get a list with the variable names of my xarray.Dataset?

I am looking for a way of extracting a list of the data variable names (strings) from a xarray.DataSet object. I have used xr_object.data_vars and xr_object.data_vars.keys() but they don't seem to give anything usefull. Also, the docs of xarray…
Thomas
  • 153
  • 1
  • 1
  • 6
1
2 3
99 100