c4dynamics 2.3.4__tar.gz → 2.3.6__tar.gz

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.
Files changed (118) hide show
  1. {c4dynamics-2.3.4 → c4dynamics-2.3.6}/PKG-INFO +16 -35
  2. {c4dynamics-2.3.4 → c4dynamics-2.3.6}/README.md +1 -3
  3. c4dynamics-2.3.6/c4dynamics/__init__.py +326 -0
  4. c4dynamics-2.3.6/c4dynamics/datasets/__init__.py +109 -0
  5. c4dynamics-2.3.6/c4dynamics/datasets/_manager.py +649 -0
  6. c4dynamics-2.3.6/c4dynamics/datasets/_registry.py +84 -0
  7. c4dynamics-2.3.6/c4dynamics/detectors/__init__.py +26 -0
  8. {c4dynamics-2.3.4 → c4dynamics-2.3.6}/c4dynamics/detectors/yolo3_opencv.py +377 -302
  9. c4dynamics-2.3.6/c4dynamics/detectors/yolov3.cfg +788 -0
  10. c4dynamics-2.3.6/c4dynamics/envs/__init__.py +11 -0
  11. c4dynamics-2.3.6/c4dynamics/envs/mountain_car.py +903 -0
  12. c4dynamics-2.3.6/c4dynamics/eqm/__init__.py +33 -0
  13. c4dynamics-2.3.6/c4dynamics/eqm/derivs.py +192 -0
  14. {c4dynamics-2.3.4 → c4dynamics-2.3.6}/c4dynamics/eqm/integrate.py +188 -181
  15. {c4dynamics-2.3.4 → c4dynamics-2.3.6}/c4dynamics/filters/__init__.py +76 -75
  16. c4dynamics-2.3.6/c4dynamics/filters/ekf.py +300 -0
  17. c4dynamics-2.3.6/c4dynamics/filters/kalman.py +733 -0
  18. c4dynamics-2.3.6/c4dynamics/filters/lowpass.py +131 -0
  19. c4dynamics-2.3.6/c4dynamics/rotmat/__init__.py +33 -0
  20. c4dynamics-2.3.6/c4dynamics/rotmat/animate.py +467 -0
  21. {c4dynamics-2.3.4 → c4dynamics-2.3.6}/c4dynamics/rotmat/rotmat.py +109 -107
  22. c4dynamics-2.3.6/c4dynamics/sensors/__init__.py +64 -0
  23. c4dynamics-2.3.6/c4dynamics/sensors/lineofsight.py +74 -0
  24. c4dynamics-2.3.6/c4dynamics/sensors/radar.py +762 -0
  25. c4dynamics-2.3.6/c4dynamics/sensors/seeker.py +1034 -0
  26. c4dynamics-2.3.6/c4dynamics/states/__init__.py +29 -0
  27. {c4dynamics-2.3.4 → c4dynamics-2.3.6}/c4dynamics/states/lib/__init__.py +13 -19
  28. c4dynamics-2.3.6/c4dynamics/states/lib/datapoint.py +625 -0
  29. c4dynamics-2.3.6/c4dynamics/states/lib/pixelpoint.py +621 -0
  30. c4dynamics-2.3.6/c4dynamics/states/lib/rigidbody.py +649 -0
  31. c4dynamics-2.3.6/c4dynamics/states/state.py +1557 -0
  32. c4dynamics-2.3.6/c4dynamics/utils/__init__.py +28 -0
  33. c4dynamics-2.3.6/c4dynamics/utils/_struct.py +10 -0
  34. {c4dynamics-2.3.4 → c4dynamics-2.3.6}/c4dynamics/utils/const.py +25 -27
  35. {c4dynamics-2.3.4 → c4dynamics-2.3.6}/c4dynamics/utils/cprint.py +37 -29
  36. c4dynamics-2.3.6/c4dynamics/utils/gen_gif.py +142 -0
  37. {c4dynamics-2.3.4 → c4dynamics-2.3.6}/c4dynamics/utils/idx2keys.py +2 -1
  38. {c4dynamics-2.3.4 → c4dynamics-2.3.6}/c4dynamics/utils/images_loader.py +12 -11
  39. c4dynamics-2.3.6/c4dynamics/utils/math.py +163 -0
  40. c4dynamics-2.3.6/c4dynamics/utils/plottools.py +95 -0
  41. c4dynamics-2.3.6/c4dynamics/utils/plottracks.py +369 -0
  42. c4dynamics-2.3.6/c4dynamics/utils/printpts.py +36 -0
  43. c4dynamics-2.3.6/c4dynamics/utils/slides_gen.py +66 -0
  44. c4dynamics-2.3.6/c4dynamics/utils/tictoc.py +170 -0
  45. c4dynamics-2.3.6/c4dynamics/utils/video_gen.py +337 -0
  46. c4dynamics-2.3.6/c4dynamics/utils/vidgen.py +173 -0
  47. {c4dynamics-2.3.4 → c4dynamics-2.3.6}/c4dynamics.egg-info/PKG-INFO +16 -35
  48. {c4dynamics-2.3.4 → c4dynamics-2.3.6}/c4dynamics.egg-info/SOURCES.txt +2 -0
  49. c4dynamics-2.3.6/c4dynamics.egg-info/requires.txt +17 -0
  50. c4dynamics-2.3.6/pyproject.toml +81 -0
  51. c4dynamics-2.3.6/setup.cfg +25 -0
  52. c4dynamics-2.3.6/setup.py +67 -0
  53. {c4dynamics-2.3.4 → c4dynamics-2.3.6}/tests/test_animate.py +27 -31
  54. {c4dynamics-2.3.4 → c4dynamics-2.3.6}/tests/test_const.py +7 -3
  55. {c4dynamics-2.3.4 → c4dynamics-2.3.6}/tests/test_cprint.py +4 -2
  56. {c4dynamics-2.3.4 → c4dynamics-2.3.6}/tests/test_datapoint.py +15 -12
  57. c4dynamics-2.3.6/tests/test_datasets.py +130 -0
  58. {c4dynamics-2.3.4 → c4dynamics-2.3.6}/tests/test_derivs.py +7 -4
  59. {c4dynamics-2.3.4 → c4dynamics-2.3.6}/tests/test_ekf.py +14 -24
  60. {c4dynamics-2.3.4 → c4dynamics-2.3.6}/tests/test_gen_gif.py +16 -24
  61. {c4dynamics-2.3.4 → c4dynamics-2.3.6}/tests/test_integrate.py +46 -16
  62. {c4dynamics-2.3.4 → c4dynamics-2.3.6}/tests/test_kalman.py +42 -41
  63. {c4dynamics-2.3.4 → c4dynamics-2.3.6}/tests/test_lowpass.py +6 -4
  64. {c4dynamics-2.3.4 → c4dynamics-2.3.6}/tests/test_math.py +4 -4
  65. {c4dynamics-2.3.4 → c4dynamics-2.3.6}/tests/test_pixelpoint.py +11 -11
  66. {c4dynamics-2.3.4 → c4dynamics-2.3.6}/tests/test_plotdefaults.py +7 -5
  67. {c4dynamics-2.3.4 → c4dynamics-2.3.6}/tests/test_radar.py +17 -9
  68. {c4dynamics-2.3.4 → c4dynamics-2.3.6}/tests/test_rigidbody.py +22 -10
  69. {c4dynamics-2.3.4 → c4dynamics-2.3.6}/tests/test_rotmat.py +7 -6
  70. {c4dynamics-2.3.4 → c4dynamics-2.3.6}/tests/test_seeker.py +12 -7
  71. {c4dynamics-2.3.4 → c4dynamics-2.3.6}/tests/test_state.py +45 -27
  72. {c4dynamics-2.3.4 → c4dynamics-2.3.6}/tests/test_state_assignment_strict.py +17 -11
  73. c4dynamics-2.3.6/tests/test_tictoc.py +43 -0
  74. {c4dynamics-2.3.4 → c4dynamics-2.3.6}/tests/test_yolov3_opencv.py +28 -19
  75. c4dynamics-2.3.4/c4dynamics/__init__.py +0 -315
  76. c4dynamics-2.3.4/c4dynamics/datasets/__init__.py +0 -97
  77. c4dynamics-2.3.4/c4dynamics/datasets/_manager.py +0 -619
  78. c4dynamics-2.3.4/c4dynamics/datasets/_registry.py +0 -83
  79. c4dynamics-2.3.4/c4dynamics/detectors/__init__.py +0 -26
  80. c4dynamics-2.3.4/c4dynamics/envs/__init__.py +0 -13
  81. c4dynamics-2.3.4/c4dynamics/envs/mountain_car.py +0 -880
  82. c4dynamics-2.3.4/c4dynamics/eqm/__init__.py +0 -36
  83. c4dynamics-2.3.4/c4dynamics/eqm/derivs.py +0 -194
  84. c4dynamics-2.3.4/c4dynamics/filters/ekf.py +0 -302
  85. c4dynamics-2.3.4/c4dynamics/filters/kalman.py +0 -709
  86. c4dynamics-2.3.4/c4dynamics/filters/lowpass.py +0 -123
  87. c4dynamics-2.3.4/c4dynamics/rotmat/__init__.py +0 -36
  88. c4dynamics-2.3.4/c4dynamics/rotmat/animate.py +0 -460
  89. c4dynamics-2.3.4/c4dynamics/sensors/__init__.py +0 -65
  90. c4dynamics-2.3.4/c4dynamics/sensors/lineofsight.py +0 -78
  91. c4dynamics-2.3.4/c4dynamics/sensors/radar.py +0 -721
  92. c4dynamics-2.3.4/c4dynamics/sensors/seeker.py +0 -1006
  93. c4dynamics-2.3.4/c4dynamics/states/__init__.py +0 -33
  94. c4dynamics-2.3.4/c4dynamics/states/lib/datapoint.py +0 -639
  95. c4dynamics-2.3.4/c4dynamics/states/lib/pixelpoint.py +0 -774
  96. c4dynamics-2.3.4/c4dynamics/states/lib/rigidbody.py +0 -647
  97. c4dynamics-2.3.4/c4dynamics/states/state.py +0 -1539
  98. c4dynamics-2.3.4/c4dynamics/utils/__init__.py +0 -27
  99. c4dynamics-2.3.4/c4dynamics/utils/_struct.py +0 -10
  100. c4dynamics-2.3.4/c4dynamics/utils/gen_gif.py +0 -135
  101. c4dynamics-2.3.4/c4dynamics/utils/math.py +0 -124
  102. c4dynamics-2.3.4/c4dynamics/utils/plottools.py +0 -123
  103. c4dynamics-2.3.4/c4dynamics/utils/plottracks.py +0 -307
  104. c4dynamics-2.3.4/c4dynamics/utils/printpts.py +0 -39
  105. c4dynamics-2.3.4/c4dynamics/utils/slides_gen.py +0 -67
  106. c4dynamics-2.3.4/c4dynamics/utils/tictoc.py +0 -174
  107. c4dynamics-2.3.4/c4dynamics/utils/video_gen.py +0 -302
  108. c4dynamics-2.3.4/c4dynamics/utils/vidgen.py +0 -185
  109. c4dynamics-2.3.4/c4dynamics.egg-info/requires.txt +0 -45
  110. c4dynamics-2.3.4/pyproject.toml +0 -51
  111. c4dynamics-2.3.4/setup.cfg +0 -4
  112. c4dynamics-2.3.4/setup.py +0 -63
  113. c4dynamics-2.3.4/tests/test_datasets.py +0 -124
  114. c4dynamics-2.3.4/tests/test_tictoc.py +0 -43
  115. {c4dynamics-2.3.4 → c4dynamics-2.3.6}/LICENSE +0 -0
  116. {c4dynamics-2.3.4 → c4dynamics-2.3.6}/c4dynamics.egg-info/dependency_links.txt +0 -0
  117. {c4dynamics-2.3.4 → c4dynamics-2.3.6}/c4dynamics.egg-info/top_level.txt +0 -0
  118. {c4dynamics-2.3.4 → c4dynamics-2.3.6}/tests/test_state_assignment.py +0 -0
@@ -1,11 +1,22 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: c4dynamics
3
- Version: 2.3.4
3
+ Version: 2.3.6
4
4
  Summary: Python framework for state-space modeling and algorithm development
5
- Author: c4dynamics
6
5
  Author-email: Ziv Meri <zivmeri@gmail.com>
7
6
  License-Expression: MIT
8
- Requires-Python: >=3.8,<3.13
7
+ Project-URL: Homepage, https://github.com/c4dynamics/c4dynamics/discussions
8
+ Project-URL: Documentation, https://c4dynamics.github.io/c4dynamics/
9
+ Project-URL: Source, https://github.com/c4dynamics/c4dynamics
10
+ Project-URL: Issues, https://github.com/c4dynamics/c4dynamics/issues
11
+ Keywords: python,state-space,dynamics,physics,algorithms,control,navigation,guidance,slam,vslam,computer-vision,image-processing,signal-processing
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Programming Language :: Python :: 3.8
14
+ Classifier: Programming Language :: Python :: 3.9
15
+ Classifier: Programming Language :: Python :: 3.10
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Operating System :: OS Independent
19
+ Requires-Python: <3.13,>=3.8
9
20
  Description-Content-Type: text/markdown
10
21
  License-File: LICENSE
11
22
  Requires-Dist: matplotlib>=3.9.2
@@ -13,45 +24,17 @@ Requires-Dist: numpy>=1.26.0
13
24
  Requires-Dist: pooch>=1.8.0
14
25
  Requires-Dist: scipy>=1.13.0
15
26
  Provides-Extra: vision
16
- Requires-Dist: matplotlib>=3.9.2; extra == "vision"
17
- Requires-Dist: numpy>=1.26.0; extra == "vision"
18
- Requires-Dist: pooch>=1.8.0; extra == "vision"
19
- Requires-Dist: scipy>=1.13.0; extra == "vision"
20
27
  Requires-Dist: imageio>=2.37.0; extra == "vision"
21
28
  Requires-Dist: natsort>=8.3.1; extra == "vision"
22
29
  Requires-Dist: opencv-python>=4.11.0.86; extra == "vision"
23
30
  Provides-Extra: dev
24
- Requires-Dist: matplotlib>=3.9.2; extra == "dev"
25
- Requires-Dist: numpy>=1.26.0; extra == "dev"
26
- Requires-Dist: pooch>=1.8.0; extra == "dev"
27
- Requires-Dist: scipy>=1.13.0; extra == "dev"
28
- Requires-Dist: imageio>=2.37.0; extra == "dev"
29
- Requires-Dist: natsort>=8.3.1; extra == "dev"
30
- Requires-Dist: opencv-python>=4.11.0.86; extra == "dev"
31
+ Requires-Dist: c4dynamics[vision]; extra == "dev"
31
32
  Requires-Dist: coverage>=7.0.0; extra == "dev"
32
33
  Requires-Dist: nbsphinx>=0.9.3; extra == "dev"
33
34
  Requires-Dist: sphinx>=8.1.3; extra == "dev"
34
35
  Requires-Dist: sphinx-book-theme>=1.1.4; extra == "dev"
35
36
  Requires-Dist: sphinx_design>=0.6.1; extra == "dev"
36
- Provides-Extra: keywords
37
- Requires-Dist: python; extra == "keywords"
38
- Requires-Dist: state-space; extra == "keywords"
39
- Requires-Dist: dynamics; extra == "keywords"
40
- Requires-Dist: physics; extra == "keywords"
41
- Requires-Dist: algorithms; extra == "keywords"
42
- Requires-Dist: control; extra == "keywords"
43
- Requires-Dist: navigation; extra == "keywords"
44
- Requires-Dist: guidance; extra == "keywords"
45
- Requires-Dist: slam; extra == "keywords"
46
- Requires-Dist: vslam; extra == "keywords"
47
- Requires-Dist: computer-vision; extra == "keywords"
48
- Requires-Dist: image-processing; extra == "keywords"
49
- Requires-Dist: signal-processing; extra == "keywords"
50
- Provides-Extra: dynamic
51
- Requires-Dist: classifiers; extra == "dynamic"
52
- Dynamic: author
53
37
  Dynamic: license-file
54
- Dynamic: requires-python
55
38
 
56
39
  <div align="center">
57
40
  <img src="https://github.com/C4dynamics/C4dynamics/blob/main/docs/source/_icon/c4dlogotext.svg">
@@ -62,9 +45,7 @@ Dynamic: requires-python
62
45
 
63
46
 
64
47
  <div align="center">
65
- <strong>📄 Published in the Journal of Open Source Software (JOSS)</strong><br>
66
- <em>A peer-reviewed open-source framework for state-space modeling and algorithm development</em>
67
- <br>
48
+ <strong> Published in the Journal of Open Source Software (JOSS)</strong><br>
68
49
  <a href="https://doi.org/10.5281/zenodo.17931207">
69
50
  <img src="https://zenodo.org/badge/DOI/10.5281/zenodo.17931207.svg">
70
51
  </a>
@@ -7,9 +7,7 @@
7
7
 
8
8
 
9
9
  <div align="center">
10
- <strong>📄 Published in the Journal of Open Source Software (JOSS)</strong><br>
11
- <em>A peer-reviewed open-source framework for state-space modeling and algorithm development</em>
12
- <br>
10
+ <strong> Published in the Journal of Open Source Software (JOSS)</strong><br>
13
11
  <a href="https://doi.org/10.5281/zenodo.17931207">
14
12
  <img src="https://zenodo.org/badge/DOI/10.5281/zenodo.17931207.svg">
15
13
  </a>
@@ -0,0 +1,326 @@
1
+ """
2
+
3
+ C4DYNAMICS
4
+ ==========
5
+
6
+ c4dynamics provides
7
+ 1. State objects as fundamental data structure for dynamic systems.
8
+ 2. Internal systems and 3rd party integrated libraries.
9
+ 3. Fast algorithmic operations over objects and systems.
10
+
11
+
12
+ How to use the documentation
13
+ ----------------------------
14
+ Documentation is currently availble through examples,
15
+ readme pages, and inline comments.
16
+
17
+
18
+ Available subpackages
19
+ ---------------------
20
+ sensors
21
+ Models of EO and EM sensors.
22
+ detectors
23
+ Objects detection models.
24
+ filters
25
+ Kalman and lowpass filters.
26
+ eqm
27
+ Runge Kutta solvers for integrating the equations of motion.
28
+ rotmat
29
+ Rotation matrices and rotational operations.
30
+ """
31
+
32
+ import os
33
+ import sys
34
+ import doctest
35
+ import warnings
36
+ import subprocess
37
+ import numpy as np
38
+
39
+ #
40
+ # body objects
41
+ ##
42
+ from . import rotmat as rotmat
43
+ from .states.lib.pixelpoint import pixelpoint as pixelpoint
44
+ from .states.lib.datapoint import datapoint as datapoint
45
+ from .states.lib.datapoint import create as create
46
+ from .states.state import state as state
47
+
48
+ # rotmat is required to importing rigidbody:
49
+ from .states.lib.rigidbody import rigidbody as rigidbody # rotmat is required to import rigidbody.
50
+
51
+ #
52
+ # routines
53
+ ##
54
+ from . import eqm as eqm
55
+
56
+ #
57
+ # utils
58
+ ##
59
+ from .utils.const import * # noqa: F403
60
+ from .utils.math import * # noqa: F403
61
+ from .utils.gen_gif import gif as gif
62
+ from .utils.cprint import cprint as cprint
63
+ from .utils.plottools import plotdefaults as plotdefaults
64
+ from .utils.plottools import _figdef as _figdef
65
+ from .utils.plottools import _legdef as _legdef
66
+ from .utils import tictoc as tictoc
67
+ from .utils.tictoc import tic as tic
68
+ from .utils.tictoc import toc as toc
69
+ from .utils._struct import struct as struct
70
+ from .utils.idx2keys import idx2keys as idx2keys
71
+ from . import datasets as datasets
72
+
73
+ #
74
+ # sensors
75
+ ##
76
+ from . import sensors as sensors
77
+ from . import filters as filters
78
+ from . import detectors as detectors
79
+
80
+ #
81
+ # reinforcement learning
82
+ ##
83
+ from . import envs as envs # noqa: F401
84
+
85
+ #
86
+ # version
87
+ ##
88
+ __version__ = "2.3.6" # update also in pyproject.toml
89
+
90
+
91
+ #
92
+ # some convinient mirroring
93
+ ##
94
+ j = os.path.join
95
+
96
+
97
+ """
98
+ WARNINGS
99
+ """
100
+
101
+
102
+ class c4warn(UserWarning):
103
+ pass
104
+
105
+
106
+ # customize the warning messages:
107
+ YELLOW = "\033[93m"
108
+ RESET = "\033[0m" # Reset color to default
109
+
110
+
111
+ # Override showwarning to globally apply custom formatting
112
+ def show_warning(message, category, filename, lineno, file=None, line=None):
113
+
114
+ if issubclass(category, c4warn):
115
+ # Apply formatting for c4warn warnings
116
+
117
+ # FIXME suppressing is absolutely not working.
118
+ message1 = str(message) + "\n"
119
+ message2 = "To suppress c4dynamics' warnings, run: import warnings," \
120
+ "import c4dynamics as c4d, warnings.simplefilter('ignore', c4d.c4warn)\n"
121
+
122
+ print(f"\n{YELLOW}{message1}{RESET}{message2} (File: {filename}, Line: {lineno})")
123
+ else:
124
+ # For other warnings, use the default behavior
125
+ print(f"{category.__name__}: {message} (File: {filename}, Line: {lineno})")
126
+
127
+
128
+ warnings.showwarning = show_warning
129
+
130
+ """
131
+ TESTING
132
+ """
133
+
134
+
135
+ class IgnoreOutputChecker(doctest.OutputChecker):
136
+ from typing import Union
137
+
138
+ IGNORE_OUTPUT = doctest.register_optionflag("IGNORE_OUTPUT") # 2048
139
+ NUMPY_FORMAT = doctest.register_optionflag("NUMPY_FORMAT") # 4096
140
+
141
+ def check_output(self, want, got, optionflags):
142
+
143
+ # If the IGNORE_OUTPUT flag is set, always return True
144
+ if optionflags & self.IGNORE_OUTPUT:
145
+ return True
146
+
147
+ # If NUMPY_FORMAT flag is set, compare NumPy arrays with formatting tolerance
148
+ if optionflags & self.NUMPY_FORMAT:
149
+
150
+ want = self._convert_to_array(want)
151
+ got = self._convert_to_array(got)
152
+
153
+ if want is not None and got is not None:
154
+
155
+ abs_tol = 1e-3
156
+ rel_tol = 1e-3
157
+
158
+ if False:
159
+
160
+ # Calculate element-wise absolute and relative differences
161
+ # if diff < abs (for small values) OR diff/want < rel (for large values)
162
+ np.abs(want - got) < abs_tol
163
+ np.abs((want - got) / np.where(want != 0, want, np.inf)) < rel_tol
164
+
165
+ return np.allclose(want, got, atol=abs_tol, rtol=rel_tol)
166
+
167
+ # Otherwise, fall back to the original behavior
168
+ return super().check_output(want, got, optionflags) # type: ignore
169
+
170
+ def _convert_to_array(self, text):
171
+
172
+ import re
173
+
174
+ """Attempt to convert text to a NumPy array for comparison."""
175
+ try:
176
+
177
+ if "," not in text:
178
+ text = re.sub(r"\s+", ",", text.strip())
179
+
180
+ # Remove 'np.type'
181
+ text = re.sub(r"np\.\w+", "", text)
182
+ # Remove 'array(' and strip leading/trailing whitespace characters
183
+ text = re.sub(r"(array\()", "", text).strip()
184
+ # Remove brackets and parantheses
185
+ text = re.sub(r"[\[\]\(\)]", "", text)
186
+ # remove ellipsis
187
+ text = re.sub(r"\.\.\.", "", text)
188
+ # Convert to NumPy array
189
+ return np.fromstring(text, sep=",")
190
+
191
+ except ValueError:
192
+ print(
193
+ "\n \033[31m DOCSTRING ERROR: Could not convert to an array \033[0m",
194
+ file=sys.stderr,
195
+ )
196
+ return None # Return None if conversion fails
197
+
198
+ # Filter out tests for the animate method by overriding the testmod.
199
+
200
+
201
+ def testmod_filtering(module, filter_functions=[], **kwargs):
202
+
203
+ tests = []
204
+
205
+ for test in doctest.DocTestFinder().find(module):
206
+ filtfunc = False
207
+ for func in filter_functions:
208
+ if func == test.name:
209
+ filtfunc = True
210
+ break
211
+ if filtfunc:
212
+ continue
213
+ tests.append(test)
214
+
215
+ runner = doctest.DocTestRunner(**kwargs)
216
+ for test in tests:
217
+ runner.run(test)
218
+ return runner.summarize()
219
+
220
+
221
+ def rundoctests(module, exclude_functions=[]):
222
+ import doctest
223
+ import contextlib
224
+ import os
225
+ from c4dynamics import IgnoreOutputChecker # , cprint
226
+
227
+ # from matplotlib import pyplot as plt
228
+ from pathlib import Path
229
+
230
+ tofile = False
231
+ # pltbe = plt.get_backend()
232
+ # plt.switch_backend("tkAgg")
233
+
234
+ # Register the custom OutputChecker
235
+ doctest.OutputChecker = IgnoreOutputChecker
236
+
237
+ optionflags = doctest.FAIL_FAST
238
+ np.set_printoptions(legacy="1.25")
239
+
240
+ if tofile:
241
+ with open(os.path.join("tests", "_out", "output.txt"), "w") as f:
242
+ with contextlib.redirect_stdout(f), contextlib.redirect_stderr(f):
243
+ # result = doctest.testmod(optionflags = optionflags)
244
+ result = testmod_filtering(module, exclude_functions, optionflags=optionflags)
245
+ else:
246
+ # result = doctest.testmod(optionflags = optionflags)
247
+ result = testmod_filtering(module, exclude_functions, optionflags=optionflags)
248
+
249
+ if result.failed == 0:
250
+ cprint(Path(module.__file__).parts[-1] + ": all tests passed!", "g")
251
+ else:
252
+ print(f"{result.failed}")
253
+
254
+ # plt.switch_backend(pltbe)
255
+
256
+
257
+ """
258
+ ROOT FOLDER
259
+ """
260
+
261
+
262
+ # just find the package root folder:
263
+ def c4dir(dir, addpath=""):
264
+ # dirname and basename are supplamentary:
265
+ # c:\dropbox\c4dynamics\text.txt
266
+ # dirname: c:\dropbox\c4dynamics
267
+ # basename: text.txt
268
+
269
+ inc4d = os.path.basename(dir) == "c4dynamics"
270
+ hasc4d = any(f == "c4dynamics" for f in os.listdir(dir) if os.path.isdir(os.path.join(dir, f)))
271
+
272
+ if inc4d and hasc4d:
273
+ addpath += ""
274
+ return addpath
275
+
276
+ addpath += "..\\"
277
+ return c4dir(os.path.dirname(dir), addpath)
278
+
279
+
280
+ """
281
+ KEYWORDS
282
+ """
283
+ #
284
+ # TODO BUG FIXME HACK NOTE XXX
285
+ #
286
+ # TODO IMPROVMEMNT
287
+ #
288
+ # BUG LOGICAL FAILURE PROBABLY COMES WITH XXX
289
+ # Highlights the presence of a bug or an issue.
290
+ # FIXME NOT SEVERE BUT A BETTER IDEA IS TO DO SO
291
+ # Indicates that there is a problem or bug that needs to be fixed.
292
+ # HACK I KNOW ITS NOT BEST SOLUTION TREAT IF U HAVE SPARE TIME
293
+ # Suggests that a workaround or temporary solution has been
294
+ # implemented and should be revisited.
295
+ # NOTE MORE IMPORTANT THAN A CASUAL COMMENT
296
+ # Provides additional information or context about the code.
297
+ # XXX TREAT THIS BEFORE OTHERS
298
+ # Used to highlight something that is problematic, needs attention,
299
+ # or should be addressed later.
300
+
301
+
302
+ # FIXME
303
+ # dependencies: for time limits requirementx.txt currently
304
+ # install all. actually maybe 90% of the users use only numpy
305
+ # and pyplot so it's a good practice to offer another full-req.txt
306
+ # file and add an import check for those not necessary:
307
+
308
+
309
+ def ensure_package(package_name):
310
+ try:
311
+ __import__(package_name)
312
+ except ImportError:
313
+ # Check if the user is in a conda environment
314
+ in_conda_env = os.environ.get("CONDA_PREFIX") is not None
315
+ manager = "conda" if in_conda_env else "pip"
316
+
317
+ user_input = input(
318
+ f"{package_name} is required but not installed. "
319
+ f"Would you like to install it with {manager}? (y/n): "
320
+ )
321
+
322
+ if user_input.lower() == "y":
323
+ if manager == "conda":
324
+ subprocess.check_call(["conda", "install", package_name, "-y"])
325
+ else:
326
+ subprocess.check_call(["pip", "install", package_name])
@@ -0,0 +1,109 @@
1
+ """
2
+
3
+ Usage of Datasets
4
+ =================
5
+
6
+ C4dynamics dataset functions can be simply called as follows:
7
+ :code:`c4dynamics.datasets.module(file)`,
8
+ where ``module`` and ``file`` define the dataset.
9
+ The available modules and files are detailed on the corresponding pages.
10
+ This downloads the dataset file over the network once, saves it to the cache,
11
+ and returns the path to the file.
12
+
13
+
14
+
15
+
16
+ Dataset retrieval and storage
17
+ =============================
18
+
19
+ The YOLOv3 weights file can be found at the official YOLO
20
+ site: `Joseph Redmon <https://pjreddie.com/darknet/yolo/>`_.
21
+ Oher dataset files are available in the
22
+ C4dynamics GitHub repository under
23
+ `datasets <https://github.com/C4dynamics/C4dynamics/blob/main/datasets/>`_
24
+
25
+
26
+ C4dynamics.datasets uses
27
+ `Pooch <https://www.fatiando.org/pooch/latest/>`_,
28
+ a Python package designed to simplify fetching data files.
29
+ `Pooch` retrieves the necessary dataset files
30
+ from these repositories when the dataset function is called.
31
+
32
+
33
+ A registry file of all datasets provides a mapping of filenames
34
+ to their SHA256 hashes and repository URLs
35
+ Pooch uses this registry to manage and verify downloads when the function is called.
36
+ After downloading the dataset once, the files are saved
37
+ in the system cache directory under ``'c4data'``.
38
+
39
+
40
+ Dataset cache locations may vary on different platforms.
41
+
42
+ For Windows::
43
+
44
+ 'C:\\Users\\<user>\\AppData\\Local\\c4data'
45
+
46
+ For macOS::
47
+
48
+ '~/Library/Caches/c4data'
49
+
50
+ For Linux and other Unix-like platforms::
51
+
52
+ '~/.cache/c4data' # or the value of the XDG_CACHE_HOME env var, if defined
53
+
54
+
55
+ In environments with constrained network connectivity for various security
56
+ reasons or on systems without continuous internet connections,
57
+ one may manually
58
+ load the cache of the datasets by placing the contents of the dataset repo in
59
+ the above mentioned cache directory to avoid fetching dataset errors without
60
+ the internet connectivity.
61
+
62
+ """
63
+
64
+ import sys
65
+
66
+ # sys.path.append(".")
67
+
68
+ # from c4dynamics.datasets._manager import (
69
+ # sha256,
70
+ # image,
71
+ # video,
72
+ # nn_model,
73
+ # d3_model,
74
+ # download_all,
75
+ # clear_cache,
76
+ # )
77
+ from c4dynamics.datasets._manager import sha256 as sha256 # noqa: F401
78
+ from c4dynamics.datasets._manager import image as image # noqa: F401
79
+ from c4dynamics.datasets._manager import video as video # noqa: F401
80
+ from c4dynamics.datasets._manager import nn_model as nn_model # noqa: F401
81
+ from c4dynamics.datasets._manager import d3_model as d3_model # noqa: F401
82
+ from c4dynamics.datasets._manager import download_all as download_all # noqa: F401
83
+ from c4dynamics.datasets._manager import clear_cache as clear_cache # noqa: F401
84
+
85
+ if __name__ == "__main__":
86
+
87
+ # import doctest, contextlib
88
+ # from c4dynamics import IgnoreOutputChecker, cprint
89
+
90
+ # # Register the custom OutputChecker
91
+ # doctest.OutputChecker = IgnoreOutputChecker
92
+
93
+ # tofile = False
94
+ # optionflags = doctest.FAIL_FAST
95
+
96
+ # if tofile:
97
+ # with open(os.path.join('tests', '_out', 'output.txt'), 'w') as f:
98
+ # with contextlib.redirect_stdout(f), contextlib.redirect_stderr(f):
99
+ # result = doctest.testmod(optionflags = optionflags)
100
+ # else:
101
+ # result = doctest.testmod(optionflags = optionflags)
102
+
103
+ # if result.failed == 0:
104
+ # cprint(os.path.basename(__file__) + ": all tests passed!", 'g')
105
+ # else:
106
+ # print(f"{result.failed}")
107
+ from c4dynamics import rundoctests
108
+
109
+ rundoctests(sys.modules[__name__])