@@ -57,34 +57,17 @@ def modifiy_pixel_array_circle(pixel_array, m_x, m_y, radius):
57
57
# instead of id = 1 until pixel id = ENV_WIDTH (and respectively for ENV_HEIGHT)
58
58
ENV_HEIGHT , ENV_WIDTH = np .shape (pixel_array )
59
59
60
- left_end_circle = int (m_x - radius )
61
- right_end_circle = int (m_x + radius + 1 )
62
- upper_end_circle = int (m_y - radius )
63
- lower_end_circle = int (m_y + radius + 1 )
64
-
65
- # adapt _end_circle such that no pixels are placed outside arena.
66
- if left_end_circle < 0 :
67
- left_end_circle = 0
68
- if right_end_circle > ENV_WIDTH :
69
- right_end_circle = ENV_WIDTH
70
- if upper_end_circle < 0 :
71
- upper_end_circle = 0
72
- if lower_end_circle > ENV_HEIGHT :
73
- lower_end_circle = ENV_HEIGHT
60
+ # create arrays of indices
61
+ x_ind = np .arange (0 , ENV_WIDTH )
62
+ y_ind = np .arange (0 , ENV_HEIGHT )
74
63
75
64
# create numpy mask
76
-
77
- for x in range (left_end_circle , right_end_circle ):
78
- for y in range (upper_end_circle , lower_end_circle ):
79
- dx = x - m_x
80
- dy = y - m_y
81
- distance_squared = dx * dx + dy * dy
82
-
83
- if distance_squared <= (radius * radius ):
84
- pixel_array [y , x ] = pixel_array [y , x ] + 1
65
+ mask_circle = (x_ind [np .newaxis , :] - m_x )** 2 + (y_ind [:, np .newaxis ] - m_y )** 2 <= radius ** 2
66
+ pixel_array [mask_circle ] += 1
85
67
86
68
return pixel_array
87
69
70
+
88
71
def save_pixel_array (normalized_pixel_array , locations_or_circles , agent_or_patch ,
89
72
R , N , radii_resources , N_R , num_batches , folderpath ):
90
73
""" Saves a pixel array for adapting plots."""
0 commit comments