timelapse
plantimager.controller.scanner.timelapse Link
Handles the coordination and the scheduling of multiple scans through the TimeLapse class
TimeLapse Link
TimeLapse(cnc, db_url, cameras, path, timelapse_name, config, power_manager, parent=None)
Bases: QObject
Source code in plantimager/controller/scanner/timelapse.py
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 | |
scan Link
scan(index)
Executes a scheduled scan based on the provided index.
This method updates the current scanning index and triggers the progressChanged signal.
It determines the interval to the next scheduled time and either waits for the appropriate
time, proceeds with the scan, or skips it if the grace period has been violated.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index
|
int
|
The index of the scan to execute. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the provided |
Notes
- The method computes the interval between the current time and the next scheduled time.
If the interval is greater than the
grace_period, the method pauses execution until the scheduled time. - If the time has already passed and exceeded the grace period, the scan is skipped.
- Sleeps the thread until the scheduled time arrives if the scan occurs too early.
See Also
Scan.scan : Executes the actual scan process.
Examples:
Suppose you have a scheduler with predefined schedule_times and grace_period, you can
invoke the following method by supplying a valid scan index:
>>> scheduler.scan(2)
Source code in plantimager/controller/scanner/timelapse.py
265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 | |
parse_duration Link
parse_duration(duration_string, /, duration_regexp=DURATION_REGEXP)
Parses a duration string and converts it into a datetime.timedelta object.
This function takes a duration string in a specific format and uses a regular expression
pattern to extract the components (e.g., days, hours, minutes, seconds). The parsed
components are then converted into a datetime.timedelta object for further manipulation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
duration_string
|
str
|
A string representing the duration in the format |
required |
duration_regexp
|
Pattern
|
A compiled regular expression pattern used to match and extract components from
|
DURATION_REGEXP
|
Returns:
| Type | Description |
|---|---|
timedelta
|
A |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If |
Notes
- The
DURATION_REGEXPconstant, if used as the defaultduration_regexp, must be pre-defined in the module. It should include named capturing groups for days (d), hours (h), minutes (m), and seconds (s).
Examples:
>>> import re
>>> import datetime
>>> DURATION_REGEXP = re.compile(r'(?:(?P<days>\d+)d)?\W?(?:(?P<hours>\d+)h)?\W?(?:(?P<minutes>\d+)m)?\W?(?P<seconds>\d+)s?')
>>> parse_duration("2d-3h-1m-0s", duration_regexp=DURATION_REGEXP)
datetime.timedelta(days=2, seconds=10980)
>>> parse_duration("3h-20m", duration_regexp=DURATION_REGEXP)
datetime.timedelta(seconds=12000)
>>> parse_duration("invalid-string", duration_regexp=DURATION_REGEXP)
Traceback (most recent call last):
...
RuntimeError: Failed to parse duration_string: invalid-string. Did not follow the format 2d-3h-1m-0s
Source code in plantimager/controller/scanner/timelapse.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | |