I have an array of dimensions (9131,101,191). The first dimension is the days from 1/1/2075 till 31/12/2099. I want to extract all the days which are in the month of July. How can I do this in xarray? I have tried using loops and numpy but not getting the desired result. Ultimately, I want to extract all the arrays which
Tag: python-xarray
__init__() missing 1 error while Adding a Discrete Colorbar to a ContourPlot
I was trying to replicate the Contour Plot: for a new set of interpolated data found on interpolated.nc I got the error: Nevetheless, I realized that the error was related to the plt.colorbar(ax=ax, shrink=.98) line, so I was wondering if I could get any help in order to solve this issue, since I need the colourbar in order to do
Calculate mean value for each pixel of a sum of Xarray DataArrays
I am trying to calculate a fog frequency map based on a number of geoTIFFs that I have read as Xarray DataArrays using the rioxarray.open_rasterio function in Python 3.10. Each “pixel” can have one of the following values: 1 = fog, 0 = no fog, -9999 = no data. The end goal is to calculate a new DataArray that contains
Getting error “unhashable type: ‘numpy.ndarray’ ” while trying to plot vectors from two different .nc files
I have read two files using open_mfdataset. What I’m trying to do is create a vector plot for the wind stress data for which the i and j components are stored in two different files. This is the data description But while trying to do the vector plotting using quiver I’m getting this unhashable typeerror. Answer You’re using matplotlib.pyplot.quiver, which
extract extreme values from xarray dataarray
I have a rather large dataset, and need to find in that dataset extreme values, including coordinates. The real dataset is much larger, but let’s take this one for testing: I want to find in this dataarray all values larger than 2. I found on here this solution: but even in this small example, this produces a lot more nans
Where does xarrays time.hour start and end?
I am not sure where xarray starts and ends the hour. For example: When I get a value for 1 o’clock, are those values form 00:00-01:00 or from 00:30-01:30 or from 01:00-02:00? In my specific case I have datas form several year token every minute and I need to know what exact timeslice the mean is when its plotted at
1D netcdf to 2D lat lon using xarray and Dask
I have a large netcdf dataset which has two dimensions – ‘time’ and a single spatial dimension ‘x’. There is also a ‘lat’ and ‘lon’ coord for each ‘x’. This needs to be mapped onto a global half degree 2D grid, such that the dimensions are ‘time’, ‘lat and ‘lon’. Not all the points on the global half degree grid
Multiply xarray variables with a numpy array
I have an xarray.DataArray: and I want ro multiply each mode with an element of the array array([68.8005905 , 17.8959575 , 8.46729004]). Any idea how to do that? Answer This is exactly what xarray is intended to help with you’re on the right track! Unlike numpy, which relies on dimension order and positional indices to align arrays, xarray relies on
When to use xarray over numpy for medium rank multidimensional data?
I have some multidimensional data and was wondering if i should use xarray when speed is one, albeit not highest, of my concerns. I have a 4D array so it’s not so big as to preclude me from using numpy. The coordinates/indices are vital for one dimension but not so for all the others. I’ll have to do slight book-keeping
compute mean from several years using xarray
I want to compute the mean for an xarray dataset that contains daily temperature data from 2015-2020. Here is what I am doing currently: ds.groupby(‘time.year’).mean(‘time’) However, this gives me annual mean for each year separately, whereas I want the mean for all the years. How do I fix this? Answer If you’re looking for the mean across the entire time