half-sample 0.1.20__tar.gz → 0.1.23__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: half_sample
3
- Version: 0.1.20
3
+ Version: 0.1.23
4
4
  Summary: sample data and analysis
5
5
  Home-page: https://github.com/KD-Group/Half.Sample
6
6
  Author: kunde
Binary file
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: half-sample
3
- Version: 0.1.20
3
+ Version: 0.1.23
4
4
  Summary: sample data and analysis
5
5
  Home-page: https://github.com/KD-Group/Half.Sample
6
6
  Author: kunde
@@ -1,30 +1,82 @@
1
1
  import os
2
2
  import shutil
3
+ import sys
4
+ import threading
5
+ from pathlib import Path
3
6
 
4
7
  from . import Process
5
8
  from . import Result
6
9
 
7
10
 
11
+ _SOURCE_ROOT = Path(os.path.realpath(os.path.abspath(__file__))).parent.parent
12
+ _SOURCE_BUILD_LOCK = threading.Lock()
13
+
14
+
15
+ def _existing_file(*parts):
16
+ try:
17
+ candidate = Path(parts[0]).joinpath(*parts[1:])
18
+ except (TypeError, ValueError):
19
+ return None
20
+ try:
21
+ if candidate.is_file():
22
+ return str(candidate.resolve())
23
+ except OSError:
24
+ return None
25
+ return None
26
+
27
+
28
+ def _is_source_checkout():
29
+ return all((
30
+ _existing_file(_SOURCE_ROOT, 'SConstruct'),
31
+ _existing_file(_SOURCE_ROOT, 'setup.py'),
32
+ _existing_file(_SOURCE_ROOT, 'sample', 'sample.py'),
33
+ ))
34
+
35
+
8
36
  class Sampler:
9
37
  @property
10
38
  def execution_path(self) -> str:
11
- main_path = os.path.join(os.path.dirname(__file__), '..')
12
-
13
- # build if SConstruct file exists
14
- if os.path.exists(os.path.join(main_path, 'SConstruct')):
15
- if os.system('cd {} && scons'.format(main_path)) != 0:
16
- raise self.Error("Compile C++ Driver Error")
17
-
18
- # try to use cpp_build/sample.exe when developing
19
- execution_name = 'sample.exe'
20
- if not os.path.exists(execution_name):
21
- execution_name = os.path.join(main_path, 'cpp_build', execution_name)
22
- if os.path.exists(execution_name):
23
- return os.path.abspath(execution_name)
39
+ # keep the historical current-working-directory override first
40
+ execution_path = _existing_file('sample.exe')
41
+ if execution_path:
42
+ return execution_path
43
+
44
+ # try to use (or build) cpp_build/sample.exe in a source checkout
45
+ if _is_source_checkout():
46
+ execution_path = _existing_file(_SOURCE_ROOT, 'cpp_build', 'sample.exe')
47
+ if execution_path:
48
+ return execution_path
49
+ with _SOURCE_BUILD_LOCK:
50
+ execution_path = _existing_file(_SOURCE_ROOT, 'cpp_build', 'sample.exe')
51
+ if not execution_path:
52
+ if os.system('cd {} && scons'.format(_SOURCE_ROOT)) != 0:
53
+ raise self.Error("Compile C++ Driver Error")
54
+ execution_path = _existing_file(_SOURCE_ROOT, 'cpp_build', 'sample.exe')
55
+ if execution_path:
56
+ return execution_path
57
+
58
+ # try the Python/frozen executable directory
59
+ try:
60
+ executable_directory = Path(sys.executable).parent
61
+ except (TypeError, ValueError):
62
+ executable_directory = None
63
+ execution_path = _existing_file(executable_directory, 'sample.exe')
64
+ if execution_path:
65
+ return execution_path
66
+
67
+ # try the environment root used by venv/uv data-file installs
68
+ execution_path = _existing_file(sys.prefix, 'sample.exe')
69
+ if execution_path:
70
+ return execution_path
24
71
 
25
72
  # try to find sample.exe in system path when release
26
- if shutil.which("sample.exe"):
27
- return shutil.which("sample.exe")
73
+ try:
74
+ path_driver = shutil.which("sample.exe")
75
+ except (OSError, ValueError):
76
+ path_driver = None
77
+ execution_path = _existing_file(path_driver)
78
+ if execution_path:
79
+ return execution_path
28
80
 
29
81
  raise self.Error('Sample Driver Not Found')
30
82
 
@@ -63,29 +115,38 @@ class Sampler:
63
115
  def measure(self, number_of_waveforms: int, emitting_frequency: float, auto_mode: bool = False,
64
116
  instant_ai_frequency_threshold: float = 0.0,
65
117
  instant_ai_target_points_per_waveform: int = 100,
66
- instant_ai_max_reliable_polling_hz: float = 10.0) -> Result:
118
+ instant_ai_max_reliable_polling_hz: float = 10.0,
119
+ waveform_processing_mode: str = "threshold_accumulation") -> Result:
67
120
  command = "to_measure {} {:.12g} {}".format(number_of_waveforms, emitting_frequency, auto_mode)
68
121
  if (instant_ai_frequency_threshold != 0.0 or instant_ai_target_points_per_waveform != 100 or
69
- instant_ai_max_reliable_polling_hz != 10.0):
122
+ instant_ai_max_reliable_polling_hz != 10.0 or waveform_processing_mode != "threshold_accumulation"):
70
123
  command += " {:.12g} {} {:.12g}".format(
71
124
  instant_ai_frequency_threshold, instant_ai_target_points_per_waveform,
72
125
  instant_ai_max_reliable_polling_hz)
126
+ if waveform_processing_mode != "threshold_accumulation":
127
+ command += " {}".format(waveform_processing_mode)
73
128
  return self.communicate(command)
74
129
 
75
130
  def dump(self, filename: str, number_of_waveforms: int, emitting_frequency: float,
76
131
  auto_mode: bool = False, instant_ai_frequency_threshold: float = 0.0,
77
132
  instant_ai_target_points_per_waveform: int = 100,
78
- instant_ai_max_reliable_polling_hz: float = 10.0) -> Result:
133
+ instant_ai_max_reliable_polling_hz: float = 10.0,
134
+ waveform_processing_mode: str = "threshold_accumulation") -> Result:
79
135
  command = "to_dump {} {} {:.12g} {}".format(filename, number_of_waveforms, emitting_frequency, auto_mode)
80
136
  if (instant_ai_frequency_threshold != 0.0 or instant_ai_target_points_per_waveform != 100 or
81
- instant_ai_max_reliable_polling_hz != 10.0):
137
+ instant_ai_max_reliable_polling_hz != 10.0 or waveform_processing_mode != "threshold_accumulation"):
82
138
  command += " {:.12g} {} {:.12g}".format(
83
139
  instant_ai_frequency_threshold, instant_ai_target_points_per_waveform,
84
140
  instant_ai_max_reliable_polling_hz)
141
+ if waveform_processing_mode != "threshold_accumulation":
142
+ command += " {}".format(waveform_processing_mode)
85
143
  return self.communicate(command)
86
144
 
87
- def process(self, filename: str) -> Result:
88
- return self.communicate("to_process {}".format(filename))
145
+ def process(self, filename: str, waveform_processing_mode: str = None) -> Result:
146
+ command = "to_process {}".format(filename)
147
+ if waveform_processing_mode is not None:
148
+ command += " {}".format(waveform_processing_mode)
149
+ return self.communicate(command)
89
150
 
90
151
  def sampling_progress(self) -> Result:
91
152
  return self.communicate("to_sampling_progress")
@@ -2,7 +2,7 @@ import setuptools
2
2
 
3
3
  setuptools.setup(
4
4
  name="half_sample",
5
- version="0.1.20",
5
+ version="0.1.23",
6
6
  author="kunde",
7
7
  author_email="gzkunde@163.com",
8
8
  description="sample data and analysis",
Binary file
File without changes
File without changes