Skip to content

Commit

Permalink
address PR comments and clean up code
Browse files Browse the repository at this point in the history
  • Loading branch information
cfrick13 committed Nov 27, 2024
1 parent d22d67b commit 3d0463a
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ def return_glasbey_on_dark(N=255, cell_id=None, cell_color=None, from_list=False
N: int, the number of colors to return
cell_id: int, the cell id to change the color of
cell_color: array, the RGB color to change the cell to
from_list: bool, whether colormap should be returned from ListedColormap or not
"""
from matplotlib.colors import LinearSegmentedColormap, ListedColormap
from nuc_morph_analysis.analyses.dataset_images_for_figures.glasbey_on_dark import (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#%%
# this code is not used in the final analysis, but was used to confirm that there is no correlation between density and nuclear area
from nuc_morph_analysis.lib.visualization.reference_points import COLONY_COLORS, COLONY_LABELS
import matplotlib.pyplot as plt
import numpy as np
Expand All @@ -9,6 +10,8 @@
from pathlib import Path
from sklearn.linear_model import LinearRegression
from matplotlib.ticker import MaxNLocator
import matplotlib


#%%
# set figure directory
Expand All @@ -22,7 +25,6 @@
dfm = filter_data.all_timepoints_minimal_filtering(df)

#%% # plot density over time for each colony along colony time
import matplotlib
matplotlib.rcParams.update({'font.size': 8})
matplotlib.rcParams.update({'axes.titlesize': 8})
matplotlib.rcParams.update({'axes.labelsize': 8})
Expand All @@ -36,10 +38,10 @@


#%%
# plot density as a function of nucleus size (and compare to old density metric)
# plot density as a function of nucleus size
colony='medium'
x_col = '2d_area_nucleus'
for yi,y_col in enumerate(['2d_area_nuc_cell_ratio','density','inv_cyto_density']):
for yi,y_col in enumerate(['2d_area_nuc_cell_ratio']):

dfsub = dfm[dfm['colony']==colony].copy()
dfsub.dropna(subset=[y_col],inplace=True)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@

from nuc_morph_analysis.analyses.dataset_images_for_figures.figure_helper import return_glasbey_on_dark


from nuc_morph_analysis.analyses.density.visually_validate_watershed_psuedo_cell_seg_workflow import get_contours_from_pair_of_2d_seg_image, draw_contours_on_image
from nuc_morph_analysis.analyses.density.extra_checks.visually_validate_watershed_psuedo_cell_seg_workflow import get_contours_from_pair_of_2d_seg_image, draw_contours_on_image
from nuc_morph_analysis.analyses.dataset_images_for_figures.figure_helper import INTENSITIES_DICT

import matplotlib
Expand Down Expand Up @@ -64,7 +63,7 @@ def determine_colormaps(img,key,crop_exp):

def run_validation_and_plot(TIMEPOINT=88,track=81463,colony='medium',RESOLUTION_LEVEL=1,plot_everything=False, testing=False):
"""
run an image through the watershed based pseudo cell segmentation and examine the outputs
run an image through the watershed based pseudo cell segmentation and examine the outputs (as full fov and crop within that fov)
optionally, run a test image through the same pipeline
Parameters
Expand Down Expand Up @@ -121,7 +120,6 @@ def run_validation_and_plot(TIMEPOINT=88,track=81463,colony='medium',RESOLUTION_
for full_crop, sizes in [('crop',(track_x,track_y,crop_w,crop_h)),('full',(0,0,mip.shape[1],mip.shape[0]))]:
x1,y1,w,h = sizes
crop_exp = np.index_exp[y1:y1+h,x1:x1+w]
# key_list = ['raw_image','mip_of_labeled_image','binarized_mip','distance','pseudo_cells_img','overlay','colorize']
key_list = ['mip_of_labeled_image','distance','pseudo_cells_img','colorize']


Expand Down Expand Up @@ -201,29 +199,24 @@ def run_validation_and_plot(TIMEPOINT=88,track=81463,colony='medium',RESOLUTION_
ax.set_position(position)
# adjust position of colorbar
cbar_position = cbar.ax.get_position()
# cbar.ax.set_position([cbar_position.x0+0.05,cbar_position.y0,cbar_position.width,cbar_position.height]) # for left location
cbar.ax.set_position([cbar_position.x0,cbar_position.y0-0.15,cbar_position.width,cbar_position.height]) # for bottom location

# now save the figure
savedir = Path(__file__).parent / 'figures' / 'watershed_figure_illustration'
savedir.mkdir(exist_ok=True,parents=True)

for ext in ['.png','.pdf']:
savename = f'{colony}_{track}_{TIMEPOINT}_{full_crop}_res{RESOLUTION_LEVEL}_{cmapstr}'
savepath = savedir / savename
print(f'Saved figure to {savepath}')
save_and_show_plot(str(savepath),
file_extension=ext,
figure=fig,
transparent=True,
keep_open=True,
**{'dpi':600}
)
ext = '.pdf'
savename = f'{colony}_{track}_{TIMEPOINT}_{full_crop}_res{RESOLUTION_LEVEL}_{cmapstr}'
savepath = savedir / savename
save_and_show_plot(str(savepath),
file_extension=ext,
figure=fig,
transparent=True,
keep_open=True,
**{'dpi':600}
)

if __name__ == '__main__':
# set the details
# dft0 = run_validation_and_plot(120,track=84619,colony='medium',RESOLUTION_LEVEL=1,plot_everything=True)
# dft1 = run_validation_and_plot(0,track=87172,colony='medium',RESOLUTION_LEVEL=1,plot_everything=False)
# dft1 = run_validation_and_plot(48,track=87099,colony='medium',RESOLUTION_LEVEL=1,plot_everything=False)
dft1 = run_validation_and_plot(88,track=81463,colony='medium',RESOLUTION_LEVEL=1,plot_everything=False)

This file was deleted.

0 comments on commit 3d0463a

Please sign in to comment.