uxarray
uxarray copied to clipboard
Add Zonal Anomaly
The zonal mean of the data uxda can be calculated as
zonmean = uxda.zonal_mean() # zonal mean
The resulting zonmean has dimension of 'latitude', but no the unstructured grids.
If I want to calculate the zonal anomaly, e.g:
zonano = uxda - zonmean # zonal anomaly
The resulting zonano has dimensions of ['n_face', 'lat'] is therefore not what we would expect. The correct zonano should be in the same dimension with uxda.
Therefore, seems that zonal_mean function generates regular grid data and can not be use for further calculating.
Is there a way of calculating this zonal_anomaly on the original unstructured grids?
Hi @liuquan18
Zonal averages are computing along lines of constant latitude, which is where the lat latitude` dimension comes from.
We can see this when we plot the result:
I'm not sure if I'm following with this part you mentioned. Do you mind clarifying?
The resulting zonano has dimensions of ['n_face', 'lat'] is therefore not what we would expect. The correct zonano should be in the same dimension with uxda.
Hi @philipc2,
Thanks for your quick reply. Zonal anomaly is similar to temporal anomaly. The temporal anomaly is calculated by subtracting a temporal mean (a fixed value for one spatial pixel) from the original data (a time series at one spatial pixel). The resulting (temporal) anomaly should have the same dimension as the original data. Same to zonal anomaly. The zonal anomaly is calculated by subtracting a zonal mean (a fixed value for one latitude, and a series for all the latitude, as is shown in the plot) from the original data. The resulting zonal anomaly should have the same dimensions as the original data. Basically, for all points, a constant was removed. This is not the case if I use the uxda-zonmean. Because the zonmean has dimension 'latitude' which is not in the uxda. the calculation of uxda-zonmean was broadcasted, so that the result has dimension of n_faces and 'latitude'. I think I can still do this calculation with to_xarray(). Maybe the zonal_mean function was not designed for further calculation on the original unstructured grids.
Hi @philipc2,
Thanks for your quick reply. Zonal anomaly is similar to temporal anomaly. The temporal anomaly is calculated by subtracting a temporal mean (a fixed value for one spatial pixel) from the original data (a time series at one spatial pixel). The resulting (temporal) anomaly should have the same dimension as the original data. Same to zonal anomaly. The zonal anomaly is calculated by subtracting a zonal mean (a fixed value for one latitude, and a series for all the latitude, as is shown in the plot) from the original data. The resulting zonal anomaly should have the same dimensions as the original data. Basically, for all points, a constant was removed. This is not the case if I use the
uxda-zonmean. Because thezonmeanhas dimension 'latitude' which is not in theuxda. the calculation ofuxda-zonmeanwas broadcasted, so that the result has dimension ofn_facesand 'latitude'. I think I can still do this calculation withto_xarray(). Maybe thezonal_meanfunction was not designed for further calculation on the original unstructured grids.
I see what you're getting at!
So you would like the resulting data to have dimension n_face, where the value at each face is the corresponding zonal average?
For faces that weren't directly intersected by one of the lines of latitude, I assume we'd do some interpolation like in the plot above to get a desired value (or use a larger sampling)
I think the zonal anomaly can easily be implemented for isolatitudinal grids like HEALPix. For other grids, perhaps we could use cross_section.constant_latitude ?
Hi @liuquan18 , I believe we can work to get a zonal anomaly function, but I am not sure if it can and should return a result in the same dimension with the data (which would mean that we'd calculate zonal anomaly for each grid face, right?). My hesitation is that while the original unstructured grid data is in [n_face] dimension, when you run a zonal analysis, you are kind of getting out of the unstructured grid space and looking at the zonal space.
Were you referring to more of structured grids when expecting the same dimensionality between the original data and the result?
If were to still generate a function in the way you're requesting though, I imagine that it'd leverage the logic from our existing functions subset.constant_latitude() or subset.constant_latitude_interval() and zonal_mean() to calculate zonal anomaly for each grid face that falls into a latitude band.
Some faces might be falling into multiple latitude bands though (because of their intersection), which would require a special treatment.