Core utilities
core.py module
API reference
- pyphyschemtools.core.centertxt(content=None, style=None, font=None, size=None, weight=None, bgc=None, fgc=None)[source]
Centers and renders text as HTML in the notebook.
input:
content = text to render (default: None)
style = predefined style name (default: None). See STYLES below; any explicit parameter overrides the style.
font = font family (default: ‘sans’)
size = font size in px (default: 12)
weight = font weight (default: ‘normal’)
bgc = background color, name or hex (default: ‘#ffffff’)
fgc = foreground color, name or hex (default: ‘#000000’)
- pyphyschemtools.core.crop_images(input_files, process_folder=False)[source]
Trims whitespace or transparency from image files and saves the results.
If process_folder is True, input_files is treated as a directory path, and all images within (excluding those ending in -C) are processed. Otherwise, input_files is treated as a single file path or a list of paths.
The function preserves original image metadata (DPI, ICC profiles).
- Parameters:
input_files (str, Path, or list) – File path(s) or a directory path.
process_folder (bool) – If True, treats input_files as a directory to crawl.
- Returns:
Prints status messages to the console for each file processed.
- Return type:
None
- pyphyschemtools.core.get_qc_examples(suite=None)[source]
Copies QC examples archive to the current directory. Supports terminal CLI (with help) and direct Python calls.
- pyphyschemtools.core.save_data(df, path_with_name: str, **kwargs)[source]
Saves a Pandas DataFrame to CSV or Excel, automatically creating missing directories.
- Parameters:
df (pd.DataFrame) – The DataFrame to save.
path_with_name (str) – The path and filename (e.g., “data/results.csv”).
**kwargs – Additional arguments passed to to_csv or to_excel (e.g., index=True).
- pyphyschemtools.core.save_fig(path_with_name: str, fig=None, dpi: int = 300, **kwargs)[source]
Saves a figure to a path, automatically creating missing directories. Works with the current plt or a specific figure object.
- Parameters:
path_with_name (str) – The path and filename (e.g., “results/plots/energy.svg”).
fig (matplotlib.figure.Figure, optional) – A specific figure object. If None, uses plt.gcf().
dpi (int) – Resolution for raster formats. Defaults to 300.
**kwargs – Additional arguments passed to savefig (e.g., transparent=True).
- pyphyschemtools.core.smart_trim(img)[source]
Determines the bounding box of the meaningful content in an image.
This function automatically detects if the image has transparency (Alpha channel). If it does, it calculates the bounding box based on non-transparent pixels. If the image is opaque, it assumes a white background and calculates the bounding box by detecting differences from a pure white canvas.
- Parameters:
img (PIL.Image.Image) – The source image object.
- Returns:
- A 4-tuple (left, upper, right, lower) defining the crop box,
or None if the image is uniform/empty.
- Return type:
tuple