Merge pull request #1782 from ma-laforge/hdf5

Add support for annotations and "Shape"s.
This commit is contained in:
Daniel Schwabeneder 2018-10-14 18:40:44 +02:00 committed by GitHub
commit dcceef2e52
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -16,16 +16,19 @@ Read from .hdf5 file using:
#==TODO #==TODO
=============================================================================== ===============================================================================
1. Support more features 1. Support more features.
- SeriesAnnotations & GridLayout known to be missing. - GridLayout known not to be working.
3. Improve error handling. 2. Improve error handling.
- Will likely crash if file format is off. - Will likely crash if file format is off.
2. Save data in a folder parallel to "plot". 3. Save data in a folder parallel to "plot".
- Will make it easier for users to locate data. - Will make it easier for users to locate data.
- Use HDF5 reference to link data? - Use HDF5 reference to link data?
3. Develop an actual versioned file format. 4. Develop an actual versioned file format.
- Should have some form of backward compatibility. - Should have some form of backward compatibility.
- Should be reliable for archival purposes. - Should be reliable for archival purposes.
5. Fix construction of plot object with hdf5plot_read.
- Not building object correctly when backends do not natively support
a certain feature (ex: :steppre)
==# ==#
import FixedPointNumbers: N0f8 #In core Julia import FixedPointNumbers: N0f8 #In core Julia
@ -56,7 +59,8 @@ const HDF5PLOT_PLOTREF = HDF5Plot_PlotRef(nothing)
#Simple sub-structures that can just be written out using _hdf5plot_gwritefields: #Simple sub-structures that can just be written out using _hdf5plot_gwritefields:
const HDF5PLOT_SIMPLESUBSTRUCT = Union{Font, BoundingBox, const HDF5PLOT_SIMPLESUBSTRUCT = Union{Font, BoundingBox,
GridLayout, RootLayout, ColorGradient, SeriesAnnotations, PlotText GridLayout, RootLayout, ColorGradient, SeriesAnnotations, PlotText,
Shape,
} }
@ -84,7 +88,8 @@ if length(HDF5PLOT_MAP_TELEM2STR) < 1
"GRIDLAYOUT" => GridLayout, "GRIDLAYOUT" => GridLayout,
"ROOTLAYOUT" => RootLayout, "ROOTLAYOUT" => RootLayout,
"SERIESANNOTATIONS" => SeriesAnnotations, "SERIESANNOTATIONS" => SeriesAnnotations,
# "PLOTTEXT" => PlotText, "PLOTTEXT" => PlotText,
"SHAPE" => Shape,
"COLORGRADIENT" => ColorGradient, "COLORGRADIENT" => ColorGradient,
"AXIS" => Axis, "AXIS" => Axis,
"SURFACE" => Surface, "SURFACE" => Surface,
@ -243,6 +248,14 @@ end
# ---------------------------------------------------------------- # ----------------------------------------------------------------
function _hdf5plot_gwrite(grp, k::String, v) #Default function _hdf5plot_gwrite(grp, k::String, v) #Default
T = typeof(v)
if !(T <: Number || T <: String)
tstr = string(T)
path = HDF5.name(grp) * "/" * k
@info("Type not supported: $tstr\npath: $path")
# @show v
return
end
grp[k] = v grp[k] = v
_hdf5plot_writetype(grp, k, HDF5PlotNative) _hdf5plot_writetype(grp, k, HDF5PlotNative)
end end
@ -297,10 +310,6 @@ function _hdf5plot_gwrite(grp, k::String, v::Colorant)
end end
#Custom vector (when not using simple numeric type): #Custom vector (when not using simple numeric type):
function _hdf5plot_gwritearray(grp, k::String, v::Array{T}) where T function _hdf5plot_gwritearray(grp, k::String, v::Array{T}) where T
if "annotations" == k;
return #Hack. Does not yet support annotations.
end
vgrp = HDF5.g_create(grp, k) vgrp = HDF5.g_create(grp, k)
_hdf5plot_writetype(vgrp, Array) #ANY _hdf5plot_writetype(vgrp, Array) #ANY
sz = size(v) sz = size(v)
@ -310,7 +319,7 @@ function _hdf5plot_gwritearray(grp, k::String, v::Array{T}) where T
coord = lidx[iter] coord = lidx[iter]
elem = v[iter] elem = v[iter]
idxstr = join(coord, "_") idxstr = join(coord, "_")
_hdf5plot_gwrite(vgrp, "v$idxstr", v[iter]) _hdf5plot_gwrite(vgrp, "v$idxstr", elem)
end end
_hdf5plot_gwrite(vgrp, "dim", [sz...]) _hdf5plot_gwrite(vgrp, "dim", [sz...])
@ -361,10 +370,6 @@ end
# return # return
# end # end
function _hdf5plot_gwrite(grp, k::String, v::SeriesAnnotations)
#Currently no support for SeriesAnnotations
return
end
function _hdf5plot_gwrite(grp, k::String, v::Subplot) function _hdf5plot_gwrite(grp, k::String, v::Subplot)
grp = HDF5.g_create(grp, k) grp = HDF5.g_create(grp, k)
_hdf5plot_gwrite(grp, "index", v[:subplot_index]) _hdf5plot_gwrite(grp, "index", v[:subplot_index])
@ -487,6 +492,29 @@ function _hdf5plot_read(grp, k::String, T::Type{HDF5CTuple}, dtid)
v = _hdf5plot_read(grp, k, Array, dtid) v = _hdf5plot_read(grp, k, Array, dtid)
return tuple(v...) return tuple(v...)
end end
function _hdf5plot_read(grp, k::String, T::Type{PlotText}, dtid)
grp = HDF5.g_open(grp, k)
str = _hdf5plot_read(grp, "str")
font = _hdf5plot_read(grp, "font")
return PlotText(str, font)
end
function _hdf5plot_read(grp, k::String, T::Type{SeriesAnnotations}, dtid)
grp = HDF5.g_open(grp, k)
strs = _hdf5plot_read(grp, "strs")
font = _hdf5plot_read(grp, "font")
baseshape = _hdf5plot_read(grp, "baseshape")
scalefactor = _hdf5plot_read(grp, "scalefactor")
return SeriesAnnotations(strs, font, baseshape, scalefactor)
end
function _hdf5plot_read(grp, k::String, T::Type{Shape}, dtid)
grp = HDF5.g_open(grp, k)
x = _hdf5plot_read(grp, "x")
y = _hdf5plot_read(grp, "y")
return Shape(x, y)
end
function _hdf5plot_read(grp, k::String, T::Type{ColorGradient}, dtid) function _hdf5plot_read(grp, k::String, T::Type{ColorGradient}, dtid)
grp = HDF5.g_open(grp, k) grp = HDF5.g_open(grp, k)
@ -560,11 +588,6 @@ end
function _hdf5plot_read(sp::Subplot, subpath::String, f) function _hdf5plot_read(sp::Subplot, subpath::String, f)
f = f::HDF5.HDF5File #Assert f = f::HDF5.HDF5File #Assert
grp = HDF5.g_open(f, _hdf5_plotelempath("$subpath/attr"))
kwlist = KW()
_hdf5plot_read(grp, kwlist)
_hdf5_merge!(sp.attr, kwlist)
grp = HDF5.g_open(f, _hdf5_plotelempath("$subpath/series_list")) grp = HDF5.g_open(f, _hdf5_plotelempath("$subpath/series_list"))
nseries = _hdf5plot_readcount(grp) nseries = _hdf5plot_readcount(grp)
@ -576,6 +599,12 @@ function _hdf5plot_read(sp::Subplot, subpath::String, f)
_hdf5_merge!(sp.series_list[end].plotattributes, kwlist) _hdf5_merge!(sp.series_list[end].plotattributes, kwlist)
end end
#Perform after adding series... otherwise values get overwritten:
grp = HDF5.g_open(f, _hdf5_plotelempath("$subpath/attr"))
kwlist = KW()
_hdf5plot_read(grp, kwlist)
_hdf5_merge!(sp.attr, kwlist)
return return
end end