Skip to content

Commit

Permalink
Updated python viz readme and python viz files.
Browse files Browse the repository at this point in the history
  • Loading branch information
johnmetzcar committed Feb 2, 2023
1 parent afd5ea0 commit 2e30e20
Show file tree
Hide file tree
Showing 15 changed files with 42 additions and 279 deletions.
15 changes: 11 additions & 4 deletions python_imaging/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,16 @@

## Scripts



Advanced scripts - using the PhysiCellPlotter class in `image_processing_for_physicell.py`. Place scripts in `output` or other directory at same level or alter path assignment.
*
Advanced scripts - using the PhysiCellPlotter class in `image_processing_for_physicell.py`. Place scripts in `output` or other directory at same level or alter path assignment. Examples used to produce stills and movies for [this preprint](https://www.biorxiv.org/content/10.1101/2022.11.21.514608) are given below. Using the various options available in the PhysiCellPlotter class, other visualizations can be created.
* `full_history_movie_script.py`: Generates movie using all available outputs and plots the full cell positional histories as well as current cell positions and ECM fiber element orientations.
* `generic_movie_maker.py`: Generates a movie with default vizualization values.
sys.path.append(r'../python_imaging')
* `full_history_still_script.py`: Generates still, ploting the full cell positional histories up to the point of the still as well as current cell positions and ECM fiber element orientations
* `image_processing_script.py`: Generic example plotter. Outputs and shows a plot of the diffusing substrate and overlays cell positions. Loads frame 100.
* `partial_history_2_level_contour_movie.py`: Generates of movie with each frame a recent portion of cell positional histories and anisotropy with 2 contour color levels (used for cases of instant ECM remodeling) as well as current cell positions and ECM fiber element orientations.
* `partial_history_2_level_contour_still.py`: Plots a recent portion of cell positional histories and anisotropy with 2 contour color levels (used for cases of instant ECM remodeling) as well as current cell positions and ECM fiber element orientations.
* `partial_history_multilevel_contour_movie.py`: Plots a recent portion of cell positional histories and anisotropy with multiple contour color levels as well as current cell positions and ECM fiber element orientations.
* `partial_history_multilevel_contour_still.py`: Generates of movie with each frame a recent portion of cell positional histories and anisotropy with multiple contour color levels as well as current cell positions and ECM fiber element orientations.


Basic scripts. Original basis for integrated plotter in `image_processing_for_physicell.py`. Included as basic original examples. Place scripts in `output` or other directory at same level or alter path assignment.
Expand All @@ -17,3 +23,4 @@ Basic scripts. Original basis for integrated plotter in `image_processing_for_ph
* `cell_plus_environment_plotter.py`: Generates a still of the ECM anisotorpy and orientations with cell overlay. Alter as needed for need.
* `cell_track_plotter.py`: Plots still of cells and cell positional histories.
* `cell_tracker_movie.py`: Generates a movie of cells and cell positional histories.
* `finished-combined-plot.py`: Generates a layered plot combining cell positions and multiple aspcts of the microenvironment.
26 changes: 3 additions & 23 deletions python_imaging/cell_march_movie_script.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import sys
import matplotlib.pyplot as plt
sys.path.append(r'/Users/JohnMetzcar/Documents/GitHub/AMIGOS-invasion/python_imaging')
sys.path.append(r'../python_imaging')

from image_processing_for_physicell import *

Expand All @@ -17,7 +17,7 @@
"load_SVG_data": False,
'plot_cells_from_physicell_data': True,
"produce_for_movie" : True,
"contour_options" : {'lowest_contour': 0.90, ### I woud like this to be cleaner - but it does work!!!
"contour_options" : {'lowest_contour': 0.90,
'upper_contour': 0.92,
'number_of_levels': 25,
'color_map_name': 'Reds',
Expand All @@ -33,32 +33,12 @@
'INCLUDE_FULL_HISTORY': False
}

#### Right now, if you don't have None or the full contour and quiver options, it will break in the plotting ... I wonder if there
#### is a better/more robust way to do it (kwargs???, lots of "trapping"??) but this will be handled later
#### Right now, if you don't have None or the full contour and quiver options, it will break in the plotting.

mf = PhysiCellPlotter()

mf.produce_movie(save_name='figure_2a_march', movie_options=movie_options_for_figure_2a, image_options=options_for_figure2a)

# m2 = PhysiCellPlotter()
# m3 = PhysiCellPlotter()

# image_list_for_figure2a = []

# image_list_for_figure2a = [90, 500, 1200]

# file_name = 'march_' + str(90)

# for number in image_list_for_figure2a:
# mf.generic_plotter(starting_index=number, number_of_samples=1, options=options_for_figure2a, file_name='march_' + str(number))

# mf.generic_plotter(starting_index=90, number_of_samples=1, options=options_for_figure2a)
# m2.generic_plotter(starting_index=500, number_of_samples=1, options=options_for_figure2a)
# m3.generic_plotter(starting_index=1200, number_of_samples=1, options=options_for_figure2a)

# mf.generic_plotter (number_of_samples=10, options=options_for_figure2a)
# mf.create_separate_colorbar(contour_options=options_for_figure2a['contour_options'])

# generic_plotter (start, intervnal, finish, save_filename, data_path, save_path, options)
#
# All based on options/logic- function
Expand Down
7 changes: 2 additions & 5 deletions python_imaging/cell_march_stills_script.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import sys
import matplotlib.pyplot as plt
sys.path.append(r'/Users/JohnMetzcar/Documents/GitHub/AMIGOS-invasion/python_imaging')
sys.path.append(r'../python_imaging')

from image_processing_for_physicell import *

Expand All @@ -26,12 +26,9 @@
"mask_quiver": False}
}

#### Right now, if you don't have None or the full contour and quiver options, it will break in the plotting ... I wonder if there
#### is a better/more robust way to do it (kwargs???, lots of "trapping"??) but this will be handled later ...
#### Right now, if you don't have None or the full contour and quiver options, it will break in the plotting ...

mf = PhysiCellPlotter()
# m2 = PhysiCellPlotter()
# m3 = PhysiCellPlotter()

image_list_for_figure2a = []

Expand Down
25 changes: 0 additions & 25 deletions python_imaging/cell_plus_environment_movie_maker.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,21 +92,6 @@ def create_plot(snapshot, folder, output_folder='.', output_plot=True, show_plot
# levels_ecm = np.linspace(1e-14, 1.0, num_levels)
levels_ecm = np.linspace(0.90, 0.93, num_levels) # for the march environment - need to especially highlight small changes in anistoropy.

# Old function and scripting to scale and threshold anisotorpy values for later use in scaling lenght of ECM fibers
# for visualization purposes.

# micro = plane_anisotropy
# micro_scaled = micro
#
# def curve(x):
# #return (V_max * x) / (K_M + x)
# return 0.5 if x > 0.5 else x

# for i in range(len(micro)):
# for j in range(len(micro[i])):
# #micro_scaled[i][j] = 10 * math.log10(micro[i][j] + 1) / math.log10(2)
# micro_scaled[i][j] = curve(micro[i][j])

##### Process data for plotting - weight fibers by anisotropy, mask out 0 anisotropy ECM units, get cell radii and types

# Anisotropy strictly runs between 0 and 1. Element by element mulitplication produces weighted lengths between 0 - 1
Expand Down Expand Up @@ -148,17 +133,10 @@ def create_plot(snapshot, folder, output_folder='.', output_plot=True, show_plot
radius=plot_df.loc[j, 'radius'], alpha=0.7, edgecolor='black')
ax.add_artist(circ)

# add quiver layer with scaled arrows ###
# q = ax.quiver(xx_ecm[mask], yy_ecm[mask], scaled_ECM_x[mask], scaled_ECM_y[mask], pivot='middle', angles='xy', scale_units='inches', scale=2.0, headwidth=0,
# width=0.0015) ## What is the deal with the line segment lengths shifting as the plots progress when I don't ue teh scaling??

# add ECM orientation vectors unscaled by anistorpy ###
plt.quiver(xx, yy, ECM_x, ECM_y,
pivot='middle', angles='xy', scale_units='inches', scale=3.0, hheadwidth=0,headlength=0, headaxislength=0)

# ax.axis('scaled') #used to be 'equal' https://stackoverflow.com/questions/45057647/difference-between-axisequal-and-axisscaled-in-matplotlib
# This changes teh axis from -750,750 to ~-710,730. It looks better with scaled compared to axix, but either way it changes the plot limits

# Labels and title (will need removed for journal - they will be added manually)
ax.set_xlabel('x [micron]')
ax.set_ylabel('y [micron]')
Expand Down Expand Up @@ -209,9 +187,6 @@ def create_movie(data_path: str, save_path: str, save_name: str):

# make the movie - see ffmpeg documentation for more information

# consider saving as jpegs - https://blender.stackexchange.com/questions/148231/what-image-format-encodes-the-fastest-or-at-least-faster-png-is-too-slow
# consider compiling as movie instead of saving the files (all to increase processing speed) (then again, it was teh same speed)

# consider not loading the unneeded data - and be sure to get rid of the unneeded fields!!!

os.system(
Expand Down
37 changes: 0 additions & 37 deletions python_imaging/cell_plus_environment_plotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,21 +97,6 @@ def create_plot(snapshot, folder, output_folder='.', output_plot=True, show_plot
# levels_ecm = np.linspace(1e-14, 1.0, num_levels)
levels_ecm = np.linspace(0.90, 0.93, num_levels) # for the march environment - need to especially highlight small changes in anistoropy.

# Old function and scripting to scale and threshold anisotorpy values for later use in scaling lenght of ECM fibers
# for visualization purposes.

# micro = plane_anisotropy
# micro_scaled = micro
#
# def curve(x):
# #return (V_max * x) / (K_M + x)
# return 0.5 if x > 0.5 else x

# for i in range(len(micro)):
# for j in range(len(micro[i])):
# #micro_scaled[i][j] = 10 * math.log10(micro[i][j] + 1) / math.log10(2)
# micro_scaled[i][j] = curve(micro[i][j])

##### Process data for plotting - weight fibers by anisotropy, mask out 0 anisotropy ECM units, get cell radii and types

# Anisotropy strictly runs between 0 and 1. Element by element mulitplication produces weighted lengths between 0 - 1
Expand Down Expand Up @@ -158,17 +143,10 @@ def create_plot(snapshot, folder, output_folder='.', output_plot=True, show_plot
# radius=plot_df.loc[j, 'radius'], alpha=0.7, edgecolor='black')
ax.add_artist(circ)

# add quiver layer with scaled arrows ###
# q = ax.quiver(xx_ecm[mask], yy_ecm[mask], scaled_ECM_x[mask], scaled_ECM_y[mask], pivot='middle', angles='xy', scale_units='inches', scale=2.0, headwidth=0,
# width=0.0015) ## What is the deal with the line segment lengths shifting as the plots progress when I don't ue teh scaling??

# add ECM orientation vectors unscaled by anistorpy ###
plt.quiver(xx, yy, ECM_x, ECM_y,
pivot='middle', angles='xy', scale_units='inches', scale=4.75, headwidth=0,headlength=0, headaxislength=0, alpha = 0.3) ### was at 3.0 before changing the mat size from 12 to 8 to match my otherr images AND get the font for the ticks large

# ax.axis('scaled') #used to be 'equal' https://stackoverflow.com/questions/45057647/difference-between-axisequal-and-axisscaled-in-matplotlib
# This changes teh axis from -750,750 to ~-710,730. It looks better with scaled compared to axix, but either way it changes the plot limits

# Labels and title (will need removed for journal - they will be added manually)

plt.ylim(-500, 500)
Expand Down Expand Up @@ -203,19 +181,4 @@ def create_plot(snapshot, folder, output_folder='.', output_plot=True, show_plot
snapshot = sys.argv[1]
output_plot = bool(distutils.util.strtobool(sys.argv[2]))
show_plot = bool(distutils.util.strtobool(sys.argv[3]))

# elif (len(sys.argv) == 4):
# usage_str = "Usage: %s <start tracking index> <step interval for tracking> <# of samples to include>" % (
# sys.argv[0])
# # print(usage_str)
# starting_index = int(sys.argv[1])
# sample_step_interval = int(sys.argv[2])
# number_of_samples = int(sys.argv[3])

# # print("e.g.,")
# # eg_str = "%s 0 1 10 indicates start at 0, go up by ones, and stop when you 10 samples" % (sys.argv[0])
# # print(eg_str)

# Sample call with meaningful variables:
# create_plot('output00000275', output_folder='21_03_leader_follower_model_3_test/',output_plot=False, show_plot=False)
create_plot(snapshot, '.', '', output_plot=True, show_plot=False)
25 changes: 2 additions & 23 deletions python_imaging/finished-combined-plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,21 +88,6 @@ def create_plot(snapshot, folder, output_folder='.', output_plot=True, show_plot
levels_o2 = np.linspace(1e-14, 38, num_levels)
levels_ecm = np.linspace(1e-14, 1.0, num_levels)

# Old function and scripting to scale and threshold anisotorpy values for later use in scaling lenght of ECM fibers
# for visualization purposes.

# micro = plane_anisotropy
# micro_scaled = micro
#
# def curve(x):
# #return (V_max * x) / (K_M + x)
# return 0.5 if x > 0.5 else x

# for i in range(len(micro)):
# for j in range(len(micro[i])):
# #micro_scaled[i][j] = 10 * math.log10(micro[i][j] + 1) / math.log10(2)
# micro_scaled[i][j] = curve(micro[i][j])

##### Process data for plotting - weight fibers by anisotropy, mask out 0 anisotropy ECM units, get cell radii and types

# Anisotropy strictly runs between 0 and 1. Element by element mulitplication produces weighted lengths between 0 - 1
Expand Down Expand Up @@ -145,15 +130,9 @@ def create_plot(snapshot, folder, output_folder='.', output_plot=True, show_plot
ax.add_artist(circ)

# add quiver layer with scaled arrows ###
q = ax.quiver(xx_ecm[mask], yy_ecm[mask], scaled_ECM_x[mask], scaled_ECM_y[mask], pivot='middle', angles='xy', scale_units='inches', scale=2.0, headwidth=0,
width=0.0015) ## What is the deal with the line segment lengths shifting as the plots progress when I don't ue teh scaling??

# add unscaled arrows ###
# plt.quiver(xx[mask], yy[mask], ECM_x[mask], ECM_y[mask],
# pivot='mid', angles='xy', headwidth=3)
q = ax.quiver(xx_ecm[mask], yy_ecm[mask], scaled_ECM_x[mask], scaled_ECM_y[mask], pivot='middle', angles='xy', scale_units='inches', scale=2.0, headwidth=0,headlength=0, headaxislength=0,
width=0.0015)

# ax.axis('scaled') #used to be 'equal' https://stackoverflow.com/questions/45057647/difference-between-axisequal-and-axisscaled-in-matplotlib
# This changes teh axis from -750,750 to ~-710,730. It looks better with scaled compared to axix, but either way it changes the plot limits

# Labels and title
ax.set_xlabel('x [micron]')
Expand Down
24 changes: 3 additions & 21 deletions python_imaging/full_history_movie_script.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import sys
import matplotlib.pyplot as plt
sys.path.append(r'/Users/JohnMetzcar/Documents/GitHub/AMIGOS-invasion/python_imaging')
sys.path.append(r'../python_imaging')

from image_processing_for_physicell import *

Expand All @@ -27,26 +27,8 @@
'INCLUDE_FULL_HISTORY': True
}

#### Right now, if you don't have None or the full contour and quiver options, it will break in the plotting ... I wonder if there
#### is a better/more robust way to do it (kwargs???, lots of "trapping"??) but this will be handled later ... and I can ask Randy etc
### What is up with scaling - hum ...

# oof - I got different results on the two runs when I did and didn't scale by anistoropy ... yikes! How do I manage that!!
#### Right now, if you don't have None or the full contour and quiver options, it will break in the plotting ...

mf = PhysiCellPlotter()

mf.produce_movie(save_name='figure_2d_circular_ecm_with_chemotaxsis', movie_options=movie_options_for_figure_2d, image_options=options_for_figure2d)

# mf.generic_plotter(starting_index=0, number_of_samples=1, options=options_for_figure2d, file_name='circular_ECM_w_chemical_cue_0')

# image_list_for_figure2d = [150, 417]

# options_for_figure2d['plot_ECM_orientation'] = False
# options_for_figure2d['retrieve_ECM_data'] = False
# options_for_figure2d['load_full_physicell_data'] = False


# mf.produce_movie()

# for number in image_list_for_figure2d:
# mf.generic_plotter(starting_index=0, number_of_samples=number, options=options_for_figure2d, file_name='circular_ECM_w_chemical_cue_' + str(number))
mf.produce_movie(save_name='figure_2d_circular_ecm_with_chemotaxsis', movie_options=movie_options_for_figure_2d, image_options=options_for_figure2d)
8 changes: 2 additions & 6 deletions python_imaging/full_history_still_script.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import sys
import matplotlib.pyplot as plt
sys.path.append(r'/Users/JohnMetzcar/Documents/GitHub/AMIGOS-invasion/python_imaging')
sys.path.append(r'../python_imaging')

from image_processing_for_physicell import *

Expand All @@ -20,11 +20,7 @@
"mask_quiver": False}
}

#### Right now, if you don't have None or the full contour and quiver options, it will break in the plotting ... I wonder if there
#### is a better/more robust way to do it (kwargs???, lots of "trapping"??) but this will be handled later ... and I can ask Randy etc
### What is up with scaling - hum ...

# oof - I got different results on the two runs when I did and didn't scale by anistoropy ... yikes! How do I manage that!!
#### Right now, if you don't have None or the full contour and quiver options, it will break in the plotting ...

mf = PhysiCellPlotter()

Expand Down
2 changes: 1 addition & 1 deletion python_imaging/generic_movie_maker.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import sys
import matplotlib.pyplot as plt
sys.path.append(r'/Users/JohnMetzcar/Documents/GitHub/AMIGOS-invasion/python_imaging')
sys.path.append(r'../python_imaging')

from image_processing_for_physicell import *

Expand Down
Loading

0 comments on commit 2e30e20

Please sign in to comment.