Apply values along one latitude band to all latitude bands xarray

I have an empty dataarray (grid_test) in the shape of (361 (lat), 1 (lon)), where lat goes from 0 to 90, and lon=0. The grid spacing is 0.25, so lat=[0,0.25,0.50,0.75...90].

grid_test=xr.DataArray(data_test, coords=[test_lats,test_lons], dims=['latitude','longitude'])

This represents one latitude band that spans the Northern Hemisphere. In this case I filled every value to equal 1.

Now, in some other code I calculate the spatial surface area of each grid box along the latitudes (area_vals). This results in 361 values that I can then apply to my empty dataarray to produce a dataarray the values of area are associated with each latitude. This is done here:

vals=[a*b for a,b in zip(grid_test.values,area_vals)]
area_da=xr.DataArray(vals, coords=[test_lats,test_lons], dims=['latitude','longitude'])

I now want to create a new grid that is (361 (lat), 1440 (lon)) at 0.25 degree grid spacing.

new_grid=xr.DataArray(fill_data, coords=[lat, lon], dims=['latitude','longitude'])

This now incorporates every longitude on the globe and only latitudes across the Northern Hemisphere. Since the area only varies across latitude, the values at lon=0, will be the same as lon=1. As such, I want to apply the values in area_da to the new grid. How can this be accomplished?

Read more here:

Content Attribution

This content was originally published by Eli Turasky at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: