diff --git a/cellpack/autopack/upy/simularium/simularium_helper.py b/cellpack/autopack/upy/simularium/simularium_helper.py index 052fa57e8..4e46416ae 100644 --- a/cellpack/autopack/upy/simularium/simularium_helper.py +++ b/cellpack/autopack/upy/simularium/simularium_helper.py @@ -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( @@ -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 @@ -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, diff --git a/cellpack/autopack/writers/__init__.py b/cellpack/autopack/writers/__init__.py index 69e610d44..68494e9c7 100644 --- a/cellpack/autopack/writers/__init__.py +++ b/cellpack/autopack/writers/__init__.py @@ -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: