Catching warning and assign missing values instead?

Hello, I get the following warning for some of my calculations.

┌ Warning: The maximum likelihood algorithm did not find a solution. Maybe try with different initial values or with another method. The returned values are the initial values.
└ @ Extremes ~/.julia/packages/Extremes/4Tbee/src/parameterestimation/maximumlikelihood.jl:20

I’d like to be able to catch this warning and instead of keeping the initial values provided by the library, I would like to assign a missing, so that we I continue other calculations, I do not get artifact down the line.

I have found this thread: Catch warnings - #2 by pjgorski but it seems not very elegant and I am wondering if there is a better solution?

That’s not a generic warning from Julia but comes from the package Extremes.jl. In order to learn how to handle this situation, I suggest you read its documentation

If need more help, then you should describe what you are doing in more detail. Like how are you using that package? What functions do you call?

1 Like

Ok, I’ll take a closer look. I thought that catching warning was more a general approach.

I am mostly trying to fit Generalized Pareto to thousands of timeseries (climate models). Threshold selection is harder for some grid point, hence the warnings for some of those time series. My aim is to use the warning and assign a “missing” instead of the fitted parameters that failed.

Thanks!

Don’t know the package, but the warning says
The returned values are the initial values.
Thus, instead of catching the warning, I would just check that condition instead and handle it, e.g., assign missing.

The initial values might be genuine solutions to the problem (perhaps unlikely, but not impossible – but hard to say without more details).

Maybe this code snippet will help with getting rid of log message:

julia> Base.CoreLogging.with_logger(Base.CoreLogging.NullLogger()) do
       @warn "hello"
       end

julia> 

But it’s also prudent not to turn off logging and getting into Base.CoreLogging isn’t necessarily an exposed API.