c4dynamics 2.0.3__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.
- c4dynamics/__init__.py +240 -0
- c4dynamics/datasets/__init__.py +95 -0
- c4dynamics/datasets/_manager.py +596 -0
- c4dynamics/datasets/_registry.py +80 -0
- c4dynamics/detectors/__init__.py +37 -0
- c4dynamics/detectors/yolo3_opencv.py +686 -0
- c4dynamics/detectors/yolo3_tf.py +124 -0
- c4dynamics/eqm/__init__.py +324 -0
- c4dynamics/eqm/derivs.py +212 -0
- c4dynamics/eqm/integrate.py +359 -0
- c4dynamics/filters/__init__.py +1373 -0
- c4dynamics/filters/a.py +48 -0
- c4dynamics/filters/ekf.py +320 -0
- c4dynamics/filters/kalman.py +725 -0
- c4dynamics/filters/kalman_v0.py +1071 -0
- c4dynamics/filters/kalman_v1.py +821 -0
- c4dynamics/filters/lowpass.py +123 -0
- c4dynamics/filters/luenberger.py +97 -0
- c4dynamics/rotmat/__init__.py +141 -0
- c4dynamics/rotmat/animate.py +465 -0
- c4dynamics/rotmat/rotmat.py +351 -0
- c4dynamics/sensors/__init__.py +72 -0
- c4dynamics/sensors/lineofsight.py +78 -0
- c4dynamics/sensors/radar.py +740 -0
- c4dynamics/sensors/seeker.py +1030 -0
- c4dynamics/states/__init__.py +327 -0
- c4dynamics/states/lib/__init__.py +320 -0
- c4dynamics/states/lib/datapoint.py +660 -0
- c4dynamics/states/lib/pixelpoint.py +776 -0
- c4dynamics/states/lib/rigidbody.py +677 -0
- c4dynamics/states/state.py +1486 -0
- c4dynamics/utils/__init__.py +44 -0
- c4dynamics/utils/_struct.py +6 -0
- c4dynamics/utils/const.py +130 -0
- c4dynamics/utils/cprint.py +80 -0
- c4dynamics/utils/gen_gif.py +142 -0
- c4dynamics/utils/idx2keys.py +4 -0
- c4dynamics/utils/images_loader.py +63 -0
- c4dynamics/utils/math.py +136 -0
- c4dynamics/utils/plottools.py +140 -0
- c4dynamics/utils/plottracks.py +304 -0
- c4dynamics/utils/printpts.py +36 -0
- c4dynamics/utils/slides_gen.py +64 -0
- c4dynamics/utils/tictoc.py +167 -0
- c4dynamics/utils/video_gen.py +300 -0
- c4dynamics/utils/vidgen.py +182 -0
- c4dynamics-2.0.3.dist-info/METADATA +242 -0
- c4dynamics-2.0.3.dist-info/RECORD +50 -0
- c4dynamics-2.0.3.dist-info/WHEEL +5 -0
- c4dynamics-2.0.3.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,596 @@
|
|
|
1
|
+
from typing import Optional
|
|
2
|
+
import hashlib
|
|
3
|
+
import shutil
|
|
4
|
+
import os, sys
|
|
5
|
+
|
|
6
|
+
sys.path.append('.')
|
|
7
|
+
from c4dynamics.datasets._registry import CACHE_DIR, image_register, video_register, nn_register, d3_register, d3_f16_register
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
imagesmap = {'planes': 'planes.png', 'planes.png': 'planes.png', 'triangle': 'triangle.png', 'triangle.png': 'triangle.png'}
|
|
11
|
+
videosmap = {'aerobatics': 'aerobatics.mp4', 'aerobatics.mp4': 'aerobatics.mp4'
|
|
12
|
+
, 'drifting_car.mp4': 'drifting_car.mp4', 'driftingcar': 'drifting_car.mp4', 'drifting_car': 'drifting_car.mp4'}
|
|
13
|
+
nnsmap = {'yolov3': 'yolov3.weights', 'yolo_v3': 'yolov3.weights', 'yolov3.weights': 'yolov3.weights'}
|
|
14
|
+
d3smap = {'f16': 'f16', 'f_16': 'f16', 'bunny': 'bunny.pcd', 'bunnymesh': 'bunny_mesh.ply', 'bunny_mesh': 'bunny_mesh.ply'
|
|
15
|
+
, 'bunny.pcd': 'bunny.pcd', 'bunnymesh.ply': 'bunny_mesh.ply', 'bunny_mesh.ply': 'bunny_mesh.ply'}
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def image(image_name: str) -> str:
|
|
19
|
+
'''
|
|
20
|
+
Fetches the path of an image from the local cache.
|
|
21
|
+
|
|
22
|
+
`image` downloads and manages image files from `c4dynamics` datasets.
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
.. list-table::
|
|
26
|
+
:widths: 20 80
|
|
27
|
+
:header-rows: 1
|
|
28
|
+
|
|
29
|
+
* - Image Name
|
|
30
|
+
- Description
|
|
31
|
+
|
|
32
|
+
* - planes
|
|
33
|
+
- A 1280x720 snapshot of aerobatic airplanes (planes.png, 300KB)
|
|
34
|
+
|
|
35
|
+
* - triangle
|
|
36
|
+
- A 800x600 image of a triangle (triangle.png, 20KB)
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
The images can be found at
|
|
41
|
+
https://github.com/C4dynamics/C4dynamics/blob/main/datasets/images/
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
Parameters
|
|
45
|
+
----------
|
|
46
|
+
image_name : str
|
|
47
|
+
The name of the image to download
|
|
48
|
+
|
|
49
|
+
Returns
|
|
50
|
+
-------
|
|
51
|
+
out : str
|
|
52
|
+
A path to the image file in the local cache
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
Examples
|
|
56
|
+
--------
|
|
57
|
+
|
|
58
|
+
Import required packages:
|
|
59
|
+
|
|
60
|
+
.. code::
|
|
61
|
+
|
|
62
|
+
>>> import c4dynamics as c4d
|
|
63
|
+
>>> import matplotlib.image as mpimg
|
|
64
|
+
>>> from matplotlib import pyplot as plt
|
|
65
|
+
|
|
66
|
+
**planes**
|
|
67
|
+
|
|
68
|
+
.. code::
|
|
69
|
+
|
|
70
|
+
>>> impath = c4d.datasets.image('planes')
|
|
71
|
+
Fetched successfully
|
|
72
|
+
>>> img = mpimg.imread(impath) # read image
|
|
73
|
+
>>> plt.imshow(img) # doctest: +IGNORE_OUTPUT
|
|
74
|
+
>>> plt.axis('off') # doctest: +IGNORE_OUTPUT
|
|
75
|
+
|
|
76
|
+
.. figure:: /_examples/datasets/planes.png
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
**triangle**
|
|
80
|
+
|
|
81
|
+
.. code::
|
|
82
|
+
|
|
83
|
+
>>> impath = c4d.datasets.image('triangle')
|
|
84
|
+
Fetched successfully
|
|
85
|
+
>>> img = mpimg.imread(impath) # read image
|
|
86
|
+
>>> plt.imshow(img) # doctest: +IGNORE_OUTPUT
|
|
87
|
+
>>> plt.axis('off') # doctest: +IGNORE_OUTPUT
|
|
88
|
+
|
|
89
|
+
.. figure:: /_examples/datasets/triangle.png
|
|
90
|
+
|
|
91
|
+
'''
|
|
92
|
+
|
|
93
|
+
imagein = imagesmap.get(image_name.lower(), None)
|
|
94
|
+
|
|
95
|
+
if imagein is None:
|
|
96
|
+
raise KeyError(f"'{image_name}' is not an image in c4dynamics datasets. Available images are: 'planes', 'triangle'.")
|
|
97
|
+
|
|
98
|
+
filename = image_register.fetch(imagein)
|
|
99
|
+
print('Fetched successfully')
|
|
100
|
+
return filename
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def video(video_name: str) -> str:
|
|
104
|
+
'''
|
|
105
|
+
Fetches the path of a video from the local cache.
|
|
106
|
+
|
|
107
|
+
`video` downloads and manages video files from `c4dynamics` datasets.
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
.. list-table::
|
|
111
|
+
:widths: 20 80
|
|
112
|
+
:header-rows: 1
|
|
113
|
+
|
|
114
|
+
* - Video Name
|
|
115
|
+
- Description
|
|
116
|
+
|
|
117
|
+
* - planes
|
|
118
|
+
- 10 seconds video file of aerobatic airplanes (aerobatics.mp4, 7MB)
|
|
119
|
+
|
|
120
|
+
* - drifting_car
|
|
121
|
+
- 9 seconds video file of a drifting car\\* (drifting_car.mp4, 10MB)
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
The videos can be found at
|
|
125
|
+
https://github.com/C4dynamics/C4dynamics/blob/main/datasets/videos/
|
|
126
|
+
|
|
127
|
+
\\* Used by kind permission of `Abed Ismail <https://www.pexels.com/@abed-ismail>`_
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
Parameters
|
|
131
|
+
----------
|
|
132
|
+
video_name : str
|
|
133
|
+
The name of the video to download
|
|
134
|
+
|
|
135
|
+
Returns
|
|
136
|
+
-------
|
|
137
|
+
out : str
|
|
138
|
+
A path to the video file in the local cache
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
Examples
|
|
142
|
+
--------
|
|
143
|
+
|
|
144
|
+
Import required packages:
|
|
145
|
+
|
|
146
|
+
.. code::
|
|
147
|
+
|
|
148
|
+
>>> import c4dynamics as c4d
|
|
149
|
+
>>> import cv2
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
Fetch and run:
|
|
153
|
+
|
|
154
|
+
.. code::
|
|
155
|
+
|
|
156
|
+
>>> vidpath = c4d.datasets.video('aerobatics')
|
|
157
|
+
Fetched successfully
|
|
158
|
+
>>> cap = cv2.VideoCapture(vidpath)
|
|
159
|
+
>>> while cap.isOpened():
|
|
160
|
+
... ret, frame = cap.read()
|
|
161
|
+
... if not ret: break
|
|
162
|
+
... cv2.imshow('aerobatics', frame)
|
|
163
|
+
... cv2.waitKey(33) # doctest: +IGNORE_OUTPUT
|
|
164
|
+
>>> cap.release()
|
|
165
|
+
>>> cv2.destroyAllWindows()
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
.. figure:: /_examples/datasets/aerobatics.gif
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
'''
|
|
173
|
+
|
|
174
|
+
videoin = videosmap.get(video_name.lower(), None)
|
|
175
|
+
|
|
176
|
+
if videoin is None:
|
|
177
|
+
raise KeyError(f"'{video_name}' is not a video in c4dynamics datasets. An available video is: 'aerobatics'.")
|
|
178
|
+
|
|
179
|
+
filename = video_register.fetch(videoin)
|
|
180
|
+
print('Fetched successfully')
|
|
181
|
+
return filename
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
def nn_model(nn_name: str) -> str:
|
|
185
|
+
'''
|
|
186
|
+
Fetches the path of a neural network model from the local cache.
|
|
187
|
+
|
|
188
|
+
`nn_model` downloads and manages neural network files from `c4dynamics` datasets.
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
.. list-table::
|
|
192
|
+
:widths: 20 80
|
|
193
|
+
:header-rows: 1
|
|
194
|
+
|
|
195
|
+
* - NN Name
|
|
196
|
+
- Description
|
|
197
|
+
|
|
198
|
+
* - YOLOv3
|
|
199
|
+
- Pre-trained weights file (237 MB)
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
YOLOv3 weights file can be found at
|
|
204
|
+
https://pjreddie.com/media/files/yolov3.weights
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
Parameters
|
|
208
|
+
----------
|
|
209
|
+
nn_name : str
|
|
210
|
+
The name of the neural network model to download
|
|
211
|
+
|
|
212
|
+
Returns
|
|
213
|
+
-------
|
|
214
|
+
out : str
|
|
215
|
+
A path to the neural network in the local cache
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
Examples
|
|
219
|
+
--------
|
|
220
|
+
|
|
221
|
+
Import required packages:
|
|
222
|
+
|
|
223
|
+
.. code::
|
|
224
|
+
|
|
225
|
+
>>> import c4dynamics as c4d
|
|
226
|
+
>>> import cv2
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
Print first 5 layers of YOLOv3:
|
|
230
|
+
|
|
231
|
+
.. code::
|
|
232
|
+
|
|
233
|
+
>>> impath = c4d.datasets.nn_model('yolov3')
|
|
234
|
+
Fetched successfully
|
|
235
|
+
>>> net = cv2.dnn.readNet(impath, 'c4dynamics/detectors/yolov3.cfg')
|
|
236
|
+
>>> for i, layer in enumerate(net.getLayerNames()):
|
|
237
|
+
... print(f"Layer {i}:\t{layer}")
|
|
238
|
+
... if i > 4: break
|
|
239
|
+
Layer 0: conv_0
|
|
240
|
+
Layer 1: bn_0
|
|
241
|
+
Layer 2: leaky_1
|
|
242
|
+
Layer 3: conv_1
|
|
243
|
+
Layer 4: bn_1
|
|
244
|
+
Layer 5: leaky_2
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
'''
|
|
248
|
+
|
|
249
|
+
nnin = nnsmap.get(nn_name.lower(), None)
|
|
250
|
+
|
|
251
|
+
if nnin is None:
|
|
252
|
+
raise KeyError(f"'{nn_name}' is not a neural network model in c4dynamics datasets. An available model is: 'yolov3'.")
|
|
253
|
+
|
|
254
|
+
filename = nn_register.fetch(nnin)
|
|
255
|
+
print('Fetched successfully')
|
|
256
|
+
return filename
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
def d3_model(d3_name: str) -> str:
|
|
260
|
+
'''
|
|
261
|
+
Fetches the path of a 3D model from the local cache.
|
|
262
|
+
|
|
263
|
+
|
|
264
|
+
`d3_model` downloads and manages 3D model files from `c4dynamics` datasets.
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
.. list-table::
|
|
268
|
+
:widths: 20 80
|
|
269
|
+
:header-rows: 1
|
|
270
|
+
|
|
271
|
+
* - Model Name
|
|
272
|
+
- Description
|
|
273
|
+
|
|
274
|
+
* - bunny
|
|
275
|
+
- Point cloud file of Stanford bunny (bunny.pcd, 0.4MB)
|
|
276
|
+
|
|
277
|
+
* - bunny_mesh
|
|
278
|
+
- Polygon file of Stanford bunny (bunny_mesh.ply, 3MB)
|
|
279
|
+
|
|
280
|
+
* - F16
|
|
281
|
+
- A folder of 10 stl files, representing the jet parts as fuselage, ailerons,
|
|
282
|
+
cockpit, rudder and stabilators (10 files, total 3MB).
|
|
283
|
+
|
|
284
|
+
|
|
285
|
+
The models can be found at
|
|
286
|
+
https://github.com/C4dynamics/C4dynamics/blob/main/datasets/d3_models/
|
|
287
|
+
|
|
288
|
+
|
|
289
|
+
|
|
290
|
+
Parameters
|
|
291
|
+
----------
|
|
292
|
+
d3_name : str
|
|
293
|
+
The name of the 3D model to download
|
|
294
|
+
|
|
295
|
+
Returns
|
|
296
|
+
-------
|
|
297
|
+
out : str
|
|
298
|
+
A path to the model in the local cache.
|
|
299
|
+
For the `f16` model, the function returns a path
|
|
300
|
+
to the folder including 10 files.
|
|
301
|
+
|
|
302
|
+
|
|
303
|
+
Examples
|
|
304
|
+
--------
|
|
305
|
+
|
|
306
|
+
**Stanford bunny (point cloud)**
|
|
307
|
+
|
|
308
|
+
Import required packages:
|
|
309
|
+
|
|
310
|
+
.. code::
|
|
311
|
+
|
|
312
|
+
>>> import c4dynamics as c4d
|
|
313
|
+
>>> import open3d as o3d
|
|
314
|
+
>>> import os
|
|
315
|
+
|
|
316
|
+
|
|
317
|
+
.. code::
|
|
318
|
+
|
|
319
|
+
>>> bunnypath = c4d.datasets.d3_model('bunny')
|
|
320
|
+
Fetched successfully
|
|
321
|
+
>>> pcd = o3d.io.read_point_cloud(bunnypath)
|
|
322
|
+
>>> print(pcd)
|
|
323
|
+
PointCloud with 35947 points.
|
|
324
|
+
>>> o3d.visualization.draw_geometries([pcd])
|
|
325
|
+
|
|
326
|
+
.. figure:: /_examples/datasets/bunny.png
|
|
327
|
+
|
|
328
|
+
|
|
329
|
+
**Stanford bunny (triangle mesh)**
|
|
330
|
+
|
|
331
|
+
.. code::
|
|
332
|
+
|
|
333
|
+
>>> mbunnypath = c4d.datasets.d3_model('bunny_mesh')
|
|
334
|
+
Fetched successfully
|
|
335
|
+
>>> ply = o3d.io.read_triangle_mesh(mbunnypath)
|
|
336
|
+
>>> ply.compute_vertex_normals() # doctest: +IGNORE_OUTPUT
|
|
337
|
+
>>> print(ply)
|
|
338
|
+
TriangleMesh with 35947 points and 69451 triangles.
|
|
339
|
+
>>> o3d.visualization.draw_geometries([ply])
|
|
340
|
+
|
|
341
|
+
.. figure:: /_examples/datasets/bunny_mesh.png
|
|
342
|
+
|
|
343
|
+
|
|
344
|
+
**F16 (10 stl files)**
|
|
345
|
+
|
|
346
|
+
.. code::
|
|
347
|
+
|
|
348
|
+
>>> f16path = c4d.datasets.d3_model('f16')
|
|
349
|
+
Fetched successfully
|
|
350
|
+
>>> model = []
|
|
351
|
+
>>> for f in sorted(os.listdir(f16path)):
|
|
352
|
+
... model.append(o3d.io.read_triangle_mesh(os.path.join(f16path, f)).compute_vertex_normals())
|
|
353
|
+
>>> o3d.visualization.draw_geometries(model)
|
|
354
|
+
|
|
355
|
+
|
|
356
|
+
.. figure:: /_examples/datasets/f16.png
|
|
357
|
+
|
|
358
|
+
|
|
359
|
+
'''
|
|
360
|
+
|
|
361
|
+
d3in = d3smap.get(d3_name.lower(), None)
|
|
362
|
+
|
|
363
|
+
if d3in is None:
|
|
364
|
+
raise KeyError(f"'{d3_name}' is not a 3D model in c4dynamics datasets. Available models are: 'bunny', 'bunny_mesh', 'f16'.")
|
|
365
|
+
|
|
366
|
+
|
|
367
|
+
# returns path
|
|
368
|
+
if d3in == 'f16':
|
|
369
|
+
d3_f16_register.fetch('Aileron_A_F16.stl')
|
|
370
|
+
d3_f16_register.fetch('Aileron_B_F16.stl')
|
|
371
|
+
d3_f16_register.fetch('Body_F16.stl')
|
|
372
|
+
d3_f16_register.fetch('Cockpit_F16.stl')
|
|
373
|
+
d3_f16_register.fetch('LE_Slat_A_F16.stl')
|
|
374
|
+
d3_f16_register.fetch('LE_Slat_B_F16.stl')
|
|
375
|
+
d3_f16_register.fetch('Rudder_F16.stl')
|
|
376
|
+
d3_f16_register.fetch('Stabilator_A_F16.stl')
|
|
377
|
+
filename = os.path.dirname(d3_f16_register.fetch('Stabilator_B_F16.stl'))
|
|
378
|
+
|
|
379
|
+
else:
|
|
380
|
+
filename = d3_register.fetch(d3in)
|
|
381
|
+
|
|
382
|
+
|
|
383
|
+
print('Fetched successfully')
|
|
384
|
+
return filename
|
|
385
|
+
|
|
386
|
+
|
|
387
|
+
def download_all() -> None:
|
|
388
|
+
'''
|
|
389
|
+
Downloads all available datasets to the local cache.
|
|
390
|
+
|
|
391
|
+
The `download_all` function fetches all predefined datasets,
|
|
392
|
+
including images, videos, neural network models, and 3D models,
|
|
393
|
+
and stores them in the local cache.
|
|
394
|
+
|
|
395
|
+
This function is a convenient way to ensure that all necessary data files are locally
|
|
396
|
+
available for use without having to download each individually.
|
|
397
|
+
|
|
398
|
+
The datasets include:
|
|
399
|
+
|
|
400
|
+
.. list-table::
|
|
401
|
+
:widths: 20 80
|
|
402
|
+
:header-rows: 1
|
|
403
|
+
|
|
404
|
+
* - Dataset Type
|
|
405
|
+
- Included Files
|
|
406
|
+
|
|
407
|
+
* - Images
|
|
408
|
+
- 'planes.png', 'triangle.png'
|
|
409
|
+
|
|
410
|
+
* - Videos
|
|
411
|
+
- 'aerobatics.mp4', 'drifting_car.mp4'
|
|
412
|
+
|
|
413
|
+
* - Neural Networks
|
|
414
|
+
- 'yolov3.weights'
|
|
415
|
+
|
|
416
|
+
* - 3D Models
|
|
417
|
+
- 'bunny.pcd', 'bunny_mesh.ply', 'f16' (multiple STL files)
|
|
418
|
+
|
|
419
|
+
This function ensures all resources are fetched into the cache directory,
|
|
420
|
+
making them accessible for further processing.
|
|
421
|
+
|
|
422
|
+
Examples
|
|
423
|
+
--------
|
|
424
|
+
|
|
425
|
+
**Download all datasets**
|
|
426
|
+
|
|
427
|
+
.. code::
|
|
428
|
+
|
|
429
|
+
>>> import c4dynamics as c4d
|
|
430
|
+
|
|
431
|
+
.. code::
|
|
432
|
+
|
|
433
|
+
>>> c4d.datasets.download_all()
|
|
434
|
+
Fetched successfully
|
|
435
|
+
Fetched successfully
|
|
436
|
+
Fetched successfully
|
|
437
|
+
Fetched successfully
|
|
438
|
+
Fetched successfully
|
|
439
|
+
Fetched successfully
|
|
440
|
+
Fetched successfully
|
|
441
|
+
|
|
442
|
+
After downloading, you can access each dataset using its
|
|
443
|
+
corresponding function, such as `image`, `video`, `nn_model`, or `d3_model`.
|
|
444
|
+
|
|
445
|
+
'''
|
|
446
|
+
image('planes')
|
|
447
|
+
image('triangle')
|
|
448
|
+
video('aerobatics')
|
|
449
|
+
nn_model('yolov3')
|
|
450
|
+
d3_model('bunny')
|
|
451
|
+
d3_model('bunny_mesh')
|
|
452
|
+
d3_model('f16')
|
|
453
|
+
|
|
454
|
+
|
|
455
|
+
|
|
456
|
+
def clear_cache(dataset: Optional[str] = None) -> None:
|
|
457
|
+
'''
|
|
458
|
+
Deletes datasets from the local cache.
|
|
459
|
+
|
|
460
|
+
If a dataset name is provided, the function deletes this alone.
|
|
461
|
+
Otherwise, clears all the cache.
|
|
462
|
+
|
|
463
|
+
|
|
464
|
+
Parameters
|
|
465
|
+
----------
|
|
466
|
+
dataset : str, optional
|
|
467
|
+
The name of the dataset to delete.
|
|
468
|
+
|
|
469
|
+
|
|
470
|
+
|
|
471
|
+
Examples
|
|
472
|
+
--------
|
|
473
|
+
|
|
474
|
+
.. code::
|
|
475
|
+
|
|
476
|
+
>>> import c4dynamics as c4d
|
|
477
|
+
>>> from matplotlib import pyplot as plt
|
|
478
|
+
>>> import matplotlib.image as mpimg
|
|
479
|
+
>>> import os
|
|
480
|
+
|
|
481
|
+
**Delete a dataset file**
|
|
482
|
+
|
|
483
|
+
.. code::
|
|
484
|
+
|
|
485
|
+
>>> # download and verify
|
|
486
|
+
>>> impath = c4d.datasets.image('planes')
|
|
487
|
+
Fetched successfully
|
|
488
|
+
>>> print(os.path.exists(impath))
|
|
489
|
+
True
|
|
490
|
+
>>> # clear and verify
|
|
491
|
+
>>> c4d.datasets.clear_cache('planes')
|
|
492
|
+
>>> print(os.path.exists(impath))
|
|
493
|
+
False
|
|
494
|
+
|
|
495
|
+
**Clear all**
|
|
496
|
+
|
|
497
|
+
.. code::
|
|
498
|
+
|
|
499
|
+
>>> # download all
|
|
500
|
+
>>> c4d.datasets.download_all()
|
|
501
|
+
Fetched successfully
|
|
502
|
+
Fetched successfully
|
|
503
|
+
Fetched successfully
|
|
504
|
+
Fetched successfully
|
|
505
|
+
Fetched successfully
|
|
506
|
+
Fetched successfully
|
|
507
|
+
Fetched successfully
|
|
508
|
+
>>> # clear all and verify
|
|
509
|
+
>>> c4d.datasets.clear_cache()
|
|
510
|
+
>>> for root, dirs, files in os.walk(CACHE_DIR):
|
|
511
|
+
... for file in files:
|
|
512
|
+
... print(os.path.join(root, file))
|
|
513
|
+
... for dir in dirs:
|
|
514
|
+
... print(os.path.join(root, dir))
|
|
515
|
+
|
|
516
|
+
'''
|
|
517
|
+
|
|
518
|
+
if dataset is None:
|
|
519
|
+
for root, dirs, files in os.walk(CACHE_DIR):
|
|
520
|
+
for file in files:
|
|
521
|
+
os.remove(os.path.join(root, file))
|
|
522
|
+
for dir in dirs:
|
|
523
|
+
shutil.rmtree(os.path.join(root, dir))
|
|
524
|
+
return
|
|
525
|
+
|
|
526
|
+
|
|
527
|
+
|
|
528
|
+
allmaps = imagesmap | videosmap | nnsmap | d3smap
|
|
529
|
+
datain = allmaps.get(dataset.lower(), None)
|
|
530
|
+
|
|
531
|
+
if datain is None:
|
|
532
|
+
raise KeyError(f"'{dataset}' is not a dataset in c4dynamics.")
|
|
533
|
+
|
|
534
|
+
datafile = os.path.join(CACHE_DIR, datain)
|
|
535
|
+
if datain == 'f16':
|
|
536
|
+
shutil.rmtree(datafile)
|
|
537
|
+
else:
|
|
538
|
+
if os.path.exists(datafile):
|
|
539
|
+
os.remove(datafile)
|
|
540
|
+
|
|
541
|
+
|
|
542
|
+
|
|
543
|
+
|
|
544
|
+
|
|
545
|
+
|
|
546
|
+
def sha256(filename: str) -> str:
|
|
547
|
+
'''
|
|
548
|
+
Computes the SHA-256 hash of a file.
|
|
549
|
+
|
|
550
|
+
Parameters
|
|
551
|
+
----------
|
|
552
|
+
filename : str
|
|
553
|
+
Path to the file for which the hash needs to be computed.
|
|
554
|
+
|
|
555
|
+
Returns
|
|
556
|
+
-------
|
|
557
|
+
str
|
|
558
|
+
The SHA-256 hash of the file.
|
|
559
|
+
|
|
560
|
+
'''
|
|
561
|
+
|
|
562
|
+
# filehash = pooch.file_hash(r'C:\Users\odely\Downloads\yolov3 (1).weights')
|
|
563
|
+
|
|
564
|
+
hash_sha256 = hashlib.sha256()
|
|
565
|
+
with open(filename, 'rb') as f:
|
|
566
|
+
for byte_block in iter(lambda: f.read(4096), b""):
|
|
567
|
+
hash_sha256.update(byte_block)
|
|
568
|
+
return hash_sha256.hexdigest()
|
|
569
|
+
|
|
570
|
+
|
|
571
|
+
|
|
572
|
+
|
|
573
|
+
if __name__ == "__main__":
|
|
574
|
+
|
|
575
|
+
import doctest, contextlib
|
|
576
|
+
from c4dynamics import IgnoreOutputChecker, cprint
|
|
577
|
+
|
|
578
|
+
# Register the custom OutputChecker
|
|
579
|
+
doctest.OutputChecker = IgnoreOutputChecker
|
|
580
|
+
|
|
581
|
+
tofile = False
|
|
582
|
+
optionflags = doctest.FAIL_FAST
|
|
583
|
+
|
|
584
|
+
if tofile:
|
|
585
|
+
with open(os.path.join('tests', '_out', 'output.txt'), 'w') as f:
|
|
586
|
+
with contextlib.redirect_stdout(f), contextlib.redirect_stderr(f):
|
|
587
|
+
result = doctest.testmod(optionflags = optionflags)
|
|
588
|
+
else:
|
|
589
|
+
result = doctest.testmod(optionflags = optionflags)
|
|
590
|
+
|
|
591
|
+
if result.failed == 0:
|
|
592
|
+
cprint(os.path.basename(__file__) + ": all tests passed!", 'g')
|
|
593
|
+
else:
|
|
594
|
+
print(f"{result.failed}")
|
|
595
|
+
|
|
596
|
+
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import pooch
|
|
2
|
+
import os
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
CACHE_DIR = os.path.join(pooch.os_cache(''), 'c4data')
|
|
6
|
+
|
|
7
|
+
image_register = pooch.create(
|
|
8
|
+
path = CACHE_DIR
|
|
9
|
+
, base_url = ''
|
|
10
|
+
, registry = {
|
|
11
|
+
'planes.png': '9bd39926e073a9092847803a18dfcc47a5a030a9e9cdb0f0e6ec2b7bc4479481'
|
|
12
|
+
, 'triangle.png': 'd2da7a29c269b05ab77ec77044ce36d3866d207cea0032af5ab7e8fc8e7f0580'
|
|
13
|
+
}
|
|
14
|
+
, urls = {
|
|
15
|
+
'planes.png': 'https://github.com/C4dynamics/C4dynamics/blob/main/datasets/images/planes.png?raw=true'
|
|
16
|
+
, 'triangle.png': 'https://github.com/C4dynamics/C4dynamics/blob/main/datasets/images/triangle.png?raw=true'
|
|
17
|
+
}
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
video_register = pooch.create(
|
|
21
|
+
path = CACHE_DIR
|
|
22
|
+
, base_url = ''
|
|
23
|
+
, registry = {'aerobatics.mp4': '4ca78c67dc199793f975caf4fca0039958d290b9af8ae46b0f87863181336afe'
|
|
24
|
+
, 'drifting_car.mp4': 'c490de3c27ade26915b20a8130c9dd58d6a45c7152ea92cd059d31c4a5c370ec'}
|
|
25
|
+
, urls = {'aerobatics.mp4': 'https://github.com/C4dynamics/C4dynamics/blob/main/datasets/videos/aerobatics.mp4?raw=true'
|
|
26
|
+
, 'drifting_car.mp4': 'https://github.com/C4dynamics/C4dynamics/blob/main/datasets/videos/drifting_car.mp4?raw=true'}
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
nn_register = pooch.create(
|
|
30
|
+
path = CACHE_DIR
|
|
31
|
+
, base_url = ''
|
|
32
|
+
, registry = {
|
|
33
|
+
'yolov3.weights': '523e4e69e1d015393a1b0a441cef1d9c7659e3eb2d7e15f793f060a21b32f297'
|
|
34
|
+
}
|
|
35
|
+
, urls = {
|
|
36
|
+
'yolov3.weights': 'https://pjreddie.com/media/files/yolov3.weights'
|
|
37
|
+
}
|
|
38
|
+
, retry_if_failed = 1
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
d3_f16_register = pooch.create(
|
|
42
|
+
path = os.path.join(CACHE_DIR, 'f16')
|
|
43
|
+
, base_url = ''
|
|
44
|
+
, registry = {
|
|
45
|
+
'Aileron_A_F16.stl': '43cdd5ef230eac34e9dd3aa727eed25500eeb4ab3733dc480c1c6b6be8ecc60f'
|
|
46
|
+
, 'Aileron_B_F16.stl': 'b59da3a237b10da2991af7850b033a584177b47eb1405928ca6a785bb6dc3935'
|
|
47
|
+
, 'Body_F16.stl': '9f1a4de66fba156079c3049756b5f1aaaeb23250a6c90f6bf566ccc693d8baa0'
|
|
48
|
+
, 'Cockpit_F16.stl': 'd6e5fdca6e645df42e6b417346c313a8981d6c5c468362bf05f7bb607e719627'
|
|
49
|
+
, 'LE_Slat_A_F16.stl': 'dbfb18d5dccf8ee56c4a198b425f6569e23ed09a6c993f9fd97306e5bac12f35'
|
|
50
|
+
, 'LE_Slat_B_F16.stl': '4a38c338767e671f09ac1c180f8983390c4441fb29a9398a6d9ba49092db1ae6'
|
|
51
|
+
, 'Rudder_F16.stl': '8315ca56856cf9efd16937b738eeb436ccd566071d0817d85d5f943be6632769'
|
|
52
|
+
, 'Stabilator_A_F16.stl': 'a8074ddb0deea10cf5f764a81f68ea3b792201dd14b303b9a1c620cde88f6201'
|
|
53
|
+
, 'Stabilator_B_F16.stl': '0c1192f5244f073086233466845350b735f6e9fce04a44a77fa93799754e6aec'
|
|
54
|
+
}
|
|
55
|
+
, urls = {
|
|
56
|
+
'Aileron_A_F16.stl': r'https://github.com/C4dynamics/C4dynamics/blob/main/datasets/d3_models/f16/Aileron_A_F16.stl?raw=true'
|
|
57
|
+
, 'Aileron_B_F16.stl': r'https://github.com/C4dynamics/C4dynamics/blob/main/datasets/d3_models/f16/Aileron_B_F16.stl?raw=true'
|
|
58
|
+
, 'Body_F16.stl': r'https://github.com/C4dynamics/C4dynamics/blob/main/datasets/d3_models/f16/Body_F16.stl?raw=true'
|
|
59
|
+
, 'Cockpit_F16.stl': r'https://github.com/C4dynamics/C4dynamics/blob/main/datasets/d3_models/f16/Cockpit_F16.stl?raw=true'
|
|
60
|
+
, 'LE_Slat_A_F16.stl': r'https://github.com/C4dynamics/C4dynamics/blob/main/datasets/d3_models/f16/LE_Slat_A_F16.stl?raw=true'
|
|
61
|
+
, 'LE_Slat_B_F16.stl': r'https://github.com/C4dynamics/C4dynamics/blob/main/datasets/d3_models/f16/LE_Slat_B_F16.stl?raw=true'
|
|
62
|
+
, 'Rudder_F16.stl': r'https://github.com/C4dynamics/C4dynamics/blob/main/datasets/d3_models/f16/Rudder_F16.stl?raw=true'
|
|
63
|
+
, 'Stabilator_A_F16.stl': r'https://github.com/C4dynamics/C4dynamics/blob/main/datasets/d3_models/f16/Stabilator_A_F16.stl?raw=true'
|
|
64
|
+
, 'Stabilator_B_F16.stl': r'https://github.com/C4dynamics/C4dynamics/blob/main/datasets/d3_models/f16/Stabilator_B_F16.stl?raw=true'
|
|
65
|
+
}
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
d3_register = pooch.create(
|
|
69
|
+
path = CACHE_DIR
|
|
70
|
+
, base_url = ''
|
|
71
|
+
, registry = {
|
|
72
|
+
'bunny.pcd': '64e10d06e9b9f9b7e4a728b0eff399334abe017cbf168e6c0ff39f01a025acc9'
|
|
73
|
+
, 'bunny_mesh.ply': 'b1acc63bece78444aa2e15bdcc72371a201279b98c6f5d4b74c993d02f0566fe'
|
|
74
|
+
}
|
|
75
|
+
, urls = {
|
|
76
|
+
'bunny.pcd': r'https://github.com/C4dynamics/C4dynamics/blob/main/datasets/d3_models/bunny.pcd?raw=true'
|
|
77
|
+
, 'bunny_mesh.ply': r'https://github.com/C4dynamics/C4dynamics/blob/main/datasets/d3_models/bunny_mesh.ply?raw=true'
|
|
78
|
+
}
|
|
79
|
+
)
|
|
80
|
+
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
'''
|
|
2
|
+
|
|
3
|
+
`c4dynamics` provides an API to third party object detection models.
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
'''
|
|
7
|
+
|
|
8
|
+
import os, sys
|
|
9
|
+
sys.path.append('.')
|
|
10
|
+
|
|
11
|
+
from c4dynamics.detectors.yolo3_opencv import yolov3
|
|
12
|
+
|
|
13
|
+
if __name__ == "__main__":
|
|
14
|
+
|
|
15
|
+
import doctest, contextlib
|
|
16
|
+
from c4dynamics import IgnoreOutputChecker, cprint
|
|
17
|
+
|
|
18
|
+
# Register the custom OutputChecker
|
|
19
|
+
doctest.OutputChecker = IgnoreOutputChecker
|
|
20
|
+
|
|
21
|
+
tofile = False
|
|
22
|
+
optionflags = doctest.FAIL_FAST
|
|
23
|
+
|
|
24
|
+
if tofile:
|
|
25
|
+
with open(os.path.join('tests', '_out', 'output.txt'), 'w') as f:
|
|
26
|
+
with contextlib.redirect_stdout(f), contextlib.redirect_stderr(f):
|
|
27
|
+
result = doctest.testmod(optionflags = optionflags)
|
|
28
|
+
else:
|
|
29
|
+
result = doctest.testmod(optionflags = optionflags)
|
|
30
|
+
|
|
31
|
+
if result.failed == 0:
|
|
32
|
+
cprint(os.path.basename(__file__) + ": all tests passed!", 'g')
|
|
33
|
+
else:
|
|
34
|
+
print(f"{result.failed}")
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|