Skip to content

Function peakmes error: UndefVarError: flipdim not defined in Spectra #24

@Matheus-gif

Description

@Matheus-gif

It's a simple detail really. If you input reversed data (e.g. XPS binding energies data) to the function peakmes it yields the following error

UndefVarError: `flipdim` not defined in `Spectra`
Suggestion: check for spelling errors or missing imports.

Stacktrace:
 [1] peakmeas(x::Vector{Float64}, y::Vector{Float64}; smoothing::String, method::String, window_length::Int64, polyorder::Int64, ese_y::Float64, y_smo_out::Bool)
   @ Spectra C:\Users\User\.julia\packages\Spectra\gifVq\src\peakmeasurement.jl:63
 [2] top-level scope
   @ c:\Users\User\Desktop\tratar_dados\codigos_julia\doutorado\dems\jl_notebook_cell_df34fa98e69747e1a8f8a730347b8e2f_X53sZmlsZQ==.jl:1

Not sure if it's worth mentioning, I've replaced flipdims with reversed and it works like a charm:

function peakmeas_custom(x::Array{Float64,1}, y::Array{Float64,1}; smoothing = "yes", method = "savgol", window_length=5, polyorder=2, ese_y=1., y_smo_out=false)
    ### PRELIMINARY CHECK: INCREASING SIGNAL
    if x[end,1] < x[1,1]
        x = reverse(x) #flipdim(x,1)
        y = reverse(y) #flipdim(y,1)
    end

	if smoothing == "yes"
    	y_smo = vec(smooth(x,y,method = method, window_length=window_length, polyorder=polyorder))
	else
		y_smo = collect(y)
	end

    x_maximum = x[y_smo .== maximum(y_smo)]

	if size(x_maximum,1) >= 2
		error("Something went wrong, is there two peaks with identical intensities in the signal? This function treats signal with one main peak...")
	end

    x_1 = x[x .<x_maximum];
	x_2 = x[x .>=x_maximum];
    y_first_portion = y_smo[x .<x_maximum];
	y_second_portion = y_smo[x .>=x_maximum];

    half_int = maximum(y_smo)/2
    idx_1 = findmin(abs.(y_first_portion.-half_int))
    idx_2 = findmin(abs.(y_second_portion.-half_int))

    hwhm = (x_2[idx_2[2]].-x_1[idx_1[2]])./2
    position = x_maximum[1]
    intensity = maximum(y_smo)
    centroid = sum(y_smo./sum(y_smo).*x)

    if y_smo_out == true
      return intensity, position, hwhm, centroid, y_smo
    elseif y_smo_out ==false
      return intensity, position, hwhm, centroid
    else
      error("Set y_smo_out to true or false.")
    end

end

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions