These functions find peaks (local maxima) or valleys (local minima) in a spectrum, using a user selectable size threshold relative to the tallest peak (global maximum). This a wrapper built on top of function peaks from package splus2R.
Usage
get_peaks(
x,
y,
ignore_threshold = 0,
span = 5,
strict = TRUE,
x_unit = "",
x_digits = 3,
na.rm = FALSE
)
get_valleys(
x,
y,
ignore_threshold = 0,
span = 5,
strict = TRUE,
x_unit = "",
x_digits = 3,
na.rm = FALSE
)
Arguments
- x
numeric
- y
numeric
- ignore_threshold
numeric Value between 0.0 and 1.0 indicating the relative size compared to tallest peak threshold below which peaks will be ignored. Negative values set a threshold so that the tallest peaks are ignored, instead of the shortest.
- span
integer A peak is defined as an element in a sequence which is greater than all other elements within a window of width
span
centered at that element. UseNULL
for the global peak.- strict
logical If
TRUE
, an element must be strictly greater than all other values in its window to be considered a peak.- x_unit
character Vector of texts to be pasted at end of labels built from x value at peaks.
- x_digits
numeric Number of significant digits in wavelength label.
- na.rm
logical indicating whether
NA
values should be stripped before searching for peaks.
Value
A data frame with variables w.length and s.irrad with their values at the peaks or valleys plus a character variable of labels.
See also
Other peaks and valleys functions:
find_peaks()
,
find_spikes()
,
peaks()
,
replace_bad_pixs()
,
spikes()
,
valleys()
,
wls_at_target()
Examples
with(sun.spct, get_peaks(w.length, s.e.irrad))
#> x y label
#> 1 321 0.1822031 321
#> 2 330 0.3295190 330
#> 3 335 0.3129253 335
#> 4 340 0.3352353 340
#> 5 343 0.3380052 343
#> 6 347 0.3207918 347
#> 7 350 0.3453572 350
#> 8 354 0.3758625 354
#> 9 360 0.3707068 360
#> 10 366 0.4491898 366
#> 11 370 0.4393233 370
#> 12 378 0.4969714 378
#> 13 381 0.4362110 381
#> 14 385 0.3915446 385
#> 15 391 0.4822105 391
#> 16 395 0.4699886 395
#> 17 402 0.6497388 402
#> 18 409 0.6615421 409
#> 19 412 0.6742498 412
#> 20 416 0.6761818 416
#> 21 421 0.6701269 421
#> 22 426 0.6388873 426
#> 23 436 0.7336607 436
#> 24 442 0.7188581 442
#> 25 451 0.8204633 451
#> 26 457 0.7984935 457
#> 27 461 0.7711277 461
#> 28 468 0.7665312 468
#> 29 472 0.7693357 472
#> 30 475 0.7724634 475
#> 31 478 0.7869773 478
#> 32 482 0.7832759 482
#> 33 490 0.7728111 490
#> 34 495 0.7899872 495
#> 35 506 0.7701737 506
#> 36 509 0.7466557 509
#> 37 512 0.7510876 512
#> 38 516 0.7302733 516
#> 39 525 0.7376088 525
#> 40 531 0.7603297 531
#> 41 536 0.7429248 536
#> 42 545 0.7272464 545
#> 43 552 0.7178863 552
#> 44 555 0.7117599 555
#> 45 563 0.6991590 563
#> 46 568 0.6750915 568
#> 47 573 0.6713390 573
#> 48 577 0.6644287 577
#> 49 582 0.6853736 582
#> 50 597 0.6256272 597
#> 51 600 0.6372767 600
#> 52 605 0.6614323 605
#> 53 612 0.6468436 612
#> 54 621 0.6464099 621
#> 55 638 0.6233510 638
#> 56 642 0.6138918 642
#> 57 653 0.5819163 653
#> 58 662 0.5995383 662
#> 59 668 0.5977089 668
#> 60 674 0.5879885 674
#> 61 692 0.5029201 692
#> 62 697 0.5164799 697
#> 63 704 0.5013394 704
#> 64 712 0.5070675 712
#> 65 722 0.4345295 722
#> 66 727 0.3855997 727
#> 67 734 0.4676589 734
#> 68 744 0.5006212 744
#> 69 747 0.5025733 747
#> 70 751 0.5000141 751
#> 71 754 0.5007593 754
#> 72 774 0.4746771 774
#> 73 777 0.4716414 777
#> 74 782 0.4680026 782
#> 75 794 0.4213304 794
#> 76 798 0.4236281 798
with(sun.spct, get_valleys(w.length, s.e.irrad))
#> x y label
#> 1 316 0.1020587 316
#> 2 323 0.1680533 323
#> 3 328 0.2648573 328
#> 4 331 0.2895510 331
#> 5 337 0.2609770 337
#> 6 341 0.3053287 341
#> 7 344 0.2675878 344
#> 8 349 0.2981687 349
#> 9 352 0.3234148 352
#> 10 358 0.2544907 358
#> 11 368 0.3980621 368
#> 12 374 0.3260057 374
#> 13 383 0.2614310 383
#> 14 393 0.2422023 393
#> 15 397 0.2541827 397
#> 16 403 0.6207287 403
#> 17 407 0.5951226 407
#> 18 410 0.5605505 410
#> 19 413 0.6456365 413
#> 20 420 0.5988416 420
#> 21 424 0.6026922 424
#> 22 431 0.4136900 431
#> 23 434 0.6298332 434
#> 24 439 0.6028502 439
#> 25 446 0.6652017 446
#> 26 453 0.6972674 453
#> 27 458 0.7618389 458
#> 28 467 0.7429891 467
#> 29 471 0.7424066 471
#> 30 474 0.7454852 474
#> 31 479 0.7536975 479
#> 32 487 0.6511654 487
#> 33 492 0.6896611 492
#> 34 498 0.7122628 498
#> 35 502 0.6916296 502
#> 36 508 0.7013302 508
#> 37 517 0.6176652 517
#> 38 523 0.6957057 523
#> 39 527 0.6492072 527
#> 40 533 0.6460471 533
#> 41 541 0.6684246 541
#> 42 548 0.6936565 548
#> 43 553 0.6920716 553
#> 44 559 0.6765463 559
#> 45 562 0.6676445 562
#> 46 566 0.6501603 566
#> 47 571 0.6443685 571
#> 48 575 0.6539001 575
#> 49 579 0.6474340 579
#> 50 589 0.5658760 589
#> 51 595 0.6028277 595
#> 52 610 0.6390005 610
#> 53 617 0.6007438 617
#> 54 628 0.5896789 628
#> 55 632 0.5841746 632
#> 56 640 0.5997701 640
#> 57 648 0.5547404 648
#> 58 656 0.4982959 656
#> 59 667 0.5856558 667
#> 60 672 0.5817669 672
#> 61 689 0.4739026 689
#> 62 694 0.4725514 694
#> 63 701 0.4684248 701
#> 64 707 0.4879018 707
#> 65 719 0.3366514 719
#> 66 725 0.3832661 725
#> 67 728 0.3791977 728
#> 68 736 0.4502648 736
#> 69 750 0.4922409 750
#> 70 753 0.4957415 753
#> 71 761 0.1373212 761
#> 72 772 0.4666001 772
#> 73 775 0.4618263 775
#> 74 791 0.4198022 791
#> 75 796 0.4080616 796