Skip to content

Commit

Permalink
changed the plot calls of acoustic_file
Browse files Browse the repository at this point in the history
  • Loading branch information
cparcerisas committed Jun 22, 2023
1 parent 993ab79 commit a1c3385
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
24 changes: 14 additions & 10 deletions pypam/acoustic_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -1087,12 +1087,14 @@ def source_separation(self, window_time=1.0, n_sources=15, binsize=None, save_pa
ds = xarray.concat((ds, separation_ds), 'id')
return ds

def plot_psd(self, db=True, log=True, save_path=None, **kwargs):
def plot_spectrum_mean(self, scaling='density', db=True, log=True, save_path=None, **kwargs):
"""
Plot the power spectrogram density of all the file (units^2 / Hz) re 1 V 1 upa
Parameters
----------
scaling : str
'density' or 'spectrum'
db : boolean
If set to True the result will be given in db. Otherwise in upa^2/Hz
log : boolean
Expand All @@ -1101,27 +1103,29 @@ def plot_psd(self, db=True, log=True, save_path=None, **kwargs):
Where to save the images
**kwargs : any attribute valid on psd() function
"""
psd = self.psd(db=db, **kwargs)
plots.plot_spectrum(ds=psd, col_name='band_density', db=db, p_ref=self.p_ref, log=log,
save_path=save_path)
psd = self._spectrum(db=db, scaling=scaling, **kwargs)
plots.plot_spectrum_mean(ds=psd, col_name='band_' + scaling, db=db, p_ref=self.p_ref, log=log,
save_path=save_path)

def plot_power_spectrum(self, db=True, log=True, save_path=None, **kwargs):
def plot_spectrum_per_chunk(self, scaling='density', db=True, log=True, save_path=None, **kwargs):
"""
Plot the power spectrogram of all the file (units^2) re 1 V 1 upa
Plot the power spectrogram density of all the file (units^2 / Hz) re 1 V 1 upa
Parameters
----------
scaling : str
'density' or 'spectrum'
db : boolean
If set to True the result will be given in db. Otherwise in upa^2/Hz
log : boolean
If set to True the scale of the y axis is set to logarithmic
save_path : string or Path
Where to save the images
**kwargs : any attribute valid on power_spectrum() function
**kwargs : any attribute valid on psd() function
"""
power = self.power_spectrum(db=db, **kwargs)
plots.plot_spectrum(ds=power, col_name='band_spectrum', db=db, p_ref=self.p_ref,
log=log, save_path=save_path)
psd = self._spectrum(db=db, scaling=scaling, **kwargs)
plots.plot_spectrum_per_chunk(ds=psd, col_name='band_' + scaling, db=db, p_ref=self.p_ref, log=log,
save_path=save_path)

def plot_spectrogram(self, db=True, log=True, save_path=None, **kwargs):
"""
Expand Down
3 changes: 2 additions & 1 deletion tests/test_acoustic_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ def setUp(self) -> None:

@skip_unless_with_plots()
def test_plots(self):
self.acu_file.plot_power_spectrum()
self.acu_file.plot_spectrum_per_chunk(scaling='density', db=True)
self.acu_file.plot_spectrum_mean(scaling='spectrum', db=True)

def test_millidecade_bands(self):
nfft = 8000
Expand Down

0 comments on commit a1c3385

Please sign in to comment.