Utilities¶
Logging¶
pix4dvortex provides seamless interoperability with Python, allowing to pass callable logger objects to most
functions. These objects may be any Python callable of type Callable[[int, str]], None], where the first
parameter is a logging level and the second is a message. This is satisfied, for example, by logging.Logger.log(), but may be a simple user defined function, as shown in the examples below.
All logging-enabled functions have a parameter logger which accepts a callable of the type decsribed above.
Note
Internally, the invocations of the callable are executed sequentially in an asynchronous queue running in a separate thread, ensuring that the logging itself doesn’t unnecessarily block the processing functions from which it is called, while ensuring that the Python Global Interpreter Lock (GIL) is released and acquired as needed.
This example shows how to use Python logging functionality, both in a script, and passed into processing functions:
import logging
from pathlib import Path
from pix4dvortex import calib, cameras
logging.basicConfig(
format="%(asctime)s | %(name)-17s | %(levelname)-8s | %(message)s", level=logging.INFO
)
data_dir = Path("some/data/dir/img")
imgs = list(data_dir.glob("*.JPG"))
vtx_log = logging.getLogger("vortex").log
vtx_log(logging.INFO, "Make input cameras")
in_cams = cameras.make_input_cameras(image_info=imgs, logger=vtx_log)
proj_cams = cameras.ProjectedCameras(input_cameras=in_cams)
vtx_log(logging.INFO, "Run calibration")
calib_scene = calib.calibrate(
cameras=proj_cams,
settings=calib.Settings(image_scale=0.25),
logger=vtx_log,
)
vtx_log(logging.INFO, "Processing finished.")
This example has a user defined logging function which simply prints to standard output:
import logging
from pathlib import Path
from pix4dvortex import calib, cameras
def print_log(level, msg):
print(f"{logging.getLevelName(level)} | {msg}")
data_dir = Path("some/data/dir/img")
imgs = list(data_dir.glob("*.JPG"))
print_log(logging.INFO, "Make input cameras")
in_cams = cameras.make_input_cameras(image_info=imgs, logger=print_log)
proj_cams = cameras.ProjectedCameras(input_cameras=in_cams)
print_log(logging.INFO, "Run calibration")
calib_scene = calib.calibrate(
cameras=proj_cams,
settings=calib.Settings(image_scale=0.25),
logger=print_log,
)
print_log(logging.INFO, "Processing finished.")