xarray

How can I replace values in an xarray variable?

老子叫甜甜 提交于 2019-12-12 21:26:10
问题 I have an xarray dataset ds <xarray.Dataset> Dimensions: (elevation_band: 4, latitude: 1, longitude: 1) Coordinates: * longitude (longitude) float64 -111.4 * latitude (latitude) float64 44.51 * elevation_band (elevation_band) int32 1 2 3 4 Data variables: area_frac (elevation_band, latitude, longitude) float64 0.005109 ... mean_elev (elevation_band, latitude, longitude) float64 2.45e+03 ... prec_frac (elevation_band, latitude, longitude) float64 0.005109 ... And I want to replace the values

When to use multiindexing vs. xarray in pandas

北城余情 提交于 2019-12-03 06:16:39
问题 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 unpivot(frame): ...: N, K = frame.shape ...: data = {'value' : frame.values.ravel('F'), ...: 'variable' : np.asarray(frame.columns).repeat(N), ...: 'date' : np.tile(np.asarray(frame.index), K)} ...: return pd.DataFrame(data, columns=['date', 'variable',

When to use multiindexing vs. xarray in pandas

前提是你 提交于 2019-12-02 19:40:46
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 unpivot(frame): ...: N, K = frame.shape ...: data = {'value' : frame.values.ravel('F'), ...: 'variable' : np.asarray(frame.columns).repeat(N), ...: 'date' : np.tile(np.asarray(frame.index), K)} ...: return pd.DataFrame(data, columns=['date', 'variable', 'value']) ...: In [5]: df = unpivot(tm.makeTimeDataFrame()) In [6]: df Out[6]: date variable value

Xarray rolling mean with weights

回眸只為那壹抹淺笑 提交于 2019-11-30 10:36:56
When I do running / rolling mean with weights in numpy, I e.g. do something like this: data = np.random.random(100) # Example data... weights = np.array([1, 2, 1]) data_m = np.convolve(data, weights/float(np.sum(weights)), "same") And then replace data_m[0] and data_m[-1] with e.g. nans, depending on application. Something alike can be done with xarray. What I do (in this case) is xr.DataArray(data).rolling(dim_0=3, center=True).mean(dim="dim_0") But this corresponds to the weights weights = np.array([1, 1, 1]) in the numpy example. How would I apply other weights, when using xarray? The

Xarray rolling mean with weights

我是研究僧i 提交于 2019-11-29 15:51:05
问题 When I do running / rolling mean with weights in numpy, I e.g. do something like this: data = np.random.random(100) # Example data... weights = np.array([1, 2, 1]) data_m = np.convolve(data, weights/float(np.sum(weights)), "same") And then replace data_m[0] and data_m[-1] with e.g. nans, depending on application. Something alike can be done with xarray. What I do (in this case) is xr.DataArray(data).rolling(dim_0=3, center=True).mean(dim="dim_0") But this corresponds to the weights weights =