Skip to content

Commit

Permalink
Cleanup trailing whitespace
Browse files Browse the repository at this point in the history
  • Loading branch information
Yu-AnChen committed May 18, 2023
1 parent 3d4b9a0 commit 6683ce2
Show file tree
Hide file tree
Showing 16 changed files with 101 additions and 101 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ Running the following command to generate the configuration file
palom-svs-helper -i "Y:\DATA\SARDANA\MIHC\768473\RAW" -n "*Hem*" -o "Y:\DATA\SARDANA\MIHC\768473\RAW\palom\768473.ome.tif" -c "Y:\DATA\SARDANA\MIHC\768473\768473.yml"
```

And the resulting `Y:\DATA\SARDANA\MIHC\768473\768473.yml` file
And the resulting `Y:\DATA\SARDANA\MIHC\768473\768473.yml` file

```yaml
input dir: Y:\DATA\SARDANA\MIHC\768473\RAW
Expand Down Expand Up @@ -153,7 +153,7 @@ palom-svs run -c "Y:\DATA\SARDANA\MIHC\768473\768473.yml"
```

When the process is finished, a pyramidal OME-TIFF file will be generated along
with PNG files showing the feature-based registration results and a log file.
with PNG files showing the feature-based registration results and a log file.

```
Y:\DATA\SARDANA\MIHC\768473\RAW
Expand Down Expand Up @@ -199,7 +199,7 @@ c1rp = palom.color.PyramidHaxProcessor(c1r.pyramid, thumbnail_level=THUMBNAIL_LE
c2rp = palom.color.PyramidHaxProcessor(c2r.pyramid, thumbnail_level=THUMBNAIL_LEVEL)

c21l = palom.align.Aligner(
c1rp.get_processed_color(LEVEL),
c1rp.get_processed_color(LEVEL),
c2rp.get_processed_color(LEVEL),
ref_thumbnail=c1rp.get_processed_color(THUMBNAIL_LEVEL).compute(),
moving_thumbnail=c2rp.get_processed_color(THUMBNAIL_LEVEL).compute(),
Expand Down
2 changes: 1 addition & 1 deletion palom/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
align,
pyramid,
color,

# debugging
block_affine,
extract,
Expand Down
34 changes: 17 additions & 17 deletions palom/align.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,12 @@ def viz_shifts(shifts, grid_shape, dcenter=None, ax=None):
cax = ax.inset_axes([1.04, 0.0, 0.02, 1])
colorbar = plt.colorbar(im, cax=cax)
colorbar.set_ticks(colorbar_ticks)

return ax


def block_affine_matrices(mx, shifts):

def shift_affine_mx(mx, shift):
y, x = shift
mx_shift = np.eye(3)
Expand Down Expand Up @@ -155,7 +155,7 @@ def coarse_register_affine(self, **kwargs):
self.coarse_affine_matrix = np.vstack(
[affine_matrix, [0, 0, 1]]
)

@property
def affine_matrix(self):
if not hasattr(self, 'coarse_affine_matrix'):
Expand All @@ -169,13 +169,13 @@ def affine_matrix(self):
mx_moving
)
return affine_matrix

@property
def tform(self):
return skimage.transform.AffineTransform(
matrix=self.affine_matrix
)

def affine_transformed_moving_img(self, mxs=None):
if mxs is None:
mxs = self.affine_matrix
Expand All @@ -185,7 +185,7 @@ def affine_transformed_moving_img(self, mxs=None):
return block_affine_transformed_moving_img(
ref_img, moving_img, mxs
)

def compute_shifts(self, pcc_kwargs=None):
logger.info(f"Computing block-wise shifts")
ref_img = self.ref_img
Expand All @@ -212,7 +212,7 @@ def constrain_shifts(self):
self.original_shifts,
self.grid_shape
)

@property
def block_affine_matrices(self):
mx = self.affine_matrix
Expand All @@ -226,7 +226,7 @@ def block_affine_matrices_da(self):
self.grid_shape
)

def overlay_grid(self, ax=None):
def overlay_grid(self, ax=None):
import matplotlib.pyplot as plt
img = self.ref_thumbnail
img = skimage.exposure.rescale_intensity(img, out_range=np.uint16)
Expand All @@ -249,7 +249,7 @@ def overlay_grid(self, ax=None):
# checkerboard pattern
ax.imshow(np.indices(shape).sum(axis=0) % 2, cmap='cool', alpha=0.2)
return grid

def plot_shifts(self):
import matplotlib.pyplot as plt
fig, axs = plt.subplots(1, 2, sharex=True, sharey=True)
Expand All @@ -271,14 +271,14 @@ def get_aligner(
)
if thumbnail_level1 <= -1: thumbnail_level1 += len(reader1.pyramid)
if thumbnail_level2 <= -1: thumbnail_level2 += len(reader2.pyramid)
return Aligner(
reader1.read_level_channels(level1, channel1),
reader2.read_level_channels(level2, channel2),
reader1.read_level_channels(thumbnail_level1, channel1),
reader2.read_level_channels(thumbnail_level2, channel2),
reader1.level_downsamples[thumbnail_level1] / reader1.level_downsamples[level1],
reader2.level_downsamples[thumbnail_level2] / reader2.level_downsamples[level2]
)
return Aligner(
reader1.read_level_channels(level1, channel1),
reader2.read_level_channels(level2, channel2),
reader1.read_level_channels(thumbnail_level1, channel1),
reader2.read_level_channels(thumbnail_level2, channel2),
reader1.level_downsamples[thumbnail_level1] / reader1.level_downsamples[level1],
reader2.level_downsamples[thumbnail_level2] / reader2.level_downsamples[level2]
)


def match_thumbnail_level(readers):
Expand Down
6 changes: 3 additions & 3 deletions palom/block_affine.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ def block_affine_dask(


def block_affine(
position, block_shape,
position, block_shape,
transformation, src_img,
fill_empty=0, multichannel=False,
is_mask=False
):
assert np.min(block_shape) >= 0, (
f'block_shape {block_shape} is invalid'
f'block_shape {block_shape} is invalid'
)
if multichannel:
assert np.min(block_shape) == block_shape[0], (
Expand Down Expand Up @@ -68,7 +68,7 @@ def block_affine(
x0_src, y0_src = np.floor(
np.clip(inversed_corners.min(axis=0), 0, None)
).astype(int)

if multichannel:
src_img_block = src_img[:, y0_src:y1_src, x0_src:x1_src]
src_img_block = np.moveaxis(src_img_block, 0, 2)
Expand Down
16 changes: 8 additions & 8 deletions palom/cli/align_he.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,16 @@ def align_he(
aligner.coarse_register_affine(n_keypoints=5000, detect_flip_rotate=True)
plt.gcf().suptitle(f"{p2.name} (coarse alignment)", fontsize=8)
plt.gca().set_title(f"{p1.name} - {p2.name}", fontsize=6)

if viz_coarse_napari:
_ = viz_coarse(r1, r2, LEVEL, LEVEL, channel1, channel2, aligner.affine_matrix)

if not only_coarse:
aligner.ref_img = r1.read_level_channels(LEVEL, channel1)
aligner.moving_img = r2.read_level_channels(LEVEL, channel2)

aligner.compute_shifts()

fig = aligner.plot_shifts()
fig.suptitle(f"{p2.name} (block shift distance)", fontsize=8)
fig.axes[0].set_title(p1.name, fontsize=6)
Expand All @@ -60,9 +60,9 @@ def align_he(

set_matplotlib_font(font_size=8)
save_all_figs(out_dir=out_dir / 'qc', format='png')

if not only_qc:
mx = aligner.affine_matrix
mx = aligner.affine_matrix
if not only_coarse:
mx = aligner.block_affine_matrices_da
mosaic = palom.align.block_affine_transformed_moving_img(
Expand All @@ -84,7 +84,7 @@ def viz_coarse(r1, r2, level1, level2, channel1, channel2, mx):
try:
import napari
except ImportError:
return
return
import dask.array as da
v = napari.Viewer()
is_bf1 = palom.img_util.is_brightfield_img(r1.pyramid[-1][channel1])
Expand Down Expand Up @@ -139,7 +139,7 @@ def save_all_figs(dpi=300, format='pdf', out_dir=None):
try: import napari
except ImportError: print("napari is not installed")
else: napari.run()

'''
Example 1: inspect coarse alignment using napari
python align_he.py \
Expand All @@ -154,6 +154,6 @@ def save_all_figs(dpi=300, format='pdf', out_dir=None):
"X:\crc-scans\histowiz scans\20230105-orion_2_cycles\22199$P54_33_HE$US$SCAN$OR$001 _104050.svs" \
"X:\crc-scans\histowiz scans\20230105-orion_2_cycles\test" \
--px_size1 0.325
'''

24 changes: 12 additions & 12 deletions palom/cli/flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def optical_flow(
if mask is None:
mask = np.ones(mask_shape, dtype=bool)
assert mask.shape == mask_shape

def func(
p1, p2, ch1, ch2, mask,
block_info=None
Expand All @@ -74,7 +74,7 @@ def func(
slice(*np.ceil(np.divide(cloc, block_size)).astype(int))
]
return block_optical_flow(chunk1, chunk2, block_size, mask=chunk_mask)

shifts = da.map_blocks(
func,
p1=p1, p2=p2, ch1=ch1, ch2=ch2, mask=mask,
Expand Down Expand Up @@ -104,12 +104,12 @@ def block_optical_flow(
wv_img1 = skimage.util.view_as_windows(img1, block_shape, block_shape)
wv_img2 = skimage.util.view_as_windows(img2, block_shape, block_shape)
h, w = wv_img1.shape[:2]

wv_mask = np.ones((h, w, 1, 1), dtype=bool)
if mask is not None:
wv_mask = mask[..., np.newaxis, np.newaxis]
wv_mask = wv_mask[..., :h, :w]

out = np.zeros((3, h, w), dtype=np.float32)
product_func = itertools.product
if show_progress:
Expand Down Expand Up @@ -158,7 +158,7 @@ def compose_thumbnail(p1, p2, ch1, ch2, log_intensity=True):
rimg2 = skimage.exposure.match_histograms(rimg2, rimg1)
out = np.array([rimg1, rimg2, rimg1])
return out


def plot_legend(
shifts, max_radius, plot_scatter, plot_kde,
Expand Down Expand Up @@ -252,7 +252,7 @@ def process_img_channel_pair(
mask = None
if compute_mask:
mask = reader_block_mask(reader, block_size)

num_cpus = dask.system.cpu_count()
if num_workers > num_cpus:
num_workers =num_cpus
Expand Down Expand Up @@ -309,7 +309,7 @@ def process_img_channel_pair(

for ax in fig.get_axes():
ax.set_anchor('N')

plt.tight_layout()
out_dir = img_path.parent / 'qc'
out_dir.mkdir(exist_ok=True)
Expand All @@ -318,7 +318,7 @@ def process_img_channel_pair(
bbox_inches='tight', dpi=144
)
figures.append(fig)

if as_script: return
return all_shifts, figures

Expand Down Expand Up @@ -354,15 +354,15 @@ def process_img_channel_pair(
-a, --as_script=AS_SCRIPT
Default: True
---
---
NOTE: OTHER_CHANNELS is a list of integers, use [1] to indicate the
second channel and [1,2,3] (do not include space) for second, third and
fourth channels.
Ref https://google.github.io/python-fire/guide/#argument-parsing
Examples
Examples
python flow.py \
"Z:\RareCyte-S3\P54_CRCstudy_Bridge\S32-Tonsil-P54_Strip_P76.ome.tif" \
Expand Down
8 changes: 4 additions & 4 deletions palom/cli/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def main(argv=sys.argv):
'Generate configuration yaml file for palom-svs run'
)
)

parser.add_argument(
'-i',
metavar='input-dir',
Expand All @@ -36,9 +36,9 @@ def main(argv=sys.argv):
help='full path to the resulting configuration yaml file',
required=True
)

args = parser.parse_args(argv[1:])

if len(argv) == 1:
parser.print_help()
return 0
Expand Down Expand Up @@ -68,7 +68,7 @@ def main(argv=sys.argv):
)

channel_names = [
'-'.join(p.name.split('_')[-2:][::-1]).replace('.svs', '')
'-'.join(p.name.split('_')[-2:][::-1]).replace('.svs', '')
for p in ([ref_slide] + svs_paths)
]

Expand Down
4 changes: 2 additions & 2 deletions palom/cli/schema/svs-config-schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ image collection: any(include('bright-field image'), include('fluorescent image'

_image_base: &_image_base
# Filename or the remaining path to the imaging data relative to the input
# dir field
# dir field
filename: str()
# [optional but recommended]
# Channel name in the output ome-tiff
Expand All @@ -43,7 +43,7 @@ bright-field image:
channel names: list(str(), min=1, max=3, required=False)
# Output color mode, currently the following 4 modes are available
output mode: enum('aec', 'hematoxylin', 'color', 'grayscale', 'dab')

fluorescent image:
<<: *_image_base
output mode: str(equals='multichannel')
Expand Down
Loading

0 comments on commit 6683ce2

Please sign in to comment.