<jupyter_start><jupyter_text>Synthetic examplesHere are some examples on how to run ISTDECO on simulated data. Some notation:- $r$ Number of imaging rounds- $c$ Number of channels- $m$ Number of codes in codebook- $h$ Image height- $w$ Image width- $\sigma_{psf}$ Standard deviation of the Gaussians describing the spatial shape of the spots- $Y \in \mathbb{R}_+^{r\times c \times h \times w}$ Image data- $D \in \mathbb{R}_+^{m \times r\times c}$ Codebook (Combinatorial labels)- $b \in \mathbb{R}_+^{m \times r\times c}$ Background  1D exampleFirst we generate some sythetic data. Everything we do here is in 1D (since it is much easier to visualise).<jupyter_code>import numpy as np
from istdeco import ISTDeco
from utils import random_codebook, random_image_stack
import matplotlib.pyplot as plt
%matplotlib notebook

ndim = 1

# Number of rounds
r = 5

# Number of channels
c = 4

# Number of codes in the codebook
m = 25

# Spatial dimensions (y, x)
space = (1,75)

# Standard deviation for the shapes of spots. 
psf = 1.2

# Number of spots
n_signals = 15

# Create a random codebook
codebook = random_codebook(n_codes=m, n_rounds=r, n_channels=c)

# Create some image data
image_data, gt = random_image_stack(codebook, n_signals, ndim, signal_std=psf, im_shape=space)

# PLOT!
plt.subplot(211)
plt.imshow(codebook.reshape(m,-1).T)
plt.title('The codebook')
plt.ylabel('Rounds & Channels')
plt.xlabel('Different barcode types')

plt.subplot(212)
plt.imshow(image_data.reshape(r*c,-1))
plt.title('Image data')
plt.xlabel('Space')
plt.ylabel('Rounds and channels')

plt.tight_layout(pad=3.0)<jupyter_output>69.91425102221828<jupyter_text>Let's run ISTDECO on the simulated images and plot the deconvolved images.<jupyter_code>psf_std = (0, 1.2)
model = ISTDeco(image_data, codebook, psf_std)
X, Q, loss = model.run()

plt.figure()
plt.imshow(X.squeeze())
plt.scatter(gt[:,0],gt[:,2], label='GT', color='red', marker='x')
plt.xlabel('Space')
plt.ylabel('Barcode type label')
plt.legend()<jupyter_output><empty_output><jupyter_text>Dense 1D ExampleAnother 1D example but with a much higher spot density.<jupyter_code>n_spots = 50   # Number of signals


# Create some image data
dense_image_data, dense_gt = \
    random_image_stack(codebook, n_spots, ndim, signal_std=psf, im_shape=space)


plt.figure()
plt.imshow(dense_image_data.reshape(r*c,-1))
plt.title('Image data')
plt.xlabel('Space')
plt.ylabel('Rounds and channels')
model = ISTDeco(dense_image_data, codebook, psf_std, b=10)
X, _, loss = model.run(niter=100)

plt.figure()
plt.imshow(X.squeeze())
plt.scatter(dense_gt[:,0],dense_gt[:,2], label='GT', color='red', marker='x')
plt.xlabel('Space')
plt.ylabel('Barcode type label')
plt.legend()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13382084095063984, 'fraction_numerical': 0.020840950639853747, 'mean_word_length': 5.722358722358722, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '541578', 'license': 'MIT', 'n_tokens_mistral': 1083, 'n_tokens_neox': 1004, 'n_words': 277, 'path': 'synthetic_example.ipynb', 'repo_name': 'axanderssonuu/istdeco', 'size': '2735'}