Skip to content

Commit

Permalink
Convert filtering multiple data variables tip to section
Browse files Browse the repository at this point in the history
  • Loading branch information
lochhh committed Jul 17, 2024
1 parent 25ebc50 commit 26d9191
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 29 deletions.
6 changes: 5 additions & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"sphinx_design",
"sphinx_gallery.gen_gallery",
"sphinx_sitemap",
"sphinx.ext.autosectionlabel",
]

# Configure the myst parser to enable cool markdown features
Expand Down Expand Up @@ -76,6 +77,9 @@
autosummary_generate = True
autodoc_default_flags = ["members", "inherited-members"]

# Prefix section labels with the document name
autosectionlabel_prefix_document = True

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
Expand Down Expand Up @@ -104,7 +108,7 @@
"binderhub_url": "https://mybinder.org",
"dependencies": ["environment.yml"],
},
'remove_config_comments': True,
"remove_config_comments": True,
# do not render config params set as # sphinx_gallery_config [= value]
}

Expand Down
54 changes: 26 additions & 28 deletions examples/filter_and_interpolate.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,33 +173,31 @@
print(log_entry)

# %%
# .. tip::
# All :py:mod:`movement.filtering` functions are available via the
# ``move`` accessor. These ``move`` accessor methods operate on the
# ``position`` data variable in the dataset ``ds`` by default.
# There is also an additional argument ``data_vars`` that allows us to
# specify which data variables in ``ds`` to filter.
# When multiple data variable names are specified in ``data_vars``,
# the method will return a dictionary with the data variable names as keys
# and the filtered DataArrays as values, otherwise it will return a single
# DataArray that is the filtered data.
# This is useful when we want to apply the same filtering operation to
# multiple data variables in ``ds`` at the same time.
# .. _target-example-filtering-multiple-data-variables:
#
# .. dropdown:: Example
#
# To filter both ``position`` and ``velocity`` data variables
# in ``ds``, based on the confidence scores, we can specify
# ``data_vars=["position", "velocity"]`` in the method call.
# As the filtered data variables are returned as a dictionary, we can
# use :py:meth:`xarray.Dataset.update` to update ``ds`` in-place
# with the filtered data variables.
#
# .. code-block:: python
#
# ds["velocity"] = ds.move.compute_velocity()
# filtered_data_dict = ds.move.filter_by_confidence(
# data_vars=["position", "velocity"]
# )
# ds.update(filtered_data_dict)
# Filtering multiple data variables
# ---------------------------------
# All :py:mod:`movement.filtering` functions are available via the
# ``move`` accessor. These ``move`` accessor methods operate on the
# ``position`` data variable in the dataset ``ds`` by default.
# There is also an additional argument ``data_vars`` that allows us to
# specify which data variables in ``ds`` to filter.
# When multiple data variable names are specified in ``data_vars``,
# the method will return a dictionary with the data variable names as keys
# and the filtered DataArrays as values, otherwise it will return a single
# DataArray that is the filtered data.
# This is useful when we want to apply the same filtering operation to
# multiple data variables in ``ds`` at the same time.
#
# For instance, to filter both ``position`` and ``velocity`` data variables
# in ``ds``, based on the confidence scores, we can specify
# ``data_vars=["position", "velocity"]`` in the method call.
# As the filtered data variables are returned as a dictionary, we can
# use :py:meth:`xarray.Dataset.update` to update ``ds`` in-place
# with the filtered data variables.

ds["velocity"] = ds.move.compute_velocity()
filtered_data_dict = ds.move.filter_by_confidence(
data_vars=["position", "velocity"]
)
ds.update(filtered_data_dict)
6 changes: 6 additions & 0 deletions examples/smooth.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,3 +360,9 @@ def plot_raw_and_smooth_timeseries_and_psd(
# %%
# Feel free to play around with the parameters of the applied filters and to
# also look at other keypoints and time ranges.

# %%
# .. seealso::
# :ref:`examples/filter_and_interpolate:Filtering multiple data variables`
# in the
# :ref:`sphx_glr_examples_filter_and_interpolate.py` example.

0 comments on commit 26d9191

Please sign in to comment.