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

Log raises TypeError when matplotlib usetex=True #6407

Open
AarynnCarter opened this issue Oct 21, 2021 · 4 comments · May be fixed by #7616
Open

Log raises TypeError when matplotlib usetex=True #6407

AarynnCarter opened this issue Oct 21, 2021 · 4 comments · May be fixed by #7616

Comments

@AarynnCarter
Copy link

Hi, our team has been using jwst to produce a transiting exoplanet data reduction pipeline, and we've encountered an error (see below) when we set rc('text', usetex=True) for matplotlib plotting and jwst logging is used.

The error occurs because when this setting is enabled, the log is passed a bytes like object at some point. The solution we've identified is to add:

if type(msg)==bytes:
    msg = msg.decode()

immediately prior to Line 158 in the log_config.py file. I opted not to submit this as a pull request as I thought you'd want to look at things on your end first, hopefully that's okay! Let me know if you need any more information from us.

Generating x1dints figure
Traceback (most recent call last):
  File "/Users/acarter/Documents/TRANSITS/EUREKA/TESTING_TAYLOR/run_eureka.py", line 12, in <module>
    s2_meta = s2.run_eurekaS2(eventlabel)
  File "/Users/acarter/anaconda3/envs/eureka_tjb/lib/python3.9/site-packages/eureka/S2_calibrations/s2_calibrate.py", line 164, in run_eurekaS2
  File "/Users/acarter/anaconda3/envs/eureka_tjb/lib/python3.9/site-packages/matplotlib/pyplot.py", line 966, in savefig
    res = fig.savefig(*args, **kwargs)
  File "/Users/acarter/anaconda3/envs/eureka_tjb/lib/python3.9/site-packages/matplotlib/figure.py", line 3015, in savefig
    self.canvas.print_figure(fname, **kwargs)
  File "/Users/acarter/anaconda3/envs/eureka_tjb/lib/python3.9/site-packages/matplotlib/backend_bases.py", line 2230, in print_figure
    self.figure.draw(renderer)
  File "/Users/acarter/anaconda3/envs/eureka_tjb/lib/python3.9/site-packages/matplotlib/artist.py", line 74, in draw_wrapper
    result = draw(artist, renderer, *args, **kwargs)
  File "/Users/acarter/anaconda3/envs/eureka_tjb/lib/python3.9/site-packages/matplotlib/artist.py", line 51, in draw_wrapper
    return draw(artist, renderer, *args, **kwargs)
  File "/Users/acarter/anaconda3/envs/eureka_tjb/lib/python3.9/site-packages/matplotlib/figure.py", line 2790, in draw
    mimage._draw_list_compositing_images(
  File "/Users/acarter/anaconda3/envs/eureka_tjb/lib/python3.9/site-packages/matplotlib/image.py", line 132, in _draw_list_compositing_images
    a.draw(renderer)
  File "/Users/acarter/anaconda3/envs/eureka_tjb/lib/python3.9/site-packages/matplotlib/artist.py", line 51, in draw_wrapper
    return draw(artist, renderer, *args, **kwargs)
  File "/Users/acarter/anaconda3/envs/eureka_tjb/lib/python3.9/site-packages/matplotlib/_api/deprecation.py", line 431, in wrapper
    return func(*inner_args, **inner_kwargs)
  File "/Users/acarter/anaconda3/envs/eureka_tjb/lib/python3.9/site-packages/matplotlib/axes/_base.py", line 2881, in draw
    self._update_title_position(renderer)
  File "/Users/acarter/anaconda3/envs/eureka_tjb/lib/python3.9/site-packages/matplotlib/axes/_base.py", line 2822, in _update_title_position
    if title.get_window_extent(renderer).ymin < top:
  File "/Users/acarter/anaconda3/envs/eureka_tjb/lib/python3.9/site-packages/matplotlib/text.py", line 903, in get_window_extent
    bbox, info, descent = self._get_layout(self._renderer)
  File "/Users/acarter/anaconda3/envs/eureka_tjb/lib/python3.9/site-packages/matplotlib/text.py", line 306, in _get_layout
    _, lp_h, lp_d = renderer.get_text_width_height_descent(
  File "/Users/acarter/anaconda3/envs/eureka_tjb/lib/python3.9/site-packages/matplotlib/backends/backend_agg.py", line 229, in get_text_width_height_descent
    w, h, d = texmanager.get_text_width_height_descent(
  File "/Users/acarter/anaconda3/envs/eureka_tjb/lib/python3.9/site-packages/matplotlib/texmanager.py", line 399, in get_text_width_height_descent
    dvifile = self.make_dvi(tex, fontsize)
  File "/Users/acarter/anaconda3/envs/eureka_tjb/lib/python3.9/site-packages/matplotlib/texmanager.py", line 291, in make_dvi
    self._run_checked_subprocess(
  File "/Users/acarter/anaconda3/envs/eureka_tjb/lib/python3.9/site-packages/matplotlib/texmanager.py", line 268, in _run_checked_subprocess
    _log.debug(report)
  File "/Users/acarter/anaconda3/envs/eureka_tjb/lib/python3.9/site-packages/jwst/associations/lib/log_config.py", line 158, in log
    for line in msg.split('\n'):
TypeError: a bytes-like object is required, not 'str'
@hbushouse
Copy link
Collaborator

@nden Can we assign this to someone like @zacharyburnett @braingram or @WilliamJamieson ?

@zacharyburnett
Copy link
Collaborator

zacharyburnett commented Jun 23, 2023

In regards to kevin218/Eureka#42 (comment), I'm not intimately familiar with what changes associations makes to logging, but this change seems to be innocuous enough. I'll run a PR through the regression tests to see if it breaks anything

@zacharyburnett zacharyburnett linked a pull request Jun 23, 2023 that will close this issue
7 tasks
@WilliamJamieson
Copy link
Collaborator

I have no knowledge about the JWST logging at this time.

@braingram
Copy link
Collaborator

I attempted to replicate this by: installing latex, modifying matplotlib rc as mentioned, generating a plot and creating jwst.stpipe.Step, which triggers the line which required modification. However I am unable to produce the mentioned error.

@zacharyburnett suggested approach sounds good to me. Any help in generating a minimal reproducer would be appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants