Skip to content

SoFTg reference

from WaLSAlib import SoFTg

Classical segmentation is available with the base installation. Model, dataset, loss, training, prediction, and utility modules load on demand and require the softg extra where their dependencies are used.

Segment granules

Complete source signature
SoFTg.segment_solar_granules(sample_img, plate_scale, k=0.165, lane_width_km=150, reconnect_ratio=4.0, lane_intensity_fraction=0.4)
Parameter Default Annotation / meaning
sample_img Required Two-dimensional intensity image.
plate_scale Required Positive spatial sampling in km/pixel.
k 0.165 Dynamic local-threshold parameter.
lane_width_km 150 Lane-width scale for morphology, in km.
reconnect_ratio 4.0 Morphological lane-reconnection control.
lane_intensity_fraction 0.4 Intensity fraction in the watershed stage.

View implementation · Parameters and defaults generated from this checkout.

Returns (labels, seeds, skeleton) with the image shape. Read classical segmentation for units and processing stages.

Underlying classical helpers

Access these through SoFTg.granule_detection_lib.

Remove bright points

Complete source signature
SoFTg.remove_bright_points(img: np.ndarray, plate_scale: float, bp_size_km: float=200.0)
Parameter Default Annotation / meaning
img Required np.ndarray — Two-dimensional input image.
plate_scale Required float — Positive spatial sampling in km/pixel.
bp_size_km 200.0 float — Bright-point scale, in km.

View implementation · Parameters and defaults generated from this checkout.

Compute a local dynamic threshold

Complete source signature
SoFTg.dynamic_threshold(img: np.ndarray, plate_scale: float, k: float, granule_size_km: float=1250.0)
Parameter Default Annotation / meaning
img Required np.ndarray — Two-dimensional input image.
plate_scale Required float — Positive spatial sampling in km/pixel.
k Required float — Dynamic local-threshold parameter.
granule_size_km 1250.0 float — Granule scale for the local threshold, in km.

View implementation · Parameters and defaults generated from this checkout.

Clean and reconnect a lane mask

Complete source signature
SoFTg.clean_lane_mask(binary_mask: np.ndarray, plate_scale: float, lane_width_km: float=150.0, reconnect_ratio: float=3.0)
Parameter Default Annotation / meaning
binary_mask Required np.ndarray — Binary lane-mask input.
plate_scale Required float — Positive spatial sampling in km/pixel.
lane_width_km 150.0 float — Lane-width scale for morphology, in km.
reconnect_ratio 3.0 float — Morphological lane-reconnection control.

View implementation · Parameters and defaults generated from this checkout.

UNet++ model

net = SoFTg.model.UNetPlusPlus(n_channels=1, n_classes=2, scale=1)
Complete source signature
SoFTg.UNetPlusPlus(n_channels, n_classes, scale=1, bilinear=True, dropout=False)
Parameter Default Annotation / meaning
n_channels Required Number of input image channels.
n_classes Required Number of output classes.
scale 1 Network filter-channel downscaling factor.
bilinear True Requested upsampling option; the current UNet++ uses bilinear dense upsampling internally.
dropout False Enable dropout in convolution blocks.

View implementation · Parameters and defaults generated from this checkout.

For prediction, match the architecture expected by the checkpoint loader.

Load weights for prediction

Complete source signature
SoFTg.load_trained_model(model_path: str, device: torch.device)
Parameter Default Annotation / meaning
model_path Required str — Path to architecture-compatible weights.
device Required torch.device — PyTorch device supplied by the caller.

View implementation · Parameters and defaults generated from this checkout.

Constructs the bundled prediction architecture, loads compatible weights, sends the model to the supplied device, and returns it in evaluation mode. See checkpoint requirements.

Process an input file

Complete source signature
SoFTg.run_inference(input_path, model, output_dir, tile_size, overlap, threshold, min_size, preprocess, device)
Parameter Default Annotation / meaning
input_path Required Path to one FITS or NPY input file.
model Required Compatible PyTorch segmentation model.
output_dir Required Directory for saved prediction masks.
tile_size Required Tile side length in pixels.
overlap Required Tile overlap in pixels.
threshold Required Prediction probability threshold.
min_size Required Minimum feature/component size in pixels.
preprocess Required Enable enhancement; stacking/normalisation still apply if false.
device Required PyTorch device supplied by the caller.

View implementation · Parameters and defaults generated from this checkout.

Reads FITS/NPY data, forms a single image (including median stacking for a cube), optionally enhances contrast, applies tiled inference and component cleanup, and writes masks. A three-dimensional input produces one mask from its median image.

Command-line modules

python -m WaLSAlib._vendor.softg.train --help
python -m WaLSAlib._vendor.softg.predict --help

The ML guide documents data layout, supported weights, preprocessing, outputs, and reproducibility. The desktop SoFTg.label_tool requires the softg-gui extra and a graphical display.