Skip to main content

Single Molecule Reconstructions

Project description

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

smrecon-0.1.0.tar.gz (21.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

smrecon-0.1.0-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

Details for the file smrecon-0.1.0.tar.gz.

File metadata

  • Download URL: smrecon-0.1.0.tar.gz
  • Upload date:
  • Size: 21.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for smrecon-0.1.0.tar.gz
Algorithm Hash digest
SHA256 fac214efe369b207f0aad08dc6bd51259cfcdd2bf1a032fb53f9780985aad926
MD5 d32b0c496365da57a2e091191c3051ab
BLAKE2b-256 409af0bd37d6b687ba3affe0338a4500f3522b8d45bb552ba2e23ddbe463fe53

See more details on using hashes here.

Provenance

The following attestation bundles were made for smrecon-0.1.0.tar.gz:

Publisher: pypi_publish.yml on joemans3/SMRecon

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file smrecon-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: smrecon-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for smrecon-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 14141b7a0809cfa5072567a64936738c4b375f7c6589c25bcf1cba2ccd2626fa
MD5 b1b019a7f15573c78ed5052a9e493bae
BLAKE2b-256 2576d7688370bd3354a2499b271892740fad79d6a8c7756c0c7f0df53b7b44f8

See more details on using hashes here.

Provenance

The following attestation bundles were made for smrecon-0.1.0-py3-none-any.whl:

Publisher: pypi_publish.yml on joemans3/SMRecon

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page