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

[MRG + 1] Create a new figure and test each plot type #127 #179

Merged
merged 9 commits into from Nov 2, 2018

Conversation

suyashb95
Copy link
Contributor

@suyashb95 suyashb95 commented Oct 27, 2018

  • move plot() to plotting.py as plot_pdf()
  • add filename param to plot_pdf()
  • modify plotting functions to return matplotlib figures
  • add test_plotting.py and baseline images
  • import plot_pdf() in __init__
  • update cli.py to use plot_pdf()
  • update advanced usage docs to reflect changes

 - move `plot()` to `plotting.py` as `plot_pdf()`
 - modify plotting functions to return matplotlib figures
 - add `test_plotting.py` and baseline images
 - import `plot_pdf()` in `__init__`
 - update `cli.py` to use `plot_pdf()`
 - update advanced usage docs to reflect changes
@suyashb95
Copy link
Contributor Author

@vinayak-mehta Any idea why changing the matplotlib backend doesn't help with the Python 2.7 build while the others pass?

@suyashb95 suyashb95 changed the title [MRG] Create a new figure and test each plot type #127 [WIP] Create a new figure and test each plot type #127 Oct 28, 2018
@suyashb95
Copy link
Contributor Author

Build logs

This call to matplotlib.use() has no effect because the backend has already
been chosen; matplotlib.use() must be called *before* pylab, matplotlib.pyplot,
or matplotlib.backends is imported for the first time.
The backend was *originally* set to 'TkAgg' by the following code:
  File "/home/travis/virtualenv/python2.7.14/bin/pytest", line 11, in <module>
    sys.exit(main())

Would moving matplotlib.use('Agg') to __init__ in the tests module help?

@vinayak-mehta
Copy link
Contributor

Would moving matplotlib.use('Agg') to init in the tests module help?

Sure, you could try that. But why do you need to specify the backend in the first place? Isn't Agg the default backend? Is this a pytest-mpl requirement?

@suyashb95
Copy link
Contributor Author

Would moving matplotlib.use('Agg') to init in the tests module help?

Sure, you could try that. But why do you need to specify the backend in the first place? Isn't Agg the default backend? Is this a pytest-mpl requirement?

I don't think Agg is the default backend for the python2.7 build. It fails on not finding a display. More on that here

 - use matplotlib rectangle instead of `cv2.rectangle` in
`plot_contour()`
 - set matplotlib backend in `tests/__init__`
 - update contour plot baseline image
 - update `test_plotting` with more checks
@codecov-io
Copy link

codecov-io commented Oct 28, 2018

Codecov Report

Merging #179 into master will increase coverage by 3.85%.
The diff coverage is 80%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #179      +/-   ##
==========================================
+ Coverage   84.12%   87.98%   +3.85%     
==========================================
  Files          13       13              
  Lines        1235     1248      +13     
  Branches      297      298       +1     
==========================================
+ Hits         1039     1098      +59     
+ Misses        151      101      -50     
- Partials       45       49       +4
Impacted Files Coverage Δ
camelot/core.py 91.6% <ø> (+4.09%) ⬆️
camelot/handlers.py 82.5% <ø> (ø) ⬆️
camelot/cli.py 92% <33.33%> (-1.75%) ⬇️
camelot/plotting.py 91.78% <87.17%> (+75.78%) ⬆️

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 79db6e3...655c4f9. Read the comment docs.

@suyashb95 suyashb95 changed the title [WIP] Create a new figure and test each plot type #127 [MRG] Create a new figure and test each plot type #127 Oct 29, 2018
for t in text:
xs.extend([t[0], t[2]])
ys.extend([t[1], t[3]])
assert ax.get_xlim() == (min(xs) - 10, max(xs) + 10)
Copy link
Contributor

Choose a reason for hiding this comment

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

@suyash458 Why do we need additional asserts here? Doesn't pytest compare the whole image which is a sure shot way of knowing whether the images are the same or not?

Copy link
Contributor Author

@suyashb95 suyashb95 Oct 31, 2018

Choose a reason for hiding this comment

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

In case image comparison tests are skipped if the --mpl option is not specified, these asserts would still work. Ultimately though, image comparison is a sure shot test.

Should the --mpl option be added to addopts in setup.cfg ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes and in the Makefile too. After that we shouldn't need to worry about additional asserts.

[cell.lb[1], cell.rb[1]])
plt.show()
return fig
Copy link
Contributor

Choose a reason for hiding this comment

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

@suyash458 Are you returning fig from the plot_* functions only for those additional asserts in the tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

pytest-mpl's image comparison decorator requires the plot functions to return a matplotlib figure

 - remove unnecessary asserts
 - update setup.cfg and makefile with `--mpl`
@vinayak-mehta
Copy link
Contributor

@suyash458 How did you generate the baseline images? Looks like there's an error of 10 units, so the tests are failing with the default tolerance of 2.

@suyashb95
Copy link
Contributor Author

suyashb95 commented Oct 31, 2018

@vinayak-mehta I'm not sure why the tests fail on Travis even though they pass locally. The baseline images were generated using the same matplotlib backend

I used the --mpl-generate-path=baseline option locally to generate them

@vinayak-mehta
Copy link
Contributor

I mean did you generate the plots using the CLI and then saved them from the matplotlib interface? or using the API. I'll try to run the tests locally too.

@suyashb95
Copy link
Contributor Author

I mean did you generate the plots using the CLI and then saved them from the matplotlib interface? or using the API. I'll try to run the tests locally too.

pytest --mpl-generate-path=baseline
This skipped the image comparison tests and generated the images in a folder called baseline

@vinayak-mehta
Copy link
Contributor

So I ran the tests locally and they failed. When I checked the diff images in /tmp I found that the large RMS error is coming from the axes not getting subtracted in the diff somehow. Check out this diff:
image

I think this difference could be the result of baseline images being generated on a system with some different font/backend/(some other setting) (you said you used 'Agg' though and that is being used on Travis too). I plan to look into what the exact difference is later by inspecting the dpi, dimensions etc. We could resolve this by doing one of the following:

  1. Adding a tolerance parameter, which I've pushed for the time being.
  2. Removing axes from plots. Does matplotlib give such an option?
  3. Generate the baseline images on Travis itself and copy them to the tests directory.

@vinayak-mehta
Copy link
Contributor

3 looks the best to me.

@suyashb95
Copy link
Contributor Author

Option 3 looks like the best bet. I think the large RMS error could be because of different system fonts being used. pytest-mpl has an option to exclude text from the comparison test so I'll try that

update plot tests with `remove_text`
@suyashb95
Copy link
Contributor Author

Looks like the tests passed after excluding text from the baseline images. The py3.7 build failed because of an AWS timeout

@vinayak-mehta
Copy link
Contributor

Restarted.

@suyashb95
Copy link
Contributor Author

Should we go ahead with this so the tests don't fail on Travis or locally owing to differences in freetype fonts?

@vinayak-mehta
Copy link
Contributor

remove_text looks good to me. I'll merge this today.

@vinayak-mehta vinayak-mehta changed the title [MRG] Create a new figure and test each plot type #127 [MRG + 1] Create a new figure and test each plot type #127 Nov 2, 2018
@vinayak-mehta vinayak-mehta merged commit c0e9235 into atlanhq:master Nov 2, 2018
@vinayak-mehta
Copy link
Contributor

@suyash458 Thanks for the contribution!

@suyashb95 suyashb95 deleted the fix-#127 branch November 2, 2018 15:50
@suyashb95 suyashb95 restored the fix-#127 branch November 2, 2018 16:45
@suyashb95 suyashb95 deleted the fix-#127 branch November 2, 2018 16:46
@suyashb95
Copy link
Contributor Author

@vinayak-mehta Glad I could help!

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.

None yet

3 participants