Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def grab_prob(time_idx):
- # make frame__idx an integer to avoid slicing errors
- frame_idx = int(time_idx)
- # get 'frame_time'
- frame_time = grab_sst_time(frame_idx)
- # set month of year
- MoY_val = int(frame_time.month)
- # get list of temperature and salinity values from subset
- temp = []
- salt = []
- point_list = zip(eta_rho,xi_rho
- # append values
- for i, j in point_list:
- temp.append(fh.variables['temp'][frame_idx,29,i,j])
- salt.append(fh.variables['salt'][frame_idx,29,i,j])
- data = {'var1': temp, 'var2': salt}
- data = pd.DataFrame(data=data)
- data['MoY'] = MoY_val
- # remove masked floats
- data = data[data.var1 >= 1]
- # calculate probabilities
- probs = lr_model.predict_proba(data[['var1','var2','MoY']])
- prob_TSW, prob_EAC = zip(*probs)
- # convert tuples to list
- prob_EAC = list(prob_EAC)
- # make 1D array
- prob_EAC = np.asarray(prob_EAC)
- # calulcate ratio metric
- count_EAC = np.count_nonzero(prob_EAC > 0.5)
- count_TSW = np.count_nonzero(prob_EAC < 0.5)
- return count_EAC, xtime # << return these instead of modifying a global var
- ## ....
- for i in range(0, len(time)):
- count_EAC, xtime = grab_prob(i)
- ## add them to the data frame
Add Comment
Please, Sign In to add comment