-
Notifications
You must be signed in to change notification settings - Fork 44
Replace use of properties with features #425
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 8 commits
1f5af0a
c356579
86f4546
caa7b14
831a788
596d9ca
e0b6cde
b8ce1df
165c302
fd6df62
00ec366
0bfa45d
426fde3
98032bb
9eed8ec
7326789
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,8 +31,8 @@ code there to add a tracks layer first, then explore the GUI controls. | |
The `tracks` layer allows you to display trajectories in `nD+t` while | ||
visualizing the recent history of the track via a fading tail. | ||
|
||
Each track can have annotations associated with it using the `Tracks.properties` | ||
dictionary. These properties can be used to set the colors of the tracks. | ||
Each track can have annotations associated with it using the `Tracks.features` | ||
table. These features can be used to set the colors of the tracks. | ||
|
||
For example, when displaying tracks of different classes/types, one could | ||
automatically set the color of the individual tracks by their respective | ||
|
@@ -41,8 +41,9 @@ class/type. | |
## A simple example | ||
|
||
You can create a new viewer and add a set of tracks in one go using the | ||
`napari.view_tracks` method, or if you already have an existing viewer, you can | ||
add tracks to it using `viewer.add_tracks`. The API of both methods is the same. | ||
:func:`napari.view_tracks` method, or if you already have an existing viewer, you can | ||
add tracks to it using :func:`viewer.add_tracks<napari.components.ViewerModel.add_tracks>`. | ||
The API of both methods is the same. | ||
|
||
In this example, we will overlay some tracks on an image from the Hubble space | ||
telescope: | ||
|
@@ -121,66 +122,6 @@ napari.run() | |
* Graph - check this box to display a previously created graph as explained in | ||
[](#arguments-of-view_tracks-and-add_tracks). | ||
|
||
## Arguments of `view_tracks` and `add_tracks` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These docs are incomplete and stale for multiple reasons (including properties/features), so I removed this in favor of link to the two functions in the text above. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. lmao I came here while trying to resolve merge conflicts with #420 going, "why on earth did this get removed. And no discussion either, wth!" ... Then I found my thumbs-up above 🤣 |
||
|
||
Both `view_tracks` and `add_tracks` have the following docstrings: | ||
|
||
```python | ||
""" | ||
Parameters | ||
---------- | ||
data : array (N, D+1) | ||
Coordinates for N points in D+1 dimensions. ID,T,(Z),Y,X. The first | ||
axis is the integer ID of the track. D is either 3 or 4 for planar | ||
or volumetric timeseries respectively. | ||
properties : dict {str: array (N,)}, DataFrame | ||
Properties for each point. Each property should be an array of length N, | ||
where N is the number of points. | ||
graph : dict {int: list} | ||
Graph representing associations between tracks. Dictionary defines the | ||
mapping between a track ID and the parents of the track. This can be | ||
one (the track has one parent, and the parent has >=1 child) in the | ||
case of track splitting, or more than one (the track has multiple | ||
parents, but only one child) in the case of track merging. | ||
See examples/tracks_3d_with_graph.py | ||
color_by: str | ||
Track property (from property keys) by which to color vertices. | ||
tail_width : float | ||
Width of the track tails in pixels. | ||
tail_length : float | ||
Length of the track tails in units of time. | ||
colormap : str | ||
Default colormap to use to set vertex colors. Specialized colormaps, | ||
relating to specified properties can be passed to the layer via | ||
colormaps_dict. | ||
colormaps_dict : dict {str: napari.utils.Colormap} | ||
Optional dictionary mapping each property to a colormap for that | ||
property. This allows each property to be assigned a specific colormap, | ||
rather than having a global colormap for everything. | ||
name : str | ||
Name of the layer. | ||
metadata : dict | ||
Layer metadata. | ||
scale : tuple of float | ||
Scale factors for the layer. | ||
translate : tuple of float | ||
Translation values for the layer. | ||
opacity : float | ||
Opacity of the layer visual, between 0.0 and 1.0. | ||
blending : str | ||
One of a list of preset blending modes that determines how RGB and | ||
alpha values of the layer visual get mixed. Allowed values are | ||
{'opaque', 'translucent', and 'additive'}. | ||
visible : bool | ||
Whether the layer visual is currently being displayed. | ||
|
||
Returns | ||
------- | ||
layer : napari.layers.Tracks | ||
The newly-created tracks layer. | ||
""" | ||
``` | ||
|
||
## Tracks data | ||
|
||
The input data to the tracks layer must be an `NxD+1` NumPy array or list | ||
|
@@ -250,13 +191,13 @@ graph = { | |
For a full example of 3d+t tracks data with a parent graph, please see | ||
[](../../gallery/tracks_3d_with_graph). | ||
|
||
## Using the `tracks` properties dictionary | ||
## Using the `tracks` features table | ||
|
||
The `tracks` layer can contain properties that annotate the vertices of each | ||
track. `Tracks.properties` stores the properties in a dictionary where each key | ||
is the name of the property and the values are NumPy arrays with a value for | ||
The `Tracks` layer can contain features that annotate the vertices of each | ||
track. `Tracks.features` stores the features in a table where each column | ||
is the name of the feature and the values are rows with a value for | ||
each vertex in the track (i.e., length `N` for `N` vertices in `Tracks.data`). | ||
As we will see below, we can use the values in a property to set the display | ||
As we will see below, we can use the feature values to set the display | ||
properties of the tracks (e.g., the track color). | ||
|
||
## 3D rendering | ||
|
@@ -335,14 +276,14 @@ length" slider in the `tracks` layer controls. | |
</figure> | ||
``` | ||
|
||
## Setting the track color with properties | ||
## Setting the track color with features | ||
|
||
We can color the tracks by mapping colors to the track properties defined in | ||
`Tracks.properties`. If we define properties and pass them via the `properties` | ||
We can color the tracks by mapping colors to the track features defined in | ||
`Tracks.features`. If we define features and pass them via the `features` | ||
keyword argument in the `viewer.add_tracks()` and `napari.view_tracks()` | ||
methods, we can then select the property we would like to color the tracks by in | ||
methods, we can then select the feature we would like to color the tracks by in | ||
the "color by" dropdown menu in the `tracks` layer controls. We can additionally | ||
specify the colormap used to map the property value to color via the "colormap" | ||
specify the colormap used to map the feature value to color via the "colormap" | ||
dropdown menu. | ||
|
||
```python | ||
|
@@ -370,13 +311,13 @@ tracks_data = np.asarray([ | |
[3, 4, 636, 1000] | ||
]) | ||
track_confidence = np.array(5*[0.9] + 5*[0.3] + 5 * [0.1]) | ||
properties = { | ||
features = { | ||
'time': tracks_data[:, 1], | ||
'confidence': track_confidence | ||
} | ||
|
||
viewer = napari.view_image(hubble_image) | ||
viewer.add_tracks(tracks_data, properties=properties) | ||
viewer.add_tracks(tracks_data, features=features) | ||
napari.run() | ||
``` | ||
|
||
|
@@ -387,7 +328,7 @@ napari.run() | |
<source src="../../_static/images/tracks_color_by.mp4" type="video/mp4" /> | ||
<img src="../../_static/images/tracks_color_by.png" | ||
title="Your browser does not support the video tag" | ||
alt="Selecting tracks by the time property and changing the color." | ||
alt="Selecting tracks by the time feature and changing the color." | ||
> | ||
</video> | ||
</figure> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe a bit confusing for folks unfamiliar with pandas to talk about columns/rows in a dictionary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, indeed, maybe worth saying that this is converted internally to a data frame with two columns and three rows? (I wouldn't specify pandas necessarily, but maybe.)
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed this paragraph is mixing things a bit too much. Let me try to fix that.
But I also want to make a distinction between the meaning of
features
(i.e. it's a table) and the type used to provide or implement it (i.e. adict
orDataFrame
). Ideally, we could do that in one place for all layers (see #23).For now, there's a little effort above to describe what the table is in the "### Using the points features table" section. I'll clean that up a little and will mention that the table can be provided as a dictionary where the values are array-likes of the same length.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also (tried to) put a link back to the section that describes the dictionary and table/dataframe relationship in both of these similar paragraphs.