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

Ignore missing values when calculating trend #10

Open
scotthosking opened this issue Feb 2, 2018 · 0 comments
Open

Ignore missing values when calculating trend #10

scotthosking opened this issue Feb 2, 2018 · 0 comments

Comments

@scotthosking
Copy link
Owner

scotthosking commented Feb 2, 2018

missing_value = scs_full_cube.data.fill_value
slope = np.zeros(cube.data[0,:,:].shape)

for x in range(0,len(lons)):
   for y in range(0,len(lats)):
      arr =cube.data.data[:,x,y]

      ind = np.where(arr < 366)[0]

      if len(ind) < len(arr)*0.8: # if 20% of points are missing then set to missing value (ignore it in plot)
        slope[x,y] = missing_value
      else:
        slope[x,y], intercept, r_value, p_value, std_err = stats.linregress(years[ind], arr[ind])

        
# create new mask and add to cube
new_mask = np.zeros(slope.shape)
new_mask[ slope == missing_value] = 1.
new_mask = new_mask.astype(bool)  # convert to boolean array (True/False)
mx = ma.masked_array(slope, mask=new_mask)

@scotthosking scotthosking changed the title Ignore missing values when calculation trend Ignore missing values when calculating trend Feb 2, 2018
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

1 participant