Skip to content

Commit

Permalink
* remove nans and sort grid values
Browse files Browse the repository at this point in the history
* user relative size for grid points in simularium
  • Loading branch information
mogres committed Sep 12, 2023
1 parent c292f6f commit 91f4f17
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
27 changes: 24 additions & 3 deletions cellpack/autopack/upy/simularium/simularium_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,12 +332,32 @@ def concatObjectMatrix(self):

def GetAbsPosUntilRoot(self, obj):
return [0, 0.0, 0.0]

@staticmethod
def remove_nans(positions, values):
naninds = np.isnan(values)
values = values[~naninds]
positions = positions[~naninds]
return positions, values

def add_grid_data_to_scene(self, incoming_name, positions, values, radius=0.5):
colormap = matplotlib.cm.Reds(values)
@staticmethod
def sort_values(positions, values):
inds = np.argsort(values)
values = values[inds]
positions = positions[inds]
return positions, values

def add_grid_data_to_scene(self, incoming_name, positions, values, radius=0.5):

positions, values = self.remove_nans(positions, values)
if len(values) == 0:
print("no values to display")
return

positions, values = self.sort_values(positions, values)

colormap = matplotlib.cm.Reds(values)

for index, value in enumerate(values):
name = f"{incoming_name}#{value:.3f}"
self.display_data[name] = DisplayData(
Expand Down Expand Up @@ -455,6 +475,7 @@ def init_scene_with_objects(
grid_point_positions=None,
grid_point_compartment_ids=None,
show_sphere_trees=False,
grid_pt_radius=0.5,
):
self.time = 0
instance_number = 0
Expand Down Expand Up @@ -531,7 +552,7 @@ def init_scene_with_objects(
name,
None,
f"{name}-{index}",
0.5,
grid_pt_radius,
point_pos,
np.identity(4),
None,
Expand Down
6 changes: 5 additions & 1 deletion cellpack/autopack/writers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,11 @@ def save_as_simularium(self, env, all_ingr_as_array, compartments):
grid_positions = env.grid.masterGridPositions if env.show_grid_spheres else None
compartment_ids = env.grid.compartment_ids if env.show_grid_spheres else None
env.helper.init_scene_with_objects(
all_ingr_as_array, grid_positions, compartment_ids, env.show_sphere_trees
objects=all_ingr_as_array,
grid_point_positions=grid_positions,
grid_point_compartment_ids=compartment_ids,
show_sphere_trees=env.show_sphere_trees,
grid_pt_radius=env.grid.gridSpacing / 4,
)

if compartments is not None:
Expand Down

0 comments on commit 91f4f17

Please sign in to comment.