Skip to content

Commit

Permalink
Updates for latest version of Meshes.jl
Browse files Browse the repository at this point in the history
  • Loading branch information
juliohm committed May 23, 2024
1 parent 64012b2 commit d254609
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 22 deletions.
8 changes: 5 additions & 3 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
name = "GslibIO"
uuid = "4610876b-9b01-57c8-9ad9-06315f1a66a5"
author = "Júlio Hoffimann <julio.hoffimann@gmail.com>"
version = "1.4.11"
version = "1.5.0"

[deps]
DelimitedFiles = "8bb1440f-4735-579b-a4ab-409b98df4dab"
GeoTables = "e502b557-6362-48c1-8219-d30d308dcdb0"
Meshes = "eacbb407-ea5a-433e-ab97-5258b1ca43fa"
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"
Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d"

[compat]
DelimitedFiles = "1.9"
GeoTables = "1.19"
Meshes = "0.42"
GeoTables = "1.21"
Meshes = "0.43"
Tables = "1.10"
Unitful = "1.20"
julia = "1.9"
4 changes: 3 additions & 1 deletion src/GslibIO.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
module GslibIO

using Meshes
using Tables
using GeoTables

using Tables
using Unitful

using Printf
using DelimitedFiles

Expand Down
6 changes: 3 additions & 3 deletions src/extended.jl
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ function save(file::AbstractString, table, domain::Domain; pointvars=nothing, he

nvars = isnothing(vars) ? length(pvars) : length(pvars) + length(vars)

pdata = mapreduce(g -> coordinates(centroid(g)), hcat, domain) |> transpose
pdata = mapreduce(g -> ustrip.(to(centroid(g))), hcat, domain) |> transpose
data = if isnothing(table)
pdata
else
Expand Down Expand Up @@ -192,8 +192,8 @@ function save(file::AbstractString, table, grid::CartesianGrid; header=HEADER, k
write(io, "$header\n")
write(io, "grid\n")
write(io, join(size(grid), " ") * "\n")
write(io, join(coordinates(minimum(grid)), " ") * "\n")
write(io, join(spacing(grid), " ") * "\n")
write(io, join(ustrip.(to(minimum(grid))), " ") * "\n")
write(io, join(ustrip.(spacing(grid)), " ") * "\n")
write(io, "$nvars\n")
if !isnothing(vars)
for var in vars
Expand Down
6 changes: 3 additions & 3 deletions src/legacy.jl
Original file line number Diff line number Diff line change
Expand Up @@ -120,16 +120,16 @@ function save_legacy(
throw(ArgumentError("the length of coordinate names must be equal to the coordinate dimension"))
end
varnames = [coordnames...; propertynames(tab)...]
xs = (coordinates(centroid(dom, i)) for i in 1:nelements(dom))
xs = (ustrip.(to(centroid(dom, i))) for i in 1:nelements(dom))
X = reduce(hcat, xs)'
V = Tables.matrix(tab)
matrix = [X V]
elseif dom isa CartesianGrid
# a regular grid does not need to save coordinates
# a Cartesian grid does not need to save coordinates
varnames = propertynames(tab)
matrix = Tables.matrix(tab)
else
@error "can only save data defined on point sets or regular grids"
@error "can only save data defined on point sets or Cartesian grids"
end

save_legacy(filename, matrix, Tuple(varnames), header, na)
Expand Down
1 change: 1 addition & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
GeoTables = "e502b557-6362-48c1-8219-d30d308dcdb0"
Meshes = "eacbb407-ea5a-433e-ab97-5258b1ca43fa"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d"
22 changes: 10 additions & 12 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using GslibIO
using GeoTables
using Meshes
using Unitful
using Test

# environment settings
Expand All @@ -15,7 +16,7 @@ savedir = mktempdir()
sdomain = domain(sdata)
@test size(sdomain) == (2, 2, 2)
@test minimum(sdomain) == Point(0.0, 0.0, 0.0)
@test spacing(sdomain) == (1.0, 1.0, 1.0)
@test spacing(sdomain) == (1.0u"m", 1.0u"m", 1.0u"m")

@test sdata.Porosity == [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8]
@test sdata.Lithology == [1, 2, 3, 4, 5, 6, 7, 8]
Expand Down Expand Up @@ -62,7 +63,7 @@ savedir = mktempdir()
# generated point variable names
# test note: point variable names appear 2 times in the file
fname = joinpath(savedir, "extended_pset_1D.gslib")
sdata = georef((; a=rand(10)), rand(Point1, 10))
sdata = georef((; a=rand(10)), rand(Point{1}, 10))
GslibIO.save(fname, sdata)
ndata = GslibIO.load(fname)
@test sdata == ndata
Expand All @@ -71,7 +72,7 @@ savedir = mktempdir()
rm(fname)

fname = joinpath(savedir, "extended_pset_2D.gslib")
sdata = georef((; a=rand(10)), rand(Point2, 10))
sdata = georef((; a=rand(10)), rand(Point{2}, 10))
GslibIO.save(fname, sdata)
ndata = GslibIO.load(fname)
@test sdata == ndata
Expand All @@ -81,7 +82,7 @@ savedir = mktempdir()
rm(fname)

fname = joinpath(savedir, "extended_pset_3D.gslib")
sdata = georef((; a=rand(10)), rand(Point3, 10))
sdata = georef((; a=rand(10)), rand(Point{3}, 10))
GslibIO.save(fname, sdata)
ndata = GslibIO.load(fname)
@test sdata == ndata
Expand All @@ -93,7 +94,7 @@ savedir = mktempdir()

# make point variable names unique
fname = joinpath(savedir, "extended_pset.gslib")
sdata = georef((x=rand(10), y=rand(10)), rand(Point2, 10))
sdata = georef((x=rand(10), y=rand(10)), rand(Point{2}, 10))
GslibIO.save(fname, sdata)
ndata = GslibIO.load(fname)
@test sdata == ndata
Expand All @@ -104,7 +105,7 @@ savedir = mktempdir()

# custom point variable names
fname = joinpath(savedir, "extended_pset.gslib")
sdata = georef((; a=rand(10)), rand(Point2, 10))
sdata = georef((; a=rand(10)), rand(Point{2}, 10))
GslibIO.save(fname, sdata, pointvars=["X", "Y"])
ndata = GslibIO.load(fname)
@test sdata == ndata
Expand All @@ -115,7 +116,7 @@ savedir = mktempdir()

# geotable without attributes
fname = joinpath(savedir, "noattrs_pset.gslib")
sdata = georef(nothing, rand(Point2, 10))
sdata = georef(nothing, rand(Point{2}, 10))
GslibIO.save(fname, sdata)
ndata = GslibIO.load(fname)
@test isnothing(values(ndata))
Expand All @@ -124,11 +125,8 @@ savedir = mktempdir()

# error: invalid number of point variable names
fname = joinpath(savedir, "error.gslib")
sdata = georef((; a=rand(10)), rand(Point2, 10))
sdata = georef((; a=rand(10)), rand(Point{2}, 10))
@test_throws ArgumentError GslibIO.save(fname, sdata, pointvars=["x", "y", "z"])
# error: geometries with more than 3 dimensions
sdata = georef((; a=rand(10)), rand(Point{4,Float64}, 10))
@test_throws ArgumentError GslibIO.save(fname, sdata)
end

@testset "LegacyParser" begin
Expand Down Expand Up @@ -161,7 +159,7 @@ savedir = mktempdir()

@test size(domain(sdata)) == (2, 2, 2)
@test minimum(domain(sdata)) == Point(0.0, 0.0, 0.0)
@test spacing(domain(sdata)) == (1.0, 1.0, 1.0)
@test spacing(domain(sdata)) == (1.0u"m", 1.0u"m", 1.0u"m")

por = sdata.Porosity
lit = sdata.Lithology
Expand Down

2 comments on commit d254609

@juliohm
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/107496

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v1.5.0 -m "<description of version>" d254609d50c2b931fbb6a59fa7e3444b290c48e6
git push origin v1.5.0

Please sign in to comment.