QoLlib
A Quality of Life (QoL) library that accumulates useful tools, hacks and such.
Usage Examples
All available methods are available from the code documentation. Below we only highlight specific use-cases that need a bit more attention.
Please be also invited to have a look at the unit tests ( /tests folder) for further code examples.
Processing
To run code (quasi-)parallel in multiple processes or threads the threaded and simultaneous methods
from the processing package remove a lot of overhead.
Given a method that we want to execute in parallel
def long_running_calculation(num: float) -> float:
# omitted for readability
pass
we can simply call:
simultaneous(long_running_calculation, [42, 1337, 3.141, 5, 6, 123.456, 1e-6])
However, common use case is that the ordering of concurrently generated results is important.
E.g., when processing individual rows in an image. A simple trick to achieve this is to return a tuple from the
processing method.
import numpy as np
def rotate_row(data: tuple) -> tuple:
"""
| 0 | 1 | 2
| row number | rot mat | row data
dat = (row: int, rot: np.array, stokes: np.array)
:return: (row: int, rotated_row: np.array)
"""
rotated = np.zeros_like(data[2]).T
for col in range(data[2].shape[1]):
rotated[col] = np.dot(data[1], data[2][:, col])
return data[0], rotated
Once our result is in this form, we can re-establish the ordering after execution by transforming the
result into a dict:
args = [(row, rot, frame[:, row]) for row in range(frame.shape[1])]
res = dict(simultaneous(rotate_row, args))
rotated = np.array([res[r] for r in range(frame.shape[1])])
Also, when working with classes, the executing method must be accessible from outside the instance scope.
This is best achieved with using @staticmethods.
class ExampleClass:
# ... lots of implementation details parallelize
@staticmethod
def parallelize(args):
pass
simultaneous(ExampleClass.parallelize, args)
Strings
When dealing with user input it is neat to allow users to specify shapes for numpy arrays as strings in
the common numpy format, e.g., [13:37, :, 42]. To extract the tuple of slices to forward this to numpy
we provide the parse_shape(str) method:
data = np.arrange(10, 10)
roi = parse_shape('[1,2:4]')
print(data[roi])
#=> [12, 13]
Metadata
Release files for qollib 0.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| qollib-0.1.3.tar.gz | 8.3 kB | Without provenance | Details for qollib-0.1.3.tar.gz |
Release files / qollib-0.1.3.tar.gz
| Download URL | qollib-0.1.3.tar.gz |
|---|---|
| Size | 8.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8dfdb8df6566395f0708556f02441c76980eb90a318a68ae17abeeb0728c0f67
|
|
BLAKE2b-256 checksum How to use checksums |
7b84def3a333949a504d5baa8d28c39dfcecff6f3f7ca94776729a6174bb6be4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.12.4
|
Security for qollib 0.1.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.