Skip to content

names of wavelength vector are lost while collapsing two hyperSpec objects #87

Closed

Description

@galaxismad

Sometimes, it might be beneficial to name the vector elements of the wavelength vector

MWE:
generating two hyperSpec objects with named wavelength vectors

object1 <- barbiturates[[1]]
object2 <- barbiturates[[1]]
names (wl (object1)) <- paste ("Mass", 1:nwl (object1))
names (wl (object2)) <- paste ("Mass", 1:nwl (object2))

wl (object1)

Mass 1  Mass 2  Mass 3  Mass 4  Mass 5  Mass 6  Mass 7  Mass 8  Mass 9 Mass 10 Mass 11 Mass 12 Mass 13 Mass 14 Mass 15 Mass 16 Mass 17 Mass 18 Mass 19 
160.90  158.85  147.00  140.90  133.05  130.90  119.95  119.15  118.05  116.95  112.90  106.00  105.10   98.95   96.95   91.00   85.05   83.05   77.00 
Mass 20 Mass 21 Mass 22 Mass 23 Mass 24 Mass 25 Mass 26 Mass 27 Mass 28 Mass 29 Mass 30 Mass 31 Mass 32 Mass 33 Mass 34 Mass 35 Mass 36 Mass 37 
71.90   71.10   70.00   69.00   57.10   56.10   55.00   43.85   43.05   41.10   40.10   39.00   32.15   31.15   30.05   29.05   28.15   27.05 

wl (object2)

Mass 1  Mass 2  Mass 3  Mass 4  Mass 5  Mass 6  Mass 7  Mass 8  Mass 9 Mass 10 Mass 11 Mass 12 Mass 13 Mass 14 Mass 15 Mass 16 Mass 17 Mass 18 Mass 19 
160.90  158.85  147.00  140.90  133.05  130.90  119.95  119.15  118.05  116.95  112.90 106.00  105.10   98.95   96.95   91.00   85.05   83.05   77.00 
Mass 20 Mass 21 Mass 22 Mass 23 Mass 24 Mass 25 Mass 26 Mass 27 Mass 28 Mass 29 Mass 30 Mass 31 Mass 32 Mass 33 Mass 34 Mass 35 Mass 36 Mass 37 
71.90   71.10   70.00   69.00   57.10   56.10   55.00   43.85   43.05   41.10   40.10   39.00   32.15   31.15   30.05   29.05   28.15   27.05 

combining the objects via collapse:

combined <- collapse (object1, object2)
wl (combined)
[1] 160.90 158.85 147.00 140.90 133.05 130.90 119.95 119.15 118.05 116.95 112.90 106.00 105.10  98.95  96.95  91.00  85.05  83.05  77.00  71.90  71.10
[22]  70.00  69.00  57.10  56.10  55.00  43.85  43.05  41.10  40.10  39.00  32.15  31.15  30.05  29.05  28.15  27.05

As can be seen, the naming of the vector elements is gone.

These named vectors might also be useful while collapsing to identify wavelengths, which should be collapsed into one single wavelength in the new object.

Activity

  1. GegznaV commented on Apr 17, 2019

    @GegznaV
    Collaborator

    Some time ago I faced a similar issue.

  2. galaxismad commented on Jun 18, 2019

    @galaxismad
    Author

    Collapse also "destroys" the column names of the spectra matrix (in $spc).

    head (colnames (chondro$spc))
    [1] "602" "606" "610" "614" "618" "622"

    after collapsing, there are some weird numbers

    head(colnames(collapse (chondro, chondro)$spc))
    [1] "40399536128" "40667971584" "40936407040" "41204842496" "41473277952" "41741713408"

  3. cbeleites commented on Dec 17, 2019

    @cbeleites
    Owner

    I'm currently overhauling collapse to fix issues #81 and #69.

    I'm not sure how this issue could/should be sensibly tackled:


    First of all, note that for the provided example, rbind would do what is required.


    The purpose of collapse is to merge hyperSpec objects with differing wavelength vectors, including to "bin" wavelengths that are almost equal (numerically). This includes that even the resulting wavelengths may not be exactly equal to any of the wavelengths of the collapsed objects.

    Up to now, the resulting wavelengths are the centers of the wavelength bins indicated by wl.tolerance and the "destroyed" column names are the bin numbers. (Exact behaviour will change with the current overhauling, though.)

    The question how to preserve column names is not straightforward in such a general way. Consider:

    object1 <- barbiturates[[1]]
    object2 <- barbiturates[[2]]
    names (wl (object1)) <- paste ("Mass", 1:nwl (object1))
    names (wl (object2)) <- paste ("Mass", 1:nwl (object2))
    

    we have

    > wl (object1) %>% head
    Mass 1 Mass 2 Mass 3 Mass 4 Mass 5 Mass 6 
    160.90 158.85 147.00 140.90 133.05 130.90 
    > wl (object2) %>% head
    Mass 1 Mass 2 Mass 3 Mass 4 Mass 5 Mass 6 
    158.85 140.90 132.95 131.00 120.05 119.05 
    

    The same difficulties may happen with the column names of $spc.

    • The same wavelength is named Mass 2 in object1 but Mass 1 in object2; also object1 Mass 4 and object2 but Mass 2 are the same (and so on).
      How should the resulting wavelengths (and columns of $spc) be named?
    • Wavelengths of object1 Mass 3 and object2 Mass 3 are different, so will end up in different columns of the resulting spectra matrix.
      Shall the result have multiple wavelengths and columns in $spc with the same name?

    What would be relatively easy to implement is to take the names of @wavelength and the columns of $spc from the first object that has the respective wavelength.

  4. cbeleites commented on Dec 17, 2019

    @cbeleites
    Owner
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions