Skip to content

Commit

Permalink
full offset (#225)
Browse files Browse the repository at this point in the history
  • Loading branch information
ordabayevy committed Oct 25, 2021
1 parent 9643e5d commit 24dcbf2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 13 deletions.
23 changes: 10 additions & 13 deletions tapqir/imscroll/glimpse_reader.py
Expand Up @@ -282,31 +282,28 @@ def read_glimpse(path, **kwargs):
assert (target_xy[dtype][c] > 0.5 * P - 1).all()
assert (target_xy[dtype][c] < 0.5 * P).all()

min_data = np.inf
for dtype in data.keys():
# concatenate channels
data[dtype] = np.stack(data[dtype], -3)
target_xy[dtype] = np.stack(target_xy[dtype], -2)
# convert data into torch tensor
min_data = min(min_data, data[dtype].min())
# convert data to torch tensor
data[dtype] = torch.tensor(data[dtype])
target_xy[dtype] = torch.tensor(target_xy[dtype])

# process offset data
offsets = OrderedDict(sorted(offsets.items()))
offset_samples = np.array(list(offsets.keys()))
offset_weights = np.array(list(offsets.values()))
# if data.min() is smaller than the smallest offset then
# add a single point to offset samples with that value - 1
if min_data <= offset_samples[0]:
offset_samples = np.insert(offset_samples, 0, min_data - 1)
offset_weights = np.insert(offset_weights, 0, 1)
# normalize weights
offset_weights = offset_weights / offset_weights.sum()
# remove values from lower and upper 0.5 percentile
low_mask = offset_weights.cumsum() < 0.005
low_weights = offset_weights[low_mask].sum()
offset_samples = offset_samples[~low_mask]
offset_weights = offset_weights[~low_mask]
offset_weights[0] += low_weights
high_mask = offset_weights.cumsum() > 0.995
high_weights = offset_weights[high_mask].sum()
offset_samples = offset_samples[~high_mask]
offset_weights = offset_weights[~high_mask]
offset_weights[-1] += high_weights
# convert data into torch tensor
# convert data to torch tensor
offset_samples = torch.tensor(offset_samples, dtype=torch.int)
offset_weights = torch.tensor(offset_weights)

Expand Down
14 changes: 14 additions & 0 deletions tapqir/main.py
Expand Up @@ -166,12 +166,17 @@ def glimpse(
for c in range(num_channels):
if len(DEFAULTS["channels"]) < c + 1:
DEFAULTS["channels"].append(defaultdict(lambda: None))
else:
DEFAULTS["channels"][c] = defaultdict(
lambda: None, DEFAULTS["channels"][c]
)
keys = [
"name",
"glimpse-folder",
"ontarget-aoiinfo",
"offtarget-aoiinfo",
"driftlist",
"ontarget-labels",
]
typer.echo(f"\nINPUTS FOR CHANNEL #{c}\n")
for key in keys:
Expand All @@ -184,6 +189,15 @@ def glimpse(
if "offtarget-aoiinfo" in DEFAULTS["channels"][c]:
del DEFAULTS["channels"][c]["offtarget-aoiinfo"]
continue
elif key == "ontarget-labels":
labels = typer.confirm(
"Add on-target labels?",
default=("ontarget-labels" in DEFAULTS["channels"][c]),
)
if not labels:
if "ontarget-labels" in DEFAULTS["channels"][c]:
del DEFAULTS["channels"][c]["ontarget-labels"]
continue
DEFAULTS["channels"][c][key] = typer.prompt(
desc[key], default=DEFAULTS["channels"][c][key]
)
Expand Down

0 comments on commit 24dcbf2

Please sign in to comment.