mboquien / cigale

10 stars 0 forks source link

Errors when saving SED figures #97

Open B1GeasY opened 3 months ago

B1GeasY commented 3 months ago

Hi,

I'm using pcigale-plots sed to plot SEDs. But it returns the error :

ValueError: arrays must be of dtype byte, short, float32 or float64

My Cigale version is 2022.1. Numpy is in 1.26.4. Matplotlib is in 3.9.0. Python is in 3.11

I paste the whole traceback below:

"""
Traceback (most recent call last):
  File "/opt/anaconda3/envs/sedfit/lib/python3.11/multiprocessing/pool.py", line 125, in worker
    result = (True, func(*args, **kwds))
                    ^^^^^^^^^^^^^^^^^^^
  File "/opt/anaconda3/envs/sedfit/lib/python3.11/multiprocessing/pool.py", line 51, in starmapstar
    return list(itertools.starmap(args[0], args[1]))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/kl/cigale/pcigale_plots/plot_types/sed/__init__.py", line 529, in worker
    figure.savefig(
  File "/opt/anaconda3/envs/sedfit/lib/python3.11/site-packages/matplotlib/figure.py", line 3388, in savefig
    self.canvas.print_figure(fname, **kwargs)
  File "/opt/anaconda3/envs/sedfit/lib/python3.11/site-packages/matplotlib/backend_bases.py", line 2218, in print_figure
    result = print_method(
             ^^^^^^^^^^^^^
  File "/opt/anaconda3/envs/sedfit/lib/python3.11/site-packages/matplotlib/backend_bases.py", line 2068, in <lambda>
    print_method = functools.wraps(meth)(lambda *args, **kwargs: meth(
                                                                 ^^^^^
  File "/opt/anaconda3/envs/sedfit/lib/python3.11/site-packages/matplotlib/backends/backend_pdf.py", line 2799, in print_pdf
    self.figure.draw(renderer)
  File "/opt/anaconda3/envs/sedfit/lib/python3.11/site-packages/matplotlib/artist.py", line 95, in draw_wrapper
    result = draw(artist, renderer, *args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/anaconda3/envs/sedfit/lib/python3.11/site-packages/matplotlib/artist.py", line 72, in draw_wrapper
    return draw(artist, renderer)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/anaconda3/envs/sedfit/lib/python3.11/site-packages/matplotlib/figure.py", line 3155, in draw
    mimage._draw_list_compositing_images(
  File "/opt/anaconda3/envs/sedfit/lib/python3.11/site-packages/matplotlib/image.py", line 156, in _draw_list_compositing_images
    flush_images()
  File "/opt/anaconda3/envs/sedfit/lib/python3.11/site-packages/matplotlib/image.py", line 140, in flush_images
    image_group[0].draw(renderer)
  File "/opt/anaconda3/envs/sedfit/lib/python3.11/site-packages/matplotlib/artist.py", line 72, in draw_wrapper
    return draw(artist, renderer)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/anaconda3/envs/sedfit/lib/python3.11/site-packages/matplotlib/image.py", line 653, in draw
    im, l, b, trans = self.make_image(
                      ^^^^^^^^^^^^^^^^
  File "/opt/anaconda3/envs/sedfit/lib/python3.11/site-packages/matplotlib/image.py", line 1397, in make_image
    return self._make_image(
           ^^^^^^^^^^^^^^^^^
  File "/opt/anaconda3/envs/sedfit/lib/python3.11/site-packages/matplotlib/image.py", line 565, in _make_image
    output_alpha = _resample(  # resample alpha channel
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/anaconda3/envs/sedfit/lib/python3.11/site-packages/matplotlib/image.py", line 208, in _resample
    _image.resample(data, out, transform,
ValueError: arrays must be of dtype byte, short, float32 or float64
"""
The above exception was the direct cause of the following exception:

╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮
│ /opt/anaconda3/envs/sedfit/bin/pcigale-plots:33 in <module>                                      │
│                                                                                                  │
│   30                                                                                             │
│   31 if __name__ == '__main__':                                                                  │
│   32 │   sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])                       │
│ ❱ 33 │   sys.exit(load_entry_point('pcigale', 'console_scripts', 'pcigale-plots')())             │
│   34                                                                                             │
│                                                                                                  │
│ /Users/kl/cigale/pcigale_plots/__init__.py:125 in main                                           │
│                                                                                                  │
│   122 │   │   │   │   │   │   │     if series not in args.series]                                │
│   123 │   │   │   │   else:                                                                      │
│   124 │   │   │   │   │   series = args.series                                                   │
│ ❱ 125 │   │   │   sed_action(config, args.type, args.nologo, args.xrange, args.yrange,           │
│   126 │   │   │   │   │      series, args.format, outdir)                                        │
│   127 │   │   elif args.parser == 'mock':                                                        │
│   128 │   │   │   mock_action(config, args.nologo, outdir)                                       │
│                                                                                                  │
│ /Users/kl/cigale/pcigale_plots/plot_types/sed/__init__.py:74 in __init__                         │
│                                                                                                  │
│    71 │   │   │   repeat(format),                                                                │
│    72 │   │   │   repeat(outdir),                                                                │
│    73 │   │   )                                                                                  │
│ ❱  74 │   │   self._parallel_job(items, counter)                                                 │
│    75 │   │                                                                                      │
│    76 │   │   # Print the final value as it may not otherwise be printed                         │
│    77 │   │   counter.global_counter.value = len(obs)                                            │
│                                                                                                  │
│ /Users/kl/cigale/pcigale_plots/plot_types/__init__.py:33 in _parallel_job                        │
│                                                                                                  │
│   30 │   │   │   │   initializer=self.initializer,                                               │
│   31 │   │   │   │   initargs=(counter,),                                                        │
│   32 │   │   │   ) as pool:                                                                      │
│ ❱ 33 │   │   │   │   pool.starmap(self.worker, items, 1)                                         │
│   34 │   │   │                                                                                   │
│   35 │   │   │   # After the parallel processes have exited, it can be restored                  │
│   36 │   │   │   counter.progress = progress                                                     │
│                                                                                                  │
│ /opt/anaconda3/envs/sedfit/lib/python3.11/multiprocessing/pool.py:375 in starmap                 │
│                                                                                                  │
│   372 │   │   be iterables as well and will be unpacked as arguments. Hence                      │
│   373 │   │   `func` and (a, b) becomes func(a, b).                                              │
│   374 │   │   '''                                                                                │
│ ❱ 375 │   │   return self._map_async(func, iterable, starmapstar, chunksize).get()               │
│   376 │                                                                                          │
│   377 │   def starmap_async(self, func, iterable, chunksize=None, callback=None,                 │
│   378 │   │   │   error_callback=None):                                                          │
│                                                                                                  │
│ /opt/anaconda3/envs/sedfit/lib/python3.11/multiprocessing/pool.py:774 in get                     │
│                                                                                                  │
│   771 │   │   if self._success:                                                                  │
│   772 │   │   │   return self._value                                                             │
│   773 │   │   else:                                                                              │
│ ❱ 774 │   │   │   raise self._value                                                              │
│   775 │                                                                                          │
│   776 │   def _set(self, i, obj):                                                                │
│   777 │   │   self._success, self._value = obj                                                   │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
ValueError: arrays must be of dtype byte, short, float32 or float64

Does anyone know how to fix this error?

Thanks in advance!

B1GeasY commented 3 months ago

I downgrade the matplotlib to 3.8 and the error disappears. So it's perhaps a confliction with a new version of matplotlib.

mboquien commented 3 months ago

Thanks for the report. This is curious. It seems pretty deep inside matplotlib. I will have a look into it when I get the chance to test matplotlib 3.9.