python-xarray

Is it possible to append to an xarray.Dataset?

为君一笑 提交于 2019-12-22 05:36:16
问题 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? 回答1: Xarray doesn't have an append method because its data structures are built on top of NumPy's non-resizable arrays, so we cannot append new elements without copying the entire array. Hence, we don't implement an append method. Instead, you should use xarray.concat. One usual pattern is to accumulate Dataset

combining spatial netcdf files using xarray python

99封情书 提交于 2019-12-22 03:56:11
问题 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, merge etc., they say that they work with a single dimension 回答1: My understanding of your question is that you want to want to open multiple netcdf files which contain different spatial sections of your data, where the overall dataset has been broken

Applying numpy.polyfit to xarray Dataset

青春壹個敷衍的年華 提交于 2019-12-19 04:36:21
问题 Does Xarray support numpy computation functions such as polyfit? Or is there an efficient way to apply such functions to datasets? Example: I want to calculate the slope of a line fitted to two variables (Temperature and Height), to calculate a lapse rate. I have a dataset (below) with these two variables with dimensions of (vertical, time, xgrid_0, ygrid_0). <xarray.Dataset> Dimensions: (PressLev: 7, time: 48, xgrid_0: 685, ygrid_0: 485) Coordinates: gridlat_0 (ygrid_0, xgrid_0) float32 44

Applying numpy.polyfit to xarray Dataset

只愿长相守 提交于 2019-12-19 04:36:00
问题 Does Xarray support numpy computation functions such as polyfit? Or is there an efficient way to apply such functions to datasets? Example: I want to calculate the slope of a line fitted to two variables (Temperature and Height), to calculate a lapse rate. I have a dataset (below) with these two variables with dimensions of (vertical, time, xgrid_0, ygrid_0). <xarray.Dataset> Dimensions: (PressLev: 7, time: 48, xgrid_0: 685, ygrid_0: 485) Coordinates: gridlat_0 (ygrid_0, xgrid_0) float32 44

python-xarray: open_mfdataset concat along two dimensions

こ雲淡風輕ζ 提交于 2019-12-18 04:13:07
问题 I have files which are made of 10 ensembles and 35 time files. One of these files looks like: >>> xr.open_dataset('ens1/CCSM4_ens1_07ic_19820701-19820731_NPac_Jul.nc') <xarray.Dataset> Dimensions: (ensemble: 1, latitude: 66, longitude: 191, time: 31) Coordinates: * ensemble (ensemble) int32 1 * latitude (latitude) float32 0.0 1.0 2.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0 ... * longitude (longitude) float32 100.0 101.0 102.0 103.0 104.0 105.0 106.0 ... * time (time) datetime64[ns] 1982-07-01 1982-07-02

add dimension to an xarray DataArray

家住魔仙堡 提交于 2019-12-14 04:16:21
问题 I need to add a dimension to a DataArray , filling the values across the new dimension. Here's the original array. a_size = 10 a_coords = np.linspace(0, 1, a_size) b_size = 5 b_coords = np.linspace(0, 1, b_size) # original 1-dimensional array x = xr.DataArray( np.random.random(a_size), coords=[('a', a coords)]) I guess I could create an empty DataArray with the new dimension and copy the existing data in. y = xr.DataArray( np.empty((b_size, a_size), coords=([('b', b_coords), ('a', a_coords)])

Drop duplicate times in xarray

左心房为你撑大大i 提交于 2019-12-13 16:31:52
问题 I'm reading NetCDF files with open_mfdataset , which contain duplicate times. For each duplicate time I only want to keep the first occurrence, and drop the second (it will never occur more often). The problem is quite similar to this Pandas question, but none of the solutions provided there seem to work with Xarray. To reproduce the problem: import numpy as np import netCDF4 as nc4 import xarray as xr # Create example NetCDF files for t in range(2): nc = nc4.Dataset('test{}.nc'.format(t), 'w

Python: How to find regression equation of multiple 3D (lat-lon-time-value) dataArrays?

南楼画角 提交于 2019-12-13 03:47:11
问题 I have two sets of dataArrays representing a value on three coordinate axes (lat, lon, time); one set of dataArrays represents variable varA, one set represents variable varB (example given below). varA <xarray.DataArray 'varA' (time: 32, lat: 20, lon: 18)> array([[[... ... ]]]) Coordinates: * lat (lat) float64 4.75 4.25 3.75 3.25 2.75 2.25 1.75 1.25 0.75 0.25 ... * lon (lon) float64 33.25 33.75 34.25 34.75 35.25 35.75 36.25 36.75 ... * time (time) datetime64[ns] 1979-01-01 1980-01-01 1981-01

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

concat Datasets along multiple dimensions

Deadly 提交于 2019-12-12 19:30:34
问题 I have multiple data with the same coords and similar values for them. I.e., there is no single unique ID but rather a combined ID of (index, split) . Ideally, I would just want to append all the datasets one after another, but I haven't found the right way to do so. import xarray as xr from xarray import Dataset import numpy as np datasets = [] for split in range(3): dim2_len = 4 dim1_len = 3 data_len = 5 d = Dataset({'data1': (['index', 'dim1'], np.random.rand(data_len, dim1_len)), 'data2':