def __call__(self, data_object):
orig_shape = data_object[self.x_name].shape
x_vals = data_object[self.x_name].ravel().astype('float64')
y_vals = data_object[self.y_name].ravel().astype('float64')
x_i = (np.digitize(x_vals, self.x_bins) - 1).astype('int32')
y_i = (np.digitize(y_vals, self.y_bins) - 1).astype('int32')
if np.any((x_i == -1) | (x_i == len(self.x_bins)-1)) \
or np.any((y_i == -1) | (y_i == len(self.y_bins)-1)):
if not self.truncate:
mylog.error("Sorry, but your values are outside" + \
" the table! Dunno what to do, so dying.")
mylog.error("Error was in: %s", data_object)
raise ValueError
else:
x_i = np.minimum(np.maximum(x_i,0), len(self.x_bins)-2)
y_i = np.minimum(np.maximum(y_i,0), len(self.y_bins)-2)
my_vals = np.zeros(x_vals.shape, dtype='float64')
lib.BilinearlyInterpolate(self.table,
x_vals, y_vals, self.x_bins, self.y_bins,
x_i, y_i, my_vals)
my_vals.shape = orig_shape
return my_vals
评论列表
文章目录