-
Notifications
You must be signed in to change notification settings - Fork 0
/
recipe.py
57 lines (45 loc) · 1.67 KB
/
recipe.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import numpy as np
import starfish
from starfish.types import Axes
"https://d2nhj9g34unfro.cloudfront.net/xiaoyan_qian/ISS_human_HCA_07_MultiFOV/main_files/experiment.json"
def process_fov(fov_num: int, experiment_str: str):
"""Process a single field of view of ISS data
Parameters
----------
fov_num : int
the field of view to process
experiment_str : int
path of experiment json file
Returns
-------
DecodedSpots :
tabular object containing the locations of detected spots.
"""
fov_str: str = f"fov_{int(fov_num):03d}"
# load experiment
experiment = starfish.Experiment.from_json(experiment_str)
fov = experiment[fov_str]
imgs = fov.get_image(starfish.FieldOfView.PRIMARY_IMAGES)
dots = imgs.max_proj(Axes.CH)
# filter
filt = starfish.image.Filter.WhiteTophat(masking_radius=15, is_volume=False)
filtered_imgs = filt.run(imgs, verbose=True, in_place=False)
filt.run(dots, verbose=True, in_place=True)
# find threshold
tmp = dots.sel({Axes.ROUND:0, Axes.CH:0, Axes.ZPLANE:0})
dots_threshold = np.percentile(np.ravel(tmp.xarray.values), 50)
# find spots
p = starfish.spots.DetectSpots.BlobDetector(
min_sigma=1,
max_sigma=10,
num_sigma=30,
threshold=dots_threshold,
measurement_type='mean',
)
# blobs = dots; define the spots in the dots image, but then find them again in the stack.
intensities = p.run(filtered_imgs, blobs_image=dots, blobs_axes=(Axes.ROUND, Axes.ZPLANE))
# decode
decoded = experiment.codebook.decode_per_round_max(intensities)
# save results
df = decoded.to_decoded_spots()
return df