Skip to main content

Single Molecule Reconstruction Package

A Python package for creating scale-space reconstructions of single molecule microscopy data, with support for masked regions and uniform distribution modeling.

Features

  • Generate 2D Gaussian reconstructions from single molecule localizations
  • Support for masked regions of interest
  • Flexible pixel size scaling and error handling
  • Uniform distribution modeling within masked regions
  • Multiple image format support (PNG, JPG, TIF, SVG)
  • Coordinate conversion between reconstruction and original space

Installation

pip install smrecon  # Package name placeholder

Quick Start

from smrecon import SMReconstruction, ImageFormat

# Initialize reconstruction
reconstructor = SMReconstruction(
    img_dims=(512, 512),  # Original image dimensions
    pixel_size=130,       # Original pixel size in nm
    rescale_pixel_size=10 # Target pixel size in nm
)

# Create reconstruction from localizations
localizations = np.array([[x1, y1], [x2, y2], ...])  # Your localization data
errors = np.array([e1, e2, ...])  # Localization errors

image = reconstructor.make_reconstruction(
    localizations=localizations,
    localization_error=errors
)

# Save the result
reconstructor.save_image(
    path="output/",
    name="reconstruction",
    fmt=ImageFormat.TIF
)

Advanced Usage: Masked Reconstruction

from smrecon import SMReconstructionMasked, MaskedReconstructionConfig

# Create custom configuration
config = MaskedReconstructionConfig(
    bounding_box_padding=5,
    mask_threshold=255,
    gaussian_scale_factor=5.0
)

# Initialize masked reconstruction
masked_reconstructor = SMReconstructionMasked(
    img_dims=(512, 512),
    pixel_size=130,
    rescale_pixel_size=10,
    config=config
)

# Create masked reconstruction
masked_image = masked_reconstructor.make_reconstruction(
    localizations=localizations,
    localization_error=errors,
    masked_img=your_mask_array,
    uniform=False  # Set to True for uniform distribution within mask, number of localizations will be placed in the mask region uniformly.
)

API Reference

Main Classes

SMReconstruction

Base class for single molecule reconstruction.

SMReconstructionMasked

Extended class supporting masked regions and uniform distributions.

Configuration Classes

ReconstructionConfig

class ReconstructionConfig:
    bounding_box_padding: int = 5
    random_seed: int = 666
    gaussian_scale_factor: float = 5.0

MaskedReconstructionConfig

class MaskedReconstructionConfig(ReconstructionConfig):
    mask_threshold: int = 255
    uniform_distribution: bool = False

Enums

ImageFormat

Supported image formats:

  • PNG
  • JPG
  • TIF
  • SVG

ConversionType

Converting between the reconstruction space coordinates and the original space (and vice versa).

# Initialize masked reconstruction
masked_reconstructor = SMReconstructionMasked(
    img_dims=(512, 512),
    pixel_size=130,
    rescale_pixel_size=10,
    config=config
)

# Create masked reconstruction
masked_image = masked_reconstructor.make_reconstruction(
    localizations=localizations,
    localization_error=errors,
    masked_img=your_mask_array,
    uniform=False  # Set to True for uniform distribution within mask
)

xycoord, spatialcoord = masked_image.coordinate_conversion([x_i, y_i], r_i, conversion_type)
# x_i, y_i are the spacial coordinates and are affected by bounding box and rescaling
# r_i is a distance and only affected by rescaling.
# first argument is always a spatial coordinate and second is always distance.

Coordinate conversion types:

  • RC_TO_ORIGINAL # recon -> original space
  • ORIGINAL_TO_RC # original -> recon space

conversion_type takes values of an enum:

class ConversionType(str, Enum):
    """Types of coordinate conversion."""

    RC_TO_ORIGINAL = "RC_to_Original"
    ORIGINAL_TO_RC = "Original_to_RC"

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Metadata

Release files for smrecon 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for smrecon 0.1.0
File Size Uploaded
smrecon-0.1.0.tar.gz 21.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for smrecon 0.1.0
File Interpreter ABI Platform
smrecon-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 27.5 kB

Release files / smrecon-0.1.0.tar.gz

Download URL smrecon-0.1.0.tar.gz
Size 21.3 kB
Tags Source
SHA-256 checksum
How to use checksums
fac214efe369b207f0aad08dc6bd51259cfcdd2bf1a032fb53f9780985aad926
BLAKE2b-256 checksum
How to use checksums
409af0bd37d6b687ba3affe0338a4500f3522b8d45bb552ba2e23ddbe463fe53
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.8

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Feb 11, 2025.

Transparency log

Release files / smrecon-0.1.0-py3-none-any.whl

Download URL smrecon-0.1.0-py3-none-any.whl
Size 6.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
14141b7a0809cfa5072567a64936738c4b375f7c6589c25bcf1cba2ccd2626fa
BLAKE2b-256 checksum
How to use checksums
2576d7688370bd3354a2499b271892740fad79d6a8c7756c0c7f0df53b7b44f8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.8

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Feb 11, 2025.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page