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

Can't return the standard variable name and reture NAN value When calculate the SPEI index using method ‘MB05’ #1552

Closed
CGL5230 opened this issue Dec 9, 2023 · 3 comments

Comments

@CGL5230
Copy link

CGL5230 commented Dec 9, 2023

Generic Issue

  • xclim version:0.46
  • Python version:3.11
  • Operating System:Linux

Description

This issue related to this post and this post.

I found I can't get the standard SPEI name,but you can see the variable name is "xarray_dataarray_variable" and the window is 1. The variable name should be 'spei' as document reported and the window should be 6(not 1).

When I try to clip the SPEI dataset, I got the error:"NoDataInBounds: No data found in bounds. Data variable: xarray_dataarray_variable".
It seems the calculation for SPEI index work incorrectly. But I can't find What's wrong.
image
image

What I Did

wb_BCC_CSM2MR_ssp585= xclim.indices.water_budget(pr=pr_BCC_CSM2MR_ssp585.pr, tas =tas_BCC_CSM2MR_ssp585.tas, method="MB05")
SPEI_BCC_CSM2MR_ssp585=xclim.indices.standardized_precipitation_evapotranspiration_index(wb=wb_BCC_CSM2MR_ssp585,freq='MS',window=6)
SPEI_BCC_CSM2MR_ssp585.to_netcdf('/path/BCC_CSM2MR2_ssp585_SPEI.nc')
BCC_CSM2MR_ssp585_SPEI = xr.opendataset('/path/BCC_CSM2MR2_ssp585_SPEI.nc')
BCC_CSM2MR_ssp585_SPEI_clip_data = BCC_CSM2MR_ssp585_SPEI .rio.clip(gdf,all_touched=True)

What I Received

"NoDataInBounds: No data found in bounds. Data variable: __xarray_dataarray_variable__".


### Code of Conduct

- [X] I agree to follow this project's Code of Conduct
@aulemahal
Copy link
Collaborator

aulemahal commented Dec 11, 2023

Hi @CGL5230,

I'm not sure this errors comes from xclim. I think the "No data in found in bounds" error relates to your polygon data gdf not overlapping with the grid. If that's the case, that would be an issue for rioxarray. Your grid looks pretty good, so I suspect something's wrong with your gdf ?

The reason for your issue with the variable name and attributes is that you are calling the low-level compute functions1 instead of the "indicators". You can simply replace .indices. by .atmos. in your case:

wb_BCC_CSM2MR_ssp585= xclim.atmos.water_budget(pr=pr_BCC_CSM2MR_ssp585.pr, tas =tas_BCC_CSM2MR_ssp585.tas, method="MB05")
SPEI_BCC_CSM2MR_ssp585=xclim.atmos.standardized_precipitation_evapotranspiration_index(wb=wb_BCC_CSM2MR_ssp585,freq='MS',window=6)
SPEI_BCC_CSM2MR_ssp585.to_netcdf('/path/BCC_CSM2MR2_ssp585_SPEI.nc')

This way, you'll have better metadata, better missing value checks and a better variable name.

Footnotes

  1. We call the low-level compute functions "indices" and the high-level ones "indicators". I agree that might be misleading at first.

@coxipi
Copy link
Contributor

coxipi commented Dec 11, 2023

window = 1 instead of window = 6

Thanks for noting this! At least, it's just another error in the attrs, so the computation "does" use window=6. I will fix this ...

@CGL5230
Copy link
Author

CGL5230 commented Dec 12, 2023

Thanks for your reply. I will check my gdf again. At least, the result from xclim is good.

@CGL5230 CGL5230 closed this as completed Dec 12, 2023
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

3 participants