Project-OSmOSE / OSEkit

OSEkit is an open source suite of tools written in python and dedicated to the management and analysis of data in underwater passive acoustics.
https://osmose.ifremer.fr
Other
3 stars 0 forks source link

Can't generate spectros - Matplotlib version conflict #156

Closed PaulCarvaillo closed 3 weeks ago

PaulCarvaillo commented 2 months ago

Context:

Using OSmOSE installed from .whl file version 0.2.0.

Build and initialize methods worked fine on my dataset.

After calling .process_all_files() method I get this error:

`--------------------------------------------------------------------------- AttributeError Traceback (most recent call last) Cell In[6], line 3 1 print(spectrogram) 2 print(spectrogram.check_spectro_size()) ----> 3 previz_spectrogram(spectrogram=spectrogram,number_of_previz=5)

Cell In[1], line 41 39 # Process the reshaped file 40 for audio_file in random.sample(files_adjust,number_of_previz): ---> 41 spectrogram.process_file(audio_file, adjust=True) 43 # Save the spectrogram metadata 44 spectrogram.save_spectro_metadata(True)

File /mnt/Data/Tools/anaconda3/envs/mmermaid-env/lib/python3.10/site-packages/OSmOSE/Spectrogram.py:1200, in Spectrogram.process_file(self, audio_file, adjust, save_matrix, save_for_LTAS, overwrite, clean_adjust_folder) 1197 data = signal.sosfilt(bpcoef, data) 1199 print(f"Generating spectrograms for {output_file.name}") -> 1200 self.gen_tiles(data=data, sample_rate=sample_rate, output_file=output_file, adjust=adjust)

File /mnt/Data/Tools/anaconda3/envs/mmermaid-env/lib/python3.10/site-packages/OSmOSE/Spectrogram.py:1303, in Spectrogram.gen_tiles(self, data, sample_rate, output_file, adjust) 1300 if self.spectro_normalization == "spectrum": 1301 log_spectro = 10 * np.log10(Sxx_int) -> 1303 self.generate_and_save_figures( 1304 time=segment_times_int, 1305 freq=Freq, 1306 log_spectro=log_spectro, 1307 output_file=output_file.parent.joinpath( 1308 f"{outputfile.stem}{str(2 ** zoomlevel)}{str(tile)}.png" 1309 ), 1310 adjust=adjust 1311 ) 1314 # highest tuile resolution 1315 if False:

File /mnt/Data/Tools/anaconda3/envs/mmermaid-env/lib/python3.10/site-packages/OSmOSE/Spectrogram.py:1457, in Spectrogram.generate_and_save_figures(self, time, freq, log_spectro, output_file, adjust) 1448 fig, ax = plt.subplots( 1449 nrows=1, 1450 ncols=1, 1451 figsize=(fact_x 1800 / my_dpi, fact_y 512 / my_dpi), 1452 dpi=my_dpi, 1453 ) 1455 print(f"- min log spectro : {np.amin(log_spectro)} \n - max log spectro : {np.amax(log_spectro)} \n") -> 1457 color_map = cm.get_cmap(self.colormap) # .reversed() 1458 plt.pcolormesh(time, freq, log_spectro, cmap=color_map) 1459 plt.clim(vmin=self.dynamic_min, vmax=self.dynamic_max)

AttributeError: module 'matplotlib.cm' has no attribute 'get_cmap'`

This comes from matplotlib version ==> pip install --force-reinstall matplotlib==3.7.0 fixed the problem.

They changed colormap attributes.

Version 3.7.0 -the one osekit is currently using-: https://matplotlib.org/3.7.0/api/_as_gen/matplotlib.pyplot.get_cmap.html

Current version 3.9.0 (stable): https://matplotlib.org/stable/api/cm_api.html

I think the

from matplotlib import pyplot as plt
...
plt.cm.get_cmap('viridis')`

is deprecated.

and we should use:

`import matplotlib.pyplot as plt
import matplotlib.colormaps as cm

cm.get_cmap('Viridis')`

in pyproject.toml I see this: matplotlib = "^3.7.0"

With this description, it installed 3.9.0 by default in our environment.

Can we update code to work with matplotlib 3.9.0 ? otherwise we can freeze the version with matplotlib==3.7.0.in pyproject.toml