@@ -6,22 +6,41 @@ import numpy as np
|
||||
|
||||
NEtaBins = 201
|
||||
|
||||
def interpolate_eta_from_points(points):
|
||||
points_integer = np.int32(points)
|
||||
points_fractional = points - points_integer
|
||||
points_fractional_x = points_fractional[:, 0]
|
||||
points_fractional_y = points_fractional[:, 1]
|
||||
def interpolate_eta_from_points(points, chunk_size=5_000_000):
|
||||
print('[EtaInterpolation]: Building eta histogram from points (Chunked)...')
|
||||
eta_hist2D = np.zeros((NEtaBins, NEtaBins), dtype=np.float64)
|
||||
|
||||
print('[EtaInterpolation]: Building eta histogram from points...')
|
||||
eta_hist2D = np.histogram2d(
|
||||
points_fractional_x, points_fractional_y,
|
||||
bins = NEtaBins, range=[[0, 1], [0, 1]]
|
||||
)[0] ### shape (201, 201), X, Y, according build_xy
|
||||
|
||||
# --- building eta histogram in chunks ---
|
||||
for i in range(0, len(points), chunk_size):
|
||||
start_idx = i
|
||||
end_idx = min(i + chunk_size, len(points))
|
||||
chunk = points[start_idx:end_idx]
|
||||
frac_x = chunk[:, 0] - np.int32(chunk[:, 0])
|
||||
frac_y = chunk[:, 1] - np.int32(chunk[:, 1])
|
||||
|
||||
hist_chunk, _, _ = np.histogram2d(
|
||||
frac_x, frac_y,
|
||||
bins=NEtaBins, range=[[0, 1], [0, 1]]
|
||||
)
|
||||
eta_hist2D += hist_chunk
|
||||
|
||||
U_tab, V_tab = build_xy_lut_Rosenblatt(eta_hist2D)
|
||||
|
||||
print('[EtaInterpolation]: Performing bilinear interpolation...')
|
||||
x_frac, y_frac = bilinear_xy_lookup(points_fractional_x, points_fractional_y, U_tab, V_tab)
|
||||
print('[EtaInterpolation]: Performing bilinear interpolation (Chunked)...')
|
||||
corrected_points = np.empty_like(points)
|
||||
|
||||
# --- performing bilinear interpolation in chunks ---
|
||||
for i in range(0, len(points), chunk_size):
|
||||
chunk = points[i:i + chunk_size]
|
||||
|
||||
int_x = np.int32(chunk[:, 0])
|
||||
int_y = np.int32(chunk[:, 1])
|
||||
frac_x = chunk[:, 0] - int_x
|
||||
frac_y = chunk[:, 1] - int_y
|
||||
|
||||
x_frac_corr, y_frac_corr = bilinear_xy_lookup(frac_x, frac_y, U_tab, V_tab)
|
||||
|
||||
corrected_points[i:i + chunk_size, 0] = int_x + x_frac_corr
|
||||
corrected_points[i:i + chunk_size, 1] = int_y + y_frac_corr
|
||||
|
||||
corrected_points = points_integer + np.stack([x_frac, y_frac], axis=-1)
|
||||
return corrected_points
|
||||
Reference in New Issue
Block a user