Skip to content
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

✨ Add plot_fitted_traces function #39

Merged
merged 18 commits into from
Oct 22, 2021
Merged

Conversation

s-weigand
Copy link
Member

@s-weigand s-weigand commented Oct 21, 2021

This adds a new plotting overview function to show data and fitted traces, for multiple wavelengths across datasets.

The wavelengths need to be calculated/selected separately so the user has more control over what to plot, which is especially important for wavelength axes that aren't equidistant.

Example

The below plot was created from the simultaneous_analysis_6d_disp by adding the following lines of code

from pyglotaran_extras.plotting.plot_traces import plot_fitted_traces
from pyglotaran_extras.plotting.plot_traces import select_plot_wavelengths

wavelengths = select_plot_wavelengths(result)
plot_fitted_traces(result, wavelengths, linlog=True)

sim_disp_d6

Change summary

  • ✨ Added 'plot_fit_overview' function to plot data and fit per wavelength
  • ✨ Added 'wavelength_range' parameter so the user can select data to plot
  • 🧹 Restricted DatasetConvertible objects to always be xr.Dataset
  • ♻️ Factored out extraction of irf location to a separate function
  • 👌 Plotted fits and data are now shifted by the irf location
  • 🧹 Unified xarray typing style
  • 👌♻️ Added 'dataset_name' argument, use 'load_dataset' to load result
  • ♻️ Refactored load_data and result_dataset_mapping to work with DataArray
  • ♻️✨ Made 'plot_fit_overview' work properly with unevenly spaced wavelengths
  • ♻️ Moved 'plot_fit_overview' helper functions to plotting.utils
  • ✨ Added figsize argument to plot_data_overview
  • 👌 Reexport 'select_plot_wavelengths' from plotting.data for convenience

After review

  • 👌 Made function name in 'select_plot_wavelengths' warning dynamic
  • 📚 Added comments and docstrings to plot style code
  • 👌 Made the ylabel of plots an argument and default to 'a.u.'
  • ♻️ Addressed requested renaming and moving functions suited for this PR

Checklist

  • ✔️ Passing the tests (mandatory for all PR's)
  • 👌 Closes issue (mandatory for ✨ feature and 🩹 bug fix PR's)

Closes issues

closes #35

✨ Also added some convenience functions for data pre proceessing
…rray

👌 result_dataset_mapping and thus also plot_data_and_fits and plot_fit_overview, no work with single file paths
…egths

♻️ This required to remove the argument 'wavelength_range' and instead pass the wavelengths directly to 'plot_fit_overview' which gives the user more control.
For convenience the function 'select_plot_wavelengths' was added, which provies the functionality of 'wavelength_range'
'maximum_coordinate_range' and 'add_unique_figure_legend'
@s-weigand s-weigand requested a review from a team as a code owner October 21, 2021 21:05
@github-actions
Copy link
Contributor

Binder 👈 Launch a binder notebook on branch s-weigand/pyglotaran-extras/data+fit-plots

@codecov
Copy link

codecov bot commented Oct 21, 2021

Codecov Report

Merging #39 (d4f3183) into main (898afd7) will decrease coverage by 1.93%.
The diff coverage is 0.00%.

Impacted file tree graph

@@           Coverage Diff            @@
##            main     #39      +/-   ##
========================================
- Coverage   6.19%   4.26%   -1.94%     
========================================
  Files         13      17       +4     
  Lines        355     516     +161     
  Branches      41      70      +29     
========================================
  Hits          22      22              
- Misses       333     494     +161     
Impacted Files Coverage Δ
pyglotaran_extras/io/load_data.py 0.00% <0.00%> (ø)
pyglotaran_extras/io/utils.py 0.00% <0.00%> (ø)
pyglotaran_extras/plotting/data.py 0.00% <0.00%> (ø)
pyglotaran_extras/plotting/plot_concentrations.py 0.00% <0.00%> (ø)
pyglotaran_extras/plotting/plot_overview.py 0.00% <0.00%> (ø)
pyglotaran_extras/plotting/plot_traces.py 0.00% <0.00%> (ø)
pyglotaran_extras/plotting/style.py 0.00% <0.00%> (ø)
pyglotaran_extras/plotting/utils.py 0.00% <0.00%> (ø)
pyglotaran_extras/types.py 0.00% <0.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 898afd7...d4f3183. Read the comment docs.

This needs a feature added in pyglotaran 0.5.0, for older results it will show a warning.
Copy link
Member

@jsnel jsnel left a comment

Choose a reason for hiding this comment

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

Reviewed ok with some minor comments.

@jsnel jsnel self-requested a review October 22, 2021 20:41
Copy link
Member

@jsnel jsnel left a comment

Choose a reason for hiding this comment

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

Request to rename / move some functions/modules.

  1. Move plot_data_and_fits and plot_fit_overview out of data.py (where see 4, 5, 6)
  2. Rename data.py to plot_data.py (different PR)
  3. Move get_shifted_traces out of plot_traces.py to util.py, remove dummy calculate_x_ranges
  4. Rename plot_traces to plot_concentrations (to indicate we mean something different than the data + fitted traces.
  5. Move function in 1. to (now empty) plot_traces module.
  6. Rename plot_fit_overview to plot_fitted_traces (which plots both data + fitted traces), which allows for a future plot function which can plot only data traces (so without fits) called plot_data_traces. Omit the word overview which we reserve for the complete summary picture or mega pdf ^^.

@s-weigand
Copy link
Member Author

I addressed the renaming and moving functions in 7ec2491 and ran the examples locally to verify that they still work.

The PR should be ready for the final review now 🤞

@s-weigand s-weigand changed the title ✨ Add plot_fit_overview function ✨ Add plot_fitted_traces function Oct 22, 2021
Copy link
Member

@jsnel jsnel left a comment

Choose a reason for hiding this comment

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

Minor changes requested.

pyglotaran_extras/plotting/utils.py Outdated Show resolved Hide resolved
Copy link
Member

@jsnel jsnel left a comment

Choose a reason for hiding this comment

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

✨ LGTM 🎉

@jsnel
Copy link
Member

jsnel commented Oct 22, 2021

All tests are successful, the codecov/patch bots failing we are aware of - the coverage are currently provided by the examples of pyglotaran-examples running with this code.

@jsnel jsnel merged commit 640d56b into glotaran:main Oct 22, 2021
@s-weigand s-weigand deleted the data+fit-plots branch October 24, 2021 11:20
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.

✨ Add PlotStyle for data + fit plots
2 participants