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

RuntimeWarnings #15

Open
FQMei opened this issue May 15, 2023 · 6 comments
Open

RuntimeWarnings #15

FQMei opened this issue May 15, 2023 · 6 comments

Comments

@FQMei
Copy link

FQMei commented May 15, 2023

Hi, first of all, thank you for your great work! I have encountered an issue where some grids in my data contain only 'NaN' values and I am receiving warning messages. Despite diligently searching for information to identify the root cause of the issue, I have not found any useful information so far.

I was wondering if you could provide me with any advice or insights on how I can effectively tackle this problem and come up with a solution? Any help would be greatly appreciated.

image

@josuemtzmo
Copy link
Owner

Hello @FQMei,

Apologies for the slow reply, but I was on leave. A while ago, I noticed a bug, when the input data had nan values. This should be fixed in the latest version of the code, but could you check if you have the fix (quoted below) is in the file: xarrayMannKendall/xarrayMannKendall.py. If the fix is included, I will need a bit more information to debug it, i.e. when you say some grids, what do you mean? Does the output matrix contains data (note that the screenshot you sent are only RuntimeWarnings, not Errors)?

There was an issue on handling nan values, where the x coordinate was assigned to [0,0] instead of [0,1].

Error:

def _check_length(self):
# Make sure that x and y have the same length and they are not empty.
if not self.x.size > 0 or not self.y.size > 0 or self.n ==0:
self.x = np.array([0,0])
self.y = np.array([0,0])
self.n = len(self.y)

Fix:

def _check_length(self):
# Make sure that x and y have the same length and they are not empty.
if not self.x.size > 0 or not self.y.size > 0 or self.n ==0:
self.x = np.array([0,1])
self.y = np.array([0,0])
self.n = len(self.y)

@FQMei
Copy link
Author

FQMei commented Jun 1, 2023

Thanks for your reply @josuemtzmo

  1. I have the fix in the file.
  2. I use geographic data for analysis, including longitude, latitude, time, and temperature information, so "grid" means a cell containing temperature (y) and time (x) in a specific location.
  3. The output matrix contains no data.

@josuemtzmo
Copy link
Owner

Which version of XarrayMannKendall are you using?

@FQMei
Copy link
Author

FQMei commented Jun 7, 2023

1.4.5, I think.

@josuemtzmo
Copy link
Owner

Hello @FQMei, I can’t not see why the code isn’t working for you. In order for me to help you more solving the issue, could you share a test case so I can reproduce it on my side?

@FQMei
Copy link
Author

FQMei commented Jun 7, 2023

Hi, thanks for your reply!!! If I remember well, the bug appeared in the file that you can download here: https://ufile.io/vi4ubhie

Let me know if this URL is valid.

And the code I use maybe like this:
ds = xr.open_dataset(file_path)
ds = ds.precipitation.sel(time=slice("2003-01-01", "2019-12-01")).transpose("time", "lat", "lon")
ds_yr = ds.groupby('time.year').mean(dim='time', skipna=True)
mk_test = Mann_Kendall_test(ds_yr, dim='time', MK_modified=False, method='theilslopes', coords_name={'time': 'time', 'x': 'lon', 'y': 'lat'}
result = mk_test.compute()

Thanks again for your kind help!

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

2 participants