sefffal / Octofitter.jl

Octofitter is a Julia package for performing Bayesian inference against direct images of exoplanets, relative astrometry, and astrometric acceleration of the host star.
https://sefffal.github.io/Octofitter.jl/dev
MIT License
32 stars 2 forks source link

Not able to set intrument names while using Octofitterpy #46

Open Bhavesh012 opened 2 weeks ago

Bhavesh012 commented 2 weeks ago

While defining the StarAbsoluteRVLikelihood through Octofitterpy, if we pass values for instrument names, like:

rv_star_like = octo.StarAbsoluteRVLikelihood(
    epoch=rv_data_df['epoch'],
    rv=rv_data_df['rv'],
    σ_rv=rv_data_df['σ_rv'],
    inst_idx=rv_data_df['inst_idx'],
    instrument_names=[ "HARPS03", "HARPS15", "HARPS20", "PFS"],
)

then, I get the issue:

{
    "name": "JuliaError",
    "message": "UndefRefError: access to undefined reference
Stacktrace:
  [1] getindex
    @ ./essentials.jl:13 [inlined]
  [2] #29
    @ ./none:0 [inlined]
  [3] iterate
    @ ./generator.jl:47 [inlined]
  [4] _totuple
    @ ./tuple.jl:402 [inlined]
  [5] _totuple (repeats 2 times)
    @ ./tuple.jl:409 [inlined]
  [6] Tuple
    @ ./tuple.jl:391 [inlined]
  [7] NamedTuple
    @ ./namedtuple.jl:148 [inlined]
  [8] getindex
    @ ~/.julia/packages/TypedTables/ItVth/src/Table.jl:129 [inlined]
  [9] getindex
    @ ./reshapedarray.jl:246 [inlined]
 [10] getindex
    @ ./subarray.jl:317 [inlined]
 [11] (::OctofitterRadialVelocity.var\"#2#6\")(row′::SubArray{@NamedTuple{inst_idx::Int64, rv::Float64, instrument_names::String, σ_rv::Float64, epoch::Float64}, 1, Base.ReshapedArray{@NamedTuple{inst_idx::Int64, rv::Float64, instrument_names::String, σ_rv::Float64, epoch::Float64}, 2, Table{@NamedTuple{inst_idx::Int64, rv::Float64, instrument_names::String, σ_rv::Float64, epoch::Float64}, 1, @NamedTuple{inst_idx::Vector{Int64}, rv::Vector{Float64}, instrument_names::Vector{String}, σ_rv::Vector{Float64}, epoch::Vector{Float64}}}, Tuple{}}, Tuple{Int64, Base.Slice{Base.OneTo{Int64}}}, true})
    @ OctofitterRadialVelocity ~/.julia/packages/OctofitterRadialVelocity/7kYZf/src/rv-absolute.jl:31
 [12] iterate
    @ ./generator.jl:47 [inlined]
 [13] collect_to!(dest::Vector{@NamedTuple{inst_idx::Int64, rv::Float64, instrument_names::String, σ_rv::Float64, epoch::Float64}}, itr::Base.Generator{RowSlices{Base.ReshapedArray{@NamedTuple{inst_idx::Int64, rv::Float64, instrument_names::String, σ_rv::Float64, epoch::Float64}, 2, Table{@NamedTuple{inst_idx::Int64, rv::Float64, instrument_names::String, σ_rv::Float64, epoch::Float64}, 1, @NamedTuple{inst_idx::Vector{Int64}, rv::Vector{Float64}, instrument_names::Vector{String}, σ_rv::Vector{Float64}, epoch::Vector{Float64}}}, Tuple{}}, Tuple{Base.OneTo{Int64}}, SubArray{@NamedTuple{inst_idx::Int64, rv::Float64, instrument_names::String, σ_rv::Float64, epoch::Float64}, 1, Base.ReshapedArray{@NamedTuple{inst_idx::Int64, rv::Float64, instrument_names::String, σ_rv::Float64, epoch::Float64}, 2, Table{@NamedTuple{inst_idx::Int64, rv::Float64, instrument_names::String, σ_rv::Float64, epoch::Float64}, 1, @NamedTuple{inst_idx::Vector{Int64}, rv::Vector{Float64}, instrument_names::Vector{String}, σ_rv::Vector{Float64}, epoch::Vector{Float64}}}, Tuple{}}, Tuple{Int64, Base.Slice{Base.OneTo{Int64}}}, true}}, OctofitterRadialVelocity.var\"#2#6\"}, offs::Int64, st::Tuple{Base.OneTo{Int64}, Int64})
    @ Base ./array.jl:892
 [14] collect_to_with_first!
    @ ./array.jl:870 [inlined]
 [15] _collect(c::RowSlices{Base.ReshapedArray{@NamedTuple{inst_idx::Int64, rv::Float64, instrument_names::String, σ_rv::Float64, epoch::Float64}, 2, Table{@NamedTuple{inst_idx::Int64, rv::Float64, instrument_names::String, σ_rv::Float64, epoch::Float64}, 1, @NamedTuple{inst_idx::Vector{Int64}, rv::Vector{Float64}, instrument_names::Vector{String}, σ_rv::Vector{Float64}, epoch::Vector{Float64}}}, Tuple{}}, Tuple{Base.OneTo{Int64}}, SubArray{@NamedTuple{inst_idx::Int64, rv::Float64, instrument_names::String, σ_rv::Float64, epoch::Float64}, 1, Base.ReshapedArray{@NamedTuple{inst_idx::Int64, rv::Float64, instrument_names::String, σ_rv::Float64, epoch::Float64}, 2, Table{@NamedTuple{inst_idx::Int64, rv::Float64, instrument_names::String, σ_rv::Float64, epoch::Float64}, 1, @NamedTuple{inst_idx::Vector{Int64}, rv::Vector{Float64}, instrument_names::Vector{String}, σ_rv::Vector{Float64}, epoch::Vector{Float64}}}, Tuple{}}, Tuple{Int64, Base.Slice{Base.OneTo{Int64}}}, true}}, itr::Base.Generator{RowSlices{Base.ReshapedArray{@NamedTuple{inst_idx::Int64, rv::Float64, instrument_names::String, σ_rv::Float64, epoch::Float64}, 2, Table{@NamedTuple{inst_idx::Int64, rv::Float64, instrument_names::String, σ_rv::Float64, epoch::Float64}, 1, @NamedTuple{inst_idx::Vector{Int64}, rv::Vector{Float64}, instrument_names::Vector{String}, σ_rv::Vector{Float64}, epoch::Vector{Float64}}}, Tuple{}}, Tuple{Base.OneTo{Int64}}, SubArray{@NamedTuple{inst_idx::Int64, rv::Float64, instrument_names::String, σ_rv::Float64, epoch::Float64}, 1, Base.ReshapedArray{@NamedTuple{inst_idx::Int64, rv::Float64, instrument_names::String, σ_rv::Float64, epoch::Float64}, 2, Table{@NamedTuple{inst_idx::Int64, rv::Float64, instrument_names::String, σ_rv::Float64, epoch::Float64}, 1, @NamedTuple{inst_idx::Vector{Int64}, rv::Vector{Float64}, instrument_names::Vector{String}, σ_rv::Vector{Float64}, epoch::Vector{Float64}}}, Tuple{}}, Tuple{Int64, Base.Slice{Base.OneTo{Int64}}}, true}}, OctofitterRadialVelocity.var\"#2#6\"}, ::Base.EltypeUnknown, isz::Base.HasShape{1})
    @ Base ./array.jl:864
 [16] collect_similar
    @ ./array.jl:763 [inlined]
 [17] map
    @ ./abstractarray.jl:3285 [inlined]
 [18] StarAbsoluteRVLikelihood(observations::Table{@NamedTuple{inst_idx::Int64, rv::Float64, instrument_names::String, σ_rv::Float64, epoch::Float64}, 1, @NamedTuple{inst_idx::Vector{Int64}, rv::Vector{Float64}, instrument_names::Vector{String}, σ_rv::Vector{Float64}, epoch::Vector{Float64}}}; instrument_names::Nothing, gaussian_process::Nothing)
    @ OctofitterRadialVelocity ~/.julia/packages/OctofitterRadialVelocity/7kYZf/src/rv-absolute.jl:30
 [19] StarAbsoluteRVLikelihood(observations::Table{@NamedTuple{inst_idx::Int64, rv::Float64, instrument_names::String, σ_rv::Float64, epoch::Float64}, 1, @NamedTuple{inst_idx::Vector{Int64}, rv::Vector{Float64}, instrument_names::Vector{String}, σ_rv::Vector{Float64}, epoch::Vector{Float64}}})
    @ OctofitterRadialVelocity ~/.julia/packages/OctofitterRadialVelocity/7kYZf/src/rv-absolute.jl:25
 [20] pyjlany_call(self::Type{StarAbsoluteRVLikelihood}, args_::Py, kwargs_::Py)
    @ PythonCall.JlWrap ~/.julia/packages/PythonCall/Nr75f/src/JlWrap/any.jl:43
 [21] _pyjl_callmethod(f::Any, self_::Ptr{PythonCall.C.PyObject}, args_::Ptr{PythonCall.C.PyObject}, nargs::Int64)
    @ PythonCall.JlWrap ~/.julia/packages/PythonCall/Nr75f/src/JlWrap/base.jl:73
 [22] _pyjl_callmethod(o::Ptr{PythonCall.C.PyObject}, args::Ptr{PythonCall.C.PyObject})
    @ PythonCall.JlWrap.Cjl ~/.julia/packages/PythonCall/Nr75f/src/JlWrap/C.jl:63",
    "stack": "---------------------------------------------------------------------------
JuliaError                                Traceback (most recent call last)
Cell In[15], line 36
     32 )
     33 planet_c
---> 36 rv_star_like = octo.StarAbsoluteRVLikelihood(
     37     epoch=rv_data_df['epoch'],
     38     rv=rv_data_df['rv'],
     39     σ_rv=rv_data_df['σ_rv'],
     40     inst_idx=rv_data_df['inst_idx'],
     41     instrument_names=[ \"HARPS03\", \"HARPS15\", \"HARPS20\", \"PFS\"],
     42 )
     44 
     45 # The name of your system determines the output file names

File ~/opt/anaconda3/envs/exo_orbit/lib/python3.10/site-packages/octofitterpy/python_interface.py:90, in StarAbsoluteRVLikelihood(**data)
     88 for k,v in data.items():
     89     data[k] = jl_array(v)
---> 90 return jl.OctofitterRadialVelocity.StarAbsoluteRVLikelihood(Octofitter.Table(**data))

File ~/.julia/packages/PythonCall/Nr75f/src/JlWrap/any.jl:258, in __call__(self, *args, **kwargs)
    256     return ValueBase.__dir__(self) + self._jl_callmethod($(pyjl_methodnum(pyjlany_dir)))
    257 def __call__(self, *args, **kwargs):
--> 258     return self._jl_callmethod($(pyjl_methodnum(pyjlany_call)), args, kwargs)
    259 def __bool__(self):
    260     return True

JuliaError: UndefRefError: access to undefined reference
Stacktrace:
  [1] getindex
    @ ./essentials.jl:13 [inlined]
  [2] #29
    @ ./none:0 [inlined]
  [3] iterate
    @ ./generator.jl:47 [inlined]
  [4] _totuple
    @ ./tuple.jl:402 [inlined]
  [5] _totuple (repeats 2 times)
    @ ./tuple.jl:409 [inlined]
  [6] Tuple
    @ ./tuple.jl:391 [inlined]
  [7] NamedTuple
    @ ./namedtuple.jl:148 [inlined]
  [8] getindex
    @ ~/.julia/packages/TypedTables/ItVth/src/Table.jl:129 [inlined]
  [9] getindex
    @ ./reshapedarray.jl:246 [inlined]
 [10] getindex
    @ ./subarray.jl:317 [inlined]
 [11] (::OctofitterRadialVelocity.var\"#2#6\")(row′::SubArray{@NamedTuple{inst_idx::Int64, rv::Float64, instrument_names::String, σ_rv::Float64, epoch::Float64}, 1, Base.ReshapedArray{@NamedTuple{inst_idx::Int64, rv::Float64, instrument_names::String, σ_rv::Float64, epoch::Float64}, 2, Table{@NamedTuple{inst_idx::Int64, rv::Float64, instrument_names::String, σ_rv::Float64, epoch::Float64}, 1, @NamedTuple{inst_idx::Vector{Int64}, rv::Vector{Float64}, instrument_names::Vector{String}, σ_rv::Vector{Float64}, epoch::Vector{Float64}}}, Tuple{}}, Tuple{Int64, Base.Slice{Base.OneTo{Int64}}}, true})
    @ OctofitterRadialVelocity ~/.julia/packages/OctofitterRadialVelocity/7kYZf/src/rv-absolute.jl:31
 [12] iterate
    @ ./generator.jl:47 [inlined]
 [13] collect_to!(dest::Vector{@NamedTuple{inst_idx::Int64, rv::Float64, instrument_names::String, σ_rv::Float64, epoch::Float64}}, itr::Base.Generator{RowSlices{Base.ReshapedArray{@NamedTuple{inst_idx::Int64, rv::Float64, instrument_names::String, σ_rv::Float64, epoch::Float64}, 2, Table{@NamedTuple{inst_idx::Int64, rv::Float64, instrument_names::String, σ_rv::Float64, epoch::Float64}, 1, @NamedTuple{inst_idx::Vector{Int64}, rv::Vector{Float64}, instrument_names::Vector{String}, σ_rv::Vector{Float64}, epoch::Vector{Float64}}}, Tuple{}}, Tuple{Base.OneTo{Int64}}, SubArray{@NamedTuple{inst_idx::Int64, rv::Float64, instrument_names::String, σ_rv::Float64, epoch::Float64}, 1, Base.ReshapedArray{@NamedTuple{inst_idx::Int64, rv::Float64, instrument_names::String, σ_rv::Float64, epoch::Float64}, 2, Table{@NamedTuple{inst_idx::Int64, rv::Float64, instrument_names::String, σ_rv::Float64, epoch::Float64}, 1, @NamedTuple{inst_idx::Vector{Int64}, rv::Vector{Float64}, instrument_names::Vector{String}, σ_rv::Vector{Float64}, epoch::Vector{Float64}}}, Tuple{}}, Tuple{Int64, Base.Slice{Base.OneTo{Int64}}}, true}}, OctofitterRadialVelocity.var\"#2#6\"}, offs::Int64, st::Tuple{Base.OneTo{Int64}, Int64})
    @ Base ./array.jl:892
 [14] collect_to_with_first!
    @ ./array.jl:870 [inlined]
 [15] _collect(c::RowSlices{Base.ReshapedArray{@NamedTuple{inst_idx::Int64, rv::Float64, instrument_names::String, σ_rv::Float64, epoch::Float64}, 2, Table{@NamedTuple{inst_idx::Int64, rv::Float64, instrument_names::String, σ_rv::Float64, epoch::Float64}, 1, @NamedTuple{inst_idx::Vector{Int64}, rv::Vector{Float64}, instrument_names::Vector{String}, σ_rv::Vector{Float64}, epoch::Vector{Float64}}}, Tuple{}}, Tuple{Base.OneTo{Int64}}, SubArray{@NamedTuple{inst_idx::Int64, rv::Float64, instrument_names::String, σ_rv::Float64, epoch::Float64}, 1, Base.ReshapedArray{@NamedTuple{inst_idx::Int64, rv::Float64, instrument_names::String, σ_rv::Float64, epoch::Float64}, 2, Table{@NamedTuple{inst_idx::Int64, rv::Float64, instrument_names::String, σ_rv::Float64, epoch::Float64}, 1, @NamedTuple{inst_idx::Vector{Int64}, rv::Vector{Float64}, instrument_names::Vector{String}, σ_rv::Vector{Float64}, epoch::Vector{Float64}}}, Tuple{}}, Tuple{Int64, Base.Slice{Base.OneTo{Int64}}}, true}}, itr::Base.Generator{RowSlices{Base.ReshapedArray{@NamedTuple{inst_idx::Int64, rv::Float64, instrument_names::String, σ_rv::Float64, epoch::Float64}, 2, Table{@NamedTuple{inst_idx::Int64, rv::Float64, instrument_names::String, σ_rv::Float64, epoch::Float64}, 1, @NamedTuple{inst_idx::Vector{Int64}, rv::Vector{Float64}, instrument_names::Vector{String}, σ_rv::Vector{Float64}, epoch::Vector{Float64}}}, Tuple{}}, Tuple{Base.OneTo{Int64}}, SubArray{@NamedTuple{inst_idx::Int64, rv::Float64, instrument_names::String, σ_rv::Float64, epoch::Float64}, 1, Base.ReshapedArray{@NamedTuple{inst_idx::Int64, rv::Float64, instrument_names::String, σ_rv::Float64, epoch::Float64}, 2, Table{@NamedTuple{inst_idx::Int64, rv::Float64, instrument_names::String, σ_rv::Float64, epoch::Float64}, 1, @NamedTuple{inst_idx::Vector{Int64}, rv::Vector{Float64}, instrument_names::Vector{String}, σ_rv::Vector{Float64}, epoch::Vector{Float64}}}, Tuple{}}, Tuple{Int64, Base.Slice{Base.OneTo{Int64}}}, true}}, OctofitterRadialVelocity.var\"#2#6\"}, ::Base.EltypeUnknown, isz::Base.HasShape{1})
    @ Base ./array.jl:864
 [16] collect_similar
    @ ./array.jl:763 [inlined]
 [17] map
    @ ./abstractarray.jl:3285 [inlined]
 [18] StarAbsoluteRVLikelihood(observations::Table{@NamedTuple{inst_idx::Int64, rv::Float64, instrument_names::String, σ_rv::Float64, epoch::Float64}, 1, @NamedTuple{inst_idx::Vector{Int64}, rv::Vector{Float64}, instrument_names::Vector{String}, σ_rv::Vector{Float64}, epoch::Vector{Float64}}}; instrument_names::Nothing, gaussian_process::Nothing)
    @ OctofitterRadialVelocity ~/.julia/packages/OctofitterRadialVelocity/7kYZf/src/rv-absolute.jl:30
 [19] StarAbsoluteRVLikelihood(observations::Table{@NamedTuple{inst_idx::Int64, rv::Float64, instrument_names::String, σ_rv::Float64, epoch::Float64}, 1, @NamedTuple{inst_idx::Vector{Int64}, rv::Vector{Float64}, instrument_names::Vector{String}, σ_rv::Vector{Float64}, epoch::Vector{Float64}}})
    @ OctofitterRadialVelocity ~/.julia/packages/OctofitterRadialVelocity/7kYZf/src/rv-absolute.jl:25
 [20] pyjlany_call(self::Type{StarAbsoluteRVLikelihood}, args_::Py, kwargs_::Py)
    @ PythonCall.JlWrap ~/.julia/packages/PythonCall/Nr75f/src/JlWrap/any.jl:43
 [21] _pyjl_callmethod(f::Any, self_::Ptr{PythonCall.C.PyObject}, args_::Ptr{PythonCall.C.PyObject}, nargs::Int64)
    @ PythonCall.JlWrap ~/.julia/packages/PythonCall/Nr75f/src/JlWrap/base.jl:73
 [22] _pyjl_callmethod(o::Ptr{PythonCall.C.PyObject}, args::Ptr{PythonCall.C.PyObject})
    @ PythonCall.JlWrap.Cjl ~/.julia/packages/PythonCall/Nr75f/src/JlWrap/C.jl:63"
}

This does not come up if I run the same version in Julia on Pluto. Also, if I comment out the instrument_name argument, it goes away.

sefffal commented 1 week ago

Thanks for the report @Bhavesh012 ! I appreciate you taking the time to help with these octofitterpy bugs.

My first guess is a problem converting the list of strings from python to Julia.

sefffal commented 1 week ago

I think this commit to octofitterpy should have resolved it: https://github.com/sefffal/octofitterpy/commit/7ecfa4c41b8a396a57255956d86c1836cb048e6a

Would you be able to test if it fixes your issue? If so I will tag a new release.

Thanks again!

PS: that example notebook also includes a section about Gaussian processes. Unfortunately I don't plan to support gaussian processes in octofitterpy.