Skip to content

Commit 408bc6c

Browse files
authored
fix: use global data_quants to handle both old and new pyspedas versions (#8)
1 parent 8caae10 commit 408bc6c

File tree

4 files changed

+12
-2
lines changed

4 files changed

+12
-2
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
Manifest.toml
22
.CondaPkg
3-
themis_data/thd/l2/fgm/2020/thd_l2_fgm_20200420_v01.cdf
3+
themis_data
44
omni_data

CondaPkg.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
1+
[deps]
2+
NetCDF4 = ""
3+
14
[pip.deps]
25
pyspedas = "@git+https://github.com/spedas/pyspedas"

src/PySPEDAS.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,17 @@ const TnamesType = Union{AbstractArray, Tuple}
2323

2424
const pyspedas = pynew()
2525
const pyns = pynew()
26+
const data_quants = pynew()
2627

2728
function __init__()
2829
PythonCall.pycopy!(pyspedas, pyimport("pyspedas"))
2930
PythonCall.pycopy!(pyns, pyimport("numpy").timedelta64(1, "ns"))
31+
try
32+
PythonCall.pycopy!(data_quants, pyimport("pyspedas.tplot_tools").data_quants)
33+
catch
34+
# for older versions
35+
PythonCall.pycopy!(data_quants, pyimport("pytplot").data_quants)
36+
end
3037
return
3138
end
3239

src/types.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ struct TplotVariable{T, N} <: AbstractDataVariable{T, N}
2222
end
2323

2424
function TplotVariable(name)
25-
py = @pyconst(pyimport("pytplot").data_quants)[String(name)]
25+
py = data_quants[String(name)]
2626
data = PyArray(py.data; copy = false)
2727
return TplotVariable(Symbol(name), data, py)
2828
end

0 commit comments

Comments
 (0)