Skip to content

Commit

Permalink
Adding in python viz scripts that are more generic.
Browse files Browse the repository at this point in the history
  • Loading branch information
johnmetzcar committed Feb 1, 2023
1 parent 7e0ccb5 commit afd5ea0
Show file tree
Hide file tree
Showing 12 changed files with 187 additions and 214 deletions.
38 changes: 10 additions & 28 deletions python_imaging/README.md
Original file line number Diff line number Diff line change
@@ -1,37 +1,19 @@
# Python Imaging
# Python Visualizations

In an effort to create some better imaging to view cells, ECM components and other things simultaneously, these scripts have been written.
`image_processing_for_physicell.py` contains the class `PhysiCellPlotter`. This class enables reproducible visualization with many options - including setting which layers to include (cell, ECM components, diffusing fields), positional tracking of cell movement history, and smoothly generating stills and movies sequentially. It uses a modified version of [`pyMCDS.py`](https://github.com/PhysiCell-Tools/python-loader) - `pyMCDS_ECM.py`. The modifications include loading ECM data .mat outputs and formatting that data for use in visualizations.


## Scripts

* `basic_cell_plot.py`: create a plot with Cells plotted.
* `basic_oxygen_density.py`: Plot the density of oxygen.
* `basic_ecm_density.py`: Plot the ECM density.
* `basic_ecm_anisotropy.py`: Plot the ECM anisotropy.

## ToDo
* Read in data
* ECM anisotropy plot
* ECM alignment plot
* Overlap all elements / modularity
* Panels

## Other stuff

### Helpful function to load in ECM matlab data
```
import scipy.io as sci

sim_frame = 'output00001192' # The name of the simulation frame (eg. `initial`, `output00001192`). This is not the file name
output_path = 'example_output' # The folder with all the output data
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.
*

def load_ecm_data(file_name):
mat = sci.loadmat(file_name)['ECM_Data']
data = {"x":mat[0], "y":mat[1], "z":mat[2], "anisotropy":mat[3], "density":mat[4], "fiber_alignment_x":mat[5], "fiber_alignment_y":mat[6], "fiber_alignment_z":mat[7], "gradient_x":mat[8], "gradient_y":mat[9], "gradient_z":mat[10]}

return data
# load data
ecm_data = load_ecm_data(output_path + '/' + sim_frame + '_ECM.mat')
```
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.
* `basic_cell_plot.py`: create a plot with Cells plotted.
* `cell_plus_environment_movie_maker.py`: Generates a movie of the ECM anisotorpy and orientations with cell overlay. Alter as needed for need.
* `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.
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,12 @@
}

#### 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!!
#### is a better/more robust way to do it (kwargs???, lots of "trapping"??) but this will be handled later

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()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@
}

#### 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!!
#### is a better/more robust way to do it (kwargs???, lots of "trapping"??) but this will be handled later ...

mf = PhysiCellPlotter()
# m2 = PhysiCellPlotter()
Expand All @@ -41,7 +38,8 @@
image_list_for_figure2a = [90, 500, 1200]

file_name = 'march_' + str(90)

print('To make \'March\' images - must hard code both colors to blue!!!!')
print('SEE plot_cells_from_physicell_data function!!!')
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))

Expand Down
52 changes: 0 additions & 52 deletions python_imaging/figure_2b_movie_script.py

This file was deleted.

70 changes: 0 additions & 70 deletions python_imaging/figure_2b_stills_script.py

This file was deleted.

42 changes: 0 additions & 42 deletions python_imaging/figure_2c_stills_script.py

This file was deleted.

File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@
"produce_for_movie" : True,
"contour_options" : {'lowest_contour': 1e-14, ### I woud like this to be cleaner - but it does work!!!
'upper_contour': 1.0,
'number_of_levels': 25,
'number_of_levels': 2,
'color_map_name': 'Reds',
'color_bar': True
'color_bar': False
},
}

movie_options_for_figure_4 = {}

movie_options_for_figure_4 = {'INCLUDE_ALL_SVGs': True,
'INCLUDE_FULL_HISTORY': True
'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
Expand All @@ -52,7 +52,11 @@

# starting_index: int = 0, sample_step_interval: int = 1, number_of_samples: int = 120,

mf.produce_movie(save_name='figure_4_parameter_set_21_80_80_ECM_with_chemotaxsis', movie_options=movie_options_for_figure_4, image_options=options_for_figure4_movie)
mf.produce_movie(save_name='adh_0_repulsion_0_speed_10_20_20_ECM_with_write_05', trail_length=15, movie_options=movie_options_for_figure_4, image_options=options_for_figure4_movie)

# next - adh_0_repulsion_0_speed_10_20_20_ECM_with_write_05_no_following(s=0)

# mf.produce_movie(save_name='figure_4_parameter_set_21_80_80_ECM_with_chemotaxsis', trail_length=1, movie_options=movie_options_for_figure_4, image_options=options_for_figure4_movie)

# 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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@

from image_processing_for_physicell import *

options_for_figure4 = {}
options_for_figure5a = {}

options_for_figure4 = {"output_plot" : True,
options_for_figure5a = {"output_plot" : True,
"show_plot" : False,
"produce_for_panel" : True,
"plot_ECM_anisotropy" : True,
"plot_ECM_orientation" : False,
"plot_ECM_orientation" : True,
"retrieve_ECM_data": True,
"load_full_physicell_data" : True,
"plot_cells_from_SVG" : True,
"load_SVG_data": True,
'plot_cells_from_physicell_data': False,
"contour_options" : {'lowest_contour': 1e-14, ### I woud like this to be cleaner - but it does work!!!
'upper_contour': 1.0,
'number_of_levels': 25,
'number_of_levels': 2,
'color_map_name': 'Reds',
'color_bar': True
'color_bar': False
},
}

Expand All @@ -36,16 +36,18 @@

# image_list_for_figure2a = []

# image_list_for_figure2a = [90, 500, 1200]
image_list_for_figure5a = [60, 160]

# 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))
number_of_samples = 12
for number in image_list_for_figure5a:
starting_index = number-number_of_samples + 1
mf.generic_plotter(starting_index=starting_index, number_of_samples=number_of_samples, options=options_for_figure5a, file_name='Figure_5a' + str(number))

# starting_index: int = 0, sample_step_interval: int = 1, number_of_samples: int = 120,

mf.generic_plotter( number_of_samples = 481, file_name='parameter_set_21_80_80_ECM_with_chemotaxsis', options=options_for_figure4)
# mf.generic_plotter( number_of_samples = 481, file_name='parameter_set_21_80_80_ECM_with_chemotaxsis', options=options_for_figure4)

# 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)
Expand Down
Loading

0 comments on commit afd5ea0

Please sign in to comment.