AntSimi / py-eddy-tracker

Eddy identification and tracking
https://py-eddy-tracker.readthedocs.io/en/latest/
GNU General Public License v3.0
132 stars 55 forks source link

grid_stat for zonal mean #241

Closed berzinastella closed 6 months ago

berzinastella commented 6 months ago

Hi, Another usage question- is there a way to calculate zonal/latitudinal means of eddy variables? I tried using grid_stat but it seems like you need at least two grids in longitude for the function to work.

This worked (but bot for any larger value than 179 that i tried)

step_lat = 1
step_lon=179
bins = ((-180, 180, step_lon), (-85, 85, step_lat)) 
g = anticyclonic.grid_stat(((-180, 180, step_lon), (-85, 85, step_lat)), "amplitude")

However, is there a more clever already made function to calculate zonal/latitude means? I had a long look around the functions and could not see anything.

If there is no such function, how do you suggest going about calculating it?

Best, Stella

berzinastella commented 6 months ago

Sorry, figured it out on my own. For anyone looking for zonal means:

zonal_mean = pd.DataFrame(columns=["lat", "mean_amplitude"])
lat_bins=np.arange(-85,85,1)

for i in range(len(lat_bins)):
    x0, x1, y0, y1 = 0, 360, lat_bins[i], lat_bins[i+1]
    area = dict(llcrnrlon=x0, llcrnrlat=y0, urcrnrlon=x1, urcrnrlat=y1)
    a_subset = a_16w.extract_with_area(area, full_path=True)
    m=a_subset.speed_radius.mean()
    zonal_mean.loc[len(zonal_mean)] = ({'lat': y0, 'mean_amplitude': m})

Have a nice day !!