From 3181fe480fa7b11a4c1a8d3af1c42797b3140983 Mon Sep 17 00:00:00 2001 From: mloubout Date: Fri, 25 Oct 2024 10:09:03 -0400 Subject: [PATCH] add build --- deps/build.jl | 16 ++++++++++++++++ src/SlimPlotting.jl | 38 ++++++++++++-------------------------- 2 files changed, 28 insertions(+), 26 deletions(-) create mode 100644 deps/build.jl diff --git a/deps/build.jl b/deps/build.jl new file mode 100644 index 0000000..d1499e4 --- /dev/null +++ b/deps/build.jl @@ -0,0 +1,16 @@ +using PythonPlot + +deps = ('colorcet', 'seiscm') + +function install_pkg(pkg) + if get(ENV, "JULIA_CONDAPKG_BACKEND", "conda") == "Null" + pyexe = PythonPlot.PythonCall.python_executable_path() + run(Cmd(`$(pyexe) -m pip install --user $(pkg)`)) + else + PythonPlot.PythonCall.C.CondaPkg.add_pip(pkg) + end +end + +for pkg in deps + install_pkg(pkg) +end \ No newline at end of file diff --git a/src/SlimPlotting.jl b/src/SlimPlotting.jl index 017533e..e538be6 100644 --- a/src/SlimPlotting.jl +++ b/src/SlimPlotting.jl @@ -4,34 +4,20 @@ using Statistics, ColorSchemes, Reexport @reexport using PythonPlot const cc = PythonPlot.PythonCall.pynew() -scm = Dict() - - -function tryimport(pkg::String) - pyi = try - PythonPlot.pyimport(pkg) - catch e - if get(ENV, "JULIA_CONDAPKG_BACKEND", "conda") == "Null" - pyexe = PythonPlot.python_executable_path() - run(Cmd(`$(pyexe) -m pip install --user $(pkg)`)) - else - PythonPlot.PythonCall.C.CondaPkg.add_pip(pkg) - end - PythonPlot.pyimport(pkg) - end - return pyi -end +const scm = PythonPlot.PythonCall.pynew() +scmp = Dict( + "seismic" => scm.seismic, + "bwr" => scm.bwr, + "phase" => scm.phase, + "frequency" => scm.frequency, +) function __init__() - # import seiscm - scmp = tryimport("seiscm") - global scm["seismic"] = scmp.seismic() - global scm["bwr"] = scmp.bwr() - global scm["phase"] = scmp.phase() - global scm["frequency"] = scmp.frequency() # Import colorcet - PythonPlot.PythonCall.pycopy!(cc, tryimport("colorcet")) + PythonPlot.PythonCall.pycopy!(cc, pyimport("colorcet")) + # Import SeisCM + PythonPlot.PythonCall.pycopy!(scm, pyimport("seiscm")) end export plot_fslice, plot_velocity, plot_simage, plot_sdata, wiggle_plot, compare_shots @@ -49,8 +35,8 @@ to_symbol(x) = x Return the colormap `name` for seiscm. These colormap are preimported as a dictionnary """ -seiscm(s::Symbol) = scm[to_string(s)] -seiscm(s::String) = scm[s] +seiscm(s::Symbol) = scmp[to_string(s)]() +seiscm(s::String) = scmp[s]() """ _plot_with_units(image, spacing; perc=95, cmap=:cet_CET_L1,