Skip to content

Commit

Permalink
Added numba.jit.
Browse files Browse the repository at this point in the history
  • Loading branch information
dwfncar committed Sep 21, 2024
1 parent 1563d3c commit f14009a
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions melodies_monet/util/grid_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import math
import numpy as np
import numba


def update_sparse_data_grid(time_edges, x_edges, y_edges,
Expand Down Expand Up @@ -95,6 +96,7 @@ def sparse_data_to_array(time_edges, x_edges, y_edges,
return count_grid_array, data_grid_array


@numba.jit(nopython=True)
def update_data_grid(time_edges, x_edges, y_edges,
time_obs, x_obs, y_obs, data_obs,
count_grid, data_grid):
Expand Down Expand Up @@ -125,9 +127,23 @@ def update_data_grid(time_edges, x_edges, y_edges,
i_time = math.floor((time_obs[i] - time_edges[0]) / time_del)
i_x = math.floor((x_obs[i] - x_edges[0]) / x_del)
i_y = math.floor((y_obs[i] - y_edges[0]) / y_del)
"""
i_time = np.clip(i_time, 0, ntime - 1)
i_x = np.clip(i_x, 0, nx - 1)
i_y = np.clip(i_y, 0, ny - 1)
"""
if i_time < 0:
i_time = 0
elif i_time >= ntime:
i_time = ntime - 1
if i_x < 0:
i_x = 0
elif i_x >= nx:
i_x = nx - 1
if i_y < 0:
i_y = 0
elif i_y >= ny:
i_y = ny - 1
count_grid[i_time, i_x, i_y] += 1
data_grid[i_time, i_x, i_y] += data_obs[i]

Expand Down

0 comments on commit f14009a

Please sign in to comment.