i am trying to find out moisture divergence using metpy divergence module and i used
qu12=q3b*u3b
qv12=q3b*v3b
HMD12 = mpcalc.divergence(qu12, qv12)
here qu12 ,qv12 are 4d xarray data array, and i got the moisture divergence correctly using this. Usually we need to give dx=lon,dy=lat in the last line of this code but when i add this i was getting the error
> too many indices for array: array is 2-dimensional, but 4 were indexed
since i was getting the divergence without giving this i didn't paid attention to this error. But now I need to find the moisture divergence for another xarray. Now i am doing it for a dictionary with years being the keys
HMD = {}
for year in [2012, 2018, 2019]:
# Get the resampled dataset for the current year
resampled_ds = resampled_data[year]
# Slice latitude and longitude ranges
# Select latitude values within the desired range(8-12, 75-77)
lat_range = resampled_ds['latitude'].where((resampled_ds['latitude'] >= 8) & (resampled_ds['latitude'] <= 12), drop=True)
sliced_ds = resampled_ds.sel(latitude=lat_range, longitude=slice(75, 78))
# Calculate the moisture flux components
qu_l = (sliced_ds['Q'] * sliced_ds['U'])
qv_l = (sliced_ds['Q'] * sliced_ds['V'])
# Compute the grid deltas (dx, dy) in meters
dx, dy = mpcalc.lat_lon_grid_deltas(sliced_ds['longitude'], sliced_ds['latitude'])
# Compute the divergence of the moisture flux
HMD[year] = mpcalc.divergence(qu_l, qv_l, dx=dx, dy=dy)
HMD[year] = HMD
here also qu_l and qv_l are 4d xarrays(lon,lat,level,time) same as qu12 the only difference is for qu12 the lat and lon are in float32 and for qu_l it is in float64. can any one tell why it works for qu12 (4darray) but not for another 4d array qu_l?