Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
# Conflicts:
#	soundscapy/utils/_sspy_accessor.py
  • Loading branch information
MitchellAcoustics committed Mar 6, 2024
2 parents 50c1450 + 689629b commit c095355
Show file tree
Hide file tree
Showing 10 changed files with 196 additions and 1,553 deletions.
154 changes: 77 additions & 77 deletions docs/tutorials/HowToAnalyseAndRepresentSoundscapes.ipynb

Large diffs are not rendered by default.

20 changes: 14 additions & 6 deletions docs/tutorials/QuickStart.ipynb

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions soundscapy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

import importlib.metadata

from soundscapy import plotting
from soundscapy.analysis._AnalysisSettings import AnalysisSettings, get_default_yaml
from soundscapy.analysis._Binaural import Binaural
from soundscapy.utils import _sspy_accessor, surveys
from soundscapy.databases import isd, araus, satp
from soundscapy import plotting
from soundscapy.databases import araus, isd, satp
from soundscapy.utils import surveys

__version__ = importlib.metadata.version("soundscapy")
317 changes: 1 addition & 316 deletions soundscapy/databases/isd.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def validate(
return df, excl_df


def _isd_select(data, select_by, condition):
def _isd_select(data: pd.DataFrame, select_by, condition):
"""
General function to select by ID variables.
Expand Down Expand Up @@ -343,318 +343,3 @@ def soundscapy_describe(
}

return pd.DataFrame.from_dict(res, orient="index")


@register_dataframe_accessor("isd")
class ISDAccessor:
"""Custom accessor for the International Soundscape Database (ISD) dataset
Parameters
----------
pandas_obj : pd.DataFrame
Dataframe containing ISD formatted data
Attributes
----------
_obj : pd.DataFrame
Dataframe containing ISD formatted data
_analysis_data : str
Date of analysis
_metadata : dict
Dictionary of metadata
Methods
-------
validate_dataset
Validate the dataset to ensure it is in the correct format.
likert_data_quality
Return the data quality of the PAQs
filter_group_ids
Filter the dataframe by GroupID
filter_location_ids
Filter the dataframe by LocationID
filter_session_ids
Filter the dataframe by SessionID
filter_record_ids
Filter the dataframe by RecordID
filter_lockdown
Filter the dataframe by Lockdown
convert_group_ids_to_index
Convert the GroupID column to the index
return_paqs
Return the PAQs as a dataframe
soundscapy_describe
Return a summary of the data
mean_responses
Calculate the mean responses for each PAQ
convert_column_to_index
Reassign an existing column as the dataframe index.
"""

def __init__(self, pandas_obj):
self._obj = pandas_obj
self._analysis_data = date.today().isoformat()
self._metadata = {}

# raise PendingDeprecationWarning("The ISD Accessor is being deprecated.")

def validate_dataset(
self,
paq_aliases=PAQ_NAMES,
allow_lockdown=False,
allow_paq_na=False,
verbose=1,
val_range=(1, 5),
):
"""DEPRECATED - Use `soundscapy.isd.validate(data)` instead.
Validate the dataset to ensure it is in the correct format.
Parameters
----------
paq_aliases : list, optional
List of aliases for the PAQ, by default PAQ_NAMES
allow_lockdown : bool, optional
Allow lockdown, by default False
allow_paq_na : bool, optional
Allow PAQ to be NA, by default False
verbose : int, optional
Print progress, by default 1
val_range : tuple, optional
Range of valid values, by default (1, 5)
Returns
-------
pandas.DataFrame
Validated dataframe
"""
raise DeprecationWarning(
"The ISD accessor has been deprecated. Please use `soundscapy.isd.validate(data)` instead."
)

def paq_data_quality(self, verbose=0):
"""Return the data quality of the PAQs
Parameters
----------
verbose : int, optional
Print progress, by default 0
Returns
-------
pandas.DataFrame
"""
raise DeprecationWarning(
"The ISD accessor has been deprecated. Please use `soundscapy.utils.likert_data_quality()` instead."
)
# return likert_data_quality(self._obj, verbose=verbose)

def filter_group_ids(self, group_ids):
"""
Filter the dataframe by GroupID
Parameters
----------
group_ids : list
List of GroupIDs to filter by
Returns
-------
pd.DataFrame
Filtered dataframe
"""
raise DeprecationWarning(
"The ISD accessor has been deprecated. Please use `soundscapy.isd.select_group_ids()` instead."
)
# return self._obj.sspy.filter("GroupID", group_ids)

def filter_location_ids(self, location_ids):
"""Filter the dataframe by LocationID
Parameters
----------
location_ids : list
List of LocationIDs to filter by
Returns
-------
pd.DataFrame
Filtered dataframe
"""
raise DeprecationWarning(
"The ISD accessor has been deprecated. Please use `soundscapy.isd.select_location_ids()` instead."
)
# return self._obj.sspy.filter("LocationID", location_ids)

def filter_session_ids(self, session_ids):
"""Filter the dataframe by SessionID
Parameters
----------
session_ids : list
List of SessionIDs to filter by
Returns
-------
pd.DataFrame
Filtered dataframe
"""
raise DeprecationWarning(
"The ISD accessor has been deprecated. Please use `soundscapy.isd.select_session_ids()` instead."
)
# return self._obj.sspy.filter("SessionID", session_ids)

def filter_record_ids(self, record_ids):
"""Filter the dataframe by RecordID
Parameters
----------
record_ids : list
List of RecordIDs to filter by
Returns
-------
pd.DataFrame
Filtered dataframe
"""
raise DeprecationWarning("The ISD accessor has been deprecated.")

def filter_lockdown(self, is_lockdown=False):
"""Filter the dataframe by Lockdown
Parameters
----------
is_lockdown : bool, optional
Filter by lockdown, by default False
Returns
-------
pd.DataFrame
Filtered dataframe
"""
raise DeprecationWarning("The ISD accessor has been deprecated.")

def convert_group_ids_to_index(self, drop=False):
"""Convert the GroupID column to the index
Parameters
----------
drop : bool, optional
Drop the GroupID column, by default False
Returns
-------
pd.DataFrame
Dataframe with GroupID as index
"""
raise DeprecationWarning("The ISD accessor has been deprecated.")

def return_paqs(self, incl_ids=True, other_cols=None):
"""Return the PAQs as a dataframe
Parameters
----------
incl_ids : bool, optional
Include the IDs, by default True
other_cols : list, optional
List of other columns to include, by default None
Returns
-------
pd.DataFrame
Dataframe containing the PAQs
"""
raise DeprecationWarning("The ISD accessor has been deprecated.")

def location_describe(
self, location, type="percent", pl_threshold=0, ev_threshold=0
):
"""Return a summary of the data
Parameters
----------
location : str
Location to describe
type : str, optional
Type of summary, by default "percent"
pl_threshold : int, optional
PL threshold, by default 0
ev_threshold : int, optional
EV threshold, by default 0
Returns
-------
pd.DataFrame
Summary of the data
"""
raise DeprecationWarning(
"The ISD accessor has been deprecated. Please use `soundscapy.isd.describe_location()` instead."
)

def soundscapy_describe(self, group_by="LocationID", type="percent"):
"""Return a summary of the data
Parameters
----------
group_by : str, optional
Column to group by, by default "LocationID"
type : str, optional
Type of summary, by default "percent"
Returns
-------
pd.DataFrame
Summary of the data
"""
raise DeprecationWarning(
"The ISD accessor has been deprecated. Please use `soundscapy.isd.soundscapy_describe()` instead."
)

def mean_responses(self, group="LocationID") -> pd.DataFrame:
"""Calculate the mean responses for each PAQ
Parameters
----------
df : pd.DataFrame
Dataframe containing ISD formatted data
Returns
-------
pd.Dataframe
Dataframe containing the mean responses for each PAQ
"""
raise DeprecationWarning("The ISD accessor has been deprecated.")

def validate_isd(
self,
paq_aliases=None,
allow_lockdown=False,
allow_paq_na=False,
verbose=1,
val_range=(1, 5),
):
"""Validate the ISD dataset.
Parameters
----------
df : pd.DataFrame
Dataframe containing ISD formatted data
paq_aliases : dict, optional
Dictionary of PAQ aliases, by default None
allow_lockdown : bool, optional
Allow lockdown PAQs?, by default False
allow_paq_na : bool, optional
Allow missing PAQs?, by default False
verbose : int, optional
Verbosity level, by default 1
val_range : tuple, optional
Range of valid values, by default (1,5)
Returns
-------
pd.DataFrame
Dataframe containing the validation results
"""
raise DeprecationWarning(
"The ISD accessor has been deprecated. Please use `soundscapy.isd.validate(data)` instead."
)
1 change: 1 addition & 0 deletions soundscapy/plotting/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
The module ``plotting`` contains functions for plotting soundscape circumplex data and directly plotting Likert scale data.
"""
from soundscapy.plotting.circumplex import scatter, density, jointplot
from soundscapy.plotting import likert
Loading

0 comments on commit c095355

Please sign in to comment.