parabellum 0.3.3__py3-none-any.whl → 0.4.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
parabellum/env.py CHANGED
@@ -223,11 +223,21 @@ class Environment(SMAX):
223
223
  # def step_env(self, rng, state: State, action: Array): # type: ignore
224
224
  # obs, state, rewards, dones, infos = super().step_env(rng, state, action)
225
225
  # delete world_state from obs
226
+ # <<<<<<< HEAD
226
227
  # obs.pop("world_state")
227
228
  # if not self.reset_when_done:
228
229
  # for key in dones.keys():
229
230
  # dones[key] = False
230
231
  # return obs, state, rewards, dones, infos
232
+ # =======
233
+ obs.pop("world_state")
234
+ if not self.reset_when_done:
235
+ for key in dones.keys():
236
+ infos[key] = dones[key]
237
+ dones[key] = False
238
+ return obs, state, rewards, dones, infos
239
+
240
+ # >>>>>>> aeb13033e57083cc512a60f8f60a3db47a65ac32
231
241
 
232
242
  def get_obs_unit_list(self, state: State) -> Dict[str, chex.Array]: # type: ignore
233
243
  """Applies observation function to state."""
parabellum/geo.py CHANGED
@@ -91,6 +91,7 @@ def geography_fn(place, buffer=400):
91
91
  # 0: building", 1: "water", 2: "highway", 3: "forest", 4: "garden"
92
92
  kernel = jnp.array([[1, 1, 1], [1, 1, 1], [1, 1, 1]])
93
93
  trans = lambda x: jnp.rot90(x, 3)
94
+ # <<<<<<< HEAD
94
95
  terrain = tps.Terrain(
95
96
  building=trans(raster[0]),
96
97
  water=trans(
@@ -102,6 +103,15 @@ def geography_fn(place, buffer=400):
102
103
  return terrain
103
104
 
104
105
 
106
+ # =======
107
+ # terrain = tps.Terrain(building=trans(raster[0] - convolve(raster[0]*raster[2], kernel, mode='same')>0),
108
+ # water=trans(raster[1] - convolve(raster[1]*raster[2], kernel, mode='same')>0),
109
+ # forest=trans(jnp.logical_or(raster[3], raster[4])),
110
+ # basemap=basemap)
111
+ # return terrain, gdf
112
+ # >>>>>>> aeb13033e57083cc512a60f8f60a3db47a65ac32
113
+
114
+
105
115
  def raster_fn(gdf, shape) -> Array:
106
116
  bbox = gdf.total_bounds
107
117
  t = transform.from_bounds(*bbox, *shape) # type: ignore
@@ -117,14 +127,74 @@ def feature_fn(t, feature, gdf, shape):
117
127
  return raster
118
128
 
119
129
 
130
+ # %%
131
+ def normalize(x):
132
+ return (np.array(x) - m) / (M - m)
133
+
134
+
135
+ def get_bridges(gdf):
136
+ xmin, ymin, xmax, ymax = gdf.total_bounds
137
+ m = np.array([xmin, ymin])
138
+ M = np.array([xmax, ymax])
139
+
140
+ bridges = {}
141
+ for idx, bridge in gdf[gdf["bridge"] == "yes"].iterrows():
142
+ if type(bridge["name"]) == str:
143
+ bridges[idx[1]] = {
144
+ "name": bridge["name"],
145
+ "coords": normalize(
146
+ [bridge.geometry.centroid.x, bridge.geometry.centroid.y]
147
+ ),
148
+ }
149
+ return bridges
150
+
151
+
152
+ """
120
153
  # %%
121
154
  if __name__ == "__main__":
122
155
  place = "Thun, Switzerland"
156
+ <<<<<<< HEAD
123
157
  terrain = geography_fn(place, 300)
124
158
 
159
+ =======
160
+ terrain, gdf = geography_fn(place, 300)
161
+
162
+ >>>>>>> aeb13033e57083cc512a60f8f60a3db47a65ac32
125
163
  fig, axes = plt.subplots(1, 5, figsize=(20, 20))
126
- axes[0].imshow(terrain.building, cmap="gray")
127
- axes[1].imshow(terrain.water, cmap="gray")
128
- axes[2].imshow(terrain.forest, cmap="gray")
129
- axes[3].imshow(terrain.building + terrain.water + terrain.forest)
130
- axes[4].imshow(terrain.basemap)
164
+ axes[0].imshow(jnp.rot90(terrain.building), cmap="gray")
165
+ axes[1].imshow(jnp.rot90(terrain.water), cmap="gray")
166
+ axes[2].imshow(jnp.rot90(terrain.forest), cmap="gray")
167
+ axes[3].imshow(jnp.rot90(terrain.building + terrain.water + terrain.forest))
168
+ axes[4].imshow(jnp.rot90(terrain.basemap))
169
+
170
+ # %%
171
+ W, H, _ = terrain.basemap.shape
172
+ bridges = get_bridges(gdf)
173
+
174
+ # %%
175
+ print("Bridges:")
176
+ for bridge in bridges.values():
177
+ x, y = int(bridge["coords"][0]*300), int(bridge["coords"][1]*300)
178
+ print(bridge["name"], f"at ({x}, {y})")
179
+
180
+ # %%
181
+ plt.subplots(figsize=(7,7))
182
+ plt.imshow(jnp.rot90(terrain.basemap))
183
+ X = [b["coords"][0]*W for b in bridges.values()]
184
+ Y = [(1-b["coords"][1])*H for b in bridges.values()]
185
+ plt.scatter(X, Y)
186
+ for i in range(len(X)):
187
+ x,y = int(X[i]), int(Y[i])
188
+ plt.text(x, y, str((int(x/W*300), int((1-(y/H))*300))))
189
+
190
+ # %%
191
+
192
+ # %% [raw]
193
+ # fig, ax = plt.subplots(figsize=(10, 10))
194
+ # gdf.plot(ax=ax, color='lightgray') # Plot all features
195
+ # bridges.plot(ax=ax, color='red') # Highlight bridges in red
196
+ # plt.show()
197
+
198
+ # %%
199
+
200
+ """
parabellum/terrain_db.py CHANGED
@@ -70,9 +70,9 @@ db = {
70
70
  {"line":[0.75, 0.25, 0., 0.2]}, {"line":[0.75, 0.55, 0., 0.19]},
71
71
  {"line":[0.6, 0.25, 0.15, 0.]}], 'water': None, 'forest': None},
72
72
  "playground": {'building': [{"line":[0.5, 0.5, 0.5, 0.]}], 'water': None, 'forest': None},
73
- "water_park": {
74
- 'building': [{"line":[0.5, 0.5, 0.5, 0.]}],
75
- "water": [{"rect":[0., 0.8, 0.1, 0.05]}, {"rect": [0.2, 0.8, 0.8, 0.05]}],
73
+ "playground2": {
74
+ 'building': [],
75
+ "water": [{"rect":[0., 0.8, 0.1, 0.1]}, {"rect": [0.2, 0.8, 0.8, 0.1]}],
76
76
  "forest": [{"rect": [0., 0., 1., 0.2]}]
77
77
  },
78
78
  "triangle": {'building': [{"line": [0.33, 0., 0., 1.]}, {"line": [0.66, 0., 0., 1.]}], 'water': None, 'forest': None},
@@ -81,23 +81,38 @@ db = {
81
81
  "water": [{"rect": [0.15, 0.2, 0.1, 0.5]}, {"rect": [0.4, 0.2, 0.1, 0.5]}, {"rect": [0.2, 0.2, 0.25, 0.1]}],
82
82
  "forest": []
83
83
  },
84
+ "bridges": {
85
+ 'building': [],
86
+ "water": [{"rect": [0.475, 0., 0.05, 0.1]}, {"rect": [0.475, 0.15, 0.05, 0.575]}, {"rect": [0.475, 0.775, 0.05, 1.]},
87
+ {"rect": [0., 0.475, 0.225, 0.05]}, {"rect": [0.275, 0.475, 0.45, 0.05]}, {"rect": [0.775, 0.475, 0.23, 0.05]}],
88
+ "forest": [{"rect": [0.1, 0.625, 0.275, 0.275]}, {"rect": [0.725, 0., 0.3, 0.275]}, ]
89
+ }
84
90
  }
85
91
 
86
92
  # %% [raw]
87
93
  # import matplotlib.pyplot as plt
88
- # size = 50
94
+ # size = 100
89
95
  # raster = np.zeros((size, size))
90
- # rect = [0.2, 0.3, 0.05, 0.4]
96
+ # rect = [0.475, 0., 0.05, 0.1]
97
+ # raster = map_raster_from_rect(raster, rect, size)
98
+ # rect = [0.475, 0.15, 0.05, 0.575]
99
+ # raster = map_raster_from_rect(raster, rect, size)
100
+ # rect = [0.475, 0.775, 0.05, 1.]
91
101
  # raster = map_raster_from_rect(raster, rect, size)
92
- # rect = [0.4, 0.3, 0.05, 0.4]
102
+ #
103
+ # rect = [0., 0.475, 0.225, 0.05]
93
104
  # raster = map_raster_from_rect(raster, rect, size)
94
- # rect = [0.2, 0.3, 0.25, 0.05]
105
+ # rect = [0.275, 0.475, 0.45, 0.05]
95
106
  # raster = map_raster_from_rect(raster, rect, size)
96
- # rect = [0.2, 0.7, 0.25, 0.05]
107
+ # rect = [0.775, 0.475, 0.23, 0.05]
97
108
  # raster = map_raster_from_rect(raster, rect, size)
98
- # rect = [0.6, 0.3, 0.4, 0.45]
109
+ #
110
+ # rect = [0.1, 0.625, 0.275, 0.275]
99
111
  # raster = map_raster_from_rect(raster, rect, size)
100
- # plt.imshow(jnp.rot90(raster))
112
+ # rect = [0.725, 0., 0.3, 0.275]
113
+ # raster = map_raster_from_rect(raster, rect, size)
114
+ #
115
+ # plt.imshow(raster[::-1, :])
101
116
 
102
117
  # %% [markdown]
103
118
  # # Main
@@ -107,11 +122,13 @@ if __name__ == "__main__":
107
122
  import matplotlib.pyplot as plt
108
123
 
109
124
  # %%
110
- terrain = make_terrain(db["u_shape"], size=50)
125
+ terrain = make_terrain(db["bridges"], size=100)
111
126
 
112
127
  # %%
113
128
  plt.imshow(jnp.rot90(terrain.basemap))
114
-
115
- # %%
129
+ bl = (39.5, 5)
130
+ tr = (44.5, 10)
131
+ plt.scatter(bl[0], 49-bl[1])
132
+ plt.scatter(tr[0], 49-tr[1], marker="+")
116
133
 
117
134
  # %%
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: parabellum
3
- Version: 0.3.3
3
+ Version: 0.4.0
4
4
  Summary: Parabellum environment for parallel warfare simulation
5
5
  Home-page: https://github.com/syrkis/parabellum
6
6
  License: MIT
@@ -1,13 +1,13 @@
1
1
  parabellum/__init__.py,sha256=hIOLir7wgaf_HU4j8uos7PaCrofqPQcr3FcMlBsZyr8,406
2
2
  parabellum/aid.py,sha256=BPabjN4BUq1HRhkwbc9pCNsXSF_ALiG8W8cHWTWeEH4,900
3
- parabellum/env.py,sha256=yf5pSmTuFEHS4J4zKTprNTVsOni6bABP9IfWTMrO0OU,22581
4
- parabellum/geo.py,sha256=PwEwspOppTPrHIXDZB_nGPTnVFIvDzbh2WtqzVKMUaM,4198
3
+ parabellum/env.py,sha256=2FDOI90IuoOTFV5DhLLWWMpuaj4mcwoPup24KK-duYI,22907
4
+ parabellum/geo.py,sha256=PJs9UevibuokDVb3oJWNHvYHlMYGCxB5OkNSbDj48vI,6198
5
5
  parabellum/gun.py,sha256=nvsJdcZ2Qd6lbPlAgsUiaLhstTi1UdLQ8kOnbCenucY,2618
6
6
  parabellum/pcg.py,sha256=d8KC_lbc4WUUUPaTdPJSx27VMGioys3jSGOWJ-2EahU,968
7
7
  parabellum/run.py,sha256=Q53__AxzROZNgfZLVU5LDdcT61UMCkmQ_Q5wWUIrnqo,3473
8
- parabellum/terrain_db.py,sha256=XTKlpLAi3ZwoVw4-KS-Eh15NKsBKP-yt8v6FJGUtwdM,3960
8
+ parabellum/terrain_db.py,sha256=5lHzbX94lzkb--cETpraXS42G4T4tKekISpTm4yaYEE,4748
9
9
  parabellum/tps.py,sha256=of-RBdelAbNCHQZd1I22RWmZkwUEh6f161mx0X_G2tE,257
10
10
  parabellum/vis.py,sha256=ABHveJj0fLRWkxOv3LFIXK20QtdGhjskuFLsp7iTFu0,6185
11
- parabellum-0.3.3.dist-info/METADATA,sha256=OzXtMvFmkyMwAv4d3X7YFRAhDLuiuRda2ytgsgAXDIA,2707
12
- parabellum-0.3.3.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
13
- parabellum-0.3.3.dist-info/RECORD,,
11
+ parabellum-0.4.0.dist-info/METADATA,sha256=GrTOPfKE1HHK2R3RR7gpYgLBFzSIgOgDTpt7h3zFlCM,2707
12
+ parabellum-0.4.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
13
+ parabellum-0.4.0.dist-info/RECORD,,