Skip to content

Commit

Permalink
Move func to utility; loose hdf type constraint
Browse files Browse the repository at this point in the history
  • Loading branch information
henry2004y committed Sep 23, 2024
1 parent afe98da commit d8f7db6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/Batsrus.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export BATLData,
load, readlogdata, readtecdata, showhead, # io
getvars, getvar, cutdata, subvolume, subsurface, # select
Batl, convertTECtoVTU, convertIDLtoVTK, readhead, readtree, getConnectivity, # vtk
interp1d, interp2d, slice1d, get_var_range # plot/utility
interp1d, interp2d, slice1d, get_var_range, squeeze # plot/utility

"Type for the file information."
struct FileList
Expand Down
11 changes: 2 additions & 9 deletions src/hdf.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module HDF

using HDF5

export BatsrusHDF5Uniform, extract_field, squeeze
export BatsrusHDF5Uniform, extract_field

abstract type BatsrusHDF5File end

Expand Down Expand Up @@ -42,7 +42,7 @@ struct HDF5Common{TI<:Signed, TF<:AbstractFloat} <: BatsrusHDF5File
function HDF5Common(filename::AbstractString)
fid = h5open(filename, "r")
meta_int = read(fid["Integer Plot Metadata"])::Vector{Int32}
meta_real = read(fid["Real Plot Metadata"])::Vector{Float32}
meta_real = read(fid["Real Plot Metadata"])::Vector{<:AbstractFloat}

version = meta_int[1]
geometry = meta_int[11]
Expand Down Expand Up @@ -276,11 +276,4 @@ function extract_field(file::BatsrusHDF5Uniform, var::String;
output, (xl_new, yl_new, zl_new), (xu_new, yu_new, zu_new)
end

"Squeeze singleton dimensions for an array `A`."
function squeeze(A::AbstractArray)
singleton_dims = tuple((d for d in 1:ndims(A) if size(A, d) == 1)...)

dropdims(A, dims=singleton_dims)
end

end
9 changes: 8 additions & 1 deletion src/plot/utility.jl
Original file line number Diff line number Diff line change
Expand Up @@ -192,4 +192,11 @@ function getview(bd::BATLData{2, T}, var) where T
end

"Return value range of `var` in `bd`."
get_var_range(bd::BATLData, var) = getview(bd, var) |> extrema
get_var_range(bd::BATLData, var) = getview(bd, var) |> extrema

"Squeeze singleton dimensions for an array `A`."
function squeeze(A::AbstractArray)
singleton_dims = tuple((d for d in 1:ndims(A) if size(A, d) == 1)...)

dropdims(A, dims=singleton_dims)
end

0 comments on commit d8f7db6

Please sign in to comment.