Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom Struct as outtype in OutDims? #478

Open
Balinus opened this issue Nov 29, 2024 · 2 comments
Open

Custom Struct as outtype in OutDims? #478

Balinus opened this issue Nov 29, 2024 · 2 comments

Comments

@Balinus
Copy link
Contributor

Balinus commented Nov 29, 2024

Hello,

I am trying to do GEV estimation using mapCube, using the following logic. The objective is to get the timeseries for each gridpoints and return the GEV model associated with the timeserie, for each gridpoint, storing the following information into a YAXArray:

MaximumLikelihoodAbstractExtremeValueModel
model :
        ThresholdExceedance
        data :          Vector{Float64}[28]
        logscale :      ϕ ~ 1
        shape :         ξ ~ 1

θ̂  :    [2.0154230098844907, 0.09042541506171095]

Hence, when I try the following:

indims = InDims("Ti")
outdims = OutDims(outtype=MaximumLikelihoodAbstractExtremeValueModel)

I get the error:

ERROR: MethodError: Cannot `convert` an object of type
  Type{MaximumLikelihoodAbstractExtremeValueModel} to an object of type
  Union{Int64, DataType}

Closest candidates are:
  convert(::Type{T}, ::T) where T
   @ Base Base.jl:84

Stacktrace:
 [1] OutDims(axisdesc::Tuple{}, backend::Symbol, backendargs::@Kwargs{}, update::Bool, artype::Type, chunksize::Symbol, outtype::Type)
   @ YAXArrays.DAT ~/.julia/packages/YAXArrays/ppMtD/src/DAT/registration.jl:102
 [2] OutDims(; backend::Symbol, update::Bool, artype::Type, chunksize::Symbol, outtype::Type, backendargs::@Kwargs{})
   @ YAXArrays.DAT ~/.julia/packages/YAXArrays/ppMtD/src/DAT/registration.jl:134
 [3] top-level scope
   @ REPL[64]:1

It seems to be possible to assign a custom type to outtype, but I am unsure why it fails for MaximumLikelihoodAbstractExtremeValueModel:

struct foo
    a
end

outdims = OutDims(outtype=foo)
OutDims((), :auto, Base.Pairs{Symbol, Union{}, Tuple{}, @NamedTuple{}}(), false, Array, :input, foo)

Thanks for any intput!

@felixcremer
Copy link
Member

The problem is, that your type is a parametric type. And then its type is not DateType but UnionAll. You would have to fix all parameters in the type to use it as outtype. The easiest would be to construct an example value of the type you want to use and call typeof on it to select the exact type that could be used.

We might want to loosen the restriction on the field in OutDims so that this would work without that pre step.

@Balinus
Copy link
Contributor Author

Balinus commented Dec 2, 2024

ok! I'm gonna try to do that. Cheers!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants