Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dimension mismatch upon running pixel_overlaps #50

Closed
ccallahan45 opened this issue Oct 16, 2023 · 10 comments
Closed

dimension mismatch upon running pixel_overlaps #50

ccallahan45 opened this issue Oct 16, 2023 · 10 comments

Comments

@ccallahan45
Copy link

Hello!

I attempted to run xa.pixel_overlaps using tropical cyclone wind data and a shapefile (GeoDataFrame) of US state boundaries. I received the following error: "ValueError: new dimensions ('lat', 'bnds') must be a superset of existing dimensions ('lat', 'bnd')".

Based on the traceback, this appears to be occurring when the latitude and longitude bounds are created. The creation of the "bnds_tmp" variable appears to concatenate a variable with the dimension "bnds" to a variable with the dimension "bnd."

Full error message is included here:

image

thanks!

@mcruzloya
Copy link

I'm running into a similar issue with a different dataset (temperature and precipitation data) when trying to aggregate over US counties with a shapefile. The same files used to work fine on a previous version of xagg.

@oscarbau
Copy link

Same issue here

@ks905383
Copy link
Owner

ks905383 commented Nov 17, 2023

Hey all - sorry for the delay. Could one of you post example files that cause this issue? I'm having trouble reproducing the bug locally. (and let me know what version of xagg you're using)

@ccallahan45
Copy link
Author

Here are a couple of files and a minimum working example that (at least for me) produced the bug. I'm using xagg version 0.3.1 installed from conda-forge.
xagg_mwe.zip

@simonmoulds
Copy link

I think the problem may be lines 230-237 of xagg/aux.py:

            bnds_tmp = xr.DataArray(data=np.zeros((ds.dims[var],2))*np.nan,
                                    dims=[var,'bnds'],
                                    coords=[ds[var],np.arange(0,2)])

            # Assign all non-edge bounds as just half of the distance from the center
            # of each pixel to the center of the next pixel
            bnds_tmp[1:,:] = xr.concat([ds[var]-0.5*ds[var].diff(var),
                                          ds[var]+0.5*ds[var].diff(var)],dim='bnd').transpose(var,'bnd')

Note the 'bnds' dimension to create bnds_tmp, then referred to as 'bnd' when it's assigned.

@ks905383
Copy link
Owner

Yeah that looks plausible, thanks @simonmoulds @ccallahan45 . The really weird thing is I still can't replicate the problem locally, even with @ccallahan45 's replication data.

Running xa.aux.get_bnds() with and without the change to bnds in 230-237 doesn't change anything for me (the following code block runs fine, for example). This is weird, because the second bnds_tmp[1:,:] = with bnd coordinates instead of bnds below should be failing on my machine, but something in xarray is letting that go through.

bnds_tmp[1:,:] = xr.concat([ds[var]-0.5*ds[var].diff(var),
                                      ds[var]+0.5*ds[var].diff(var)],dim='bnds').transpose(var,'bnds')
a = bnds_tmp.copy()

bnds_tmp[1:,:] = xr.concat([ds[var]-0.5*ds[var].diff(var),
                                      ds[var]+0.5*ds[var].diff(var)],dim='bnd').transpose(var,'bnd')

b = bnds_tmp.copy()

xr.testing.assert_allclose(a,b)

In any case, let me fix those lines, and hopefully that'll fix this issue.

ks905383 added a commit that referenced this issue Nov 29, 2023
ks905383 added a commit that referenced this issue Nov 29, 2023
@ks905383
Copy link
Owner

Could someone for whom this error occurs locally test the new release #52 locally and make sure it works? Thanks!

@simonmoulds
Copy link

Thanks @ks905383 - this is now working for me.

@helsharif
Copy link

Hello,
I was running into the same issue mentioned in this thread, and didn't realize that I didn't have the latest version of xagg installed. I used the installation instructions on the github page:
conda install -c conda-forge xagg==0.3.1

But I see the version of xagg with the fix is version 0.3.1.1

I recommend to please update the github page installation instructions

@ks905383
Copy link
Owner

Fixed, thanks for pointing that out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants