From 02afdcd4b7ab56df868eed21644488a379d07a2a Mon Sep 17 00:00:00 2001 From: jingpengw Date: Wed, 26 Dec 2018 04:02:14 -0500 Subject: [PATCH] make raw encoding really not doing anything; fix a bug of creating temp layer; fix a bug of reinterpret --- src/Codings.jl | 5 ++--- src/Infos.jl | 17 +++++++++++++---- src/backends/BinDicts.jl | 7 ++++--- src/modes/sequential.jl | 3 ++- src/type.jl | 5 +++-- 5 files changed, 24 insertions(+), 13 deletions(-) diff --git a/src/Codings.jl b/src/Codings.jl index 27a5c86..c29b39b 100644 --- a/src/Codings.jl +++ b/src/Codings.jl @@ -31,10 +31,10 @@ struct BlosclzCoding <: AbstractBigArrayCoding end struct GzipCoding <: AbstractBigArrayCoding end struct ZstdCoding <: AbstractBigArrayCoding end -const DEFAULT_CODING = RawCoding +const DEFAULT_CODING = GzipCoding function encode(data::Array, coding::Type{RawCoding}) - reinterpret(UInt8, data[:]) + reinterpret(UInt8, data[:]) |> Vector end function decode(data::Vector{UInt8}, coding::Type{RawCoding}) @@ -42,7 +42,6 @@ function decode(data::Vector{UInt8}, coding::Type{RawCoding}) end function encode(data::Array, coding::Type{ZstdCoding}) - #Libz.deflate(reinterpret(UInt8, data[:])) transcode(ZstdCompressor, reinterpret(UInt8, vec(data)) |> Vector) end diff --git a/src/Infos.jl b/src/Infos.jl index 2052b0a..eb79369 100644 --- a/src/Infos.jl +++ b/src/Infos.jl @@ -22,7 +22,7 @@ export InfoScale const ENCODING_MAP = Dict{String,Any}( # note that the raw encoding in cloud storage will be automatically gzip encoded! - "raw" => GzipCoding, + "raw" => RawCoding, "jpeg" => JPEGCoding, "blosclz" => BlosclzCoding, "gzip" => GzipCoding, @@ -89,7 +89,7 @@ function Base.Dict(self::InfoScale) end end d[:size] = [get_volume_size(self)...] - d[:voxelOffset] = [Tuple(get_voxel_offset(self))...] + d[:voxel_offset] = [Tuple(get_voxel_offset(self))...] return d end @@ -120,8 +120,17 @@ end end @inline function get_encoding(self::InfoScale) self.encoding end +@inline function set_encoding!(self::InfoScale, encoding::DataType) + self.encoding = encoding +end + +""" + set_encoding!(self::InfoScale, encoding::Symbol) -@inline function set_encoding!(self::InfoScale, encoding::Symbol) +the encoding map is: +$(ENCODING_MAP) +""" +@inline function set_encoding!(self::InfoScale, encoding::String) self.encoding = ENCODING_MAP[encoding] end @@ -328,7 +337,7 @@ end @inline function get_encoding(self::Info, mip::Integer=1) InfoScales.get_encoding( get_scales(self)[mip] ) end -@inline function set_encoding!(self::Info, encoding::DataType) +@inline function set_encoding!(self::Info, encoding::Union{String, DataType}) for scale in get_scales(self) InfoScales.set_encoding!(scale, encoding) end diff --git a/src/backends/BinDicts.jl b/src/backends/BinDicts.jl index 3efd2bd..eb3cd4a 100644 --- a/src/backends/BinDicts.jl +++ b/src/backends/BinDicts.jl @@ -18,8 +18,8 @@ struct BinDict <: AbstractBigArrayBackend end end -@inline function Base.show(self::BinDict) - println("BinDict in ", get_path(self)) +@inline function Base.show(io::IO, self::BinDict) + write(io, "BinDict in " * get_path(self)) end @inline function get_path(self::BinDict) @@ -42,7 +42,7 @@ end end @inline function Base.setindex!( self::BinDict, value::Array, key::AbstractString ) - data = reinterpret(UInt8, value[:]) + data = reinterpret(UInt8, value[:]) |> Vector fileName = joinpath( get_path(self), key ) write(fileName, data) end @@ -63,3 +63,4 @@ end end # module + diff --git a/src/modes/sequential.jl b/src/modes/sequential.jl index b902f64..4417fea 100644 --- a/src/modes/sequential.jl +++ b/src/modes/sequential.jl @@ -11,7 +11,8 @@ function setindex_sequential!( ba::BigArray{D,T,N}, buf::Array{T,N}, chunkGlobalRange, globalRange, rangeInChunk, rangeInBuffer = adjust_volume_boundary(ba, chunkGlobalRange, globalRange, rangeInChunk, rangeInBuffer) @inbounds chk = buf[rangeInBuffer] - ba.kvStore[ joinpath(mipLevelName, cartesian_range2string(chunkGlobalRange)) ] = encode( chk, C) + ba.kvStore[ joinpath(mipLevelName, cartesian_range2string(chunkGlobalRange)) ] = + encode( chk, C) end end diff --git a/src/type.jl b/src/type.jl index 62bd8f4..0c4d902 100644 --- a/src/type.jl +++ b/src/type.jl @@ -21,6 +21,7 @@ end function BigArray(layerPath::AbstractString; mip::Int=1, fillMissing::Bool=DEFAULT_FILL_MISSING, mode::Symbol=DEFAULT_MODE) if isdir(layerPath) || startswith(layerPath, "file://") + layerPath = replace(layerPath, "file://"=>"/", count=1) d = BinDict(layerPath) elseif startswith(layerPath, "gs://") d = GSDict(layerPath) @@ -35,7 +36,7 @@ end @inline function BigArray(d::AbstractBigArrayBackend; mip::Int=1, fillMissing::Bool=DEFAULT_FILL_MISSING, mode::Symbol=DEFAULT_MODE) - info = d["info"] |> Info + info = d["info"] |> Info return BigArray(d, info, mip, fillMissing, mode) end @@ -93,7 +94,7 @@ function BigArray(info::Info{T,N}; mip::Integer=1, datasetDir = joinpath(layerDir, string(Infos.get_key(info, 1))) mkdir(layerDir) mkdir(datasetDir) - d = BinDict(datasetDir) + d = BinDict(layerDir) # write the info as file write(joinpath(layerDir, "info"), JSON.json(Dict(info)))