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.
surveys
The module containing functions for dealing with soundscape survey data.
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
.
add_iso_coords
add_iso_coords(data, val_range=(1, 5), names=('ISOPleasant', 'ISOEventful'), overwrite=False, angles=(0, 45, 90, 135, 180, 225, 270, 315))
Calculate and add ISO coordinates as new columns in dataframe
Calls calculate_paq_coords()
PARAMETER | DESCRIPTION |
---|---|
angles |
DEFAULT:
|
data |
ISD Dataframe
TYPE:
|
val_range |
(max, min) range of original PAQ responses, by default (5, 1)
DEFAULT:
|
names |
Names for new coordinate columns, by default ["ISOPleasant", "ISOEventful"]
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
DataFrame
|
Dataframe with new columns added |
See Also
:func:soundscapy.database.calculate_paq_coords
Source code in soundscapy/utils/surveys.py
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 414 415 416 417 418 419 420 421 422 423 424 425 426 |
|
adj_iso_ev
adj_iso_ev(values, angles, scale=None)
Calculate the adjusted ISOEventful value
This calculation is based on the formulae given in Aletta et. al. (2024), adapted from ISO12913-3. These formulae were developed to enable the use of adjusted angles and are as follows:
$$ E_{ISO} = \frac{1}{\lambda_{ev}} \sum_{i=1}^{8} \sin(\theta_i) \cdot \sigma_i $$ where i indexes each circumplex scale, $ heta_i$ is the adjusted angle for the circumplex scale for the appropriate language, and \(\sigma_i\) is the response value for the circumplex scale. The \(\frac{1}{\lambda}\) provides a scaling factor (equivalent to the \(\frac{1}{(4 + \sqrt{32})}\) from ISO 12913-3) to bring the range of ISOPleasant, ISOEventful to (-1, +1):
where \(\rho\) is the range of the PAQ values (i.e. 5 - 1 = 4). \(\lambda_{ev}\) is calculated in the same but using \(\sin(\theta_i)\) as before.
PARAMETER | DESCRIPTION |
---|---|
values |
|
angles |
|
scale |
DEFAULT:
|
The |
|
RETURNS | DESCRIPTION |
---|---|
float
|
|
Source code in soundscapy/utils/surveys.py
331 332 333 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 |
|
adj_iso_pl
adj_iso_pl(values, angles, scale=None)
Calculate the adjusted ISOPleasant value
This calculation is based on the formulae given in Aletta et. al. (2024), adapted from ISO12913-3. These formulae were developed to enable the use of adjusted angles and are as follows:
$$ E_{ISO} = \frac{1}{\lambda_{ev}} \sum_{i=1}^{8} \sin(\theta_i) \cdot \sigma_i $$ where i indexes each circumplex scale, $ heta_i$ is the adjusted angle for the circumplex scale for the appropriate language, and \(\sigma_i\) is the response value for the circumplex scale. The \(\frac{1}{\lambda}\) provides a scaling factor (equivalent to the \(\frac{1}{(4 + \sqrt{32})}\) from ISO 12913-3) to bring the range of ISOPleasant, ISOEventful to (-1, +1):
where \(\rho\) is the range of the PAQ values (i.e. 5 - 1 = 4). \(\lambda_{ev}\) is calculated in the same but using \(\sin(\theta_i)\) as before.
PARAMETER | DESCRIPTION |
---|---|
values |
TYPE:
|
angles |
TYPE:
|
scale |
DEFAULT:
|
The |
|
RETURNS | DESCRIPTION |
---|---|
float
|
|
Source code in soundscapy/utils/surveys.py
282 283 284 285 286 287 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 |
|
calculate_iso_coords
calculate_iso_coords(results_df, val_range=(5, 1), angles=(0, 45, 90, 135, 180, 225, 270, 315))
Calculates the projected ISOPleasant and ISOEventful coordinates
If a value is missing, by default it is replaced with neutral (3). The raw PAQ values should be Likert data from 1 to 5 and the column names should match the PAQ_cols given above.
PARAMETER | DESCRIPTION |
---|---|
angles |
DEFAULT:
|
results_df |
Dataframe containing ISD formatted data
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
tuple
|
ISOPleasant and ISOEventful coordinate values |
Source code in soundscapy/utils/surveys.py
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 |
|
calculate_polar_coords
calculate_polar_coords(results_df, scaling='iso')
Calculates the polar coordinates
Based on the calculation given in Gurtman and Pincus (2003), pg. 416.
The raw PAQ values should be Likert data from 1 to 5 and the column names should match the PAQ_cols given above.
PARAMETER | DESCRIPTION |
---|---|
results_df |
Dataframe containing ISD formatted data
TYPE:
|
scaling |
The scaling to use for the polar coordinates, by default 'iso' Options are 'iso', 'gurtman', and 'none' For 'iso', the cartesian coordinates are scaled to (-1, +1) according to the basic method given in ISO12913. For 'gurtman', the polar coordinates are scaled according to the method given in Gurtman and Pincus (2003), pg. 416. For 'none', no scaling is applied.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
tuple
|
Polar coordinates |
Source code in soundscapy/utils/surveys.py
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 |
|
convert_column_to_index
convert_column_to_index(df, col, drop=False)
Reassign an existing column as the dataframe index
Source code in soundscapy/utils/surveys.py
90 91 92 93 94 95 96 |
|
likert_data_quality
likert_data_quality(df, verbose=0, allow_na=False, val_range=(1, 5))
Basic check of PAQ data quality
The likert_data_quality function takes a DataFrame and returns a list of indices that should be dropped from the DataFrame. The function checks for:
-
Rows with all values equal to 1 (indicating no PAQ data)
-
Rows with more than 4 NaN values (indicating missing PAQ data)
-
Rows where any value is greater than 5 or less than 1 (indicating invalid PAQ data)
RETURNS | DESCRIPTION |
---|---|
A list of indices that need to be removed from the dataframe
|
|
Source code in soundscapy/utils/surveys.py
157 158 159 160 161 162 163 164 165 166 167 168 169 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 |
|
mean_responses
mean_responses(df, group)
Calculate the mean responses for each PAQ
PARAMETER | DESCRIPTION |
---|---|
df |
Dataframe containing ISD formatted data
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Dataframe
|
Dataframe containing the mean responses for each PAQ |
Source code in soundscapy/utils/surveys.py
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
|
rename_paqs
rename_paqs(df, paq_aliases=None, verbose=0)
The rename_paqs function renames the PAQ columns in a dataframe.
Soundscapy works with PAQ IDs (PAQ1, PAQ2, etc), so if you use labels such as pleasant, vibrant, etc. these will need to be renamed.
It takes as input a pandas DataFrame and returns the same DataFrame with renamed columns. If no arguments are passed, it will attempt to rename all of the PAQs based on their column names.
RETURNS | DESCRIPTION |
---|---|
A pandas dataframe with the paq_ids column names
|
|
Source code in soundscapy/utils/surveys.py
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 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 |
|
return_paqs
return_paqs(df, incl_ids=True, other_cols=None)
Return only the PAQ columns
PARAMETER | DESCRIPTION |
---|---|
incl_ids |
whether to include ID cols too (i.e. RecordID, GroupID, etc), by default True
TYPE:
|
other_cols |
other columns to also include, by default None
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
DataFrame
|
dataframe containing only the PAQ columns |
Source code in soundscapy/utils/surveys.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
|
simulation
simulation(n=3000, val_range=(1, 5), add_iso_coords=False, **coord_kwargs)
Generate random PAQ responses
The PAQ responses will follow a uniform random distribution for each PAQ, meaning e.g. for calm either 1, 2, 3, 4, or 5 is equally likely.
PARAMETER | DESCRIPTION |
---|---|
n |
number of samples to simulate, by default 3000
TYPE:
|
add_iso_coords |
should we also calculate the ISO coordinates, by default False
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Dataframe
|
dataframe of randomly generated PAQ response |
Source code in soundscapy/utils/surveys.py
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 |
|
ssm_cosine_fit
ssm_cosine_fit(y, angles=(0, 45, 90, 135, 180, 225, 270, 315), bounds=([0, 0, 0, -np.inf], [np.inf, 360, np.inf, np.inf]))
Fit a cosine model to the data
PARAMETER | DESCRIPTION |
---|---|
angles |
List of angles
TYPE:
|
y |
List of y values
TYPE:
|
bounds |
Bounds for the parameters
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
tuple
|
(amp, delta, elev, dev) |
Source code in soundscapy/utils/surveys.py
564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 |
|
ssm_metrics
ssm_metrics(df, paq_cols=PAQ_IDS, method='cosine', val_range=(5, 1), scale_to_one=True, angles=(0, 45, 90, 135, 180, 225, 270, 315))
Calculate the SSM metrics for each response
PARAMETER | DESCRIPTION |
---|---|
df |
Dataframe containing ISD formatted data
TYPE:
|
paq_cols |
List of PAQ columns, by default PAQ_IDS
TYPE:
|
method |
Method by which to calculate the SSM, by default 'cosine' 'cosine' fits a cosine model to the data, using the Structural Summary Method developed by Gurtman (1994; Gurtman & Balakrishnan, 1998). 'polar_conversion' directly converts the ISO coordinates to polar coordinates.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
DataFrame
|
Dataframe containing the SSM metrics |
Source code in soundscapy/utils/surveys.py
496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 |
|