Skip to content

Commit

Permalink
Change Python plots and bump versions in CI (#139)
Browse files Browse the repository at this point in the history
* Change Python plots and added test

* bump version of coverage CI
  • Loading branch information
facusapienza21 authored Nov 13, 2024
1 parent 031fb79 commit 8c2d02e
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
- uses: julia-actions/julia-buildpkg@v1
- uses: julia-actions/julia-runtest@v1
- uses: julia-actions/julia-processcoverage@v1
- uses: codecov/codecov-action@v3
- uses: codecov/codecov-action@v4
with:
token: ${{secrets.CODECOV_TOKEN}}
files: lcov.info
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ scripts/plots/
# Core dump files
*.core

# CondaPkg
.CondaPkg

# Files generated by invoking Julia with --code-coverage
*.jl.cov
*.jl.*.cov
Expand Down
8 changes: 1 addition & 7 deletions src/SphereUDE.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,12 @@ include("losses.jl")
include("train.jl")
include("plot.jl")

# Python libraries
# const mpl_base::PyObject = isdefined(SphereUDE, :mpl_base) ? SphereUDE.mpl_base : PyNULL()
# const mpl_colors::PyObject = isdefined(SphereUDE, :mpl_colors) ? SphereUDE.mpl_colors : PyNULL()
# const mpl_colormap::PyObject = isdefined(SphereUDE, :mpl_colormap) ? SphereUDE.mpl_colormap : PyNULL()
# const sns::PyObject = isdefined(SphereUDE, :sns) ? SphereUDE.sns : PyNULL()
# const ccrs::PyObject = isdefined(SphereUDE, :ccrs) ? SphereUDE.ccrs : PyNULL()
# const feature::PyObject = isdefined(SphereUDE, :feature) ? SphereUDE.feature : PyNULL()

# We define empty objects for the Python packages
const mpl_base = Ref{Py}()
const mpl_colors = Ref{Py}()
const mpl_colormap = Ref{Py}()
const plt = Ref{Py}()
const sns = Ref{Py}()
const ccrs = Ref{Py}()
const feature = Ref{Py}()
Expand Down
34 changes: 17 additions & 17 deletions src/plot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ function plot_sphere(# ax::PyCall.PyObject,

# cmap = mpl_colormap.get_cmap("viridis")

plt.figure(figsize=(10,10))
ax = plt.axes(projection=ccrs.Orthographic(central_latitude=central_latitude, central_longitude=central_longitude))
plt[].figure(figsize=(10,10))
ax = plt[].axes(projection=ccrs[].Orthographic(central_latitude=central_latitude, central_longitude=central_longitude))

# Set default plot parameters.
# See https://matplotlib.org/stable/users/explain/customizing.html for customizable optionsz
if !isnothing(matplotlib_rcParams)
for (key, value) in matplotlib_rcParams
@warn "Setting Matplotlib parameters with rcParams currently not working. See following GitHub issue: https://github.com/JuliaPy/PyPlot.jl/issues/525"
mpl_base.rcParams[key] = value
mpl_base[].rcParams[key] = value
end
end

Expand All @@ -50,20 +50,20 @@ function plot_sphere(# ax::PyCall.PyObject,

# Plots in Python follow the long, lat ordering

sns.scatterplot(ax=ax, x = X_true_points[2,:], y=X_true_points[1, :],
hue = data.times, s=150,
palette="viridis",
transform = ccrs.PlateCarree());
sns[].scatterplot(ax=ax, x = X_true_points[2,:], y=X_true_points[1, :],
hue = data.times, s=150,
palette="viridis",
transform = ccrs[].PlateCarree());

for i in 1:(length(results.fit_times)-1)
plt.plot([X_fit_path[2,i], X_fit_path[2,i+1]],
[X_fit_path[1,i], X_fit_path[1,i+1]],
linewidth=2, color="black",#cmap(norm(results.fit_times[i])),
transform = ccrs.Geodetic())
plt[].plot([X_fit_path[2,i], X_fit_path[2,i+1]],
[X_fit_path[1,i], X_fit_path[1,i+1]],
linewidth=2, color="black",#cmap(norm(results.fit_times[i])),
transform = ccrs[].Geodetic())
end
# plt.title(title, fontsize=20)
if !isnothing(saveas)
plt.savefig(saveas, format="pdf")
plt[].savefig(saveas, format="pdf")
end

return nothing
Expand All @@ -78,7 +78,7 @@ function plot_L(data::AbstractData,
saveas::Union{String, Nothing},
title::String)

fig, ax = plt.subplots(figsize=(10,5))
fig, ax = plt[].subplots(figsize=(10,5))

times_smooth = collect(LinRange(results.fit_times[begin], results.fit_times[end], 1000))
Ls = reduce(hcat, (t -> results.U([t], results.θ, results.st)[1]).(times_smooth))
Expand All @@ -94,13 +94,13 @@ function plot_L(data::AbstractData,
end

# plt.title("")
plt.xlabel("Time")
plt.ylabel("Angular Velocity")
plt.legend()
plt[].xlabel("Time")
plt[].ylabel("Angular Velocity")
plt[].legend()
# plt.title(title)

if !isnothing(saveas)
plt.savefig(saveas, format="pdf")
plt[].savefig(saveas, format="pdf")
end

return nothing
Expand Down
3 changes: 2 additions & 1 deletion src/setup/config.jl
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
export mpl_base, mpl_colormap, mpl_colormap, sns, ccrs, feature
export mpl_base, mpl_colormap, mpl_colormap, plt, sns, ccrs, feature

function __init__()

try
isassigned(mpl_base) ? nothing : mpl_base[] = pyimport("matplotlib")
isassigned(mpl_colors) ? nothing : mpl_colors[] = pyimport("matplotlib.colors")
isassigned(mpl_colormap) ? nothing : mpl_colormap[] = pyimport("matplotlib.cm")
isassigned(plt) ? nothing : plt[] = pyimport("matplotlib.pyplot")
isassigned(sns) ? nothing : sns[] = pyimport("seaborn")
isassigned(ccrs) ? nothing : ccrs[] = pyimport("cartopy.crs")
isassigned(feature) ? nothing : feature[] = pyimport("cartopy.feature")
Expand Down
12 changes: 12 additions & 0 deletions test/python.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using SphereUDE

function test_matplotplib()
plt[].figure(figsize=(10,10))
ax = plt[].axes(projection=ccrs[].Orthographic(central_latitude=0.0, central_longitude=0.0))
@test true
end

function test_pmagpy()
pmag = SphereUDE.pyimport("pmagpy.pmag")
@test true
end
6 changes: 6 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ using Lux
include("constructors.jl")
include("utils.jl")
include("rotation.jl")
include("python.jl")

@testset "Constructors" begin
test_reg_constructor()
Expand All @@ -17,6 +18,11 @@ end
test_integration()
end

@testset "Python Integration" begin
test_matplotplib()
test_pmagpy()
end

@testset "Inversion" begin
test_single_rotation()
end

0 comments on commit 8c2d02e

Please sign in to comment.