Guest User

Untitled

a guest
Mar 17th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. def grab_prob(time_idx):
  2. # make frame__idx an integer to avoid slicing errors
  3. frame_idx = int(time_idx)
  4. # get 'frame_time'
  5. frame_time = grab_sst_time(frame_idx)
  6.  
  7. # set month of year
  8. MoY_val = int(frame_time.month)
  9.  
  10. # get list of temperature and salinity values from subset
  11. temp = []
  12. salt = []
  13.  
  14. point_list = zip(eta_rho,xi_rho
  15.  
  16. # append values
  17. for i, j in point_list:
  18. temp.append(fh.variables['temp'][frame_idx,29,i,j])
  19. salt.append(fh.variables['salt'][frame_idx,29,i,j])
  20.  
  21. data = {'var1': temp, 'var2': salt}
  22. data = pd.DataFrame(data=data)
  23. data['MoY'] = MoY_val
  24. # remove masked floats
  25. data = data[data.var1 >= 1]
  26.  
  27. # calculate probabilities
  28. probs = lr_model.predict_proba(data[['var1','var2','MoY']])
  29. prob_TSW, prob_EAC = zip(*probs)
  30. # convert tuples to list
  31. prob_EAC = list(prob_EAC)
  32. # make 1D array
  33. prob_EAC = np.asarray(prob_EAC)
  34.  
  35. # calulcate ratio metric
  36. count_EAC = np.count_nonzero(prob_EAC > 0.5)
  37. count_TSW = np.count_nonzero(prob_EAC < 0.5)
  38.  
  39. return count_EAC, xtime # << return these instead of modifying a global var
  40.  
  41.  
  42.  
  43. ## ....
  44. for i in range(0, len(time)):
  45. count_EAC, xtime = grab_prob(i)
  46. ## add them to the data frame
Add Comment
Please, Sign In to add comment