python-xarray

How to get the coordinates of the maximum in xarray?

谁说胖子不能爱 提交于 2020-01-22 17:41:27
问题 simple question: I don't only want the value of the maximum but also the coordinates of it in a xarray DataArray. How to do that? I can of course write my own simple reduce funtion, but I wonder if there is anything built-in in xarray? 回答1: You can use da.where() to filter based on the max value: In [15]: da = xr.DataArray(np.random.rand(2,3,4)) In [16]: da.where(da==da.max(), drop=True).squeeze() Out[16]: <xarray.DataArray (dim_0: 1, dim_1: 1, dim_2: 1)> array([[[ 0.91077406]]]) Coordinates:

using Prophet on netCDF file using xarray

a 夏天 提交于 2020-01-16 05:39:06
问题 I have a 'netCDF' file which I have read with xarray and I want to use to generate a forecast for each pixel in the file. import xarray as xr from fbprophet import Prophet import time with xr.open_dataset('avi.nc', chunks={'y': 2, 'x':2}) as avi: print(avi) <xarray.Dataset> Dimensions: (ds: 104, lat: 213, lon: 177) Coordinates: * lat (lat) float64 -2.711e+06 -2.711e+06 -2.711e+06 -2.711e+06 ... * lon (lon) float64 1.923e+06 1.924e+06 1.924e+06 1.924e+06 1.924e+06 ... * ds (ds) object '1999-07

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

拟墨画扇 提交于 2020-01-05 01:32:44
问题 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. <xarray.Dataset> Dimensions: (latitude: 1, longitude: 1, param_set: 1, time: 17167) Coordinates: * time (time) datetime64[ns] 1970-01-01 ... * latitude (latitude) float32 44.5118 * longitude (longitude) float32 -111.435 * param_set (param_set) |S1 b'' Data variables: ppt (time, param_set,

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

荒凉一梦 提交于 2020-01-05 01:32:20
问题 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. <xarray.Dataset> Dimensions: (latitude: 1, longitude: 1, param_set: 1, time: 17167) Coordinates: * time (time) datetime64[ns] 1970-01-01 ... * latitude (latitude) float32 44.5118 * longitude (longitude) float32 -111.435 * param_set (param_set) |S1 b'' Data variables: ppt (time, param_set,

Create DataArray from Dict of 2D DataFrames/Arrays

倾然丶 夕夏残阳落幕 提交于 2020-01-02 10:02:38
问题 I'm trying to transition from Pandas into Xarray for N-Dimensional DataArrays to expand my repertoire. Realistically, I'm going to have a bunch of different pd.DataFrames (in this case row=month, col=attribute) along a particular axis (patients in the mock example below) that I would like to merge (w/o using panels or multindex :), thank you). I want to convert them to xr.DataArrays so I can build dimensions upon them. I made a mock dataset to give a gist of what I'm talking about. For this

Select xarray/pandas index based on specific months

别说谁变了你拦得住时间么 提交于 2020-01-01 19:18:28
问题 I have an xarray DataArray that I want to select the months April, May, June (similar to time.season=='JJA') for an entire time series. Its structured like: <xarray.DataArray 't2m' (time: 492, latitude: 81, longitude: 141)> I have been previously selecting JJA by: seasonal_data =temp_data.sel(time=temp_data['time.season']=='JJA') I would like to do the same thing but with the months 'AMJ' instead. I can add any details that I might be missing. Thanks 回答1: The easiest way to select custom

Segmentation fault writing xarray datset to netcdf or dataframe

走远了吗. 提交于 2019-12-25 06:24:29
问题 I get a segmentation fault working with a xarray dataset that was created from multiple grib2 files. The fault occurs when writing out to a netcdf as well as when writing to a dataframe. Any suggestions on what is going wrong are appreciated. files = os.listdir(download_dir) Example of files (from http://dd.weather.gc.ca/model_hrdps/west/grib2/00/000/) 'CMC_hrdps_west_RH_TGL_2_ps2.5km_2016072800_P015-00.grib2',... 'CMC_hrdps_west_TMP_TGL_2_ps2.5km_2016072800_P011-00.grib2' # import and

Upsample seasonal data to daily data over 10 years in Python xarray

南笙酒味 提交于 2019-12-25 00:33:41
问题 I have a netCDF file for seasonal data. When loaded into Dataset, it contains season , latitude and longitude dimensions. print(dataset_seasonal_nc) <xarray.Dataset> Dimensions: (latitude: 106, longitude: 193, season: 4) Coordinates: * latitude (latitude) float32 -39.2 -39.149525 ... -33.9 * longitude (longitude) float32 140.8 140.84792 ... 150.0 * season (season) object 'DJF' 'JJA' 'MAM' 'SON' Data variables: FFDI 95TH PERCENTILE (season, latitude, longitude) float64 dask.array<shape=(4, 106

How do I combine multiple datasets (.h5 files) with different dimensions sizes in xarray

这一生的挚爱 提交于 2019-12-24 23:06:02
问题 I tried several methods to make a xarray (xr) dataset out of multiple .h5 files. The files contain data from SMAP project on soil moisture content along with other useful variables. Each variable represent a 2-D Array. The count of variables and their label are in every file equal. The problem is the dimensions size of dimension x and y are not equal. Example dataset load via xr.open_dataset() <xarray.Dataset> Dimensions: (x: 54, y: 129) Coordinates: EASE_column_index_3km (x, y) float32 ...

Incorrect shape of array after xarray multiplication operation

空扰寡人 提交于 2019-12-24 21:35:32
问题 As per Value error in multplying xarray variable with 2D numpy array import xarray as xr hndl_tran = xr.open_dataset(path_netcdf, chunks={'time': 10}) flow_data = hndl_tran['val'] new_arr = flow_data * xr.DataArray(vba) Here are the shapes of input arrays flow_data.shape (1165, 720, 1440) vba.shape (720L, 1440L) Here is the shape of the array after multiplying: new_arr.shape (1165, 720, 1440, 720, 1440) I want the resulting array to have same shape as flow_data. How do i do this? 回答1: xarray