Note
Go to the end to download the full example code.
Configuring verbosity level#
This example demonstrates how to configure verbosity level, or logging, using a coregistration method.
Logging can be customized to various severity levels, from DEBUG for detailed diagnostic output, to INFO for
general updates, WARNING for potential issues, and ERROR or CRITICAL for serious problems.
Setting the verbosity to a certain severity level prints all outputs from that level and those above. For instance,
level INFO also prints warnings, error and critical messages.
See also Configuration.
Important
The verbosity level defaults to WARNING, so no INFO or DEBUG is printed.
import logging
import xdem
We start by configuring the logging level, which can be as simple as specifying we want to print information.
logging.basicConfig(level=logging.INFO)
We can change the configuration even more by specifying the format, date, and multiple destinations for the output.
logging.basicConfig(
level=logging.INFO, # Change this level to DEBUG or WARNING to see different outputs.
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
datefmt="%Y-%m-%d %H:%M:%S",
handlers=[
logging.FileHandler("../xdem_example.log"), # Save logs to a file
logging.StreamHandler(), # Also print logs to the console
],
force=True, # To re-set from previous logging
)
We can now load example files and demonstrate the logging through a functionality, such as coregistration.
reference_dem = xdem.DEM(xdem.examples.get_path("longyearbyen_ref_dem"))
dem_to_be_aligned = xdem.DEM(xdem.examples.get_path("longyearbyen_tba_dem"))
coreg = xdem.coreg.NuthKaab()
With the INFO verbosity level defined above, we can follow the iteration with a detailed format, saved to file.
2026-04-30 08:22:40 - root - INFO - Running Nuth and Kääb (2011) coregistration
Progress: 0%| | 0/10 [00:00<?, ?it/s]
Iteration #1 - Offset: (np.float64(-8.309815337601904), np.float64(-1.125693938821563), -2.7552547454833984); Magnitude: 0.4192857551507786
Progress: 0%| | 0/10 [00:00<?, ?it/s]
Progress: 10%|█ | 1/10 [00:00<00:02, 3.67it/s]
Iteration #2 - Offset: (np.float64(-8.588458139140956), np.float64(-1.255261994098664), -2.4402336216360823); Magnitude: 0.01536470727005738
Progress: 10%|█ | 1/10 [00:00<00:02, 3.67it/s]
Progress: 20%|██ | 2/10 [00:00<00:02, 3.71it/s]
Iteration #3 - Offset: (np.float64(-8.588457830044044), np.float64(-1.267515250117788), -2.426217934828969); Magnitude: 0.0006126628011511315
Progress: 20%|██ | 2/10 [00:00<00:02, 3.71it/s]
Last offset was below the residual offset threshold of 0.001 -> stopping
Progress: 20%|██ | 2/10 [00:00<00:02, 3.71it/s]
Progress: 20%|██ | 2/10 [00:00<00:03, 2.46it/s]
With a more severe verbosity level, there is no output.
logging.basicConfig(level=logging.ERROR, force=True)
aligned_dem = coreg.fit_and_apply(reference_dem, dem_to_be_aligned)
Total running time of the script: (0 minutes 1.993 seconds)