Survey Analysis
This section provides an overview of the survey instruments used in soundscape research. It includes a brief description of each instrument, as well as information on how to access and use them.
Soundscape survey data processing module.
This module contains functions for processing and analyzing soundscape survey data, including ISO coordinate calculations, data quality checks, and SSM metrics.
Notes
The functions in this module are designed to be fairly general and can be used with any dataset in a similar format to the ISD. The key to this is using a simple dataframe/sheet with the following columns: Index columns: e.g. LocationID, RecordID, GroupID, SessionID Perceptual attributes: PAQ1, PAQ2, ..., PAQ8 Independent variables: e.g. Laeq, N5, Sharpness, etc.
The key functions of this module are designed to clean/validate datasets, calculate ISO coordinate values or SSM metrics,
filter on index columns. Functions and operations which are specific to a particular dataset are located in their own
modules under soundscape.databases
.
ISOCoordinates
dataclass
ISOCoordinates(pleasant, eventful)
Dataclass for storing ISO coordinates.
SSMMetrics
dataclass
SSMMetrics(amplitude, angle, elevation, displacement, r_squared)
Dataclass for storing Structural Summary Method (SSM) metrics.
add_iso_coords
add_iso_coords(data, val_range=(1, 5), names=('ISOPleasant', 'ISOEventful'), overwrite=False, angles=EQUAL_ANGLES)
Calculate and add ISO coordinates as new columns in the DataFrame.
PARAMETER | DESCRIPTION |
---|---|
data |
Input DataFrame containing PAQ data
TYPE:
|
val_range |
(min, max) range of original PAQ responses, by default (1, 5)
TYPE:
|
names |
Names for new coordinate columns, by default ("ISOPleasant", "ISOEventful")
TYPE:
|
overwrite |
Whether to overwrite existing ISO coordinate columns, by default False
TYPE:
|
angles |
Angles for each PAQ in degrees, by default EQUAL_ANGLES
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
DataFrame
|
DataFrame with new ISO coordinate columns added |
RAISES | DESCRIPTION |
---|---|
Warning
|
If ISO coordinate columns already exist and overwrite is False |
Examples:
>>> import pandas as pd
>>> df = pd.DataFrame({
... 'PAQ1': [4, 2], 'PAQ2': [3, 5], 'PAQ3': [2, 4], 'PAQ4': [1, 3],
... 'PAQ5': [5, 1], 'PAQ6': [3, 2], 'PAQ7': [4, 3], 'PAQ8': [2, 5]
... })
>>> df_with_iso = add_iso_coords(df)
>>> df_with_iso[['ISOPleasant', 'ISOEventful']].round(2)
ISOPleasant ISOEventful
0 -0.03 -0.28
1 0.47 0.18
Source code in soundscapy/surveys/processing.py
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 |
|
calculate_iso_coords
calculate_iso_coords(results_df, val_range=(5, 1), angles=EQUAL_ANGLES)
Calculate the projected ISOPleasant and ISOEventful coordinates.
PARAMETER | DESCRIPTION |
---|---|
results_df |
DataFrame containing PAQ data.
TYPE:
|
val_range |
(max, min) range of original PAQ responses, by default (5, 1)
TYPE:
|
angles |
Angles for each PAQ in degrees, by default EQUAL_ANGLES
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Tuple[Series, Series]
|
ISOPleasant and ISOEventful coordinate values |
Examples:
>>> import pandas as pd
>>> df = pd.DataFrame({
... 'PAQ1': [4, 2], 'PAQ2': [3, 5], 'PAQ3': [2, 4], 'PAQ4': [1, 3],
... 'PAQ5': [5, 1], 'PAQ6': [3, 2], 'PAQ7': [4, 3], 'PAQ8': [2, 5]
... })
>>> iso_pleasant, iso_eventful = calculate_iso_coords(df)
>>> iso_pleasant.round(2)
0 -0.03
1 0.47
dtype: float64
>>> iso_eventful.round(2)
0 -0.28
1 0.18
dtype: float64
Source code in soundscapy/surveys/processing.py
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
|
likert_data_quality
likert_data_quality(df, allow_na=False, val_range=(1, 5))
Perform basic quality checks on PAQ (Likert scale) data.
PARAMETER | DESCRIPTION |
---|---|
df |
DataFrame containing PAQ data
TYPE:
|
allow_na |
Whether to allow NaN values in PAQ data, by default False
TYPE:
|
val_range |
Valid range for PAQ values, by default (1, 5)
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Optional[List[int]]
|
List of indices to be removed, or None if no issues found |
Examples:
>>> import pandas as pd
>>> import numpy as np
>>> df = pd.DataFrame({
... 'PAQ1': [np.nan, 2, 3, 3], 'PAQ2': [3, 2, 6, 3], 'PAQ3': [2, 2, 3, 3],
... 'PAQ4': [1, 2, 3, 3], 'PAQ5': [5, 2, 3, 3], 'PAQ6': [3, 2, 3, 3],
... 'PAQ7': [4, 2, 3, 3], 'PAQ8': [2, 2, 3, 3]
... })
>>> likert_data_quality(df)
[0, 1, 2]
>>> likert_data_quality(df, allow_na=True)
[1, 2]
Source code in soundscapy/surveys/processing.py
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 |
|
simulation
simulation(n=3000, val_range=(1, 5), incl_iso_coords=False, **coord_kwargs)
Generate random PAQ responses for simulation purposes.
PARAMETER | DESCRIPTION |
---|---|
n |
Number of samples to simulate, by default 3000
TYPE:
|
val_range |
Range of values for PAQ responses, by default (1, 5)
TYPE:
|
add_iso_coords |
Whether to add calculated ISO coordinates, by default False
TYPE:
|
**coord_kwargs |
Additional keyword arguments to pass to add_iso_coords function
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
DataFrame
|
DataFrame of randomly generated PAQ responses |
Examples:
>>> df = simulation(n=5, incl_iso_coords=True)
>>> df.shape
(5, 10)
>>> list(df.columns)
['PAQ1', 'PAQ2', 'PAQ3', 'PAQ4', 'PAQ5', 'PAQ6', 'PAQ7', 'PAQ8', 'ISOPleasant', 'ISOEventful']
Source code in soundscapy/surveys/processing.py
288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 |
|
ssm_cosine_fit
ssm_cosine_fit(y, angles=EQUAL_ANGLES, bounds=([0, 0, 0, -np.inf], [np.inf, 360, np.inf, np.inf]))
Fit a cosine model to the PAQ data for SSM analysis.
PARAMETER | DESCRIPTION |
---|---|
y |
Series of PAQ values
TYPE:
|
angles |
Angles for each PAQ in degrees, by default EQUAL_ANGLES
TYPE:
|
bounds |
Bounds for the optimization parameters, by default ([0, 0, 0, -np.inf], [np.inf, 360, np.inf, np.inf])
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
SSMMetrics
|
Calculated SSM metrics |
Examples:
>>> # xdoctest: +SKIP
>>> import pandas as pd
>>> y = pd.Series([4, 3, 2, 1, 5, 3, 4, 2])
>>> metrics = ssm_cosine_fit(y)
>>> [round(v, 2) if isinstance(v, float) else v for v in metrics.table()]
[0.68, 263.82, 10.57, -7.57, 0.15]
Source code in soundscapy/surveys/processing.py
416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 |
|
ssm_metrics
ssm_metrics(df, paq_cols=PAQ_IDS, method='cosine', val_range=(5, 1), angles=EQUAL_ANGLES)
Calculate the Structural Summary Method (SSM) metrics for each response.
PARAMETER | DESCRIPTION |
---|---|
df |
DataFrame containing PAQ data
TYPE:
|
paq_cols |
List of PAQ column names, by default PAQ_IDS
TYPE:
|
method |
Method to calculate SSM metrics, either "cosine" or "polar", by default "cosine"
TYPE:
|
val_range |
Range of values for PAQ responses, by default (5, 1)
TYPE:
|
angles |
Angles for each PAQ in degrees, by default EQUAL_ANGLES
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
DataFrame
|
DataFrame containing the SSM metrics |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If PAQ columns are not present in the DataFrame or if an invalid method is specified |
Examples:
>>> # xdoctest: +SKIP
>>> import pandas as pd
>>> df = pd.DataFrame({
... 'PAQ1': [4, 2], 'PAQ2': [3, 5], 'PAQ3': [2, 4], 'PAQ4': [1, 3],
... 'PAQ5': [5, 1], 'PAQ6': [3, 2], 'PAQ7': [4, 3], 'PAQ8': [2, 5]
... })
>>> ssm_metrics(df).round(2)
amplitude angle elevation displacement r_squared
0 0.68 263.82 10.57 -7.57 0.15
1 1.21 20.63 0.01 3.11 0.39
Source code in soundscapy/surveys/processing.py
334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 |
|
Core utility functions for processing soundscape survey data.
This module contains fundamental functions and constants used across the soundscapy package for handling and analyzing soundscape survey data.
PAQ
PAQ(label, id)
Bases: Enum
Enumeration of Perceptual Attribute Questions (PAQ) names and IDs.
Source code in soundscapy/surveys/survey_utils.py
27 28 29 |
|
mean_responses
mean_responses(df, group)
Calculate the mean responses for each PAQ group.
PARAMETER | DESCRIPTION |
---|---|
df |
Input DataFrame containing PAQ data.
TYPE:
|
group |
Column name to group by.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
DataFrame
|
DataFrame with mean responses for each PAQ group. |
Source code in soundscapy/surveys/survey_utils.py
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
|
rename_paqs
rename_paqs(df, paq_aliases=None)
Rename the PAQ columns in a DataFrame to standard PAQ IDs.
PARAMETER | DESCRIPTION |
---|---|
df |
Input DataFrame containing PAQ data.
TYPE:
|
paq_aliases |
Specify which PAQs are to be renamed. If None, will check if the column names are in pre-defined options. If a tuple, the order must match PAQ_IDS. If a dict, keys are current names and values are desired PAQ IDs.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
DataFrame
|
DataFrame with renamed PAQ columns. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If paq_aliases is not a tuple, list, or dictionary. |
Examples:
>>> import pandas as pd
>>> df = pd.DataFrame({
... 'pleasant': [4, 3],
... 'vibrant': [2, 5],
... 'other_col': [1, 2]
... })
>>> rename_paqs(df)
PAQ1 PAQ2 other_col
0 4 2 1
1 3 5 2
>>> df_custom = pd.DataFrame({
... 'pl': [4, 3],
... 'vb': [2, 5],
... })
>>> rename_paqs(df_custom, paq_aliases={'pl': 'PAQ1', 'vb': 'PAQ2'})
PAQ1 PAQ2
0 4 2
1 3 5
Source code in soundscapy/surveys/survey_utils.py
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
|
return_paqs
return_paqs(df, incl_ids=True, other_cols=None)
Return only the PAQ columns from a DataFrame.
PARAMETER | DESCRIPTION |
---|---|
df |
Input DataFrame containing PAQ data.
TYPE:
|
incl_ids |
Whether to include ID columns (RecordID, GroupID, etc.), by default True.
TYPE:
|
other_cols |
Other columns to include in the output, by default None.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
DataFrame
|
DataFrame containing only the PAQ columns and optionally ID and other specified columns. |
Examples:
>>> import pandas as pd
>>> df = pd.DataFrame({
... 'RecordID': [1, 2],
... 'PAQ1': [4, 3],
... 'PAQ2': [2, 5],
... 'PAQ3': [1, 2],
... 'PAQ4': [3, 4],
... 'PAQ5': [5, 1],
... 'PAQ6': [2, 3],
... 'PAQ7': [4, 5],
... 'PAQ8': [1, 2],
... 'OtherCol': ['A', 'B']
... })
>>> return_paqs(df)
RecordID PAQ1 PAQ2 PAQ3 PAQ4 PAQ5 PAQ6 PAQ7 PAQ8
0 1 4 2 1 3 5 2 4 1
1 2 3 5 2 4 1 3 5 2
>>> return_paqs(df, incl_ids=False, other_cols=['OtherCol'])
PAQ1 PAQ2 PAQ3 PAQ4 PAQ5 PAQ6 PAQ7 PAQ8 OtherCol
0 4 2 1 3 5 2 4 1 A
1 3 5 2 4 1 3 5 2 B
Source code in soundscapy/surveys/survey_utils.py
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
|