Reputation: 31
i have used this syntax which helped in finding the maximum of the dataset and which coordinates they are at: da.where(da==da.max(), drop=True).squeeze()
is there a way like this to find the top 10 values/ 90th percentile of the dataset and which coordinates they are at?
thanks
Upvotes: 3
Views: 1215
Reputation: 781
I think it's easiest to use the .quantile()
functionality in xarray. This is in essence just a wrapper around the .reduce()
method, for the case where you reduce the array using the np.nanpercentile()
function.
For example in your case:
da.quantile([5, 95], dim='time', interpolation='linear')
Where because the question is a bit vague, I've assumed you're taking the quantile over the time
dimension. The interpolation is something you can play about with, but if in doubt I use linear
or lower
.
For the second part of your question, if you're certain there aren't repeated values in your DataArray then you could just use the .where()
method to find where the data matches these percentiles, otherwise I'm not sure if there's a simple way to do this?
Read more here: http://xarray.pydata.org/en/stable/generated/xarray.DataArray.quantile.html
And for a bit of the development history: https://github.com/pydata/xarray/issues/561
Cheers! :)
Upvotes: 1