Parameter Models¶
soundscapy.plotting.param_models
¶
Parameter models for plotting functions in soundscapy.
This module provides parameter validation and management classes for various plotting functions using Pydantic dataclasses. The module includes:
- Base ParamModel class with common functionality
- SeabornParams for seaborn plotting parameters
- Specialized parameter classes for different plot types
- Style and subplot configuration classes
The parameter models provide:
- Type validation and conversion
- Default value management
- Parameter updating with validation
- Dictionary-style access to parameters
- Deep copying functionality
| CLASS | DESCRIPTION |
|---|---|
ParamModel |
Base model for parameter validation using dataclasses. |
SeabornParams |
Base parameters for seaborn plotting functions. |
ScatterParams |
Parameters for scatter plot functions. |
DensityParams |
Parameters for density plot functions. |
SimpleDensityParams |
Parameters for simple density plot functions. |
SPISeabornParams |
Base parameters for SPI (Soundscape Perceptual Index) seaborn plotting functions. |
SPISimpleDensityParams |
Parameters for SPI simple density plot functions. |
JointPlotParams |
Parameters for joint plot functions. |
StyleParams |
Parameters for plot styling. |
SubplotsParams |
Parameters for subplots. |
ParamModel
¶
Base model for parameter validation using dataclasses.
This class provides the foundation for all parameter models with common configuration settings and utility methods.
| METHOD | DESCRIPTION |
|---|---|
__post_init__ |
Process extra fields after initialization. |
update |
Update the attributes of the instance based on the provided parameters. |
get_defaults |
Get the default values for all defined fields in the model. |
get |
Get a parameter value with a default fallback. |
__getitem__ |
Get a parameter value using dictionary-style access. |
as_dict |
Get all parameters as a dictionary. |
copy |
Create a deep copy of the parameter model instance. |
model_copy |
Create a copy of the parameter model instance. |
get_changed_params |
Get parameters that have been changed from their defaults. |
get_multiple |
Get multiple parameters as a dictionary. |
pop |
Remove a parameter and return its value. |
drop |
Remove a parameter without returning its value. |
| ATTRIBUTE | DESCRIPTION |
|---|---|
defaults |
Property to access default field values. |
defined_field_names |
Get the names of all fields defined for the model. |
current_field_names |
Get the names of all current fields. |
defaults
property
¶
defined_field_names
property
¶
current_field_names
property
¶
__post_init__
¶
Process extra fields after initialization.
Source code in src/soundscapy/plotting/param_models.py
update
¶
update(
*,
extra: Literal["allow", "forbid", "ignore"] = "allow",
ignore_null: bool = True,
**kwargs: Any,
) -> None
Update the attributes of the instance based on the provided parameters.
| PARAMETER | DESCRIPTION |
|---|---|
extra
|
Determines how to handle extra fields in
TYPE:
|
ignore_null
|
If True, removes
TYPE:
|
**kwargs
|
Field names and values to be updated.
TYPE:
|
Source code in src/soundscapy/plotting/param_models.py
get_defaults
¶
Get the default values for all defined fields in the model.
| RETURNS | DESCRIPTION |
|---|---|
dict[str, Any]
|
Dictionary mapping field names to their default values.
Excludes the special |
Source code in src/soundscapy/plotting/param_models.py
get
¶
Get a parameter value with a default fallback.
| PARAMETER | DESCRIPTION |
|---|---|
key
|
Name of the parameter
TYPE:
|
default
|
Default value if parameter doesn't exist
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Any
|
Parameter value or default |
Source code in src/soundscapy/plotting/param_models.py
__getitem__
¶
Get a parameter value using dictionary-style access.
| PARAMETER | DESCRIPTION |
|---|---|
key
|
Name of the parameter
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Any
|
Parameter value |
| RAISES | DESCRIPTION |
|---|---|
KeyError
|
If the parameter doesn't exist |
Source code in src/soundscapy/plotting/param_models.py
as_dict
¶
copy
¶
Create a deep copy of the parameter model instance.
| RETURNS | DESCRIPTION |
|---|---|
ParamModel
|
A deep copy of the current instance with all nested objects copied. |
Source code in src/soundscapy/plotting/param_models.py
model_copy
¶
Create a copy of the parameter model instance.
Deprecated
This method is deprecated. Use :meth:copy instead.
Kept only for backwards compatibility with Pydantic.
| RETURNS | DESCRIPTION |
|---|---|
ParamModel
|
A deep copy of the current instance. |
Source code in src/soundscapy/plotting/param_models.py
get_changed_params
¶
Get parameters that have been changed from their defaults.
This method compares the current parameter values against the default values and returns a dictionary containing only the parameters that differ from their defaults.
| RETURNS | DESCRIPTION |
|---|---|
dict[str, Any]
|
Dictionary of changed parameters and their current values. |
Source code in src/soundscapy/plotting/param_models.py
get_multiple
¶
pop
¶
Remove a parameter and return its value.
For fields defined in the model, the value is reset to its default.
| PARAMETER | DESCRIPTION |
|---|---|
key
|
Name of the parameter
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Any
|
Value of the removed parameter |
| RAISES | DESCRIPTION |
|---|---|
KeyError
|
If the parameter doesn't exist |
Source code in src/soundscapy/plotting/param_models.py
drop
¶
Remove a parameter without returning its value.
| PARAMETER | DESCRIPTION |
|---|---|
keys
|
Name of the parameter or list of parameters |
ignore_missing
|
If True, ignore missing keys. If False, raise KeyError for missing keys.
TYPE:
|
Source code in src/soundscapy/plotting/param_models.py
SeabornParams
¶
Bases: ParamModel
Base parameters for seaborn plotting functions.
Provides common parameters used across seaborn plotting functions including data source, aesthetic mappings, and color settings.
| METHOD | DESCRIPTION |
|---|---|
crosscheck_palette_hue |
Check if the palette is valid for the given hue. |
as_seaborn_kwargs |
Convert parameters to kwargs compatible with seaborn functions. |
crosscheck_palette_hue
¶
Check if the palette is valid for the given hue.
This method ensures that palette is only used when hue is provided.
Source code in src/soundscapy/plotting/param_models.py
ScatterParams
¶
Bases: SeabornParams
Parameters for scatter plot functions.
Inherits from SeabornParams and adds scatter-specific parameters.
DensityParams
¶
Bases: SeabornParams
Parameters for density plot functions.
Inherits from SeabornParams and adds density-specific parameters for contour plots and kernel density estimation.
| METHOD | DESCRIPTION |
|---|---|
as_seaborn_kwargs |
Convert parameters to kwargs compatible with seaborn functions. |
to_outline |
Convert to outline parameters. |
as_seaborn_kwargs
¶
Convert parameters to kwargs compatible with seaborn functions.
| RETURNS | DESCRIPTION |
|---|---|
dict[str, Any]
|
Dictionary of parameter values suitable for seaborn plotting functions. |
Source code in src/soundscapy/plotting/param_models.py
to_outline
¶
Convert to outline parameters.
| PARAMETER | DESCRIPTION |
|---|---|
alpha
|
Alpha value for the outline.
TYPE:
|
fill
|
Whether to fill the outline.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
DensityParams
|
New instance with outline parameters. |
Source code in src/soundscapy/plotting/param_models.py
SimpleDensityParams
¶
Bases: DensityParams
Parameters for simple density plot functions.
Inherits from DensityParams with overridden defaults for simplified density plots with fewer contour levels.
SPISeabornParams
¶
Bases: SeabornParams
Base parameters for SPI (Soundscape Perceptual Index) seaborn plotting functions.
Specialized parameters for plotting SPI data with specific styling and annotation options.
| METHOD | DESCRIPTION |
|---|---|
as_seaborn_kwargs |
Convert parameters to kwargs compatible with seaborn functions. |
as_seaborn_kwargs
¶
Convert parameters to kwargs compatible with seaborn functions.
| RETURNS | DESCRIPTION |
|---|---|
dict[str, Any]
|
Dictionary of parameter values suitable for seaborn plotting functions. |
Source code in src/soundscapy/plotting/param_models.py
SPISimpleDensityParams
¶
Bases: SPISeabornParams, SimpleDensityParams
Parameters for SPI simple density plot functions.
Combines SPI-specific parameters with simple density plot parameters through multiple inheritance.
JointPlotParams
¶
Bases: ParamModel
Parameters for joint plot functions.
Parameters for creating joint plots that show both the relationship between two variables and their individual distributions.
StyleParams
¶
Bases: ParamModel
Parameters for plot styling.
Controls the visual appearance of plots including axes limits, labels, lines, and text formatting.
SubplotsParams
¶
Bases: ParamModel
Parameters for subplots.
Controls the layout and configuration of subplot grids, including figure size, sharing of axes, and automatic allocation.
| METHOD | DESCRIPTION |
|---|---|
as_plt_subplots_args |
Pass matplotlib subplot arguments to a plt.subplots call. |
| ATTRIBUTE | DESCRIPTION |
|---|---|
n_subplots_by |
"The number of subplots allocated for each subplot_by category.
TYPE:
|
n_subplots |
Get the number of subplots.
TYPE:
|
n_subplots_by
class-attribute
instance-attribute
¶
"The number of subplots allocated for each subplot_by category.
as_plt_subplots_args
¶
Pass matplotlib subplot arguments to a plt.subplots call.
| RETURNS | DESCRIPTION |
|---|---|
dict[str, Any]
|
Dictionary of subplot parameters. |