Skip to content
Advertisement

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:

JavaScript

I want to find in this dataarray all values larger than 2. I found on here this solution:

JavaScript

but even in this small example, this produces a lot more nans than values:

JavaScript

and it’s worse in my actual dataset.

I’ve tried to write a helper function to convert it to a pandas dataframe, like this:

JavaScript

This produces the output I want, but 3 nested for loops seems excessive.

JavaScript

Any good suggestions on how to improve this?

Advertisement

Answer

There is already an implementation of converting to Pandas

JavaScript

https://docs.xarray.dev/en/stable/generated/xarray.DataArray.to_dataframe.html

On a side note, if you are looking to remove extreme values with no specific range then you might want to check out outlier detection https://scikit-learn.org/stable/modules/outlier_detection.html

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement