8000 Set mica.report.report.main matplotlib backend to Agg by jeanconn · Pull Request #317 · sot/mica · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Set mica.report.report.main matplotlib backend to Agg #317

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

Merged
merged 3 commits into from
Jan 14, 2025

Conversation

jeanconn
Copy link
Contributor
@jeanconn jeanconn commented Jan 7, 2025

Description

Set the matplotlib backend to Agg in mica.report.report.main()

This is meant to be run non-interactively. It is generally called from scripts/update_reports.py which explicitly sets the backend to Agg, but if one needs to manually run reports, it would be a defect for it to not have the non-interactive backend set. It also looks like for 2025.x that the test to write reports would fail trying to run with the interactive backend in a headless test env.

FAILED mica/report/tests/test_write_report.py::test_write_reports - ImportError: Cannot load backend 'TkAgg' which requires the 'tk' interactive framework, as 'headless' is currently running

I could have fixed the test by just setting the backend for the test, but it seemed a bug in general for the code to try to use the interactive backend in general to make mica html reports.

Interface impacts

I think this would leave the backend set as Agg for downstream code if mica.report.report.main was run before other codes as I made no attempt to put this in a closure and retain the original backend state after reports are made. Given how the reporting is used, this seems non-impacting, but could be reevaluated if it becomes an issue.

Testing

Tested in 2025.0rc5

Unit tests

  • Linux
jeanconn-fido> conda list ska3
# packages in environment at /fido.real/miniforge3/envs/ska3-flight-2025.0rc2:
#
# Name                    Version                   Build  Channel
ska3-core                 2025.0rc5                     0    https://icxc.cfa.harvard.edu/aspect/ska3-conda/twelve
ska3-flight               2025.0rc5                     0    https://icxc.cfa.harvard.edu/aspect/ska3-conda/twelve
ska3-perl                 2025.0rc5                     0    https://icxc.cfa.harvard.edu/aspect/ska3-conda/twelve
ska3-template             2022.06.02                    0    https://icxc.cfa.harvard.edu/aspect/ska3-conda/twelve
jeanconn-fido> git rev-parse HEAD
2567e454118f6490509eec179d98ef662155586f
jeanconn-fido> pytest
================================================================ test session starts =================================================================
platform linux -- Python 3.12.8, pytest-8.3.4, pluggy-1.5.0
rootdir: /proj/sot/ska/jeanproj/git
configfile: pytest.ini
plugins: timeout-2.3.1, anyio-4.7.0
collected 112 items                                                                                                                                  

mica/archive/tests/test_aca_dark_cal.py ..................                                                                                     [ 16%]
mica/archive/tests/test_aca_hdr3.py .                                                                                                          [ 16%]
mica/archive/tests/test_aca_l0.py .....                                                                                                        [ 21%]
mica/archive/tests/test_asp_l1.py .......                                                                                                      [ 27%]
mica/archive/tests/test_cda.py ..............................................                                                                  [ 68%]
mica/archive/tests/test_obspar.py .                                                                                                            [ 69%]
mica/report/tests/test_report.py ..                                                                                                            [ 71%]
mica/report/tests/test_write_report.py .                                                                                                       [ 72%]
mica/starcheck/tests/test_catalog_fetches.py ...............                                                                                   [ 85%]
mica/stats/tests/test_acq_stats.py ...                                                                                                         [ 88%]
mica/stats/tests/test_guide_stats.py ....                                                                                                      [ 91%]
mica/vv/tests/test_vv.py .........                                                                                                             [100%]

================================================================== warnings summary ==================================================================
mica/mica/archive/tests/test_asp_l1.py::test_update_l1_archive
  /fido.real/miniforge3/envs/ska3-flight-2025.0rc2/lib/python3.12/pty.py:95: DeprecationWarning: This process (pid=1221525) is multi-threaded, use of forkpty() may lead to deadlocks in the child.
    pid, fd = os.forkpty()

mica/mica/archive/tests/test_cda.py::test_get_proposal_abstract
mica/mica/archive/tests/test_cda.py::test_get_proposal_abstract
mica/mica/report/tests/test_write_report.py::test_write_reports
mica/mica/report/tests/test_write_report.py::test_write_reports
  /fido.real/miniforge3/envs/ska3-flight-2025.0rc2/lib/python3.12/site-packages/bs4/builder/_lxml.py:124: DeprecationWarning: The 'strip_cdata' option of HTMLParser() has never done anything and will eventually be removed.
    parser = parser(

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
==================================================== 112 passed, 5 warnings in 548.96s (0:09:08)

Independent check of unit tests by [REVIEWER NAME]

  • [PLATFORM]:

Functional tests

No functional testing.

@jeanconn jeanconn requested a review from javierggt January 7, 2025 15:20
@javierggt
Copy link
Contributor

acq_stat_reports is setup so, if you run the functions manually, you see the plots right away. If I run manually, I expect to see the plots, not to have a report saved. If I want the report saved, I run the script.

Just saying that it is not necessarily a "defect".

@jeanconn
Copy link
Contributor Author
jeanconn commented Jan 7, 2025

I agree with you in general, but mica.report basically has a specific job of making html reports from the plots from mica.vv and some other database lookups and links to other plots. Along the way I think it makes one, low-value, non-original, plot that is a remake of the starcheck field plot. So the mica.report code doesn't really make any plots that are useful in an interactive way.

The mica.vv plots are handy in an interactive way, and I suggest no changes there.

@jeanconn
Copy link
Contributor Author

Are you passionate about this fix not going forward Javier? Otherwise the test fails for me - I could reduce the scope to just the test.

@taldcroft
Copy link
Member

This seems fairly non-controversial to me...

@jeanconn jeanconn merged commit 5e8dc51 into master Jan 14, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
4522
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0