pyflange.utils
Internal utilities shared by the other PyFlange modules.
This module collects small helpers that are used throughout the library:
- Logging helpers:
Logger,log_dataandread_data_log. load_csv_database, which loads the tabular data (bolt dimensions, material properties, shell stiffness results, etc.) shipped with the package.reduce_to_pi, an angle reduction function.
These helpers are mainly meant for internal use, but they are public and documented because they may be useful when extending the library.
Logger(id)
Create a logger configured with the PyFlange logging level.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Example
from pyflange.utils import Logger
logger = Logger(__name__)
logger.warning("Something looks suspicious")
load_csv_database(db_name, index_col='id')
cached
Load one of the CSV databases shipped with the package.
The files are read from the data folder of the package, as
data/<db_name>.csv. Results are cached, so each database is read from
disk only once.
| Parameters: |
|
|---|
| Returns: |
|
|---|
| Raises: |
|
|---|
log_data(object, **kwargs)
Attach intermediate calculation values to an object.
The values are stored in a private dictionary on the object (created on
first use), so that intermediate results of a calculation can be inspected
afterwards with read_data_log. Existing keys are overwritten.
| Parameters: |
|
|---|
Example
from pyflange.utils import log_data, read_data_log
class Calc: pass
calc = Calc()
log_data(calc, k_shell=1.5e9, f_tot=2.0)
read_data_log(calc, "f_tot") # 2.0
read_data_log(object, key)
Read a value previously stored with log_data.
| Parameters: |
|
|---|
| Returns: |
|
|---|
reduce_to_pi(angle)
Reduce an angle to the interval [0, pi].
The angle is first wrapped to (-pi, pi] and then its absolute value is taken. This is useful for angles whose sign is irrelevant, such as a tilt angle magnitude.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Example
from math import pi
reduce_to_pi(3*pi/2) # pi/2
reduce_to_pi(-0.3) # 0.3