Skip to content

Conversation

@LizaShch
Copy link

Summary:

This pull request includes changes to src/spac/visualization.py file to creating a new heatmap function using the package datashader. There is an option to facet plots by annotation as well. A rest file tests/test_visualization/test_datashader.py was added as well to ensure proper functionality.

Changes:

  • imports required now are datashader.transfer_functions, datashader
  • Allows for the use of a ann-data object with optional anotations to see the densities of the points.
  • Added unit tests to ensure proper plots with legends and proper facet amounts.

Copy link
Contributor

@georgezakinih georgezakinih left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@LizaShch @ThomasSheeley , Thanks for the PR. I left few comments.


for i, cat in enumerate(categories):
subset = coords[coords["labels"] == cat]
canvas = ds.Canvas(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@LizaShch, consider combining this the code at line 133 using the "partial" construct in python. This way, when you edit it, it will be edited once.

# Fixed categorical labels to ensure representation of each category
fixed_labels = ['A', 'B', 'C', 'A', 'B', 'C', 'A', 'B', 'C', 'A']
self.labels_categorical = pd.Series(fixed_labels, dtype="category")
self.labels_continuous = pd.Series(np.random.rand(10))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@LizaShch , what do you do with teh continuous labels?

heatmap_datashader(self.x, self.y, labels=wrong_labels)
self.assertIn("Labels length should match x and y length", str(context_manager.exception))

def test_valid_input_returns_figure(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@LizaShch, would you please add a case with number of labels not multiple of 3?

# There should be as many subplots as unique labels (3 in this case)
num_axes = len(fig.axes)
expected_axes = self.labels_categorical.nunique()
self.assertEqual(num_axes, expected_axes)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@LizaShch, any other assertion you can add to make sure the plot got generated correctly besides the number of axes? For example, the content of the plot?


def heatmap_datashader(x, y, labels=None, theme=None,
x_axis_title="Component 1", y_axis_title="Component 2",
plot_title=None, **kwargs):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@LizaShch, can we use kwargs to pass optional arguments to ds.Canvas to control the figure? This way, you don't need to explicty control only for plot width and plot height, but for all other input argument that function would tak.

Copy link
Contributor

@ying39purdue ying39purdue left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@georgezakinih I added a few formatting additions and Liza's previous commit resolved the previous comments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants