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
18
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
  • 7,600
  • 17
  • 63
  • 123
10
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
  • 18,706
  • 61
  • 194
  • 336
10
votes
1 answer

Avoid overlapping colorbar in xarray facet grid plot

import xarray as xr import cartopy.crs as ccrs USA_PROJ = ccrs.AlbersEqualArea(central_longitude=-97., central_latitude=38.) g_simple = ds_by_month.t2m.plot(x='longitude', y='latitude', …
user308827
  • 18,706
  • 61
  • 194
  • 336
10
votes
5 answers

Get hourly average for each month from a netcdf file

I have a netCDF file with the time dimension containing data by the hour for 2 years. I want to average it to get an hourly average for each hour of the day for each month. I tried this: import xarray as xr ds =…
user308827
  • 18,706
  • 61
  • 194
  • 336
7
votes
3 answers

How to flatten an xarray dataset into a 1D numpy array?

Is there a simple way of flattening an xarray dataset into a single 1D numpy array? For example, flattening the following test dataset: xr.Dataset({ 'a' : xr.DataArray( data=[10,11,12,13,14], …
user7821537
  • 131
  • 2
  • 7
7
votes
2 answers

Xarray: slice coordinates with no dimensions

I am having difficultly with this topic, even though it seems like it should be rather simple. I want to slice an xarray dataset using a set of latitude and longitude coordinates. Here is what my dataset looks like: In [31]: data =…
Maria Molina
  • 165
  • 11
5
votes
2 answers

create netcdf using xarray with time stamp beyond year 2263

Is there a way to create a netCDF file with time dimension beyond year 2263 using xarray? Here is how a netCDF toy dataset can be created http://xarray.pydata.org/en/stable/time-series.html However the time dimension has a type of pandas datetime…
user308827
  • 18,706
  • 61
  • 194
  • 336
5
votes
1 answer

Do xarray or dask really support memory-mapping?

In my experimentation so far, I've tried: xr.open_dataset with chunks arg, and it loads the data into memory. Set up a NetCDF4DataStore, and call ds['field'].values and it loads the data into memory. Set up a ScipyDataStore with mmap='r', and…
5
votes
2 answers

Getting monthly climatology using xarray in python

I have a netCDF file containing daily data for a variable called var2001-01-01 to 2010-12-31. I want to compute monthly sum for var resulting in a netCDF containing 12 time steps (one for each month of the year). Currently, I am doing this: import…
user308827
  • 18,706
  • 61
  • 194
  • 336
4
votes
1 answer

How can I replace values in an xarray variable?

I have an xarray dataset ds Dimensions: (elevation_band: 4, latitude: 1, longitude: 1) Coordinates: * longitude (longitude) float64 -111.4 * latitude (latitude) float64 44.51 * elevation_band …
ferengi
  • 317
  • 2
  • 10
4
votes
1 answer

How to multiply Python Xarray Datasets?

I am reading multiple netCDF formatted data files (WRF model output files) using xarray.open_mfdataset() function. I am reading and destaggering various variables such as Variable QVAPOR, U & V resp. I am using the following code for reading netCDF…
4
votes
1 answer

python-xarray: how to convert individual-band raster data, for multiple bands and dates, to xarray-Dataset or DataArray?

I'd like to take raster (satellite imagery) data, and build a Dataset or DataArray, to speed up my image processing (I have to work on multi-band, multi-date satellite imagery a lot). The data comes as individual bands for each image date, and I…
KenC
  • 43
  • 4
4
votes
1 answer

How to read .csv with a compound header into a xarray DataArray (using pandas)

Given a dataset with the following structure: time var1 var2 var2 var1 var3 loc1 loc1 loc2 loc2 loc1 1 11 12 13 14 15 2 21 22 23 25 3 32 33 34 35 Given as a…
Grismar
  • 12,597
  • 2
  • 21
  • 37
4
votes
2 answers

xarray equivalent to pandas subtract/add

I'm looking for a concise way to do arithmetics on a single dimension of a DataArray, and then have the result returned as a new DataArray (both the changed and unchanged parts). In pandas, I would do this using df.subtract(), but I haven't found…
user8188435
  • 101
  • 1
  • 8
3
votes
1 answer

xarray: compute daily anomalies from monthly resampled average (not the climatology)

xarray's documentation explains how to compute anomalies to the monthly climatology. Here I am trying to do something slightly different: from daily timeseries, I would like to compute the daily anomaly to this month's average (not from the monthly…
Fabzi
  • 536
  • 3
  • 14
1
2 3 4 5