Skip to content

Implement usage of numeric vectors as input for wl.eval() #287

Closed

Description

@galaxismad

Up to now, wl.eval expects as input already an hyperSpec object, using its wavelength axis to apply a function given in expression to it resulting in an hyperSpec object with the same wavelength axis as in the original hyperSpec object and values in spc column derived from applied function results.

Another intended use may be, that there is no initial hyperSpec object available, where the wavelength axis can be derived from (e.g. simulation of spectra from scratch). Here, it would be benefical to be able to use a numeric vector of wavelengths as input instead of a full hyperSpec object. The returned structure should be the same as now being a hyperSpec object, but now using the supplied numeric vector as wavelength slot for the newly generated hyperSpec object.

Activity

  1. added
    Type: enhancement 🎈
    on Dec 18, 2020
  2. GegznaV commented on Dec 21, 2020

    @GegznaV
    Collaborator

    @galaxismad again I would ask you to provide a minimal example of code on how the function works now and the way you would like it to work. The results of the two examples should coincide so that we could use them as a reference.

  3. galaxismad commented on Dec 21, 2020

    @galaxismad
    Author

    The functions works now as follows:

    wl.eval(laser, exp = function(x) exp(-x))

    hyperSpec object
    1 spectra
    3 data columns
    36 data points / spectrum
    wavelength: lambda/nm [numeric] 404.5828 404.6181 ... 405.8176
    data: (1 rows x 3 columns)

    1. spc: I / a.u. [matrix36] 1.958541e-176 1.890618e-176 ... 5.69705e-177
    2. filename: filename [character] 1
    3. .f: .f [character] exp

    What I like to have is something like:

    axis <- wl(laser)
    wl.eval(axis, exp = function(x) exp(-x))

    hyperSpec object
    1 spectra
    2 data columns
    36 data points / spectrum
    wavelength: lambda/nm [numeric] 404.5828 404.6181 ... 405.8176
    data: (1 rows x 3 columns)

    1. spc: I / a.u. [matrix36] 1.958541e-176 1.890618e-176 ... 5.69705e-177
    2. .f: .f [character] exp

    So basically, it will not be dependend on a hyperSpec object as input, but also excepts an numeric vector, which than is used as wavelength instead of extracting the wavelength from a hyperSpec object internally. This results in a slightly different hyperSpec object as output, as the new hyperSpec object does not know any columns except for spc and .f (the named function call, as before).

  4. GegznaV commented on Dec 21, 2020

    @GegznaV
    Collaborator

    Another intended use may be, that there is no initial hyperSpec object available, ...

    As I understand, the following code can do what @galaxismad expects:

    axis <- wl(laser)
    new("hyperSpec", spc = exp(-axis), wavelength = axis)

    Should we enhance wl.eval() to have this functionality, @cbeleites?

  5. cbeleites commented on Dec 21, 2020

    @cbeleites
    Owner

    Yes @GegznaV, I think this would be a good functionality to have. And as you say, it isn't difficult to implement.

  6. GegznaV commented on Dec 22, 2020

    @GegznaV
    Collaborator

    Please, check my implementation in #295

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

    Type: enhancement 🎈

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions