What is the proper way to preserve XArray and units when running a gaussian_filter? #3294
-
Let's say I have the following code that extracts some u-wind data from the models, along with other fields. I want to run a simple smoother like gaussian_filter() before feeding it into q_vector() because the source data is too noisy to use.
The problem is I can't figure out a way to do this that preserves the Xarray structure, especially the units , which appear to be stored at the end of the array (not in attributes). Gaussian_filter() outputs a 2D array without the Xarray and I can't feed this into q_vector(). No problems if I feed u_wind directly into q_vector() without smoothing of the inputs, but I need the smoothing. Maybe I am not approaching this the right way? Or maybe MetPy has its own filter? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
HI @rolypolyman MetPy does have a couple of filtering options that we call smoothing. The closest to the SciPy If the function is fed an xarray DataArray, then it should give you back an xarray DataArray as is done in the MetPy xarray tutorial. https://unidata.github.io/MetPy/dev/tutorials/xarray_tutorial.html#cf-compliant-dataset-example |
Beta Was this translation helpful? Give feedback.
HI @rolypolyman MetPy does have a couple of filtering options that we call smoothing.
https://unidata.github.io/MetPy/dev/examples/calculations/Smoothing.html#sphx-glr-examples-calculations-smoothing-py
The closest to the SciPy
gaussian_filter
would be MetPy'ssmooth_gaussian
.https://unidata.github.io/MetPy/dev/api/generated/metpy.calc.smooth_gaussian.html#metpy.calc.smooth_gaussian
If the function is fed an xarray DataArray, then it should give you back an xarray DataArray as is done in the MetPy xarray tutorial.
https://unidata.github.io/MetPy/dev/tutorials/xarray_tutorial.html#cf-compliant-dataset-example